269 Commits

Author SHA1 Message Date
Andrew Phelps
5c8d8431ba many: update component-related TODOs to use TODO:COMPS 2024-07-10 11:03:22 -04:00
Miguel Pires
8128ed20bb many: rename aspect/bundle to view/registry
This changes the naming of the aspects feature to be "registry" instead
of bundle (i.e., a configuration space backed with its own storage) and
"view" instead of aspect. Once this lands, anyone that has this enabled
needs to unset the experimental flag and rename the state entry before
refreshing snapd and then re-enable.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-06-17 17:16:57 +02:00
Andrew Phelps
6abc1a3e6a a/snapasserts, o/assertstate: implement validate-component task handler (#13964)
* a/snapasserts: add helpers for checking validity of component against assertions

* a/snapasserts, o/assertstate: implement validate-component task handler

* o/assertstate: test validate-component handler with provenance
2024-06-03 17:29:13 +02:00
Miguel Pires
562fe027c8 asserts: move aspect schema to assertion body (#13666)
* asserts: move aspect schema to assertion body

Move the aspect schema from a "storage" stanza to the assertion body.
Also format parse and re-encode the JSON with two spaces for indentation
and map ordered map keys. This should make the schema uniform and easy
to read while still using a format that can be emulated by other tools.

* many: nest schema in storage stanza

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* asserts: support checking JSON body format

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* asserts: improve err messages; move check

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

---------

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-03-13 17:22:05 +02:00
Andrew Phelps
c57901e705 many: add API routes for creating/removing recovery systems (#13651)
* o/assertstate, o/devicestate: add more general function for fetching validation set assertions

* daemon, client: add API routes for creating/removing recovery system

* daemon, o/snapstate: add .snap file extension to snaps from forms

The seed writer will fail to consider files as snaps if their filenames
do not end in .snap.

* tests: test creating a recovery system

* tests: add spread test for offline creation of recovery system

* tests: update offline recovery system test to reboot into new system

* tests/nested/manual/recovery-system-reboot: add variants for factory-reset and install modes

* tests: replace usage of default-recovery-system with default-recovery

* o/devicestate: enable offline creation of recovery system entirely from pre-installed snaps

* daemon, client: test that offline API works without providing snaps or validation sets

* tests/nested/manual/recovery-system-offline: test offline remodel with only pre-installed snaps

* tests/nested/manual/recovery-system-reboot: modify test to create system with new set of essential snaps

* tests: disable shellcheck printf check

* daemon: rename functions for working with form values and add one for working with booleans

* daemon: acquire state lock later in postSystemActionCreateOffline

* daemon: cleanup form files if we fail to make change to create a recovery system

* daemon: rename parseValidationSets to assertionsFromValidationSetStrings for clarity

* client, daemon, tests: add "offline" field to create recovery system JSON api

* daemon: convert TODO about comma-delimited list into explanation of why we use a comma delimited list

* NEWS.md: add mention of create/remove recovery systems API

* tests/nested/manual/recovery-system-offline: explicitly disable network from nested vm

* tests/nested/manual/recovery-system-reboot: do not use new gadget in recovery system for now

* tests/lib/nested.sh: add variable NESTED_FORCE_MS_KEYS to force using microsoft keys

* tests/nested/manual/recovery-system-reboot: add back gadget snap swap to test

* tests/nested/manual/recovery-system-reboot: retry POST to remove since there might be an auto-refresh happening
2024-03-10 22:35:04 +02:00
Miguel Pires
bebd832e62 aspects: check path type mismatch on aspect creation (#13635)
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-02-27 12:42:31 +00:00
Andrew Phelps
9d9f2be62d o/assertstate: rename variables to be a bit clearer 2024-02-23 08:45:26 +01:00
Andrew Phelps
04fd0ecdde o/assertstate: use ValidationSetKey to create unique identifiers for validation sets 2024-02-23 08:45:26 +01:00
Andrew Phelps
b79debc962 o/assertstate: add function to get enforced validation sets that are associated with a model 2024-02-23 08:45:26 +01:00
Miguel Pires
d264d4e732 o/aspectstate: get local aspect-bundle assertions (#13585)
* o/aspectstate: use real aspect-bundle assertions

Get a local aspect-bundle assertion instead of using the mock. Move the
transaction creation into aspectstate since it now needs to use the real
schema from the assertion.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* tests: use aspect-bundle assertion in spread test

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* o/aspectstate: remove unused mock aspect assertion

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

---------

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-02-21 11:06:22 +02:00
Andrew Phelps
154d46b46c many: take into account validation sets during remodel (#13243)
This PR makes remodels take into account revision constraints from validation sets on the new model. Additionally, snaps that are marked as invalid in validation sets are checked for in the model.

* a/snapasserts: add methods for extracting more information out of ValidationSets type

* o/assertstate: add ValidationSetsFromModel function for extracting a snapasserts.ValidationSets from an asserts.Model

* o/snapstate: prevent installing/updating a snap from a local file that does not match requested revision

* o/devicestate: consider validation sets during remodeling

* tests/nested/manual: add remodel test that downgrades a snap because of a validation set

* tests/nested/manual: add remodel test that fails to remodel because of an invalid snap in a validation set

* tests/nested/manual: extend offline remodel test to also include a validation set

* tests/lib/assertions: fix timestamps on assertions

* asserts: add Key method to ValidationSet and ModelValidationSet

* o/devicestate: use new Key methods

* o/devicestate: maybe enforce validation sets during doSetModel

* o/devicestate: add test for enforcing validation sets in doSetModel

* a/snapasserts: simplify TestCanBePresent with loop

* tests/lib/assertions: add bluez snap to offline remodel test

* o/devicestate: remove done TODO

* o/snapstate: if remodeling, do not install prereq if link-snap task is present

* tests/nested/manual/remodel-offline: extend test to verify that validation sets are accounted for

* Revert "o/snapstate: if remodeling, do not install prereq if link-snap task is present"

This reverts commit 57c7725a2513df51be7ac1c06c492aaed07a6e3b.

This change is independent and will be included in another PR.

* a/snapasserts: add methods for extracting more information out of ValidationSets type

* o/assertstate: add ValidationSetsFromModel function for extracting a snapasserts.ValidationSets from an asserts.Model

* o/devicestate: add test for ValidationSetsConflictError.Is

* a/snapasserts: move methods after New function

* a/snapasserts: add test for ValidationSets.Revisions to verify ValidationSetsConflictError is returned

* o/assertstate: change ValidationSetsFromModel to take in a DeviceContext, rather than a StoreService

* o/assertstate: rename ValidationSetsModelFlags to ValidationSetsModelOptions

* o/devicestate: add type to export_test to make testing simpler

* tests: add details to new spread tests

* asserts: rename ModelValidationSet.Key and ValidationSet.Key to .SequenceName and add unit tests for them

* o/snapstate: update snap revision mismatch error message to be more clear

* o/devicestate: introduce helper for setting ValidationSets on snapstate.RevisionOptions if Revision is set

* o/devicestate: verify the parameters that fakeSequenceStore receives

* o/devicestate: fix revisions not being respected for essential snaps (and add a test for it)

* o/devicestate: extend TestRemodelUC20EssentialSnapsAlreadyInstalledAndLocal to also exercise case where a validation set requires a revision but the currently installed version is unasserted

* s/seedtest: update retrieveSeq to handle unconstrained sequence forming assertions

* a/snapasserts: add ValidationSets.Sets method

* o/assertstate: add deviceContext to ForgetValidationSet function so that change can happen during remodel

* o/devicestate: attempt to handle rollback of validation sets during failed remodel

* overlord: test for replacing conflicting validation sets during remodel

* o/assertstate: update ForgetValidationSet to take in a DeviceContext and to allow for forcing removal even if the validation set is in use by the model

* o/devicestate: roll back validation set changes on remodel failure

* o/devicestate: make sure that validation sets unrelated to the model survive a remodel

* o/devicestate: rename param in installedSnapRevisionChanged

* o/devicestate: rename field newSnapRevision to newRequiredRevision in modelSnapsForRemodel

* o/devicestate: simplify loops in checkForInvalidSnapsInModel

* o/devicestate: compare validation sets using SequenceName methods

* o/devicestate: fail remodel if we attempt to use an unasserted snap as a specific revision

* tests/nested/manual/remodel-offline: fix test to actually use validation set

* o/devicestate: create helper for creating snapstate.RevisionOptions during remodel

* o/devicestate: name param literals for clarity

* o/devicestate: invert logic to eliminate double negative

* o/devicestate: fix missed inversion of logic

* o/assertstate: update comment on ForgetValidationSetOpts.ForceForget

* overlord, o/devicestate: update remodel test to change models that contain the same validation set

* o/assertstate: test ForceForget functionality in ForgetValidationSet

* o/devicestate: rename function newRevisionOptionsForRemodel to revisionOptionsForRemodel

* o/assertstate, o/devicestate, daemon: remove unneeded DeviceContext param from ForgetValidationSet

* o/devicestate: remove println

* o/devicestate: clarify comment in rollback of adding validation sets

* o/devicestate: rename variable in enforceValidationSetsForRemodel

* o/snapstate: clarify error when attempting to install/refresh local snap with different revision than requested

* o/devicestate: naming consistency

* o/devicestate: simplify error when model is missing snap that is required in validation set

* asserts, overlord, o/devicestate: rename SequenceName to SequenceKey and prefix the series to the string that is returned
2023-12-12 10:00:48 +01:00
Alfonso Sánchez-Beato
768021bf03 many: add components side info to snapstate
Add components information to the snap state. This is included in the
Sequence variable, so we need to handle in a special way the
marshaling to keep compatibility with state files created by older
snapd versions.

The change to the Sequence field implies multiple changes in tests
that use it. Ancillary methods to handle this have been created.
2023-12-02 09:40:31 +00:00
Andrew Phelps
38a74ecb3f a/snapasserts, o/assertstate: add functions to help during remodel (#13345) 2023-11-28 15:54:39 -05:00
Michael Vogt
7cc3b748ea assertstate: fix nil access in checkConflictsAndPresence
The code checks that `as` is of type `asserts.ValidationSet`. Hower
when it is not the (nil) value of the failed type assertion is
used in the error. So if this ever is hit it would causes a crash.
2023-07-25 08:46:36 +02:00
Miguel Pires
16aa83a96d many: rename store opt from IsAutoRefresh to Schedule
The store option that controls whether requests carry the "Scheduled"
header will soon be on for non-continued auto-refreshes. This renames
the field to avoid a mismatch between its name and when it's set.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-07-06 08:30:37 +01:00
Philip Meulengracht
120bc68a11 o/assertstate: take the validation-set enforce mode into account when forgetting/enforcing validation-sets
Consult with the model assertion when manipulating validation-sets, to verify that the one we are
manipulating is not explicitly controlled by the assertion. In this case there will be certain
restraints in terms of sequence, or whether it must be enforced.
2023-05-15 13:42:09 +02:00
Philip Meulengracht
cd52cdd0d8 o/devicestate: track included validation-sets in seed on first boot (#12757)
* o/devicestate: add initial code for tracking validation-sets on first boot

* o/devicestate: add possibility for setting validation sets in model setup for firstboot20 tests

* o/devicestate: allow enforcing validation-sets before device is marked seeded, add unit tests to verify tracking completes.

* o/devicestate: restore preseed done task order

* o/devicestate,o/snapstate: create a Local variant of EnforceValidationSets and parameterize enforce-validation-sets task

* overlord: add clarifying comments for the local parameter to "enforce-validation-sets"

* o/assertstate,o/devicestate: add unit tests for  ApplyLocalEnforcedValidationSets and firstboot UC18

* o/devicestate: fix wrong comment

* o/devicestate: fix static check for typo

* o/devicestate: add additional unit test checks

* o/snapstate,o/devicestate: review feedback, additional unit tests still needed for handler changes

* overlord: add handler unit tests, add more checks for task data being passed in the firstboot tests

* o/snapstate: add parameter checks for the DoEnforceValidationSetsTask handler
2023-04-26 08:44:48 +02:00
Zeyad Yasser
54c6a1d8c3 refactor: replace IsNotFound usages for errors.Is(err, &NotFoundError{}) 2023-02-09 16:02:40 +00:00
Miguel Pires
1f5f8dee04 o/assertstate: add Sequence() to val set tracking
Since Current sometimes differed from PinnedAt even when PinnedAt != 0,
be more robust by using a Sequence() method that takes PinnedAt into
account when reading as well.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-11-21 18:00:38 +01:00
Miguel Pires
1807c4f031 o/assertstate: set val set 'Current' to pinned sequence
Make sure that the current sequence number in the validation set
tracking is set to the same as the pinned sequence number, if the
validation set is pinned (PinnedAt != 0).

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-11-21 18:00:38 +01:00
Miguel Pires
23e4fc658e o/assertstate: improve variable names
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-10-03 13:54:51 +01:00
Miguel Pires
e3cd90ae91 o/assertstate: iterate on names
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-10-03 13:01:01 +01:00
Miguel Pires
be98d9144c o/assertstate: s/Enforce/ApplyEnforced/
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-10-03 09:54:50 +01:00
Miguel Pires
f277d90279 o/snapstate: mostly test and documentation improvements
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-30 17:13:33 +01:00
Miguel Pires
1f2ab20c4c o/snapstate: auto-resolve validation set enforcement constraints
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-29 11:41:22 +01:00