Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] add first version of setup for creating disk with failures #173

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions roles/qe-dmdisks/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
================
QE-DM-disks
================

This role creates Device Mapper disk based on real device and
selected table format (e.g "error", "zero", "delay", "flakey").

This role is first role in row for testing disk failures.


See Also:

* https://www.kernel.org/doc/Documentation/device-mapper/dm-flakey.txt
* https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/logical_volume_manager_administration/device_mapper
* https://mbroz.fedorapeople.org/talks/DeviceMapperBasics/dm.pdf
* https://stackoverflow.com/questions/31806244/simulating-bad-sectors-in-linux

If there is need to do scsi disk with failure, see:

* http://sg.danny.cz/sg/sdebug26.html
* https://www.certdepot.net/rhel7-configure-iscsi-target-initiator-persistently/
13 changes: 13 additions & 0 deletions roles/qe-dmdisks/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
# Table format, see 'man 8 dmsetup'
table_format: "flakey"
# see https://www.kernel.org/doc/Documentation/device-mapper/dm-flakey.txt
flakey_args: "1 1"
mbukatov marked this conversation as resolved.
Show resolved Hide resolved

# This default configuration creates 20 failed blocks, 1kB each.
# First failed blocks will be at 100MB.
# Size of used disk for mapping should be at least 10GB.
number_of_failed_blocks: 20
first_failure_at: 100 #MB
repeat_failure_every: 500 #MB
failed_block_size: 5 #kB
78 changes: 78 additions & 0 deletions roles/qe-dmdisks/files/gen_dm_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

