diff --git a/test/units/TEST-87-AUX-UTILS-VM.bind-volume.sh b/test/units/TEST-87-AUX-UTILS-VM.bind-volume.sh index 6339e39093..d9437d3325 100755 --- a/test/units/TEST-87-AUX-UTILS-VM.bind-volume.sh +++ b/test/units/TEST-87-AUX-UTILS-VM.bind-volume.sh @@ -90,24 +90,6 @@ mke2fs -t ext4 -q -d "$WORKDIR/rootfs" "$WORKDIR/root.raw" BOOT_VOL="test-bind-volume-boot-$$" RUNTIME_VOL="test-bind-volume-runtime-$$" -wait_for_machine() { - local machine="$1" pid="$2" log="$3" - timeout 30 bash -c " - while ! machinectl list --no-legend 2>/dev/null | grep >/dev/null '$machine'; do - if ! kill -0 $pid 2>/dev/null; then - echo 'vmspawn exited before machine registration' - cat '$log' - exit 77 - fi - sleep .5 - done - " || { - local rc=$? - if [[ $rc -eq 77 ]]; then exit 0; fi - exit "$rc" - } -} - # --- Boot the VM with one boot-time bind-volume --- MACHINE="test-bind-volume-$$" systemd-vmspawn \ diff --git a/test/units/TEST-87-AUX-UTILS-VM.replace-storage.sh b/test/units/TEST-87-AUX-UTILS-VM.replace-storage.sh index 22ff57adf8..67c4cbacef 100755 --- a/test/units/TEST-87-AUX-UTILS-VM.replace-storage.sh +++ b/test/units/TEST-87-AUX-UTILS-VM.replace-storage.sh @@ -92,24 +92,6 @@ RUNTIME_VOL="test-replace-storage-runtime-$$" truncate -s 32M "$WORKDIR/new-backing-1.raw" truncate -s 32M "$WORKDIR/new-backing-2.raw" -wait_for_machine() { - local machine="$1" pid="$2" log="$3" - timeout 30 bash -c " - while ! machinectl list --no-legend 2>/dev/null | grep >/dev/null '$machine'; do - if ! kill -0 $pid 2>/dev/null; then - echo 'vmspawn exited before machine registration' - cat '$log' - exit 77 - fi - sleep .5 - done - " || { - local rc=$? - if [[ $rc -eq 77 ]]; then exit 0; fi - exit "$rc" - } -} - MACHINE="test-replace-storage-$$" systemd-vmspawn \ --machine="$MACHINE" \ diff --git a/test/units/TEST-87-AUX-UTILS-VM.vmspawn-drives.sh b/test/units/TEST-87-AUX-UTILS-VM.vmspawn-drives.sh index 31b3bf8b51..cbdba03200 100755 --- a/test/units/TEST-87-AUX-UTILS-VM.vmspawn-drives.sh +++ b/test/units/TEST-87-AUX-UTILS-VM.vmspawn-drives.sh @@ -83,20 +83,6 @@ mke2fs -t ext4 -q -d "$WORKDIR/rootfs" "$WORKDIR/root.raw" truncate -s 64M "$WORKDIR/extra1.raw" truncate -s 32M "$WORKDIR/extra2.raw" -wait_for_machine() { - local machine="$1" pid="$2" log="$3" - timeout 30 bash -c " - while ! machinectl list --no-legend 2>/dev/null | grep >/dev/null '$machine'; do - if ! kill -0 $pid 2>/dev/null; then - echo 'vmspawn exited before machine registration' - cat '$log' - exit 1 - fi - sleep .5 - done - " -} - # --- Test 1: Multi-drive setup (root + 2 extra drives) --- # Verifies that --image with multiple --extra-drive flags works with the async # QMP pipeline. Three drives means three fdset allocations, three blockdev-add diff --git a/test/units/TEST-87-AUX-UTILS-VM.vmspawn.sh b/test/units/TEST-87-AUX-UTILS-VM.vmspawn.sh index 0a33cbd60c..74071ec3af 100755 --- a/test/units/TEST-87-AUX-UTILS-VM.vmspawn.sh +++ b/test/units/TEST-87-AUX-UTILS-VM.vmspawn.sh @@ -77,30 +77,6 @@ exec sleep infinity EOF chmod +x "$WORKDIR/root/sbin/init" -# Wait for a vmspawn machine to register with machined. -# Skips the test gracefully if vmspawn fails due to missing vhost-user-fs support (nested VM). -wait_for_machine() { - local machine="$1" pid="$2" log="$3" - timeout 30 bash -c " - while ! machinectl list --no-legend 2>/dev/null | grep >/dev/null '$machine'; do - if ! kill -0 $pid 2>/dev/null; then - if grep >/dev/null 'virtiofs.*QMP\|vhost-user-fs-pci' '$log'; then - echo 'vhost-user-fs not supported (nested VM?), skipping' - exit 77 - fi - echo 'vmspawn exited before registering' - cat '$log' - exit 1 - fi - sleep .5 - done - " || { - local rc=$? - if [[ $rc -eq 77 ]]; then exit 0; fi - exit "$rc" - } -} - # Launch vmspawn in the background with direct kernel boot and headless console. systemd-vmspawn \ --machine="$MACHINE" \ diff --git a/test/units/util.sh b/test/units/util.sh index 14bc29af11..265f180098 100755 --- a/test/units/util.sh +++ b/test/units/util.sh @@ -576,3 +576,28 @@ find_qemu_binary() { command -v "qemu-system-$arch" >/dev/null 2>&1 } + +# Waits for a systemd-vmspawn machine to register with machined. If vmspawn bailed out because +# vhost-user-fs isn't available (e.g. inside a nested VM) the test is skipped gracefully; any other +# early vmspawn exit is treated as a failure. Args: machine name, vmspawn PID, vmspawn console log. +wait_for_machine() { + local machine="$1" pid="$2" log="$3" + timeout 30 bash -c " + while ! machinectl list --no-legend 2>/dev/null | grep >/dev/null '$machine'; do + if ! kill -0 $pid 2>/dev/null; then + if grep >/dev/null 'virtiofs.*QMP\|vhost-user-fs-pci' '$log'; then + echo 'vhost-user-fs not supported (nested VM?), skipping' + exit 77 + fi + echo 'vmspawn exited before registering' + cat '$log' + exit 1 + fi + sleep .5 + done + " || { + local rc=$? + if [[ $rc -eq 77 ]]; then exit 0; fi + exit "$rc" + } +}