Skip to content

Commit

Permalink
Merge pull request #4085 from kolyshkin/fix-check_cgroup_value
Browse files Browse the repository at this point in the history
CI fixes
  • Loading branch information
kolyshkin authored Oct 24, 2023
2 parents 37ad02b + 7f5daa8 commit 3272edf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion libcontainer/cgroups/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (m *Manager) Set(r *configs.Resources) error {
if path == "" {
// We never created a path for this cgroup, so we cannot set
// limits for it (though we have already tried at this point).
return fmt.Errorf("cannot set %s limit: container could not join or create cgroup, and the error is %w", sys.Name(), err)
return fmt.Errorf("cannot set %s limit: container could not join or create cgroup", sys.Name())
}
return err
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cgroups.bats
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ convert_hugetlb_size() {
[ "$status" -eq 0 ]

lim="max"
[ -v CGROUP_V1 ] && lim=".limit_in_bytes"
[ -v CGROUP_V1 ] && lim="limit_in_bytes"

optional=("")
# Add rsvd, if available.
Expand Down
22 changes: 16 additions & 6 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,11 @@ function get_cgroup_value() {
# Helper to check a if value in a cgroup file matches the expected one.
function check_cgroup_value() {
local current
local cgroup
cgroup="$(get_cgroup_path "$1")"
if [ ! -f "$cgroup/$1" ]; then
skip "$cgroup/$1 does not exist"
fi
current="$(get_cgroup_value "$1")"
local expected=$2

echo "current $current !? $expected"
[ "$current" = "$expected" ] || [ "$current" = "$((expected / 1000))" ]
[ "$current" = "$expected" ]
}

# Helper to check a value in systemd.
Expand Down Expand Up @@ -318,6 +313,7 @@ function check_cpu_quota() {
function check_cpu_burst() {
local burst=$1
if [ -v CGROUP_V2 ]; then
burst=$((burst / 1000))
check_cgroup_value "cpu.max.burst" "$burst"
else
check_cgroup_value "cpu.cfs_burst_us" "$burst"
Expand Down Expand Up @@ -438,6 +434,20 @@ function requires() {
skip_me=1
fi
;;
cgroups_cpu_burst)
local p f
init_cgroup_paths
if [ -v CGROUP_V1 ]; then
p="$CGROUP_CPU_BASE_PATH"
f="cpu.cfs_burst_us"
elif [ -v CGROUP_V2 ]; then
p="$CGROUP_BASE_PATH"
f="cpu.max.burst"
fi
if [ -z "$(find "$p" -name "$f" -print -quit)" ]; then
skip_me=1
fi
;;
cgroupns)
if [ ! -e "/proc/self/ns/cgroup" ]; then
skip_me=1
Expand Down
23 changes: 17 additions & 6 deletions tests/integration/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,6 @@ EOF
runc update test_update --cpu-share 200
[ "$status" -eq 0 ]
check_cpu_shares 200
runc update test_update --cpu-period 900000 --cpu-burst 500000
[ "$status" -eq 0 ]
check_cpu_burst 500000
runc update test_update --cpu-period 900000 --cpu-burst 0
[ "$status" -eq 0 ]
check_cpu_burst 0

# Revert to the test initial value via json on stding
runc update -r - test_update <<EOF
Expand Down Expand Up @@ -338,6 +332,23 @@ EOF
check_cpu_shares 100
}

@test "cpu burst" {
[ $EUID -ne 0 ] && requires rootless_cgroup
requires cgroups_cpu_burst

runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]
check_cpu_burst 0

runc update test_update --cpu-period 900000 --cpu-burst 500000
[ "$status" -eq 0 ]
check_cpu_burst 500000

runc update test_update --cpu-period 900000 --cpu-burst 0
[ "$status" -eq 0 ]
check_cpu_burst 0
}

@test "set cpu period with no quota" {
[ $EUID -ne 0 ] && requires rootless_cgroup

Expand Down

0 comments on commit 3272edf

Please sign in to comment.