Skip to content

Commit

Permalink
tests: Check that volume is functional after live migration.
Browse files Browse the repository at this point in the history
Changes are as follows:
- Increases the memory of the nested VM to 1GiB (the parent VMs have
  2GiB each).
- Waits indefinitely for the nested VM to start up by checking the
  number of process via `lxc info`.
- Formats the volume with ext4, mounts it, and adds a file.
- Checks that the file is present and has the same contents after live
  migrating the instance.

Signed-off-by: Mark Laing <[email protected]>
  • Loading branch information
markylaing committed Aug 6, 2024
1 parent 4e069f5 commit 6ef9d52
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions tests/vm-migration
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ for _ in $(seq 60); do
fi
done

# Launch two instances for our LXD cluster and wait for them to be ready.
lxc launch "${TEST_IMG:-ubuntu-minimal-daily:24.04}" member1 --vm -c limits.memory=2GiB
lxc launch "${TEST_IMG:-ubuntu-minimal-daily:24.04}" member2 --vm -c limits.memory=2GiB
# Launch two instances for our LXD cluster and wait for them to be ready. If the host supports `devlxd_images_vm` then
# set `security.devlxd.images=true` so that we don't have to download the image again.
if hasNeededAPIExtension devlxd_images_vm; then
lxc launch "${TEST_IMG:-ubuntu-minimal-daily:24.04}" member1 --vm -c limits.memory=2GiB -c security.devlxd.images=true
lxc launch "${TEST_IMG:-ubuntu-minimal-daily:24.04}" member2 --vm -c limits.memory=2GiB -c security.devlxd.images=true
else
lxc launch "${TEST_IMG:-ubuntu-minimal-daily:24.04}" member1 --vm -c limits.memory=2GiB
lxc launch "${TEST_IMG:-ubuntu-minimal-daily:24.04}" member2 --vm -c limits.memory=2GiB
fi

waitInstanceReady member1
waitInstanceReady member2
# shellcheck disable=SC3044 # Ignore "declare is undefined" shellcheck error.
Expand All @@ -71,6 +78,11 @@ if [ -n "${LXD_SIDELOAD_PATH:-}" ]; then
lxc file push "${LXD_SIDELOAD_PATH}" member1/var/snap/lxd/common/lxd.debug
lxc exec member1 -- systemctl restart snap.lxd.daemon
fi
if [ -n "${LXD_AGENT_SIDELOAD_PATH:-}" ]; then
lxc file push "${LXD_AGENT_SIDELOAD_PATH}" "member1/root/$(basename "${LXD_AGENT_SIDELOAD_PATH}")"
lxc exec member1 -- mount --bind "$(basename "${LXD_AGENT_SIDELOAD_PATH}")" /snap/lxd/current/bin/lxd-agent
lxc exec member1 -- systemctl restart snap.lxd.daemon
fi

# Initialise and configure LXD in the first member.
lxc exec member1 -- lxd init --auto
Expand All @@ -87,6 +99,11 @@ if [ -n "${LXD_SIDELOAD_PATH:-}" ]; then
lxc file push "${LXD_SIDELOAD_PATH}" member2/var/snap/lxd/common/lxd.debug
lxc exec member2 -- systemctl restart snap.lxd.daemon
fi
if [ -n "${LXD_AGENT_SIDELOAD_PATH:-}" ]; then
lxc file push "${LXD_AGENT_SIDELOAD_PATH}" "member2/root/$(basename "${LXD_AGENT_SIDELOAD_PATH}")"
lxc exec member2 -- mount --bind "$(basename "${LXD_AGENT_SIDELOAD_PATH}")" /snap/lxd/current/bin/lxd-agent
lxc exec member2 -- systemctl restart snap.lxd.daemon
fi

# Create a preseed file for member2 to join member1.
member2Address="$(lxc query /1.0/instances/member2?recursion=2 | jq -r ".state.network.enp5s0.addresses[0].address")"
Expand Down Expand Up @@ -119,15 +136,33 @@ lxc exec member1 -- lxc storage create ceph ceph
lxc exec member1 -- lxc storage volume create ceph vol1 --type=block size=500MiB

# Create a VM in the cluster, on member1.
lxc exec member1 -- lxc init "${TEST_IMG:-ubuntu-minimal-daily:24.04}" v1 --vm --storage ceph --target member1 -c migration.stateful=true -c limits.memory=512MiB
lxc exec member1 -- lxc init "${TEST_IMG:-ubuntu-minimal-daily:24.04}" v1 --vm --storage ceph --target member1 -c migration.stateful=true -c limits.memory=1GiB

# Add vol1 as a disk device to the VM.
lxc exec member1 -- lxc config device add v1 vol1-disk disk pool=ceph source=vol1

# Start the VM.
lxc exec member1 -- lxc start v1
sleep 60

# Wait for a long time for it to boot (doubly nested VM takes a while).
while [ "$(lxc exec member1 -- sh -c "lxc info v1 | grep -F 'Processes:' | cut -d':' -f2 | tr -d '[:blank:]'")" -le 1 ]; do
sleep 30
done

# vol1 should be available as /dev/sdb. Format it as ext4. Then mount it and create a file.
lxc exec member1 -- sh -c "lxc exec v1 -- mkfs -t ext4 /dev/sdb"
lxc exec member1 -- sh -c "lxc exec v1 -- mkdir /mnt/vol1"
lxc exec member1 -- sh -c "lxc exec v1 -- mount -t auto /dev/sdb /mnt/vol1"
lxc exec member1 -- sh -c "lxc exec v1 -- sh -c 'echo foo > /mnt/vol1/bar'"
lxc exec member1 -- lxc move v1 --target member2

# The VM is slow. So the agent isn't immediately available after the live migration.
while [ "$(lxc exec member2 -- sh -c "lxc info v1 | grep -F 'Processes:' | cut -d':' -f2 | tr -d '[:blank:]'")" -le 1 ]; do
sleep 5
done

# The volume should be functional, still mounted, and the file we created should still be there with the same contents.
[ "$(lxc exec member2 -- sh -c "lxc exec v1 -- cat /mnt/vol1/bar")" = "foo" ]

# shellcheck disable=SC2034
FAIL=0

0 comments on commit 6ef9d52

Please sign in to comment.