Merge pull request #2757 from kolyshkin/test-int-cleanups

tests/int: cleanups
This commit is contained in:
Kir Kolyshkin
2021-02-23 20:50:17 -08:00
committed by GitHub
29 changed files with 180 additions and 264 deletions
+1 -4
View File
@@ -61,15 +61,12 @@ load helpers
# setup is called at the beginning of every test.
function setup() {
# see functions teardown_hello and setup_hello in helpers.bash, used to
# create a pristine environment for running your tests
teardown_hello
setup_hello
}
# teardown is called at the end of every test.
function teardown() {
teardown_hello
teardown_bundle
}
@test "this is a simple test" {
+19 -24
View File
@@ -3,15 +3,10 @@
load helpers
function teardown() {
teardown_running_container test_cgroups_kmem
teardown_running_container test_cgroups_permissions
teardown_running_container test_cgroups_group
teardown_running_container test_cgroups_unified
teardown_busybox
teardown_bundle
}
function setup() {
teardown
setup_busybox
}
@@ -19,10 +14,10 @@ function setup() {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
requires cgroups_kmem
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path
# Set some initial known values
update_config '.linux.resources.memory |= {"kernel": 16777216, "kernelTCP": 11534336}' "${BUSYBOX_BUNDLE}"
update_config '.linux.resources.memory |= {"kernel": 16777216, "kernelTCP": 11534336}'
# run a detached busybox to work with
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_kmem
@@ -46,7 +41,7 @@ function setup() {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
requires cgroups_kmem
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path
# run a detached busybox to work with
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_kmem
@@ -75,7 +70,7 @@ function setup() {
# systemd controls the permission, so error does not happen
requires no_systemd
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 1 ]
@@ -88,7 +83,7 @@ function setup() {
# systemd controls the permission, so error does not happen
requires no_systemd
set_resources_limit "$BUSYBOX_BUNDLE"
set_resources_limit
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 1 ]
@@ -98,8 +93,8 @@ function setup() {
@test "runc create (limits + cgrouppath + permission on the cgroup dir) succeeds" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
set_cgroups_path "$BUSYBOX_BUNDLE"
set_resources_limit "$BUSYBOX_BUNDLE"
set_cgroups_path
set_resources_limit
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 0 ]
@@ -120,8 +115,8 @@ function setup() {
@test "runc exec (limits + cgrouppath + permission on the cgroup dir) succeeds" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
set_cgroups_path "$BUSYBOX_BUNDLE"
set_resources_limit "$BUSYBOX_BUNDLE"
set_cgroups_path
set_resources_limit
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_permissions
[ "$status" -eq 0 ]
@@ -134,8 +129,8 @@ function setup() {
@test "runc exec (cgroup v2 + init process in non-root cgroup) succeeds" {
requires root cgroups_v2
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroup_mount_writable "$BUSYBOX_BUNDLE"
set_cgroups_path
set_cgroup_mount_writable
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_group
[ "$status" -eq 0 ]
@@ -181,9 +176,9 @@ function setup() {
@test "runc run (cgroup v1 + unified resources should fail)" {
requires root cgroups_v1
set_cgroups_path "$BUSYBOX_BUNDLE"
set_resources_limit "$BUSYBOX_BUNDLE"
update_config '.linux.resources.unified |= {"memory.min": "131072"}' "$BUSYBOX_BUNDLE"
set_cgroups_path
set_resources_limit
update_config '.linux.resources.unified |= {"memory.min": "131072"}'
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
[ "$status" -ne 0 ]
@@ -193,7 +188,7 @@ function setup() {
@test "runc run (cgroup v2 resources.unified only)" {
requires root cgroups_v2
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path
update_config ' .linux.resources.unified |= {
"memory.min": "131072",
"memory.low": "524288",
@@ -203,7 +198,7 @@ function setup() {
"pids.max": "99",
"cpu.max": "10000 100000",
"cpu.weight": "42"
}' "$BUSYBOX_BUNDLE"
}'
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
[ "$status" -eq 0 ]
@@ -233,7 +228,7 @@ function setup() {
@test "runc run (cgroup v2 resources.unified override)" {
requires root cgroups_v2
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path
# CPU shares of 3333 corresponds to CPU weight of 128.
update_config ' .linux.resources.memory |= {"limit": 33554432}
| .linux.resources.memorySwap |= {"limit": 33554432}
@@ -248,7 +243,7 @@ function setup() {
"pids.max": "42",
"cpu.max": "5000 50000",
"cpu.weight": "42"
}' "$BUSYBOX_BUNDLE"
}'
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
[ "$status" -eq 0 ]
+1 -3
View File
@@ -6,13 +6,11 @@ function setup() {
# XXX: currently criu require root containers.
requires criu root
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_running_container test_busybox_restore
teardown_bundle
}
function setup_pipes() {
+3 -3
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "runc create" {
@@ -61,11 +60,12 @@ function teardown() {
}
@test "runc create --pid-file with new CWD" {
bundle="$(pwd)"
# create pid_file directory as the CWD
mkdir pid_file
cd pid_file
runc create --pid-file pid.txt -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
runc create --pid-file pid.txt -b "$bundle" --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]
testcontainer test_busybox created
+1 -2
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
# Test case for https://github.com/opencontainers/runc/pull/2086
+1 -2
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_hello
setup_hello
}
function teardown() {
teardown_hello
teardown_bundle
}
@test "global --debug" {
+6 -8
View File
@@ -3,13 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_running_container testbusyboxdelete
teardown_bundle
}
@test "runc delete" {
@@ -20,7 +18,7 @@ function teardown() {
runc kill testbusyboxdelete KILL
[ "$status" -eq 0 ]
retry 10 1 eval "__runc state testbusyboxdelete | grep -q 'stopped'"
wait_for_container 10 1 testbusyboxdelete stopped
runc delete testbusyboxdelete
[ "$status" -eq 0 ]
@@ -54,8 +52,8 @@ function teardown() {
@test "runc delete --force in cgroupv1 with subcgroups" {
requires cgroups_v1 root cgroupns
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroup_mount_writable "$BUSYBOX_BUNDLE"
set_cgroups_path
set_cgroup_mount_writable
# enable cgroupns
update_config '.linux.namespaces += [{"type": "cgroup"}]'
@@ -104,8 +102,8 @@ EOF
@test "runc delete --force in cgroupv2 with subcgroups" {
requires cgroups_v2 root
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroup_mount_writable "$BUSYBOX_BUNDLE"
set_cgroups_path
set_cgroup_mount_writable
# run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
+1 -3
View File
@@ -3,13 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_running_container test_dev
teardown_bundle
}
@test "runc run [redundant default /dev/tty]" {
+6 -7
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "events --stats" {
@@ -47,8 +46,8 @@ function test_events() {
# 2. Waits for an event that includes test_busybox then kills the
# test_busybox container which causes the event logger to exit.
(
retry 10 "$retry_every" eval "grep -q 'test_busybox' events.log"
teardown_running_container test_busybox
retry 10 "$retry_every" grep -q test_busybox events.log
__runc delete -f test_busybox
) &
wait # for both subshells to finish
@@ -77,7 +76,7 @@ function test_events() {
init_cgroup_paths
# we need the container to hit OOM, so disable swap
update_config '(.. | select(.resources? != null)) .resources.memory |= {"limit": 33554432, "swap": 33554432}' "${BUSYBOX_BUNDLE}"
update_config '(.. | select(.resources? != null)) .resources.memory |= {"limit": 33554432, "swap": 33554432}'
# run busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
@@ -89,10 +88,10 @@ function test_events() {
# and waits for an oom event
(__runc events test_busybox >events.log) &
(
retry 10 1 eval "grep -q 'test_busybox' events.log"
retry 10 1 grep -q test_busybox events.log
# shellcheck disable=SC2016
__runc exec -d test_busybox sh -c 'test=$(dd if=/dev/urandom ibs=5120k)'
retry 10 1 eval "grep -q 'oom' events.log"
retry 10 1 grep -q oom events.log
__runc delete -f test_busybox
) &
wait # wait for the above sub shells to finish
+3 -3
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "runc exec" {
@@ -41,12 +40,13 @@ function teardown() {
}
@test "runc exec --pid-file with new CWD" {
bundle="$(pwd)"
# create pid_file directory as the CWD
mkdir pid_file
cd pid_file
# run busybox detached
runc run -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
runc run -d -b "$bundle" --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]
runc exec --pid-file pid.txt test_busybox echo Hello from exec
+48 -93
View File
@@ -1,5 +1,11 @@
#!/bin/bash
# bats-core v1.2.1 defines BATS_RUN_TMPDIR
if [ -z "$BATS_RUN_TMPDIR" ]; then
echo "bats >= v1.2.1 is required. Aborting." >&2
exit 1
fi
# Root directory of integration tests.
INTEGRATION_ROOT=$(dirname "$(readlink -f "$BASH_SOURCE")")
@@ -14,11 +20,6 @@ RECVTTY="${INTEGRATION_ROOT}/../../contrib/cmd/recvtty/recvtty"
# Test data path.
TESTDATA="${INTEGRATION_ROOT}/testdata"
# Destinations for test containers.
BUSYBOX_BUNDLE="$BATS_TMPDIR/busyboxtest"
HELLO_BUNDLE="$BATS_TMPDIR/hello-world"
DEBIAN_BUNDLE="$BATS_TMPDIR/debiantest"
# CRIU PATH
CRIU="$(which criu 2>/dev/null || true)"
@@ -28,12 +29,6 @@ KERNEL_MAJOR="${KERNEL_VERSION%%.*}"
KERNEL_MINOR="${KERNEL_VERSION#$KERNEL_MAJOR.}"
KERNEL_MINOR="${KERNEL_MINOR%%.*}"
# Root state path.
ROOT=$(mktemp -d "$BATS_TMPDIR/runc.XXXXXX")
# Path to console socket.
CONSOLE_SOCKET="$BATS_TMPDIR/console.sock"
# Check if we're in rootless mode.
ROOTLESS=$(id -u)
@@ -49,7 +44,7 @@ function runc() {
# Raw wrapper for runc.
function __runc() {
"$RUNC" ${RUNC_USE_SYSTEMD+--systemd-cgroup} --root "$ROOT" "$@"
"$RUNC" ${RUNC_USE_SYSTEMD+--systemd-cgroup} --root "$ROOT/state" "$@"
}
# Wrapper for runc spec, which takes only one argument (the bundle path).
@@ -117,18 +112,19 @@ function init_cgroup_paths() {
# init once
test -n "$CGROUP_UNIFIED" && return
local rnd="$RANDOM"
if [ -n "${RUNC_USE_SYSTEMD}" ]; then
SD_UNIT_NAME="runc-cgroups-integration-test.scope"
SD_UNIT_NAME="runc-cgroups-integration-test-${rnd}.scope"
if [ $(id -u) = "0" ]; then
REL_CGROUPS_PATH="/machine.slice/$SD_UNIT_NAME"
OCI_CGROUPS_PATH="machine.slice:runc-cgroups:integration-test"
OCI_CGROUPS_PATH="machine.slice:runc-cgroups:integration-test-${rnd}"
else
REL_CGROUPS_PATH="/user.slice/user-$(id -u).slice/user@$(id -u).service/machine.slice/$SD_UNIT_NAME"
# OCI path doesn't contain "/user.slice/user-$(id -u).slice/user@$(id -u).service/" prefix
OCI_CGROUPS_PATH="machine.slice:runc-cgroups:integration-test"
OCI_CGROUPS_PATH="machine.slice:runc-cgroups:integration-test-${rnd}"
fi
else
REL_CGROUPS_PATH="/runc-cgroups-integration-test/test-cgroup"
REL_CGROUPS_PATH="/runc-cgroups-integration-test/test-cgroup-${rnd}"
OCI_CGROUPS_PATH=$REL_CGROUPS_PATH
fi
@@ -400,48 +396,14 @@ function retry() {
# retry until the given container has state
function wait_for_container() {
local attempts=$1
local delay=$2
local cid=$3
# optionally wait for a specific status
local wait_for_status="${4:-}"
local i
for ((i = 0; i < attempts; i++)); do
runc state $cid
if [[ "$status" -eq 0 ]]; then
if [[ "${output}" == *"${wait_for_status}"* ]]; then
return 0
fi
fi
sleep $delay
done
echo "runc state failed to return state $statecheck $attempts times. Output: $output"
false
}
# retry until the given container has state
function wait_for_container_inroot() {
local attempts=$1
local delay=$2
local cid=$3
# optionally wait for a specific status
local wait_for_status="${4:-}"
local i
for ((i = 0; i < attempts; i++)); do
ROOT=$4 runc state $cid
if [[ "$status" -eq 0 ]]; then
if [[ "${output}" == *"${wait_for_status}"* ]]; then
return 0
fi
fi
sleep $delay
done
echo "runc state failed to return state $statecheck $attempts times. Output: $output"
false
if [ $# -eq 3 ]; then
retry "$1" "$2" __runc state "$3"
elif [ $# -eq 4 ]; then
retry "$1" "$2" eval "__runc state $3 | grep -qw $4"
else
echo "Usage: wait_for_container ATTEMPTS DELAY ID [STATUS]" 1>&2
return 1
fi
}
function testcontainer() {
@@ -456,28 +418,38 @@ function testcontainer() {
}
function setup_recvtty() {
[ -z "$ROOT" ] && return 1 # must not be called without ROOT set
local dir="$ROOT/tty"
mkdir $dir
export CONSOLE_SOCKET="$dir/sock"
# We need to start recvtty in the background, so we double fork in the shell.
("$RECVTTY" --pid-file "$BATS_TMPDIR/recvtty.pid" --mode null "$CONSOLE_SOCKET" &) &
("$RECVTTY" --pid-file "$dir/pid" --mode null "$CONSOLE_SOCKET" &) &
}
function teardown_recvtty() {
[ -z "$ROOT" ] && return 0 # nothing to teardown
local dir="$ROOT/tty"
# When we kill recvtty, the container will also be killed.
if [ -f "$BATS_TMPDIR/recvtty.pid" ]; then
kill -9 $(cat "$BATS_TMPDIR/recvtty.pid")
if [ -f "$dir/pid" ]; then
kill -9 $(cat "$dir/pid")
fi
# Clean up the files that might be left over.
rm -f "$BATS_TMPDIR/recvtty.pid"
rm -f "$CONSOLE_SOCKET"
rm -rf "$dir"
}
function setup_bundle() {
local image="$1"
local bundle="$2"
# Root for various container directories (state, tty, bundle).
export ROOT=$(mktemp -d "$BATS_RUN_TMPDIR/runc.XXXXXX")
mkdir -p "$ROOT/state" "$ROOT/bundle/rootfs"
setup_recvtty
mkdir -p "$bundle"/rootfs
cd "$bundle"
cd "$ROOT/bundle"
tar --exclude './dev/*' -C rootfs -xf "$image"
@@ -485,43 +457,26 @@ function setup_bundle() {
}
function setup_busybox() {
setup_bundle "$BUSYBOX_IMAGE" "$BUSYBOX_BUNDLE"
setup_bundle "$BUSYBOX_IMAGE"
}
function setup_hello() {
setup_bundle "$HELLO_IMAGE" "$HELLO_BUNDLE"
setup_bundle "$HELLO_IMAGE"
update_config '(.. | select(.? == "sh")) |= "/hello"'
}
function setup_debian() {
setup_bundle "$DEBIAN_IMAGE" "$DEBIAN_BUNDLE"
setup_bundle "$DEBIAN_IMAGE"
}
function teardown_running_container() {
__runc delete -f "$1"
}
function teardown_bundle() {
[ -z "$ROOT" ] && return 0 # nothing to teardown
function teardown_running_container_inroot() {
ROOT="$2" __runc delete -f "$1"
}
function teardown_busybox() {
cd "$INTEGRATION_ROOT"
teardown_recvtty
teardown_running_container test_busybox
rm -f -r "$BUSYBOX_BUNDLE"
}
function teardown_hello() {
cd "$INTEGRATION_ROOT"
teardown_recvtty
teardown_running_container test_hello
rm -f -r "$HELLO_BUNDLE"
}
function teardown_debian() {
cd "$INTEGRATION_ROOT"
teardown_recvtty
teardown_running_container test_debian
rm -f -r "$DEBIAN_BUNDLE"
local ct
for ct in $(__runc list -q); do
__runc delete -f "$ct"
done
rm -rf "$ROOT"
}
+14 -19
View File
@@ -2,28 +2,23 @@
load helpers
# CR = CreateRuntime
# CC = CreataContainer
HOOKLIBCR=librunc-hooks-create-runtime.so
HOOKLIBCC=librunc-hooks-create-container.so
LIBPATH="$DEBIAN_BUNDLE/rootfs/lib/"
function setup() {
umount "$LIBPATH"/$HOOKLIBCR.1.0.0 &>/dev/null || true
umount "$LIBPATH"/$HOOKLIBCC.1.0.0 &>/dev/null || true
requires root no_systemd
teardown_debian
setup_debian
# CR = CreateRuntime, CC = CreataContainer
HOOKLIBCR=librunc-hooks-create-runtime.so
HOOKLIBCC=librunc-hooks-create-container.so
LIBPATH="$(pwd)/rootfs/lib/"
}
function teardown() {
umount "$LIBPATH"/$HOOKLIBCR.1.0.0 &>/dev/null || true
umount "$LIBPATH"/$HOOKLIBCC.1.0.0 &>/dev/null || true
rm -f $HOOKLIBCR.1.0.0 $HOOKLIBCC.1.0.0
teardown_debian
if [ -n "$LIBPATH" ]; then
umount "$LIBPATH"/$HOOKLIBCR.1.0.0 &>/dev/null || true
umount "$LIBPATH"/$HOOKLIBCC.1.0.0 &>/dev/null || true
rm -f $HOOKLIBCR.1.0.0 $HOOKLIBCC.1.0.0
fi
teardown_bundle
}
@test "runc run (hooks library tests)" {
@@ -31,25 +26,25 @@ function teardown() {
gcc -shared -Wl,-soname,librunc-hooks-create-runtime.so.1 -o "$HOOKLIBCR.1.0.0"
gcc -shared -Wl,-soname,librunc-hooks-create-container.so.1 -o "$HOOKLIBCC.1.0.0"
current_pwd="$(pwd)"
bundle=$(pwd)
# To mount $HOOKLIBCR we need to do that in the container namespace
create_runtime_hook=$(
cat <<-EOF
pid=\$(cat - | jq -r '.pid')
touch "$LIBPATH/$HOOKLIBCR.1.0.0"
nsenter -m \$ns -t \$pid mount --bind "$current_pwd/$HOOKLIBCR.1.0.0" "$LIBPATH/$HOOKLIBCR.1.0.0"
nsenter -m \$ns -t \$pid mount --bind "$bundle/$HOOKLIBCR.1.0.0" "$LIBPATH/$HOOKLIBCR.1.0.0"
EOF
)
create_container_hook="touch ./lib/$HOOKLIBCC.1.0.0 && mount --bind $current_pwd/$HOOKLIBCC.1.0.0 ./lib/$HOOKLIBCC.1.0.0"
create_container_hook="touch ./lib/$HOOKLIBCC.1.0.0 && mount --bind $bundle/$HOOKLIBCC.1.0.0 ./lib/$HOOKLIBCC.1.0.0"
CONFIG=$(jq --arg create_runtime_hook "$create_runtime_hook" --arg create_container_hook "$create_container_hook" '
.hooks |= . + {"createRuntime": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", $create_runtime_hook]}]} |
.hooks |= . + {"createContainer": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", $create_container_hook]}]} |
.hooks |= . + {"startContainer": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", "ldconfig"]}]} |
.root.readonly |= false |
.process.args = ["/bin/sh", "-c", "ldconfig -p | grep librunc"]' "$DEBIAN_BUNDLE"/config.json)
.process.args = ["/bin/sh", "-c", "ldconfig -p | grep librunc"]' "$bundle"/config.json)
echo "${CONFIG}" >config.json
runc run test_debian
+2 -4
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "kill detached busybox" {
@@ -21,8 +20,7 @@ function teardown() {
runc kill test_busybox KILL
[ "$status" -eq 0 ]
retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'"
wait_for_container 10 1 test_busybox stopped
# we should ensure kill work after the container stopped
runc kill -a test_busybox 0
+23 -24
View File
@@ -3,54 +3,53 @@
load helpers
function setup() {
teardown_running_container_inroot test_box1 "$HELLO_BUNDLE"
teardown_running_container_inroot test_box2 "$HELLO_BUNDLE"
teardown_running_container_inroot test_box3 "$HELLO_BUNDLE"
teardown_busybox
setup_busybox
ALT_ROOT="$ROOT/alt"
mkdir -p "$ALT_ROOT/state"
}
function teardown() {
teardown_running_container_inroot test_box1 "$HELLO_BUNDLE"
teardown_running_container_inroot test_box2 "$HELLO_BUNDLE"
teardown_running_container_inroot test_box3 "$HELLO_BUNDLE"
teardown_busybox
if [ -n "$ALT_ROOT" ]; then
ROOT="$ALT_ROOT" teardown_bundle
fi
teardown_bundle
}
@test "list" {
bundle=$(pwd)
# run a few busyboxes detached
ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_box1
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box1
[ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_box2
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box2
[ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_box3
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box3
[ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE runc list
ROOT=$ALT_ROOT runc list
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]]
[[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$bundle*[0-9]* ]]
[[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$bundle*[0-9]* ]]
[[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$bundle*[0-9]* ]]
ROOT=$HELLO_BUNDLE runc list -q
ROOT=$ALT_ROOT runc list -q
[ "$status" -eq 0 ]
[[ "${lines[0]}" == "test_box1" ]]
[[ "${lines[1]}" == "test_box2" ]]
[[ "${lines[2]}" == "test_box3" ]]
ROOT=$HELLO_BUNDLE runc list --format table
ROOT=$ALT_ROOT runc list --format table
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]]
[[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$bundle*[0-9]* ]]
[[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$bundle*[0-9]* ]]
[[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$bundle*[0-9]* ]]
ROOT=$HELLO_BUNDLE runc list --format json
ROOT=$ALT_ROOT runc list --format json
[ "$status" -eq 0 ]
[[ "${lines[0]}" == [\[][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box1\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box3\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}][\]] ]]
[[ "${lines[0]}" == [\[][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box1\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$bundle*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$bundle*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box3\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$bundle*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}][\]] ]]
}
+1 -2
View File
@@ -3,7 +3,6 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
# Create fake rootfs.
@@ -15,7 +14,7 @@ function setup() {
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "mask paths [file]" {
+1 -2
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "runc run [bind mount]" {
+1 -2
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "runc run --no-pivot must not expose bare /proc" {
+3 -4
View File
@@ -3,18 +3,17 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "runc pause and resume" {
if [[ "$ROOTLESS" -ne 0 ]]; then
requires rootless_cgroup
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path
fi
requires cgroups_freezer
@@ -42,7 +41,7 @@ function teardown() {
@test "runc pause and resume with nonexist container" {
if [[ "$ROOTLESS" -ne 0 ]]; then
requires rootless_cgroup
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path
fi
requires cgroups_freezer
+3 -5
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "ps" {
@@ -64,7 +63,7 @@ function teardown() {
@test "ps after the container stopped" {
# ps requires cgroups
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path
# start busybox detached
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
@@ -78,8 +77,7 @@ function teardown() {
runc kill test_busybox KILL
[ "$status" -eq 0 ]
retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'"
wait_for_container 10 1 test_busybox stopped
runc ps test_busybox
[ "$status" -eq 0 ]
+15 -12
View File
@@ -3,19 +3,22 @@
load helpers
function setup() {
teardown_running_container_inroot test_dotbox "$HELLO_BUNDLE"
teardown_busybox
setup_busybox
ALT_ROOT="$ROOT/alt"
mkdir -p "$ALT_ROOT/state"
}
function teardown() {
teardown_running_container_inroot test_dotbox "$HELLO_BUNDLE"
teardown_busybox
if [ -n "$ALT_ROOT" ]; then
ROOT=$ALT_ROOT __runc delete -f test_dotbox
rm -rf "$ALT_ROOT"
fi
teardown_bundle
}
@test "global --root" {
# run busybox detached using $HELLO_BUNDLE for state
ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_dotbox
# run busybox detached using $ALT_ROOT for state
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_dotbox
[ "$status" -eq 0 ]
# run busybox detached in default root
@@ -26,11 +29,11 @@ function teardown() {
[ "$status" -eq 0 ]
[[ "${output}" == *"running"* ]]
ROOT=$HELLO_BUNDLE runc state test_dotbox
ROOT=$ALT_ROOT runc state test_dotbox
[ "$status" -eq 0 ]
[[ "${output}" == *"running"* ]]
ROOT=$HELLO_BUNDLE runc state test_busybox
ROOT=$ALT_ROOT runc state test_busybox
[ "$status" -ne 0 ]
runc state test_dotbox
@@ -38,13 +41,13 @@ function teardown() {
runc kill test_busybox KILL
[ "$status" -eq 0 ]
retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'"
wait_for_container 10 1 test_busybox stopped
runc delete test_busybox
[ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE runc kill test_dotbox KILL
ROOT=$ALT_ROOT runc kill test_dotbox KILL
[ "$status" -eq 0 ]
retry 10 1 eval "ROOT='$HELLO_BUNDLE' __runc state test_dotbox | grep -q 'stopped'"
ROOT=$HELLO_BUNDLE runc delete test_dotbox
ROOT=$ALT_ROOT wait_for_container 10 1 test_dotbox stopped
ROOT=$ALT_ROOT runc delete test_dotbox
[ "$status" -eq 0 ]
}
+1 -2
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "runc run [seccomp -ENOSYS handling]" {
+2 -2
View File
@@ -7,7 +7,7 @@ function setup() {
}
function teardown() {
teardown_hello
teardown_bundle
}
@test "spec generation cwd" {
@@ -16,7 +16,7 @@ function teardown() {
}
@test "spec generation --bundle" {
runc run --bundle "$HELLO_BUNDLE" test_hello
runc run --bundle "$(pwd)" test_hello
[ "$status" -eq 0 ]
}
+1 -2
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "runc start" {
+3 -3
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "runc run detached" {
@@ -52,12 +51,13 @@ function teardown() {
}
@test "runc run detached --pid-file with new CWD" {
bundle="$(pwd)"
# create pid_file directory as the CWD
mkdir pid_file
cd pid_file
# run busybox detached
runc run --pid-file pid.txt -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
runc run --pid-file pid.txt -d -b "$bundle" --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]
# check state
+1 -2
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_hello
setup_hello
}
function teardown() {
teardown_hello
teardown_bundle
}
@test "runc run" {
+2 -5
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "state (kill + delete)" {
@@ -24,9 +23,7 @@ function teardown() {
runc kill test_busybox KILL
[ "$status" -eq 0 ]
# wait for busybox to be in the destroyed state
retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'"
wait_for_container 10 1 test_busybox stopped
# delete test_busybox
runc delete test_busybox
+1 -2
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "runc run [stdin not a tty]" {
+1 -2
View File
@@ -3,12 +3,11 @@
load helpers
function setup() {
teardown_busybox
setup_busybox
}
function teardown() {
teardown_busybox
teardown_bundle
}
@test "umask" {
+15 -18
View File
@@ -3,22 +3,19 @@
load helpers
function teardown() {
rm -f "$BATS_TMPDIR"/runc-cgroups-integration-test.json
teardown_running_container test_update
teardown_running_container test_update_rt
teardown_busybox
rm -f "$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json
teardown_bundle
}
function setup() {
teardown
setup_busybox
set_cgroups_path "$BUSYBOX_BUNDLE"
set_cgroups_path
# Set some initial known values
update_config ' .linux.resources.memory |= {"limit": 33554432, "reservation": 25165824}
| .linux.resources.cpu |= {"shares": 100, "quota": 500000, "period": 1000000, "cpus": "0"}
| .linux.resources.pids |= {"limit": 20}' "${BUSYBOX_BUNDLE}"
| .linux.resources.pids |= {"limit": 20}'
}
# Tests whatever limits are (more or less) common between cgroup
@@ -208,7 +205,7 @@ EOF
check_systemd_value "TasksMax" 10
# reset to initial test value via json file
cat <<EOF >"$BATS_TMPDIR"/runc-cgroups-integration-test.json
cat <<EOF >"$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json
{
"memory": {
"limit": 33554432,
@@ -226,7 +223,7 @@ EOF
}
EOF
runc update -r "$BATS_TMPDIR"/runc-cgroups-integration-test.json test_update
runc update -r "$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json test_update
[ "$status" -eq 0 ]
check_cgroup_value "cpuset.cpus" 0
@@ -297,7 +294,7 @@ EOF
check_cpu_quota -1 100000 "infinity"
# reset to initial test value via json file
cat <<EOF >"$BATS_TMPDIR"/runc-cgroups-integration-test.json
cat <<EOF >"$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json
{
"cpu": {
"shares": 100,
@@ -308,7 +305,7 @@ EOF
EOF
[ "$status" -eq 0 ]
runc update -r "$BATS_TMPDIR"/runc-cgroups-integration-test.json test_update
runc update -r "$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json test_update
[ "$status" -eq 0 ]
check_cpu_quota 500000 1000000 "500ms"
check_cpu_shares 100
@@ -317,7 +314,7 @@ EOF
@test "set cpu period with no quota" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
update_config '.linux.resources.cpu |= { "period": 1000000 }' "${BUSYBOX_BUNDLE}"
update_config '.linux.resources.cpu |= { "period": 1000000 }'
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]
@@ -328,7 +325,7 @@ EOF
@test "set cpu quota with no period" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
update_config '.linux.resources.cpu |= { "quota": 5000 }' "${BUSYBOX_BUNDLE}"
update_config '.linux.resources.cpu |= { "quota": 5000 }'
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]
@@ -338,7 +335,7 @@ EOF
@test "update cpu period with no previous period/quota set" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
update_config '.linux.resources.cpu |= {}' "${BUSYBOX_BUNDLE}"
update_config '.linux.resources.cpu |= {}'
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]
@@ -352,7 +349,7 @@ EOF
@test "update cpu quota with no previous period/quota set" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
update_config '.linux.resources.cpu |= {}' "${BUSYBOX_BUNDLE}"
update_config '.linux.resources.cpu |= {}'
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]
@@ -407,7 +404,7 @@ EOF
update_config ' .linux.resources.CPU |= {
"Cpus": "0",
"Mems": "0"
}' "${BUSYBOX_BUNDLE}"
}'
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]
@@ -455,7 +452,7 @@ EOF
update_config ' .linux.resources.unified |= {
"cpuset.cpus": "0",
"cpuset.mems": "0"
}' "${BUSYBOX_BUNDLE}"
}'
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]
@@ -573,7 +570,7 @@ EOF
update_config '.process.args |= ["sh", "-c", "while true; do echo >/dev/null; done"]'
# Set up a temporary console socket and recvtty so we can get the stdio.
TMP_RECVTTY_DIR="$(mktemp -d "$BATS_TMPDIR/runc-tmp-recvtty.XXXXXX")"
TMP_RECVTTY_DIR="$(mktemp -d "$BATS_RUN_TMPDIR/runc-tmp-recvtty.XXXXXX")"
TMP_RECVTTY_PID="$TMP_RECVTTY_DIR/recvtty.pid"
TMP_CONSOLE_SOCKET="$TMP_RECVTTY_DIR/console.sock"
CONTAINER_OUTPUT="$TMP_RECVTTY_DIR/output"