2016-04-28 22:30:50 +08:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load helpers
|
|
|
|
|
|
|
|
function teardown() {
|
|
|
|
rm -f $BATS_TMPDIR/runc-update-integration-test.json
|
2016-05-11 14:17:32 +08:00
|
|
|
teardown_running_container test_update
|
2016-04-28 22:30:50 +08:00
|
|
|
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 <<EOF
|
|
|
|
"memory": {
|
|
|
|
"limit": 33554432,
|
|
|
|
"reservation": 25165824,
|
2016-05-09 23:14:29 +08:00
|
|
|
"kernel": 16777216,
|
|
|
|
"kernelTCP": 11534336
|
2016-04-28 22:30:50 +08:00
|
|
|
},
|
|
|
|
"cpu": {
|
|
|
|
"shares": 100,
|
|
|
|
"quota": 500000,
|
|
|
|
"period": 1000000,
|
|
|
|
"cpus": "0"
|
|
|
|
},
|
|
|
|
"blockio": {
|
|
|
|
"blkioWeight": 1000
|
|
|
|
},
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
DATA=$(echo ${DATA} | sed 's/\n/\\n/g')
|
|
|
|
sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_cgroup_value() {
|
|
|
|
cgroup=$1
|
|
|
|
source=$2
|
|
|
|
expected=$3
|
|
|
|
|
|
|
|
current=$(cat $cgroup/$source)
|
|
|
|
[ "$current" -eq "$expected" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "update" {
|
2016-05-14 06:49:45 +08:00
|
|
|
# run a few busyboxes detached
|
|
|
|
runc run -d --console /dev/pts/ptmx test_update
|
2016-04-28 22:30:50 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2016-05-11 14:17:32 +08:00
|
|
|
wait_for_container 15 1 test_update
|
2016-04-28 22:30:50 +08:00
|
|
|
|
2016-05-09 21:06:42 +08:00
|
|
|
# get the cgroup paths
|
|
|
|
for g in MEMORY CPUSET CPU BLKIO; do
|
|
|
|
base_path=$(grep "cgroup" /proc/self/mountinfo | gawk 'toupper($NF) ~ /\<'${g}'\>/ { print $5; exit }')
|
|
|
|
eval CGROUP_${g}="${base_path}/runc-update-integration-test"
|
|
|
|
done
|
2016-04-28 22:30:50 +08:00
|
|
|
|
|
|
|
# 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
|
2016-05-09 23:14:29 +08:00
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 11534336
|
2016-04-28 22:30:50 +08:00
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 33554432
|
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824
|
|
|
|
|
|
|
|
# update blkio-weight
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_update --blkio-weight 500
|
2016-04-28 22:30:50 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
check_cgroup_value $CGROUP_BLKIO "blkio.weight" 500
|
|
|
|
|
|
|
|
# update cpu-period
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_update --cpu-period 900000
|
2016-04-28 22:30:50 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 900000
|
|
|
|
|
|
|
|
# update cpu-quota
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_update --cpu-quota 600000
|
2016-04-28 22:30:50 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 600000
|
|
|
|
|
|
|
|
# update cpu-shares
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_update --cpu-share 200
|
2016-04-28 22:30:50 +08:00
|
|
|
[ "$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 -ge 1 ]; then
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_update --cpuset-cpus "1"
|
2016-04-28 22:30:50 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# update memory limit
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_update --memory 67108864
|
2016-04-28 22:30:50 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 67108864
|
|
|
|
|
2016-05-30 18:56:10 +08:00
|
|
|
runc update test_update --memory 50M
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 52428800
|
|
|
|
|
|
|
|
|
2016-04-28 22:30:50 +08:00
|
|
|
# update memory soft limit
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_update --memory-reservation 33554432
|
2016-04-28 22:30:50 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 33554432
|
|
|
|
|
|
|
|
# update memory swap (if available)
|
|
|
|
if [ -f "$CGROUP_MEMORY/memory.memsw.limit_in_bytes" ]; then
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_update --memory-swap 96468992
|
2016-04-28 22:30:50 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.memsw.limit_in_bytes" 96468992
|
|
|
|
fi
|
|
|
|
|
|
|
|
# update kernel memory limit
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_update --kernel-memory 50331648
|
2016-04-28 22:30:50 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648
|
|
|
|
|
2016-05-09 23:14:29 +08:00
|
|
|
# update kernel memory tcp limit
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_update --kernel-memory-tcp 41943040
|
2016-05-09 23:14:29 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 41943040
|
|
|
|
|
2016-04-28 22:30:50 +08:00
|
|
|
# Revert to the test initial value via json on stding
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update -r - test_update <<EOF
|
2016-04-28 22:30:50 +08:00
|
|
|
{
|
|
|
|
"memory": {
|
|
|
|
"limit": 33554432,
|
|
|
|
"reservation": 25165824,
|
2016-05-09 23:14:29 +08:00
|
|
|
"kernel": 16777216,
|
|
|
|
"kernelTCP": 11534336
|
2016-04-28 22:30:50 +08:00
|
|
|
},
|
|
|
|
"cpu": {
|
|
|
|
"shares": 100,
|
|
|
|
"quota": 500000,
|
|
|
|
"period": 1000000,
|
|
|
|
"cpus": "0"
|
|
|
|
},
|
|
|
|
"blockIO": {
|
|
|
|
"blkioWeight": 1000
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
[ "$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
|
2016-05-09 23:14:29 +08:00
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 11534336
|
2016-04-28 22:30:50 +08:00
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 33554432
|
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824
|
|
|
|
|
|
|
|
# redo all the changes at once
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update test_update --blkio-weight 500 \
|
2016-04-28 22:30:50 +08:00
|
|
|
--cpu-period 900000 --cpu-quota 600000 --cpu-share 200 --memory 67108864 \
|
2016-05-09 23:14:29 +08:00
|
|
|
--memory-reservation 33554432 --kernel-memory 50331648 --kernel-memory-tcp 41943040
|
2016-04-28 22:30:50 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
check_cgroup_value $CGROUP_BLKIO "blkio.weight" 500
|
|
|
|
check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 900000
|
|
|
|
check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 600000
|
|
|
|
check_cgroup_value $CGROUP_CPU "cpu.shares" 200
|
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648
|
2016-05-09 23:14:29 +08:00
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 41943040
|
2016-04-28 22:30:50 +08:00
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 67108864
|
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 33554432
|
|
|
|
|
|
|
|
# reset to initial test value via json file
|
|
|
|
DATA=$(cat <<"EOF"
|
|
|
|
{
|
|
|
|
"memory": {
|
|
|
|
"limit": 33554432,
|
|
|
|
"reservation": 25165824,
|
2016-05-09 23:14:29 +08:00
|
|
|
"kernel": 16777216,
|
|
|
|
"kernelTCP": 11534336
|
2016-04-28 22:30:50 +08:00
|
|
|
},
|
|
|
|
"cpu": {
|
|
|
|
"shares": 100,
|
|
|
|
"quota": 500000,
|
|
|
|
"period": 1000000,
|
|
|
|
"cpus": "0"
|
|
|
|
},
|
|
|
|
"blockIO": {
|
|
|
|
"blkioWeight": 1000
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
echo $DATA > $BATS_TMPDIR/runc-update-integration-test.json
|
|
|
|
|
2016-05-09 21:06:42 +08:00
|
|
|
runc update -r $BATS_TMPDIR/runc-update-integration-test.json test_update
|
2016-04-28 22:30:50 +08:00
|
|
|
[ "$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
|
2016-05-09 23:14:29 +08:00
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 11534336
|
2016-04-28 22:30:50 +08:00
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 33554432
|
|
|
|
check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824
|
|
|
|
}
|