From ac70a9a1b2671bae1bd2da1cbd072d45d9204736 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 6 May 2021 13:18:09 -0700 Subject: [PATCH] tests/int: run rootless_cgroup tests for v2+systemd Before this commit, "require rootless_cgroup" feature check required "cgroup" to be present in ROOTLESS_FEATURES. The idea of the requirement, though, is to ensure that rootless runc can manage cgroups. In case of systemd + cgroup v2, rootless runc can manage cgroups, thanks to systemd delegation, so modify the feature check accordingly. Next, convert (simplify) some of the existing users to the modified check. Signed-off-by: Kir Kolyshkin --- tests/integration/cgroups.bats | 10 ++-------- tests/integration/helpers.bash | 9 +++++++-- tests/integration/update.bats | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/integration/cgroups.bats b/tests/integration/cgroups.bats index 2bc94074d01..5875469c68c 100644 --- a/tests/integration/cgroups.bats +++ b/tests/integration/cgroups.bats @@ -16,10 +16,7 @@ function setup() { } @test "runc create (rootless + no limits + cgrouppath + no permission) fails with permission error" { - requires rootless - requires rootless_no_cgroup - # systemd controls the permission, so error does not happen - requires no_systemd + requires rootless rootless_no_cgroup set_cgroups_path @@ -29,10 +26,7 @@ function setup() { } @test "runc create (rootless + limits + no cgrouppath + no permission) fails with informative error" { - requires rootless - requires rootless_no_cgroup - # systemd controls the permission, so error does not happen - requires no_systemd + requires rootless rootless_no_cgroup set_resources_limit diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index 236f8652836..b92c4169a4f 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -271,6 +271,11 @@ function fail() { exit 1 } +# Check whether rootless runc can use cgroups. +function rootless_cgroup() { + [[ "$ROOTLESS_FEATURES" == *"cgroup"* || -n "$RUNC_USE_SYSTEMD" ]] +} + # Allows a test to specify what things it requires. If the environment can't # support it, the test is skipped with a message. function requires() { @@ -298,12 +303,12 @@ function requires() { fi ;; rootless_cgroup) - if [[ "$ROOTLESS_FEATURES" != *"cgroup"* ]]; then + if ! rootless_cgroup; then skip_me=1 fi ;; rootless_no_cgroup) - if [[ "$ROOTLESS_FEATURES" == *"cgroup"* ]]; then + if rootless_cgroup; then skip_me=1 fi ;; diff --git a/tests/integration/update.bats b/tests/integration/update.bats index bc9005663d3..e204ea49550 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -21,7 +21,7 @@ function setup() { # Tests whatever limits are (more or less) common between cgroup # v1 and v2: memory/swap, pids, and cpuset. @test "update cgroup v1/v2 common limits" { - [[ "$ROOTLESS" -ne 0 && -z "$RUNC_USE_SYSTEMD" ]] && requires rootless_cgroup + [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup requires cgroups_memory cgroups_pids cgroups_cpuset init_cgroup_paths