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

Skip to content
Closed
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
2 changes: 1 addition & 1 deletion test/cgroups.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
load helpers

function setup() {
newconfig="$TESTDIR/config.json"
setup_test
newconfig="$TESTDIR/config.json"
}

function teardown() {
Expand Down
6 changes: 3 additions & 3 deletions test/config_migrate.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
load helpers

@test "config migrate should succeed with default config" {
output=$(crio -c "" -d "" config -m 1.17 2>&1)
output=$("$CRIO_BINARY_PATH" -c "" -d "" config -m 1.17 2>&1)
[[ "$output" != *"Changing"* ]]
}

@test "config migrate should succeed with 1.17 config" {
# when
output=$(crio -c "$TESTDATA/config/config-v1.17.0.toml" -d "" config -m 1.17 2>&1)
output=$("$CRIO_BINARY_PATH" -c "$TESTDATA/config/config-v1.17.0.toml" -d "" config -m 1.17 2>&1)

# then
[[ "$output" == *'Changing \"apparmor_profile\" to \"crio-default\"'* ]]
Expand All @@ -25,7 +25,7 @@ load helpers

@test "config migrate should fail on invalid version" {
# when
run crio -c "" -d "" config -m 1.16
run "$CRIO_BINARY_PATH" -c "" -d "" config -m 1.16

# then
[[ "$output" == *"unsupported migration version"* ]]
Expand Down
2 changes: 1 addition & 1 deletion test/crio-wipe.bats
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ function run_podman_with_args() {
}

function teardown() {
cleanup_test
run_podman_with_args stop -a
run_podman_with_args rm -fa
cleanup_test
cleanup_namespaces_dir
}

Expand Down
6 changes: 3 additions & 3 deletions test/critest.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
load helpers

function setup() {
if [[ -z $RUN_CRITEST ]]; then
if [ ! -v RUN_CRITEST ]; then
skip "critest because RUN_CRITEST is not set"
fi

Expand All @@ -19,7 +19,7 @@ function teardown() {
critest --parallel 8 \
--runtime-endpoint "unix://${CRIO_SOCKET}" \
--image-endpoint "unix://${CRIO_SOCKET}" \
--ginkgo.focus="${CRI_FOCUS}" \
--ginkgo.skip="${CRI_SKIP}" \
--ginkgo.focus="${CRI_FOCUS:-}" \
--ginkgo.skip="${CRI_SKIP:-}" \
--ginkgo.flakeAttempts=3 >&3
}
37 changes: 22 additions & 15 deletions test/helpers.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#!/usr/bin/env bash

# BATS is broken wrt. 'set -u' with bash < 4.4.
# Until/unless https://github.com/bats-core/bats-core/pull/550 is
# merged, make sure we don't run with 'set -u' on offending bash.
bash_version=$((1000 * $(echo "${BASH_VERSION%.[^.]*}" | tr '.' '+')))
if [ "$bash_version" -ge 4004 ]; then
set -u
fi

# Work around skip() in old BATS versions not handling substitutions properly
# wrt. 'set -u'. (fixed in commit 9b2b659e5ba769752c0d00dadb3ad9b58f59cbaa).
# This can be removed once all CI nodes have been setup with new enough BATS.
BATS_TEARDOWN_STARTED=${BATS_TEARDOWN_STARTED:-}

# Root directory of integration tests.
INTEGRATION_ROOT=${INTEGRATION_ROOT:-$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")}

Expand Down Expand Up @@ -246,11 +259,7 @@ function setup_img() {
}

function setup_crio() {
apparmor=""
if [[ -n "$1" ]]; then
apparmor="$1"
fi

apparmor="${1:-}"
for img in "${IMAGES[@]}"; do
setup_img "$img"
done
Expand Down Expand Up @@ -373,8 +382,8 @@ function cleanup_pods() {
}

function stop_crio_no_clean() {
local signal="$1"
if [ -n "${CRIO_PID+x}" ]; then
local signal="${1:-}"
if [ -v CRIO_PID ]; then
kill "$signal" "$CRIO_PID" >/dev/null 2>&1 || true
wait "$CRIO_PID"
unset CRIO_PID
Expand All @@ -399,7 +408,7 @@ function restart_crio() {
}

function cleanup_lvm() {
if [ -n "${LVM_DEVICE+x}" ]; then
if [ -v LVM_DEVICE ]; then
lvm lvremove -y storage/thinpool
lvm vgremove -y storage
lvm pvremove -y "$LVM_DEVICE"
Expand All @@ -416,7 +425,7 @@ function cleanup_testdir() {
}

function cleanup_test() {
[ -z "$TESTDIR" ] && return
[ ! -v TESTDIR ] && return
# show crio log (only shown by bats in case of test failure)
if [ -f "$CRIO_LOG" ]; then
echo "# --- crio.log :: ---"
Expand Down Expand Up @@ -561,19 +570,17 @@ function create_runtime_with_allowed_annotation() {
default_runtime = "$NAME"
[crio.runtime.runtimes.$NAME]
runtime_path = "$RUNTIME_BINARY_PATH"
runtime_root = "$RUNTIME_ROOT"
runtime_root = "${RUNTIME_ROOT:-}"
runtime_type = "$RUNTIME_TYPE"
allowed_annotations = ["$ANNOTATION"]
EOF
}

function create_workload_with_allowed_annotation() {
local act="$2"
local act="${2:-}"
# Fallback on the specified allowed annotation if
# a specific activation annotation wasn't specified.
if [[ -z "$act" ]]; then
act="$1"
fi
act="${act:-$1}"
cat <<EOF >"$CRIO_CONFIG_DIR/01-workload.conf"
[crio.runtime.workloads.management]
activation_annotation = "$act"
Expand All @@ -593,7 +600,7 @@ function set_swap_fields_given_cgroup_version() {

function check_conmon_cpuset() {
local ctr_id="$1"
local cpuset="$2"
local cpuset="${2:-}"
systemd_supports_cpuset=$(systemctl show --property=AllowedCPUs systemd || true)

if [[ "$CONTAINER_CGROUP_MANAGER" == "cgroupfs" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion test/namespaces.bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function teardown() {
}

@test "pid namespace mode target test" {
if [[ -n "$TEST_USERNS" ]]; then
if [[ -v TEST_USERNS ]]; then
skip "test fails in a user namespace"
fi
start_crio
Expand Down