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
|
summary: Basic verification of socket-activated services.
details: |
This installs a snap which define sockets for systemd socket activation, and verifies
that basic start/stop works as intended for services that have socket activation.
environment:
CONFINEMENT/strict: strict
CONFINEMENT/classic: classic
prepare: |
case "$CONFINEMENT" in
classic)
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
if os.query is-core; then
# cannot install classic snaps on core
exit 0
elif [ "$SNAP_MOUNT_DIR" != "/snap" ] && [ ! -L /snap ]; then
# although classic snaps do not work out of the box on fedora,
# we still want to verify if the basics do work if the user
# symlinks /snap to $SNAP_MOUNT_DIR themselves
ln -sf "$SNAP_MOUNT_DIR" /snap
tests.cleanup defer rm -f /snap
fi
"$TESTSTOOLS"/snaps-state install-local socket-activation-classic --classic
;;
strict)
"$TESTSTOOLS"/snaps-state install-local socket-activation
;;
esac
restore: |
systemctl daemon-reload
execute: |
case "$CONFINEMENT" in
classic)
if os.query is-core; then
# cannot install classic snaps on core
exit 0
fi
;;
esac
[ -f /etc/systemd/system/snap.socket-activation.sleep-daemon.sock.socket ]
[ -S /var/snap/socket-activation/common/socket ]
verify_status() {
local ENABLED="$1"
local MAIN_ACTIVE="$2"
local ACT_ACTIVE="$3"
echo "Checking that services are listed correctly"
snap services | cat -n > svcs.txt
MATCH " 1\s+Service\s+Startup\s+Current\s+Notes$" < svcs.txt
MATCH " 2\s+socket-activation.sleep-daemon\s+${ENABLED}\s+${MAIN_ACTIVE}\s+socket-activated$" < svcs.txt
echo "Check that systemctl for the main unit is as expected"
systemctl show --property=UnitFileState snap.socket-activation.sleep-daemon.service | grep "static"
systemctl show --property=ActiveState snap.socket-activation.sleep-daemon.service | grep "ActiveState=${MAIN_ACTIVE}"
echo "Check that systemctl for the socket is looking correct too"
systemctl show --property=UnitFileState snap.socket-activation.sleep-daemon.sock.socket | grep "${ENABLED}"
systemctl show --property=ActiveState snap.socket-activation.sleep-daemon.sock.socket | grep "ActiveState=${ACT_ACTIVE}"
}
# verify default behavior on install is that the main service
# is inactive but enabled, and socket is active
verify_status "enabled" "inactive" "active"
# this will fail, but still start the service
echo "Start the primary unit, emulate that the trigger has run"
systemctl start snap.socket-activation.sleep-daemon.service
# verify that the main service is now active
verify_status "enabled" "active" "active"
# test normal restart
snap restart socket-activation
verify_status "enabled" "active" "active"
# test --reload restart, with --reload we expect different behavior
# because of systemd. Verify that systemd is acting like we expect
# as well
snap restart --reload socket-activation
verify_status "enabled" "active" "active"
systemctl reload-or-restart snap.socket-activation.sleep-daemon.sock.socket 2>&1 | MATCH "failed"
echo "Testing that we can stop will not disable the service"
snap stop socket-activation.sleep-daemon
verify_status "enabled" "inactive" "inactive"
echo "Testing that we can correctly disable activations"
snap stop --disable socket-activation.sleep-daemon
echo "Verifying that service is now listed as disabled"
verify_status "disabled" "inactive" "inactive"
echo "Starting the service will start the socket unit, but not enable"
snap start socket-activation.sleep-daemon
verify_status "disabled" "inactive" "active"
echo "Enable service and verify its listed as enabled"
snap start --enable socket-activation.sleep-daemon
verify_status "enabled" "inactive" "active"
|