From 2cca3315c4c90de0acabe748c762dc6d9c33e829 Mon Sep 17 00:00:00 2001 From: Philip Meulengracht Date: Wed, 2 Oct 2024 14:23:38 +0200 Subject: [PATCH] tests: test multiple volumes --- tests/lib/nested.sh | 27 ++++++++++++++----- .../install-volume-assignment/task.yaml | 27 +++++++++++++++---- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/tests/lib/nested.sh b/tests/lib/nested.sh index bf0c0ab14f6..9537f0335ed 100755 --- a/tests/lib/nested.sh +++ b/tests/lib/nested.sh @@ -454,7 +454,7 @@ nested_cleanup_env() { rm -rf "$(nested_get_extra_snaps_path)" } -nested_get_image_name() { +nested_get_image_name_base() { local TYPE="$1" local SOURCE="${NESTED_CORE_CHANNEL}" local NAME="${NESTED_IMAGE_ID:-generic}" @@ -476,7 +476,12 @@ nested_get_image_name() { if [ "$(nested_get_extra_snaps | wc -l)" != "0" ]; then SOURCE="custom" fi - echo "ubuntu-${TYPE}-${VERSION}-${SOURCE}-${NAME}.img" + echo "ubuntu-${TYPE}-${VERSION}-${SOURCE}-${NAME}" +} + +nested_get_image_name() { + local BASE_NAME="$(nested_get_image_name_base $1)" + echo "${BASE_NAME}.img" } nested_is_generic_image() { @@ -914,13 +919,21 @@ nested_create_core_vm() { # ubuntu-image dropped the --output parameter, so we have to rename # the image ourselves, the images are named after volumes listed in # gadget.yaml + local IMAGE_BASE_NAME="$(nested_get_image_name_base core)" find "$NESTED_IMAGES_DIR/" -maxdepth 1 -name '*.img' | while read -r imgname; do - if [ -e "$NESTED_IMAGES_DIR/$IMAGE_NAME" ]; then - echo "Image $IMAGE_NAME file already present" - exit 1 - fi - mv "$imgname" "$NESTED_IMAGES_DIR/$IMAGE_NAME" + volname=$(basename "$imgname" .img) + mv "$imgname" "$NESTED_IMAGES_DIR/$IMAGE_BASE_NAME-$volname.img" done + + # get the name of the boot-volume, and then create a symlink + # between the regular image name and the main volume, additional + # volumes must be manually added to the VM creation by the tests + BOOTVOLUME=pc + if [ -e pc-gadget/meta/gadget.yaml ]; then + BOOTVOLUME="$(yq eval '.volumes[] | .structure.[] | select(.name == \"ubuntu-boot\") | parent(2) | key' pc-gadget/meta/gadget.yaml)" + fi + ln -s "$NESTED_IMAGES_DIR/$IMAGE_BASE_NAME-$BOOTVOLUME.img" "$NESTED_IMAGES_DIR/$IMAGE_NAME" + unset SNAPPY_FORCE_SAS_URL unset UBUNTU_IMAGE_SNAP_CMD fi diff --git a/tests/nested/manual/install-volume-assignment/task.yaml b/tests/nested/manual/install-volume-assignment/task.yaml index e5e6aa2f0fe..d137b32d3e3 100644 --- a/tests/nested/manual/install-volume-assignment/task.yaml +++ b/tests/nested/manual/install-volume-assignment/task.yaml @@ -1,6 +1,11 @@ -summary: install a gadget that uses min-size +summary: Install a gadget that uses volume-assignments -details: install a gadget that uses min-size +details: | + Tests volume-assignments syntax, and that we get the volumes installed to the expected + disks. The gadget will assign two different volumes to two different disks. The disks + are hardcoded at their PCI location, which hopefully does not change easily. We must + use a path in /dev/disk/.. as those are the only supported device assignments currently + for volumes. The test also tests gadget update. systems: [ubuntu-2*] @@ -8,6 +13,7 @@ environment: NESTED_CUSTOM_MODEL: $TESTSLIB/assertions/valid-for-testing-pc-{VERSION}.model NESTED_ENABLE_SECURE_BOOT: false NESTED_BUILD_SNAPD_FROM_CURRENT: true + NESTED_IMAGE_ID: volassign prepare: | snap install yq @@ -18,6 +24,13 @@ prepare: | # append volume-assignments cat <> pc-gadget/meta/gadget.yaml + backup: + schema: mbr + structure: + - filesystem: ext4 + name: system-backup + size: 127M + type: 83,0FC63DAF-8483-4772-8E79-3D69D8477DE4 volume-assignments: - name: do-not-match-device assignment: @@ -27,6 +40,8 @@ prepare: | assignment: pc: device: /dev/disk/by-path/pci-0000:00:05.0 + backup: + device: /dev/disk/by-path/pci-0000:00:06.0 EOF # enable debug @@ -43,10 +58,10 @@ prepare: | execute: | # create new disk for the gadget volume-assignments that we attach # to the VM - truncate --size=4G fake-disk.img + BACKUP_VOLUME="$NESTED_IMAGES_DIR/$(nested_get_image_name_base core)-backup.img" # setup extra disk options for tests.nested - NESTED_PARAM_EXTRA="-drive file=$(pwd)/fake-disk.img,if=none,snapshot=off,format=raw,id=disk2 \ + NESTED_PARAM_EXTRA="-drive file=$BACKUP_VOLUME,if=none,snapshot=off,format=raw,id=disk2 \ -device virtio-blk-pci,drive=disk2,serial=target" tests.nested create-vm core --extra-param "$NESTED_PARAM_EXTRA" @@ -54,7 +69,8 @@ execute: | # Build a new gadget that has content that needs to be updated sed -i 's/This program cannot be run in DOS mode/This program cannot be run in XXX mode/' \ pc-gadget/grubx64.efi - yq -i '(.volumes.pc.structure[] | select(.name == "ubuntu-boot") | .update.edition) |= . + 1' pc-gadget/meta/gadget.yaml + yq -i '(.volumes.pc.structure[] | select(.name == "ubuntu-boot") | .update.edition) |= . + 1' \ + pc-gadget/meta/gadget.yaml snap pack --filename=pc.snap pc-gadget remote.push pc.snap @@ -65,6 +81,7 @@ execute: | # even though at this point if it didn't exist the system would have # failed to install remote.exec "ls /dev/disk/by-path | grep 'pci-0000:00:05.0'" + remote.exec "ls /dev/disk/by-path | grep 'pci-0000:00:06.0'" boot_id=$(tests.nested boot-id)