diff --git a/test/README.md b/test/README.md index 38ba51b0b28..9c7ee746140 100644 --- a/test/README.md +++ b/test/README.md @@ -15,7 +15,7 @@ Integration tests are written in *bash* using the ### Containerized tests -The easiest way to run integration tests is with Docker: +The easiest way to run integration tests is with Podman: ``` $ make integration ``` @@ -70,11 +70,16 @@ Tests on the host will run with `runc` as the default runtime. However you can select other OCI compatible runtimes by setting the `RUNTIME` environment variable. -For example one could use the [Clear Containers](https://github.com/clearcontainers/runtime) -runtime instead of `runc`: +For example, to use [crun](https://github.com/containers/crun) instead of `runc`: +``` +make CONTAINER_DEFAULT_RUNTIME=crun localintegration +``` + +If you'd like to run the tests with a runtime of a different type, you need to also specify `$RUNTIME_TYPE` +For example, to use [kata](https://github.com/kata-containers/runtime) with shim v2: ``` -make localintegration RUNTIME=cc-runtime +make CONTAINER_DEFAULT_RUNTIME=containerd-shim-kata-v2 RUNTIME_TYPE=vm localintegration ``` ## Writing integration tests diff --git a/test/config.bats b/test/config.bats index c2a3522b215..0fb7fc1281c 100644 --- a/test/config.bats +++ b/test/config.bats @@ -41,6 +41,7 @@ function teardown() { @test "replace default runtime should succeed" { # when + unset CONTAINER_RUNTIMES RES=$("$CRIO_BINARY_PATH" -d "$TESTDATA"/50-crun-default.conf config 2>&1) # then diff --git a/test/devices.bats b/test/devices.bats index b0073cb96c9..369947e75ab 100644 --- a/test/devices.bats +++ b/test/devices.bats @@ -20,7 +20,7 @@ function create_device_runtime() { [crio.runtime] default_runtime = "device" [crio.runtime.runtimes.device] -runtime_path = "$RUNTIME_BINARY" +runtime_path = "$RUNTIME_BINARY_PATH" runtime_root = "$RUNTIME_ROOT" runtime_type = "$RUNTIME_TYPE" allowed_annotations = ["io.kubernetes.cri-o.Devices"] diff --git a/test/drop_infra.bats b/test/drop_infra.bats index 96b8bf96134..db01c950ed9 100644 --- a/test/drop_infra.bats +++ b/test/drop_infra.bats @@ -21,7 +21,7 @@ function teardown() { "$TESTDATA"/sandbox_config.json > "$TESTDIR"/sandbox_no_infra.json pod_id=$(crictl runp "$TESTDIR"/sandbox_no_infra.json) - output=$("$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" list) + output=$(runtime list) [[ ! "$output" = *"$pod_id"* ]] } @@ -30,6 +30,6 @@ function teardown() { "$TESTDATA"/sandbox_config.json > "$TESTDIR"/sandbox_no_infra.json pod_id=$(crictl runp "$TESTDIR"/sandbox_no_infra.json) - output=$("$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" list) + output=$(runtime list) [[ "$output" = *"$pod_id"* ]] } diff --git a/test/helpers.bash b/test/helpers.bash index 5f831bd7470..cf3aa199e8d 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -35,16 +35,9 @@ CONTAINER_UID_MAPPINGS=${CONTAINER_UID_MAPPINGS:-} CONTAINER_GID_MAPPINGS=${CONTAINER_GID_MAPPINGS:-} OVERRIDE_OPTIONS=${OVERRIDE_OPTIONS:-} # Runtime -CONTAINER_RUNTIME=${CONTAINER_RUNTIME:-runc} CONTAINER_DEFAULT_RUNTIME=${CONTAINER_DEFAULT_RUNTIME:-runc} -RUNTIME_NAME=${RUNTIME_NAME:-runc} -RUNTIME_PATH=$(command -v "$CONTAINER_RUNTIME" || true) -RUNTIME_BINARY=${RUNTIME_PATH:-$(command -v runc)} +RUNTIME_BINARY_PATH=$(command -v "$CONTAINER_DEFAULT_RUNTIME") RUNTIME_TYPE=${RUNTIME_TYPE:-oci} -if [[ $CONTAINER_RUNTIME == "kata-runtime" ]]; then - export RUNTIME_NAME="$CONTAINER_RUNTIME" - export CONTAINER_DEFAULT_RUNTIME="$RUNTIME_NAME" -fi # Path of the apparmor_parser binary. APPARMOR_PARSER_BINARY=${APPARMOR_PARSER_BINARY:-/sbin/apparmor_parser} # Path of the apparmor profile for test. @@ -198,6 +191,11 @@ function crictl() { "$CRICTL_BINARY" -r "unix://$CRIO_SOCKET" -i "unix://$CRIO_SOCKET" "$@" } +# Run the runtime binary with the specified RUNTIME_ROOT +function runtime() { + "$RUNTIME_BINARY_PATH" --root "$RUNTIME_ROOT" "$@" +} + # Communicate with Docker on the host machine. # Should rarely use this. function docker_host() { @@ -263,12 +261,9 @@ function setup_crio() { CNI_DEFAULT_NETWORK=${CNI_DEFAULT_NETWORK:-crio} CNI_TYPE=${CNI_TYPE:-bridge} - # Workaround for https://github.com/containers/crun/pull/531. - # TODO: remove once crun > 0.15 is released and used here. - if $RUNTIME_BINARY --version | grep -q '^crun '; then - OVERRIDE_OPTIONS="$OVERRIDE_OPTIONS --selinux=false" - fi - RUNTIME_ROOT="$TESTDIR/crio-runtime-root" + RUNTIME_ROOT=${RUNTIME_ROOT:-"$TESTDIR/crio-runtime-root"} + # export here so direct calls to crio later inherit the variable + export CONTAINER_RUNTIMES=${CONTAINER_RUNTIMES:-$CONTAINER_DEFAULT_RUNTIME:$RUNTIME_BINARY_PATH:$RUNTIME_ROOT:$RUNTIME_TYPE} # shellcheck disable=SC2086 "$CRIO_BINARY_PATH" \ @@ -279,7 +274,6 @@ function setup_crio() { --listen "$CRIO_SOCKET" \ --registry "quay.io" \ --registry "docker.io" \ - --runtimes "$RUNTIME_NAME:$RUNTIME_BINARY:$RUNTIME_ROOT:$RUNTIME_TYPE" \ -r "$TESTDIR/crio" \ --runroot "$TESTDIR/crio-run" \ --cni-default-network "$CNI_DEFAULT_NETWORK" \ diff --git a/test/restore.bats b/test/restore.bats index 57c16b49cd9..cffd461b101 100644 --- a/test/restore.bats +++ b/test/restore.bats @@ -62,7 +62,7 @@ function teardown() { stop_crio # simulate reboot with runc state going away - "$CONTAINER_RUNTIME" delete -f "$pod_id" + runtime delete -f "$pod_id" start_crio @@ -79,8 +79,8 @@ function teardown() { stop_crio # simulate reboot with runc state going away - "$CONTAINER_RUNTIME" delete -f "$pod_id" - "$CONTAINER_RUNTIME" delete -f "$ctr_id" + runtime delete -f "$pod_id" + runtime delete -f "$ctr_id" start_crio @@ -98,8 +98,8 @@ function teardown() { stop_crio # simulate reboot with runc state going away - "$CONTAINER_RUNTIME" delete -f "$pod_id" - "$CONTAINER_RUNTIME" delete -f "$ctr_id" + runtime delete -f "$pod_id" + runtime delete -f "$ctr_id" start_crio @@ -118,7 +118,7 @@ function teardown() { stop_crio # simulate reboot with runc state going away - "$CONTAINER_RUNTIME" delete -f "$pod_id" + runtime delete -f "$pod_id" start_crio @@ -141,8 +141,8 @@ function teardown() { stop_crio # simulate reboot with runc state going away - "$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" delete -f "$pod_id" - "$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" delete -f "$ctr_id" + runtime delete -f "$pod_id" + runtime delete -f "$ctr_id" start_crio output=$(crictl pods --quiet) @@ -171,8 +171,8 @@ function teardown() { stop_crio # simulate reboot with runtime state and config.json going away - "$CONTAINER_RUNTIME" delete -f "$pod_id" - "$CONTAINER_RUNTIME" delete -f "$ctr_id" + runtime delete -f "$pod_id" + runtime delete -f "$ctr_id" find "$TESTDIR"/ -name config.json -exec rm \{\} \; find "$TESTDIR"/ -name shm -exec umount -l \{\} \; diff --git a/test/shm_size.bats b/test/shm_size.bats index 59c9bc8683b..b6dc7c75438 100644 --- a/test/shm_size.bats +++ b/test/shm_size.bats @@ -15,7 +15,7 @@ function create_shmsize_runtime() { [crio.runtime] default_runtime = "shmsize" [crio.runtime.runtimes.shmsize] -runtime_path = "$RUNTIME_BINARY" +runtime_path = "$RUNTIME_BINARY_PATH" runtime_root = "$RUNTIME_ROOT" runtime_type = "$RUNTIME_TYPE" allowed_annotations = ["io.kubernetes.cri-o.ShmSize"] diff --git a/test/timeout.bats b/test/timeout.bats index 309c4fdff37..bbdfe79b304 100644 --- a/test/timeout.bats +++ b/test/timeout.bats @@ -58,7 +58,7 @@ function wait_clean() { pods=$(crictl pods -q) [[ -z "$pods" ]] - created_ctr_id=$("$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" list -q) + created_ctr_id=$(runtime list -q) [ -n "$created_ctr_id" ] output=$(crictl runp "$TESTDATA"/sandbox_config.json) @@ -81,7 +81,7 @@ function wait_clean() { [[ -z "$ctrs" ]] # cri-o should have created a container - created_ctr_id=$("$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" list -q | grep -v "$pod_id") + created_ctr_id=$(runtime list -q | grep -v "$pod_id") [ -n "$created_ctr_id" ] output=$(crictl create "$pod_id" "$TESTDATA"/container_config.json "$TESTDATA"/sandbox_config.json) @@ -98,7 +98,7 @@ function wait_clean() { wait_create - created_ctr_id=$("$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" list -q) + created_ctr_id=$(runtime list -q) [ -n "$created_ctr_id" ] # we should create a new pod and not reuse the old one @@ -108,7 +108,7 @@ function wait_clean() { wait_clean # the old, timed out container should have been removed - ! "$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" list -q | grep "$created_ctr_id" + ! runtime list -q | grep "$created_ctr_id" } @test "should clean up container after timeout if request changes" { @@ -123,7 +123,7 @@ function wait_clean() { wait_create # cri-o should have created a container - created_ctr_id=$("$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" list -q | grep -v "$pod_id") + created_ctr_id=$(runtime list -q | grep -v "$pod_id") [ -n "$created_ctr_id" ] # should create a new container and not reuse the old one @@ -133,7 +133,7 @@ function wait_clean() { wait_clean # the old, timed out container should have been removed - ! "$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" list -q | grep "$created_ctr_id" + ! runtime list -q | grep "$created_ctr_id" } @test "should clean up pod after timeout if not re-requested" { @@ -151,7 +151,7 @@ function wait_clean() { [[ -z "$pods" ]] # pod should have been cleaned up - [[ -z $("$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" list -q) ]] + [[ -z $(runtime list -q) ]] # we should recreate the pod and not reuse the old one crictl runp "$TESTDATA"/sandbox_config.json @@ -173,7 +173,7 @@ function wait_clean() { [[ -z "$ctrs" ]] # container should have been cleaned up - ! "$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" list -q | grep -v "$pod_id" + ! runtime list -q | grep -v "$pod_id" # we should recreate the container and not reuse the old one crictl create "$pod_id" "$TESTDATA"/container_config.json "$TESTDATA"/sandbox_config.json @@ -193,7 +193,7 @@ function wait_clean() { wait_create # container should not have been cleaned up - created_ctr_id=$("$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" list -q) + created_ctr_id=$(runtime list -q) [ -n "$created_ctr_id" ] ! crictl create "$created_ctr_id" "$TESTDATA"/container_config.json "$TESTDATA"/sandbox_config.json @@ -213,7 +213,7 @@ function wait_clean() { wait_create # cri-o should have created a container - created_ctr_id=$("$CONTAINER_RUNTIME" --root "$RUNTIME_ROOT" list -q | grep -v "$pod_id") + created_ctr_id=$(runtime list -q | grep -v "$pod_id") [ -n "$created_ctr_id" ] ! crictl start "$created_ctr_id"