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 (95 lines) | stat: -rw-r--r-- 3,156 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
summary: Check install, configure, remove and pre-refresh/post-refresh hooks.

details: |
    Check that the various snap hooks are called at the right times (e.g.,
    refresh hooks are only called on refresh, the install hook is only called
    on initial install, etc).

# slow in autopkgtest (>1m)
backends: [-autopkgtest]

environment:
    REMOVE_HOOK_FILE/regular: "/tmp/snap-private-tmp/snap.snap-hooks/tmp/remove-hook-executed"
    REMOVE_HOOK_FILE/parallel: "/tmp/snap-private-tmp/snap.snap-hooks_instance/tmp/remove-hook-executed"
    NAME/regular: snap-hooks
    NAME/parallel: snap-hooks_instance

prepare: |
    if [[ "$SPREAD_VARIANT" == "parallel" ]]; then
        snap set system experimental.parallel-instances=true
    fi

restore: |
    if [[ "$SPREAD_VARIANT" == "parallel" ]]; then
        snap set system experimental.parallel-instances=null
    fi

    rm -f "$REMOVE_HOOK_FILE"

execute: |
    "$TESTSTOOLS"/snaps-state install-local-as snap-hooks "$NAME"

    echo "Verify configuration value with snap get"
    snap get "$NAME" installed | MATCH 1
    snap get "$NAME" foo | MATCH bar

    echo "Verify that pre-refresh hook was not executed"
    if snap get snap-install-hooks prerefreshed; then
        echo "'prerefreshed' config value not expected on first install"
        exit 1
    fi

    echo "Verify that post-refresh hook was not executed"
    if snap get snap-install-hooks postrefreshed; then
        echo "'postrefreshed' config value not expected on first install"
        exit 1
    fi

    echo "Verify that install hook is run only once"
    snap set "$NAME" installed=2
    "$TESTSTOOLS"/snaps-state install-local-as snap-hooks "$NAME"
    snap get "$NAME" installed | MATCH 2

    echo "Verify that pre-refresh hook was executed"
    snap get "$NAME" prerefreshed | MATCH "pre-refresh at revision x1"

    echo "Verify that post-refresh hook was executed"
    snap get "$NAME" postrefreshed | MATCH "post-refresh at revision x2"

    snap connect "$NAME:home"

    echo "Verify that remove hook is not executed when removing single revision"
    snap set "$NAME" exitcode=0
    snap remove --revision=x1 "$NAME"
    if test -f "$REMOVE_HOOK_FILE"; then
        echo "Remove hook was executed. It shouldn't."
        exit 1
    fi

    echo "Verify that remove hook is executed"
    snap set "$NAME" exitcode=0
    snap remove --purge "$NAME"
    if ! test -f "$REMOVE_HOOK_FILE"; then
        echo "Remove hook was not executed"
        exit 1
    fi

    echo "Installing a snap with hooks again"
    rm -f "$REMOVE_HOOK_FILE" > /dev/null 2>&1
    "$TESTSTOOLS"/snaps-state install-local-as snap-hooks "$NAME"
    snap connect "$NAME:home"

    echo "Forcing remove script to fail"
    snap set "$NAME" exitcode=1
    snap remove "$NAME"
    EXITCODE_VALUE=$(cat "$REMOVE_HOOK_FILE")
    if test "$EXITCODE_VALUE" != "1"; then
        echo "Remove hook was not executed"
        exit 1
    fi

    echo "Installing a snap with broken install hook aborts the installation"
    if "$TESTSTOOLS"/snaps-state install-local snap-hook-broken; then
        echo "Expected installation to fail"
        exit 1
    fi