From 46f84674a7e8c93694b4a4cab13199774765cd73 Mon Sep 17 00:00:00 2001 From: hamistao Date: Thu, 5 Sep 2024 22:30:20 -0300 Subject: [PATCH 1/6] tests: Add file for general VM tests Signed-off-by: hamistao --- tests/vm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/vm diff --git a/tests/vm b/tests/vm new file mode 100644 index 000000000..ab251c3fb --- /dev/null +++ b/tests/vm @@ -0,0 +1,23 @@ +#!/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 + +# Cleanup +lxc delete -f vm1 + +# shellcheck disable=SC2034 +FAIL=0 From a2a98ef5768189786b7ab29a0268d4dab66d68af Mon Sep 17 00:00:00 2001 From: hamistao Date: Fri, 13 Sep 2024 10:27:17 -0300 Subject: [PATCH 2/6] github: Add `vm` tests to `tests.yml` Signed-off-by: hamistao --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) 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: From 54ccd218c87ee98405bfea57b71e3f9577acccff Mon Sep 17 00:00:00 2001 From: hamistao Date: Thu, 5 Sep 2024 22:31:38 -0300 Subject: [PATCH 3/6] tests/vm: Add test for VM disconnection during `lxc exec` Signed-off-by: hamistao --- tests/vm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/vm b/tests/vm index ab251c3fb..eb8dcf248 100644 --- a/tests/vm +++ b/tests/vm @@ -16,6 +16,25 @@ 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 From a364513b6494c209b2aa06d8dbf57478184f08ed Mon Sep 17 00:00:00 2001 From: hamistao Date: Mon, 9 Sep 2024 12:00:00 -0300 Subject: [PATCH 4/6] tests/container: Test container clean stop Signed-off-by: hamistao --- tests/container | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/container b/tests/container index f2d35535b..267c55fa6 100755 --- a/tests/container +++ b/tests/container @@ -147,5 +147,13 @@ 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 + # shellcheck disable=SC2034 FAIL=0 From 8637cbdd2e31ab25822bc3d4f65518d4493800bb Mon Sep 17 00:00:00 2001 From: hamistao Date: Fri, 6 Sep 2024 00:18:16 -0300 Subject: [PATCH 5/6] tests/container: Test container disconnect during exec Signed-off-by: hamistao --- tests/container | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/container b/tests/container index 267c55fa6..ff5a6845c 100755 --- a/tests/container +++ b/tests/container @@ -147,7 +147,6 @@ 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 @@ -155,5 +154,23 @@ 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 From 8e4438c80ead974ef87f41377c70118c1e95f56d Mon Sep 17 00:00:00 2001 From: hamistao Date: Thu, 12 Sep 2024 06:22:16 -0300 Subject: [PATCH 6/6] tests/container: Avoid `lxc exec` with guest not ready Signed-off-by: hamistao --- tests/container | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/container b/tests/container index ff5a6845c..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