991 Commits

Author SHA1 Message Date
Maciej Borzecki
8c56532e35 client: expose a helper for executing raw queries to the snapd API
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-07-04 07:35:07 +02:00
Alfonso Sánchez-Beato
64decd9d15 client: define components type 2024-06-18 18:31:42 +01: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
Philip Meulengracht
b6241ccf8a many: add support for user daemons in "snapctl services" (#13806)
* many: add support for user daemons in "snapctl services" by introducing the same --user/--global switches as "snap services"

* o/hookstate/ctlcmd: remove error messages

* cmd/snap,o/hookstate/ctlcmd: correct some doc strings
2024-04-12 13:32:52 +02:00
Philip Meulengracht
81309e59a9 daemon,cmd/snap: support for user services in snap services (#13381)
* daemon,cmd/snap: support for user services in snap services

* NEWS: update news to reflect this functionality

* cmd/snap: add missing unit tests

* many: use interface instead for StatusDecorator to allow for unit testing

* daemon: fix a static check for a range loop where a variable could be omitted

* daemon,cmd/snap: support user-service status of the root user with a --user switch

* t/main/services-user: add a case for root user

* t/main/services-user: fix wrong filename

* cmd/snap: fix TestAppStatus unit test failing

* cmd/snap: extend help for "snap services" to describe the new --global and --user switches

remove errors on redundant switches, remove unneeded argument, move validation of arguments closer to entry of Execute

* cmd/snap: refer directly to fields in the help docs
2024-04-11 12:45:48 +02:00
Zeyad Yasser
02908bcfc9 client: add support to send notices (#13791)
This is a backport from pebble:
https://github.com/canonical/pebble/pull/297

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
2024-04-09 14:18:50 +02:00
Miguel Pires
79c5ac14b2 many: remove usages of deprecated io/ioutil package (#13768)
* many: remove usages of deprecated io/ioutil package

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

* .golangci.yml: remove errcheck ignore rule for io/ioutil

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

* run-checks: prevent new usages of io/ioutil

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

---------

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-04-03 23:23:24 +02:00
Philip Meulengracht
de453d009f many: move ServiceScopeOptions into clientutil and use in both client cases instead of having it duplicated 2024-03-14 19:18:24 +01:00
Oliver Calder
b78a22a2ee client,daemon: expose features supported/enabled in /v2/system-info
Add a "features" field containing a map of feature flag names to boolean
subfields for whether the feature is "supported" and/or "enabled", along
with an "unsupported-reason" if the feature is not supported.

Feature flags which are not set to true or false are omitted from this
map. Feature flags may be unsupported but nonetheless enabled. This
indicates that the feature flag has been set to true, but the backing
feature itself is not currently supported.

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
2024-03-14 08:39:09 +01:00
Philip Meulengracht
261d1c2e90 client,cmd/snap: introduce --user, --system and --users switches for snap service operations (#13368)
* client,cmd/snap: introduce --user, --system and --users switches for snap service operations

* client,o/servicestate: move Scope/UserSelection to client for reuse in client

* client,cmd/snap: improve handling of user and scope args

* NEWS: update news to reflect that we now support user daemons in start/stop/restart

* cmd/snap: some review feedback on allowed input

* t/main/services-user: add additional user to verify services are correctly affected

* cmd/snap: do not allow --system --user together, do not allow --users with =all

* tests,cmd: use --users=all in test, dont mark --users optional, enforce a value for it, add case for --system --users=all in spread test

* cmd/snap: add a comment for unreachable code, and correct a couple of messages
2024-03-13 14:57:35 +01: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
Andrew Phelps
e2b17d0250 o/devicestate: add concept of default-recovery-system (#13634)
* o/devicestate: use default recovery system that is independent of seeded systems

* o/devicestate: use default recovery system from state when rebooting without a specified label

This change has the side effect of enabling users to reboot into any
recovery system with "snap reboot --recover", regardless if it is the
default or the most recently seeded system.

* o/devicestate: expose default-recovery-system via DeviceManager.Systems()

* daemon, client: expose default-recovery-system via the systems api

* c/snap: update help text for reboot to match new default-recovery-system behavior

* c/snap: add default-recovery-system to notes section in recovery cli output

* o/devicestate: prevent removal of default recovery system

* o/devicestate, daemon: use default-recovery-system for factory-reset mode as well

* c/snap: update help text to mention that default recovery system is used for factory-reset

* o/devicestate: make a newly seeded system the default-recovery-system

* o/devicestate: add helper to DeviceManager for getting the default-recovery-system

* o/devicestate: use default-recovery-system for install mode as well

* c/snap: correct "snap reboot" help text

* o/devicestate, daemon: store more information for default-recovery-system in state to match seeded systems

* cmd/snap: tweak default recovery system notes

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>

* o/devicestate: make sure that we're storing correct type when setting default-recovery-system, extend tests

Make sure we're storing the right type when setting default-recovery-system.

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>

---------

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
Co-authored-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-02-29 11:36:00 -05:00
Zeyad Gouda
41512c4860 many: add "refresh-inhibited" select query to /v2/snaps
This select query allows only showing snaps that whose refresh
is inhibited.

* daemon: only show monitored snaps in "refresh-inhibited" select
* many: update refresh-inhibit-proceed-time field to refresh-inhibit in snaps api
* many: address review comments
* o/snapstate: export IsSnapMonitored
* o/snapstate: add doc comment for IsSnapMonitored
* daemon: check snap proceed time
* daemon: adjust proceed-time check
* client: update SnapRefreshInhibit.ProceedTime doc comment

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
2024-02-28 12:37:31 +01:00
Zeyad Gouda
98c6cbdab2 many: add refresh-inhibit-proceed-time field to snaps api
This field determines the time after which a pending refresh
is forced for a running snap in the next auto-refresh.

* many: prepare RefreshInhibitProceedTime for configurable max inhibition
* many: remove unneeded newline in RefreshInhibitProceedTime doc comment
* client/packages_test: test client snap with nil RefreshInhibitProceedTime
* client/packages_test: make TestClientSnap tests more readable
* many: precompute refreshInhibitProceedTime in aboutSnap
    This avoids locking/unlocking each snap to get RefreshInhibitProceedTime.
    We get the proceed time while already holding the lock.

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
2024-02-19 08:54:18 +01: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
Miguel Pires
d3055c96d2 many: add CLI support for getting and setting aspects (#13492)
* aspects: namespace Get value at API, not aspects/

Make aspects/ return the retrieved value without the namespace keyed by
the request (per the spec). Since the API supports a GET with many
request paths, it can then build the namespace only once with all the
values it retrieved.

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

* many: add a CLI for aspect get and set

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

---------

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-01-24 17:43:53 +02:00
Samuele Pedroni
c500a6c877 client,tests: do not try to change the gid when reading/removing auth.json (#13321)
* tests: cover auth.json NFS related fixes in nfs-support test

* client,tests: do not try to change the gid when reading/removing auth.json

the group is not relevant for this even under NFS, otoh
trying to switch it fails under running with sg

this makes sg lxd -c "snap..." work again

* skip nfs-support in ubuntu trusty

group 'systemd-journal' does not exist

---------

Co-authored-by: Sergio Cazzolato <sergio.cazzolato@canonical.com>
2023-11-16 17:07:06 +02:00
Miguel Pires
29c9752d66 many: s/ioutil.WriteFile/os.WriteFile (#13217)
Replace ioutil.WriteFile with os.WriteFile since the former has been
deprecated since go1.16 and simply calls the latter.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-09-26 11:38:46 +01:00
Zeyad Yasser
b028176e30 many: implement snap install --prefer (#12993)
* many: implement snap install --prefer

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>

* many: add more tests and validation to --prefer install flag

* client/snap_op: add tests for prefer flag
* daemon/api_snaps: add input validation for prefer flag
	* prefer flag cannot be used with unaliased flag
	* prefer is supported only for install action
	* prefer is not supported int multi-snap operations
	* add tests
* o/snapstate: prevent implicilty setting unaliased flag when prefer flag is passed
	* add tests
* spread: update parallel-install-auto-aliases to cover edge cases for --prefer
	* check --prefer interaction with --unaliased implicit passing
	* resolve conflicts after merging master

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>

* spread: fix comment typo in main/parallel-install-auto-aliases

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>

* daemon: update flags conflict error message to be consistent

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>

* many: adjust help texts and move Prefer closer to Unaliased in structs

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>

* daemon/api_snaps_test: update TestPostSnapPreferWrongAction to match updated error message

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>

---------

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
2023-07-31 16:28:59 +02:00
Michael Vogt
c0e8ad56f3 client: fix specificErr handling in SnapshotExport() (#13001)
* client: fix specificErr handling in SnapshotExport()

The code was checking generating a `specificErr` but then checked
`if err != nil {` (and not check for specificErr) and also lacked
a unit test.

When adding the code test it became clear that the other issue
there is that the response body was never read so r.err() would
always return nil.

This commit fixes both issues.

* client: fix TestClientExportSnapshotSpecificErr naming

Co-authored-by: Miguel Pires <miguelpires94@gmail.com>

---------

Co-authored-by: Miguel Pires <miguelpires94@gmail.com>
2023-07-26 11:19:13 +02:00
Michael Vogt
57c8e27e91 client: extract realUidGid() helper (thanks to Oliver for the suggestion) 2023-07-20 13:52:49 +02:00
Philip Meulengracht
bd6fddcc3e client,osutil: support for accessing auth.json without root
Revive PR 4983 from @chipaca as the launchpad issue is still relevant, and we moved on to newer go versions a long time ago.
2023-07-20 13:52:49 +02:00
Alfonso Sánchez-Beato
8a9f3c889e many: move helper gadgettest function to gadget
Move SetEnclosingVolumeInStructs from gadgettest to gadget package so
it can be used from production code.
2023-07-05 07:56:23 +01:00
Alfonso Sánchez-Beato
7841d66e9f client: set enclosing volume when retrieving system details
As it is needed to answer correctly questions for partial gadgets.
2023-07-05 07:56:23 +01:00
Alfonso Sánchez-Beato
45b57be9fa client,cmd: support for offline remodeling
This adds options --snap and --assertion to the "snap remodel"
command, which can be used to pass local files to snapd so offline
remodelling is possible.
2023-06-22 12:44:28 +02:00