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.
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>
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>
* 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
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.
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.
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.
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.