895 Commits

Author SHA1 Message Date
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
Alfonso Sánchez-Beato
32cbe91b8b client/snap_op.go: add colon to TODO comment 2022-01-28 10:41:08 +01:00
Alfonso Sánchez-Beato
d363105501 many: address review comments 2022-01-27 16:27:44 +01:00
Alfonso Sánchez-Beato
b71dff99a3 client: add transactional flag 2022-01-26 17:49:13 +01:00
Philip Meulengracht
a8e899e128 client: Update signature of EnsureQuota to take a struct
In preparation of supporting multiple quotas
2022-01-20 11:46:21 +01:00
Miguel Pires
baa1307075 client: improve err msg 2022-01-10 16:01:17 +00:00
Miguel Pires
c8dabcecd1 cmd: support installing multiple local snaps 2022-01-04 11:58:45 +00:00
Miguel Pires
cd80af2f61 client: rename func 2021-10-06 12:26:00 +01:00
Miguel Pires
d0335406d5 client: rename InternalError to InternalClientError 2021-10-05 09:55:56 +01:00
Miguel Pires
baa186e027 client: fail fast on non-retryable errors
The snap client would always retry requests for a long time,
regardless of error type (e.g., snap list retries for 2min,
if it fails to read auth.json).
This commit prevents retries caused by internal and auth errors.
2021-10-04 09:57:23 +01:00
Miguel Pires
aa623a49ea many: remove unused parameters and returns 2021-09-02 17:44:34 +01:00
Miguel Pires
dee56590be client: correct import order
Corrects the import order by removing an unnecessary package.
2021-08-26 18:24:02 +01:00
Miguel Pires
5f098640bb cmd/snap: print logs in local timezone
Sets the default timezone for the 'snap logs' command to the local timezone.
Adds an --abs-time flag to display the log timestamps in UTC.
2021-08-17 09:28:39 +01:00
Ian Johnson
a62abd6c97 Merge branch 'master' into feature/quota-groups-the-final-countdown-1
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-07-08 06:26:28 -05:00
Ian Johnson
11319a1c80 client/tests, cmd/quota/tests: use json.Number for exactness
Thanks to Michael for the suggestion!

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-07-08 06:26:19 -05:00
Ian Johnson
7bdd335da6 client/quota: remove the duplicative error wrapping for ensuring quotas
It is slightly unfortunate in that errors from the daemon that are not wrapped,
such as the unit test we have end up being generic, but most realistic errors
should already be quite readable and usable, so just remove the wrapping.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-07-06 17:30:16 -05:00
Ian Johnson
d082924c0f client, cmd/snap, daemon: re-re-re-factor the API implementation
As per request, a thrice baked API implementation.
🍽️ Bon Appétit!

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-07-06 16:59:03 -05:00
Ian Johnson
f93a993c76 client, cmd/quota, daemon: change constraints + current maps to use ints
Instead of passing the values as strings, pass them as ints exactly with a map
of string -> interface{}. This induces a fair amount of overhead to parse
everywhere but still enables us to relatively easily add new keys/resource
types, assuming those types don't need special formatting like the memory does
with units.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-07-05 14:38:48 -05:00
Ian Johnson
0aab832d6b daemon, client: add QuotaChangeContlict + ErrorKindQuotaChangeConflict
Use a more proper error kind for quota conflicts, supporting the error type
*servicestate.QuotaChangeConflictError inside errToResponse and indicating what
sort of change the conflict is being used for.

Also update the unit tests for the daemon error response to check for this.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-07-05 13:30:29 -05:00
Ian Johnson
37e7842338 client, cmd/snap, daemon: refactor REST API for quotas to match CLI org
The CLI has organization where the current and constraint keys are maps of the
unit of measure for the quota group to the value, so update the REST API to
match this.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-07-02 10:38:37 -05:00
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