Ubuntu Pastebin

Paste from zyga at Fri, 13 Oct 2017 15:48:23 +0000

Download as text
 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
zyga@lambert ~/go/src/github.com/snapcore/snapd/tests/main/ubuntu-core-upgrade $ cat task.yaml 
summary: Upgrade the core snap and revert a few times

systems: [ubuntu-core-16-*]

debug: |
    snap list
    . $TESTSLIB/boot.sh
    bootenv
    cat /proc/cmdline

restore: |
    if [ -f curChg ] ; then
        snap abort $(cat curChg) || true
    fi
    rm -f prevBoot nextBoot curChg

prepare: |
    snap list | awk "/^core / {print(\$3)}" > nextBoot

execute: |
    . $TESTSLIB/boot.sh

    # FIXME Why it starting with snap_mode=try the first time?
    # Perhaps because core is installed after seeding? Do we
    # want that on pristine images?
    if [ $SPREAD_REBOOT != 0 ]; then
        echo "Waiting for snapd to clean snap_mode"
        while [ "$(bootenv snap_mode)" != "" ]; do
            sleep 1
        done

        echo "Ensure the bootloader is correct after reboot"
        test "$(bootenv snap_core)" = "core_$(cat nextBoot).snap"
        test "$(bootenv snap_try_core)" = ""
        test "$(bootenv snap_mode)" = ""
    fi

    snap list | awk "/^core / {print(\$3)}" > prevBoot

    # wait for ongoing change if there is one
    if [ -f curChg ] ; then
       snap watch $(cat curChg)
       rm -f curChg
    fi

    case $SPREAD_REBOOT in

    0) cmd="snap install --dangerous /var/lib/snapd/snaps/core_$(cat prevBoot).snap" ;;
    1) cmd="snap revert core" ;;
    2) cmd="snap install --dangerous /var/lib/snapd/snaps/core_$(cat prevBoot).snap" ;;
    3) cmd="snap revert core" ;;
    4) exit 0 ;;

    esac

    # start the op and get the change id
    chg_id=$(eval ${cmd} --no-wait)

    # save change id to wait later or abort
    echo ${chg_id} >curChg

    # wait for the link task to be done
    while ! snap change ${chg_id}|grep -q "^Done.*Make snap.*available to the system" ; do sleep 1 ; done

    echo "Ensure the bootloader is correct before reboot"
    snap list | awk "/^core / {print(\$3)}" > nextBoot
    test "$(cat prevBoot)" != "$(cat nextBoot)"
    test "$(bootenv snap_try_core)" = "core_$(cat nextBoot).snap"
    test "$(bootenv snap_mode)" = "try"

    echo "Ensure the device is scheduled for auto-reboot"
    output=$(dbus-send --print-reply \
        --type=method_call \
        --system \
        --dest=org.freedesktop.login1 \
        /org/freedesktop/login1 \
        org.freedesktop.DBus.Properties.Get \
        string:org.freedesktop.login1.Manager string:ScheduledShutdown)
    if ! echo $output | MATCH 'string "reboot"'; then
        echo "Failed to detect scheduled reboot in logind output"
        exit 1
    fi

    REBOOT
Download as text