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 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
summary: Check that snap-mgmt.sh works
details: |
Check that "snap-mgmt.sh --purge" removes all data installed by snapd.
This includes /var/snap, some writable parts of /var/lib/snapd.
/run/snapd/ns should be unmounted. Systemd and dbus configuration
managed in /etc should also be removed.
# slow in autopkgtest (>1m)
backends: [-autopkgtest]
# purging everything on core devices will not work
systems: [-ubuntu-core-*]
prepare: |
# TODO: unify this with tests/main/postrm-purge/task.yaml
# note: no need to unset these since this spread test purges snapd totally
# and snapd won't be around to respond, much less remove any state since
# the state should be removed by the test
snap set system experimental.user-daemons=true
# Install a number of snaps that contain various features that have
# representation in the file system.
for name in test-snapd-service test-snapd-timer-service socket-activation \
test-snapd-user-service test-snapd-user-service-sockets \
test-snapd-user-timer-service test-snapd-tools \
test-snapd-control-consumer test-snapd-auto-aliases \
test-snapd-kvm ; do
if echo "$name" | grep -q user && os.query is-trusty; then
# None of the "user" snaps work on 14.04
continue
fi
"$TESTSTOOLS"/snaps-state install-local "$name"
snap list | MATCH test-snapd-service
done
# kvm interface needs manual connection
snap connect test-snapd-kvm:kvm
snap install --edge test-snapd-dbus-provider
snap list | MATCH test-snapd-dbus-provider
if ! os.query is-trusty; then
snap install --edge test-snapd-dbus-service
snap list | MATCH test-snapd-dbus-service
fi
if ! os.query is-trusty && ! os.query is-amazon-linux && ! os.query is-centos 7 && ! os.query is-xenial; then
# create a quota with a service in it
snap set-quota group1 test-snapd-service --memory=100MB
fi
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
before=$(find "${SNAP_MOUNT_DIR}" -type d | wc -l)
if [ "$before" -lt 2 ]; then
echo "${SNAP_MOUNT_DIR} empty - test setup broken"
exit 1
fi
echo "test service is known to systemd and enabled"
systemctl list-unit-files --type service --no-legend | MATCH 'snap.test-snapd-service\..*\.service\s+enabled'
# install a snap with some components to make sure that we properly clean
# those up too
snap install test-snap-with-components+one+two
# expecting to find various files that snap installation produced
test "$(find /etc/udev/rules.d -name '*-snap.*.rules' | wc -l)" -gt 0
test "$(find /etc/dbus-1/system.d -name 'snap.*.conf' | wc -l)" -gt 0
test "$(find /etc/modules-load.d/ -name 'snap.*.conf' | wc -l)" -gt 0
test "$(find /etc/systemd/system -name 'snap.*.service' | wc -l)" -gt 0
test "$(find /etc/systemd/system -name 'snap.*.timer' | wc -l)" -gt 0
test "$(find /etc/systemd/system -name 'snap.*.socket' | wc -l)" -gt 0
if ! os.query is-trusty; then
test "$(find /etc/systemd/user -name 'snap.*.service' | wc -l)" -gt 0
test "$(find /etc/systemd/user -name 'snap.*.timer' | wc -l)" -gt 0
test "$(find /etc/systemd/user -name 'snap.*.socket' | wc -l)" -gt 0
test "$(find /var/lib/snapd/dbus-1/services -name '*.service' | wc -l)" -gt 0
test "$(find /var/lib/snapd/dbus-1/system-services -name '*.service' | wc -l)" -gt 0
fi
if ! os.query is-trusty && ! os.query is-amazon-linux && ! os.query is-centos 7 && ! os.query is-xenial; then
test "$(find /etc/systemd/system -name 'snap.*.slice' | wc -l)" -gt 0
fi
restore: |
# during purge, there is no way to stop snap services running in user
# sessions, so take a best effort approach to kill all the processes which
# are in cgroups that resemble snap services in user sessions
find /sys/fs/cgroup/ -type d -path "*/user.slice/*/snap.*service" -prune | while read -r svc; do
while (("$(wc -l < "$svc/cgroup.procs" || echo 0)" > 0)); do
# for compatibility with v1/hybrid and old kernels not having cgroup.kill
if [ -f "$svc/cgroup.kill" ]; then
echo 1 > "$svc/cgroup.kill"
else
# shellcheck disable=SC2002
cat "$svc/cgroup.procs" | while read -r killpid; do
kill -9 "$killpid" || true
done
fi
sleep 1
done
rmdir "$svc" || true
done
#shellcheck source=tests/lib/pkgdb.sh
. "$TESTSLIB/pkgdb.sh"
if [ -e pkg-removed ]; then
distro_install_build_snapd
rm pkg-removed
fi
debug: |
systemctl --no-legend --full | grep -E 'snap\..*\.(service|timer|socket|slice)' || true
execute: |
echo "Stop snapd before purging"
systemctl stop snapd.service snapd.socket
echo "A purge will really purge things"
snapd.tool exec snap-mgmt --purge
touch pkg-removed
echo "Data directories are empty"
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
emptydirs="${SNAP_MOUNT_DIR} \
/var/snap \
/var/lib/snapd/dbus-1/services/ \
/var/lib/snapd/dbus-1/system-services/ \
/var/lib/snapd/desktop/applications/ \
/var/lib/snapd/seccomp/bpf/ \
/var/lib/snapd/device/ \
/var/lib/snapd/assertions/ \
/var/lib/snapd/cookie/ \
/var/lib/snapd/cache/ \
"
for d in $emptydirs ; do
n=$(find "$d" | wc -l)
if [ "$n" -gt 1 ]; then
echo "$d not empty after snap-mgmt.sh purge"
ls -lR "$d"
exit 1
fi
done
echo "State file is gone"
not test -f /var/lib/snapd/state.json
echo "And so is the system key"
not test -f /var/lib/snapd/system-key
echo "Preserved namespaces directory is not mounted"
NOMATCH "/run/snapd/ns" < /proc/mounts
systemctl daemon-reload
echo "Snap *.service files are removed"
systemctl list-unit-files --type service | NOMATCH '^snap.test-snapd-service.*\.service'
echo "Snap quota group slice files are removed"
systemctl list-unit-files --type slice | NOMATCH '^snap.group.slice'
echo "No dangling service symlinks are left behind"
test -z "$(find /etc/systemd/system/multi-user.target.wants/ -name 'snap.test-snapd-service.*')"
# shellcheck disable=SC2251
! test -d /etc/systemd/system/snapd.mounts.target.wants
# shellcheck disable=SC2251
! test -d /etc/systemd/system/multi-user.target.wants
test -z "$(find /etc/systemd/system/sockets.target.wants/ -name 'snap.*')"
test -z "$(find /etc/systemd/system/timers.target.wants/ -name 'snap.*')"
if ! os.query is-trusty; then
test -z "$(find /etc/systemd/user/default.target.wants/ -name 'snap.*')"
test -z "$(find /etc/systemd/user/sockets.target.wants/ -name 'snap.*')"
test -z "$(find /etc/systemd/user/timers.target.wants/ -name 'snap.*')"
fi
test "$(find /etc/udev/rules.d -name '*-snap.*.rules' | wc -l)" -eq 0
test "$(find /etc/dbus-1/system.d -name 'snap.*.conf' | wc -l)" -eq 0
test "$(find /etc/modules-load.d/ -name 'snap.*.conf' | wc -l)" -eq 0
test "$(find /etc/systemd/system -name 'snap.*.service' -a ! -name "snap.mount.service" | wc -l)" -eq 0
test "$(find /etc/systemd/system -name 'snap.*.timer' | wc -l)" -eq 0
test "$(find /etc/systemd/system -name 'snap.*.socket' | wc -l)" -eq 0
if ! os.query is-trusty; then
test "$(find /etc/systemd/user -name 'snap.*.service' | wc -l)" -eq 0
test "$(find /etc/systemd/user -name 'snap.*.timer' | wc -l)" -eq 0
test "$(find /etc/systemd/user -name 'snap.*.socket' | wc -l)" -eq 0
fi
|