dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
594167
From c9fe9526f07ad24d29842fa853ee458b68660896 Mon Sep 17 00:00:00 2001
594167
From: Frantisek Sumsal <frantisek@sumsal.cz>
594167
Date: Fri, 22 Apr 2022 18:03:14 +0200
594167
Subject: [PATCH] test: extend the "hashed" unit names coverage a bit
594167
594167
Follow-up to #22759.
594167
594167
(cherry picked from commit 98f8c316389177169c6599e67010ebb1789a6b26)
594167
594167
Related: #2083493
594167
---
594167
 test/units/testsuite-64.sh | 19 ++++++++++++++++---
594167
 1 file changed, 16 insertions(+), 3 deletions(-)
594167
594167
diff --git a/test/units/testsuite-64.sh b/test/units/testsuite-64.sh
594167
index 218b2ee8d1..5f9aeee261 100755
594167
--- a/test/units/testsuite-64.sh
594167
+++ b/test/units/testsuite-64.sh
594167
@@ -646,7 +646,7 @@ testcase_iscsi_lvm() {
594167
 }
594167
 
594167
 testcase_long_sysfs_path() {
594167
-    local link logfile mpoint
594167
+    local cursor link logfile mpoint
594167
     local expected_symlinks=(
594167
         "/dev/disk/by-label/data_vol"
594167
         "/dev/disk/by-label/swap_vol"
594167
@@ -657,6 +657,12 @@ testcase_long_sysfs_path() {
594167
         "/dev/disk/by-uuid/deadbeef-dead-dead-beef-222222222222"
594167
     )
594167
 
594167
+    # Create a cursor file to skip messages generated by udevd in initrd, as it
594167
+    # might not be the same up-to-date version as we currently run (hence generating
594167
+    # messages we check for later and making the test fail)
594167
+    cursor="$(mktemp)"
594167
+    journalctl --cursor-file="${cursor:?}" -n0 -q
594167
+
594167
     # Make sure the test device is connected and show its "wonderful" path
594167
     stat /sys/block/vda
594167
     readlink -f /sys/block/vda/dev
594167
@@ -685,13 +691,20 @@ testcase_long_sysfs_path() {
594167
     udevadm settle
594167
 
594167
     logfile="$(mktemp)"
594167
-    [[ "$(journalctl -b -q --no-pager -o short-monotonic -p info --grep "Device path.*vda.?' too long to fit into unit name" | wc -l)" -eq 0 ]]
594167
+    # Check state of affairs after https://github.com/systemd/systemd/pull/22759
594167
+    # Note: can't use `--cursor-file` here, since we don't want to update the cursor
594167
+    #       after using it
594167
+    [[ "$(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 ]]
594167
+    [[ "$(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 ]]
594167
+    # Check if the respective "hashed" units exist and are active (plugged)
594167
+    systemctl status --no-pager "$(readlink -f /sys/block/vda/vda1)"
594167
+    systemctl status --no-pager "$(readlink -f /sys/block/vda/vda2)"
594167
     # Make sure we don't unnecessarily spam the log
594167
     { journalctl -b -q --no-pager -o short-monotonic -p info --grep "/sys/devices/.+/vda[0-9]?" _PID=1 + UNIT=systemd-udevd.service || :;} | tee "$logfile"
594167
     [[ "$(wc -l <"$logfile")" -lt 10 ]]
594167
 
594167
     : >/etc/fstab
594167
-    rm -fr "${logfile:?}" "${mpoint:?}"
594167
+    rm -fr "${cursor:?}" "${logfile:?}" "${mpoint:?}"
594167
 }
594167
 
594167
 : >/failed