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
|
summary: Check that own services can be controlled by snapctl
details: |
Snaps should be able to control their own services via snapctl.
This test verifies that this is the case by installing a snap with multiple
services and a configure hook which allows for two capabilities:
1. Controlling one of those services via snapctl according to the command
to which the `command` configuration is set.
2. Setting another service option via snapctl according to the value of the
`service-option-source` configuration which is itself retrieved via snapctl.
The test then verifies the following:
1. After installing, the service is initially running.
2. Changing the configuration to stop, start, stop, and restart each result
in the service being controlled accordingly via snapctl.
3. When the configuration was set to restart, the restart command was
executed as part of the change associated with the configure hook.
4. The `service-option-source` configuration can be successfully retrieved
in a configure hook via snapctl and used to set another option via snapctl
as well.
5. Reinstalling the snap with the configure hook set to call
`snapctl restart` results in the snap being successfully reinstalled and
the service successfully restarted.
# takes >1.5min to run
backends: [-autopkgtest]
kill-timeout: 10m
environment:
SERVICEOPTIONFILE: /var/snap/test-snapd-service/current/service-option
restore: |
rm -f "$SERVICEOPTIONFILE"
snap remove --purge test-snapd-service || true
execute: |
_wait_for_service() {
retry=5
while ! snap services "$1" | MATCH "$2"; do
retry=$(( retry - 1 ))
if [ $retry -le 0 ]; then
echo "Failed to match the status of service $1, expected: $2"
exit 1
fi
sleep 1
done
}
echo "When the service snap is installed"
"$TESTSTOOLS"/snaps-state install-local test-snapd-service
echo "We can see it running"
_wait_for_service "test-snapd-service.test-snapd-service" " active"
echo "When we stop the service via configure hook"
snap set test-snapd-service command=stop
echo "It's stopped"
_wait_for_service "test-snapd-service.test-snapd-service" " inactive"
echo "When we start the service via configure hook"
snap set test-snapd-service command=start
echo "It's running again"
_wait_for_service "test-snapd-service.test-snapd-service" " active"
echo "When we stop it again"
snap set test-snapd-service command=stop
echo "It's stopped"
_wait_for_service "test-snapd-service.test-snapd-service" " inactive"
echo "And then restart"
snap set test-snapd-service service-option-source=foo command=restart
echo "It's running"
_wait_for_service "test-snapd-service.test-snapd-service" " active"
echo "And restart command was executed as part of configure hook change"
snap tasks --last=configure|MATCH -z "restart of .test-snapd-service.test-snapd-service.+restart of .test-snapd-service.test-snapd-other-service"
echo "And service could get the new service-option set from the hook"
retry -n 5 --wait 1 MATCH '^foo$' "$SERVICEOPTIONFILE"
echo "Reinstalling the snap with configure hook calling snapctl restart works"
snap set test-snapd-service command=restart
"$TESTSTOOLS"/snaps-state install-local test-snapd-service
# shellcheck disable=SC2119
if "$TESTSTOOLS"/journal-state get-log | MATCH "error: snapctl"; then
echo "snapctl should not report errors"
exit 1
fi
|