Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/config.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/devices.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 2 additions & 2 deletions test/drop_infra.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"* ]]
}

Expand All @@ -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"* ]]
}
24 changes: 9 additions & 15 deletions test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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" "$@"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, did you mean "$CONTAINER_RUNTIME" here? There's no "$RUNTIME_BINARY_PATH" (yet?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, the order of commits seems to be wrong (or github is showing them in the wrong order), as this ^^^ belongs to the first commit, and $RUNTIME_BINARY_PATH is introduced by the third commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oopsies, updated!

}

# Communicate with Docker on the host machine.
# Should rarely use this.
function docker_host() {
Expand Down Expand Up @@ -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" \
Expand All @@ -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" \
Expand Down
20 changes: 10 additions & 10 deletions test/restore.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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 \{\} \;

Expand Down
2 changes: 1 addition & 1 deletion test/shm_size.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
20 changes: 10 additions & 10 deletions test/timeout.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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" {
Expand All @@ -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
Expand All @@ -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" {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand Down