Commit Graph

291 Commits

Author SHA1 Message Date
Kir Kolyshkin 65c2d3c2b6 tests/int/update: add test case for PR #592
Add integration test coverage for code initially added by commit
d8b8f76c4f ("Fix problem when update memory and swap memory",
2016-04-05).

This is in addition to existing unit test,
TestMemorySetSwapSmallerThanMemory.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Vasiliy Ulyanov efb8552b05 tests/int: add device access test
The test verifies if the device file can be queried using
'access(dev_name, F_OK)' when the permissions are set to 'rw'. The call
does not explicitly trigger read or write access but should succeed.

Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de>
2021-02-08 14:14:14 +01:00
Kir Kolyshkin c348b98203 tests/rootless.sh: fix/ignore shellcheck warnings
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-02 16:03:52 -08:00
Kir Kolyshkin 1143759338 tests/rootless.sh: use set -e -u -o pipefail
Currently, set -e ("exit on error") is only set before running tests.
The bad consequence is the script may fail to set up test environment
but will still run the tests.

Use "set -e -u -o pipefail" for the whole script to catch potential
issues with test setup and/or the script itself.

A few caveats:

1. We have to set RUNC_USE_SYSTEMD to an empty value if it is unset, so
   that the subsequent checks like [ -z "$RUNC_USE_SYSTEMD" ] won't
   trigger a "unbound variable" error. Same for ROOTLESS_TESTPATH.

