Files
snapd/tests/main/command-chain/task.yaml
Maciej Borzecki 7e09dd8e08 tests/main: account for expected failures when running with SNAP_REEXEC=1
Account for expected failures when running with SNAP_REEXEC on unsupported
distros.

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-06-27 12:35:31 +02:00

70 lines
2.6 KiB
YAML

summary: Check that command-chain is properly supported
details: |
Verify the command-chain feature works as expected for hooks, apps, and
services. Rather than running the hook, app, or service directly, the
command-chain should be prefixed to the target command. Additionally verify
that the command-chain is executed when running a snap with `snap run
--shell`.
systems:
# uubuntu 32bit: test uses snap with base core20 which there is no 32bit
# variant of
- -ubuntu-*-32
environment:
# Ensure that running purely from the deb (without re-exec) works
# correctly
SNAP_REEXEC/reexec0: 0
SNAP_REEXEC/reexec1: 1
BREADCRUMB: /var/snap/command-chain/current/breadcrumb
ENVDUMP: /var/snap/command-chain/current/env
prepare: |
echo "Build command chain snap"
snap pack command-chain
snap install --dangerous command-chain_1.0_all.snap
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
if [ "$SNAP_REEXEC" = "1" ] && [ "$SNAP_MOUNT_DIR" != "/snap" ] && [ ! -L /snap ]; then
# reexec expects to find the snapd snap under /snap, enable it to do so
# on distros using /var/lib/snapd/snap
ln -sf "$SNAP_MOUNT_DIR" /snap
tests.cleanup defer rm -f /snap
fi
execute: |
echo "Test that command-chain runs for hooks"
[ "$(cat "$BREADCRUMB")" = "chain1 chain2 configure" ]
MATCH '^CHAIN_1_RAN=1$' < "$ENVDUMP"
MATCH '^CHAIN_2_RAN=1$' < "$ENVDUMP"
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
if [ "$SNAP_REEXEC" = "1" ] && [ "$SNAP_MOUNT_DIR" != "/snap" ]; then
# with snap mount dir different than /snap, internal s-c checks will fail
if command-chain.hello > err.out 2>&1 ; then
echo "unexpected success"
cat err.out || true
exit 1
fi
# with no AA support, we fail on a simple check for s-c being executed
# from /snap/snapd/<rev>/, with AA we fail on an earlier check for AA
# confinement
MATCH "(running from unexpected location:|snap-confine has elevated permissions)" < err.out
exit 0
fi
echo "Test that command-chain runs for apps"
[ "$(command-chain.hello)" = "chain1 chain2 hello" ]
echo "Test that command-chain runs for services"
# let the logs catch up
sleep 1
snap logs command-chain | MATCH 'chain3 chain4 running: 0 0 1 1$'
echo "Ensure that the command-chain is run with 'snap run --shell' as well"
[ "$(snap run --shell command-chain.hello -c 'echo "shell"')" = "chain1 chain2 shell" ]
env="$(snap run --shell command-chain.hello -c 'env')"
echo "$env" | MATCH '^CHAIN_1_RAN=1$'
echo "$env" | MATCH '^CHAIN_2_RAN=1$'