From 40b97919163494223ef72c7e7e161ef8e69e6094 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 6 May 2021 18:21:57 -0700 Subject: [PATCH] tests/int: enable/use requires cgroups_ 1. In case of cgroup v2 + systemd + rootless, get the list of controllers from the own cgroup, rather than from the root one (as systemd cgroup delegation is required in this case, and it might not be set or fully working). 2. Use "requires cgroups_" in tests that need those controllers. Tested on Fedora 31 (which does not support delegation of cpuset controller). Signed-off-by: Kir Kolyshkin --- tests/integration/helpers.bash | 10 +++++++++- tests/integration/update.bats | 20 ++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index d099acae2..236f86528 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -103,13 +103,21 @@ function init_cgroup_paths() { if stat -f -c %t /sys/fs/cgroup | grep -qFw 63677270; then CGROUP_UNIFIED=yes + local controllers="/sys/fs/cgroup/cgroup.controllers" + # For rootless + systemd case, controllers delegation is required, + # so check the controllers that the current user has, not the top one. + # NOTE: delegation of cpuset requires systemd >= 244 (Fedora >= 32, Ubuntu >= 20.04). + if [[ "$ROOTLESS" -ne 0 && -n "$RUNC_USE_SYSTEMD" ]]; then + controllers="/sys/fs/cgroup/user.slice/user-$(id -u).slice/user@$(id -u).service/cgroup.controllers" + fi + # "pseudo" controllers do not appear in /sys/fs/cgroup/cgroup.controllers. # - devices (since kernel 4.15) we must assume to be supported because # it's quite hard to test. # - freezer (since kernel 5.2) we can auto-detect by looking for the # "cgroup.freeze" file a *non-root* cgroup. CGROUP_SUBSYSTEMS=$( - cat /sys/fs/cgroup/cgroup.controllers + cat "$controllers" echo devices ) CGROUP_BASE_PATH=/sys/fs/cgroup diff --git a/tests/integration/update.bats b/tests/integration/update.bats index 9e4d702f0..bc9005663 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -22,15 +22,7 @@ function setup() { # 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 - if [[ "$ROOTLESS" -ne 0 && -n "$RUNC_USE_SYSTEMD" ]]; then - file="/sys/fs/cgroup/user.slice/user-$(id -u).slice/user@$(id -u).service/cgroup.controllers" - # NOTE: delegation of cpuset requires systemd >= 244 (Fedora >= 32, Ubuntu >= 20.04). - for f in memory pids cpuset; do - if grep -qwv $f "$file"; then - skip "$f is not enabled in $file" - fi - done - fi + requires cgroups_memory cgroups_pids cgroups_cpuset init_cgroup_paths # run a few busyboxes detached @@ -70,10 +62,6 @@ function setup() { fi # check that initial values were properly set - if [[ "$CGROUP_UNIFIED" = "yes" ]] && ! grep -qw memory "$CGROUP_PATH/cgroup.controllers"; then - # This happen on containerized environment because "echo +memory > /sys/fs/cgroup/cgroup.subtree_control" fails with EINVAL - skip "memory controller not available" - fi check_cgroup_value $MEM_LIMIT 33554432 check_systemd_value $SD_MEM_LIMIT 33554432 @@ -83,7 +71,7 @@ function setup() { check_cgroup_value "pids.max" 20 check_systemd_value "TasksMax" 20 - # update cpuset if supported (i.e. we're running on a multicore cpu) + # update cpuset if possible (i.e. we're running on a multicore cpu) cpu_count=$(grep -c '^processor' /proc/cpuinfo) if [ "$cpu_count" -gt 1 ]; then runc update test_update --cpuset-cpus "1" @@ -426,7 +414,7 @@ EOF @test "update cpuset parameters via resources.CPU" { [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup - requires smp + requires smp cgroups_cpuset local AllowedCPUs='AllowedCPUs' AllowedMemoryNodes='AllowedMemoryNodes' # these properties require systemd >= v244 @@ -482,7 +470,7 @@ EOF @test "update cpuset parameters via v2 unified map" { # This test assumes systemd >= v244 [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup - requires cgroups_v2 smp + requires cgroups_v2 smp cgroups_cpuset update_config ' .linux.resources.unified |= { "cpuset.cpus": "0",