Skip to content

Commit 21a635e

Browse files
committed
tests/int: add "--manage-cgroups-mode ignore" test
This test checks that the container is restored into a different cgroup. To do so, a user should - use --manage-cgroups-mode ignore on both checkpoint and restore; - change the cgroupsPath value in config.json before restoring. The test does some checks to ensure that its logic is correct, and that after the restore the old (original) cgroup does not exist, the new one exists, and the container's init is in that new cgroup. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent de3c43e commit 21a635e

File tree

2 files changed

+60
-11
lines changed

2 files changed

+60
-11
lines changed

tests/integration/checkpoint.bats

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,44 @@ function simple_cr() {
405405
# busybox should be back up and running
406406
testcontainer test_busybox running
407407
}
408+
409+
@test "checkpoint then restore into a different cgroup (via --manage-cgroups-mode ignore)" {
410+
set_resources_limit
411+
set_cgroups_path
412+
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
413+
[ "$status" -eq 0 ]
414+
testcontainer test_busybox running
415+
416+
local orig_path
417+
orig_path=$(get_cgroup_path "pids")
418+
# Check that the cgroup exists.
419+
test -d "$orig_path"
420+
421+
runc checkpoint --work-path ./work-dir --manage-cgroups-mode ignore test_busybox
422+
grep -B 5 Error ./work-dir/dump.log || true
423+
[ "$status" -eq 0 ]
424+
testcontainer test_busybox checkpointed
425+
# Check that the cgroup is gone.
426+
! test -d "$orig_path"
427+
428+
# Restore into a different cgroup.
429+
set_cgroups_path # Changes the path.
430+
runc restore -d --manage-cgroups-mode ignore --pid-file pid \
431+
--work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
432+
grep -B 5 Error ./work-dir/restore.log || true
433+
[ "$status" -eq 0 ]
434+
testcontainer test_busybox running
435+
436+
# Check that the old cgroup path doesn't exist.
437+
! test -d "$orig_path"
438+
439+
# Check that the new path exists.
440+
local new_path
441+
new_path=$(get_cgroup_path "pids")
442+
test -d "$new_path"
443+
444+
# Check that container's init is in the new cgroup.
445+
local pid
446+
pid=$(cat "pid")
447+
grep -q "${REL_CGROUPS_PATH}$" "/proc/$pid/cgroup"
448+
}

tests/integration/helpers.bash

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,27 @@ function set_cgroups_path() {
232232
update_config '.linux.cgroupsPath |= "'"${OCI_CGROUPS_PATH}"'"'
233233
}
234234

235-
# Get a value from a cgroup file.
236-
function get_cgroup_value() {
237-
local source=$1
238-
local cgroup var current
239-
235+
# Get a path to cgroup directory, based on controller name.
236+
# Parameters:
237+
# $1: controller name (like "pids") or a file name (like "pids.max").
238+
function get_cgroup_path() {
240239
if [ -v CGROUP_V2 ]; then
241-
cgroup=$CGROUP_PATH
242-
else
243-
var=${source%%.*} # controller name (e.g. memory)
244-
var=CGROUP_${var^^}_BASE_PATH # variable name (e.g. CGROUP_MEMORY_BASE_PATH)
245-
eval cgroup=\$"${var}${REL_CGROUPS_PATH}"
240+
echo "$CGROUP_PATH"
241+
return
246242
fi
247-
cat "$cgroup/$source"
243+
244+
local var cgroup
245+
var=${1%%.*} # controller name (e.g. memory)
246+
var=CGROUP_${var^^}_BASE_PATH # variable name (e.g. CGROUP_MEMORY_BASE_PATH)
247+
eval cgroup=\$"${var}${REL_CGROUPS_PATH}"
248+
echo "$cgroup"
249+
}
250+
251+
# Get a value from a cgroup file.
252+
function get_cgroup_value() {
253+
local cgroup
254+
cgroup="$(get_cgroup_path "$1")"
255+
cat "$cgroup/$1"
248256
}
249257

250258
# Helper to check a if value in a cgroup file matches the expected one.

0 commit comments

Comments
 (0)