github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/cri-o/cri-o.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2017-2018 Intel Corporation 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 8 set -e 9 10 SCRIPT_PATH=$(dirname "$(readlink -f "$0")") 11 source "${SCRIPT_PATH}/../../.ci/lib.sh" 12 source "${SCRIPT_PATH}/crio_skip_tests.sh" 13 source "${SCRIPT_PATH}/../../metrics/lib/common.bash" 14 source /etc/os-release || source /usr/lib/os-release 15 16 export JOBS="${JOBS:-$(nproc)}" 17 export CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-containerd-shim-kata-v2}" 18 export CONTAINER_DEFAULT_RUNTIME="${CONTAINER_DEFAULT_RUNTIME:-$CONTAINER_RUNTIME}" 19 export RUNTIME_ROOT="${RUNTIME_ROOT:-/run/vc}" 20 export RUNTIME_TYPE="${RUNTIME_TYPE:-vm}" 21 export STORAGE_OPTIONS="--storage-driver overlay" 22 export PRIVILEGED_WITHOUT_HOST_DEVICES=true 23 24 # Skip the cri-o tests if TEST_CRIO is not true 25 # and we are on a CI job. 26 # For non CI execution, run the cri-o tests always. 27 if [ "$CI" = true ] && [ "$TEST_CRIO" != true ] 28 then 29 echo "Skipping cri-o tests as TEST_CRIO is not true" 30 exit 31 fi 32 33 crio_repository="github.com/cri-o/cri-o" 34 crio_repository_git="https://${crio_repository}.git" 35 crio_repository_path="$GOPATH/src/${crio_repository}" 36 37 img_file="" 38 loop_device="" 39 cleanup() { 40 [ -n "${loop_device}" ] && sudo losetup -d "${loop_device}" 41 [ -n "${img_file}" ] && rm -f "${img_file}" 42 } 43 44 # Check no processes are left behind 45 check_processes 46 47 # Clone CRI-O repo if it is not already present. 48 if [ ! -d "${crio_repository_path}" ]; then 49 mkdir -p "${crio_repository_path}" 50 git clone ${crio_repository_git} "${crio_repository_path}" 51 fi 52 53 # If the change we are testing does not come from CRI-O repository, 54 # then checkout to the version from versions.yaml in the runtime repository. 55 if [ "$ghprbGhRepository" != "${crio_repository/github.com\/}" ];then 56 pushd "${crio_repository_path}" 57 crio_version=$(get_version "externals.crio.branch") 58 git fetch 59 git checkout "${crio_version}" 60 popd 61 fi 62 63 # Ensure the correct version of the CRI-O binary is built and ready 64 pushd "${crio_repository_path}" 65 CONTAINER_DEFAULT_RUNTIME="" make 66 make test-binaries 67 popd 68 69 OLD_IFS=$IFS 70 IFS='' 71 72 # Skip CRI-O tests that currently are not working 73 pushd "${crio_repository_path}/test/" 74 75 CRIO_VERSION=$(echo ${PULL_BASE_REF} | cut -d'-' -f 2) 76 if [ -z "$CRIO_VERSION" ]; then 77 CRIO_VERSION="1.21" 78 echo "Unknown version of cri-o - assuming v$CRIO_VERSION to skip more tests" 79 else 80 echo GOT CRIO VERSION $CRIO_VERSION 81 fi 82 83 for batsfile in ${bats_files_list[@]}; do 84 testfile=${batsfile}_kata_integration_tests.bats 85 [ ! -f ${batsfile}.bats ] && continue 86 cp ${batsfile}.bats ${testfile} 87 declare -n skip_list=${batsfile//-}_skipCRIOTests 88 for testName in "${!skip_list[@]}" 89 do 90 echo "Skipping $testName in $testfile" 91 sed -i '/'${testName}'/a skip \"'${skip_list[$testName]}'\"' "${testfile}" 92 done 93 94 # selectively skip tests depending on the version of cri-o we're testing with 95 if [ "$CRIO_VERSION" != "main" ]; then 96 declare -n skip_list=${batsfile//-}_fixedInCrioVersion 97 for testName in "${!skip_list[@]}" 98 do 99 if [ "$(echo -e "$CRIO_VERSION\n${skip_list[$testName]}" | sort -V | head -n1)" != "${skip_list[$testName]}" ]; then 100 echo "Skipping $testName in $testfile for cri-o v$CRIO_VERSION" 101 sed -i '/'${testName}'/a skip \"- fixed in cri-o v'${skip_list[$testName]}'\"' "${testfile}" 102 fi 103 done 104 fi 105 done 106 107 IFS=$OLD_IFS 108 109 echo "Ensure crio service is stopped before running the tests" 110 if systemctl is-active --quiet crio; then 111 sudo systemctl stop crio 112 fi 113 114 echo "Ensure docker service is stopped before running the tests" 115 if systemctl is-active --quiet docker; then 116 sudo systemctl stop docker 117 fi 118 119 echo "Running cri-o tests with runtime: $CONTAINER_RUNTIME" 120 ./test_runner.sh *_kata_integration_tests.bats 121 rm *_kata_integration_tests.bats 122 123 popd