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
|
summary: A snap migrates from base "core" to "core18"
details: |
Verify that a snap can be migrated from base:core to base:core18 and
from base:core18 to base:core. Validate the base snaps are properly
downloaded, the mount namespace information file is owned by root
and the base version for the snap is updated accordingly.
environment:
DIRECTION/forward: forward
DIRECTION/back: back
prepare: |
snap install core18
snap pack test-snapd-core-migration.base-core
snap pack test-snapd-core-migration.base-core18
execute: |
case "$DIRECTION" in
forward)
# When we install a snap that is using (implicitly) base: core, then that
# snap runs on top of the core16 runtime environment. This can be seen by
# looking at the os-release file which will match that of ubuntu core 16.
snap install --dangerous test-snapd-core-migration_1_all.snap
su test -c 'snap run test-snapd-core-migration.sh -c "cat /usr/lib/os-release"' | MATCH 'VERSION_ID="16"'
# The mount namespace information file is owned by root:root and has mode 0644
# even though the user invoking the snap command was non-root.
MATCH 'base-snap-name=core' < /run/snapd/ns/snap.test-snapd-core-migration.info
test "$(stat -c '%u.%g' /run/snapd/ns/snap.test-snapd-core-migration.info)" = 0.0
test "$(stat -c '%a' /run/snapd/ns/snap.test-snapd-core-migration.info)" = 644
# When said snap is refreshed to use "base: core18" then, because there are
# no active processes in that snap, the base will change correctly to core18.
# This can be again observed by looking at the os-release file.
snap install --dangerous test-snapd-core-migration_2_all.snap
test-snapd-core-migration.sh -c "cat /usr/lib/os-release" | MATCH 'VERSION_ID="18"'
MATCH 'base-snap-name=core18' < /run/snapd/ns/snap.test-snapd-core-migration.info
# If we rewind and do the update again, this time allowing one of the apps
# from the core16 world to keep running. Normally this would hold the update
# of the base snap, as seen by the processes of the application snap. This
# ensures that all processes in a given snap see a consistent view of the
# filesystem.
snap remove --purge test-snapd-core-migration
snap install --dangerous test-snapd-core-migration_1_all.snap
test-snapd-core-migration.sh -c "exec sleep 1h" &
pid=$!
test-snapd-core-migration.sh -c "cat /usr/lib/os-release" | MATCH 'VERSION_ID="16"'
MATCH 'base-snap-name=core' < /run/snapd/ns/snap.test-snapd-core-migration.info
# there is a sleep process running in the background in the snap context, due to
# refresh-app-awareness we need to ignore it
snap install --ignore-running --dangerous test-snapd-core-migration_2_all.snap
# With core -> core18 migration this doesn't work however, as now
# applications that were expecting to use core18 libraries would be forced to
# run on top of core16.
#
# Therefore, to ensure compatibility, even before the background process
# terminates we are now using the new base snap, processes across base snaps
# see different mount namespaces.
test-snapd-core-migration.sh -c "cat /usr/lib/os-release" | MATCH 'VERSION_ID="18"'
MATCH 'base-snap-name=core18' < /run/snapd/ns/snap.test-snapd-core-migration.info
kill "$pid"
wait "$pid" || true # wait returns the exit code and we kill the process
# Nothing changes after the background app terminates.
test-snapd-core-migration.sh -c "cat /usr/lib/os-release" | MATCH 'VERSION_ID="18"'
MATCH 'base-snap-name=core18' < /run/snapd/ns/snap.test-snapd-core-migration.info
;;
back)
# When we install a snap that is using (explicitly) base: core18, then that
# snap runs on top of the core18 runtime environment. This can be seen by
# looking at the os-release file which will match that of ubuntu core 18.
snap install --dangerous test-snapd-core-migration_2_all.snap
su test -c 'snap run test-snapd-core-migration.sh -c "cat /usr/lib/os-release"' | MATCH 'VERSION_ID="18"'
# The mount namespace information file is owned by root:root and has mode 0644
# even though the user invoking the snap command was non-root.
MATCH 'base-snap-name=core18' < /run/snapd/ns/snap.test-snapd-core-migration.info
test "$(stat -c '%u.%g' /run/snapd/ns/snap.test-snapd-core-migration.info)" = 0.0
test "$(stat -c '%a' /run/snapd/ns/snap.test-snapd-core-migration.info)" = 644
# When said snap is refreshed to use core (implicitly) then, because there are
# no active processes in that snap, the base will change correctly to core.
# This can be again observed by looking at the os-release file.
snap install --dangerous test-snapd-core-migration_1_all.snap
test-snapd-core-migration.sh -c "cat /usr/lib/os-release" | MATCH 'VERSION_ID="16"'
MATCH 'base-snap-name=core' < /run/snapd/ns/snap.test-snapd-core-migration.info
# If we rewind and do the update again, this time allowing one of the apps
# from the core18 world to keep running. Normally this would hold the update
# of the base snap, as seen by the processes of the application snap. This
# ensures that all processes in a given snap see a consistent view of the
# filesystem.
snap remove --purge test-snapd-core-migration
snap install --dangerous test-snapd-core-migration_2_all.snap
test-snapd-core-migration.sh -c "exec sleep 1h" &
pid=$!
test-snapd-core-migration.sh -c "cat /usr/lib/os-release" | MATCH 'VERSION_ID="18"'
MATCH 'base-snap-name=core18' < /run/snapd/ns/snap.test-snapd-core-migration.info
# We run a process in the background, so due to refresh-app-awareness need to
# ignore running apps.
snap install --ignore-running --dangerous test-snapd-core-migration_1_all.snap
# With core18 -> core migration this doesn't work however, as now
# applications that were expecting to use core libraries would be forced to
# run on top of core18.
#
# Therefore, to ensure compatibility, even before the background process
# terminates we are now using the new base snap, processes across base snaps
# see different mount namespaces.
test-snapd-core-migration.sh -c "cat /usr/lib/os-release" | MATCH 'VERSION_ID="16"'
MATCH 'base-snap-name=core' < /run/snapd/ns/snap.test-snapd-core-migration.info
kill "$pid"
wait "$pid" || true # wait returns the exit code and we kill the process
# Nothing changes after the background app terminates.
test-snapd-core-migration.sh -c "cat /usr/lib/os-release" | MATCH 'VERSION_ID="16"'
MATCH 'base-snap-name=core' < /run/snapd/ns/snap.test-snapd-core-migration.info
;;
esac
|