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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
summary: Ensure snap run inside a devmode snap works (for now)
details: |
This test ensures inside a devmode snap the "snap run" command
works.
Because of historic mistakes we allowed this and until we properly
deprecated it we need to ensure it works. We really do not want to
support running other snaps from devmode snaps as the use-case for
devmode is to get help on the way to confined snaps. But snaps can
not run other snaps so this does not make sense.
systems:
# run the classic test on xenial so that we can build the snapd snap
# destructively without needing the lxd snap and thus execute much quicker
# NOTE: if this test is moved to classic impish or later before the snapd
# snap moves off of building based on xenial, then building with LXD will
# not work because xenial containers do not boot/get networking properly
# when the host has cgroupsv2 in it
- ubuntu-16.04-*
environment:
# ensure that re-exec is on by default like it should be
SNAP_REEXEC: "1"
SNAP_TO_USE_FIRST/snapd_first: snapd
SNAP_TO_USE_FIRST/core_first: core
# TODO: we should probably have a smaller / simpler test-snapd-* snap for
# testing devmode confinement with base: core
BASE_CORE_DEVMODE_SNAP: godd
BASE_NON_CORE_DEVMODE_SNAP: test-snapd-tools-core18
BASE_CORE_STRICT_SNAP: test-snapd-sh
BASE_NON_CORE_STRICT_SNAP: test-snapd-sh-core18
prepare: |
# Core snap is not modified for classic re-exec any more in this scenario
if tests.info is-snapd-from-archive; then
tests.exec skip-test "Core snap is not modified for classic re-exec any more in this scenario" && exit 0
fi
CURRENT_SNAPD_SNAP="$(ls "$SNAPD_WORK_DIR"/snapd_snap/snapd_*.snap)"
cp "$CURRENT_SNAPD_SNAP" "$PWD/snapd-from-branch.snap"
# now repack the core snap with this snapd snap
snap download core --edge --basename=core-from-edge
unsquashfs -d edge-core-snap core-from-edge.snap
coredir=edge-core-snap
snapddir=snapd-from-branch
dpkg-deb -x "$GOHOME"/snapd_*.deb "${snapddir}"
pushd "${PROJECT_PATH}"
SNAPD_SNAP_VERSION=$(./mkversion.sh --output-only)
popd
# copy everything from the snapd snap into the core snap
cp -arT "${snapddir}" "${coredir}"
# set the version for the core snap to be the version from the snapd snap
CORE_SNAP_VERSION=$(grep -Po "version: \K.*" "${coredir}/meta/snap.yaml")
sed -i -e "s/${CORE_SNAP_VERSION}/${SNAPD_SNAP_VERSION}/" "${coredir}/meta/snap.yaml"
# pack the core snap
snap pack --filename=core-from-branch.snap "$coredir"
rm -r "$coredir"
rm -r "$snapddir"
execute: |
tests.exec is-skipped && exit 0
if [ "$SNAP_TO_USE_FIRST" = "core" ]; then
# first install our core snap because we don't have the snapd snap on
# the system yet, so we don't need to do any shenanigans
snap install --dangerous core-from-branch.snap
snap install --devmode --beta "$BASE_CORE_DEVMODE_SNAP"
snap install "$BASE_CORE_STRICT_SNAP"
# umask is the command we execute to avoid yet another layer of quoting
OUTPUT=$(echo "snap run ${BASE_CORE_STRICT_SNAP}.sh -c umask" | snap run --shell "${BASE_CORE_DEVMODE_SNAP}")
if [ "$OUTPUT" != "0022" ]; then
echo "test failed"
exit 1
fi
snap install --dangerous snapd-from-branch.snap
# trigger profile re-generation because the same build-id for snapd is
# in the core and snapd snaps we are using, so profiles won't be
# regenerated when we install the snapd snap above
systemctl stop snapd.socket snapd.service
rm /var/lib/snapd/system-key
systemctl start snapd.socket snapd.service
# also install the non-core base snap, note that we can install and use it
# even without the snapd snap, but we cannot execute other snaps from this
# devmode snap without also installing the snapd snap, as inside non-core
# base snaps, there is a symlink
# /usr/bin/snap -> /snap/snapd/current/usr/bin/snap
# which effectively requires the snapd snap to be installed to execute other
# snaps from inside the devmode non-core based snap
snap install --devmode "$BASE_NON_CORE_DEVMODE_SNAP"
# umask is the command we execute to avoid yet another layer of quoting
OUTPUT=$(echo "snap run ${BASE_CORE_STRICT_SNAP}.sh -c umask" | snap run --shell "${BASE_CORE_DEVMODE_SNAP}")
if [ "$OUTPUT" != "0022" ]; then
echo "test failed"
exit 1
fi
OUTPUT=$(echo "snap run ${BASE_CORE_STRICT_SNAP}.sh -c umask" | snap run --shell "${BASE_NON_CORE_DEVMODE_SNAP}.sh")
if [ "$OUTPUT" != "0022" ]; then
echo "test failed"
exit 1
fi
elif [ "$SNAP_TO_USE_FIRST" = "snapd" ]; then
# we already had the core snap installed, so we need to purge things
# and then install only the snapd snap to test this scenario
snap remove core18
apt remove --purge -y snapd
apt install snapd -y
snap install --dangerous snapd-from-branch.snap
# snaps that don't depend on the core snap
snap install --devmode "$BASE_NON_CORE_DEVMODE_SNAP"
snap install "$BASE_NON_CORE_STRICT_SNAP"
# umask is the command we execute to avoid yet another layer of quoting
OUTPUT=$(echo "snap run ${BASE_NON_CORE_STRICT_SNAP}.sh -c umask" | snap run --shell "${BASE_NON_CORE_DEVMODE_SNAP}.sh" )
if [ "$OUTPUT" != "0022" ]; then
echo "test failed"
exit 1
fi
# now install the core snap and run those tests
echo "install the core snap"
snap install --dangerous core-from-branch.snap
# trigger profile re-generation because the same build-id for snapd is
# in the core and snapd snaps we are using, so profiles won't be
# regenerated when we install the snapd snap above
systemctl stop snapd.socket snapd.service
rm /var/lib/snapd/system-key
systemctl start snapd.socket snapd.service
snap install --devmode --beta "$BASE_CORE_DEVMODE_SNAP"
snap install "$BASE_CORE_STRICT_SNAP"
OUTPUT=$(echo "snap run ${BASE_CORE_STRICT_SNAP}.sh -c umask" | snap run --shell "${BASE_CORE_DEVMODE_SNAP}")
if [ "$OUTPUT" != "0022" ]; then
echo "test failed"
exit 1
fi
OUTPUT=$(echo "snap run ${BASE_CORE_STRICT_SNAP}.sh -c umask" | snap run --shell "${BASE_NON_CORE_DEVMODE_SNAP}.sh")
if [ "$OUTPUT" != "0022" ]; then
echo "test failed"
exit 1
fi
# undo the purging
apt install -y "$GOHOME"/snapd_*.deb
fi
|