Files
snapd/daemon
Ian Johnson 1da9c47189 o/servicestate: restart slices + services on modifications
* wrappers/services: observe slice mutation with callback in EnsureSnapServices

This is needed so that we can detect which slices need to be restarted when
they are modified.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestae/servicemgr_test.go: increment systemctlCalls when not handled

This had a bug previously where calls past the expected number did not cause
the test to fail if the systemctl command's output and error status was not
checked.

Now we will fail properly at the end with the function that ensures the number
of systemctl calls matches what we expected.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* snap/types: add stop reasons for quota-group and vitality-rank modification

This is because under both situations we will need to stop and restart
services, and the proper ordering is to manually stop all services, then start
them up one by one in the required dependency order, otherwise just using
RestartServices() on the full set will not start them in the right order.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate/servicemgr_test.go: add logging of all systemctl calls on fail

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate/quota_control.go: restart slices + svcs after group modification

When we add or remove a snap from a slice (or modify the slice itself), we need
to restart the slice unit and also restart the snaps such that systemd moves
the processes over, as it does not move them over just with systemctl
daemon-reload.

Also update the tests to check that systemctl is used as expected.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate, many: check systemd version before using quota groups

We need systemd version 205+ in order to properly use slice units, so check
this for each function.

Note: we could cache the result of this check since systemd versions shouldn't
change during a boot, but the check should be relatively cheap to perform and
is simpler to handle here by just calling it every time (if a bit verbose in
tests).

Also update the spread test to skip trusty since it has systemd 204.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate: cache systemd version check result

Thanks to Pawel for the recommendation.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate/quota_control.go: don't use systemctl when preseeding

Thanks to Pawel for spotting this issue. Also thanks for spotting the
optimization to just allocate a single null timings to provide for all
invocations instead of making a new one each iteration of the loop.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate/servicemgr_test.go: simplify mockSystemctlCalls

Thanks to Michael for the suggestion

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* tests/main/snap-quota: fix checking stderr

Thanks to Pawel for pointing this out

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate/quota_control.go: add TODO about systemd.AtLeast sort of thing

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* daemon/api_quotas_test.go: fix unit tests on trusty

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate: refactor systemd version check

We now only call the checking function once at package initialization which is
simpler and requires less global state, but it does mean we need to separately
export and then call the checking function from the unit test which uses the
"real" systemctl command in the code to check the version.

Thanks to Samuele for the suggestion.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate/quota_control.go: refactor systemctl + checks for slice mods

When modifying slice units, we have a few different cases that need to be
handled which require systemctl operations.

1) Snaps are added to a slice (also another case for removal in a followup PR)
2) A group is newly created
3) A group is removed
4a) A group has it's memory limit increased
4a) A group has it's memory limit decreased

For 1, we don't need to modify the slice at all, but the services need to be
restarted.

For 2, the slice unit needs to be started, and any new snaps in the group are
subject to 1.

For 3, the slice unit has to be stopped, and any snaps that were in the group
are subject to 1

For 4a, we just need to call systemctl daemon-reload

For 4b, we need to first stop any services currently in the slice, then call
systemctl daemon-reload, then start any stopped services. This is because the
systemctl daemon-reload call could fail if there are currently processes in the
cgroup which are using more memory than the new memory limit (since it is being
decreased), and it fails in an unfortunate way where the systemctl call does
not fail, but the old higher limit remains in effect but systemd reports the
new, not currently enforced limit, as being in effect.

Becuase 4b is complicated to handle, we exclude it by preventing any
modification to an existing quota group that would decrease the memory limit.
We may someday wish to enable this use-case but it will take more code to
properly implement.

Also refactor the restarting of services in ensureSnapServicesForGroup slightly
to release the state lock while services are being started, and restart them
in their startup order rather than stopping them all and then starting them up
one by one.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* wrappers: test the observe callback function for quota groups

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* wrappers/services_test.go: eliminate random ordering of observed svc mods

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* daemon/api_quotas_test.go: remove unnecessary systemd version mocking

We don't call systemctl version on every servicestate quota group method now,
so these are unnecessary.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate/quota_control.go: add doc-comment to MockSystemdVersion

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate/quota_control.go: move quotaGroupsAvailable, invert check order

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* snap/types.go: remove unused stop reasons

These are no longer needed or used anywhere. The vitality-rank code actually
doesn't need to stop services manually right now, it should be adapted to use
the same code that we use in servicestate to call Restart on services in the
right ordering.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate/quota_control.go: refactor preseeding handling

* Don't allow removing quota groups during preseeding since it doesn't make
  sense how that could even happen right now
* Move the checks around in ensureSnapServicesForGroup so we don't do anything
  after wrappers.EnsureSnapServices if we are preseeding - the only on-disk
  thing we actually would need to do in that bit of code is deleting a removed
  quota's slice file, but as per above, we don't support that during preseeding
  so we can just ignore that case.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* o/servicestate/quota_control.go: invert preseeding check

This results in less deeply nested code, thanks to Samuele for the suggestion.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* wrappers/services_test.go: add comment about groups being sorted already

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-05-18 08:08:54 +02:00
..
2021-04-13 10:16:09 +08:00
2021-05-05 14:28:53 +03:00
2021-05-05 14:28:53 +03:00
2021-05-05 14:28:53 +03:00
2019-06-11 14:42:05 +02:00
2021-05-05 14:28:53 +03:00
2021-05-05 14:28:53 +03:00
2021-05-05 14:28:53 +03:00
2021-04-30 13:59:58 +00:00
2021-05-05 14:28:53 +03:00
2021-05-05 14:28:53 +03:00
2021-03-24 10:41:36 +00:00
2021-05-05 14:28:53 +03:00
2020-12-08 09:53:13 +01:00