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 157 158 159 160
|
summary: Test a remodel that switches to a new base and gadget
details: |
This test remodels to a model that uses a custom base (not one of the core?? snaps),
and a gadget that is based on that custom base.
# TODO:UC20: enable on UC20
systems: [ubuntu-core-18-64]
environment:
OLD_BASE: core18
NEW_BASE: test-snapd-core18
NEW_GADGET: test-snapd-pc-core18
prepare: |
#shellcheck source=tests/lib/core-config.sh
. "$TESTSLIB"/core-config.sh
if [ "$SPREAD_REBOOT" = 0 ]; then
REBOOT_NEEDED=false
if os.query is-core18 && snap list snapd | NOMATCH ' x1 '; then
REBOOT_NEEDED=true
fi
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
if [ "$REBOOT_NEEDED" = true ] && "$TESTSTOOLS"/journal-state match-log -n 30 "Waiting for system reboot"; then
REBOOT
fi
fi
# 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
if [ "$SPREAD_REBOOT" = 0 ]; then
REBOOT_NEEDED=false
if os.query is-core18 && snap list snapd | NOMATCH ' x1 '; then
REBOOT_NEEDED=true
fi
# find out what is the revision of the base in seed and one that is
# currently installed, if different a reboot will be issued
seed_base_rev="$(basename /var/lib/snapd/seed/snaps/core18_*.snap | cut -f1 -d. | cut -f2 -d_)"
cur_base_rev="$(readlink /snap/core18/current)"
if [ "$seed_base_rev" != "$cur_base_rev" ]; then
REBOOT_NEEDED=true
fi
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
if [ "$REBOOT_NEEDED" = true ] && "$TESTSTOOLS"/journal-state match-log -n 30 "Waiting for system reboot"; then
REBOOT
fi
fi
# 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_BASE/current ]; then
echo "Leftover $NEW_BASE data dir found, test does not "
echo "properly cleanup"
echo "see https://github.com/snapcore/snapd/pull/6620"
echo
find /var/snap
exit 1
fi
debug: |
snap changes || true
snap change 1 || true
journalctl -u snapd --no-pager || true
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 | MATCH "[0-9]+\\ +Done\\ +.* $chg_summary"; then
break
fi
# some debug output
snap changes
# wait a bit
sleep 5
done
snap changes | MATCH "[0-9]+\\ +Done\\ +.* $chg_summary"
}
# initial boot with the current model
if [ "$SPREAD_REBOOT" = 0 ]; then
# precondition check
snap list "$OLD_BASE"
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-base-revno-2)"
snap remodel "${TESTSLIB}/assertions/${MODEL}"
echo "Double check that we boot into the right base"
MATCH "snap_try_core=$NEW_BASE" < /boot/grub/grubenv
echo "reboot to finish the change"
REBOOT
fi
# first boot with the new model base
if [ "$SPREAD_REBOOT" = 1 ]; then
echo "and we have the new base snap installed"
snap list "$NEW_BASE"
echo "And are using it"
"$TESTSTOOLS"/boot-state wait-core-post-boot
MATCH "snap_core=$NEW_BASE" < /boot/grub/grubenv
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 base snap"
not snap remove --purge "$NEW_BASE"
# TODO: test when keeping the old base, test removing the old base
# (not possible here as the pc gadget uses core18 as its base)
echo "And we can remodel again and remove the new base"
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
MATCH "snap_core=$OLD_BASE" < /boot/grub/grubenv
wait_change_done "Refresh model assertion from revision 2 to 3"
snap debug model|MATCH "revision: 3"
echo "cleanup"
snap remove --purge "$NEW_GADGET"
snap remove --purge "$NEW_BASE"
snap refresh --channel="$BASE_CHANNEL" "$OLD_BASE"
REBOOT
fi
|