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
|
summary: Check basic functionality when memory cgroup is disabled
details: |
Check that when memory cgroups is disabled by adding cgroup_disable=memory
to the kernel command line, then updating quota groups does not work and
the installed snaps still have the Slice setting. Verify also that the
snaps can be refreshed (preserving the Slice setting) and removed.
# external backends fails because a signed gadget cannot be replaced
# with an unsigned one
# TODO: remove once https://github.com/snapcore/snapd/pull/11589 landed
backends: [-external]
# only run on UC20+ to use the convenient cmdline.extra file
systems: [ubuntu-core-2*]
environment:
SVC_UNIT: /etc/systemd/system/snap.test-snapd-simple-service.test-snapd-simple-service.service
prepare: |
if not os.query is-pc-amd64; then
echo "Skipping non-grub device test"
exit 0
fi
echo "Create copy of gadget snap with cgroup_disable=memory set in cmdline.extra"
PC_REV=$(snap list pc | tail -n +2 | awk '{print $3}')
sudo cp "/var/lib/snapd/snaps/pc_$PC_REV.snap" pc-gadget.snap
unsquashfs -d pc-gadget-no-cgroup pc-gadget.snap
# check if there is already a cmdline.extra or cmdline.full and append to it
# if it's there
if [ -f pc-gadget-no-cgroup/cmdline.full ]; then
# use the cmdline.full file
echo "" >> pc-gadget-no-cgroup/cmdline.full
echo "cgroup_disable=memory" >> pc-gadget-no-cgroup/cmdline.full
else
# either no file at all or cmdline.extra
echo "" >> pc-gadget-no-cgroup/cmdline.extra
echo "cgroup_disable=memory" >> pc-gadget-no-cgroup/cmdline.extra
fi
snap pack pc-gadget-no-cgroup --filename=pc-cgroup-disabled.snap
# make sure that the snapd daemon gives us time for comms before
# closing the socket
sed -i '/^Environment=/ s/$/ SNAPD_SHUTDOWN_DELAY=1/' /etc/systemd/system/snapd.service.d/local.conf
systemctl restart snapd
restore: |
# remove SNAPD_SHUTDOWN_DELAY again
sed -i 's/SNAPD_SHUTDOWN_DELAY=1//g' /etc/systemd/system/snapd.service.d/local.conf
systemctl restart snapd
execute: |
if not os.query is-pc-amd64; then
echo "Skipping non-grub device test"
exit 0
fi
case "$SPREAD_REBOOT" in
0)
# ensure memory cgroups is enabled to start
if [ "$(grep memory < /proc/cgroups | awk '{print $4}')" != "1" ]; then
echo "expected memory cgroup to be enabled to start"
exit 1
fi
# install a snap with a service
"$TESTSTOOLS"/snaps-state install-local test-snapd-simple-service
# put it in a quota group
snap set-quota grp --memory=100MB test-snapd-simple-service
# check it is in the slice
MATCH Slice=snap.grp.slice < "$SVC_UNIT"
# now disable the memory cgroup by adding cgroup_disable=memory to the
# kernel command line
snap install --dangerous pc-cgroup-disabled.snap
REBOOT
;;
1)
# wait for change to complete
snap watch --last=install\?
# ensure memory cgroups is now disabled
if [ "$(grep memory < /proc/cgroups | awk '{print $4}')" != "0" ]; then
echo "expected memory cgroup to be disabled"
exit 1
fi
# we cannot check quota group usage
if snap quota grp; then
echo "expected quota command to fail"
exit 1
fi
# and we get the expected error message
snap quota grp 2>&1 | MATCH "error: memory usage unavailable"
# updating quota groups does not work and gives a useful error message
snap set-quota --memory=200MB grp 2>&1 | tr -s "\n " " " | MATCH 'error: cannot update quota group: cannot update group "grp": cannot use memory quota: cgroup memory controller is disabled on this system'
# make sure our snap still has the Slice setting
MATCH Slice=snap.grp.slice < "$SVC_UNIT"
# we can refresh the snap still even though memory cgroup is disabled
"$TESTSTOOLS"/snaps-state install-local test-snapd-simple-service
# and still has the slice setting
MATCH Slice=snap.grp.slice < "$SVC_UNIT"
# TODO: should we also check the vitality-rank config too?
# finally we can still remove the snap without issue
snap remove test-snapd-simple-service
# revert back to normal pc gadget without the command line
snap revert pc
REBOOT
;;
2)
# wait for change to complete
snap watch --last=revert\?
# ensure memory cgroups is enabled again
if [ "$(grep memory < /proc/cgroups | awk '{print $4}')" != "1" ]; then
echo "expected memory cgroup to be enabled after revert"
exit 1
fi
# ensure quota commands don't error
snap quota grp | NOMATCH "error: memory usage unavailable"
;;
esac
|