if [ $# -lt 6 -o "$1" == "-help" -o "$1" == "-h" ]; then
echo "This script generates file with map for device mapper."
echo "Usage: $0 <full path to device> <table format> <first failure> <repeat failure> <failed set> <set number> [<flakey args>]"
echo "<full path to device>: for example '/dev/vdb'"
echo "<table format>: can be one of: 'flakey', 'zero', 'delay', 'error'"
echo "<first failure>: first failure is after X MB from disk "
exit
fi

device=$1
table_format=$2
first_failure_at=$3
repeat_failure_every=$4
failed_block_size=$5
number_of_failed_blocks=$6
flakey_args=${@:7}

# Get disk size and size of one sector
lsblk_out=$(lsblk -b --output 'SIZE,PHY-SEC' ${device} | tail -1)

disk_size=$(echo ${lsblk_out} | tr -s ' ' | cut -d ' ' -f 1)
sector_size=$(echo ${lsblk_out} | tr -s ' ' | cut -d ' ' -f 2)

# Get number of sectors
block_count=$(echo ${lsblk_out} | tr -s ' ' '/' | bc)

# Get number of sectors till first faulty set of sectors
block100=$(echo "${first_failure_at}*1024*1024/${sector_size}" | bc)

# Get number of failed sectors in one sector set
failed_set=$(echo "${failed_block_size}*1024/${sector_size}" | bc)

# Get number of failed sectors till next failure
repeated_set=$(echo "${repeat_failure_every}*1024*1024/${sector_size}" | bc)

#block100=10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there this commented code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is here so people can try it with human easily countable data sizes. Should I remove it?

#failed_set=5
#repeated_set=10
#block_count=500

# 0 10 linear /dev/vdb 0
# 10 5 flakey /dev/vdb 10 1 1
# 15 10 linear /dev/vdb 15
# 25 5 flakey /dev/vdb 25 1 1
# 30 10 linear /dev/vdb 30


# 0 10 linear /dev/vdb 0
# 10 5 error
# 15 10 linear /dev/vdb 10
# 25 5 error
# 30 10 linear /dev/vdb 20

echo "0 ${block100} linear ${device} 0"
head=${block100}

if [ "${table_format}" == "flakey" ]; then
for i in `seq ${number_of_failed_blocks}`; do
echo "${head} ${failed_set} flakey ${device} ${head} ${flakey_args}"
head=$((${head} + ${failed_set}))
echo "${head} ${repeated_set} linear ${device} ${head}"
head=$((${head} + ${repeated_set}))
done

echo "${head} $((${block_count} - ${head})) linear ${device} ${head}"
else
head2=${block100}
for i in `seq ${number_of_failed_blocks}`; do
echo "${head} ${failed_set} ${table_format}"
head=$((${head} + ${failed_set}))
echo "${head} ${repeated_set} linear ${device} ${head2}"
head=$((${head} + ${repeated_set}))
head2=$((${head2} + ${repeated_set}))
done
echo "${head} $((${block_count} - ${head2})) linear ${device} ${head2}"
fi
24 changes: 24 additions & 0 deletions roles/qe-dmdisks/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---

- name: Install helper script
copy:
src: "gen_dm_file.sh"
dest: "/usr/local/bin/usmqe_gen_dm_file.sh"
mode: "755"

- name: Install tools required by helper script
yum:
name: bc
state: installed

- name: Generate description file
shell: "usmqe_gen_dm_file.sh /dev/{{ item.device }} {{ table_format }} {{ first_failure_at }} {{ repeat_failure_every }} {{ failed_block_size }} {{ number_of_failed_blocks }} {{ flakey_args }} > {{item.device}}_description_file"
with_items: "{{ devices }}"

- name: Create disk
shell: "cat {{item.device}}_description_file | dmsetup create {{ item.new_device }}"
with_items: "{{ devices }}"

- name: Check result
shell: "lsblk | grep {{ item.new_device }}"
with_items: "{{ devices }}"
46 changes: 46 additions & 0 deletions test_setup.disk_failures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
# ========================================
# QE configuration of disk with failures
# ========================================
#
# Overview of the configuration this playbook sets up:
#
# * Creates device mapper disks from disks avaialble for volumes/pools.
# First failure is at 100MB and there are other 19 failures. Size of failed block is 1kB
#
# Example of dm file
# 0 10 linear /dev/vdb 0
# 10 5 flakey /dev/vdb 10 1 1
# 15 10 linear /dev/vdb 15
# 25 5 flakey /dev/vdb 25 1 1
# 30 10 linear /dev/vdb 30
#
# Requirements:
#
# * Size of used disks is at least 10 GB
#
# See Also:
#
# * https://www.kernel.org/doc/Documentation/device-mapper/dm-flakey.txt
# * https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/logical_volume_manager_administration/device_mapper
# * https://mbroz.fedorapeople.org/talks/DeviceMapperBasics/dm.pdf
# * https://stackoverflow.com/questions/31806244/simulating-bad-sectors-in-linux
#
# If there is need to do scsi disk with failure, see:
#
# * http://sg.danny.cz/sg/sdebug26.html
# * https://www.certdepot.net/rhel7-configure-iscsi-target-initiator-persistently/

- hosts: usm_nodes
remote_user: root
vars:
# TODO use available disks instead of hardcoded ones
devices:
- { device: 'vdd', new_device: 'xxa' }
- { device: 'vde', new_device: 'xxb' }
# other options "error", "zero", "delay", see 'man 8 dmsetup'
table_format: "flakey"

roles:
- name: Create new disks with specified table format
role: qe-dmdisks
25 changes: 25 additions & 0 deletions test_teardown.disk_failures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# ==============================================
# QE teardown of setup with disk with failures
# ==============================================
#
# See 'Setup' file for details.

- hosts: usm_nodes
remote_user: root
vars:
# TODO use available disks instead of hardcoded ones
devices:
- { device: 'vdd', new_device: 'xxa' }
- { device: 'vde', new_device: 'xxb' }

tasks:

- name: Remove helper script
file:
dest: "/usr/local/bin/usmqe_gen_dm_file.sh"
state: "absent"

- name: Remove disks
shell: "dmsetup remove {{ item.new_device }}"
with_items: "{{ devices }}"