From 25ef852ad60f9d09b6f23eef1cb3c4bce12d5b28 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 7 Feb 2022 16:15:52 -0800 Subject: [PATCH 1/4] tests/int: use = in test for strings comparison Strictly speaking, == is for [[ only, not for [ / test, and, unlike =, the right side is a pattern. To avoid confusion, use =. In cases where we compare with empty string, use -z instead. Keep using [[ in some cases since it does not require quoting the left and right side of comparison (I trust shellcheck on that one). This should have no effect (other than the code being a tad more strict). Signed-off-by: Kir Kolyshkin --- tests/integration/cgroups.bats | 8 ++++---- tests/integration/checkpoint.bats | 2 +- tests/integration/create.bats | 4 ++-- tests/integration/exec.bats | 5 ++--- tests/integration/helpers.bash | 8 ++++---- tests/integration/list.bats | 6 +++--- tests/integration/mask.bats | 4 ++-- tests/rootless.sh | 4 ++-- 8 files changed, 20 insertions(+), 21 deletions(-) diff --git a/tests/integration/cgroups.bats b/tests/integration/cgroups.bats index 89c63f398..914ec499d 100644 --- a/tests/integration/cgroups.bats +++ b/tests/integration/cgroups.bats @@ -87,7 +87,7 @@ function setup() { runc exec test_cgroups_group cat /proc/self/cgroup [ "$status" -eq 0 ] - [[ ${lines[0]} == "0::/" ]] + [[ ${lines[0]} = "0::/" ]] runc exec test_cgroups_group mkdir /sys/fs/cgroup/foo [ "$status" -eq 0 ] @@ -99,7 +99,7 @@ function setup() { # because we haven't enabled any domain controller. runc exec test_cgroups_group cat /proc/self/cgroup [ "$status" -eq 0 ] - [[ ${lines[0]} == "0::/" ]] + [[ ${lines[0]} = "0::/" ]] # turn on a domain controller (memory) runc exec test_cgroups_group sh -euxc 'echo $$ > /sys/fs/cgroup/foo/cgroup.procs; echo +memory > /sys/fs/cgroup/cgroup.subtree_control' @@ -109,7 +109,7 @@ function setup() { # falls back to "/foo". runc exec test_cgroups_group cat /proc/self/cgroup [ "$status" -eq 0 ] - [[ ${lines[0]} == "0::/foo" ]] + [[ ${lines[0]} = "0::/foo" ]] # teardown: remove "/foo" # shellcheck disable=SC2016 @@ -301,7 +301,7 @@ function setup() { [[ $exec_cgroup == *"runc-cgroups-integration-test"* ]] # check that the cgroups v2 path is the same for both processes - [[ "$run_cgroup" == "$exec_cgroup" ]] + [ "$run_cgroup" = "$exec_cgroup" ] } @test "runc exec should refuse a paused container" { diff --git a/tests/integration/checkpoint.bats b/tests/integration/checkpoint.bats index 98b112dc6..615ef8cb6 100644 --- a/tests/integration/checkpoint.bats +++ b/tests/integration/checkpoint.bats @@ -98,7 +98,7 @@ function runc_restore_with_pipes() { runc exec --cwd /bin "$name" echo ok [ "$status" -eq 0 ] - [[ ${output} == "ok" ]] + [ "$output" = "ok" ] } function simple_cr() { diff --git a/tests/integration/create.bats b/tests/integration/create.bats index afa9f9dfb..938ac8b63 100644 --- a/tests/integration/create.bats +++ b/tests/integration/create.bats @@ -50,7 +50,7 @@ function teardown() { # check pid.txt was generated [ -e pid.txt ] - [[ $(cat pid.txt) == $(__runc state test_busybox | jq '.pid') ]] + [[ $(cat pid.txt) = $(__runc state test_busybox | jq '.pid') ]] # start the command runc start test_busybox @@ -73,7 +73,7 @@ function teardown() { # check pid.txt was generated [ -e pid.txt ] - [[ $(cat pid.txt) == $(__runc state test_busybox | jq '.pid') ]] + [[ $(cat pid.txt) = $(__runc state test_busybox | jq '.pid') ]] # start the command runc start test_busybox diff --git a/tests/integration/exec.bats b/tests/integration/exec.bats index 140cd1810..16a972cfa 100644 --- a/tests/integration/exec.bats +++ b/tests/integration/exec.bats @@ -140,8 +140,7 @@ function teardown() { runc exec --user 1000:1000 --additional-gids 100 --additional-gids 65534 test_busybox id -G [ "$status" -eq 0 ] - - [[ ${output} == "1000 100 65534" ]] + [ "$output" = "1000 100 65534" ] } @test "runc exec --preserve-fds" { @@ -154,7 +153,7 @@ function teardown() { exec 4 Date: Mon, 7 Feb 2022 16:24:53 -0800 Subject: [PATCH 2/4] tests/int: replace CGROUP_UNIFIED with CGROUP_V{1,2} This makes it work similar to all the other variables we use as binary flags. The new 'shellcheck disable' is due to a bug in shellcheck (basically, it does not track the scope of variables or execution order, assuming everything is executed as soon as it is seen). Signed-off-by: Kir Kolyshkin --- tests/integration/cgroups.bats | 13 +++++-------- tests/integration/helpers.bash | 24 ++++++++++++------------ tests/integration/update.bats | 16 +++++++--------- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/tests/integration/cgroups.bats b/tests/integration/cgroups.bats index 914ec499d..bf8284941 100644 --- a/tests/integration/cgroups.bats +++ b/tests/integration/cgroups.bats @@ -44,7 +44,7 @@ function setup() { runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions [ "$status" -eq 0 ] - if [ "$CGROUP_UNIFIED" != "no" ]; then + if [ -v CGROUP_V2 ]; then if [ -v RUNC_USE_SYSTEMD ]; then if [ "$(id -u)" = "0" ]; then check_cgroup_value "cgroup.controllers" "$(cat /sys/fs/cgroup/machine.slice/cgroup.controllers)" @@ -177,7 +177,7 @@ function setup() { # The loop device itself is no longer needed. losetup -d "$dev" - if [ "$CGROUP_UNIFIED" = "yes" ]; then + if [ -v CGROUP_V2 ]; then file="io.bfq.weight" else file="blkio.bfq.weight_device" @@ -377,18 +377,15 @@ function setup() { set_cgroups_path - case $CGROUP_UNIFIED in - no) + if [ -v CGROUP_V1 ]; then FREEZER_DIR="${CGROUP_FREEZER_BASE_PATH}/${REL_CGROUPS_PATH}" FREEZER="${FREEZER_DIR}/freezer.state" STATE="FROZEN" - ;; - yes) + else FREEZER_DIR="${CGROUP_PATH}" FREEZER="${FREEZER_DIR}/cgroup.freeze" STATE="1" - ;; - esac + fi # Create and freeze the cgroup. mkdir -p "$FREEZER_DIR" diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index 2bd743c65..f0e9823c5 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -104,10 +104,10 @@ function systemd_version() { function init_cgroup_paths() { # init once - [ -v CGROUP_UNIFIED ] && return + [[ -v CGROUP_V1 || -v CGROUP_V2 ]] && return if stat -f -c %t /sys/fs/cgroup | grep -qFw 63677270; then - CGROUP_UNIFIED=yes + CGROUP_V2=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. @@ -135,7 +135,7 @@ function init_cgroup_paths() { if stat -f -c %t /sys/fs/cgroup/unified | grep -qFw 63677270; then CGROUP_HYBRID=yes fi - CGROUP_UNIFIED=no + CGROUP_V1=yes CGROUP_SUBSYSTEMS=$(awk '!/^#/ {print $1}' /proc/cgroups) local g base_path for g in ${CGROUP_SUBSYSTEMS}; do @@ -152,7 +152,7 @@ function create_parent() { "$SD_HELPER" --parent machine.slice start "$SD_PARENT_NAME" else [ ! -v REL_PARENT_PATH ] && return - if [ "$CGROUP_UNIFIED" = "yes" ]; then + if [ -v CGROUP_V2 ]; then mkdir "/sys/fs/cgroup$REL_PARENT_PATH" else local subsys @@ -172,7 +172,7 @@ function remove_parent() { "$SD_HELPER" --parent machine.slice stop "$SD_PARENT_NAME" else [ ! -v REL_PARENT_PATH ] && return - if [ "$CGROUP_UNIFIED" = "yes" ]; then + if [ -v CGROUP_V2 ]; then rmdir "/sys/fs/cgroup/$REL_PARENT_PATH" else local subsys @@ -229,7 +229,7 @@ function set_cgroups_path() { fi # Absolute path to container's cgroup v2. - if [ "$CGROUP_UNIFIED" = "yes" ]; then + if [ -v CGROUP_V2 ]; then CGROUP_PATH=${CGROUP_BASE_PATH}${REL_CGROUPS_PATH} fi @@ -243,7 +243,7 @@ function get_cgroup_value() { local source=$1 local cgroup var current - if [ "$CGROUP_UNIFIED" = "yes" ]; then + if [ -v CGROUP_V2 ]; then cgroup=$CGROUP_PATH else var=${source%%.*} # controller name (e.g. memory) @@ -283,7 +283,7 @@ function check_cpu_quota() { local period=$2 local sd_quota=$3 - if [ "$CGROUP_UNIFIED" = "yes" ]; then + if [ -v CGROUP_V2 ]; then if [ "$quota" = "-1" ]; then quota="max" fi @@ -310,7 +310,7 @@ function check_cpu_quota() { function check_cpu_shares() { local shares=$1 - if [ "$CGROUP_UNIFIED" = "yes" ]; then + if [ -v CGROUP_V2 ]; then local weight=$((1 + ((shares - 2) * 9999) / 262142)) check_cpu_weight "$weight" else @@ -397,7 +397,7 @@ function requires() { ;; cgroups_swap) init_cgroup_paths - if [ $CGROUP_UNIFIED = "no" ] && [ ! -e "${CGROUP_MEMORY_BASE_PATH}/memory.memsw.limit_in_bytes" ]; then + if [ -v CGROUP_V1 ] && [ ! -e "${CGROUP_MEMORY_BASE_PATH}/memory.memsw.limit_in_bytes" ]; then skip_me=1 fi ;; @@ -408,13 +408,13 @@ function requires() { ;; cgroups_v1) init_cgroup_paths - if [ "$CGROUP_UNIFIED" != "no" ]; then + if [ ! -v GROUP_V1 ]; then skip_me=1 fi ;; cgroups_v2) init_cgroup_paths - if [ "$CGROUP_UNIFIED" != "yes" ]; then + if [ ! -v CGROUP_V2 ]; then skip_me=1 fi ;; diff --git a/tests/integration/update.bats b/tests/integration/update.bats index f4f349aa9..48d1efa4c 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -30,8 +30,7 @@ function setup() { [ "$status" -eq 0 ] # Set a few variables to make the code below work for both v1 and v2 - case $CGROUP_UNIFIED in - no) + if [ -v CGROUP_V1 ]; then MEM_LIMIT="memory.limit_in_bytes" SD_MEM_LIMIT="MemoryLimit" MEM_RESERVE="memory.soft_limit_in_bytes" @@ -43,8 +42,7 @@ function setup() { if [ -f "${CGROUP_MEMORY_BASE_PATH}/${MEM_SWAP}" ]; then HAVE_SWAP="yes" fi - ;; - yes) + else MEM_LIMIT="memory.max" SD_MEM_LIMIT="MemoryMax" MEM_RESERVE="memory.low" @@ -53,8 +51,8 @@ function setup() { SD_MEM_SWAP="MemorySwapMax" SYSTEM_MEM="max" HAVE_SWAP="yes" - ;; - esac + fi + SD_UNLIMITED="infinity" SD_VERSION=$(systemctl --version | awk '{print $2; exit}') if [ "$SD_VERSION" -lt 227 ]; then @@ -105,7 +103,7 @@ function setup() { check_systemd_value "$SD_MEM_SWAP" $SD_UNLIMITED # update memory swap - if [ "$CGROUP_UNIFIED" = "yes" ]; then + if [ -v CGROUP_V2 ]; then # for cgroupv2, memory and swap can only be set together runc update test_update --memory 52428800 --memory-swap 96468992 [ "$status" -eq 0 ] @@ -233,7 +231,7 @@ EOF check_cgroup_value $MEM_LIMIT $((30 * 1024 * 1024)) check_systemd_value $SD_MEM_LIMIT $((30 * 1024 * 1024)) - if [ "$CGROUP_UNIFIED" = "yes" ]; then + if [ -v CGROUP_V2 ]; then # for cgroupv2, swap does not include mem check_cgroup_value "$MEM_SWAP" $((20 * 1024 * 1024)) check_systemd_value "$SD_MEM_SWAP" $((20 * 1024 * 1024)) @@ -249,7 +247,7 @@ EOF check_cgroup_value $MEM_LIMIT $((60 * 1024 * 1024)) check_systemd_value $SD_MEM_LIMIT $((60 * 1024 * 1024)) - if [ "$CGROUP_UNIFIED" = "yes" ]; then + if [ -v CGROUP_V2 ]; then # for cgroupv2, swap does not include mem check_cgroup_value "$MEM_SWAP" $((20 * 1024 * 1024)) check_systemd_value "$SD_MEM_SWAP" $((20 * 1024 * 1024)) From d330f94b575037c6de69a0e3565c55096b7cf319 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 7 Feb 2022 19:07:16 -0800 Subject: [PATCH 3/4] tests/int/update.bats: fix extra reqs This test requires both rootless and root, which does not make sense. Remove the rootless part. Fixes: d41a273da Signed-off-by: Kir Kolyshkin --- tests/integration/update.bats | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/integration/update.bats b/tests/integration/update.bats index 48d1efa4c..23f9d8a94 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -627,8 +627,6 @@ EOF } @test "update devices [minimal transition rules]" { - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup - requires root # Run a basic shell script that tries to read from /dev/kmsg, but From d620a401d7fbf3608209ae227300bf62a81662f7 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 7 Feb 2022 19:08:26 -0800 Subject: [PATCH 4/4] tests/int: remove $ROOTLESS, use $EUID The variable $ROOTLESS, as set by helpers.bash and used in many places, provides the same value as $EUID which is always set by bash. Since we are using bash, we can rely on $EUID being omnipresent. Modify all uses accordingly, and since the value is known to be a number, omit the quoting. Similarly, replace all uses of $(id -u) to $EUID. Do some trivial cleanups along the way, such as - simplify some if A; then B; to A && B; - do not use [[ instead of [ where not necessary. Signed-off-by: Kir Kolyshkin --- tests/integration/cgroups.bats | 28 ++++++++++----------------- tests/integration/delete.bats | 2 +- tests/integration/dev.bats | 2 +- tests/integration/exec.bats | 2 +- tests/integration/helpers.bash | 25 +++++++++++------------- tests/integration/pause.bats | 8 ++++---- tests/integration/ps.bats | 2 +- tests/integration/run.bats | 3 +-- tests/integration/start_detached.bats | 2 +- tests/integration/start_hello.bats | 2 +- tests/integration/tty.bats | 8 ++++---- tests/integration/update.bats | 26 ++++++++++++------------- tests/integration/userns.bats | 2 +- 13 files changed, 50 insertions(+), 62 deletions(-) diff --git a/tests/integration/cgroups.bats b/tests/integration/cgroups.bats index bf8284941..ffa3fb0be 100644 --- a/tests/integration/cgroups.bats +++ b/tests/integration/cgroups.bats @@ -37,7 +37,7 @@ function setup() { } @test "runc create (limits + cgrouppath + permission on the cgroup dir) succeeds" { - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup set_cgroups_path set_resources_limit @@ -46,11 +46,11 @@ function setup() { [ "$status" -eq 0 ] if [ -v CGROUP_V2 ]; then if [ -v RUNC_USE_SYSTEMD ]; then - if [ "$(id -u)" = "0" ]; then + if [ $EUID -eq 0 ]; then check_cgroup_value "cgroup.controllers" "$(cat /sys/fs/cgroup/machine.slice/cgroup.controllers)" else # Filter out hugetlb and misc as systemd is unable to delegate them. - check_cgroup_value "cgroup.controllers" "$(sed -e 's/ hugetlb//' -e 's/ misc//' = 244 (Fedora >= 32, Ubuntu >= 20.04). - if [[ "$ROOTLESS" -ne 0 && -v RUNC_USE_SYSTEMD ]]; then - controllers="/sys/fs/cgroup/user.slice/user-$(id -u).slice/user@$(id -u).service/cgroup.controllers" + if [[ $EUID -ne 0 && -v RUNC_USE_SYSTEMD ]]; then + controllers="/sys/fs/cgroup/user.slice/user-${UID}.slice/user@${UID}.service/cgroup.controllers" fi # "pseudo" controllers do not appear in /sys/fs/cgroup/cgroup.controllers. @@ -188,7 +185,7 @@ function remove_parent() { function set_parent_systemd_properties() { [ ! -v SD_PARENT_NAME ] && return local user="" - [ "$(id -u)" != "0" ] && user="--user" + [ $EUID -ne 0 ] && user="--user" systemctl set-property $user "$SD_PARENT_NAME" "$@" } @@ -213,12 +210,12 @@ function set_cgroups_path() { local rnd="$RANDOM" if [ -v RUNC_USE_SYSTEMD ]; then SD_UNIT_NAME="runc-cgroups-integration-test-${rnd}.scope" - if [ "$(id -u)" = "0" ]; then + if [ $EUID -eq 0 ]; then REL_PARENT_PATH="/machine.slice${pod_slice}" OCI_CGROUPS_PATH="machine${dash_pod}.slice:runc-cgroups:integration-test-${rnd}" else - REL_PARENT_PATH="/user.slice/user-$(id -u).slice/user@$(id -u).service/machine.slice${pod_slice}" - # OCI path doesn't contain "/user.slice/user-$(id -u).slice/user@$(id -u).service/" prefix + REL_PARENT_PATH="/user.slice/user-${UID}.slice/user@${UID}.service/machine.slice${pod_slice}" + # OCI path doesn't contain "/user.slice/user-${UID}.slice/user@${UID}.service/" prefix OCI_CGROUPS_PATH="machine${dash_pod}.slice:runc-cgroups:integration-test-${rnd}" fi REL_CGROUPS_PATH="$REL_PARENT_PATH/$SD_UNIT_NAME" @@ -271,7 +268,7 @@ function check_systemd_value() { local expected="$2" local expected2="${3:-}" local user="" - [ "$(id -u)" != "0" ] && user="--user" + [ $EUID -ne 0 ] && user="--user" current=$(systemctl show $user --property "$source" "$SD_UNIT_NAME" | awk -F= '{print $2}') echo "systemd $source: current $current !? $expected $expected2" @@ -360,12 +357,12 @@ function requires() { fi ;; root) - if [ "$ROOTLESS" -ne 0 ]; then + if [ $EUID -ne 0 ]; then skip_me=1 fi ;; rootless) - if [ "$ROOTLESS" -eq 0 ]; then + if [ $EUID -eq 0 ]; then skip_me=1 fi ;; diff --git a/tests/integration/pause.bats b/tests/integration/pause.bats index c2daa1f46..787d2d0d0 100644 --- a/tests/integration/pause.bats +++ b/tests/integration/pause.bats @@ -11,11 +11,11 @@ function teardown() { } @test "runc pause and resume" { - if [[ "$ROOTLESS" -ne 0 ]]; then + requires cgroups_freezer + if [ $EUID -ne 0 ]; then requires rootless_cgroup set_cgroups_path fi - requires cgroups_freezer # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox @@ -39,11 +39,11 @@ function teardown() { } @test "runc pause and resume with nonexist container" { - if [[ "$ROOTLESS" -ne 0 ]]; then + requires cgroups_freezer + if [ $EUID -ne 0 ]; then requires rootless_cgroup set_cgroups_path fi - requires cgroups_freezer # run test_busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox diff --git a/tests/integration/ps.bats b/tests/integration/ps.bats index c28abfc2d..0d96cb250 100644 --- a/tests/integration/ps.bats +++ b/tests/integration/ps.bats @@ -62,7 +62,7 @@ function teardown() { @test "ps after the container stopped" { # ps requires cgroups - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup set_cgroups_path # start busybox detached diff --git a/tests/integration/run.bats b/tests/integration/run.bats index 63be89d2c..16ee6a011 100644 --- a/tests/integration/run.bats +++ b/tests/integration/run.bats @@ -36,8 +36,7 @@ function teardown() { @test "runc run --keep (check cgroup exists)" { # for systemd driver, the unit's cgroup path will be auto removed if container's all processes exited requires no_systemd - - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup set_cgroups_path diff --git a/tests/integration/start_detached.bats b/tests/integration/start_detached.bats index 0f1c23326..73e10c8cb 100644 --- a/tests/integration/start_detached.bats +++ b/tests/integration/start_detached.bats @@ -21,7 +21,7 @@ function teardown() { @test "runc run detached ({u,g}id != 0)" { # cannot start containers as another user in rootless setup without idmap - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap + [ $EUID -ne 0 ] && requires rootless_idmap # replace "uid": 0 with "uid": 1000 # and do a similar thing for gid. diff --git a/tests/integration/start_hello.bats b/tests/integration/start_hello.bats index 1c3c906fa..231f3a797 100644 --- a/tests/integration/start_hello.bats +++ b/tests/integration/start_hello.bats @@ -21,7 +21,7 @@ function teardown() { @test "runc run ({u,g}id != 0)" { # cannot start containers as another user in rootless setup without idmap - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap + [ $EUID -ne 0 ] && requires rootless_idmap # replace "uid": 0 with "uid": 1000 # and do a similar thing for gid. diff --git a/tests/integration/tty.bats b/tests/integration/tty.bats index 8bbb47649..6f008e5f7 100644 --- a/tests/integration/tty.bats +++ b/tests/integration/tty.bats @@ -34,7 +34,7 @@ function teardown() { @test "runc run [tty owner]" { # tty chmod is not doable in rootless containers without idmap. # TODO: this can be made as a change to the gid test. - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap + [ $EUID -ne 0 ] && requires rootless_idmap # Replace sh script with stat. # shellcheck disable=SC2016 @@ -50,7 +50,7 @@ function teardown() { @test "runc run [tty owner] ({u,g}id != 0)" { # tty chmod is not doable in rootless containers without idmap. - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap + [ $EUID -ne 0 ] && requires rootless_idmap # replace "uid": 0 with "uid": 1000 # and do a similar thing for gid. @@ -100,7 +100,7 @@ function teardown() { @test "runc exec [tty owner]" { # tty chmod is not doable in rootless containers without idmap. # TODO: this can be made as a change to the gid test. - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap + [ $EUID -ne 0 ] && requires rootless_idmap # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox @@ -119,7 +119,7 @@ function teardown() { @test "runc exec [tty owner] ({u,g}id != 0)" { # tty chmod is not doable in rootless containers without idmap. - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap + [ $EUID -ne 0 ] && requires rootless_idmap # replace "uid": 0 with "uid": 1000 # and do a similar thing for gid. diff --git a/tests/integration/update.bats b/tests/integration/update.bats index 23f9d8a94..b28105809 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 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup requires cgroups_memory cgroups_pids cgroups_cpuset init_cgroup_paths @@ -259,7 +259,7 @@ EOF } @test "update cgroup cpu limits" { - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup # run a few busyboxes detached runc run -d --console-socket "$CONSOLE_SOCKET" test_update @@ -333,7 +333,7 @@ EOF } @test "set cpu period with no quota" { - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup update_config '.linux.resources.cpu |= { "period": 1000000 }' @@ -344,7 +344,7 @@ EOF } @test "set cpu period with no quota (invalid period)" { - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup update_config '.linux.resources.cpu |= { "period": 100 }' @@ -353,7 +353,7 @@ EOF } @test "set cpu quota with no period" { - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup update_config '.linux.resources.cpu |= { "quota": 5000 }' @@ -363,7 +363,7 @@ EOF } @test "update cpu period with no previous period/quota set" { - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup update_config '.linux.resources.cpu |= {}' @@ -377,7 +377,7 @@ EOF } @test "update cpu quota with no previous period/quota set" { - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup update_config '.linux.resources.cpu |= {}' @@ -392,7 +392,7 @@ EOF @test "update cpu period in a pod cgroup with pod limit set" { requires cgroups_v1 - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup set_cgroups_path "pod_${RANDOM}" @@ -426,7 +426,7 @@ EOF } @test "update cgroup v2 resources via unified map" { - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup requires cgroups_v2 runc run -d --console-socket "$CONSOLE_SOCKET" test_update @@ -455,7 +455,7 @@ EOF } @test "update cpuset parameters via resources.CPU" { - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup requires smp cgroups_cpuset local AllowedCPUs='AllowedCPUs' AllowedMemoryNodes='AllowedMemoryNodes' @@ -511,7 +511,7 @@ EOF @test "update cpuset parameters via v2 unified map" { # This test assumes systemd >= v244 - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup requires cgroups_v2 smp cgroups_cpuset update_config ' .linux.resources.unified |= { @@ -558,7 +558,7 @@ EOF } @test "update rt period and runtime" { - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup requires cgroups_v1 cgroups_rt no_systemd local cgroup_cpu="${CGROUP_CPU_BASE_PATH}/${REL_CGROUPS_PATH}" @@ -678,8 +678,8 @@ EOF } @test "update paused container" { - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup requires cgroups_freezer + [ $EUID -ne 0 ] && requires rootless_cgroup # Run the container in the background. runc run -d --console-socket "$CONSOLE_SOCKET" test_update diff --git a/tests/integration/userns.bats b/tests/integration/userns.bats index b1188592f..f6c677bcb 100644 --- a/tests/integration/userns.bats +++ b/tests/integration/userns.bats @@ -15,7 +15,7 @@ function setup() { mkdir -p rootfs/{proc,sys,tmp} mkdir -p rootfs/tmp/mount-{1,2} - if [ "$ROOTLESS" -eq 0 ]; then + if [ $EUID -eq 0 ]; then update_config ' .linux.namespaces += [{"type": "user"}] | .linux.uidMappings += [{"hostID": 100000, "containerID": 0, "size": 65534}] | .linux.gidMappings += [{"hostID": 100000, "containerID": 0, "size": 65534}] '