Commit Graph

875 Commits

Author SHA1 Message Date
Ian Johnson
bc94a84f79 client/quota.go: wrap error from removing quota too
This matches what we do with EnsureQuota too. Thanks to Pawel for the
suggestion.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-07-01 17:46:46 -05:00
Ian Johnson
a7a1061ca9 many: use changes + tasks for quota group operations
The exported methods from the servicestate package all return tasksets now,
which is expected to be put into changes that are executed by the overlord
loop. This involves changes in many parts that use quotas, such as the tests,
where a new mock function to create a quota group in state without running any
servicectl commands as well as changes to the client side.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-06-29 17:25:49 +02:00
Samuele Pedroni
9242fb8256 many: turn Contact into an accessor
as later it will be derived from links and also we will have
to deal with links from store response vs snap.yaml
2021-06-25 19:10:08 +02:00
Samuele Pedroni
54e84fb8db many: fix imports order (according to gci)
had to make the comment in wrappers/services_test.go a one-liner
otherwise half of it is lost

last set of files needing changing (as per current master)
2021-06-16 09:54:31 +02:00
Ian Johnson
d750b7b1fb cmd/snap/quota: refactor quota CLI as per new design
* client/quota.go: support current-memory key

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

* cmd/snap/quota: refactor quota CLI as per new design

* Make quota command only responsible for showing/displaying quota group
  information.
* Introduce new set-quota command which creates or updates quota groups
* Move the display of memory limit under a map section "constraints" which then
  has a memory key to allow future resource types to live under this section.
* Display current memory usage for quota groups under a new section "current",
  which like "constraints" can be expanded for future resource types too.

Also update the spread test and unit tests for the new output formats.

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

* tests/main/snap-quota-groups: check the cgroup procs file in a loop

This too is a race condition, thanks to Maciej for pointing this out.

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

* tests/snap-quota-groups: compare slice mem usage from both snapd and kernel

This check ensures that what the kernel says the current memory usage is and
what snapd says the current memory usage is don't differ by more than 10%. In
practice they should be exactly equal if the program is doing nothing as the
go-example-webserver should be, but something does happen to change it \
shouldn't change drastically.

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

* tests/snap-quota: add a snap with a service to one of the groups

This ensures that we can check the `snap quota` and `snap quotas` output for
the "current" section with the memory usage in it.

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

* tests/main/snap-quota: fix trusty check

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

* tests/main/snap-quota: increase limits so the webserver snap can start

These limits were too low so the service was killed and no memory usage was
reported in the output, but we want to see some usage from the output to check
that it works, so increase the limits so the server is not killed due to OOM.

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

* tests/main/snap-quota: fix group-one line in output

Also fix the defer statement which was missing the snap to unset the config on.

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

* tests/main/snap-quota-groups: refactor memory check for empty quota groups

We only should be checking what snapd says about memory usage for these empty
groups, we don't need to compare with what the kernel says.

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

* tests/snap-quota-groups: fix typo

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

* tests/main/snap-quota-groups: treat memory=4096 as memory=0 for new systems

On the following systems:

- Arch Linux
- Fedora 33
- Fedora 34
- Debian sid
- Ubuntu 21.04

The memory usage of an "empty" but active cgroup ends up being 4K for some
reason, so handle this in the expected output.

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

* tests/snap-quota-groups: silly typos

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

* tests/main/snap-quota: fix more typos

non capturing groups are not a thing in grep -E because of course they aren't

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

* tests/main/snap-quota-groups: use python if python3 is not available

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

* tests/main/snap-quota: adjust memory limits for test groups to be at least 4K

On some systems, an empty cgroup with just cgroups nested inside it (but not
necessarily any processes) will have 4K memory usage, so on these systems, we
should make sure that the nested cgroups have enough space in them.

In a follow-up, we will adjust the minimum usable memory limit for a given
cgroup to be 4K to prevent this situation from happening in practice.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-06-07 09:12:45 +02:00
Alberto Mardegan
99ea6f4642 client: Fix linter errors 2021-05-05 12:44:38 +03:00
Paweł Stołowski
60b571341f Update client tests. 2021-04-30 14:52:23 +00:00
Paweł Stołowski
6a6ad217e5 Fix error messages. 2021-04-30 13:59:58 +00:00
Paweł Stołowski
4b3f23170b Implement 'snap quotas' command. 2021-04-29 10:41:43 +00:00
Paweł Stołowski
a0d698e988 Implement remove-quota command. 2021-04-29 08:33:50 +00:00
Paweł Stołowski
509d3cc460 Rename the endpoint to v2/quotas, introduce action field in post data. 2021-04-28 13:54:21 +00:00
Paweł Stołowski
387bf1c09f Use uint64 for max-memory. Remove redundant max-memory arg check. 2021-04-28 13:54:21 +00:00
Paweł Stołowski
85ffccaa99 Introduce 'snap quota' command. 2021-04-28 13:54:21 +00:00
Maciej Borzecki
e01ae41862 client: tweak the test to give very slow machines a chance
The test sometimes fails on OBS when building for AARCH64, where it's likely
done in a VM. Tweak the test so that even very slow hosts have a chance of
running it successfully.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-03-23 15:03:42 +01:00
Michael Vogt
2d7911e05b client: tweak LimitedReader handling, thanks to Maciej 2021-03-08 12:19:34 +01:00
Michael Vogt
f97ad5a083 client: protect against reading too much data from stdin
This is a followup for PR#9692 where it was suggested that the
new "snapctl" support for reading from stdin should have some
protection against reading too much data. See
https://github.com/snapcore/snapd/pull/9692#discussion_r530255566

This starts with a 4MB limit.
2021-03-04 16:17:06 +01:00
James Henstridge
2240e02324 cmd, client: move identification of user daemons to notes column 2021-02-24 18:00:51 +08:00
James Henstridge
69a0b28b0b client: expose "daemon-scope" property on apps 2021-02-08 12:52:14 +08:00
James Henstridge
5275d39dce client/clientutil: add "dbus-activated" as an AppInfo note 2021-01-27 20:56:53 +08:00
Paweł Stołowski
e2859532fb Add extra test check for ContentHash() where different sha3_384 checksums inside Snapshot lead to different hash (thanks ijohnson) 2021-01-13 09:58:50 +00:00
Paweł Stołowski
d3019ab394 Tweak comments. Remove obsolete XXX comment. 2020-12-15 16:02:59 +00:00
Paweł Stołowski
39fb98fed6 Merge branch 'master' into snapshot-content-hash 2020-12-15 09:54:07 +00:00
Paweł Stołowski
132437cfef Merge branch 'master' into snapshot-content-hash 2020-12-14 10:39:10 +00:00
Paweł Stołowski
1bc754c77b Merge branch 'master' into validation-sets/api 2020-12-14 08:47:46 +00:00
Paweł Stołowski
c4161a45b1 Fix formatting. 2020-12-10 10:45:56 +01:00