Skip to content

Commit

Permalink
tests/storage-vm: Test that we avoid deleting existing target directo…
Browse files Browse the repository at this point in the history
…ries not created by LXD when unmounting disks

Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Feb 27, 2024
1 parent b04148e commit b97d789
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/storage-vm
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,49 @@ for poolDriver in $poolDriverList; do
echo "==> Deleting VM"
lxc delete -f v1

if hasNeededAPIExtension disk_state_created; then
# Check that we don't remove an existing target directory when unmounting a disk device if the original dir hasn't been created by LXD
echo "==> Avoid deleting existing target directories not created by LXD when unmounting disks."
mkdir -p "/tmp/lxd-test-${poolName}/empty-dir"
lxc launch "${TEST_IMG:-ubuntu-minimal-daily:22.04}" v1 --vm -s "${poolName}"
waitInstanceReady v1

! lxc exec v1 -- mkdir /opt || false # The directory already exists and is not created by LXD.
lxc config device add v1 empty-dir disk source="/tmp/lxd-test-${poolName}/empty-dir" path=/opt
# Check that no `volatile.<deviceName>.last_state.created` has been set.
if [ -n "$(lxc config get v1 volatile.empty-dir.last_state.created)"]; then
echo "==> volatile.<deviceName>.last_state.created should not be set"
false
fi

lxc config device remove v1 empty-dir
lxc exec v1 -- stat /opt # /opt is not removed as it was not created by LXD.

lxc exec v1 -- mkdir -p /tmp/empty-dir # Create a new directory to check that it is not removed when unmounting the disk.
lxc config device add v1 empty-dir disk source="/tmp/lxd-test-${poolName}/empty-dir" path=/tmp/empty-dir
# Check that no `volatile.<deviceName>.last_state.created` has been set.
if [ -n "$(lxc config get v1 volatile.empty-dir.last_state.created)"]; then
echo "==> volatile.<deviceName>.last_state.created should not be set"
false
fi

lxc config device remove v1 empty-dir
lxc exec v1 -- stat /tmp/empty-dir

lxc config device add v1 empty-dir disk source="/tmp/lxd-test-${poolName}/empty-dir" path=/tmp/new-dir
# Check that the volatile.<deviceName>.last_state.created is set.
targetPath=$(lxc config get v1 volatile.empty-dir.last_state.created)
if [ "${targetPath}" != "/tmp/new-dir" ]; then
echo "==> volatile.<deviceName>.last_state.created is not set to the correct value"
false
fi

lxc config device remove v1 empty-dir
! lxc exec v1 -- stat /tmp/new-dir || false # /tmp/new-dir is removed as it was created by LXD.

lxc delete -f v1
rmdir "/tmp/lxd-test-${poolName}/empty-dir"
fi
# Create directory with a file for directory disk tests.
mkdir "/tmp/lxd-test-${poolName}"

Expand Down

0 comments on commit b97d789

Please sign in to comment.