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 (97 lines) | stat: -rw-r--r-- 4,090 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
summary: Ensure that `snap advise-snap` works

details: |
    `snap advise-snap` searches for a snap that provides the given
    command line or package name. This test verifies that the database
    downloaded from the store used by `advise-snap` is readable to all
    users. It verifies that it can lookup by both command lines and
    package name.  And it verifies that it can work as a replacement
    for `command-not-found`.

# On some slow external devices the test fails to restart snapd on restore
backends:
    - -external

# advise-snap / command-not-found only works on ubuntu classic, and on uc16
# on uc18+ we don't have the /usr/lib/command-not-found symlink so it's not
# useful
systems:
    - ubuntu-1*
    - ubuntu-2*
    - ubuntu-core-16*

prepare: |
    if ! os.query is-core16 && [ -e /usr/lib/command-not-found ]; then
        mv /usr/lib/command-not-found /usr/lib/command-not-found.orig
    fi
    if [ -e /etc/systemd/system/snapd.service.d/local.conf ]; then
        cp /etc/systemd/system/snapd.service.d/local.conf /etc/systemd/system/snapd.service.d/local.conf.bak
    fi
    mkdir -p /etc/systemd/system/snapd.service.d
    # enable catalog refresh requests
    cat <<EOF >> /etc/systemd/system/snapd.service.d/local.conf
    # added by snap-advise-command test
    [Service]
    Environment=SNAPD_CATALOG_REFRESH=1
    EOF
    systemctl daemon-reload
    systemctl restart snapd.socket

restore: |
    if [ -e /usr/lib/command-not-found.orig ]; then
        mv /usr/lib/command-not-found.orig /usr/lib/command-not-found
    fi
    if [ -e /etc/systemd/system/snapd.service.d/local.conf.bak ]; then
        mv /etc/systemd/system/snapd.service.d/local.conf.bak /etc/systemd/system/snapd.service.d/local.conf
    fi
    systemctl daemon-reload
    systemctl restart snapd.socket

execute: |
    echo "wait for snapd to pull in the commands data"
    echo "(it will do that on startup)"
    if ! retry -n 120 --wait 1 sh -c 'stat /var/cache/snapd/commands.db'; then
        # workaround for misbehaving store
        if "$TESTSTOOLS"/journal-state get-log -u snapd | MATCH "429 Too Many Requests"; then
            echo "Store is reporting 429 (too many requests), skipping the test"
            exit 0
        fi
        if "$TESTSTOOLS"/journal-state get-log -u snapd | MATCH "Catalog refresh failed: cannot retrieve sections"; then
            echo "Store is reporting catalog refresh failed: cannot retrieve the sections, skipping the test"
            exit 0
        fi
        if "$TESTSTOOLS"/journal-state get-log -u snapd | MATCH "cannot decode new commands catalog: got unexpected HTTP status code 403"; then
            echo "Store is reporting 403: cannot retrieve the sections, skipping the test"
            exit 0
        fi
        exit 1
    fi
    echo "Ensure the database is readable by a regular user"
    if [ "$(stat -c '%a' /var/cache/snapd/commands.db)" != "644" ]; then
        echo "incorrect permissions for /var/cache/snapd/commands.db"
        echo "expected 0644 got:"
        stat /var/cache/snapd/commands.db
        exit 1
    fi

    echo "Ensure 'snap advise-snap --command' lookup works"
    snap advise-snap --command test-snapd-tools.echo | MATCH test-snapd-tools

    echo "Ensure 'advise-snap --command' works as command-not-found symlink"
    # it's already this symlink on uc16, just use as-is there
    if ! os.query is-core16; then
        ln -s /usr/bin/snap /usr/lib/command-not-found    
    fi
    /usr/lib/command-not-found test-snapd-tools.echo | MATCH test-snapd-tools

    echo "Ensure short names are found too"
    snap advise-snap --command test_snapd_wellknown1 | MATCH '"test_snapd_wellknown1" not found, but can be installed with'

    echo "Ensure advise-snap without a match returns exit code 1"
    if snap advise-snap --command no-such-command-for-any-snap; then
        echo "A not-found snap command should return an error"
        exit 1
    fi

    echo "Ensure advise on snap pkg name advise also works"
    snap advise-snap test-snapd-tools | MATCH "Tools for testing the snapd application"