Skip to content

Commit

Permalink
test: Check that we can still access the target dir if it hasn''t bee…
Browse files Browse the repository at this point in the history
…n created by lxd

Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Mar 27, 2024
1 parent 9c52f10 commit 67f46b6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/suites/container_devices_disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,41 @@ test_container_devices_disk_shift() {
[ "$(lxc exec foo-isol1 -- stat /mnt/a -c '%u:%g')" = "123:456" ] || false
[ "$(lxc exec foo-isol2 -- stat /mnt/a -c '%u:%g')" = "123:456" ] || false

mkdir -p "${TEST_DIR}/empty-dir"
lxc exec foo -- mkdir /opt
lxc config device add foo empty-dir disk source="${TEST_DIR}/empty-dir" path=/opt
# Check that no `volatile.<deviceName>.last_state.created` has been set.
if [ -n "$(lxc config get foo volatile.empty-dir.last_state.created)" ]; then
echo "==> volatile.<deviceName>.last_state.created should not be set"
false
fi

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

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

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

lxc config device add foo empty-dir disk source="${TEST_DIR}/empty-dir" path=/tmp/new-dir # /tmp/new-dir is created by LXD.
# Check that the volatile.<deviceName>.last_state.created is set.
targetPath=$(lxc config get foo 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 foo empty-dir
! lxc exec foo -- stat /tmp/new-dir || false # /tmp/new-dir is removed as it was created by LXD.
rm -rf "${TEST_DIR}/empty-dir"

lxc delete -f foo-priv foo-isol1 foo-isol2
lxc config device remove foo shifted
lxc storage volume delete "${POOL}" foo-shift
Expand Down

0 comments on commit 67f46b6

Please sign in to comment.