#!/usr/bin/env bats load helpers function teardown() { rm -f $BATS_TMPDIR/runc-update-integration-test.json teardown_running_container test_update teardown_running_container test_update_rt teardown_busybox } function setup() { teardown setup_busybox # Add cgroup path sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "\/runc-update-integration-test",/' ${BUSYBOX_BUNDLE}/config.json # Set some initial known values DATA=$(cat </ { print $5; exit }') eval CGROUP_${g}="${base_path}/runc-update-integration-test" done CGROUP_SYSTEM_MEMORY=$(grep "cgroup" /proc/self/mountinfo | gawk 'toupper($NF) ~ /\<'MEMORY'\>/ { print $5; exit }') # check that initial values were properly set check_cgroup_value $CGROUP_BLKIO "blkio.weight" 1000 check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 1000000 check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 500000 check_cgroup_value $CGROUP_CPU "cpu.shares" 100 check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 0 check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 16777216 check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 11534336 check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 33554432 check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824 check_cgroup_value $CGROUP_PIDS "pids.max" 20 # update blkio-weight runc update test_update --blkio-weight 500 [ "$status" -eq 0 ] check_cgroup_value $CGROUP_BLKIO "blkio.weight" 500 # update cpu-period runc update test_update --cpu-period 900000 [ "$status" -eq 0 ] check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 900000 # update cpu-quota runc update test_update --cpu-quota 600000 [ "$status" -eq 0 ] check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 600000 # update cpu-shares runc update test_update --cpu-share 200 [ "$status" -eq 0 ] check_cgroup_value $CGROUP_CPU "cpu.shares" 200 # update cpuset if supported (i.e. we're running on a multicore cpu) cpu_count=$(grep '^processor' /proc/cpuinfo | wc -l) if [ $cpu_count -gt 1 ]; then runc update test_update --cpuset-cpus "1" [ "$status" -eq 0 ] check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 1 fi # update memory limit runc update test_update --memory 67108864 [ "$status" -eq 0 ] check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 67108864 runc update test_update --memory 50M [ "$status" -eq 0 ] check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 52428800 # update memory soft limit runc update test_update --memory-reservation 33554432 [ "$status" -eq 0 ] check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 33554432 # Run swap memory tests if swap is avaialble if [ -f "$CGROUP_MEMORY/memory.memsw.limit_in_bytes" ]; then # try to remove memory swap limit runc update test_update --memory-swap -1 [ "$status" -eq 0 ] # Get System memory swap limit SYSTEM_MEMORY_SW=$(cat "${CGROUP_SYSTEM_MEMORY}/memory.memsw.limit_in_bytes") check_cgroup_value $CGROUP_MEMORY "memory.memsw.limit_in_bytes" ${SYSTEM_MEMORY_SW} # update memory swap runc update test_update --memory-swap 96468992 [ "$status" -eq 0 ] check_cgroup_value $CGROUP_MEMORY "memory.memsw.limit_in_bytes" 96468992 fi; # try to remove memory limit runc update test_update --memory -1 [ "$status" -eq 0 ] # Get System memory limit SYSTEM_MEMORY=$(cat "${CGROUP_SYSTEM_MEMORY}/memory.limit_in_bytes") # check memory limited is gone check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" ${SYSTEM_MEMORY} # check swap memory limited is gone if [ -f "$CGROUP_MEMORY/memory.memsw.limit_in_bytes" ]; then check_cgroup_value $CGROUP_MEMORY "memory.memsw.limit_in_bytes" ${SYSTEM_MEMORY} fi # update kernel memory limit runc update test_update --kernel-memory 50331648 [ "$status" -eq 0 ] check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648 # update kernel memory tcp limit runc update test_update --kernel-memory-tcp 41943040 [ "$status" -eq 0 ] check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 41943040 # update pids limit runc update test_update --pids-limit 10 [ "$status" -eq 0 ] check_cgroup_value $CGROUP_PIDS "pids.max" 10 # Revert to the test initial value via json on stding runc update -r - test_update < $BATS_TMPDIR/runc-update-integration-test.json runc update -r $BATS_TMPDIR/runc-update-integration-test.json test_update [ "$status" -eq 0 ] check_cgroup_value $CGROUP_BLKIO "blkio.weight" 1000 check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 1000000 check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 500000 check_cgroup_value $CGROUP_CPU "cpu.shares" 100 check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 0 check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 16777216 check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 11534336 check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 33554432 check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824 check_cgroup_value $CGROUP_PIDS "pids.max" 20 } @test "update rt period and runtime" { requires cgroups_rt # run a detached busybox runc run -d --console-socket $CONSOLE_SOCKET test_update_rt [ "$status" -eq 0 ] # get the cgroup paths eval CGROUP_CPU="${CGROUP_CPU_BASE_PATH}/runc-update-integration-test" runc update -r - test_update_rt <