test: add workaround for unexpected VM restart (#38397)

Workarounds for issue #38240.
This commit is contained in:
Luca Boccassi
2025-07-29 09:52:37 +01:00
committed by GitHub
2 changed files with 45 additions and 38 deletions

View File

@@ -6,9 +6,9 @@ set -eux
set -o pipefail
# Check if homectl is installed, and if it isn't bail out early instead of failing
if ! test -x /usr/bin/homectl ; then
echo "no homed" >/skipped
exit 77
if ! command -v homectl >/dev/null; then
echo "no homed" >/skipped
exit 77
fi
inspect() {
@@ -29,19 +29,11 @@ inspect() {
}
wait_for_exist() {
# 2min max
for i in {1..60}; do
(( i > 1 )) && sleep 2
homectl inspect "$1" && break
done
timeout 2m bash -c "until homectl inspect '${1:?}'; do sleep 2; done"
}
wait_for_state() {
# 2min max
for i in {1..60}; do
(( i > 1 )) && sleep 2
homectl inspect "$1" | grep -qF "State: $2" && break
done
timeout 2m bash -c "until homectl inspect '${1:?}' | grep -qF 'State: $2'; do sleep 2; done"
}
FSTYPE="$(stat --file-system --format "%T" /)"
@@ -123,32 +115,32 @@ inspect test-user
# Do some keyring tests, but only on real kernels, since keyring access inside of containers will fail
# (See: https://github.com/systemd/systemd/issues/17606)
if ! systemd-detect-virt -cq ; then
PASSWORD=xEhErW0ndafV4s homectl activate test-user
inspect test-user
PASSWORD=xEhErW0ndafV4s homectl activate test-user
inspect test-user
# Key should now be in the keyring
homectl update test-user --real-name "Keyring Test"
inspect test-user
# Key should now be in the keyring
homectl update test-user --real-name "Keyring Test"
inspect test-user
# These commands shouldn't use the keyring
(! timeout 5s homectl authenticate test-user )
(! NEWPASSWORD="foobar" timeout 5s homectl passwd test-user )
# These commands shouldn't use the keyring
(! timeout 5s homectl authenticate test-user )
(! NEWPASSWORD="foobar" timeout 5s homectl passwd test-user )
homectl lock test-user
inspect test-user
homectl lock test-user
inspect test-user
# Key should be gone from keyring
(! timeout 5s homectl update test-user --real-name "Keyring Test 2" )
# Key should be gone from keyring
(! timeout 5s homectl update test-user --real-name "Keyring Test 2" )
PASSWORD=xEhErW0ndafV4s homectl unlock test-user
inspect test-user
PASSWORD=xEhErW0ndafV4s homectl unlock test-user
inspect test-user
# Key should have been re-instantiated into the keyring
homectl update test-user --real-name "Keyring Test 3"
inspect test-user
# Key should have been re-instantiated into the keyring
homectl update test-user --real-name "Keyring Test 3"
inspect test-user
homectl deactivate test-user
inspect test-user
homectl deactivate test-user
inspect test-user
fi
# Do some resize tests, but only if we run on real kernels and are on btrfs, as quota inside of containers
@@ -242,13 +234,13 @@ homectl remove test-user
# blob directory tests
# See docs/USER_RECORD_BLOB_DIRS.md
checkblob() {
test -f "/var/cache/systemd/home/blob-user/$1"
stat -c "%u %#a" "/var/cache/systemd/home/blob-user/$1" | grep "^0 0644"
test -f "/home/blob-user/.identity-blob/$1"
stat -c "%u %#a" "/home/blob-user/.identity-blob/$1" | grep "^12345 0644"
test -f "/var/cache/systemd/home/blob-user/$1"
stat -c "%u %#a" "/var/cache/systemd/home/blob-user/$1" | grep "^0 0644"
test -f "/home/blob-user/.identity-blob/$1"
stat -c "%u %#a" "/home/blob-user/.identity-blob/$1" | grep "^12345 0644"
diff "/var/cache/systemd/home/blob-user/$1" "$2"
diff "/var/cache/systemd/home/blob-user/$1" "/home/blob-user/.identity-blob/$1"
diff "/var/cache/systemd/home/blob-user/$1" "$2"
diff "/var/cache/systemd/home/blob-user/$1" "/home/blob-user/.identity-blob/$1"
}
mkdir /tmp/blob1 /tmp/blob2
@@ -640,6 +632,7 @@ EOF
homedsshtest@localhost env
wait_for_state homedsshtest inactive
homectl remove homedsshtest
fi
NEWPASSWORD=hunter4711 homectl create aliastest --storage=directory --alias=aliastest2 --alias=aliastest3 --realm=myrealm
@@ -665,6 +658,8 @@ getent passwd aliastest@myrealm
getent passwd aliastest2@myrealm
getent passwd aliastest3@myrealm
homectl remove aliastest
NEWPASSWORD=quux homectl create tmpfsquota --storage=subvolume --dev-shm-limit=50K --tmp-limit=50K -P
for p in /dev/shm /tmp; do
if findmnt -n -o options "$p" | grep -q usrquota; then

View File

@@ -1186,6 +1186,12 @@ EOF
helper_check_device_units
# Cleanup
mdadm -v --stop "$raid_dev"
# Clear superblocks to make the MD device will not be restarted even if the VM is restarted.
# This is a workaround for issue #38240.
mdadm -v --zero-superblock --force "${devices[@]}"
udevadm settle --timeout=30
# Check if all expected symlinks were removed after the cleanup
udevadm wait --settle --timeout=30 --removed "${expected_symlinks[@]}"
helper_check_device_units
@@ -1243,6 +1249,12 @@ testcase_mdadm_lvm() {
# Cleanup
lvm vgchange -an "$vgroup"
mdadm -v --stop "$raid_dev"
# Clear superblocks to make the MD device will not be restarted even if the VM is restarted.
# This is a workaround for issue #38240.
mdadm -v --zero-superblock --force "${devices[@]}"
udevadm settle --timeout=30
# Check if all expected symlinks were removed after the cleanup
udevadm wait --settle --timeout=30 --removed "${expected_symlinks[@]}"
helper_check_device_units