Permalink
Fetching contributors…
Cannot retrieve contributors at this time
114 lines (90 sloc) 3.79 KB
summary: check that the core and kernel snaps roll back correctly after a failed upgrade
systems: [ubuntu-core-16-*]
details: |
This test ensures that the system can survive to a failed upgrade of a fundamental
snap, rolling back to the last good known version.
The logic common to all the scenarios unpacks the target snap, injects the failure,
repacks and installs it. Then it checks that all is set for installed the snap with
the failure and executes a reboot. The test checks that after the reboot (in fact two
reboots, one for trying the upgrade and another for rolling back) the installed
fundamental snap is the good one and the boot environment variables are correctly set.
environment:
INJECT_FAILURE/rclocalcrash: inject_rclocalcrash_failure
INJECT_FAILURE/emptysystemd: inject_emptysystemd_failure
# FIXME: disabled until we find what to do!
# fails with: ERROR cannot replace signed kernel snap with an unasserted one
#INJECT_FAILURE/emptyinitrd: inject_emptyinitrd_failure
TARGET_SNAP/rclocalcrash: core
TARGET_SNAP/emptysystemd: core
#TARGET_SNAP/emptyinitrd: kernel
BUILD_DIR: /home/tmp
prepare: |
mkdir -p $BUILD_DIR
restore: |
rm -f failing.snap failBoot currentBoot prevBoot
rm -rf $BUILD_DIR
# FIXME: remove the unset when we reset properly snap_try_{core,kernel} on rollback
. $TESTSLIB/boot.sh
bootenv_unset snap_try_core
bootenv_unset snap_try_kernel
debug: |
. $TESTSLIB/boot.sh
bootenv
snap list
snap changes
execute: |
inject_rclocalcrash_failure(){
chmod a+x $BUILD_DIR/unpack/etc/rc.local
cat <<EOF > $BUILD_DIR/unpack/etc/rc.local
#!bin/sh
printf c > /proc/sysrq-trigger
EOF
}
inject_emptysystemd_failure(){
truncate -s 0 $BUILD_DIR/unpack/lib/systemd/systemd
}
inject_emptyinitrd_failure(){
truncate -s 0 $BUILD_DIR/unpack/initrd.img
}
. $TESTSLIB/names.sh
. $TESTSLIB/boot.sh
if [ "$TARGET_SNAP" = kernel ]; then
TARGET_SNAP_NAME=$kernel_name
else
TARGET_SNAP_NAME=core
fi
if [ "$SPREAD_REBOOT" = 0 ]; then
# first pass, save current target snap revision
snap list | awk "/^${TARGET_SNAP_NAME} / {print(\$3)}" > prevBoot
# unpack current target snap
unsquashfs -d $BUILD_DIR/unpack /var/lib/snapd/snaps/${TARGET_SNAP_NAME}_$(cat prevBoot).snap
# set failure condition
eval ${INJECT_FAILURE}
# repack new target snap
snap pack $BUILD_DIR/unpack && mv ${TARGET_SNAP_NAME}_*.snap failing.snap
# install new target snap
chg_id=$(snap install --dangerous failing.snap --no-wait)
while ! snap change ${chg_id}|grep -q "^Done.*Make snap.*available to the system" ; do sleep 1 ; done
# check boot env vars
snap list | awk "/^${TARGET_SNAP_NAME} / {print(\$3)}" > failBoot
test "$(bootenv snap_${TARGET_SNAP})" = "${TARGET_SNAP_NAME}_$(cat prevBoot).snap"
test "$(bootenv snap_try_${TARGET_SNAP})" = "${TARGET_SNAP_NAME}_$(cat failBoot).snap"
REBOOT
fi
# after rollback, we have the original target snap for a while
# wait until the kernel and core snap revisions are in place
while true ; do
current=$(snap list | awk "/^${TARGET_SNAP_NAME} / {print(\$3)}")
if [ "$current" = "$(cat prevBoot)" ] ; then
break
fi
sleep 1
done
# and the boot env vars are correctly set
echo "Waiting for snapd to clean snap_mode"
while [ "$(bootenv snap_mode)" != "" ]; do
sleep 1
done
test "$(bootenv snap_${TARGET_SNAP})" = "${TARGET_SNAP_NAME}_$(cat prevBoot).snap"
# FIXME: reenable the last check when we reset properly snap_try_{core,kernel} on rollback
# test "$(bootenv snap_try_${TARGET_SNAP})" = ""