1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

TEST-17-UDEV: Don't hardcode root device name

There's no guarantee the root device will be /dev/sda, so let's use
bootctl to get the actual path instead of harcoding it.
This commit is contained in:
Daan De Meyer 2024-11-01 21:27:08 +01:00
parent f4092cb974
commit 29a8e71d9c
2 changed files with 32 additions and 28 deletions

View File

@ -5,52 +5,54 @@ set -o pipefail
mkdir -p /run/udev/rules.d/
ROOTDEV="$(bootctl -RR)"
rm -f /run/udev/rules.d/50-testsuite.rules
udevadm control --reload
udevadm trigger --settle /dev/sda
udevadm trigger --settle "$ROOTDEV"
while : ; do
(
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=foobar.service
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q -v sda
systemctl show -p WantedBy waldo.service | grep -q -v sda
udevadm info "$ROOTDEV" | grep -q -v SYSTEMD_WANTS=foobar.service
udevadm info "$ROOTDEV" | grep -q -v SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q -v "${ROOTDEV#/dev/}"
systemctl show -p WantedBy waldo.service | grep -q -v "${ROOTDEV#/dev/}"
) && break
sleep .5
done
cat >/run/udev/rules.d/50-testsuite.rules <<EOF
SUBSYSTEM=="block", KERNEL=="sda", OPTIONS="log_level=debug"
ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sda", ENV{SYSTEMD_WANTS}="foobar.service"
SUBSYSTEM=="block", KERNEL=="${ROOTDEV#/dev/}", OPTIONS="log_level=debug"
ACTION!="remove", SUBSYSTEM=="block", KERNEL=="${ROOTDEV#/dev/}", ENV{SYSTEMD_WANTS}="foobar.service"
EOF
udevadm control --reload
udevadm trigger --settle /dev/sda
udevadm trigger --settle "$ROOTDEV"
while : ; do
(
udevadm info /dev/sda | grep -q SYSTEMD_WANTS=foobar.service
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q sda
systemctl show -p WantedBy waldo.service | grep -q -v sda
udevadm info "$ROOTDEV" | grep -q SYSTEMD_WANTS=foobar.service
udevadm info "$ROOTDEV" | grep -q -v SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q "${ROOTDEV#/dev/}"
systemctl show -p WantedBy waldo.service | grep -q -v "${ROOTDEV#/dev/}"
) && break
sleep .5
done
cat >/run/udev/rules.d/50-testsuite.rules <<EOF
SUBSYSTEM=="block", KERNEL=="sda", OPTIONS="log_level=debug"
ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sda", ENV{SYSTEMD_WANTS}="waldo.service"
SUBSYSTEM=="block", KERNEL=="${ROOTDEV#/dev/}", OPTIONS="log_level=debug"
ACTION!="remove", SUBSYSTEM=="block", KERNEL=="${ROOTDEV#/dev/}", ENV{SYSTEMD_WANTS}="waldo.service"
EOF
udevadm control --reload
udevadm trigger --settle /dev/sda
udevadm trigger --settle "$ROOTDEV"
while : ; do
(
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=foobar.service
udevadm info /dev/sda | grep -q SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q -v sda
systemctl show -p WantedBy waldo.service | grep -q sda
udevadm info "$ROOTDEV" | grep -q -v SYSTEMD_WANTS=foobar.service
udevadm info "$ROOTDEV" | grep -q SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q -v "${ROOTDEV#/dev/}"
systemctl show -p WantedBy waldo.service | grep -q "${ROOTDEV#/dev/}"
) && break
sleep .5
@ -59,14 +61,14 @@ done
rm /run/udev/rules.d/50-testsuite.rules
udevadm control --reload
udevadm trigger --settle /dev/sda
udevadm trigger --settle "$ROOTDEV"
while : ; do
(
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=foobar.service
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q -v sda
systemctl show -p WantedBy waldo.service | grep -q -v sda
udevadm info "$ROOTDEV" | grep -q -v SYSTEMD_WANTS=foobar.service
udevadm info "$ROOTDEV" | grep -q -v SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q -v "${ROOTDEV#/dev/}"
systemctl show -p WantedBy waldo.service | grep -q -v "${ROOTDEV#/dev/}"
) && break
sleep .5

View File

@ -46,8 +46,10 @@ EOF
check
MAJOR=$(udevadm info /dev/sda | grep -e '^E: MAJOR=' | sed -e 's/^E: MAJOR=//')
MINOR=$(udevadm info /dev/sda | grep -e '^E: MINOR=' | sed -e 's/^E: MINOR=//')
ROOTDEV="$(bootctl -RR)"
MAJOR="$(udevadm info "$ROOTDEV" | grep -e '^E: MAJOR=' | sed -e 's/^E: MAJOR=//')"
MINOR="$(udevadm info "$ROOTDEV" | grep -e '^E: MINOR=' | sed -e 's/^E: MINOR=//')"
test -L "/run/udev/watch/b${MAJOR}:${MINOR}"
cat >/run/udev/rules.d/50-testsuite.rules <<EOF
@ -56,8 +58,8 @@ EOF
check
MAJOR=$(udevadm info /dev/sda | grep -e '^E: MAJOR=' | sed -e 's/^E: MAJOR=//')
MINOR=$(udevadm info /dev/sda | grep -e '^E: MINOR=' | sed -e 's/^E: MINOR=//')
MAJOR="$(udevadm info "$ROOTDEV" | grep -e '^E: MAJOR=' | sed -e 's/^E: MAJOR=//')"
MINOR="$(udevadm info "$ROOTDEV" | grep -e '^E: MINOR=' | sed -e 's/^E: MINOR=//')"
test ! -e "/run/udev/watch/b${MAJOR}:${MINOR}"
rm /run/udev/rules.d/00-debug.rules