|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load helpers |
| 4 | + |
| 5 | +UPDATE_TEST_RUNC_ROOT="$BATS_TMPDIR/runc-update-integration-test" |
| 6 | + |
| 7 | +CGROUP_MEMORY="" |
| 8 | +CGROUP_CPUSET="" |
| 9 | +CGROUP_CPU="" |
| 10 | +CGROUP_BLKIO="" |
| 11 | + |
| 12 | +function init_cgroup_path() { |
| 13 | + for g in MEMORY CPUSET CPU BLKIO; do |
| 14 | + base_path=$(grep "rw," /proc/self/mountinfo | grep -i -m 1 "$g\$" | cut -d ' ' -f 5) |
| 15 | + eval CGROUP_${g}="${base_path}/runc-update-integration-test" |
| 16 | + done |
| 17 | +} |
| 18 | + |
| 19 | +function teardown() { |
| 20 | + rm -f $BATS_TMPDIR/runc-update-integration-test.json |
| 21 | + teardown_running_container_inroot test_update $UPDATE_TEST_RUNC_ROOT |
| 22 | + teardown_busybox |
| 23 | +} |
| 24 | + |
| 25 | +function setup() { |
| 26 | + teardown |
| 27 | + setup_busybox |
| 28 | + |
| 29 | + # Add cgroup path |
| 30 | + sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "runc-update-integration-test",/' ${BUSYBOX_BUNDLE}/config.json |
| 31 | + |
| 32 | + # Set some initial known values |
| 33 | + DATA=$(cat <<EOF |
| 34 | + "memory": { |
| 35 | + "limit": 33554432, |
| 36 | + "reservation": 25165824, |
| 37 | + "kernel": 16777216 |
| 38 | + }, |
| 39 | + "cpu": { |
| 40 | + "shares": 100, |
| 41 | + "quota": 500000, |
| 42 | + "period": 1000000, |
| 43 | + "cpus": "0" |
| 44 | + }, |
| 45 | + "blockio": { |
| 46 | + "blkioWeight": 1000 |
| 47 | + }, |
| 48 | +EOF |
| 49 | + ) |
| 50 | + DATA=$(echo ${DATA} | sed 's/\n/\\n/g') |
| 51 | + sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json |
| 52 | +} |
| 53 | + |
| 54 | +function check_cgroup_value() { |
| 55 | + cgroup=$1 |
| 56 | + source=$2 |
| 57 | + expected=$3 |
| 58 | + |
| 59 | + current=$(cat $cgroup/$source) |
| 60 | + [ "$current" -eq "$expected" ] |
| 61 | +} |
| 62 | + |
| 63 | +@test "update" { |
| 64 | + # start a few busyboxes detached |
| 65 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT start -d --console /dev/pts/ptmx test_update |
| 66 | + [ "$status" -eq 0 ] |
| 67 | + wait_for_container_inroot 15 1 test_update $UPDATE_TEST_RUNC_ROOT |
| 68 | + |
| 69 | + init_cgroup_path |
| 70 | + |
| 71 | + # check that initial values were properly set |
| 72 | + check_cgroup_value $CGROUP_BLKIO "blkio.weight" 1000 |
| 73 | + check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 1000000 |
| 74 | + check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 500000 |
| 75 | + check_cgroup_value $CGROUP_CPU "cpu.shares" 100 |
| 76 | + check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 0 |
| 77 | + check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 16777216 |
| 78 | + check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 33554432 |
| 79 | + check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824 |
| 80 | + |
| 81 | + # update blkio-weight |
| 82 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --blkio-weight 500 |
| 83 | + [ "$status" -eq 0 ] |
| 84 | + check_cgroup_value $CGROUP_BLKIO "blkio.weight" 500 |
| 85 | + |
| 86 | + # update cpu-period |
| 87 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --cpu-period 900000 |
| 88 | + [ "$status" -eq 0 ] |
| 89 | + check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 900000 |
| 90 | + |
| 91 | + # update cpu-quota |
| 92 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --cpu-quota 600000 |
| 93 | + [ "$status" -eq 0 ] |
| 94 | + check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 600000 |
| 95 | + |
| 96 | + # update cpu-shares |
| 97 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --cpu-share 200 |
| 98 | + [ "$status" -eq 0 ] |
| 99 | + check_cgroup_value $CGROUP_CPU "cpu.shares" 200 |
| 100 | + |
| 101 | + # update cpuset if supported (i.e. we're running on a multicore cpu) |
| 102 | + cpu_count=$(grep '^processor' /proc/cpuinfo | wc -l) |
| 103 | + if [ $cpu_count -ge 1 ]; then |
| 104 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --cpuset-cpus "1" |
| 105 | + [ "$status" -eq 0 ] |
| 106 | + check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 1 |
| 107 | + fi |
| 108 | + |
| 109 | + # update memory limit |
| 110 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --memory 67108864 |
| 111 | + [ "$status" -eq 0 ] |
| 112 | + check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 67108864 |
| 113 | + |
| 114 | + # update memory soft limit |
| 115 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --memory-reservation 33554432 |
| 116 | + [ "$status" -eq 0 ] |
| 117 | + check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 33554432 |
| 118 | + |
| 119 | + # update memory swap (if available) |
| 120 | + if [ -f "$CGROUP_MEMORY/memory.memsw.limit_in_bytes" ]; then |
| 121 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --memory-swap 96468992 |
| 122 | + [ "$status" -eq 0 ] |
| 123 | + check_cgroup_value $CGROUP_MEMORY "memory.memsw.limit_in_bytes" 96468992 |
| 124 | + fi |
| 125 | + |
| 126 | + # update kernel memory limit |
| 127 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --kernel-memory 50331648 |
| 128 | + [ "$status" -eq 0 ] |
| 129 | + check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648 |
| 130 | + |
| 131 | + # Revert to the test initial value via json on stding |
| 132 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update -r - test_update <<EOF |
| 133 | +{ |
| 134 | + "memory": { |
| 135 | + "limit": 33554432, |
| 136 | + "reservation": 25165824, |
| 137 | + "kernel": 16777216 |
| 138 | + }, |
| 139 | + "cpu": { |
| 140 | + "shares": 100, |
| 141 | + "quota": 500000, |
| 142 | + "period": 1000000, |
| 143 | + "cpus": "0" |
| 144 | + }, |
| 145 | + "blockIO": { |
| 146 | + "blkioWeight": 1000 |
| 147 | + } |
| 148 | +} |
| 149 | +EOF |
| 150 | + [ "$status" -eq 0 ] |
| 151 | + check_cgroup_value $CGROUP_BLKIO "blkio.weight" 1000 |
| 152 | + check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 1000000 |
| 153 | + check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 500000 |
| 154 | + check_cgroup_value $CGROUP_CPU "cpu.shares" 100 |
| 155 | + check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 0 |
| 156 | + check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 16777216 |
| 157 | + check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 33554432 |
| 158 | + check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824 |
| 159 | + |
| 160 | + # redo all the changes at once |
| 161 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update test_update --blkio-weight 500 \ |
| 162 | + --cpu-period 900000 --cpu-quota 600000 --cpu-share 200 --memory 67108864 \ |
| 163 | + --memory-reservation 33554432 --kernel-memory 50331648 |
| 164 | + [ "$status" -eq 0 ] |
| 165 | + check_cgroup_value $CGROUP_BLKIO "blkio.weight" 500 |
| 166 | + check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 900000 |
| 167 | + check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 600000 |
| 168 | + check_cgroup_value $CGROUP_CPU "cpu.shares" 200 |
| 169 | + check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648 |
| 170 | + check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 67108864 |
| 171 | + check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 33554432 |
| 172 | + |
| 173 | + # reset to initial test value via json file |
| 174 | + DATA=$(cat <<"EOF" |
| 175 | +{ |
| 176 | + "memory": { |
| 177 | + "limit": 33554432, |
| 178 | + "reservation": 25165824, |
| 179 | + "kernel": 16777216 |
| 180 | + }, |
| 181 | + "cpu": { |
| 182 | + "shares": 100, |
| 183 | + "quota": 500000, |
| 184 | + "period": 1000000, |
| 185 | + "cpus": "0" |
| 186 | + }, |
| 187 | + "blockIO": { |
| 188 | + "blkioWeight": 1000 |
| 189 | + } |
| 190 | +} |
| 191 | +EOF |
| 192 | +) |
| 193 | + echo $DATA > $BATS_TMPDIR/runc-update-integration-test.json |
| 194 | + |
| 195 | + run "$RUNC" --root $UPDATE_TEST_RUNC_ROOT update -r $BATS_TMPDIR/runc-update-integration-test.json test_update |
| 196 | + [ "$status" -eq 0 ] |
| 197 | + check_cgroup_value $CGROUP_BLKIO "blkio.weight" 1000 |
| 198 | + check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 1000000 |
| 199 | + check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 500000 |
| 200 | + check_cgroup_value $CGROUP_CPU "cpu.shares" 100 |
| 201 | + check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 0 |
| 202 | + check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 16777216 |
| 203 | + check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 33554432 |
| 204 | + check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824 |
| 205 | +} |
0 commit comments