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