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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
summary: Exercise a gadget update on a PC
details: |
This test validates the system works properly after the pc gadget
snap is installed. Also it is validated the new gadgets are installed
correctly.
environment:
BLOB_DIR: $(pwd)/fake-store-blobdir
# snap-id of 'pc' gadget snap
PC_SNAP_ID: UqFziVZDHLSyO3TqSWgNBoAdHbLI4dAH
START_REVISION: 1000
prepare: |
# external backends do not enable test keys
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
if not snap list pc; then
echo "This test needs a host using 'pc' gadget snap"
exit 1
fi
# Set the retain count to 4 to ensure we keep the current gadget snap
# intact and can roll back to it. This is easier to get right than to
# manually fiddle with re-installing it.
snap set core refresh.retain=4
# Save the current revision of the pc snap. At this moment the pc snap is
# the real snap from the store and the revision will drift over time.
readlink /snap/pc/current > original-revision.txt
snap ack "$TESTSLIB/assertions/testrootorg-store.account-key"
"$TESTSTOOLS"/store-state setup-fake-store "$BLOB_DIR"
cp /var/lib/snapd/snaps/pc_*.snap gadget.snap
unsquashfs -d pc-snap gadget.snap
# prepare a vanilla version
sed -i -e 's/^version: \(.*\)/version: \1-1/' pc-snap/meta/snap.yaml
# pack it
snap pack pc-snap --filename=pc_x1.snap
cat <<EOF > decl-headers.json
{"snap-id": "$PC_SNAP_ID"}
EOF
cat <<EOF > rev-headers.json
{"snap-id": "$PC_SNAP_ID", "snap-revision": "$START_REVISION"}
EOF
p=$(fakestore new-snap-declaration --dir "$BLOB_DIR" pc --snap-decl-json decl-headers.json)
snap ack "$p"
p=$(fakestore new-snap-revision --dir "$BLOB_DIR" pc_x1.snap --snap-rev-json rev-headers.json)
snap ack "$p"
cp -av pc_x1.snap "$BLOB_DIR/"
cp pc-snap/meta/gadget.yaml gadget.yaml.orig
system_seed=""
system_bios="--system-bios"
if os.query is-core-ge 20 ; then
system_seed="--system-seed"
fi
if os.query is-arm; then
system_bios=""
fi
# prepare first update
python3 ./generate.py ./gadget.yaml.orig v1 $system_seed > pc-snap/meta/gadget.yaml
echo 'this is foo-x2' > foo-x2.img
cp foo-x2.img pc-snap/foo.img
echo 'this is foo.cfg' > pc-snap/foo.cfg
if os.query is-core-ge 20; then
echo 'this is foo-seed.cfg' > pc-snap/foo-seed.cfg
fi
sed -i -e 's/^version: \(.*\)-1/version: \1-2/' pc-snap/meta/snap.yaml
snap pack pc-snap --filename=pc_x2.snap
cat <<EOF > rev-headers-2.json
{"snap-id": "$PC_SNAP_ID", "snap-revision": "$((START_REVISION+1))"}
EOF
# prepare second update
# Disabling warning as we don't want the (empty) arguments
# shellcheck disable=SC2086
python3 ./generate.py ./gadget.yaml.orig v2 $system_seed $system_bios > pc-snap/meta/gadget.yaml
echo 'this is updated foo-x3' > foo-x3.img
cp foo-x3.img pc-snap/foo.img
echo 'this is updated foo.cfg' > pc-snap/foo.cfg
if os.query is-core-ge 20; then
echo 'this is updated foo-seed.cfg' > pc-snap/foo-seed.cfg
fi
echo 'this is bar.cfg' > pc-snap/bar.cfg
sed -i -e 's/^version: \(.*\)-2/version: \1-3/' pc-snap/meta/snap.yaml
snap pack pc-snap --filename=pc_x3.snap
cat <<EOF > rev-headers-3.json
{"snap-id": "$PC_SNAP_ID", "snap-revision": "$((START_REVISION+2))"}
EOF
if os.query is-core-ge 20; then
# on uc20, the pc snap we booted with is unasserted for extra debugging
snap install pc_x1.snap --dangerous
else
# all other platforms, the pc snap is asserted, so no flags
snap install pc_x1.snap
fi
restore: |
# external backends do not enable test keys
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
if not snap list pc; then
echo "This test needs a host using 'pc' gadget snap"
exit 1
fi
"$TESTSTOOLS"/store-state teardown-fake-store "$BLOB_DIR"
# Restore the state of the gadget snap.
snap revert pc --revision="$(cat original-revision.txt)"
for rev in $(seq "$START_REVISION" "$((START_REVISION + 2))") ; do
snap remove --revision="$rev" pc
done
# Undo changes to refresh.retain settings.
snap unset core refresh.retain
execute: |
# external backends do not enable test keys
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
if not snap list pc; then
echo "This test needs a host using 'pc' gadget snap"
exit 1
fi
# XXX: the test hardcodes a bunch of locations
# - 'BIOS Boot' and 'EFI System' are modified during the update
# - 'EFI System' is mounted at /boot/efi
bootdir=/boot/efi
if os.query is-core-ge 20; then
# /boot/efi is not mounted on UC20, so use the /run/mnt hierarchy
bootdir=/run/mnt/ubuntu-boot
fi
if [[ "$SPREAD_REBOOT" == 0 ]]; then
p=$(fakestore new-snap-revision --dir "$BLOB_DIR" pc_x2.snap --snap-rev-json rev-headers-2.json)
snap ack "$p"
cp -av pc_x2.snap "$BLOB_DIR/"
if os.query is-core-ge 20; then
# on uc20, the pc snap we booted with is unasserted for extra debugging
snap install pc_x2.snap --dangerous
else
# all other platforms, the pc snap is asserted, so no flags
snap install pc_x2.snap
fi
REBOOT
fi
if [[ "$SPREAD_REBOOT" == 1 ]]; then
# wait for change to complete
snap watch --last=install\?
# verify the update
# a filesystem structure entry was copied to the right place
test "$(cat "$bootdir"/foo.cfg)" = 'this is foo.cfg'
if [ -e /snap/pc/current/pc-core.img ]; then
szimg=$(stat -c '%s' /snap/pc/current/pc-core.img)
# using foo.img from x2
szfoo=$(stat -c '%s' foo-x2.img)
# a raw content was written
dd if='/dev/disk/by-partlabel/BIOS\x20Boot' skip="$szimg" bs=1 count="$szfoo" of=foo-written.img
test "$(cat foo-written.img)" = 'this is foo-x2'
fi
if os.query is-core20 || os.query is-core20; then
# a filesystem structure entry was copied to the right place
test "$(cat /run/mnt/ubuntu-seed/foo-seed.cfg)" = 'this is foo-seed.cfg'
# managed boot config was preserved for boot and seed partitions
MATCH '# Snapd-Boot-Config-Edition: [0-9]+' < /boot/grub/grub.cfg
MATCH '# Snapd-Boot-Config-Edition: [0-9]+' < /run/mnt/ubuntu-seed/EFI/ubuntu/grub.cfg
fi
# prepare & install the next update
p=$(fakestore new-snap-revision --dir "$BLOB_DIR" pc_x3.snap --snap-rev-json rev-headers-3.json)
snap ack "$p"
cp -av pc_x3.snap "$BLOB_DIR/"
if os.query is-core-ge 20; then
# on uc20, the pc snap we booted with is unasserted for extra debugging
snap install pc_x3.snap --dangerous
else
# all other platforms, the pc snap is asserted, so no flags
snap install pc_x3.snap
fi
REBOOT
fi
if [[ "$SPREAD_REBOOT" == 2 ]]; then
# wait for change to complete
snap watch --last=install\?
# verify the update
# a new filesystem structure entry was copied to the right place
test "$(cat "$bootdir"/bar.cfg)" = 'this is bar.cfg'
# this one was preserved
test "$(cat "$bootdir"/foo.cfg)" = 'this is foo.cfg'
if [ -e /snap/pc/current/pc-core.img ]; then
# raw content was updated
szimg=$(stat -c '%s' /snap/pc/current/pc-core.img)
# using foo.img from x3
szfoo=$(stat -c '%s' foo-x3.img)
# a raw content was written
dd if='/dev/disk/by-partlabel/BIOS\x20Boot' skip="$szimg" bs=1 count="$szfoo" of=foo-updated-written.img
test "$(cat foo-updated-written.img)" = 'this is updated foo-x3'
fi
if os.query is-core-ge 20; then
# a filesystem structure entry was copied to the right place
test "$(cat /run/mnt/ubuntu-seed/foo-seed.cfg)" = 'this is updated foo-seed.cfg'
# managed boot config was preserved for boot and seed partitions
MATCH '# Snapd-Boot-Config-Edition: [0-9]+' < /boot/grub/grub.cfg
MATCH '# Snapd-Boot-Config-Edition: [0-9]+' < /run/mnt/ubuntu-seed/EFI/ubuntu/grub.cfg
fi
fi
|