112 Commits

Author SHA1 Message Date
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
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
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
Miguel Pires
d097436c1c many: fix formatting w/ gofmt 1.19
Go 1.19 includes some changes to gofmt which intend to make lists and
heading clearer when rendered (https://go.dev/doc/go1.19). This commit
is the result of running the new gofmt and manually fixing some of it.
This was necessary because the new gofmt assumed lines beginning w/ tabs
to start lists or examples. While this is often true in our codebase,
we occasionally also use tabs to indent the lines after a TODO or FIXME
prefix or in yaml (e.g., excerpts of a snap.yaml). This meant that a lot of the
reformatted comments were broken and had to be fixed manually.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-01-16 14:23:11 +01:00
Philip Meulengracht
a199598051 o/servicestate,wrappers: handle quota changes on a service level instead of on a snap level (2/3) (#12395)
* o/servicestate,wrappers: handle services individually to avoid affecting all services in cases where you modify a group with only one service.

* o/servicestate: add unit tests for AffectedSnapServices to make it easier to verify the new behavior

* o/servicestate,wrappers: fix failing unit tests, fix a logic mistake in MakeServiceQuotaMap

* multiple: a bit of code cleanup and missing doc

* multiple: i hopefully stop misspelling separate

* o/ifacestate: pass snap.Info instead of instance name to avoid doing a lookup

* o/ifacestate: pass snap.Info instead of instance name to avoid doing a lookup

* multiple: filter services out instead of passing the relevant services to SnapServiceOptions. Also update doc comment

* o/servicestate: rename filterApps to filterSnapServices

* o/snapstate/backend: change usage to EnsureSnapServices to avoid needless copying

* multiple: review feedback

rename SnapServiceOptions to SnapServicesOptions. And rename FindQuotaGroupForServiceInSubGroups to GroupForService.

* many: review feedback

Move MakeServiceQuotaMap, remove usage of AddSnapServices and move it into services_test.go instead where it can be used as a test helper instead. SnapServicesOptions is now requiredx

* multiple: simplify arguments to MakeServiceQuotaMap

* o/snapstate: rename function pointer as well

* wrappers,o/servicestate: only build a map of services that has a quota group

* o/snapstate/backend: fix unit tests in link_test.go

* wrappers,overlord: refactor AddSnapServiceOptions into a new structure, and remove the original usage. Remove some earlier changes requiring SnapServicesOptions to be provided, no longer necessary with the changes done to the service map

* root: remove log.txt

* o/patch: set nil SnapServicesOptions

* wrappers,o/servicestate: Add unit test that test across layers to verify correct service files are touched when we change a service group.
Change the approach on how we filter services in wrappers, we now provide a filter list, which if provided, controls which services are generated.

* review feedback: allow nil entries in the service map, verify the quota groups provided are sane, add unit tests

* multiple: move MakeServiceQuotaMap to snap/quota, and add unit tests

* snap/quota: no need for BaseTest :-)

* multiple: remove the ServiceQuotaMap as the wrappers layer has all the information available anyway.

* many: unrename SnapServiceOptions

* multiple: more code cleanup

* multiple: review feedback

replace GroupForService with ServiceMap that provides us with a map of group replacements, and then replace usage of GroupForService with this. Update a couple doc strings.

* snap/quota: restructure the unit tests a bit

* o/servicestate: fix test that started failing. It was missing systemctl calls for the service group.

* wrappers: review feedback

correct doc string for QuotaGroup in generateSnapServicesOptions

* wrappers,o/servicestate: review feedback

small cleanup, use sort.Strings() instead of sort.Slice. Undo some whiteline changes. Use strings.SplitN instead of split
2022-12-15 11:41:26 +01:00
Miguel Pires
d8eb8dc9df many: replace ErrNoState equality checks w/ errors.Is() 2022-05-20 10:07:29 +01:00
Michael Vogt
46ef068423 many: replace use of "sanity" with more inclusive naming
This commit replaces the use of "sanity" with more inclusive
naming. When "sanity" is used in a more general sense either
"validity" or "quick" is used.
2022-03-16 09:10:59 +01:00
Michael Vogt
277eb06412 many: replace use of "sanity" with more inclusive naming
This commit replaces the use of "sanity" with more inclusive
naming.

When `sanity` is used in a more general sense either `validity`
or `quick` is used.
2022-03-14 18:22:34 +01:00
Paweł Stołowski
d7b7764019 Simplify the condition (thanks mardy!). 2021-05-24 12:10:46 +02:00
Paweł Stołowski
10d73e5511 Check if we have snapd snap with correct snap type already in snapstate
and skip migration step if so as we can have at most one snapd snap
anyway. This fixes such edge case and also makes use of previously
unused statePatch6_2JSONWithSnapd meant for such test.
2021-05-24 12:10:46 +02:00
Alberto Mardegan
0388665ac9 overlord/patch: remove unused code
This became unused with e0234de8ae.
2021-05-07 14:10:23 +03:00
Alberto Mardegan
c8ac14c622 overlord/patch: remove unused constants
These were added in 2d44337b7c but not
actually used.
2021-05-07 14:10:23 +03:00
Pawel Stolowski
de22e00a2e o/snapstate,servicestate: use service-control task for service actions (9/9) (#8960)
This PR finalizes changes to the semantics of services as follows:
- when units for services are created on snap install/refresh (in link handler), systemd units are only created on disk but not immediately enabled.
- units are enabled later on start-snap-services. These two changes are reflected in wrappers/services.go and changes to AddSnapServies and StartServices.
- service commands executed from snap and snapctl are handled by new service-control-task. This unifies service handling for these commands as there are no ad-hoc calls to systemctl, but everything goes through wrappers. There is one task per snap in case of service commands affecting multiple snaps. The task carries snap name and affected services (if the list is empty, then all services of the snap are considered).
- for compatibility with old snapd though, old-style exec-command tasks are created alongside new type of tasks, but they have ignore flag set on them so new snapd skips them (logic for that landed already in cmdstate).
- disabled/enabled services are tracked with ServicesDisabledByHooks/ServicesEnabledByHooks in SnapState. This is needed for hooks that run between link-snap and start-snap-services, and may effect state of the services.
2020-11-13 12:51:13 +01:00
Samuele Pedroni
7167c71307 many: rename back snap.Info.GetType to Type
to follow again golang naming conventions
2020-06-19 10:23:29 +02:00
Paweł Stołowski
c0e52fc3a8 Merge branch 'master' into service-control-task 2020-06-17 09:07:43 +02:00
Samuele Pedroni
d3dd6e3afa cmd,many: move Version and bits related to snapd tools to snapdtool 2020-06-12 17:24:35 +02:00
Paweł Stołowski
3a94059bfb service-control task handler and ServiceManager. 2020-06-10 11:54:09 +02:00
Paweł Stołowski
79a3cdbd0b Use StopFlags instead of bool flag. 2020-05-12 12:37:50 +02:00
Paweł Stołowski
9789860d90 Pass 'disable' flag to StopServices wrapper to optionally disable services. This is not yet used for real but will be used by service-control task. 2020-05-11 14:10:45 +02:00
Samuele Pedroni
495c211c1a snap,overlord: base IsSnapd on WellKnownSnapID
given that we consider the type most of the time now it seems mocking
the snap-id is not very useful, adjust some tests for this
2020-03-24 21:00:21 +01:00
Samuele Pedroni
2b76ee5e5b many: introduce snapdenv.Preseeding instead of release.PreseedMode 2020-03-16 21:33:56 +01:00
John R. Lenton
331eef3a38 overlord/patch: deal with state with no channels!
whoopsie :-)
2019-11-26 11:23:08 +00:00
John R. Lenton
45ffb85e8b overlord/patch: update 6_3 patch for TrackingChannel work 2019-11-26 11:23:08 +00:00
Michael Vogt
289f6cd06b patch: use ch.Full() in patch6.3 2019-11-26 11:23:08 +00:00
Michael Vogt
00150ba702 patch: run channel.Clean in patch6_3 too (thanks Samuele) 2019-11-26 11:23:08 +00:00