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 (112 lines) | stat: -rw-r--r-- 5,165 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
102
103
104
105
106
107
108
109
110
111
112
summary: smoke test for the snapd-state test tool

details: |
    The snapd-state tool is used in tests to manage the snapd state by editing
    the state.json file. 

    This test verifies the different functionalities provided by such tool.

backends: [google, qemu]

prepare: |
    snap install test-snapd-tools

debug: |
    # GCE does not always NTP sync, try to figure out why here
    # (LP: 1949886)
    systemctl status systemd-timedated || true
    journalctl -u systemd-timedated || true
    timedatectl || true

execute: |
    # Check help
    "$TESTSTOOLS"/snapd-state | MATCH "usage: check-state <jq-filter>"
    "$TESTSTOOLS"/snapd-state -h | MATCH "usage: check-state <jq-filter>"
    "$TESTSTOOLS"/snapd-state --help | MATCH "usage: check-state <jq-filter>"

    # Unknown commands and options are reported
    "$TESTSTOOLS"/snapd-state --foo 2>&1 | MATCH "snapd-state: no such command: --foo"
    "$TESTSTOOLS"/snapd-state foo 2>&1 | MATCH "snapd-state: no such command: foo"

    function check_date() {
        local TEST_DATE="$1"
        # The tolerance is the maximun since the snapd state is backed up when the suite
        # is prepared. In case of external backend that time could be until 12 hours.
        # In case of the google backend the tolerance time could be until 90 minutes
        local TOLERANCE_SECONDS
        if [ "$SPREAD_BACKEND" = "external" ]; then
            TOLERANCE_SECONDS=43200 # 60s*60m*12h=43200
        else
            TOLERANCE_SECONDS=5400 # 60s*90m=5400
        fi
        local TEST_TIMESTAMP CURRENT_TIMESTAMP

        TEST_TIMESTAMP=$(date +'%s' --date="${TEST_DATE}")
        CURRENT_TIMESTAMP="$(date +'%s')"
        if ((TEST_TIMESTAMP < CURRENT_TIMESTAMP - TOLERANCE_SECONDS || TEST_TIMESTAMP > CURRENT_TIMESTAMP)); then
            echo "Time $TEST_DATE too far from current time ($(date --iso-8601=seconds))"
            exit 1
        fi
    }

    # Check print state command
    current_date="$("$TESTSTOOLS"/snapd-state print-state '.data["last-refresh"]')"
    check_date "$current_date"

    # Check check state command
    "$TESTSTOOLS"/snapd-state check-state '.data["last-refresh"]' = "$current_date"
    "$TESTSTOOLS"/snapd-state check-state '.data["last-refresh"]' != "$(date +'%F')"
    output="$("$TESTSTOOLS"/snapd-state check-state '.data["last-refresh"]' = "$current_date")"
    test -z "$output"

    "$TESTSTOOLS"/snapd-state check-state '.data["last-refresh"]' = "$(date +'%F')" "ErrorOnTest" 2>&1 | MATCH "ErrorOnTest"
    "$TESTSTOOLS"/snapd-state check-state '.data["last-refresh"]' != "$current_date" "ErrorOnTest" 2>&1 | MATCH "ErrorOnTest"

    # must remove refresh holds for autorefresh command to succeed
    snap set system refresh.hold!

    # check how snap channel is changed    
    current_channel="$("$TESTSTOOLS"/snapd-state print-state '.data.snaps["test-snapd-tools"].channel')"
    test "$current_channel" = latest/stable
    "$TESTSTOOLS/snapd-state" change-snap-channel test-snapd-tools edge
    new_channel="$("$TESTSTOOLS"/snapd-state print-state '.data.snaps["test-snapd-tools"].channel')"
    test "$new_channel" = edge

    # check force autorefresh command
    "$TESTSTOOLS"/snapd-state force-autorefresh
    new_refresh_date="$("$TESTSTOOLS"/snapd-state print-state '.data["last-refresh"]')"
    echo "$new_refresh_date" | MATCH "^2007-08-22"

    # check prevent autorefresh command
    "$TESTSTOOLS"/snapd-state prevent-autorefresh
    new_refresh_date="$("$TESTSTOOLS"/snapd-state print-state '.data["last-refresh"]')"
    check_date "$new_refresh_date"

    # check wait-for-snap-autorefresh command
    systemctl stop snapd.{service,socket}
    "$TESTSTOOLS"/snapd-state force-autorefresh
    systemctl start snapd.{socket,service}

    change_id="$("$TESTSTOOLS"/snapd-state wait-for-snap-autorefresh test-snapd-tools)"
    snap changes | MATCH "$change_id.*Done.*Auto-refresh.*test-snapd-tool"

    # check wait-for-snap-autorefresh command with previous change id
    systemctl stop snapd.{service,socket}
    "$TESTSTOOLS/snapd-state" change-snap-channel test-snapd-tools beta
    "$TESTSTOOLS"/snapd-state force-autorefresh
    systemctl start snapd.{socket,service}

    new_change_id="$("$TESTSTOOLS"/snapd-state wait-for-snap-autorefresh test-snapd-tools "$change_id")"
    snap changes | MATCH "$new_change_id.*Done.*Auto-refresh.*test-snapd-tool"

    test "$change_id" -lt "$new_change_id"

    # check wait-for-autorefresh command with previous change id
    new_change_id="$("$TESTSTOOLS"/snapd-state wait-for-autorefresh "$change_id")"
    test "$change_id" -lt "$new_change_id"

    # check required parameters
    "$TESTSTOOLS"/snapd-state print-state 2>&1 | MATCH "snapd-state: jq-filter is a required parameter"
    "$TESTSTOOLS"/snapd-state check-state '.data["last-refresh"]' 2>&1 | MATCH "snapd-state: jq-filter, comparison and expected-res are required parameters"
    "$TESTSTOOLS/snapd-state" change-snap-channel test-snapd-tools 2>&1 | MATCH "snapd-state: snap and channel are required parameters"
    "$TESTSTOOLS/snapd-state" wait-for-snap-autorefresh 2>&1 | MATCH "snapd-state: snap-name is a required parameter"