tests/int: simplify check_systemd_value use

...so it will be easier to write more tests

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2020-05-19 19:19:59 -07:00
parent 716079f95b
commit 4fc9fa05da
2 changed files with 15 additions and 28 deletions

View File

@ -110,11 +110,12 @@ function init_cgroup_paths() {
test -n "$CGROUP_UNIFIED" && return test -n "$CGROUP_UNIFIED" && return
if [ -n "${RUNC_USE_SYSTEMD}" ] ; then if [ -n "${RUNC_USE_SYSTEMD}" ] ; then
SD_UNIT_NAME="runc-cgroups-integration-test.scope"
if [ $(id -u) = "0" ]; then if [ $(id -u) = "0" ]; then
REL_CGROUPS_PATH="/machine.slice/runc-cgroups-integration-test.scope" REL_CGROUPS_PATH="/machine.slice/$SD_UNIT_NAME"
OCI_CGROUPS_PATH="machine.slice:runc-cgroups:integration-test" OCI_CGROUPS_PATH="machine.slice:runc-cgroups:integration-test"
else else
REL_CGROUPS_PATH="/user.slice/user-$(id -u).slice/user@$(id -u).service/machine.slice/runc-cgroups-integration-test.scope" REL_CGROUPS_PATH="/user.slice/user-$(id -u).slice/user@$(id -u).service/machine.slice/$SD_UNIT_NAME"
# OCI path doesn't contain "/user.slice/user-$(id -u).slice/user@$(id -u).service/" prefix # OCI path doesn't contain "/user.slice/user-$(id -u).slice/user@$(id -u).service/" prefix
OCI_CGROUPS_PATH="machine.slice:runc-cgroups:integration-test" OCI_CGROUPS_PATH="machine.slice:runc-cgroups:integration-test"
fi fi
@ -178,16 +179,14 @@ function check_cgroup_value() {
# Helper to check a value in systemd. # Helper to check a value in systemd.
function check_systemd_value() { function check_systemd_value() {
unitname=$1 [ -z "${RUNC_USE_SYSTEMD}" ] && return
source=$2 source=$1
expected=$3 expected="$2"
user=""
[ $(id -u) != "0" ] && user="--user"
if [ $(id -u) = "0" ]; then current=$(systemctl show $user --property $source $SD_UNIT_NAME | awk -F= '{print $2}')
current=$(systemctl show $unitname | grep $source) echo "systemd $source: current $current !? $expected"
else
current=$(systemctl --user show $unitname | grep $source)
fi
echo "current" $current "!?" "$expected"
[ "$current" = "$expected" ] [ "$current" = "$expected" ]
} }

View File

@ -63,6 +63,7 @@ EOF
case $CGROUP_UNIFIED in case $CGROUP_UNIFIED in
no) no)
MEM_LIMIT="memory.limit_in_bytes" MEM_LIMIT="memory.limit_in_bytes"
SD_MEM_LIMIT="MemoryLimit"
MEM_RESERVE="memory.soft_limit_in_bytes" MEM_RESERVE="memory.soft_limit_in_bytes"
MEM_SWAP="memory.memsw.limit_in_bytes" MEM_SWAP="memory.memsw.limit_in_bytes"
SYSTEM_MEM=$(cat "${CGROUP_MEMORY_BASE_PATH}/${MEM_LIMIT}") SYSTEM_MEM=$(cat "${CGROUP_MEMORY_BASE_PATH}/${MEM_LIMIT}")
@ -70,6 +71,7 @@ EOF
;; ;;
yes) yes)
MEM_LIMIT="memory.max" MEM_LIMIT="memory.max"
SD_MEM_LIMIT="MemoryMax"
MEM_RESERVE="memory.low" MEM_RESERVE="memory.low"
MEM_SWAP="memory.swap.max" MEM_SWAP="memory.swap.max"
SYSTEM_MEM="max" SYSTEM_MEM="max"
@ -101,24 +103,12 @@ EOF
runc update test_update --memory 67108864 runc update test_update --memory 67108864
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value $MEM_LIMIT 67108864 check_cgroup_value $MEM_LIMIT 67108864
if [[ -n "${RUNC_USE_SYSTEMD}" ]] ; then check_systemd_value $SD_MEM_LIMIT 67108864
if [ "$CGROUP_UNIFIED" != "yes" ]; then
check_systemd_value "runc-cgroups-integration-test.scope" "MemoryLimit=" "MemoryLimit=67108864"
else
check_systemd_value "runc-cgroups-integration-test.scope" "MemoryMax=" "MemoryMax=67108864"
fi
fi
runc update test_update --memory 50M runc update test_update --memory 50M
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value $MEM_LIMIT 52428800 check_cgroup_value $MEM_LIMIT 52428800
if [[ -n "${RUNC_USE_SYSTEMD}" ]] ; then check_systemd_value $SD_MEM_LIMIT 52428800
if [ "$CGROUP_UNIFIED" != "yes" ]; then
check_systemd_value "runc-cgroups-integration-test.scope" "MemoryLimit=" "MemoryLimit=52428800"
else
check_systemd_value "runc-cgroups-integration-test.scope" "MemoryMax=" "MemoryMax=52428800"
fi
fi
# update memory soft limit # update memory soft limit
runc update test_update --memory-reservation 33554432 runc update test_update --memory-reservation 33554432
@ -154,9 +144,7 @@ EOF
runc update test_update --pids-limit 10 runc update test_update --pids-limit 10
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
check_cgroup_value "pids.max" 10 check_cgroup_value "pids.max" 10
if [[ -n "${RUNC_USE_SYSTEMD}" ]] ; then check_systemd_value "TasksMax" 10
check_systemd_value "runc-cgroups-integration-test.scope" "TasksMax=" "TasksMax=10"
fi
# Revert to the test initial value via json on stdin # Revert to the test initial value via json on stdin
runc update -r - test_update <<EOF runc update -r - test_update <<EOF