diff --git a/tests/integration/checkpoint.bats b/tests/integration/checkpoint.bats index 615ef8cb6..fe351e747 100644 --- a/tests/integration/checkpoint.bats +++ b/tests/integration/checkpoint.bats @@ -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" +} diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index a9b70ffd8..f07996450 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -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.