1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
summary: Check that the /system/<label> API works via fake installer
details: |
Check that the fake installed works properly using the /system/<label> API
Verify the instance created is a classic ubuntu with the kernel snap installed
# this is a UC20+ specific test
# TODO this currently fails on ubuntu-20.04-64 timing out
systems: [ubuntu-22.04-64, ubuntu-24.04-64]
environment:
# nested test so that we can test encryted installs eventually
# TODO enable tpm variant too for testing of encryption installs
# this will probably require fixes in nested.sh as the classic VM
# does not (yet) support tpm/secureboot(?)
NESTED_ENABLE_TPM: false
NESTED_ENABLE_SECURE_BOOT: false
NESTED_BUILD_SNAPD_FROM_CURRENT: true
NESTED_REPACK_KERNEL_SNAP: true
# store related setup
STORE_ADDR: localhost:11028
STORE_DIR: $(pwd)/fake-store-blobdir
prepare: |
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
echo "Install used snaps"
if [ -d /var/lib/snapd/seed ]; then
mv /var/lib/snapd/seed /var/lib/snapd/seed.orig
fi
"$TESTSTOOLS"/store-state setup-fake-store "$STORE_DIR"
restore: |
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
rm -rf /var/lib/snapd/seed
if [ -d /var/lib/snapd/seed.orig ]; then
mv /var/lib/snapd/seed.orig /var/lib/snapd/seed
fi
"$TESTSTOOLS"/store-state teardown-fake-store "$STORE_DIR"
rm -rf pc-kernel.* pc.* initrd* linux* kernel* tmp* pc-gadget pc muinstaller classic-seed fake-disk.img fdisk_output
execute: |
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
# XXX: the code in DeviceManager.SystemAndGadgetInfo() will only work on
# classic systems with modeenv right now (which is something we may need
# to fix to work from the classic installer).
# For now pretend we have a modeenv
echo "mode=run" > /var/lib/snapd/modeenv
tests.cleanup defer rm -f /var/lib/snapd/modeenv
# need snapd restart as GET /systems/<label> is only available on systems
# with a modeenv
systemctl restart snapd
echo Expose the needed assertions through the fakestore
cp "$TESTSLIB"/assertions/developer1.account "$STORE_DIR/asserts"
cp "$TESTSLIB"/assertions/developer1.account-key "$STORE_DIR/asserts"
cp "$TESTSLIB"/assertions/testrootorg-store.account-key "$STORE_DIR/asserts"
export SNAPPY_FORCE_SAS_URL=http://$STORE_ADDR
# shellcheck source=tests/lib/prepare.sh
. "$TESTSLIB/prepare.sh"
#shellcheck source=tests/lib/nested.sh
. "$TESTSLIB"/nested.sh
version="$(nested_get_version)"
# get an updated kernel
snap download --basename=pc-kernel --channel="$version/${KERNEL_CHANNEL}" pc-kernel
if os.query is-ubuntu-ge 24.04; then
uc24_build_initramfs_kernel_snap "$PWD/pc-kernel.snap" "$NESTED_ASSETS_DIR"
else
uc20_build_initramfs_kernel_snap "$PWD/pc-kernel.snap" "$NESTED_ASSETS_DIR"
fi
mv "${NESTED_ASSETS_DIR}"/pc-kernel_*.snap pc-kernel.snap
# Prepare gadget with the right gadget.yaml
snap download --basename=pc --channel="$version/edge" pc
unsquashfs -d pc pc.snap
sed -i 's/name: ubuntu-seed/name: EFI System partition/' pc/meta/gadget.yaml
sed -i 's/role: system-seed/role: system-seed-null/' pc/meta/gadget.yaml
snap pack --filename=pc-new.snap pc
rm -rf pc
# prepare a classic seed
# TODO:
# - create pc-classic custom gadget
# - repacked snapd snap
# (should be as simple as adding "--snap=./local-gadget.snap ...")
gendeveloper1 sign-model < "$TESTSLIB"/assertions/developer1-"$version"-classic-dangerous.json > my.model
snap prepare-image --classic \
--channel=edge \
--snap ./pc-kernel.snap \
--snap ./pc-new.snap \
my.model \
./classic-seed
# make the seed label more predictable for fake-installer auto-mode
LABEL=classic
mv ./classic-seed/system-seed/systems/* ./classic-seed/system-seed/systems/"$LABEL"
cp -a ./classic-seed/system-seed/ /var/lib/snapd/seed
rm -rf classic-seed
# do some light checking that the system is valid
snap debug api /v2/systems | gojq '.result.systems[0].label' | MATCH "$LABEL"
snap debug api "/v2/systems/$LABEL" > system
gojq '.result.model.distribution' system | MATCH "ubuntu"
# build muinstaller and put in place
go build -o muinstaller "$TESTSLIB"/muinstaller/main.go
# create fake disk for the installer to work on
truncate --size=4G fake-disk.img
export LABEL
bash create-disk.sh
# HACK: better to change nested_start_vm() to take an image name
# Note that use "core" here as the boot is so close to core that classic
# does not work
IMAGE_NAME="$(nested_get_image_name core)"
mv fake-disk.img "$NESTED_IMAGES_DIR/$IMAGE_NAME"
# boot into the created image
# Note that use "core" here as the boot is so close to core that classic
# does not work
# TODO: this prevents "nested_prepare_ssh" inside nested_start_core_vm
# from running, we already have a user so this is not needed
touch "$NESTED_IMAGES_DIR/$IMAGE_NAME.configured"
tests.nested create-vm core
remote.exec "cat /etc/os-release" | MATCH 'NAME="Ubuntu"'
remote.exec "snap changes" | MATCH "Done.* Initialize system state"
remote.exec "snap list" | MATCH pc-kernel
# Check disk traits
# TODO: enable for the encrypted cases
# TODO: this should grow extensive check like
# tests/main/uc20-create-partitions/task.yaml
# tests/main/uc20-create-partitions-encrypt/task.yaml
#DISK_MAPPINGS=(/run/mnt/ubuntu-save/device/disk-mapping.json
# /run/mnt/data/var/lib/snapd/device/disk-mapping.json)
#for DM in "${DISK_MAPPINGS[@]}"; do
# remote.exec "jq '.pc.\"structure-encryption\".\"ubuntu-save\".method' $DM" | MATCH '"LUKS"'
# remote.exec "jq '.pc.\"structure-encryption\".\"ubuntu-data\".method' $DM" | MATCH '"LUKS"'
#done
|