/
task.yaml
109 lines (92 loc) · 4.96 KB
/
task.yaml
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
summary: verify a simple UC20 remodel
systems: [ubuntu-20.04-64]
environment:
NESTED_CUSTOM_MODEL: $TESTSLIB/assertions/valid-for-testing-pc-20.model
NESTED_IMAGE_ID: uc20-remodel-testing
NESTED_ENABLE_TPM: true
NESTED_ENABLE_SECURE_BOOT: true
NESTED_BUILD_SNAPD_FROM_CURRENT: true
prepare: |
tests.nested build-image core
tests.nested create-vm core
execute: |
# shellcheck source=tests/lib/nested.sh
. "$TESTSLIB/nested.sh"
boot_id="$( nested_get_boot_id )"
tests.nested exec snap model |MATCH 'model +my-model$'
# XXX: recovery system label is based on a date; we may end up with a
# different label if the remodel runs around midnight; the label will
# conflict with an existing system label
label_base=$(tests.nested exec "date '+%Y%m%d'")
# wait until device is initialized and has a serial
nested_wait_for_device_initialized_change
echo "Refresh model assertion to revision 2"
nested_copy "$TESTSLIB/assertions/valid-for-testing-pc-revno-2-20.model"
REMOTE_CHG_ID="$(tests.nested exec sudo snap remodel --no-wait valid-for-testing-pc-revno-2-20.model)"
nested_wait_for_reboot "${boot_id}"
tests.nested exec sudo snap watch "${REMOTE_CHG_ID}"
echo "Verify the system is back in run mode"
tests.nested exec "sudo cat /proc/cmdline" | MATCH snapd_recovery_mode=run
# this is a simple model revision refresh
echo "Verify the model"
tests.nested exec snap model --verbose > rev-2-model
MATCH 'model: +my-model' < rev-2-model
MATCH 'revision: +2' < rev-2-model
# seed system was created
revno2_label="${label_base}-1"
echo "Verify seed system with label $revno2_label"
tests.nested exec "sudo cat /run/mnt/ubuntu-seed/systems/${revno2_label}/model" > revno-2-from-seed.model
MATCH 'model: my-model' < revno-2-from-seed.model
MATCH 'revision: 2' < revno-2-from-seed.model
tests.nested exec "sudo cat /var/lib/snapd/modeenv" > modeenv
MATCH "current_recovery_systems=.*,${revno2_label}" < modeenv
MATCH "good_recovery_systems=.*,${revno2_label}" < modeenv
tests.nested exec "sudo snap debug boot-vars --root-dir=/run/mnt/ubuntu-seed" | MATCH "snapd_good_recovery_systems=${label_base},${revno2_label}"
# the revision pulls in test-snapd-tools-core20 snap
echo "Verify new model revision snaps"
tests.nested exec snap list test-snapd-tools-core20
# the snap is pulled in from the store, so it should be located in shared
# snaps directory
tests.nested exec find /run/mnt/ubuntu-seed/snaps -name 'test-snapd-tools-core20_*.snap' | MATCH 'test-snapd-tools-core20'
boot_id="$( nested_get_boot_id )"
echo "Refresh model assertion to revision 3"
nested_copy "$TESTSLIB/assertions/valid-for-testing-pc-revno-3-20.model"
REMOTE_CHG_ID="$(tests.nested exec sudo snap remodel --no-wait valid-for-testing-pc-revno-3-20.model)"
nested_wait_for_reboot "${boot_id}"
tests.nested exec sudo snap watch "${REMOTE_CHG_ID}"
echo "Verify the model"
tests.nested exec snap model --verbose > rev-3-model
MATCH 'model: +my-model' < rev-3-model
MATCH 'revision: +3' < rev-3-model
# seed system was created
revno3_label="${label_base}-2"
echo "Verify seed system with label $revno3_label"
tests.nested exec "sudo cat /run/mnt/ubuntu-seed/systems/${revno3_label}/model" > revno-3-from-seed.model
MATCH 'model: my-model' < revno-3-from-seed.model
MATCH 'revision: 3' < revno-3-from-seed.model
tests.nested exec "sudo cat /var/lib/snapd/modeenv" > modeenv
MATCH "current_recovery_systems=.*,${revno3_label}" < modeenv
MATCH "good_recovery_systems=.*,${revno3_label}" < modeenv
tests.nested exec "sudo snap debug boot-vars --root-dir=/run/mnt/ubuntu-seed" | MATCH "snapd_good_recovery_systems=${label_base},${revno2_label},${revno3_label}"
# because the system is considered 'seeded' we are able to switch to the
# recover mode
echo "Switch to recover mode of new seed system"
boot_id="$( nested_get_boot_id )"
tests.nested exec sudo snap reboot --recover "${revno3_label}" | MATCH 'Reboot into ".*" "recover" mode'
nested_wait_for_reboot "${boot_id}"
# Verify we are in recover mode with the expected system label
tests.nested exec 'sudo cat /proc/cmdline' | MATCH "snapd_recovery_mode=recover snapd_recovery_system=${revno3_label} "
# we are in recover mode, so tools need to be set up again
nested_prepare_tools
boot_id="$( nested_get_boot_id )"
echo "And back to run mode"
nested_wait_for_snap_command
tests.nested exec "sudo snap wait system seed.loaded"
tests.nested exec sudo snap reboot --run | MATCH 'Reboot into "run" mode.'
nested_wait_for_reboot "${boot_id}"
tests.nested exec 'sudo cat /proc/cmdline' | MATCH "snapd_recovery_mode=run "
echo "Verify all recovery systems are listed"
tests.nested exec "sudo snap recovery" > recovery.out
for label in "$label_base" "$revno2_label" "$revno3_label"; do
MATCH "$label " < recovery.out
done