summary: Checks for parallel installation of a local snap files details: | Snapd allows installation of the same snap more than once by combining the same snap name with different values of an instance key. The test installs a snap twice, and inspects that the applications can be invoked separately, obtain tailored environment variables which are aware of the difference in the instance key, read and write data to separate directories and that while the directories to not always show up as the instance-key-aware names on the inside of the snap execution environment, on the outside the names are indeed correct and do contain the instance key. In other words, the two applications are separate and have separate state. # ubuntu-14.04: the test sets up a user session, which requires more recent systemd systems: [-ubuntu-14.04-*] prepare: | # ensure we have no snap user data directory yet rm -rf /home/test/snap rm -rf /var/snap/test-snapd-sh /var/snap/test-snapd-sh_foo snap set system experimental.parallel-instances=true tests.session -u test prepare restore: | snap set system experimental.parallel-instances=null tests.session -u test restore execute: | "$TESTSTOOLS"/snaps-state install-local test-snapd-sh "$TESTSTOOLS"/snaps-state install-local-as test-snapd-sh test-snapd-sh_foo tests.session -u test exec sh -c '! test -d ~/snap/test-snapd-sh' tests.session -u test exec sh -c '! test -d ~/snap/test-snapd-sh_foo' tests.session -u test exec sh -c 'snap run test-snapd-sh_foo.sh -c "echo foo"' | MATCH foo tests.session -u test exec sh -c 'test -d ~/snap/test-snapd-sh' tests.session -u test exec sh -c 'test -d ~/snap/test-snapd-sh_foo' # instance environment variables are correctly set up tests.session -u test exec sh -c 'snap run test-snapd-sh_foo.sh -c "env"' test > snap_foo-env.txt MATCH 'SNAP_INSTANCE_NAME=test-snapd-sh_foo' < snap_foo-env.txt MATCH 'SNAP_NAME=test-snapd-sh' < snap_foo-env.txt MATCH 'SNAP_INSTANCE_KEY=foo' < snap_foo-env.txt MATCH 'SNAP=/snap/test-snapd-sh/x1' < snap_foo-env.txt MATCH 'SNAP_COMMON=/var/snap/test-snapd-sh/common' < snap_foo-env.txt MATCH 'SNAP_DATA=/var/snap/test-snapd-sh/x1' < snap_foo-env.txt MATCH 'SNAP_USER_DATA=/home/test/snap/test-snapd-sh_foo/x1' < snap_foo-env.txt MATCH 'SNAP_USER_COMMON=/home/test/snap/test-snapd-sh_foo/common' < snap_foo-env.txt # and non-instance one's are too tests.session -u test exec sh -c 'test-snapd-sh.sh -c env' test > snap-env.txt MATCH 'SNAP_INSTANCE_NAME=test-snapd-sh' < snap-env.txt MATCH 'SNAP_NAME=test-snapd-sh' < snap-env.txt MATCH 'SNAP_INSTANCE_KEY=$' < snap-env.txt MATCH 'SNAP=/snap/test-snapd-sh/x1' < snap-env.txt mkdir /var/snap/test-snapd-sh_foo/common/foobar echo canary-instance > /var/snap/test-snapd-sh_foo/common/foobar/data chown -R test:test /var/snap/test-snapd-sh_foo/common/foobar mkdir /var/snap/test-snapd-sh/common/foobar echo canary-regular > /var/snap/test-snapd-sh/common/foobar/data chown -R test:test /var/snap/test-snapd-sh/common/foobar echo "Make sure snap data writes and reads work" # instance can access its data tests.session -u test exec sh -c "snap run test-snapd-sh_foo.sh -c 'cat \$SNAP_COMMON/foobar/data'" | MATCH canary-instance # non-instance sees its data tests.session -u test exec sh -c "test-snapd-sh.sh -c 'cat \$SNAP_COMMON/foobar/data'" | MATCH canary-regular # instance can write data tests.session -u test exec sh -c "snap run test-snapd-sh_foo.sh -c 'echo hello from instance \$SNAP_INSTANCE_NAME > \$SNAP_COMMON/foobar/hello'" MATCH 'hello from instance test-snapd-sh_foo' < /var/snap/test-snapd-sh_foo/common/foobar/hello # and the file is not visible in non instance snap tests.session -u test exec sh -c "test-snapd-sh.sh -c 'cat \$SNAP_COMMON/foobar/hello || true'" 2>&1 | MATCH 'cat: /var/snap/test-snapd-sh/common/foobar/hello: No such file or directory' echo "Make sure snap user data writes work" echo canary-instance-snap > /home/test/snap/test-snapd-sh_foo/x1/canary chown test:test /home/test/snap/test-snapd-sh_foo/x1/canary echo canary-instance-common > /home/test/snap/test-snapd-sh_foo/common/canary chown test:test /home/test/snap/test-snapd-sh_foo/common/canary # instance snap can write to user data tests.session -u test exec sh -c "snap run test-snapd-sh_foo.sh -c 'echo hello user data from \$SNAP_INSTANCE_NAME > \$SNAP_USER_DATA/data'" MATCH 'hello user data from test-snapd-sh_foo' < /home/test/snap/test-snapd-sh_foo/x1/data # the file not present in non-instance snap data not test -f /home/test/snap/test-snapd-sh/x1/data # instance snap can write to common user data tests.session -u test exec sh -c "snap run test-snapd-sh_foo.sh -c 'echo hello user data from \$SNAP_INSTANCE_NAME > \$SNAP_USER_COMMON/data'" MATCH 'hello user data from test-snapd-sh_foo' < /home/test/snap/test-snapd-sh_foo/common/data # the file not present in non-instance snap data not test -f /home/test/snap/test-snapd-sh/common/data tests.session -u test exec sh -c "snap run test-snapd-sh_foo.sh -c 'cat \$SNAP_USER_COMMON/canary'" | MATCH canary-instance-common tests.session -u test exec sh -c "snap run test-snapd-sh_foo.sh -c 'cat \$SNAP_USER_DATA/canary'" | MATCH canary-instance-snap