From d293d77c667f6b1017e6be742064367bbf9e6104 Mon Sep 17 00:00:00 2001 From: Mark Laing Date: Tue, 6 Aug 2024 08:52:21 +0100 Subject: [PATCH 1/2] bin: Allow sideloading of LXD agent. Signed-off-by: Mark Laing --- bin/helpers | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/helpers b/bin/helpers index b6b10af1c..db9352b3f 100644 --- a/bin/helpers +++ b/bin/helpers @@ -168,12 +168,19 @@ install_lxd() ( touch ~/snap/lxd/common/config/config.yml if [ -n "${LXD_SIDELOAD_PATH:-}" ]; then - systemctl stop snap.lxd.daemon cp "${LXD_SIDELOAD_PATH}" /var/snap/lxd/common/lxd.debug if [ "$start_daemon" = "true" ]; then systemctl start snap.lxd.daemon fi fi + + if [ -n "${LXD_AGENT_SIDELOAD_PATH:-}" ]; then + mount --bind "${LXD_AGENT_SIDELOAD_PATH}" /snap/lxd/current/bin/lxd-agent + systemctl restart snap.lxd.daemon + if [ "$start_daemon" = "true" ]; then + systemctl start snap.lxd.daemon + fi + fi ) # hasNeededAPIExtension: check if LXD supports the needed extension. From 8b5a55f4861dd4ec59006718b87df670b123bf40 Mon Sep 17 00:00:00 2001 From: Mark Laing Date: Tue, 6 Aug 2024 08:52:48 +0100 Subject: [PATCH 2/2] tests: Test image export over devlxd for VMs. Signed-off-by: Mark Laing --- tests/devlxd-vm | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/devlxd-vm b/tests/devlxd-vm index b34902280..4037423dc 100755 --- a/tests/devlxd-vm +++ b/tests/devlxd-vm @@ -11,7 +11,7 @@ install_lxd lxc network create lxdbr0 lxc profile device add default eth0 nic network=lxdbr0 -IMAGE="${TEST_IMG:-ubuntu-daily:24.04}" +IMAGE="${TEST_IMG:-ubuntu-minimal-daily:24.04}" poolName="vmpool$$" poolDriver=dir @@ -20,7 +20,12 @@ echo "==> Create storage pool using driver ${poolDriver}" lxc storage create "${poolName}" "${poolDriver}" echo "==> Create VM and boot" -lxc launch "${IMAGE}" v1 --vm -s "${poolName}" +if hasNeededAPIExtension devlxd_images_vm; then + lxc launch "${IMAGE}" v1 --vm -s "${poolName}" -c security.devlxd.images=true +else + lxc launch "${IMAGE}" v1 --vm -s "${poolName}" +fi + waitInstanceReady v1 lxc info v1 @@ -94,10 +99,35 @@ waitInstanceBooted v1 lxc exec v1 -- snap remove --purge lxd || true lxc exec v1 -- snap install lxd --channel="${LXD_SNAP_CHANNEL}" lxc exec v1 -- /snap/bin/lxd init --auto +if [ -n "${LXD_SIDELOAD_PATH:-}" ]; then + lxc file push "${LXD_SIDELOAD_PATH}" v1/var/snap/lxd/common/lxd.debug + lxc exec v1 -- systemctl restart snap.lxd.daemon +fi +if [ -n "${LXD_AGENT_SIDELOAD_PATH:-}" ]; then + lxc file push "${LXD_AGENT_SIDELOAD_PATH}" "v1/root/$(basename "${LXD_AGENT_SIDELOAD_PATH}")" + lxc exec v1 -- mount --bind "$(basename "${LXD_AGENT_SIDELOAD_PATH}")" /snap/lxd/current/bin/lxd-agent + lxc exec v1 -- systemctl restart snap.lxd.daemon +fi + +monitorPID="" +if hasNeededAPIExtension devlxd_images_vm; then + lxc monitor --type lifecycle --format json > monitor.json 2>&1 & + monitorPID="${!}" +fi + lxc exec v1 -- /snap/bin/lxc launch "${TEST_IMG:-ubuntu-minimal-daily:24.04}" v1v1 --vm sleep 30 lxc exec v1 -- /snap/bin/lxc info v1v1 | grep -F RUNNING +if hasNeededAPIExtension devlxd_images_vm; then + kill -9 "${monitorPID}" + + # If the guest retrieved the image from the host, the host should emit an "image-retrieved" lifecycle event. The + # requestor address tells us that this was definitely the guest. + [ "$(grep -wF 'image-retrieved' monitor.json | jq -r '.metadata.requestor.address')" = "@devlxd" ] + rm monitor.json +fi + echo "==> Deleting VM" lxc delete -f v1 lxc profile device remove default eth0