29 Commits

Author SHA1 Message Date
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
Andrew Phelps
935b84f5f0 client, cmd/snap, daemon: api level changes for introducing offline flag to remodel (#13507)
* daemon: add offline field to remodeling JSON payload

* client, cmd/snap: add offline boolean option for remodeling to client and cli interface

* daemon: make snap files optional in the "multipart/form-data" remodel api

* tests/nested/manual/remodel-offline: add variants to test different combinations of installed/local snaps/assertions

* client: update comment on RemodelWithLocalSnaps to mention not contacting the store

* c/snap: remove unneeded var declaration

* tests/nested/manual/remodel-offline: clarify section that acks/adds the validation set assertion

* tests/nested/manual/remodel-offline: fix shellcheck warning on test's -a flag

* client: verify that normal (online) remodel does not set offline field in JSON payload
2024-02-02 11:41:55 +02:00
Andrew Phelps
8a7f3f2c63 o/devicestate, overlord, daemon: add flag to devicestate.Remodel to force an offline remodel (#13494)
This flag will enable offline remodeling, even when all snaps required for the remodel are not provided locally. The remodel will fall back to using already installed snaps in situations that it can. This includes simple channel switches, and when the required revision of a snap is already installed. If a snap is required for the remodel, and the snap is neither provided locally or already installed, then the remodel will fail.

* snap: add support for errors.Is for NotInstalledError

* o/snapstate: add Type to SnapSetup created in snapstate.Switch

* o/devicestate, overlord, daemon: add flag to devicestate.Remodel to force an offline remodel

This flag will enable offline remodeling, even when all snaps required
for the remodel are not provided locally. The remodel will fall back to
using already installed snaps in situations that it can. This includes
simple channel switches, and when the required revision of a snap is
already installed.

* o/devicestate: re-word comment on RemodelOptions.Offline

* o/devicestate: convert sideInfoAndPathFromID to a method on remodelVariant

* o/devicestate: make comment in UpdateWithDeviceContext more clear

* o/devicestate: add TODO about looking for other revisions

* o/devicestate: add comment explaining that case in UpdateWithDeviceContext is unexpected

* o/devicestate: prefix unexpected state error with "internal error"

* o/devicestate: use var for default initialization

* o/devicestate: invert if in UpdateWithDeviceContext to reduce some nesting

* o/devicestate: rename sideInfoAndPathFromID and add some clarifying comments

* o/devicestate: remove unused parameter from remodelEssentialSnapTasks

* o/devicestate: correct copy-pasted comment
2024-01-30 15:17:38 +01:00
Alfonso Sánchez-Beato
2c8094ebca daemon,overlord: add support for offline remodeling
Allow remodeling by using local snaps and assertions.
2023-08-03 17:45:52 +02:00
Michael Vogt
416177122d daemon: fix crash when a non-model assertion is sent /v2/model
A remodel with an assertion that is not a model assertion will
currently crash the daemon. This commit fixes this and adds a
test.
2023-07-25 08:47:10 +02:00
Alfonso Sánchez-Beato
18f4aa798f daemon: check mime type for POST /v2/model 2023-06-22 12:44:28 +02:00
Miguel Pires
d8eb8dc9df many: replace ErrNoState equality checks w/ errors.Is() 2022-05-20 10:07:29 +01:00
Philip Meulengracht
56f17ad957 many: review feedback
move ModelAssertJSON, add additional unit test, add additional members to test models, rename and reorder parameters
2022-05-12 10:33:31 +02:00
Philip Meulengracht
1b232d0973 multiple: use a shared structure for ModelAssertJSON in asserts package.
review feedback
2022-05-12 10:33:31 +02:00
Samuele Pedroni
1bb7387787 daemon,tests: support forgetting device serial via API (#11135)
this is done by posting {"action":"forget"} to /v2/model/serial

a flag no-registration-until-reboot is also supported
2021-12-02 15:29:34 +01:00
Samuele Pedroni
716b13b5f9 daemon: simplify SyncResponse
it doesn't take Meta anymore
2021-06-03 13:49:26 +02:00
Samuele Pedroni
edf0b3f422 daemon: use apiError in api_model.go 2021-06-01 18:48:44 +02:00
Samuele Pedroni
25e9e2e1f9 daemon: start coalescing resp into respJSON and evaporating Meta
the cleanliness gained by having two structures with almost
the same fields is probably not enough to justify both of them,
especially because daemon is where we are supposed to build
responses, we might as well deal with the details

Meta was a quick hack, also it hasn't really grown since so we can
try to remove it now

AsyncResponse never takes anything over the result but the change id
2021-05-28 19:48:19 +02:00
Samuele Pedroni
a710d6c266 daemon: tighten access to POST /v2/model to be root only 2021-05-26 16:21:41 +02:00
Samuele Pedroni
bb7eaf9dfb Merge remote-tracking branch 'upstream/master' into daemon-access-check 2021-05-19 17:57:13 +02:00
Alberto Mardegan
cccdcf8639 daemon: fix linter errors 2021-05-05 14:28:53 +03:00
James Henstridge
885de6ed72 Merge remote-tracking branch 'upstream/master' into daemon-access-check 2021-01-04 15:28:41 +08:00
Samuele Pedroni
219ebb3a95 daemon: move some more api tests from daemon to daemon_test
this covers tests for api_model.go, api_systems.go, and recent
api_system_recovery_keys.go
2020-11-30 21:53:36 +01:00
James Henstridge
6dca0bae80 daemon: reorder access checkers after method functions, to match struct layout 2020-08-27 13:48:57 +08:00
James Henstridge
8dd53dfad6 Merge remote-tracking branch 'upstream/master' into daemon-access-check 2020-08-07 08:52:36 +08:00
James Henstridge
ea3c3c4b6a daemon: don't export access checkers, and rename RootOnlyAccess to rootAccess 2020-08-07 08:42:36 +08:00
James Henstridge
14b9e7ec62 daemon: have each command list a ReadAccess and/or WriteAccess policy directly.
This is simpler than determining how the current set of flags
interoperate, and more closely matches how API access is documented to
work.
2020-08-07 08:32:56 +08:00
Samuele Pedroni
3c944b608b daemon: switch to use client.ErrorKind and drop the local errorKind... 2020-08-02 16:22:51 +02:00
Ian Johnson
f75f7bd2c2 many: rename error kind for assertions not found to be consistent
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2019-08-22 17:27:56 -05:00
Ian Johnson
2ba10914a3 daemon/api_model.go: use status codes directly
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2019-08-13 19:14:09 -05:00