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 (84 lines) | stat: -rw-r--r-- 2,779 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
summary: Ensure apt hooks work

details: |
    Verify the snap catalog is stored locally and apt command shows a
    message to install the snap with the same name of the requested deb

# apt hook only available on 18.04+ and aws-cli only for amd64
systems: [ubuntu-18.04-64, ubuntu-2*-64]

prepare: |
    cp /etc/systemd/system/snapd.service.d/local.conf /etc/systemd/system/snapd.service.d/local.conf.bak
    # enable catalog refresh requests
    cat <<EOF >> /etc/systemd/system/snapd.service.d/local.conf
    # added by apt-hooks test
    [Service]
    Environment=SNAPD_CATALOG_REFRESH=1
    EOF
    systemctl daemon-reload
    systemctl restart snapd.socket

restore: |
    mv /etc/systemd/system/snapd.service.d/local.conf.bak /etc/systemd/system/snapd.service.d/local.conf
    systemctl daemon-reload
    systemctl restart snapd.socket

debug: |
    ls -lh /var/cache/snapd
    # low tech dump of db
    strings /var/cache/snapd/commands.db | sed  -e 's#"}\(]\)\?#"}\1\n#g'
    
execute: |
    echo "Ensure we have a snap catalog in our cache"
    for _ in {1..30}; do
        if [ -s /var/cache/snapd/commands.db ]; then
            break
        fi
        sleep 1
    done

    if ! stat /var/cache/snapd/commands.db; then
        # workaround for misbehaving store
        if "$TESTSTOOLS"/journal-state get-log -u snapd | grep -E "(429 Too Many Requests|403 Forbidden)"; then
            echo "Store is reporting 429 (too many requests) or 403, 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
        exit 1
    fi

    echo "Creating expected file"
    cat > expected <<EOF

    WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
    
    No apt package "aws-cli", but there is a snap with that name.
    Try "snap install aws-cli"
    
    EOF
    if os.query is-ubuntu-ge 25.04; then
        echo "Error: Unable to locate package aws-cli" >> expected
    else
        echo "E: Unable to locate package aws-cli" >> expected
    fi

    echo "Checking apt hook"
    if apt install -qq aws-cli > out 2>&1; then
        res=$?
        echo "apt should return a non-zero exit code but it returned $res"
        exit 1
    fi

    echo "Verify the result"
    diff -uB out expected

    echo "Ensure that apt install does not show any errors from the hook"
    apt install -o Apt::Cmd::Disable-Script-Warning=true -qq -s petname 2>apt.stderr
    if [ "$(cat apt.stderr)" != "" ]; then
        echo "Errors when doing an apt install"
        cat apt.stderr
        exit 1
    fi