Skip to content

Commit

Permalink
tests/storage-vm: create extra part with random data
Browse files Browse the repository at this point in the history
Compare the extra part content through `lxc copy` operations

Signed-off-by: Simon Deziel <[email protected]>
  • Loading branch information
simondeziel committed Sep 24, 2024
1 parent 18514a8 commit 6a893e1
Showing 1 changed file with 60 additions and 14 deletions.
74 changes: 60 additions & 14 deletions tests/storage-vm
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,42 @@ for poolDriver in $poolDriverList; do
V1_EFI_PART="$(lxc exec v1 -- fdisk --list /dev/sda | awk '/EFI System$/ {print $1}')"
lxc exec v1 -- umount "${V1_EFI_PART}"
V1_EFI_SHA256SUM="$(lxc exec v1 -- sha256sum "${V1_EFI_PART}")"

echo "==> Deactivate cloud-init after initial boot to avoid rootfs resize/growpart"
lxc exec v1 -- systemctl mask --now cloud-init.service

# Note the original size of the rootfs partition.
ROOTFS_SIZE_ORIG="$(lxc exec v1 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root-part1)"

lxc exec v1 -- sync
lxc stop -f v1
if [ "${poolDriver}" != "powerflex" ]; then
echo "==> Increasing VM root disk size for next boot (4GiB)"
lxc config device override v1 root size=4GiB
else
echo "==> Increasing VM root disk size for next boot (16GiB)"
lxc config device override v1 root size=16GiB
fi
lxc start v1
waitInstanceReady v1

echo "==> Verify that the rootfs partition size has not changed after the disk resize"
ROOTFS_SIZE_NEW="$(lxc exec v1 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root-part1)"
[ "${ROOTFS_SIZE_ORIG}" = "${ROOTFS_SIZE_NEW}" ]

echo "==> Reactivate cloud-init"
lxc exec v1 -- systemctl unmask cloud-init.service

echo "==> Create extra partition"
echo ";" | lxc exec v1 -- sfdisk /dev/sda --force --no-reread --no-tell-kernel --append
lxc exec v1 -- partx -u /dev/sda

echo "==> Write random data to extra partition"
lxc exec v1 -- dd if=/dev/urandom of=/dev/sda2 bs=16M count=1
V1_SDA2_SHA256_ORIG="$(lxc exec v1 -- dd if=/dev/sda2 bs=16M count=1 | sha256sum)"

lxc exec v1 -- sync
lxc stop -f v1
echo "==> Copy to different storage pool with same driver and check size"
if [ "${poolDriver}" = "dir" ] || [ "${poolDriver}" = "ceph" ]; then
lxc storage create "${poolName}-2" "${poolDriver}"
Expand All @@ -433,6 +467,9 @@ for poolDriver in $poolDriverList; do
waitInstanceReady v2
lxc info v2

echo "==> Read random data from extra partition"
[ "${V1_SDA2_SHA256_ORIG}" = "$(lxc exec v2 -- dd if=/dev/sda2 bs=16M count=1 | sha256sum)" ]

echo "==> Check the EFI partition number and content did not change after the volume size override"
V2_EFI_PART="$(lxc exec v2 -- fdisk --list /dev/sda | awk '/EFI System$/ {print $1}')"
lxc exec v2 -- umount "${V2_EFI_PART}"
Expand All @@ -452,11 +489,11 @@ for poolDriver in $poolDriverList; do
[ "$(lxc exec v2 -- fdisk --list /dev/sda 2>&1 >/dev/null)" = "" ]

if [ "${poolDriver}" != "powerflex" ]; then
echo "==> Checking copied VM root disk size is 3584MiB"
[ "$(($(lxc exec v2 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root) / MiB))" -eq "3584" ]
echo "==> Checking copied VM root disk size is 4GiB"
[ "$(($(lxc exec v2 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root) / GiB))" -eq "4" ]
else
echo "==> Checking copied VM root disk size is 8GiB"
[ "$(($(lxc exec v2 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root) / GiB))" -eq "8" ]
echo "==> Checking copied VM root disk size is 16GiB"
[ "$(($(lxc exec v2 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root) / GiB))" -eq "16" ]
fi
lxc delete -f v2
lxc storage delete "${poolName}-2"
Expand All @@ -473,27 +510,33 @@ for poolDriver in $poolDriverList; do
waitInstanceReady v2
lxc info v2

