File: task.yaml

package info (click to toggle)
snapd 2.71-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 79,536 kB
  • sloc: ansic: 16,114; sh: 16,105; python: 9,941; makefile: 1,890; exp: 190; awk: 40; xml: 22
file content (101 lines) | stat: -rw-r--r-- 5,733 bytes parent folder | download | duplicates (2)
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: 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