From a6badc6a3b8a837d14bd7dfe426b466771df82e2 Mon Sep 17 00:00:00 2001 From: ernestl Date: Thu, 12 Sep 2024 00:51:33 +0200 Subject: [PATCH] tests: add auto-install transition test --- tests/lib/prepare.sh | 2 +- .../connections-reference.txt | 43 ++++++ .../task.yaml | 126 ++++++++++++++++++ .../task.yaml | 22 ++- 4 files changed, 180 insertions(+), 13 deletions(-) create mode 100644 tests/main/snapd-snap-transition-auto-install/connections-reference.txt create mode 100644 tests/main/snapd-snap-transition-auto-install/task.yaml rename tests/main/{snapd-snap-transition => snapd-snap-transition-experimental-flag}/task.yaml (53%) diff --git a/tests/lib/prepare.sh b/tests/lib/prepare.sh index 096e8fd318d..10605402580 100755 --- a/tests/lib/prepare.sh +++ b/tests/lib/prepare.sh @@ -401,7 +401,7 @@ prepare_classic() { # This also prevents snapd from automatically installing snapd snap as # prerequisite for installing any non-base snap introduced in PR#14173. if snap list snapd ; then - snap snap info snapd + snap info snapd echo "Error: not expecting snapd snap to be installed" exit 1 else diff --git a/tests/main/snapd-snap-transition-auto-install/connections-reference.txt b/tests/main/snapd-snap-transition-auto-install/connections-reference.txt new file mode 100644 index 00000000000..8d8eb4270b3 --- /dev/null +++ b/tests/main/snapd-snap-transition-auto-install/connections-reference.txt @@ -0,0 +1,43 @@ +Interface Plug Slot Notes +audio-playback firefox:audio-playback :audio-playback - +audio-record firefox:audio-record :audio-record - +avahi-observe firefox:avahi-observe :avahi-observe - +bluez fwupd:bluez :bluez - +browser-support firefox:browser-sandbox :browser-support - +camera firefox:camera :camera - +content[gnome-42-2204] firefox:gnome-42-2204 gnome-42-2204:gnome-42-2204 - +content[gtk-3-themes] firefox:gtk-3-themes gtk-common-themes:gtk-3-themes - +content[icon-themes] firefox:icon-themes gtk-common-themes:icon-themes - +content[sound-themes] firefox:sound-themes gtk-common-themes:sound-themes - +cups-control firefox:cups-control :cups-control - +desktop firefox:desktop :desktop - +desktop-legacy firefox:desktop-legacy :desktop-legacy - +gsettings firefox:gsettings :gsettings - +hardware-observe firefox:hardware-observe :hardware-observe - +hardware-observe fwupd:hardware-observe :hardware-observe - +home firefox:home :home - +home fwupd:home :home - +joystick firefox:joystick :joystick - +login-session-observe firefox:login-session-observe :login-session-observe - +mount-control firefox:host-hunspell :mount-control - +network firefox:network :network - +network fwupd:network :network - +network-bind firefox:network-bind :network-bind - +opengl firefox:opengl :opengl - +opengl fwupd:opengl :opengl - +personal-files firefox:dot-mozilla-firefox :personal-files - +polkit fwupd:polkit :polkit - +raw-usb fwupd:raw-usb :raw-usb - +removable-media firefox:removable-media :removable-media - +screen-inhibit-control firefox:screen-inhibit-control :screen-inhibit-control - +shutdown fwupd:shutdown :shutdown - +system-files firefox:etc-firefox :system-files - +system-files firefox:host-usr-share-hunspell :system-files - +system-packages-doc firefox:system-packages-doc :system-packages-doc - +u2f-devices firefox:u2f-devices :u2f-devices - +udisks2 fwupd:udisks2 :udisks2 - +unity7 firefox:unity7 :unity7 - +upower-observe firefox:upower-observe :upower-observe - +upower-observe fwupd:upower-observe :upower-observe - +wayland firefox:wayland :wayland - +x11 firefox:x11 :x11 - diff --git a/tests/main/snapd-snap-transition-auto-install/task.yaml b/tests/main/snapd-snap-transition-auto-install/task.yaml new file mode 100644 index 00000000000..19c2683a59e --- /dev/null +++ b/tests/main/snapd-snap-transition-auto-install/task.yaml @@ -0,0 +1,126 @@ +summary: Ensure auto-install based transition to snapd snap works. + +details: | + Ensure that we can transition classic systems to snapd snap + with auto-install of snapd snap from snapd deb or snapd in core + triggered by any snap install. This change was introduced in PR14173. + +# Exclude Ubuntu Core systems - require proper remodeling +# Simplify test by limiting system to ubuntu 22.04 amd64 +systems: [ubuntu-22.04-64] + +environment: + SNAPD_SRC/deb: "deb" + SNAPD_SRC/core: "core" + +prepare: | + # remove all snaps to remove snapd + snap remove core + # this is only possible when snapd is the only installed snap + snap remove snapd + # at this point we expect to be running from the deb + systemctl restart snapd.service + + # Install deb + core before introduction of snapd auto-install + # on classic systems. + # deb: snapd | Aug 2024 | 2.63+22.04ubuntu0.1 | http://archive.ubuntu.com/ubuntu/pool/main/s/snapd/2.63+22.04ubuntu0.1_amd64.deb + # deb: snapd | Apr 2022 | 2.55.3+22.04 | http://archive.ubuntu.com/ubuntu/pool/main/s/snapd/2.55.3+22.04_amd64.deb + # snap: core | Jun 2024 | 16-2.61.4-20240607 (rev 17200) | https://snapcraft.io/core/releases + + # 'deb' : transition snapd deb to re-exec from snapd snap + # 'core': transition re-exec from snapd in core snap to re-exec from snapd snap + if [ "$SNAPD_SRC" = "deb" ]; then + # core < deb, exec snapd deb + apt install -y --allow-downgrades snapd=2.63+22.04ubuntu0.1 + else + # core => deb, re-exec snapd from core snap + apt install -y --allow-downgrades snapd=2.55.3+22.04 + fi + snap install core --revision=17200 # 16-2.61.4-20240607 + +execute: | + # check re-exec disabled, exec from snapd deb or re-exec from core snap + snap_mount_dir="$(os.paths snap-mount-dir)" + expect="" + if [ "${SNAP_REEXEC:-}" = "0" ]; then + echo "Ensure re-exec disabled" + expect="DEBUG: re-exec disabled by user" + elif [ "$SNAPD_SRC" = "deb" ]; then + echo "Ensure exec from snapd deb" + expect="DEBUG: snap \(at \"$snap_mount_dir/core/current\"\) is older \(\"2\.61\.4\"\) than distribution package \(\"2\.63\+22\.04ubuntu0\.1\"\)" + else + echo "Ensure re-exec from core snap" + expect="DEBUG: restarting into \"$snap_mount_dir/core/current/usr/bin/snap\"" + fi + SNAPD_DEBUG=1 snap list 2>&1 | MATCH "$expect" + + # Install snaps with snaps with complex interface requirements. + # Use specific revisions to pin expected behaviour. + install_snaps() { + snap install firefox --revision=4848 # 130.0-2 + snap install modem-manager --revision=541 # 1.20.0-2 + snap install fwupd --revision=6368 # 1.9.23-12-g92df65c6a + } + + # Trigger transition to snapd by installing either deb or core snap that supports snapd auto-install + # For both the deb and the core snap, installation of snapd snap is expected to follow after + # installation of any snap. + change_marker=$(snap changes | wc -l) + expected_changes_after_mark="" + expected_snap_with_snapd_prereq="" + if [ "$SNAPD_SRC" = "deb" ]; then + echo "Update snapd deb and install snaps to trigger auto-install of snapd" + # install snapd deb built during image preparation + sudo dpkg -i "${GOHOME}"/snapd_*.deb + + # Install snaps after updating snapd deb to exercise the post PR14173 logic for installing snapd snap. + # The first snap install will trigger the snapd auto-install. + install_snaps + expected_changes_after_mark="3" + expected_snap_with_snapd_prereq="firefox" + else + echo "Install snaps, update core snap and trigger auto-install of snapd with install of hello-world snap" + # install snaps before updating core snap to exercise transition of system slots and plugs + # from provided by core snap to provided by snapd snap + install_snaps + + # check connections + snap connections > /tmp/connections-actual.txt + diff -u ./connections-reference.txt /tmp/connections-actual.txt + + # install core snap built during image preparation + snap install --dangerous "$TESTSTMP"/core_snap/core_*.snap + + # snapd auto-install should happen as prerequisite for hello-world + snap install hello-world + expected_changes_after_mark="5" + expected_snap_with_snapd_prereq="hello-world" + fi + + echo "Ensure no change errors during installation" + snap changes | tail -n +"$change_marker" | NOMATCH "Error" + test "$(snap changes | tail -n +"$change_marker" | grep -c "Done")" = "$expected_changes_after_mark" + + echo "Ensure snapd snap was successfully automatically installed" + snap list snapd + change=$(snap changes | tail -n +"$change_marker" | grep "Install \"$expected_snap_with_snapd_prereq\"" | awk '{print $1}') + snap change "$change" | NOMATCH "Error" + snap change "$change" | MATCH "INFO Requested daemon restart \(snapd snap\)." + snap change "$change" | MATCH "Automatically connect eligible plugs and slots of snap \"snapd\"" + + # check re-exec disabled, exec from snapd deb or re-exec from snapd snap + if [ "${SNAP_REEXEC:-}" = "0" ]; then + echo "Ensure re-exec disabled" + expect="DEBUG: re-exec disabled by user" + elif [ "$SNAPD_SRC" = "deb" ]; then + echo "Ensure exec from snapd deb" + expect="DEBUG: snap \(at \"$snap_mount_dir/snapd/current\"\) is older \(\"2\.[0-9.]*\"\) than distribution package \(\"1337.[0-9.]*\"\)" + else + echo "Ensure re-exec from snapd snap" + expect="DEBUG: restarting into \"$snap_mount_dir/snapd/current/usr/bin/snap\"" + fi + SNAPD_DEBUG=1 snap list 2>&1 | MATCH "$expect" + + echo "Ensure expected interface connections" + snap connections > /tmp/connections-actual.txt + diff -u ./connections-reference.txt /tmp/connections-actual.txt diff --git a/tests/main/snapd-snap-transition/task.yaml b/tests/main/snapd-snap-transition-experimental-flag/task.yaml similarity index 53% rename from tests/main/snapd-snap-transition/task.yaml rename to tests/main/snapd-snap-transition-experimental-flag/task.yaml index bd02f569c02..dc2153fdee2 100644 --- a/tests/main/snapd-snap-transition/task.yaml +++ b/tests/main/snapd-snap-transition-experimental-flag/task.yaml @@ -1,25 +1,24 @@ -summary: Ensure the snapd snap transition works +summary: Ensure snapd-snap experimental flag based transition to snapd snap works. details: | - Ensure the snapd snap transition feature works + Ensure that we can transition classic systems from core snap + to snapd snap using the snapd-snap experimental flag. -# ubuntu-core-18+ already has the snapd snap -# FIXME: ubuntu-core-16 needs special code for the transition -systems: [-ubuntu-core-18-*, -ubuntu-core-2*, -ubuntu-core-16-*] +# Exclude Ubuntu Core systems - require proper remodeling +systems: [-ubuntu-core-*] -execute: | - echo "Ensure no snapd snap is installed" +prepare: | # remove all snaps to remove snapd snap remove core # this is only possible when snapd is the only installed snap snap remove snapd - # we should now be running from the distro package + # at this point we expect to be running from the distro package systemctl restart snapd.service - # TODO the test should install the snapd snap we built + # transition from core snap to snapd snap snap install --dangerous "$TESTSTMP"/core_snap/core_*.snap - - echo "Enable the snapd snap" +execute: | + echo "Enable the snapd snap experimental feature" snap set core experimental.snapd-snap=true for _ in $(seq 30); do @@ -31,4 +30,3 @@ execute: | done snap list snapd snap changes | MATCH "Transition to the snapd snap" -