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 (104 lines) | stat: -rw-r--r-- 3,929 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
98
99
100
101
102
103
104
summary: Check that firstboot assertions are imported and snaps installed also on classic

details: |
  Verify that the snapd.seeded.service unit is able to import assertions from
  the seed directory and install the seed snaps on classic systems. We verify
  this by creating a seed directory with the needed snaps and assertions and
  then starting the snapd.seeded.service unit. Additionally, we check that any
  services defined by the seed snaps are restarted before the mark-seeded task
  is completed.

systems: [-ubuntu-core-*]

environment:
    SEED_DIR: /var/lib/snapd/seed

prepare: |
    # In this scenario, the keys from the snapd pkg are used
    if [ "$TRUST_TEST_KEYS" = "false" ] || tests.info is-snapd-from-archive; then
        tests.exec skip-test "This test needs test keys to be trusted" && exit 0
    fi

    snap pack "$TESTSLIB/snaps/basic"
    snap pack "$TESTSLIB/snaps/test-snapd-service"
    snap download "--$CORE_CHANNEL" core

    "$TESTSLIB/reset.sh" --keep-stopped
    mkdir -p "$SEED_DIR/snaps"
    mkdir -p "$SEED_DIR/assertions"
    cat > "$SEED_DIR/seed.yaml" <<EOF
    snaps:
      - name: core
        channel: $CORE_CHANNEL
        file: core.snap
      - name: basic
        unasserted: true
        file: basic.snap
      - name: test-snapd-service
        unasserted: true
        file: test-snapd-service.snap
    EOF

    echo Copy the needed assertions to /var/lib/snapd/
    cp core_*.assert "$SEED_DIR/assertions"
    cp "$TESTSLIB/assertions/developer1.account" "$SEED_DIR/assertions"
    cp "$TESTSLIB/assertions/developer1.account-key" "$SEED_DIR/assertions"
    cp "$TESTSLIB/assertions/developer1-my-classic.model" "$SEED_DIR/assertions"
    cp "$TESTSLIB/assertions/testrootorg-store.account-key" "$SEED_DIR/assertions"
    echo "Copy the needed snaps to $SEED_DIR/snaps"
    cp ./core_*.snap "$SEED_DIR/snaps/core.snap"
    cp ./basic_1.0_all.snap "$SEED_DIR/snaps/basic.snap"
    cp ./test-snapd-service_1.0_all.snap "$SEED_DIR/snaps/test-snapd-service.snap"

restore: |
    tests.exec is-skipped && exit 0

    rm -rf "$SEED_DIR"
    systemctl start snapd.socket snapd.service

execute: |
    tests.exec is-skipped && exit 0

    echo "Start the daemon with an empty state, this will make it import "
    echo "assertions from the $SEED_DIR/assertions subdirectory and "
    echo "install the seed snaps."
    systemctl start snapd.seeded.service

    echo "Wait for Seed change to be finished"
    for _ in $(seq 120); do
        if snap list 2>/dev/null |grep -q -E "^basic" ; then
            break
        fi
        sleep 1
    done

    echo "Ensure snapd.seeded.service is active"
    systemctl status snapd.seeded.service

    echo "Verifying the imported assertions"
    if ! snap model --verbose | MATCH "model:\s* my-classic" ; then
        echo "Model assertion was not imported on firstboot"
        exit 1
    fi

    snap list | MATCH "^basic"
    snap list | MATCH "^test-snapd-service"
    test -f "$SEED_DIR/snaps/basic.snap"
    test -f "$SEED_DIR/snaps/test-snapd-service.snap"

    echo "Checking that service restart happened before mark-seeded"
    # precondition check
    snap change 1 | MATCH "Mark system seeded"
    snap change 1 | MATCH "restart of .*test-snapd-service.test-snapd-other-service"
    # extract task ids from state
    # XXX: snap change output cannot be used for that; ideally we would have some sort of 'snap debug ..' command.
    MARKSEEDED_WAIT=$(gojq -r '.tasks[] | select (.kind == "mark-seeded") | ."wait-tasks"' < /var/lib/snapd/state.json)
    SERVICECMD_TASK=$(gojq -r '.tasks[] | select (.kind == "exec-command") | .id' < /var/lib/snapd/state.json)
    if test -z "$SERVICECMD_TASK" ; then
        echo "Could not find exec-command task"
        exit 1
    fi
    if ! echo "$MARKSEEDED_WAIT" | MATCH "$SERVICECMD_TASK" ; then
        echo "Expected mark-seeded task to wait for exec-command"
        exit 1
    fi