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: inspect all the set environment variables prefixed with SNAP_ and XDG_
details: |
Environment variables are widely used across Linux to provide convenient access to system
and application properties. Snapd uses specific environment variables to support running
snaps.
This test verifies that all the environment variables used by snapd start with
SNAP_, XDG_ and EXTRA_ and their content is what we expect. Also it is checked
that SNAP, PATH and HOME env vars have the expected content.
environment:
NAME/regular: test-snapd-tools
INSTANCE_KEY/regular: ""
NAME/parallel: test-snapd-tools_foo
INSTANCE_KEY/parallel: foo
prepare: |
if [[ "$SPREAD_VARIANT" == "parallel" ]]; then
snap set system experimental.parallel-instances=true
fi
"$TESTSTOOLS"/snaps-state install-local-as test-snapd-tools "$NAME"
restore: |
if [[ "$SPREAD_VARIANT" == "parallel" ]]; then
snap set system experimental.parallel-instances=null
fi
debug: |
find . -name '*-vars.txt' -exec cat {} \;
execute: |
echo "Collect SNAP and XDG environment variables"
"$NAME".env | grep -E '^SNAP_' | sort > snap-vars.txt
"$NAME".env | grep -E '^XDG_' | sort > xdg-vars.txt
"$NAME".env | grep -E '^EXTRA_' | sort > extra-vars.txt
echo "Collect PATH, HOME and SHELL environment variables"
"$NAME".env | grep -E '^(SNAP|PATH|HOME|SHELL)=' | sort > misc-vars.txt
SHELL=/bin/sh "$NAME".env | grep -E '^SHELL=' | sort > custom-sh-vars.txt
echo "Ensure that SNAP environment variables are what we expect"
MATCH '^SNAP_ARCH=(amd64|arm64|armhf|ppc64el|s390x)$' < snap-vars.txt
# parallel-installs: global snap directories are remapped to $SNAP_NAME
MATCH '^SNAP_COMMON=/var/snap/test-snapd-tools/common$' < snap-vars.txt
MATCH '^SNAP_DATA=/var/snap/test-snapd-tools/x1$' < snap-vars.txt
MATCH '^SNAP_LIBRARY_PATH=/var/lib/snapd/lib/gl:/var/lib/snapd/lib/gl32:/var/lib/snapd/void$' < snap-vars.txt
# XXX: probably not something we ought to test
# egrep -q '^SNAP_REEXEC=0$' snap-vars.txt
MATCH '^SNAP_REVISION=x1$' < snap-vars.txt
# parallel-installs: user directories are instance specific
MATCH "^SNAP_USER_COMMON=/root/snap/$NAME/common$" < snap-vars.txt
MATCH "^SNAP_USER_DATA=/root/snap/$NAME/x1$" < snap-vars.txt
MATCH '^SNAP_VERSION=1.0$' < snap-vars.txt
CTX=$(cat "/var/lib/snapd/cookie/snap.$NAME")
MATCH "^SNAP_COOKIE=$CTX" < snap-vars.txt
MATCH "^SNAP_CONTEXT=$CTX" < snap-vars.txt
# parallel-installs: $SNAP_NAME is always _the_ snap name
MATCH '^SNAP_NAME=test-snapd-tools$' < snap-vars.txt
# parallel-install: name of a particular instance
MATCH "^SNAP_INSTANCE_NAME=$NAME$" < snap-vars.txt
# parallel-installs: empty if none is set
MATCH "^SNAP_INSTANCE_KEY=$INSTANCE_KEY$" < snap-vars.txt
MATCH "^SNAP_REAL_HOME=/root$" < snap-vars.txt
MATCH "^SNAP_UID=0$" < snap-vars.txt
MATCH "^SNAP_EUID=0$" < snap-vars.txt
# if on UC20+, then we should see an additional variable (SNAP_SAVE_DATA)
if [[ "$SPREAD_SYSTEM" == ubuntu-core-2* ]]; then
MATCH "^SNAP_SAVE_DATA=/var/lib/snapd/save/snap/$NAME$" < snap-vars.txt
# 18 variables are expected on ubuntu-core
test "$(wc -l < snap-vars.txt)" -eq 18
else
# 17 variables are expected on non ubuntu-core
test "$(wc -l < snap-vars.txt)" -eq 17
fi
echo "Ensure that XDG environment variables are what we expect"
# parallel-installs: xdg directory is instance specific
MATCH "^XDG_RUNTIME_DIR=/run/user/0/snap.$NAME$" < xdg-vars.txt
test "$(wc -l < xdg-vars.txt)" -ge 1
echo "Enure that EXTRA environment variables are what we expect"
MATCH '^EXTRA_GLOBAL=extra-global' < extra-vars.txt
MATCH '^EXTRA_LOCAL=extra-local' < extra-vars.txt
MATCH '^EXTRA_LOCAL_NESTED=extra-global-nested' < extra-vars.txt
MATCH "^EXTRA_CACHE_DIR=$HOME/snap/$NAME/x1/.cache" < extra-vars.txt
MATCH '^EXTRA_LOCAL_PATH=/snap/test-snapd-tools/x1/bin:/snap/test-snapd-tools/x1/usr/bin:/usr/bin' < extra-vars.txt
test "$(wc -l < extra-vars.txt)" -eq 5
echo "Ensure that TMPDIR is not passed through to a confined snap"
TMPDIR=/foobar "$NAME".env | grep -qv ^TMPDIR=
echo "Ensure that SNAP, PATH and HOME are what we expect"
# parallel-installs: $SNAP is remapped to appear under $SNAP_NAME
MATCH "^SNAP=/snap/test-snapd-tools/x1$" < misc-vars.txt
MATCH '^PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games$' < misc-vars.txt
MATCH '^SHELL=/bin/bash$' < misc-vars.txt
MATCH '^SHELL=/bin/bash$' < custom-sh-vars.txt
# parallel-installs: $HOME is set to instance specific path
MATCH "^HOME=/root/snap/$NAME/x1$" < misc-vars.txt
test "$(wc -l < misc-vars.txt)" -eq 4
|