From 9a8babe495fddb751e01e97c19ed54cdd0ce932d Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Wed, 18 Oct 2023 15:51:27 -0300 Subject: [PATCH] tests/e2e: give more controls to tests_runner.sh This makes the tests/e2e/tests_runner.sh more flexible so to improve the experience of debugging an error on tests. The new controls introduced are: - Exporting `CI=false` will disable the teardown of most Kata's tests. The clean up and revert routines won't execute, resources like pods are preserved. - You can filter only the tests you want to run by exporting the FILTER_TESTS variable. For example: $ export FILTER_TESTS='.*Test can pull an unencrypted image inside the guest' - Exporting KATA_TESTS_REPO_DIR it won't attempt to clone the tests repo. Notice that you should export GOPATH properly. Example: $ sudo -E PATH="$PATH" GOPATH=$PWD \ KATA_TESTS_REPO_DIR=$PWD/src/github.com/kata-containers/tests \ bash -c "./tests_runner.sh -r kata-qemu" Signed-off-by: Wainer dos Santos Moschetta --- tests/e2e/tests_runner.sh | 47 +++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/tests/e2e/tests_runner.sh b/tests/e2e/tests_runner.sh index 62d71c2e..5847e908 100755 --- a/tests/e2e/tests_runner.sh +++ b/tests/e2e/tests_runner.sh @@ -12,15 +12,19 @@ set -o pipefail script_dir="$(dirname "$(readlink -f "$0")")" project_dir="$(readlink -f ${script_dir}/../..)" -export GOPATH="$(mktemp -d)" -tests_repo_dir="$GOPATH/src/github.com/kata-containers/tests" -export CI=true +# It will be either be cloned or passed via environment variable +tests_repo_dir="" +export CI=${CI:-true} # TODO: Debug should be enabled in order for some tests to enable the console # debug and search for patterns on agent logs. Probably console debug should # be enabled always. export DEBUG=true +export FILTER_TESTS="${FILTER_TESTS:-}" + +export KATA_TESTS_REPO_DIR="${KATA_TESTS_REPO_DIR:-}" + # The container runtime class (e.g. kata, kata-qemu, kata-clh) test pods should # be created with. runtimeclass="kata-qemu" @@ -32,6 +36,14 @@ export TESTS_CONFIGURE_CC_CONTAINERD=no clone_kata_tests() { local cc_branch="CCv0" + # Do not clone if an existing repo. + if [ -n "$KATA_TESTS_REPO_DIR" ]; then + tests_repo_dir="$KATA_TESTS_REPO_DIR" + return + fi + + export GOPATH="$(mktemp -d)" + tests_repo_dir="$GOPATH/src/github.com/kata-containers/tests" # TODO: checkout on the exact sha1 where the kata-deploy was created # so that we ensure the same tests are used here. git clone --branch="$cc_branch" \ @@ -41,7 +53,9 @@ clone_kata_tests() { cleanup() { [ ! -s "/usr/local/bin/kata-runtime" ] || \ unlink /usr/local/bin/kata-runtime - rm -rf "$tests_repo_dir" || true + if [ -z "$KATA_TESTS_REPO_DIR" ]; then + rm -rf "$tests_repo_dir" || true + fi } trap cleanup EXIT @@ -64,9 +78,26 @@ usage() { -h | --help : show this usage -r RUNTIMECLASS: run tests for RUNTIMECLASS (e.g. kata-clh). Defaults to "kata-qemu". + Environment variables: + CI: some tests will skip teardown (i.e. resources won't be removed) + if CI=false. Defaults to "true". + FILTER_TESTS: use to filter tests. Pass a regex expression + to match the tests names to run. + KATA_TESTS_REPO_DIR: path to kata container's tests repository. If set then + this script will not attempt to clone the repository + nor delete on exit. You should export GOPATH properly to + ensure the scripts will work correctly. EOF } +run_bats() { + local bats_files=$* + local cmd="bats" + + [ -n "$FILTER_TESTS" ] && cmd+=" -f \"$FILTER_TESTS\"" + eval $cmd $bats_files +} + # tests for CC without specific hardware support run_non_tee_tests() { local runtimeclass="$1" @@ -86,7 +117,7 @@ run_non_tee_tests() { sed -i "s#kata-runtime kata-env#kata-runtime --config $runtime_config_file kata-env#g" \ ../../../lib/common.bash - bats \ + run_bats \ "agent_image.bats" \ "agent_image_encrypted.bats" \ "${script_dir}/operator_tests.bats" @@ -95,13 +126,15 @@ run_non_tee_tests() { # Tests for CC with QEMU on SEV HW run_kata_qemu_sev_tests() { - bats "sev.bats" + run_bats \ + "sev.bats" } # Tests for CC with QEMU on SNP HW run_kata_qemu_snp_tests() { - bats "snp.bats" + run_bats \ + "snp.bats" } main() {