File: task.yaml

package info (click to toggle)
snapd 2.74.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 81,428 kB
  • sloc: sh: 16,966; ansic: 16,788; python: 11,332; makefile: 1,897; exp: 190; awk: 58; xml: 22
file content (150 lines) | stat: -rw-r--r-- 7,881 bytes parent folder | download
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
summary: Check parallel installation of sideloaded snaps containing services

details: |
    Check that snaps with services can have parallel installations and that
    removing one instance does not affect the others.

# takes >3min to run
backends: [-autopkgtest]

prepare: |
    snap set system experimental.parallel-instances=true

restore: |
    snap remove --purge test-snapd-service || true
    snap remove --purge test-snapd-service_foo || true
    snap remove --purge test-snapd-service_longname || true
    snap unset system experimental.parallel-instances

execute: |
    "$TESTSTOOLS"/snaps-state install-local test-snapd-service

    check_services_active() {
       test -n "$1"
       systemctl is-active "snap.$1.test-snapd-service.service"
       systemctl is-active "snap.$1.test-snapd-other-service.service"
    }

    function service_start_time {
        systemctl show --property=ExecMainStartTimestampMonotonic "$1" | cut -d= -f2
    }

    SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
    for instance in foo longname; do
        echo "Install a snap as instance named test-snapd-service_$instance"
        expected="^test-snapd-service_$instance 1.0 installed\$"
        "$TESTSTOOLS"/snaps-state install-local-as test-snapd-service "test-snapd-service_$instance" | MATCH "$expected"

        test -d "$SNAP_MOUNT_DIR/test-snapd-service_$instance/x1"

        test -f /etc/systemd/system/snap.test-snapd-service_$instance.test-snapd-service.service
        test -f /etc/systemd/system/snap.test-snapd-service_$instance.test-snapd-other-service.service
        check_services_active "test-snapd-service_$instance"
    done

    check_services_active test-snapd-service

    echo "All snaps are listed"
    snap list | MATCH '^test-snapd-service '
    snap list | MATCH '^test-snapd-service_foo '
    snap list | MATCH '^test-snapd-service_longname '

    echo "Ensure we can use snapctl to stop a service of the main installation, but not affect others"
    snap run --shell test-snapd-service -c "snapctl stop test-snapd-service.test-snapd-other-service"
    systemctl is-active snap.test-snapd-service.test-snapd-other-service | MATCH "inactive"
    systemctl is-active snap.test-snapd-service_foo.test-snapd-other-service | MATCH "^active"
    systemctl is-active snap.test-snapd-service_longname.test-snapd-other-service | MATCH "^active"

    echo "Ensure we can start it again"
    snap run --shell test-snapd-service -c "snapctl start test-snapd-service.test-snapd-other-service"
    systemctl is-active snap.test-snapd-service.test-snapd-other-service | MATCH "^active"
    systemctl is-active snap.test-snapd-service_foo.test-snapd-other-service | MATCH "^active"
    systemctl is-active snap.test-snapd-service_longname.test-snapd-other-service | MATCH "^active"

    echo "Ensure we can use snapctl to stop a service in parallel installs without affecting others"
    for instance in foo longname; do
        echo "Testing stop of test-snapd-service_$instance"
        systemctl is-active "snap.test-snapd-service_${instance}.test-snapd-other-service" | MATCH "^active"
        snap run --shell test-snapd-service_${instance} -c "snapctl stop test-snapd-service_${instance}.test-snapd-other-service"
        systemctl is-active "snap.test-snapd-service_${instance}.test-snapd-other-service" | MATCH "inactive"
    done

    echo "Verifying the main install should be unaffected after stop"
    systemctl is-active snap.test-snapd-service.test-snapd-other-service | MATCH "^active"

    for instance in foo longname; do
        echo "Testing start of test-snapd-service_$instance"
        systemctl is-active "snap.test-snapd-service_${instance}.test-snapd-other-service" | MATCH "inactive"
        snap run --shell test-snapd-service_${instance} -c "snapctl start test-snapd-service_${instance}.test-snapd-other-service"
        systemctl is-active "snap.test-snapd-service_${instance}.test-snapd-other-service" | MATCH "^active"
    done

    svc_other_nokey="$(service_start_time snap.test-snapd-service.test-snapd-other-service)"
    svc_other_foo="$(service_start_time snap.test-snapd-service_foo.test-snapd-other-service)"

    echo "Verifying snap can only manage its own services"
    snap run --shell test-snapd-service_foo -c "snapctl restart test-snapd-service_longname.test-snapd-other-service" |& \
        MATCH 'snapctl: unexpected snap instance key: "longname"'
    snap run --shell test-snapd-service_foo -c "snapctl restart other-snap.test-snapd-other-service" |& \
        MATCH 'snapctl: unknown service: "other-snap.test-snapd-other-service"'
    echo "But requests to manage snap name services are silently remapped to instance specific ones"
    snap run --shell test-snapd-service_foo -c "snapctl restart test-snapd-service.test-snapd-other-service"

    svc_other_nokey_after="$(service_start_time snap.test-snapd-service.test-snapd-other-service)"
    svc_other_foo_after="$(service_start_time snap.test-snapd-service_foo.test-snapd-other-service)"
    # test-snapd-service.other-service was not restarted
    test "$svc_other_nokey_after" = "$svc_other_nokey"
    # but test-snapd-service_foo.other-service was
    test "$svc_other_foo_after" -gt "$svc_other_foo"

    echo "Service statuses of all services are reported"
    snap run --shell test-snapd-service_foo -c "snapctl services" |\
        tee no-name.statuses
    MATCH "test-snapd-service_foo.test-snapd-other-service .* active" < no-name.statuses

    echo ".. when using aliased snap name"
    snap run --shell test-snapd-service_foo -c "snapctl services test-snapd-service" |\
        tee aliased.statuses
    # the names re remapped back in the output
    MATCH "test-snapd-service.test-snapd-other-service .* active" < aliased.statuses

    echo ".. when using explicit snap instance name"
    snap run --shell test-snapd-service_foo -c "snapctl services test-snapd-service_foo" |\
        tee explicit.statuses
    MATCH "test-snapd-service_foo.test-snapd-other-service .* active" < explicit.statuses

    # the contents are the same
    diff no-name.statuses explicit.statuses
    # but these will obviously be different
    not diff aliased.statuses explicit.statuses

    echo "And for single service queries"
    snap run --shell test-snapd-service_foo -c "snapctl services test-snapd-service.test-snapd-other-service" |\
        tee single-aliased.statuses
    MATCH "test-snapd-service.test-snapd-other-service .* active" < single-aliased.statuses

    echo ".. when using explicit snap instance name"
    snap run --shell test-snapd-service_foo -c "snapctl services test-snapd-service_foo.test-snapd-other-service" |\
        tee single-explicit.statuses
    MATCH "test-snapd-service_foo.test-snapd-other-service .* active" < single-explicit.statuses

    not diff single-aliased.statuses single-explicit.statuses

    echo "Removing one instance does not remove services from other instances"
    snap remove --purge test-snapd-service_foo
    not test -f /etc/systemd/system/snap.test-snapd-service_foo.test-snapd-service.service
    test -f /etc/systemd/system/snap.test-snapd-service_longname.test-snapd-service.service
    test -f /etc/systemd/system/snap.test-snapd-service.test-snapd-service.service

    echo "The services of remaining snaps are still active"
    check_services_active test-snapd-service
    check_services_active test-snapd-service_longname

    snap remove --purge test-snapd-service
    not test -f /etc/systemd/system/snap.test-snapd-service.test-snapd-service.service
    test -f /etc/systemd/system/snap.test-snapd-service_longname.test-snapd-service.service
    echo "The services of remaining snap are active"
    check_services_active test-snapd-service_longname

    snap remove --purge test-snapd-service_longname
    not test -f /etc/systemd/system/snap.test-snapd-service_longname.test-snapd-service.service