Merge pull request #812 from cyphar/integration-fix-cgroup-parsing
integration: fix cgroup parsing
This commit is contained in:
commit
0d8878a6c0
|
@ -6,6 +6,7 @@ RUN echo 'deb http://httpredir.debian.org/debian jessie-backports main' > /etc/a
|
|||
RUN apt-get update && apt-get install -y \
|
||||
build-essential \
|
||||
curl \
|
||||
gawk \
|
||||
iptables \
|
||||
libaio-dev \
|
||||
libcap-dev \
|
||||
|
|
|
@ -2,20 +2,17 @@
|
|||
|
||||
load helpers
|
||||
|
||||
UPDATE_TEST_RUNC_ROOT="$BATS_TMPDIR/runc-cgroups-integration-test"
|
||||
|
||||
CGROUP_MEMORY=""
|
||||
|
||||
TEST_CGROUP_NAME="runc-cgroups-integration-test"
|
||||
|
||||
function init_cgroup_path() {
|
||||
base_path=$(grep "rw," /proc/self/mountinfo | grep -i -m 1 'MEMORY$' | cut -d ' ' -f 5)
|
||||
CGROUP_MEMORY="${base_path}/${TEST_CGROUP_NAME}"
|
||||
base_path=$(grep "cgroup" /proc/self/mountinfo | gawk 'toupper($NF) ~ /\<MEMORY\>/ { print $5; exit }')
|
||||
CGROUP_MEMORY="${base_path}/${TEST_CGROUP_NAME}"
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
rm -f $BATS_TMPDIR/runc-update-integration-test.json
|
||||
teardown_running_container_inroot test_cgroups_kmem $UPDATE_TEST_RUNC_ROOT
|
||||
teardown_running_container test_cgroups_kmem
|
||||
teardown_busybox
|
||||
}
|
||||
|
||||
|
@ -37,7 +34,7 @@ function check_cgroup_value() {
|
|||
[ "$current" -eq "$expected" ]
|
||||
}
|
||||
|
||||
@test "cgroups-kernel-memory-initialized" {
|
||||
@test "runc update --kernel-memory (initialized)" {
|
||||
# Add cgroup path
|
||||
sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json
|
||||
|
||||
|
@ -52,26 +49,26 @@ EOF
|
|||
sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json
|
||||
|
||||
# start a detached busybox to work with
|
||||
"$RUNC" --root $UPDATE_TEST_RUNC_ROOT start -d --console /dev/pts/ptmx test_cgroups_kmem
|
||||
run "$RUNC" start -d --console /dev/pts/ptmx test_cgroups_kmem
|
||||
[ "$status" -eq 0 ]
|
||||
wait_for_container_inroot 15 1 test_cgroups_kmem $UPDATE_TEST_RUNC_ROOT
|
||||
wait_for_container 15 1 test_cgroups_kmem
|
||||
|
||||
# update kernel memory limit
|
||||
"$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_cgroups_kmem --kernel-memory 50331648
|
||||
run "$RUNC" update test_cgroups_kmem --kernel-memory 50331648
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648
|
||||
}
|
||||
|
||||
@test "cgroups-kernel-memory-uninitialized" {
|
||||
@test "runc update --kernel-memory (uninitialized)" {
|
||||
# Add cgroup path
|
||||
sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json
|
||||
|
||||
# start a detached busybox to work with
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT start -d --console /dev/pts/ptmx test_cgroups_kmem
|
||||
run "$RUNC" start -d --console /dev/pts/ptmx test_cgroups_kmem
|
||||
[ "$status" -eq 0 ]
|
||||
wait_for_container_inroot 15 1 test_cgroups_kmem $UPDATE_TEST_RUNC_ROOT
|
||||
wait_for_container 15 1 test_cgroups_kmem
|
||||
|
||||
# update kernel memory limit
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_cgroups_kmem --kernel-memory 50331648
|
||||
run "$RUNC" update test_cgroups_kmem --kernel-memory 50331648
|
||||
[ ! "$status" -eq 0 ]
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
load helpers
|
||||
|
||||
UPDATE_TEST_RUNC_ROOT="$BATS_TMPDIR/runc-update-integration-test"
|
||||
|
||||
CGROUP_MEMORY=""
|
||||
CGROUP_CPUSET=""
|
||||
CGROUP_CPU=""
|
||||
|
@ -11,14 +9,14 @@ CGROUP_BLKIO=""
|
|||
|
||||
function init_cgroup_path() {
|
||||
for g in MEMORY CPUSET CPU BLKIO; do
|
||||
base_path=$(grep "rw," /proc/self/mountinfo | grep -i -m 1 "$g\$" | cut -d ' ' -f 5)
|
||||
base_path=$(grep "cgroup" /proc/self/mountinfo | gawk 'toupper($NF) ~ /\<'${g}'\>/ { print $5; exit }')
|
||||
eval CGROUP_${g}="${base_path}/runc-update-integration-test"
|
||||
done
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
rm -f $BATS_TMPDIR/runc-update-integration-test.json
|
||||
teardown_running_container_inroot test_update $UPDATE_TEST_RUNC_ROOT
|
||||
teardown_running_container test_update
|
||||
teardown_busybox
|
||||
}
|
||||
|
||||
|
@ -63,9 +61,9 @@ function check_cgroup_value() {
|
|||
|
||||
@test "update" {
|
||||
# start a few busyboxes detached
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT start -d --console /dev/pts/ptmx test_update
|
||||
run "$RUNC" start -d --console /dev/pts/ptmx test_update
|
||||
[ "$status" -eq 0 ]
|
||||
wait_for_container_inroot 15 1 test_update $UPDATE_TEST_RUNC_ROOT
|
||||
wait_for_container 15 1 test_update
|
||||
|
||||
init_cgroup_path
|
||||
|
||||
|
@ -81,62 +79,62 @@ function check_cgroup_value() {
|
|||
check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824
|
||||
|
||||
# update blkio-weight
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --blkio-weight 500
|
||||
run "$RUNC" update test_update --blkio-weight 500
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value $CGROUP_BLKIO "blkio.weight" 500
|
||||
|
||||
# update cpu-period
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --cpu-period 900000
|
||||
run "$RUNC" update test_update --cpu-period 900000
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 900000
|
||||
|
||||
# update cpu-quota
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --cpu-quota 600000
|
||||
run "$RUNC" update test_update --cpu-quota 600000
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 600000
|
||||
|
||||
# update cpu-shares
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --cpu-share 200
|
||||
run "$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 -ge 1 ]; then
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --cpuset-cpus "1"
|
||||
run "$RUNC" update test_update --cpuset-cpus "1"
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 1
|
||||
fi
|
||||
|
||||
# update memory limit
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --memory 67108864
|
||||
run "$RUNC" update test_update --memory 67108864
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 67108864
|
||||
|
||||
# update memory soft limit
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --memory-reservation 33554432
|
||||
run "$RUNC" update test_update --memory-reservation 33554432
|
||||
[ "$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
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --memory-swap 96468992
|
||||
run "$RUNC" update test_update --memory-swap 96468992
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value $CGROUP_MEMORY "memory.memsw.limit_in_bytes" 96468992
|
||||
fi
|
||||
|
||||
# update kernel memory limit
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --kernel-memory 50331648
|
||||
run "$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
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --kernel-memory-tcp 41943040
|
||||
run "$RUNC" update test_update --kernel-memory-tcp 41943040
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 41943040
|
||||
|
||||
# Revert to the test initial value via json on stding
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update -r - test_update <<EOF
|
||||
run "$RUNC" update -r - test_update <<EOF
|
||||
{
|
||||
"memory": {
|
||||
"limit": 33554432,
|
||||
|
@ -167,7 +165,7 @@ EOF
|
|||
check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824
|
||||
|
||||
# redo all the changes at once
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --blkio-weight 500 \
|
||||
run "$RUNC" update test_update --blkio-weight 500 \
|
||||
--cpu-period 900000 --cpu-quota 600000 --cpu-share 200 --memory 67108864 \
|
||||
--memory-reservation 33554432 --kernel-memory 50331648 --kernel-memory-tcp 41943040
|
||||
[ "$status" -eq 0 ]
|
||||
|
@ -203,7 +201,7 @@ EOF
|
|||
)
|
||||
echo $DATA > $BATS_TMPDIR/runc-update-integration-test.json
|
||||
|
||||
run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update -r $BATS_TMPDIR/runc-update-integration-test.json test_update
|
||||
run "$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
|
||||
|
|
Loading…
Reference in New Issue