]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add MD-related tests to TEST-64 23011/head
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 7 Apr 2022 16:03:17 +0000 (18:03 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 13 Apr 2022 15:12:02 +0000 (00:12 +0900)
test/TEST-64-UDEV-STORAGE/test.sh
test/test-functions
test/units/testsuite-64.sh

index 04632952d002b9a7b12363394517439c14587a3c..0e684e01a049feeb28cab46277319d01f0629bdf 100755 (executable)
@@ -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
index 47eae9f0cbd938bc778740c69da2fda4a8547efe..b5a618c741763237464db1b4f8b9ccd0f3a11cba 100644 (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"
 
index 5f50131dd5db0399856bd5538b98653f66649d2d..43c46db2f9fed22101e8163dd30ba45c43ff42c5 100755 (executable)
@@ -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