test: move wait_for_machine into util.sh

The vmspawn-based TEST-87 subtests each carried a near-identical
wait_for_machine() helper. Move it into util.sh so it can be shared.
The shared version is the vmspawn.sh variant, which tells missing
vhost-user-fs (nested VM) apart from any other early exit. As a result,
bin-volume and replace-storage now use that distinction too instead of
treating every early exit alike. vmspawn-drives is unaffected of this,
its --image-only console never matches the vhost-user-fs marker, so an
early exit still fails.

Signed-off-by: Paul Meyer <katexochen0@gmail.com>
This commit is contained in:
Paul Meyer
2026-08-14 16:00:49 +02:00
parent 77b9a626ce
commit c346b82a53
5 changed files with 25 additions and 74 deletions
@@ -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 \
@@ -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" \
@@ -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
@@ -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" \
+25
View File
@@ -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"
}
}