test: add MD-related tests to TEST-64

This commit is contained in:
Frantisek Sumsal 2022-04-07 18:03:17 +02:00 committed by Yu Watanabe
parent 9a78ee002f
commit 3c9af05cae
3 changed files with 86 additions and 0 deletions

View file

@ -42,6 +42,9 @@ _host_has_feature() {(
lvm)
command -v lvm || return $?
;;
mdadm)
command -v mdadm || return $?
;;
multipath)
command -v multipath && command -v multipathd || return $?
;;
@ -64,6 +67,7 @@ test_append_files() {(
[btrfs]=install_btrfs
[iscsi]=install_iscsi
[lvm]=install_lvm
[mdadm]=install_mdadm
[multipath]=install_multipath
)
@ -444,6 +448,32 @@ EOF
rm -f "${testdisk:?}"
}
testcase_mdadm_basic() {
if ! _host_has_feature "mdadm"; then
echo "Missing mdadm tools/modules, skipping the test..."
return 77
fi
local qemu_opts=("-device ahci,id=ahci0")
local diskpath i size
for i in {0..4}; do
diskpath="${TESTDIR:?}/mdadmbasic${i}.img"
dd if=/dev/zero of="$diskpath" bs=1M count=64
qemu_opts+=(
"-device ide-hd,bus=ahci0.$i,drive=drive$i,model=foobar,serial=deadbeefmdadm$i"
"-drive format=raw,cache=unsafe,file=$diskpath,if=none,id=drive$i"
)
done
KERNEL_APPEND="systemd.setenv=TEST_FUNCTION_NAME=${FUNCNAME[0]} ${USER_KERNEL_APPEND:-}"
QEMU_OPTIONS="${qemu_opts[*]} ${USER_QEMU_OPTIONS:-}"
test_run_one "${1:?}" || return $?
rm -f "${TESTDIR:?}"/mdadmbasic*.img
}
# Allow overriding which tests should be run from the "outside", useful for manual
# testing (make -C test/... TESTCASES="testcase1 testcase2")
if [[ -v "TESTCASES" && -n "$TESTCASES" ]]; then

View file

@ -1055,6 +1055,29 @@ install_iscsi() {
fi
}
install_mdadm() {
local unit
local mdadm_units=(
system/mdadm-grow-continue@.service
system/mdadm-last-resort@.service
system/mdadm-last-resort@.timer
system/mdmon@.service
system/mdmonitor-oneshot.service
system/mdmonitor-oneshot.timer
system/mdmonitor.service
system-shutdown/mdadm.shutdown
)
image_install mdadm mdmon
inst_rules 01-md-raid-creating.rules 63-md-raid-arrays.rules 64-md-raid-assembly.rules 69-md-clustered-confirm-device.rules
# Fedora/CentOS/RHEL ships this rule file
[[ -f /lib/udev/rules.d/65-md-incremental.rules ]] && inst_rules 65-md-incremental.rules
for unit in "${mdadm_units[@]}"; do
image_install "${ROOTLIBDIR:?}/$unit"
done
}
install_compiled_systemd() {
dinfo "Install compiled systemd"

View file

@ -534,6 +534,39 @@ testcase_long_sysfs_path() {
rm -fr "${logfile:?}" "${mpoint:?}"
}
testcase_mdadm_basic() {
local raid_name uuid
local expected_symlinks=()
local devices=(
/dev/disk/by-id/ata-foobar_deadbeefmdadm{0..4}
)
ls -l "${devices[@]}"
echo "Mirror raid"
raid_name="mdmirror"
uuid="aaaaaaaa:bbbbbbbb:cccccccc:00000001"
expected_symlinks=(
"/dev/md/$raid_name"
"/dev/disk/by-id/md-name-H:mdmirror"
"/dev/disk/by-id/md-uuid-$uuid"
"/dev/disk/by-label/mdadm_mirror" # ext4 partition
)
# Create a simple RAID 1 with an ext4 filesystem
echo y | mdadm --create "${expected_symlinks[0]}" --name "$raid_name" --uuid "$uuid" /dev/disk/by-id/ata-foobar_deadbeefmdadm{0..1} -v -f --level=1 --raid-devices=2
udevadm wait --settle --timeout=30 "${expected_symlinks[0]}"
mkfs.ext4 -L mdadm_mirror "/dev/md/$raid_name"
udevadm wait --settle --timeout=30 "${expected_symlinks[@]}"
# Disassemble the array
mdadm -v --stop "${expected_symlinks[0]}"
udevadm settle
helper_check_device_symlinks
# Reassemble it and check if all requires symlinks exist
mdadm --assemble "${expected_symlinks[0]}" --name "$raid_name" -v
udevadm wait --settle --timeout=30 "${expected_symlinks[@]}"
helper_check_device_symlinks
}
: >/failed
udevadm settle