]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
TEST-64-UDEV-STORAGE: Don't hardcode device name in long-sysfs-path test 34984/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 1 Nov 2024 20:27:52 +0000 (21:27 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 2 Nov 2024 19:43:22 +0000 (20:43 +0100)
There's no guarantee our device will be named /dev/vda, so give it
a serial so we can query for its devname inside the test.

test/TEST-64-UDEV-STORAGE/long_sysfs_path.configure
test/TEST-64-UDEV-STORAGE/test.sh
test/units/TEST-64-UDEV-STORAGE.sh

index f29677ce663f535c0a178887e6673a0973be2dc6..02e2ac4daaabec54708e108c6ac55b0446862cbe 100755 (executable)
@@ -26,6 +26,6 @@ for bridge in range(1, 26):
         f"pci-bridge,id=pci_bridge{bridge},bus=pci_bridge{bridge - 1},chassis_nr={64 + bridge},addr=1",
     ]
 
-config["QemuArgs"] += ["-device", f"virtio-blk-pci,drive=drive0,bus=pci_bridge25,addr=1"]
+config["QemuArgs"] += ["-device", f"virtio-blk-pci,drive=drive0,bus=pci_bridge25,addr=1,serial=long-sysfs-path"]
 
 json.dump(config, sys.stdout)
index 2fd7bf2bfb97bca0b518a6b98f60813db064f737..104902055b5e9094a8051e4c41c6a6d1c5b82834 100755 (executable)
@@ -464,7 +464,7 @@ testcase_long_sysfs_path() {
         qemu_opts+=("-device pci-bridge,id=pci_bridge$brid,bus=pci_bridge$((brid-1)),chassis_nr=$((64+brid))")
     done
 
-    qemu_opts+=("-device virtio-blk-pci,drive=drive0,bus=pci_bridge$brid")
+    qemu_opts+=("-device virtio-blk-pci,drive=drive0,bus=pci_bridge$brid,serial=long-sysfs-path")
 
     KERNEL_APPEND="systemd.setenv=TEST_FUNCTION_NAME=${FUNCNAME[0]} ${USER_KERNEL_APPEND:-}"
     QEMU_OPTIONS="${qemu_opts[*]} ${USER_QEMU_OPTIONS:-}"
index 6c8f6d63e6d1b5b224e6cb3557682c938561877e..17f93dc4a1a56ecbe488affb8bf5de4d86836eb7 100755 (executable)
@@ -1006,19 +1006,21 @@ testcase_long_sysfs_path() {
     journalctl --cursor-file="${cursor:?}" -n0 -q
 
     # Make sure the test device is connected and show its "wonderful" path
-    stat /sys/block/vda
-    readlink -f /sys/block/vda/dev
+    dev="$(udevadm info -e --property-match=ID_SERIAL=long-sysfs-path --property-match DEVTYPE=disk --json=short | jq -r .DEVNAME)"
+    dev="${dev#/dev/}"
 
-    dev="/dev/vda"
-    udevadm lock --device "$dev" sfdisk "$dev" <<EOF
+    stat "/sys/block/${dev}"
+    readlink -f "/sys/block/${dev}/dev"
+
+    udevadm lock --device "/dev/${dev}" sfdisk "/dev/${dev}" <<EOF
 label: gpt
 
 name="test_swap", size=32M
 uuid="deadbeef-dead-dead-beef-000000000000", name="test_part", size=5M
 EOF
     udevadm settle
-    udevadm lock --device "${dev}1" mkswap -U "deadbeef-dead-dead-beef-111111111111" -L "swap_vol" "${dev}1"
-    udevadm lock --device "${dev}2" mkfs.ext4 -U "deadbeef-dead-dead-beef-222222222222" -L "data_vol" "${dev}2"
+    udevadm lock --device "/dev/${dev}1" mkswap -U "deadbeef-dead-dead-beef-111111111111" -L "swap_vol" "/dev/${dev}1"
+    udevadm lock --device "/dev/${dev}2" mkfs.ext4 -U "deadbeef-dead-dead-beef-222222222222" -L "data_vol" "/dev/${dev}2"
     udevadm wait --settle --timeout=30 "${expected_symlinks[@]}"
 
     # Try to mount the data partition manually (using its label)
@@ -1044,13 +1046,13 @@ EOF
     # Check state of affairs after https://github.com/systemd/systemd/pull/22759
     # Note: can't use `--cursor-file` here, since we don't want to update the cursor
     #       after using it
-    [[ "$(journalctl --after-cursor="$(<"$cursor")" -q --no-pager -o short-monotonic -p info --grep "Device path.*vda.?' too long to fit into unit name" | wc -l)" -eq 0 ]]
-    [[ "$(journalctl --after-cursor="$(<"$cursor")" -q --no-pager -o short-monotonic --grep "Unit name .*vda.?\.device\" too long, falling back to hashed unit name" | wc -l)" -gt 0 ]]
+    [[ "$(journalctl --after-cursor="$(<"$cursor")" -q --no-pager -o short-monotonic -p info --grep "Device path.*${dev}.?' too long to fit into unit name" | wc -l)" -eq 0 ]]
+    [[ "$(journalctl --after-cursor="$(<"$cursor")" -q --no-pager -o short-monotonic --grep "Unit name .*${dev}.?\.device\" too long, falling back to hashed unit name" | wc -l)" -gt 0 ]]
     # Check if the respective "hashed" units exist and are active (plugged)
-    systemctl status --no-pager "$(readlink -f /sys/block/vda/vda1)"
-    systemctl status --no-pager "$(readlink -f /sys/block/vda/vda2)"
+    systemctl status --no-pager "$(readlink -f "/sys/block/${dev}/${dev}1")"
+    systemctl status --no-pager "$(readlink -f "/sys/block/${dev}/${dev}2")"
     # Make sure we don't unnecessarily spam the log
-    { journalctl -b -q --no-pager -o short-monotonic -p info --grep "/sys/devices/.+/vda[0-9]?" _PID=1 + UNIT=systemd-udevd.service || :;} | tee "$logfile"
+    { journalctl -b -q --no-pager -o short-monotonic -p info --grep "/sys/devices/.+/${dev}[0-9]?" _PID=1 + UNIT=systemd-udevd.service || :;} | tee "$logfile"
     [[ "$(wc -l <"$logfile")" -lt 10 ]]
 
     : >/etc/fstab