1079 Commits

Author SHA1 Message Date
Andrew Phelps
411ac6c548 o/snapstate: install components from the store (#14092)
* o/snapstate: replace some args to doInstallComponent with a flags type

* o/snapstate: create validate-component task when installing component from the store

* o/snapstate: add arg to doInstall for components

* o/snapstate: install components from store in StoreTarget

* o/snapstate: add component fields to fakeSnappyBackend ops

* o/snapstate: add helpers for checking tasks for installing components

* o/snapstate: add testing channel that adds a component to snap that is being installed

* o/snapstate: use instance name in path to that is set for remove ops in test backend

* o/snapstate: extend doInstall to handle components

* o/snapstate: refactor addTask in doInstall to update prev pointer to eliminate manual tracking of last task

* o/snapstate: test tasks created when installing component from the store

* o/snapstate: remove component files when snap file is also ephemeral

* o/snapstate: change component types in error strings to be more clear

* o/snapstate: always install components for each snap in a consistent order

* o/snapstate: replace pointer params to doInstall with copies

* o/snapstate: unexport componentTarget

* o/snapstate: add TODOs about handling components

* o/snapstate: add comment explaining why we do not create setup-profiles task for new components when installed with snap

* o/snapstate: remove usage of new go stdlib function

* o/snapstate: fully initialize ComponentSetup in store's InstallGoal implementation

* o/snapstate: rename componentInstallFlags.SkipSecurity to SkipProfiles

* o/snapstate: move componentTarget struct

* o/snapstate: eliminate componentTarget type

* store, o/snapstate: swap out resources slice in SnapAction for flag in RefreshOptions

* o/snapstate: remove this change for now, it should not be a part of this PR

* o/snapstate: add TODO about ordering component and snap hook tasks

* o/snapstate: rename variable for readability
2024-06-26 18:30:49 +01:00
Andrew Phelps
8377d7dbae store: interface with the store to request snap resources (#13982)
* store: add resources to snap action results

* store: parse resources into snap components in store responses

* store: only request resources in SnapAction if one of the actions includes resources

* snap: add function for converting a string to a ComponentType, with checks

* store: explictly ignore unknown component types

* store: remove usage of strings.CutPrefix

* store: add comment noting that resources do not have download deltas

* snap: correct doc comment on ComponentTypeFromString

* store: remove incorrect usage of description in component summary
2024-06-03 17:26:30 +02:00
Miguel Pires
9e7fed9fed o/snapstate: apps don't wait for reboot on classic w/ kernel (#13852)
Refreshes of essential snaps are organised to have a single reboot.
However, on classic systems with kernel/gadget snaps this means that
apps must wait for the essential snaps and therefore for a reboot. To
prevent apps from blocking until then, this change splits a refresh into
two tasksets. One with essential snaps which is still organised
according to the single reboot and another with apps and their bases
which can complete before the reboot. Some constraints on this are snapd
which is always refreshed first and apps that depend on the model base.
In those cases, we add dependencies across essential/non-essential sets.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-05-02 12:26:42 +02:00
Miguel Pires
a3740a0a66 store: fix race condition warning in test
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-04-30 13:55:20 +02:00
Maciej Borzecki
02f4e53585 store: conditionally skip download monitoring unit tests
Skip download speed monitoring unit tests if SNAPD_SKIP_SLOW_TESTS is set. The
test is based on getting the timings right and so it becomes generally
unreliable when running in super slow environment, such as a build VM in OBS,
thus failing like so:

```
[ 2317s] ----------------------------------------------------------------------
[ 2317s] FAIL: store_download_test.go:886: storeDownloadSuite.TestTransferSpeedMonitoringWriterHappy
[ 2317s]
[ 2317s] store_download_test.go:903:
[ 2317s]     c.Check(store.Cancelled(ctx), Equals, false)
[ 2317s] ... obtained bool = true
[ 2317s] ... expected bool = false
[ 2317s]
[ 2317s] store_download_test.go:904:
[ 2317s]     c.Check(w.Err(), IsNil)
[ 2317s] ... value *store.transferSpeedError = &store.transferSpeedError{Speed:0} ("download too slow: 0.00 bytes/sec")
[ 2317s]
[ 2317s] store_download_test.go:907:
[ 2317s]     // we should hit at least 100*5/50 = 10 measurement windows
[ 2317s]     c.Assert(w.MeasuredWindowsCount() >= 10, Equals, true, Commentf("%d", w.MeasuredWindowsCount()))
[ 2317s] ... obtained bool = false
[ 2317s] ... expected bool = true
[ 2317s] ... 9
```

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-04-05 09:16:25 +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
Zygmunt Bazyli Krynicki
b8e9bed636 many: allow building without bolt using nobolt tag (#13534)
* many: allow building without bolt using nobolt tag

Bolt is an abandoned project. Upstream is not accepting any patches.
Debian has three versions of bolt, none of which build on riscv64 due to
the lack of appropriate architecture tags.

In Debian, bolt is not built from the vendored package but instead from
the distribution package, one of three in the archive, each capturing a
different, outdated and differently patched fork.

Fortunately, bolt is not really heavily used in snapd. While we try to
address the issue regarding bolt and riscv64, we can continue to build
snapd on riscv64 without the ability to store information only used by
command-not-found helpers.

Allow advisor to fail with advisor.ErrNotSupported when snapd is built without
bolt support. Tests for the store, overlord package and the "snap advise"
command are adjusted to skip certain tests when that error is returned.

Debian-Bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1010686

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

* advisor: adjust error message

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

* tests: run unit tests for nobolt build tag

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

* packaging: drop bolt from debian dependencies

With the ability to build snapd without bolt support, we can drop the patch
responsible for using non-forked bolt.  Bolt is really only needed by the
advisor package, which is used and consumed as a command-not-found data set.
None of that is effective on Debian, making maintenance easier.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

* packaging: do not use bolt on Debian

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

---------

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2024-02-07 13:48:42 +01:00
Andrew Phelps
ec12734fa2 store, o/storecontext, o/devicestate, o/c/configcore: use store.access to disable access to snap store (#13198)
* o/c/configcore: add store.access configurable to allow store access to be disable

* o/devicestate: expose store.access via the storeContextBackend

* overlord,o/storecontext: expose store.access via storecontext.storeContext

* store: use store.access to disable access to snap store when using methods store.Store

* configcore: add tests for validation of store.access

* store: test offline store functionality

* o/storecontext: add test case for StoreAccess

* store, o/c/configcore, o/storecontext: remove usage of online as valid value for store.access

* store: correct ErrStoreOffline message

* store: add unit test to check that http retries do not happen when store is offline

* store: rename isStoreOnline to checkStoreOnline for consistency

* store: remove outdated comment

* o/c/configcore: convert handleStoreAccess to be a fsOnlyHandler since it does not need state

* store: disable more instances of store network access

* overlord,o/storecontext: combine ProxyStoreer and StoreAccessQuerier into one interface

* o/devicestate: add test for storeContextBackend.StoreAccess

* store: modify Store.endpointURL to check if the store is offline

* o/storecontext: simplify TestStoreAccess test case

* store: make Store.assertionsEndpointURL return an error if the store is offline

* store: add more test cases for an offline store

* o/devicestate: remove outdated comment

* store: remove outdated comment

* store: fix outdated comments

* store: test that SnapAction returns an error when the store is offline

* store: clarify ErrStoreOffline message

* o/c/configcore: move store.access registration for more general use

* o/c/configcore, dirs: write config file for snap-repair in store.access handler

* cmd/snap-repair: consume snap repair config file to check if store access is offline

* overlord: remove accidental goimports change

* image: set root dir to temp dir for tests

* o/c/configcore: remove build flags from store.go

* store: rename checkStoreOnline to checkStoreOffline for consistency

* Revert "store: rename checkStoreOnline to checkStoreOffline for consistency"

This reverts commit dd07e487127964c417eeac11d1d954a5d1132469.

* cmd/snap-repair, o/c/configcore: use unexported repairConfig for configuring snap-repair

* o/c/configcore: fix broken test following type rename

* o/c/configcore: remove defined error to make future modifications less error-prone

* o/c/configcore: remove superfluous $

* store, o/devicestate, o/storecontext: change StoreAccess methods to StoreOffline methods that return a boolean indicator

* dirs, o/c/configcore: make sure to check fsOnlyContext for a different root dir

* cmd/snap-repair: move this change into a seperate PR

* o/c/configcore: fixup some comments

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

* o/c/configcore: add test for setting store.access on filesystem only apply

---------

Co-authored-by: Miguel Pires <miguelpires94@gmail.com>
2023-09-27 15:27:21 -04: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
Samuele Pedroni
1437ce25d4 store: use as much from snap-yaml as possible if available
then applies any store only/store override data

this should help make any pre-download checks/validations work correctly
2023-09-14 08:34:36 +02:00
Alfonso Sánchez-Beato
b99b03f0d1 snap: add components field to snap.yaml 2023-08-18 15:39:58 +02:00
Zeyad Gouda
0cb8e9d29b store: reword panic message and add test to check httputil client has CheckRedirect defined
Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
2023-08-09 14:24:49 +02:00
Zeyad Gouda
e8c7ba5902 store: extract auth header removal into a function and panic if CheckRedirect is nil
Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
2023-08-09 14:24:49 +02:00
Zeyad Gouda
95fdeacc37 store: remove auth headers from being sent in CDN redirects
See also: https://bugs.launchpad.net/snapd/+bug/2027993

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
2023-08-09 14:24:49 +02:00
Ernest Lotter
2dbc1b6dfb snap, store: filter out invalid snap edited links from store info and persisted state (#12983)
* snap, store: avoid invalid snap edited links from store

* snap, store: extend unit tests

* snap, store, o/snapstate: remove temporary comments

* store: add test case for empty link from store

* snap, store: changed how edited links from store are normalized
2023-08-04 12:02:50 +02:00
Zeyad Gouda
8e76198cfc store: remove refresh hold data in store requests for older proxies
"held" is supported starting v54 of the store API. Some store proxies might
be running older versions of the store which will fail with: "Additional
properties are not allowed ('held' was unexpected)".

This approach retries bad requests, with the new knowledge of the store
version parsed from the response header ""Snap-Store-Version"" and removes
the "held" field if store version is less than v54.

This approach is generic and can be used for other new fields using
minStoreVersion(storeVer, <MIN_VER>).

* o/snapstate: make debug message consistent and store version check explicit

* o/snapstate: check Snap-Store-Version header is valid for retry logic and fix typo in test name

* o/snapstate: extract refresh hold retrieval into a helper function

* o/snapstate: move effectiveRefreshHold to autorefresh.go

* o/snapstate: bump store api requirement to v55 for held field support

	* v55 includes bug fixes related to held field

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
2023-07-25 14:08:37 +01:00
Miguel Pires
3355b78c21 o/snapstate: send refresh hold data in store requests
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-07-25 14:08:37 +01:00
Miguel Pires
f1e72fa0bd many: rename dl opt from IsAutoRefresh to Scheduled
Renamed the field in DownloadOptions to keep the names consistent with
each other.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-07-06 08:30:37 +01: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
44dc7cfe8c image, store/tooling: correct how validation-sets were sent to store (#12763)
* image, store/tooling: fix how validation-sets and required revision was set for snaps that were controlled by validation-sets. Mirror how it's done for the snap validate --refresh.

* image: fix unit tests and optimize a bit how many times we call validationSetsAndRevisionForSnap

* image: wrong revision in comment

* image: review feedback, add TODO around missing logic for optional snaps, and add unit test for conflict logic that is now added

* image: review feedback, be a bit more consistent in naming between keys and actual validation-set objects
2023-04-26 15:42:00 +02:00
Philip Meulengracht
bdc82f35d7 image: pass validation-sets to store actions (#12692)
* image: pass validation-sets to store functions

* image: get fetched validation set assertions and use them for keys to store

* image: add additional check to unit test

* image: move seed database into imageSeeder structure

* image: fix unit test
2023-04-20 14:59:18 +02:00
Robert Ancell
8bde56574a store: return categories in find results (#12513)
* store: Return categories in find results

This allows clients to show the categories as snapcraft.io does.

Fixes https://bugs.launchpad.net/snapd/+bug/1838786

* Remove unnecessary CategoryInfos type

* Only show categories when using --verbose

* Add tests for snap info printing categories

* Update cmd/snap/cmd_info.go

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

* Update cmd/snap/cmd_info.go

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

* v1 store API doesn't return categories

* Drop category information from snap info

Other snap commands don't support categories yet, this change should be part of that.

* Add /v2/categories and support /v2/find?category=foo

* Add note that section is deprecated

* Update client/packages.go

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

* Update daemon/api_categories.go

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

* Update daemon/api_categories.go

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

* Update daemon/api_categories.go

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

* Update store/store.go

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

* Update store/details_v2.go

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

* Update client/packages.go

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

* Improve test error message

* Drop copy/pasted comments that doesn't seem relevant

* Remove unused import

* Reorder CategoryInfo struct

* Fix accepted content type for store v2/snaps/categories request

* Set APILevel for v2/snaps/categories request

* Update accept string used to get data for store test

* Make /v2/categories return objects not just strings

---------

Co-authored-by: Miguel Pires <miguelpires94@gmail.com>
2023-04-06 10:02:09 +02:00
Philip Meulengracht
cc281dff0d image,store: introduce AssertionSequenceFormingFetcher in ToolingStore (#12665) 2023-03-22 20:55:46 +01:00
Philip Meulengracht
ae6489f798 golang: remove deadcode linter 2023-03-09 14:43:47 +01:00
Samuele Pedroni
52a8d7d2bb image,store: ensure to fetch assertions appropriate for the snapd in the image
this fetches assertions using the right assertion max formats based
on what is supported by the snapd from the system snap going into the image
2023-02-17 14:42:00 +01:00