echo "==> Read random data from extra partition"
[ "${V1_SDA2_SHA256_ORIG}" = "$(lxc exec v2 -- dd if=/dev/sda2 bs=16M count=1 | sha256sum)" ]

if [ "${poolDriver}" != "powerflex" ]; then
echo "==> Checking copied VM root disk size is 3584MiB"
[ "$(($(lxc exec v2 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root) / MiB))" -eq "3584" ]
echo "==> Checking copied VM root disk size is 4GiB"
[ "$(($(lxc exec v2 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root) / GiB))" -eq "4" ]
else
echo "==> Checking copied VM root disk size is 8GiB"
[ "$(($(lxc exec v2 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root) / GiB))" -eq "8" ]
echo "==> Checking copied VM root disk size is 16GiB"
[ "$(($(lxc exec v2 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root) / GiB))" -eq "16" ]
fi
lxc delete -f v2

if [ "${poolDriver}" != "powerflex" ]; then
echo "==> Override volume size from profile (4GiB) to 5GiB and copy to different storage pool"
lxc config device override v1 root size=5GiB
lxc config device set v1 root size=5GiB
else
echo "==> Override volume size from profile (8GiB) to 16GiB and copy to different storage pool"
lxc config device override v1 root size=16GiB
echo "==> Override volume size from profile (16GiB) to 24GiB and copy to different storage pool"
lxc config device set v1 root size=24GiB
fi
lxc copy v1 v2 -s "${poolName}-${dstPoolDriver}"
lxc start v2
waitInstanceReady v2
lxc info v2

echo "==> Read random data from extra partition"
[ "${V1_SDA2_SHA256_ORIG}" = "$(lxc exec v2 -- dd if=/dev/sda2 bs=16M count=1 | sha256sum)" ]

echo "==> Check the EFI partition number and content did not change after the volume size override"
V2_EFI_PART="$(lxc exec v2 -- fdisk --list /dev/sda | awk '/EFI System$/ {print $1}')"
lxc exec v2 -- umount "${V2_EFI_PART}"
Expand All @@ -516,16 +559,16 @@ for poolDriver in $poolDriverList; do
echo "==> Checking copied VM root disk size is 5GiB"
[ "$(($(lxc exec v2 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root) / GiB))" -eq "5" ]
else
echo "==> Checking copied VM root disk size is 16GiB"
[ "$(($(lxc exec v2 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root) / GiB))" -eq "16" ]
echo "==> Checking copied VM root disk size is 24GiB"
[ "$(($(lxc exec v2 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root) / GiB))" -eq "24" ]
fi
lxc delete -f v2
lxc storage delete "${poolName}-${dstPoolDriver}"

if [ "${poolDriver}" != "powerflex" ]; then
echo "==> Publishing larger VM (5GiB)"
else
echo "==> Publishing larger VM (16GiB)"
echo "==> Publishing larger VM (24GiB)"
fi
lxc publish v1 --alias vmbig
lxc delete -f v1
Expand All @@ -545,6 +588,9 @@ for poolDriver in $poolDriverList; do
waitInstanceReady v1
lxc info v1

echo "==> Read random data from extra partition"
[ "${V1_SDA2_SHA256_ORIG}" = "$(lxc exec v1 -- dd if=/dev/sda2 bs=16M count=1 | sha256sum)" ]

if [ "${poolDriver}" != "powerflex" ]; then
echo "==> Checking new VM root disk size has default volume size of 10GiB"
[ "$(($(lxc exec v1 -- blockdev --getsize64 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_root) / GiB))" -eq "10" ]
Expand Down

0 comments on commit 6a893e1

Please sign in to comment.