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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
summary: Test a remodel that switches to a new kernel
details: |
Check that is it possible to `snap remodel` to a new kernel.
Verify after the reboot the new kernel is installed, the new
model assertion is being used and it is not possible to remove
the new kernel snap. Finally check it is possible to remodel
back to the initial model.
systems: [ubuntu-core-16-64]
environment:
OLD_KERNEL: pc-kernel
NEW_KERNEL: test-snapd-pc-kernel
prepare: |
#shellcheck source=tests/lib/core-config.sh
. "$TESTSLIB"/core-config.sh
# Save the revision of the pc-kernel snap.
readlink /snap/"$OLD_KERNEL"/current > original-revision.txt
# Save the original tracking channel
snap info "$OLD_KERNEL" | awk '/^tracking:/ {print $2}' > original-channel.txt
systemctl stop snapd.service snapd.socket
clean_snapd_lib
prepare_core_model
prepare_test_account valid-for-testing
prepare_test_model valid-for-testing-pc
# kick first boot again
systemctl start snapd.service snapd.socket
# wait for first boot to be done
wait_for_first_boot_change
# and for the serial to be available
wait_for_device_initialized_change
restore: |
#shellcheck source=tests/lib/core-config.sh
. "$TESTSLIB"/core-config.sh
# Wait for the final refresh to complete (if needed).
snap watch --last=refresh?
# Remove all the revisions of pc-kernel that should not be there.
for revno_path in /snap/"$OLD_KERNEL"/*; do
revno="$(basename "$revno_path")"
if [ "$revno" == current ] || [ "$revno" == "$(cat original-revision.txt)" ]; then
continue;
fi
snap remove "$OLD_KERNEL" --revision="$revno"
done
systemctl stop snapd.service snapd.socket
clean_snapd_lib
restore_test_account valid-for-testing
restore_test_model valid-for-testing-pc
restore_core_model
# kick first boot again
systemctl start snapd.service snapd.socket
# wait for first boot to be done
wait_for_first_boot_change
# extra paranoia because failure to cleanup earlier took us a long time
# to find
if [ -e /var/snap/$NEW_KERNEL/current ]; then
echo "Leftover $NEW_KERNEL data dir found, test does not "
echo "properly cleanup"
echo "see https://github.com/snapcore/snapd/pull/6620"
echo
find /var/snap -ls
exit 1
fi
execute: |
#shellcheck source=tests/lib/core-config.sh
. "$TESTSLIB"/core-config.sh
wait_change_done() {
chg_summary="$1"
for _ in $(seq 10); do
if snap changes | grep -qE "[0-9]+\ +Done\ +.* $chg_summary"; then
break
fi
# some debug output
snap changes
# wait a bit
sleep 5
done
snap changes | MATCH "$chg_summary"
}
# initial boot with the current model
if [ "$SPREAD_REBOOT" = 0 ]; then
# precondition check
snap list "$OLD_KERNEL"
echo "We have the right model assertion"
snap debug model|MATCH "model: my-model"
echo "Now we remodel"
MODEL="$(get_test_model valid-for-testing-pc-new-kernel-revno-2)"
snap remodel "${TESTSLIB}/assertions/${MODEL}"
echo "Double check that we boot into the right kernel"
grub-editenv list | MATCH "snap_try_kernel=$NEW_KERNEL"
echo "reboot to finish the change"
REBOOT
fi
# first boot with the new model kernel
if [ "$SPREAD_REBOOT" = 1 ]; then
echo "and we have the new kernel snap installed"
snap list "$NEW_KERNEL"
echo "And are using it"
"$TESTSTOOLS"/boot-state wait-core-post-boot
grub-editenv list | MATCH "snap_kernel=$NEW_KERNEL"
echo "and we got the new model assertion"
wait_change_done "Refresh model assertion from revision 0 to 2"
snap debug model|MATCH "revision: 2"
echo "and we cannot remove the kernel snap"
not snap remove --purge "$NEW_KERNEL"
# TODO: test when keeping the old kernel
echo "but we can remove the old kernel"
snap remove --purge "$OLD_KERNEL"
echo "And we can remodel again and remove the new kernel"
MODEL="$(get_test_model valid-for-testing-pc-revno-3)"
snap remodel "${TESTSLIB}/assertions/${MODEL}"
REBOOT
fi
# reboot from new model to undo the new model again (to not pollute tests)
if [ "$SPREAD_REBOOT" = 2 ]; then
"$TESTSTOOLS"/boot-state wait-core-post-boot
grub-editenv list | MATCH "snap_kernel=$OLD_KERNEL"
wait_change_done "Refresh model assertion from revision 2 to 3"
snap debug model|MATCH "revision: 3"
echo "cleanup"
snap remove --purge "$NEW_KERNEL"
echo "Ensure we are back to the original kernel channel and kernel"
snap refresh --channel="$(cat original-channel.txt)" "$OLD_KERNEL"
REBOOT
fi
|