Skip to content

Commit

Permalink
tests: add auto-install transition test
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestl committed Sep 13, 2024
1 parent 30cf57a commit f2e055e
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/lib/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 -
126 changes: 126 additions & 0 deletions tests/main/snapd-snap-transition-auto-install/task.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -31,4 +30,3 @@ execute: |
done
snap list snapd
snap changes | MATCH "Transition to the snapd snap"

0 comments on commit f2e055e

Please sign in to comment.