Skip to content

Commit

Permalink
tests: test multiple volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
Meulengracht committed Oct 2, 2024
1 parent 0fa2fdf commit 2cca331
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
27 changes: 20 additions & 7 deletions tests/lib/nested.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
27 changes: 22 additions & 5 deletions tests/nested/manual/install-volume-assignment/task.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
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*]

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
Expand All @@ -18,6 +24,13 @@ prepare: |
# append volume-assignments
cat <<EOF >> 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:
Expand All @@ -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
Expand All @@ -43,18 +58,19 @@ 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"
# 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
Expand All @@ -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)
Expand Down

0 comments on commit 2cca331

Please sign in to comment.