2. Functions that have code like [ -f $file ] && do_something towards
   the end may return 1 in case $file does not exist (as test aka [
   was the last operation performed, and its exit code is returned.
   This is why we had to add return 0.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-02 16:03:52 -08:00
Kir Kolyshkin 5ab0588432 ci: untangle getting test images
This simplifies and optimizes getting container images used for tests.

Currently, we have three different ways of getting images:

1. (for hello-world) the image is in this repo under tests/integration/testdata.

2. (for busybox) download it from github (the repo that is used for
   preparing official Docker image) using curl.

3. (for debian) download from Docker hub, using skopeo and umoci.

To further complicate things, we have to do this downloading in multiple
scenarios (at least 4): locally, in github CI, from Dockefile, inside a
Vagrant VM. For each scenario, we have to install skopeo and umoci, and
those two are not yet universally available for all the distros that we
use.

Yet another complication is those images are used for tests/integration
(bats-driven tests) as well as for libcontainer/integration (go tests).
The tests in libcontainer/integration rely on busybox being available
from /busybox, and the bats tests just download the images to a
temporary location during every run.

It is also hard to support CI for other architectures, because all
the machinery for preparing images is so complicated.

This commit is an attempt to simplify and optimize getting images,
mostly by getting rid of skopeo and umoci dependencies, but also
by moving the download logic into one small shell script, which
is used from all the places.

Benefits:

 - images (if not present) are only downloaded once;
 - same images are used for both kind of tests (go and bats);
 - same images are used for local and inside-docker tests
   (because source directory is mounted into container);
 - the download logic is located within 1 simple shell script.

[v2: fix eval; more doc to get-images; print URL if curl failed]
[v3: use "slim" debian, twice as small]
[v4: fix not using $image in setup_bundle]
[v5: don't remove TESTDATA from helpers.bash]
[v6: add i386 support]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-02 16:03:29 -08:00
Kir Kolyshkin bc175ba423 tests/helpers.bash: rm GOPATH
It is not used anywhere since commit 30601efa81.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-02 11:47:06 -08:00
Aleksa Sarai a4f2b2b0a8 merge branch 'pr-2769'
Kir Kolyshkin (2):
  ci: test with golang 1.16-rc1
  tests/int/spec.bats: fix for go 1.16

LGTMs: @AkihiroSuda @cyphar
Closes #2769
2021-02-01 11:05:49 +11:00
Kir Kolyshkin 164e0adb58 tests/int/spec.bats: fix for go 1.16
go 1.16 has GO111MODULE=on by default, and since runtime-spec/schema
does not come with go.mod, it complains:

> runtime-spec/schema/validate.go:10:2: no required module provides package github.com/xeipuuv/gojsonschema: working directory is not part of a module

Use GO111MODULE=auto as a workaround.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-28 13:13:56 -08:00
Aleksa Sarai 8bd19cd5f8 tests: add seccomp -ENOSYS integration test
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-01-28 23:11:25 +11:00
Aleksa Sarai 346f87fec1 merge branch 'pr-2715'
Kir Kolyshkin (3):
  tests/int/mounts.bats: cleanup
  tests/int/mount.bats: reformat
  runc run: resolve tmpfs mount dest in container scope

LGTMs: @AkihiroSuda @cyphar
Closes #2715
2021-01-27 21:50:11 +11:00
Mrunal Patel 2adbc66b71 Merge pull request #2727 from kolyshkin/cpuset
libc/cg: convert r.CPU.Cpus/Mems to systemd props
2021-01-20 21:25:52 -08:00
Kir Kolyshkin a21e57d7f6 tests/int/hooks.bats: skip earlier
This particular test downloads and unpacks debian from setup(),
but then in many cases the actual test is skipped because it
requires root and no_systemd.

Let's skip it earlier.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-14 18:11:05 -08:00
Kir Kolyshkin 03b512e511 libc/cg: convert r.CPU.Cpus/Mems to systemd props
Support for systemd properties AllowedCPUs and AllowedMemoryNodes
was added by commit 13afa58d0e, but only for unified resources
of systemd v2 driver.

This adds support for Cpu.Cpus and Cpu.Mems resources to
both systemd v1 and v2 cgroup drivers.

An integration test is added to check that the settings work.

[v2: check for systemd version]
[v3: same in the test]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-13 19:28:54 -08:00
Kir Kolyshkin 5de00ad9d4 tests/int/multi-arch.bash: fix for busybox
Due to https://github.com/docker-library/busybox/pull/94 the URLs
to get busybox has changed, so the current URLs give HTTP 404.

Fix the URLs accordingly.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-11 17:41:28 -08:00
Kir Kolyshkin 637f82d6b8 runc run: resolve tmpfs mount dest in container scope
In case a tmpfs mount path contains absolute symlinks, runc errors out
because those symlinks are resolved in the host (rather than container)
filesystem scope.

The fix is similar to that for bind mounts -- resolve the destination
in container rootfs scope using securejoin, and use the resolved path.

A simple integration test case is added to prevent future regressions.

Fixes https://github.com/opencontainers/runc/issues/2683.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-06 14:57:02 -08:00
Kir Kolyshkin d64c3afe1b tests/int/mount.bats: reformat
Easier to read mounts. No functional change.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-06 14:57:02 -08:00
Kir Kolyshkin a2c9866e54 tests/int/mounts.bats: cleanup
1. Make sure that containers created are stopped and removed.
This is done by using a predefined test_busybox container name,
which is getting removed in teardown_busybox.

2. Fix space at EOL.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-06 14:57:02 -08:00
Kir Kolyshkin 1125ae7835 tests/events.bats: unify duplicated code
There are three tests that only differ in delays (and a few other
minor details line whitespace formatting and number of retries).

Let's unify those so maintaining this code will be easier.

This also implicitly increases the number of retries from 3 to 10
for the non-default --interval tests.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-05 20:26:03 -08:00
Kir Kolyshkin 27268b1a7e tests/int/cwd: add test case for cwd not owned by runc
The test setup is complicated, as we want to run it as non-root,
but we need to create a directory owned by a particular user,
and root is needed for chown. To do that, we hijack enable_idmap.

Now, there is no ideal place to clean up AUX_DIR. A function
cleanup is called after the test to do so. Note that it won't
be called if the test fails.

This was verified to fail before and pass after the
previous commit.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-12-18 13:23:27 -08:00
Kir Kolyshkin 8bd3b8786b test: add case for GH #2086
Commit 5e0e67d7 ("fix permission denied") modified some code but
did not provide a test case.

This is a test case that was tested to fail before and succeed after
the above commit.

For more details, see https://github.com/opencontainers/runc/pull/2086

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-12-18 12:56:48 -08:00
Kir Kolyshkin fce8dd4d66 tests/int/tty.bats: increase timeout
Just saw the timeout being hit on CI (Fedora 33 vagrant VM on Travis),
so let's increase it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-27 14:15:32 -08:00
Sebastiaan van Stijn d9010b0e2d integration: update README to link to bats-core
We switched to bats-core in commit d4bc7c10ec,
so updating the instructions to match.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-11-17 17:46:04 +01:00
Mrunal Patel 27227a9358 Merge pull request #2669 from kolyshkin/systemd-unified
Initial v2 resources.unified systemd support
2020-11-06 12:31:31 -08:00
Kir Kolyshkin c013be563c libct/cg/sd/v2: support memory.* / Memory* unified
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:05:00 -08:00
Kir Kolyshkin 13afa58d0e libct/cg/sd/v2: support cpuset.* / Allowed*
* cpuset.cpus -> AllowedCPUs
 * cpuset.mems -> AllowedMemoryNodes

No test for cgroup v2 resources.unified override, as this requires a
separate test case, and all the unified resources are handled uniformly
so there's little sense to test all parameters.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:04:57 -08:00
Kir Kolyshkin 5be8b97aec libct/cg/sd/v2: support cpu.weight / CPUWeight
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:04:46 -08:00
Kir Kolyshkin 390a98f3fd runc update: support unified resources
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:04:41 -08:00
Kir Kolyshkin ab80eb32d2 libct/cg/sd/v2: support cpu.max unified resource
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:04:37 -08:00
Kir Kolyshkin 7f24098d9b tests/int: move check_cpu* to helpers
To be used by the following commit.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:04:32 -08:00
Kir Kolyshkin 0cb8bf67a3 Initial v2 resources.unified systemd support
In case systemd is used as cgroups manager, and a user sets some
resources using unified resource map (as per [1]), systemd is not
aware of any parameters, so there will be a discrepancy between
the cgroupfs state and systemd unit state.

Let's try to fix that by converting known unified resources to systemd
properties.

Currently, this is only implemented for pids.max as a POC.

Some other parameters (that might or might not have systemd unit
property equivalents) are:

$ ls -l | grep w-
-rw-r--r--. 1 root root 0 Oct 10 13:57 cgroup.freeze
-rw-r--r--. 1 root root 0 Oct 10 13:57 cgroup.max.depth
-rw-r--r--. 1 root root 0 Oct 10 13:57 cgroup.max.descendants
-rw-r--r--. 1 root root 0 Oct 10 13:57 cgroup.procs
-rw-r--r--. 1 root root 0 Oct 21 09:43 cgroup.subtree_control
-rw-r--r--. 1 root root 0 Oct 10 13:57 cgroup.threads
-rw-r--r--. 1 root root 0 Oct 10 13:57 cgroup.type
-rw-r--r--. 1 root root 0 Oct 22 10:30 cpu.max
-rw-r--r--. 1 root root 0 Oct 10 13:57 cpu.pressure
-rw-r--r--. 1 root root 0 Oct 22 10:30 cpuset.cpus
-rw-r--r--. 1 root root 0 Oct 22 10:30 cpuset.cpus.partition
-rw-r--r--. 1 root root 0 Oct 22 10:30 cpuset.mems
-rw-r--r--. 1 root root 0 Oct 22 10:30 cpu.weight
-rw-r--r--. 1 root root 0 Oct 22 10:30 cpu.weight.nice
-rw-r--r--. 1 root root 0 Oct 22 10:30 hugetlb.1GB.max
-rw-r--r--. 1 root root 0 Oct 22 10:30 hugetlb.1GB.rsvd.max
-rw-r--r--. 1 root root 0 Oct 22 10:30 hugetlb.2MB.max
-rw-r--r--. 1 root root 0 Oct 22 10:30 hugetlb.2MB.rsvd.max
-rw-r--r--. 1 root root 0 Oct 22 10:30 io.bfq.weight
-rw-r--r--. 1 root root 0 Oct 22 10:30 io.latency
-rw-r--r--. 1 root root 0 Oct 22 10:30 io.max
-rw-r--r--. 1 root root 0 Oct 10 13:57 io.pressure
-rw-r--r--. 1 root root 0 Oct 22 10:30 io.weight
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.high
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.low
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.max
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.min
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.oom.group
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.pressure
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.swap.high
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.swap.max

Surely, it is a manual conversion for every such case...

[1] https://github.com/opencontainers/runtime-spec/pull/1040

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:04:19 -08:00
Kir Kolyshkin ed54837690 tests/int/update.bats: add checks for runc status
Those were missing for some reason, so we did not fail the test in case
"runc update" returned an error.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:03:21 -08:00
Kir Kolyshkin d0991db2e7 tests/int/cgroups.bats: reformatting
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:02:53 -08:00
Kir Kolyshkin 2ceb97196e tests/integration: rm excessive run use
Bats' run should only be used when we want to check both the command
output and its non-zero exit status.

Otherwise, we can rely on implicit exit code check (as the tests are
run with set -e), or use if, etc.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-29 16:49:43 -07:00
Kir Kolyshkin e32716d3da tests/int: simplify teardown_running_container
In its current form, it is complicated, unreliable, and error prone.

Using runc delete -f will kill and remove any container, running or not,
and it won't error if a container with a given name does not exist.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-29 16:49:43 -07:00
Kir Kolyshkin c114919fd3 tests/int: fix "runc exec --preserve-fds"
1. Fix the check, mostly by changing `cat hello` to `echo hello`,
   and checking for "hello" rather than *"hello"*.

   Previously, `cat hello` generated `cat: hello: no such file or
   directory` error message, which `run` added to `$output` and
   so the check for $output containing `hello` worked!

2. Simplify the test by not using the subshell and the `run`.
   The only catch is, fd 3 is used by bats itself, so we have to use
   fd 4 and thus --preserve-fds 2.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-29 16:49:43 -07:00
Akihiro Suda 7b8c4e980a shfmt mounts.bats to pass make validate
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-10-29 15:56:21 +09:00
Akihiro Suda 9d4c02cf29 Merge pull request #2570 from EduardoVega/2246-fix-chmod-ro-tmpfs-mount
Fix mount error when chmod RO tmpfs
2020-10-26 18:19:16 +09:00
Akihiro Suda f5c345c30c test: add "runc run --no-pivot must not expose bare /proc"
For preventing regression like #2647

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-21 21:42:59 -07:00
Kir Kolyshkin ff9852c4de *.sh: use shfmt
I played with shfmt options (-bn, -ci, -sr) a bit trying to minimize
the patch generated (and also because I don't have a strong preference
on these matters), and it appears to be that the patch size is about the
same nevertheless, so I chose no options.

This commit is brought to you by

	shfmt -ln bash -w man/*.sh script/*.sh tests/*.sh tests/integration/*.bash

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-11 19:31:55 -07:00
Kir Kolyshkin fc8c779704 tests/integration/*.bats: reformat with shfmt
Various bats tests use various types of indentation (about half
is tabs, the rest is 2 spaces, 4 spaces, etc.).

Let's bring it to one style (tabs) using recently added
shfmt support for bats files (see [1]).

This commit is brought to you by

	shfmt -ln bats -w tests/integration/*.bats

[1] https://github.com/mvdan/sh/issues/600

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-11 19:15:36 -07:00
Eduardo Vega fb4c27c4b7 Fix mount error when chmod RO tmpfs
Signed-off-by: Eduardo Vega <edvegavalerio@gmail.com>
2020-10-05 21:23:30 -06:00
Mrunal Patel bbf33043af Merge pull request #2615 from kolyshkin/cgroups-ebusy
runc run: fix removing cgroups on error; improve logging on error
2020-09-30 08:18:20 -07:00
Kir Kolyshkin ecfad5a118 Merge pull request #2574 from EduardoVega/2249-add-integration-tests-resource-devices
Add integration tests for cgroup devices
2020-09-30 00:19:27 -07:00
Kir Kolyshkin a4d5e8a27b libcontainer/ignoreTerminateError: ignore SIGKILL
When we call terminate(), we kill the process, and wait
returns the error indicating the process was killed.
This is exactly what we expect here, so there is no reason
to treat it as an error.

Before this patch, when a container with invalid cgroup parameters is
started:

> WARN[0000] unable to terminate initProcess               error="signal: killed"
> ERRO[0000] container_linux.go:366: starting container process caused: process_linux.go:495: container init caused: process_linux.go:458: setting cgroup config for procHooks process caused: failed to write "555": open /sys/fs/cgroup/blkio/user.slice/xx33/blkio.weight: permission denied

After:

> ERRO[0000] container_linux.go:366: starting container process caused: process_linux.go:495: container init caused: process_linux.go:458: setting cgroup config for procHooks process caused: failed to write "555": open /sys/fs/cgroup/blkio/user.slice/xx33/blkio.weight: permission denied

I.e. the useless warning is gone.

NOTE this breaks a couple of integration test cases, since they were
expecting a particular message in the second line, and now due to
"signal: killed" removed it's in the first line. Fix those, too.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-29 23:55:02 -07:00
Mrunal Patel 43d2b10300 Merge pull request #2592 from kolyshkin/tests-int-nits
tests/integration: nits
2020-09-28 09:27:03 -07:00
Kir Kolyshkin 4929c05ad1 tests/int: add cgroupv2 unified resources tests
Note that various invalid keys are covered by test cases in
libcontainer/integration/exec_test.go

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-24 15:29:40 -07:00
Kir Kolyshkin 6e2159be74 tests/int/cgroups: make sure to rm containers
Container test_cgroups_group was missing from the teardown.

Fixes: c91fe9aeba.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-24 15:29:40 -07:00
Kir Kolyshkin 30601efa81 tests/int/spec.bats: simplify
Most of whatever is happening in the test cases is already available in
setup_hello and teardown_hello. Use these.

Rewrite the validation test to be more compact and not dependent
on `pwd` value. Also, pinning xeipuuv/gojsonschema to a particular
version is no longer required.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-21 03:11:02 -07:00
Kir Kolyshkin 6c21de38a1 tests/int/spec: only run once for rootless
The purpose of the spec validation test is to make sure
that config.json generated by runc spec is valid. Therefore,
it does not depend on ROOTLESS_FEATURES.

Taking that into account, and given the fact that this test
involves cloning repos and building some code, it makes sense
to not run it 4 times for various rootless features.

Time it takes to execute spec.bats in rootless mode has improved.

Before:
	real	0m21.286s
	user	0m37.837s
	sys	0m5.745s

After:
	real	0m13.162s
	user	0m30.814s
	sys	0m4.050s

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-21 03:10:19 -07:00
Kir Kolyshkin 186a38ba73 tests/int: whitespace cleanup
Fix
 - whitespace at EOL
 - empty lines at EOF

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-21 02:47:23 -07:00