Files

128 lines
4.8 KiB
YAML
Raw Permalink Normal View History

summary: Check basic core20 and later system functionality
details: |
Verify some basic functionalities in ubuntu core (>=20): system
snaps are present, the system is fully seeded, install a simple
snap, check boot configuration, symlinks in /var/lib/snapd/snaps,
snap recovery, loop devices and apparmor after a reboot works
properly
2022-03-08 09:29:00 +01:00
systems:
- ubuntu-core-20-*
- ubuntu-core-22-*
execute: |
2022-03-08 09:29:00 +01:00
case "$SPREAD_SYSTEM" in
ubuntu-core-22-*)
base_snap=core22
;;
ubuntu-core-20-*)
base_snap=core20
;;
esac
echo "Check that the system snaps are there"
2022-03-08 09:29:00 +01:00
snap list "${base_snap}"
snap list snapd
if snap list core; then
echo "The old core snap is installed but should not"
exit 1
fi
echo "Ensure that the system is fully seeded"
snap changes | MATCH "Done.*Initialize system state"
echo "Check that a simple shell snap"
2022-03-08 09:29:00 +01:00
if os.query is-core22; then
snap install --edge "test-snapd-sh-${base_snap}"
else
snap install "test-snapd-sh-${base_snap}"
fi
"test-snapd-sh-${base_snap}.sh" -c 'echo hello' | MATCH hello
if python3 -m json.tool < /var/lib/snapd/system-key | grep '"build-id": ""'; then
echo "The build-id of snapd must not be empty."
exit 1
fi
echo "Ensure passwd/group is available for snaps"
2022-03-08 09:29:00 +01:00
"test-snapd-sh-${base_snap}.sh" -c 'cat /var/lib/extrausers/passwd' | MATCH test
# rpi devices don't use grub
if ( os.query is-core20 || os.query is-core22 ) && not snap list pi-kernel &>/dev/null; then
echo "Ensure extracted kernel.efi exists"
tests: use new snaps.name and snaps.cleanup tools (#11599) * Squashed 'tests/lib/external/snapd-testing-tools/' changes from 872b64e05b..1a986df8d5 1a986df8d5 Merge pull request #17 from snapcore/new-snaps-cleanup-tool 29600af53a Fixing os.paths test for arch linux e5cdb06053 Minor fixes based on comment reviews 89a0073b88 Run cleanup tests just on systems with snapd pre-installed 19d216a1b9 New tools to get os paths, snap names and cleanup the snaps a36ee8451a Merge pull request #16 from snapcore/add-codespell f837691b62 Adding codespell tool to github workflow 58418c3f7e Merge pull request #15 from snapcore/testing-jammy f015a34899 Fix issue about how info is saved for Debug output 1ee4240e79 Adding jammy to the test systems in spread.yaml 61a4c3142d Merge pull request #14 from snapcore/include-support-s390x 3a1a65f6e1 Update the comments about shellchek 5ddfb7e1db New support for s390x arch in os.query tool 575f5d2016 Merge pull request #13 from snapcore/new-utils-section 4701612434 avoid installing and removing snapd in ubuntu focal 4d0317633d shellcheck in xenial is not needed d95cb2e627 Moving some tools to the new utils section 839a0ce808 Merge pull request #10 from snapcore/new-spread-shellcheck-tool 5d5efd6fbe Merge pull request #12 from snapcore/run-shellchek-in-old-version 497b7d691f Force testing shellchek with versions 0.8 and 0.7 b3cb5a5a0a Update the copyright 5cfa7cb84d New shellcheck for spread tasks git-subtree-dir: tests/lib/external/snapd-testing-tools git-subtree-split: 1a986df8d5e66459ec9aa2498a1e9c7d7e419284 * Using new snaps.name and snaps.cleanup tools These tools are imported from snapd-testing-tools * cleanup tool will not be in bin * Fix shellcheck * Update missing tests * Fix shellcheck * Squashed 'tests/lib/external/snapd-testing-tools/' changes from 1a986df8d5..53ca1b3b70 53ca1b3b70 Merge pull request #21 from snapcore/fix-some-shellcheks d380a8065e Fix shellchecks ad410d44cd Merge pull request #20 from snapcore/fixes-on-remote-tools 80bfd6d85b Updates based on review comments in snapd project 5c77d93bd6 Merge pull request #18 from snapcore/tests-new-remote-tools 3cef4b69b4 Updating timeouts 2c6bf4bd48 Using local vars and removing wait-for tool 8642893803 Test fixes a14ec4ea88 New remote tools 4545a5e5be Merge branch 'main' into tests-new-remote-tools a791ae89cb New remote tools git-subtree-dir: tests/lib/external/snapd-testing-tools git-subtree-split: 53ca1b3b709e685b7910e4b559f182dd78039029 * Make snaps.name executable
2022-05-13 15:11:54 -03:00
kernel_name="$(snaps.name kernel)"
test -e /boot/grub/"$kernel_name"*/kernel.efi
echo "Ensure kernel.efi is a symlink"
test -L /boot/grub/kernel.efi
echo "Ensure we are using managed boot assets"
MATCH '# Snapd-Boot-Config-Edition: [0-9]+' < /boot/grub/grub.cfg
MATCH '# Snapd-Boot-Config-Edition: [0-9]+' < /run/mnt/ubuntu-seed/EFI/ubuntu/grub.cfg
else
echo "Ensure extracted {kernel,initrd}.img exists"
test -e /run/mnt/ubuntu-seed/systems/*/kernel/kernel.img
test -e /run/mnt/ubuntu-seed/systems/*/kernel/initrd.img
fi
echo "Ensure that model was written to ubuntu-boot"
test -e /run/mnt/ubuntu-boot/device/model
# ensure that our the-tool (and thus our snap-bootstrap ran)
# for external backend the initramfs is not rebuilt
echo "Check that we booted with the rebuilt initramfs in the kernel snap"
if [ "$SPREAD_BACKEND" != "external" ] && [ "$SPREAD_BACKEND" != "testflinger" ]; then
test -e /writable/system-data/the-tool-ran
fi
# ensure we handled cloud-init, either we have:
# a) cloud init is disabled
# b) there was a cloud.cfg.d override (e.g. MAAS), then we must have more
# files in writable than in the core20 snap. The core20 content and the
# extra config will be merged
test -e /writable/system-data/etc/cloud/cloud-init.disabled || [ "$(find /writable/system-data/etc/cloud/cloud.cfg.d/ | wc -l)" -gt "$(find /snap/"${base_snap}"/current/etc/cloud/cloud.cfg.d/ | wc -l)" ]
snap/squashfs: also symlink snap Install with uc20 seed snap dir layout (#8711) This ensures that during install/recover mode we use symlinks in /var/lib/snapd/snaps to /var/lib/snapd/seed/systems//snaps, and that makebootable will still copy the full snap file to /run/mnt/ubuntu-data/... such that the initramfs and run mode see a normal snap file. Note that we specifically don't want the initramfs to use symlinks from ubuntu-data to ubuntu-seed because this is not trusted, this is enforced by passing a new InstallOptions to Container.Install with a MustNostCrossDevices flag. This was prompted by https://bugs.launchpad.net/snapd/+bug/1878647 because there, the tmpfs we mount for ubuntu-data/writable is only 205M, and all the kernel and base snaps are over 205M and so the install runs out of space to copy the snap files onto the tmpfs and eventually snapd tries to uninstall itself during first-boot. This fixes https://bugs.launchpad.net/snapd/+bug/1878647 * boot/makebootable: if kernel,base snaps are symlinks, follow symlink This ensures that if we switch setup during install/recover mode to use symlinks in /var/lib/snapd/snaps to /var/lib/snapd/seed/systems/<label>/snaps, that makebootable will still copy the full snap file to /run/mnt/ubuntu-data/... such that the initramfs and run mode see a normal snap file. Signed-off-by: Ian Johnson <ian.johnson@canonical.com> * snap/squashfs: fix creating symlinks when snap is in uc20 seed system snaps dir During uc20 install and recover modes, we will have a tmpfs as our writable partition and as such we don't really want or need to make a full copy of the snap files into /var/lib/snapd/snaps, and can make do with a symlink instead. However, during uc20 install and recover modes the snap files from the seed dir will be of the form /var/lib/snapd/seed/systems<label>/snaps/<name>.snap and so the previous logic to install it was wrong, as the <name>.snap would not be a direct child of /var/lib/snapd/seed, and instead needs to check that it is just prefixed with /var/lib/snapd/seed somewhere. Signed-off-by: Ian Johnson <ian.johnson@canonical.com> * snap/many: support InstallOptions + MustCopy for Install() This will allow us from snapstate to decide how a snap file should be installed, if it should be symlinked or if it should be always copied, etc. Eventually we should also introduce logic to snapstate to decide if it should be linked to remove the overlayfs specific logic from here where it is kind of awkward to see. Also add tests for the squashfs and snapstate implementations. Signed-off-by: Ian Johnson <ian.johnson@canonical.com> * overlord/snapstate: always copy files when seeding in uc20 run mode This prevents us from inadventently installing symlinks from ubuntu-data to ubuntu-seed, which would be insecure in the full disk encryption case because an attacker could modify ubuntu-seed and after the disk is unlocked on ubuntu-data and the system starts running, the snap from ubuntu-seed would be mounted. Signed-off-by: Ian Johnson <ian.johnson@canonical.com> * snap: rename MustCopy to MustNotCrossDevices for InstallOptions This option is really about security and ensuring that when we install a snap that installation does not cross device/trust boundaries, i.e. on UC20 from ubuntu-data (trusted) to ubuntu-seed (untrusted), so rename the option to better reflect this. Also, refactor the implementation to allow hard-links if MustNotCrossDevices is true, as by definition hard-links cannot cross devices/filesystems, and really should only limit symlinks. Signed-off-by: Ian Johnson <ian.johnson@canonical.com> * snap/snapdir: un-support MustNotCrossDevices in Install() for now It's unclear what we want this implementation to look like, so for now just drop it. `snap try` may be less secure on UC20 as a result, but that shouldn't be happening on production devices anyways. Signed-off-by: Ian Johnson <ian.johnson@canonical.com> * tests/core/basic20: also test that no symlinks were created during seeding Signed-off-by: Ian Johnson <ian.johnson@canonical.com> * tests/core/seed-base-symlinks: disable for UC20 permanently, adjust comment We don't have symlinks from ubuntu-data /var/lib/snapd/snaps to ubuntu-seed at /var/lib/snapd/seed by design on UC20 run mode. Signed-off-by: Ian Johnson <ian.johnson@canonical.com> * tests/core: fix spread tests adjustments * squashfs: drop TODO:UC20 more likely to confuse than get ever addressed Co-authored-by: Samuele Pedroni <pedronis@lucediurna.net>
2020-05-26 04:06:08 -05:00
# ensure that we have no symlinks from /var/lib/snapd/snaps to
# /var/lib/snapd/seed
for sn in /var/lib/snapd/snaps/*.snap ; do
if [[ -L $sn ]]; then
echo "snap $sn is a symlink but should not be"
exit 1
fi
done
# ensure that disk-mapping.json is created - we check the format of this
# file in unit tests and in uc20-create-partitions so we don't check
# anything here, just that the file exists
test -e /var/lib/snapd/device/disk-mapping.json
# ubuntu-save has it too
test -e /run/mnt/ubuntu-save/device/disk-mapping.json
# ensure the "snap recovery" command works
2020-09-15 13:50:07 -03:00
MODEL="$(snap model --verbose | grep '^model' | awk '{ print $2 }')"
2020-09-16 14:02:21 -03:00
BRAND_ID="$(snap model --verbose | grep '^brand-id:' | awk '{print $2}')"
if [ "$(snap known account "username=$BRAND_ID" | grep '^validation:' | awk '{print $2}')" != "unproven" ]; then
2022-04-26 14:59:56 +02:00
BRAND_ID="$BRAND_ID\*\*"
fi
2020-09-16 14:02:21 -03:00
snap recovery --unicode=never | MATCH "[0-9]+ +$BRAND_ID +$MODEL +current"
# check that we have a boot-flags file
test -f /run/snapd/boot-flags
# make sure that loop devices created by snap-bootstrap initramfs-mounts for snaps are readonly
for mount in /run/mnt/base /run/mnt/kernel; do
mountpoint "${mount}"
loop="$(findmnt -o source "${mount}" -n)"
echo "${loop}" | MATCH "/dev/loop[0-9]+"
losetup -O ro -n --raw "${loop}" | MATCH "1"
done
# ensure apparmor works, see LP: 2024637
systemctl status apparmor.service
# reboot to double check that apparmor still works after the reboot
# (LP: 2024637)
if [ "$SPREAD_REBOOT" = 0 ]; then
REBOOT
fi