File: task.yaml

package info (click to toggle)
snapd 2.72-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,412 kB
  • sloc: sh: 16,506; ansic: 16,211; python: 11,213; makefile: 1,919; exp: 190; awk: 58; xml: 22
file content (131 lines) | stat: -rw-r--r-- 6,425 bytes parent folder | download | duplicates (3)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
summary: Check that the basic snapshots functionality works for different users

details: |
    This test checks that the basic snapshots functionality works for different
    users. It runs through a series of operations that create, restore, and
    remove snapshots for both the root and test users.

# ubuntu-14.04: the test sets up a user session, which requires more recent systemd
systems: [-ubuntu-14.04-*]

prepare: |
    snap install test-snapd-sh
    tests.session -u test prepare

restore: |
    tests.session -u test restore

execute: |
    # use the snaps, so they create the dirs
    test-snapd-sh.sh -c 'true'
    SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
    tests.session -u test exec sh -c "$SNAP_MOUNT_DIR/bin/test-snapd-sh.sh -c 'true'" test

    # drop in canaries for both users
    echo "hello versioned test-snapd-sh"  > /root/snap/test-snapd-sh/current/canary.txt
    echo "hello common test-snapd-sh" > /root/snap/test-snapd-sh/common/canary.txt
    echo "hello versioned test-snapd-sh"  > /home/test/snap/test-snapd-sh/current/canary.txt
    echo "hello common test-snapd-sh" > /home/test/snap/test-snapd-sh/common/canary.txt

    # create different snapshots for each user
    SET_ID_ROOT=$( snap save --users=root test-snapd-sh | cut -d\  -f1 | tail -n1 )
    SET_ID_TEST=$( snap save --users=test test-snapd-sh | cut -d\  -f1 | tail -n1 )

    # Update content on canary files
    echo "content updated"  > /root/snap/test-snapd-sh/current/canary.txt
    echo "content updated" > /root/snap/test-snapd-sh/common/canary.txt
    echo "content updated"  > /home/test/snap/test-snapd-sh/current/canary.txt
    echo "content updated" > /home/test/snap/test-snapd-sh/common/canary.txt

    # create snapshots for both users
    SET_ID_BOTH=$( snap save --users=root,test test-snapd-sh | cut -d\  -f1 | tail -n1 )

    # Add more files and dirs for the test user and save snapshot for both users
    mkdir -p /home/test/snap/test-snapd-sh/current/canary/
    echo "content updated"  > /home/test/snap/test-snapd-sh/current/canary/canary.txt
    SET_ID_NONE=$( snap save test-snapd-sh | cut -d\  -f1 | tail -n1 )

    # check all the snapshots include the correct snap
    snap saved --id="$SET_ID_ROOT" | MATCH test-snapd-sh
    snap saved --id="$SET_ID_TEST" | MATCH test-snapd-sh
    snap saved --id="$SET_ID_BOTH" | MATCH test-snapd-sh
    snap saved --id="$SET_ID_NONE" | MATCH test-snapd-sh

    # check the snapshots
    snap check-snapshot "$SET_ID_ROOT"
    snap check-snapshot "$SET_ID_TEST"
    snap check-snapshot "$SET_ID_BOTH"
    snap check-snapshot "$SET_ID_NONE"

    # remove the canaries for both users
    rm -f /root/snap/test-snapd-sh/{current,common}/canary.txt
    rm -f /home/test/snap/test-snapd-sh/{current,common}/canary.txt

    # restore the snapshot for the root user and check the files
    snap restore "$SET_ID_ROOT" test-snapd-sh
    MATCH "hello versioned test-snapd-sh" < /root/snap/test-snapd-sh/current/canary.txt
    MATCH "hello common test-snapd-sh" < /root/snap/test-snapd-sh/common/canary.txt
    test ! -e /home/test/snap/test-snapd-sh/current/canary.txt
    test ! -e /home/test/snap/test-snapd-sh/common/canary.txt
    MATCH "content updated" < /home/test/snap/test-snapd-sh/current/canary/canary.txt

    # restore the snapshot for the test user and check the files
    snap restore "$SET_ID_TEST" test-snapd-sh
    MATCH "hello versioned test-snapd-sh" < /home/test/snap/test-snapd-sh/current/canary.txt
    MATCH "hello common test-snapd-sh" < /home/test/snap/test-snapd-sh/common/canary.txt
    test ! -d /home/test/snap/test-snapd-sh/current/canary

    # remove the canaries for both users
    rm -f /root/snap/test-snapd-sh/{current,common}/canary.txt
    rm -f /home/test/snap/test-snapd-sh/{current,common}/canary.txt

    # restore the snapshot for both users and check the files
    snap restore "$SET_ID_BOTH" test-snapd-sh
    MATCH "content updated" < /root/snap/test-snapd-sh/current/canary.txt
    MATCH "content updated" < /root/snap/test-snapd-sh/common/canary.txt
    MATCH "content updated" < /home/test/snap/test-snapd-sh/current/canary.txt
    MATCH "content updated" < /home/test/snap/test-snapd-sh/common/canary.txt
    test ! -d /home/test/snap/test-snapd-sh/current/canary

    # remove the canaries for both users
    rm -f /root/snap/test-snapd-sh/{current,common}/canary.txt
    rm -f /home/test/snap/test-snapd-sh/{current,common}/canary.txt

    # restore the snapshot for root user and check the files
    snap restore "$SET_ID_BOTH" --users=root
    MATCH "content updated" < /root/snap/test-snapd-sh/current/canary.txt
    MATCH "content updated" < /root/snap/test-snapd-sh/common/canary.txt
    test ! -e /home/test/snap/test-snapd-sh/current/canary.txt
    test ! -e /home/test/snap/test-snapd-sh/common/canary.txt
    test ! -d /home/test/snap/test-snapd-sh/current/canary

    # remove the canaries for both users
    rm -f /root/snap/test-snapd-sh/{current,common}/canary.txt
    rm -f /home/test/snap/test-snapd-sh/{current,common}/canary.txt

    # restore the snapshot for test user and check the files
    snap restore "$SET_ID_NONE" --users=test
    test ! -e /root/snap/test-snapd-sh/current/canary.txt
    test ! -e /root/snap/test-snapd-sh/common/canary.txt
    MATCH "content updated" < /home/test/snap/test-snapd-sh/current/canary.txt
    MATCH "content updated" < /home/test/snap/test-snapd-sh/common/canary.txt
    MATCH "content updated" < /home/test/snap/test-snapd-sh/current/canary/canary.txt

    # remove the canaries for both users
    rm -f /root/snap/test-snapd-sh/{current,common}/canary.txt
    rm -rf /home/test/snap/test-snapd-sh/{current,common,current/canary}/canary.txt

    # restore the snapshot for both user and check the files
    snap restore "$SET_ID_NONE" --users=test,root
    MATCH "content updated" < /root/snap/test-snapd-sh/current/canary.txt
    MATCH "content updated" < /root/snap/test-snapd-sh/common/canary.txt
    MATCH "content updated" < /home/test/snap/test-snapd-sh/current/canary.txt
    MATCH "content updated" < /home/test/snap/test-snapd-sh/common/canary.txt
    MATCH "content updated" < /home/test/snap/test-snapd-sh/current/canary/canary.txt

    # check removal works
    snap forget "$SET_ID_NONE"
    snap saved --id="$SET_ID_NONE" | grep "No snapshots found"
    snap forget "$SET_ID_ROOT"
    snap forget "$SET_ID_TEST"
    snap forget "$SET_ID_BOTH"