* daemon: establish a cancelation chain for incoming API requests
Establish a cancelation chain for incoming API requests, to ensure orderly
shutdown. This prevents a situation in which an API request, such as notices
wait can block snapd shtudown for a long time.
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* daemon: return 500 when the request context gets canceled
Request's can be canceled based on the code actually issuing a cancel on the
associted context, hence an Internal Server Error seems more appropriate.
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* o/snapstate: leave TODOs about using caller provided context
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* daemon: pass down request context where possible
Pass the context from the API request further down.
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* daemon: set context in snap instruction for many-snap operation
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* daemon: pass context as an explicit parameter to request handlers
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* daemon: pass context
Thanks to @ZeyadYasser
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* daemon: comment on Start() taking a context.
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* daemon: add unit tests targeting context passed to Start()
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* daemon: drop unit test for hijacked context
The test isn't very useful. Another option to trigger this would be to call
Stop() without a prior call to Start(), but this segfaults on
d.standbyOpinions.Stop(), so it'c clear this needs a followup fix or callign
Stop() this way isn't supported.
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
---------
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
The test creates two symbolic links but reuses some information about them by
passing the same variable. Use the proper variable to avoid being sensitive to
symlink mtime differences on fast enough systems.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Information about components of a snap is repacked from a map to a list. Since
map iteration does not guarantee stability, we need to sort the list of
components to keep the tests reliable.
Fixes the following failure:
FAIL: api_snaps_test.go:1611: snapsSuite.TestMapLocalFieldsWithComponents
api_snaps_test.go:1809:
c.Check(daemon.MapLocal(about, nil), check.DeepEquals, expected)
... obtained *client.Snap = &client.Snap{...}
... expected *client.Snap = &client.Snap{...}
... Difference:
... Components[2].Name: "comp-4" != "comp-3"
... Components[2].Summary: "" != "summary 3"
... Components[2].Description: "" != "description 3"
... Components[3].Name: "comp-3" != "comp-4"
... Components[3].Summary: "summary 3" != ""
... Components[3].Description: "description 3" != ""
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
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>
Add a Provenance to snap.ComponentInfo. This allows snap pack to work with components that define a provenance in their component.yaml file.
* snap, interfaces, daemon: add Provenance field to ComponentInfo
* s/pack: test packing component with provenance
* snap: validate provenance when parsing component.yaml
* many: replace interfaces.Repo.AddSnap with AddAppSet
* interfaces: remove repo.RemovePlug since it is unused
* interfaces: simplify check for a snap's presence in interfaces repo
* interfaces: update doc comment on Repository.AddAppSet
* o/ifacestate: fix duplicate init of app set following refactor in master
* o/snapstate: fix bug that caused implicit slots to be added to core and snapd snaps
Access to /v2/snaps/{name} is required for snap-refresh-observe
because it is needed to get the path for the XXXXX.desktop file,
which is needed for the icon and the visible name.
It should not be a problem because /v2/snaps is already
enabled.
* many: update snap.ReadComponentInfoFromContainer to take in an optional snap.ComponentSideInfo that contains the component revision
* snap: add back NewComponentInfo function
* daemon, snap, interfaces: replace manual creation of ComponentInfo with usage of NewComponentInfo
* daemon: make sure to re-pin validation sets that were already pinned when enforcing new validation sets
* tests: update snap-refresh-enforce to verify that validation sets do not become unpinned when enforcing new sets
* o/snapstate: when invoked for rollback, check for any changes related to snapd
When the snapd.service unit fails to be activated, an OnFailure handler will
execute snap-failure which in turn starts the snapd process from the previous
revision of the snap with SNAPD_REVERT_TO_REV set in its environment. It may
happen that the snapd unit fails at runtime without an associated change to the
snapd snap, however snap-failure is not able to detect such case, and so the
snapd process started in its context would continue to run. Avoid this by
extending the logic within snapd to check it if has been started by snap-failure
with the intention of handling a rollback, and so whether there is a change
related to snapd snap in the state. When the conditions have not been met, snapd
exits and snap-failure continues to restart the snapd service.
Related issues: SNAPDENG-21605
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* tests/core/snapd-failover: account for improved snap-failure behavior
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* overlord: add Is() to startup error
Add Is() support to startupError, so that error can be introspected at runtime.
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* o/snapstate: return an explicit error from StartUp() when no recovery was detected
When snapd is invoked in a context of recovery but the state does not reflect
this, return an explicit error indicating that further startup should be carried out.
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* daemon: return an explicit error when startup in recovery context was aborted
Return an explicit error when startup in failure recovery context was aborted
due to lack of operations in the state which may have triggered it.
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* cmd/snapd: handle unnecessary failure recovery
Gracefully handle unnecessary failure recovery but exiting with 0 status, so
that snap-failure may continue with cleanup and restart.
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* o/snapstate: improve the check for asserting if restart was warranted
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* overlord: add managers test for handling of runtime restart with failure handling
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* many: tweak names and comments
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* o/snapstate: tweak unit test names
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* cmd/snapd: use fmt.Fprintln
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* overlord/snapstate: tweak naming
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
---------
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
* o/snapstate: export affectedSnaps, so it can be used by daemon package
Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
* daemon: attach affected-snaps data to tasks
This allows API caller to associate each task with the
relevant snaps which is useful in the case change progress
tracking when a change is associated with multiple snaps.
This exact use case is needed by snapd-desktop-integration.
Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
---------
Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
* daemon, o/snapstate, snap: add hook information to snap.ComponentInfo
* snap: add functions for helping with snap component instances
* snap: return correct security tags from hook if it is a component hook
* s/snaptest: add function for mocking an installed component
* snap: add functions to help with hook and component locations
* snap: add test for ReadComponentInfoFromContainer where component is not found in provided snap.Info
* snap, o/snapstate: move component and snap consistency checks into snap.ReadComponentInfoFromContainer
* snap: remove unneeded json tag
* snap: log if we ignore an unsuppported implicit component hook
* snap: reorder addAndBindImplicitComponentHooksFromContainer args to be more consistent
* snap: add extra component hook to test
* snap: reorder ComponentHooksDir args and implement it using ComponentMountDir
* snap: correct doc comment on SnapComponentName
* snap: use two spaces for indentation in yaml literals
* snap: upgrade debug log for unsupported hook to notice
* tests: Ensure that parseOptionalTime honors nanoseconds
This PR adds a test for parseOptionalTime, which checks whether
it honors nanoseconds in a RFC3339 date/time or not.
* Fix package name
* Update daemon/request_test.go
Co-authored-by: Zeyad Yasser <zeyady98@gmail.com>
* Move exports into exports_test.go
---------
Co-authored-by: Zeyad Yasser <zeyady98@gmail.com>
* 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
* daemon: remove polkit check from POST /v2/notices (thanks @olivercalder)
* o/state: update snap-run-inhibit notice doc comment
* daemon: allow snap command only to add snap-run-inhibit notices
Check that the call to /v2/notices to create snap-run-inhibit notices
is coming from an expected source by checking the symlink target of
/proc/<PID>/exe is one of the known locations:
- /usr/bin/snap
- /snap/snapd/current/usr/bin/snap
- /snap/core/current/usr/bin/snap
* daemon/api_notices_test.go: fix typo (thanks @olivercalder)
* daemon: address review comments
* daemon: extract validation out of postNotices
* o/state,daemon: use common notice validation (thanks @Meulengracht)
* p/state,daemon: s/attempted to/cannot/ in notice validation errors (thanks @pedronis)
* daemon: use wildcard matching for snap binary location (thanks @bboozzoo)
* daemon: simplify snap-run-inhibit snap validation
* daemon: remove unused snapInstanceExists
Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
Some endpoints needs to be accessible to snaps via more than one
interface. This change turns the `Interface string` field of
`interface{Open,Authenticated}Access` into `Interfaces []string`.
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
The `RemoteAddr` of a request can now store more than one interface:
`...;iface=foo&bar&baz;` includes the interfaces "foo", "bar", and "baz".
Importantly, `ucrednetAttachInterface` is now idempotent. No matter how
many times it is called with the same interface, once the interface is
in the list, it is not added again.
Also, the corresponding `ucrednetGetWithInterface` now returns a slice
of interfaces instead of a single one. This slice is obtained by
splitting the value of the `iface=` field on `'&'` characters.
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
daemon: refactor ucrednetAttachInterface to use raddrRegexp
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
daemon: add comments about ucrednet remote address regexp groups
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
daemon: deduplicate types in notices filter and test types for multiple interfaces
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
daemon: add duplicate type to notices types filter test
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
daemon: rename ucrednetGetWithInterface to ucrednetGetWithInterfaces
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>