Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: backport preseed test fixes to 2.45 #8980

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 24 additions & 21 deletions tests/lib/preseed.sh
Expand Up @@ -3,8 +3,8 @@
# mount ubuntu cloud image through qemu-nbd and mount
# critical virtual filesystems (such as proc) under
# the root of mounted image.
# XXX: cannot be used in prepare: section of the tests
# as the test gets stuck around qemu-nbd on 20.04.
# The path of the image needs to be absolute as a systemd service
# gets created for qemu-nbd.
mount_ubuntu_image() {
local CLOUD_IMAGE=$1
local IMAGE_MOUNTPOINT=$2
Expand All @@ -13,9 +13,12 @@ mount_ubuntu_image() {
modprobe nbd
fi

qemu-nbd -c /dev/nbd0 "$CLOUD_IMAGE"
# Run qemu-nbd as a service, so that it does not interact with ssh
# stdin/stdout it would otherwise inherit from the spread session.
systemd-run --system --service-type=forking --unit=qemu-nbd-preseed.service "$(command -v qemu-nbd)" --fork -c /dev/nbd0 "$CLOUD_IMAGE"
# nbd0p1 may take a short while to become available
retry-tool -n 5 --wait 1 mount /dev/nbd0p1 "$IMAGE_MOUNTPOINT"
retry-tool -n 5 --wait 1 test -e /dev/nbd0p1
mount /dev/nbd0p1 "$IMAGE_MOUNTPOINT"
mount -t proc /proc "$IMAGE_MOUNTPOINT/proc"
mount -t sysfs sysfs "$IMAGE_MOUNTPOINT/sys"
mount -t devtmpfs udev "$IMAGE_MOUNTPOINT/dev"
Expand All @@ -36,24 +39,24 @@ umount_ubuntu_image() {
retry-tool -n 5 --wait 1 qemu-nbd -d /dev/nbd0
}

# XXX inject new snapd into the core image in seed/snaps of the cloud image
# and make core unasserted.
# this will go away once snapd on the core is new enough to support
# pre-seeding.
setup_preseeding() {
# inject latest snapd snap from edge into seed/snaps of the cloud image
# and make it unasserted.
# this is needed if snapd from the deb is newer than snapd in seeds as
# otherwise
inject_snapd_into_seeds() {
local IMAGE_MOUNTPOINT=$1
local CORE_IMAGE

# TODO: on 20.04 there is no core_*.snap anymore, just snapd
CORE_IMAGE=$(find "$IMAGE_MOUNTPOINT/var/lib/snapd/seed/snaps/" -name "core_*.snap")
unsquashfs "$CORE_IMAGE"
cp /usr/lib/snapd/snapd squashfs-root/usr/lib/snapd/snapd
# XXX to satisfy version check; this will go away once preseeding
# is available in 2.44
echo "VERSION=2.44.0" > squashfs-root/usr/lib/snapd/info
rm "$CORE_IMAGE"
local SNAP_IMAGE

#shellcheck source=tests/lib/snaps.sh
. "$TESTSLIB"/snaps.sh
mksnap_fast squashfs-root "$CORE_IMAGE"
sed -i "$IMAGE_MOUNTPOINT/var/lib/snapd/seed/seed.yaml" -E -e 's/^(\s+)name: core/\1name: core\n\1unasserted: true/'

SNAP_IMAGE=$(find "$IMAGE_MOUNTPOINT/var/lib/snapd/seed/snaps/" -name "snapd_*.snap")
if [ -e "$SNAP_IMAGE" ]; then
snap download --edge snapd
SNAPD_EDGE=$(ls snapd_*.snap)
rm -f "$IMAGE_MOUNTPOINT"/var/lib/snapd/seed/snaps/snapd_*.snap
mv "$SNAPD_EDGE" "$IMAGE_MOUNTPOINT"/var/lib/snapd/seed/snaps/
sed -i "$IMAGE_MOUNTPOINT/var/lib/snapd/seed/seed.yaml" -E -e "s/^(\\s+)name: snapd/\\1name: snapd\\n\\1unasserted: true/"
sed -i "$IMAGE_MOUNTPOINT/var/lib/snapd/seed/seed.yaml" -E -e "s/^(\\s+)file: snapd.*/\\1file: $SNAPD_EDGE\\n/"
fi
}
8 changes: 5 additions & 3 deletions tests/main/nfs-support/task.yaml
Expand Up @@ -183,9 +183,11 @@ execute: |
# Ensure that this removed the extra permissions.
ensure_normal_perms

# Skip udp protocol on arch-linux because it is not supported
# Error displayed: mount.nfs: requested NFS version or transport protocol is not supported
if [[ ! "$SPREAD_SYSTEM" =~ arch-* ]]; then
# Skip udp protocol on arch-linux and debian-sid because it is not supported
# Error displayed:
# - arch: mount.nfs: requested NFS version or transport protocol is not supported
# - debian-sid: mount.nfs: an incorrect mount option was specified
if [[ "$SPREAD_SYSTEM" != arch-* && "$SPREAD_SYSTEM" != debian-sid-* ]]; then
# Mount NFS-exported /home over real /home using NFSv3 and UDP transport
mount -t nfs localhost:/home /home -o nfsvers=3,proto=udp

Expand Down
21 changes: 8 additions & 13 deletions tests/main/preseed-reset/task.yaml
Expand Up @@ -3,8 +3,7 @@ description: |
This test checks that preseeding of Ubuntu cloud images with snap-preseed
can be undone with --reset flag.

# TODO: reenable for ubuntu-20.04-*, that now uses the snapd snap
systems: [ubuntu-19.10-*]
systems: [ubuntu-19.10-*, ubuntu-2*]

environment:
IMAGE_MOUNTPOINT: /mnt/cloudimg
Expand All @@ -17,13 +16,17 @@ prepare: |
wget "$(get_image_url_for_nested_vm)" -O cloudimg.img
mkdir -p "$IMAGE_MOUNTPOINT"

#shellcheck source=tests/lib/preseed.sh
. "$TESTSLIB/preseed.sh"
mount_ubuntu_image "$(pwd)/cloudimg.img" "$IMAGE_MOUNTPOINT"

restore: |
rm -f before-preseeding.txt
rm -f after-reset.txt

# any of the restore commands can fail depending on where execute part stopped,
# account for that with ||true.
umount_ubuntu_image "$IMAGE_MOUNTPOINT" || true
#shellcheck source=tests/lib/preseed.sh
. "$TESTSLIB/preseed.sh"
umount_ubuntu_image "$IMAGE_MOUNTPOINT"

execute: |
find_files() {
Expand All @@ -36,11 +39,6 @@ execute: |
fi
}

#shellcheck source=tests/lib/preseed.sh
. "$TESTSLIB/preseed.sh"
mount_ubuntu_image cloudimg.img "$IMAGE_MOUNTPOINT"
setup_preseeding "$IMAGE_MOUNTPOINT"

find_files > before-preseeding.txt

echo "Running pre-seeeding"
Expand Down Expand Up @@ -68,6 +66,3 @@ execute: |
echo "Running preseeeding again should succeed"
/usr/lib/snapd/snap-preseed "$IMAGE_MOUNTPOINT"

#shellcheck source=tests/lib/preseed.sh
. "$TESTSLIB/preseed.sh"
umount_ubuntu_image "$IMAGE_MOUNTPOINT"
7 changes: 0 additions & 7 deletions tests/main/preseed-snapd-snap/seed.yaml.in

This file was deleted.

110 changes: 0 additions & 110 deletions tests/main/preseed-snapd-snap/task.yaml

This file was deleted.