diff --git a/tests/integration/cgroups.bats b/tests/integration/cgroups.bats index 89c63f398..ffa3fb0be 100644 --- a/tests/integration/cgroups.bats +++ b/tests/integration/cgroups.bats @@ -37,20 +37,20 @@ 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 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 + 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//' /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 @@ -133,7 +133,7 @@ function setup() { @test "runc run (blkio weight)" { requires cgroups_v2 - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup set_cgroups_path update_config '.linux.resources.blockIO |= {"weight": 750}' @@ -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" @@ -270,7 +270,7 @@ function setup() { @test "runc run (cgroupv2 mount inside container)" { requires cgroups_v2 - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup + [ $EUID -ne 0 ] && requires rootless_cgroup set_cgroups_path @@ -301,14 +301,12 @@ 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" { - if [[ "$ROOTLESS" -ne 0 ]]; then - requires rootless_cgroup - fi requires cgroups_freezer + [ $EUID -ne 0 ] && requires rootless_cgroup set_cgroups_path @@ -324,10 +322,8 @@ function setup() { } @test "runc exec --ignore-paused" { - if [[ "$ROOTLESS" -ne 0 ]]; then - requires rootless_cgroup - fi requires cgroups_freezer + [ $EUID -ne 0 ] && requires rootless_cgroup set_cgroups_path @@ -349,9 +345,7 @@ function setup() { } @test "runc run/create should warn about a non-empty cgroup" { - if [[ "$ROOTLESS" -ne 0 ]]; then - requires rootless_cgroup - fi + [ $EUID -ne 0 ] && requires rootless_cgroup set_cgroups_path @@ -371,24 +365,19 @@ function setup() { @test "runc run/create should refuse pre-existing frozen cgroup" { requires cgroups_freezer - if [[ "$ROOTLESS" -ne 0 ]]; then - requires rootless_cgroup - fi + [ $EUID -ne 0 ] && requires rootless_cgroup 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/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/delete.bats b/tests/integration/delete.bats index 624095884..d8e02f939 100644 --- a/tests/integration/delete.bats +++ b/tests/integration/delete.bats @@ -15,7 +15,7 @@ function teardown() { # XXX(@kolyshkin): currently this test does not handle rootless when # fs cgroup driver is used, because in this case cgroup (with a # predefined name) is created by tests/rootless.sh, not by runc. - [[ "$ROOTLESS" -ne 0 ]] && requires systemd + [ $EUID -ne 0 ] && requires systemd set_resources_limit runc run -d --console-socket "$CONSOLE_SOCKET" testbusyboxdelete diff --git a/tests/integration/dev.bats b/tests/integration/dev.bats index 01f677859..95675fd30 100644 --- a/tests/integration/dev.bats +++ b/tests/integration/dev.bats @@ -17,7 +17,7 @@ function teardown() { runc run test_dev [ "$status" -eq 0 ] - if [[ "$ROOTLESS" -ne 0 ]]; then + if [ $EUID -ne 0 ]; then [[ "${lines[0]}" =~ "crw-rw-rw".+"1".+"65534".+"65534".+"5,".+"0".+"/dev/tty" ]] else [[ "${lines[0]}" =~ "crw-rw-rw".+"1".+"0".+"0".+"5,".+"0".+"/dev/tty" ]] diff --git a/tests/integration/exec.bats b/tests/integration/exec.bats index 140cd1810..c6f4bfcb8 100644 --- a/tests/integration/exec.bats +++ b/tests/integration/exec.bats @@ -117,7 +117,7 @@ function teardown() { @test "runc exec --user" { # --user can't work in rootless containers that don't have idmap. - [[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap + [ $EUID -ne 0 ] && requires rootless_idmap # run busybox detached runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox @@ -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= 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. @@ -135,7 +132,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 +149,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 +169,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 @@ -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" @@ -229,7 +226,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 +240,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) @@ -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" @@ -283,7 +280,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 +307,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 @@ -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 ;; @@ -397,7 +394,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 +405,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 ;; @@ -498,7 +495,7 @@ function wait_for_container() { function testcontainer() { # test state of container runc state "$1" - if [ "$2" == "checkpointed" ]; then + if [ "$2" = "checkpointed" ]; then [ "$status" -eq 1 ] return fi diff --git a/tests/integration/list.bats b/tests/integration/list.bats index a22dd19a4..b8821bc70 100644 --- a/tests/integration/list.bats +++ b/tests/integration/list.bats @@ -35,9 +35,9 @@ function teardown() { ROOT=$ALT_ROOT runc list -q [ "$status" -eq 0 ] - [[ "${lines[0]}" == "test_box1" ]] - [[ "${lines[1]}" == "test_box2" ]] - [[ "${lines[2]}" == "test_box3" ]] + [ "${lines[0]}" = "test_box1" ] + [ "${lines[1]}" = "test_box2" ] + [ "${lines[2]}" = "test_box3" ] ROOT=$ALT_ROOT runc list --format table [ "$status" -eq 0 ] diff --git a/tests/integration/mask.bats b/tests/integration/mask.bats index b5f296756..4bf834ef9 100644 --- a/tests/integration/mask.bats +++ b/tests/integration/mask.bats @@ -24,7 +24,7 @@ function teardown() { runc exec test_busybox cat /testfile [ "$status" -eq 0 ] - [[ "${output}" == "" ]] + [ -z "$output" ] runc exec test_busybox rm -f /testfile [ "$status" -eq 1 ] @@ -42,7 +42,7 @@ function teardown() { runc exec test_busybox ls /testdir [ "$status" -eq 0 ] - [[ "${output}" == "" ]] + [ -z "$output" ] runc exec test_busybox touch /testdir/foo [ "$status" -eq 1 ] 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 f4f349aa9..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 @@ -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)) @@ -261,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 @@ -335,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 }' @@ -346,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 }' @@ -355,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 }' @@ -365,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 |= {}' @@ -379,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 |= {}' @@ -394,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}" @@ -428,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 @@ -457,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' @@ -513,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 |= { @@ -560,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}" @@ -629,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 @@ -682,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}] ' diff --git a/tests/rootless.sh b/tests/rootless.sh index f6872fad0..83be248a1 100755 --- a/tests/rootless.sh +++ b/tests/rootless.sh @@ -112,9 +112,9 @@ function enable_cgroup() { # for runc to set up the hierarchy. XXX: This really shouldn't be # necessary, and might actually be a bug in our impl of cgroup # handling. - [[ "$cg" == "cpuset" ]] && chown rootless:rootless "$CGROUP_MOUNT/$cg$CGROUP_PATH/cpuset."{cpus,mems} + [ "$cg" = "cpuset" ] && chown rootless:rootless "$CGROUP_MOUNT/$cg$CGROUP_PATH/cpuset."{cpus,mems} # The following is required by "update rt period and runtime". - if [[ "$cg" == "cpu" ]]; then + if [ "$cg" = "cpu" ]; then if [[ -e "$CGROUP_MOUNT/$cg$CGROUP_PATH/cpu.rt_period_us" ]]; then chown rootless:rootless "$CGROUP_MOUNT/$cg$CGROUP_PATH/cpu.rt_period_us" fi