mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
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 <kolyshkin@gmail.com>
This commit is contained in:
@@ -405,3 +405,44 @@ function simple_cr() {
|
||||
# busybox should be back up and running
|
||||
testcontainer test_busybox running
|
||||
}
|
||||
|
||||
@test "checkpoint then restore into a different cgroup (via --manage-cgroups-mode ignore)" {
|
||||
set_resources_limit
|
||||
set_cgroups_path
|
||||
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
|
||||
[ "$status" -eq 0 ]
|
||||
testcontainer test_busybox running
|
||||
|
||||
local orig_path
|
||||
orig_path=$(get_cgroup_path "pids")
|
||||
# Check that the cgroup exists.
|
||||
test -d "$orig_path"
|
||||
|
||||
runc checkpoint --work-path ./work-dir --manage-cgroups-mode ignore test_busybox
|
||||
grep -B 5 Error ./work-dir/dump.log || true
|
||||
[ "$status" -eq 0 ]
|
||||
testcontainer test_busybox checkpointed
|
||||
# Check that the cgroup is gone.
|
||||
! test -d "$orig_path"
|
||||
|
||||
# Restore into a different cgroup.
|
||||
set_cgroups_path # Changes the path.
|
||||
runc restore -d --manage-cgroups-mode ignore --pid-file pid \
|
||||
--work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
|
||||
grep -B 5 Error ./work-dir/restore.log || true
|
||||
[ "$status" -eq 0 ]
|
||||
testcontainer test_busybox running
|
||||
|
||||
# Check that the old cgroup path doesn't exist.
|
||||
! test -d "$orig_path"
|
||||
|
||||
# Check that the new path exists.
|
||||
local new_path
|
||||
new_path=$(get_cgroup_path "pids")
|
||||
test -d "$new_path"
|
||||
|
||||
# Check that container's init is in the new cgroup.
|
||||
local pid
|
||||
pid=$(cat "pid")
|
||||
grep -q "${REL_CGROUPS_PATH}$" "/proc/$pid/cgroup"
|
||||
}
|
||||
|
||||
@@ -232,19 +232,27 @@ function set_cgroups_path() {
|
||||
update_config '.linux.cgroupsPath |= "'"${OCI_CGROUPS_PATH}"'"'
|
||||
}
|
||||
|
||||
# Get a path to cgroup directory, based on controller name.
|
||||
# Parameters:
|
||||
# $1: controller name (like "pids") or a file name (like "pids.max").
|
||||
function get_cgroup_path() {
|
||||
if [ -v CGROUP_V2 ]; then
|
||||
echo "$CGROUP_PATH"
|
||||
return
|
||||
fi
|
||||
|
||||
local var cgroup
|
||||
var=${1%%.*} # controller name (e.g. memory)
|
||||
var=CGROUP_${var^^}_BASE_PATH # variable name (e.g. CGROUP_MEMORY_BASE_PATH)
|
||||
eval cgroup=\$"${var}${REL_CGROUPS_PATH}"
|
||||
echo "$cgroup"
|
||||
}
|
||||
|
||||
# Get a value from a cgroup file.
|
||||
function get_cgroup_value() {
|
||||
local source=$1
|
||||
local cgroup var current
|
||||
|
||||
if [ -v CGROUP_V2 ]; then
|
||||
cgroup=$CGROUP_PATH
|
||||
else
|
||||
var=${source%%.*} # controller name (e.g. memory)
|
||||
var=CGROUP_${var^^}_BASE_PATH # variable name (e.g. CGROUP_MEMORY_BASE_PATH)
|
||||
eval cgroup=\$"${var}${REL_CGROUPS_PATH}"
|
||||
fi
|
||||
cat "$cgroup/$source"
|
||||
local cgroup
|
||||
cgroup="$(get_cgroup_path "$1")"
|
||||
cat "$cgroup/$1"
|
||||
}
|
||||
|
||||
# Helper to check a if value in a cgroup file matches the expected one.
|
||||
|
||||
Reference in New Issue
Block a user