diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d8cfb5dc8..8fe1fe06e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -112,6 +112,7 @@ jobs: - "storage-vm zfs" - storage-volumes-vm - tpm-vm + - vm - vm-migration - vm-nesting include: diff --git a/tests/container b/tests/container index f2d35535b..f0e9be45c 100755 --- a/tests/container +++ b/tests/container @@ -139,6 +139,7 @@ IMAGE="ubuntu-minimal-daily:24.04" echo "==> check that we can mount devpts and procfs in unprivileged container" lxc launch "${IMAGE}" u1 +waitInstanceBooted u1 lxc exec u1 -- mkdir /root/proc lxc exec u1 -- mount -t proc proc /root/proc lxc exec u1 -- mkdir /root/devpts @@ -147,5 +148,30 @@ lxc exec u1 -- mkdir /root/sys lxc exec u1 -- mount -t sysfs sysfs /root/sys lxc delete -f u1 +echo "==> Try cleanly stopping a container" +lxc launch "${IMAGE}" c1 +waitInstanceBooted c1 +lxc stop c1 +lxc start c1 +waitInstanceBooted c1 + +echo "==> Test exit codes when container disconnects during lxc exec" + +# Try disconnecting a container stopping forcefully and gracefully to make sure they differ appropriately. +(sleep 1 && lxc stop -f c1) & +lxc exec c1 -- sleep 10 || exitCode=$? +[ "${exitCode:-0}" -eq 137 ] + +wait $! +lxc start c1 +waitInstanceBooted c1 +(sleep 1 && lxc stop c1) & +lxc exec c1 -- sleep 10 || exitCode=$? +# Both 129 and 143 have been seen and both make sense here. +[ "${exitCode:-0}" -eq 129 ] || [ "${exitCode:-0}" -eq 143 ] + +wait $! +lxc delete -f c1 + # shellcheck disable=SC2034 FAIL=0 diff --git a/tests/vm b/tests/vm new file mode 100644 index 000000000..eb8dcf248 --- /dev/null +++ b/tests/vm @@ -0,0 +1,42 @@ +#!/bin/bash +set -eux + +# Install LXD +install_lxd + +# Configure LXD +lxd init --auto + +IMAGE="${TEST_IMG:-ubuntu-minimal-daily:24.04}" + +# Launch test instance +lxc launch "${IMAGE}" vm1 --vm +waitInstanceBooted vm1 + +echo "==> Test cleanly stopping a VM" +lxc stop vm1 + +if ! echo "${LXD_SNAP_CHANNEL}" | grep -qE '^4\.0/'; then + echo "==> Test lxc exec exit code upon VM disconnection due to a stop/reboot" + lxc start vm1 + waitInstanceBooted vm1 + + # Try disconnecting a VM stopping forcefully and gracefully to make sure they match. + (sleep 1 && lxc stop -f vm1) & + lxc exec vm1 -- sleep 10 || exitCode=$? + [ "${exitCode:-0}" -eq 129 ] + + wait $! + lxc start vm1 + waitInstanceBooted vm1 + (sleep 1 && lxc stop vm1) & + lxc exec vm1 -- sleep 10 || exitCode=$? + [ "${exitCode:-0}" -eq 129 ] + wait $! +fi + +# Cleanup +lxc delete -f vm1 + +# shellcheck disable=SC2034 +FAIL=0