33 Commits

Author SHA1 Message Date
Samuele Pedroni
76e808fb34 Merge branch 'uc20-boot-streamline-mock-device' into uc20-reseal-with-kernel-cleanup
fix conflicts, mockDevice.SetModel is not necessary anymore
2020-09-12 23:46:20 +02:00
Samuele Pedroni
0d4c7467bc boot: make MockUC20Device use a model and MockDevice more realistic
We will need to add Model to Device for UC20 cases, prepare for that
by forcing MockUC20Device to use one and produce output consistent
with it.

Make also the behavior of MockDevice a bit more consistent/realistic
though it has limited use for UC20, it allowed for mode != "run"
with HasModeenv false for example.
2020-09-12 23:17:09 +02:00
Samuele Pedroni
cb98729f5d boot: have the mock model helper in boottest, a bit more naming consistence 2020-09-12 22:36:53 +02:00
Maciej Borzecki
2066fff4d1 boot: reseal when changing kernels
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-09-12 20:12:43 +02:00
Maciej Borzecki
58e5be103d boot: add model to the Device
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-09-12 20:12:43 +02:00
Ian Johnson
6fbf33403b boot/bootstate16.go: clean snap_try_* vars when not in Trying status too
This is needed because the uc18/uc16 bootloader implementations do not actually
do this, and instead snapd needs to reset the value.

Also modify the bootenv bootloader logic simulation to not clean this anymore,
just as the real bootloaders do. 

This all requires some slight changes to the test logic, which since they are 
checking the BootVars map directly will see some additional empty keys in the 
map as markSuccessful will now write those empty keys. Eventually we should port
these tests to use GetBootVars and not use the map directly since empty 
string keys show up the same as missing keys with GetBootVars and that would 
have prevented needing to change these tests at all.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-06-02 18:18:39 -05:00
Ian Johnson
9e01639f22 boot/boottest/bootenv: add TODO on MockUC20EnvRefExtractedKernelRunBootenv
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-04-20 16:02:34 -05:00
Ian Johnson
f8180fa8f9 boot/boottest/bootenv: add MockUC20EnvRefExtractedKernelRunBootenv
This internally uses Bootenv16, with snap_mode usage replaced with kernel_status
which is what we have for UC20.

Also fix doc-comment on RunBootenv20.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-04-20 14:49:45 -05:00
Ian Johnson
8e3e4c7706 boot: simplify modeenv mocking to always write a modeenv
In a future refactor of the boot tests, we will always need to write out a new
modeenv in the tests and never just read it, so we don't need this mocking
utility anymore.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-04-02 10:45:42 -05:00
Samuele Pedroni
b86b891681 many: address lingering XXXs
* add missing doc comments
* make sure we indicate in tests which bits of bootenv (kernel or base)
  we are trying/rolling back
2020-03-11 11:48:52 +01:00
Samuele Pedroni
1177064a2f many: separate mocking of bootenvs vs bootloaders and among those
some XXX todos in doc comments, and difference in simulating
reboots between UC20 vs UC16/18
2020-03-05 18:08:58 +01:00
Ian Johnson
3f17704686 bootstate20: use "" instead of GlobalRootDir
This is more consistent and means the same thing everywhere else, except for one
test helper which is also updated here to now mean the same thing.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-02-17 10:54:45 -06:00
Ian Johnson
e275664270 boottest: re-format HasModeenv definition
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-01-27 12:00:04 -06:00
Ian Johnson
16541c7d4b tests/boottest: add tests for MockUC20Device
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-01-27 12:00:02 -06:00
Maciej Borzecki
4f36dd1f88 boot, boottest: tweak boot.Device mocks, update comments
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-01-14 14:49:59 +01:00
Maciej Borzecki
c108ff6d9a boot: tweak implementation mocking for better go doc output
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-01-14 13:14:27 +01:00
Ian Johnson
159b14d17b boot/modeenv: allow forcing a specific modeenv to always be read
This makes future tests simpler, and since it's all in memory is simpler than
writing out the files to the filesystem for each test, since restoring it is
just defer'ing the returned function.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-01-13 14:40:41 -06:00
Ian Johnson
53ffb3526d boot: add HasModeenv to Device
This will be used by bootStateFor in determining if a given device is a UC20
device and thus needs a different bootState implementation.

Adjust some tests to ensure that we have a modeenv when expected and don't when
expected.

This also requires refactoring the MockDevice in boottest to be slightly more
complicated to have devices that are in run mode, but are not uc20.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-01-13 14:40:34 -06:00
Samuele Pedroni
aa2759d2e8 follow-up: fix/improve doc comments (thanks @bboozzoo) 2019-12-13 13:10:43 +01:00
Samuele Pedroni
2113b5748a many: pass consistently boot.Device state to boot methods
instead of passing model and/or a classic flag to them
and adding operating mode now as well, pass a new interface
boot.Device that is implemented by DeviceContext
2019-12-12 18:52:38 +01:00
John R. Lenton
30d8deff77 many: refactor boot/boottest and move to bootloader/mockbootloader
all boottest had was MockBootloader, so moved it there.
2019-09-02 10:48:59 +01:00
John R. Lenton
5061d2aa6d boot, etc.: refactor boot to have a lookup with different imps
Currently the logic of boot has a lot of per-snap-type cheks in the
exported functions. Going forwards into core20 we know these checks
are going to get more involved, so now is a good time to switch things
around so that different implementations exist for each of the
situations, and thus the checks can be done while looking up which
implementation to use, instead of in each of the functions.
2019-07-29 10:14:08 +01:00
John R. Lenton
23ece3c3ff boot: one last mini refactor / cleanup
thanks @pedronis again
2019-07-23 11:52:49 +01:00
John R. Lenton
20ac21d59a boot/boottest: helpers to set boot kernel and base
This makes it so that only tests that care about the boot mechanics
need to care about the details of it.

These tests might be better off be split and part of them moved into
boot, as there's little reason for them to be where they are caring
for the level they have (e.g. devicemanager shouldn't need to care
about the vagaries of boot rollback, probably).

But that's work for another PR.
2019-07-23 11:23:40 +01:00
Michael Vogt
a900bb39ad bootloader: remove "Dir()" from Bootloader interface
The Bootloader.Dir() method is no longer needed and can be removed.
It used to be used to extract kernel assets but that is now part
of the Bootloader interface so expect for test code nothing is
using "Dir()" anymore. The extraction of boot assets is now done
via the Bootloader interface directly.

Note that Dir() also does not make sense for bootloaders that work
inside partitions (like littleKernel).
2019-07-18 10:21:14 +02:00