From 25ac2783956acc916e9c749e29757cd2ae055fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Papou=C5=A1ek?= Date: Thu, 26 Oct 2023 13:08:11 +0200 Subject: [PATCH] Change tests run scripts --- docker-compose.yml | 1 + insights_sha_extractor_test.sh | 41 +++++++++++++++++++++++++--------- run_in_docker.sh | 7 ++---- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 20fa43d8..4a2a707c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,6 +26,7 @@ services: profiles: - test-notification-services - test-aggregator + - test-sha-extractor image: quay.io/ccxdev/kafka-no-zk:latest ports: - 9092:9092 diff --git a/insights_sha_extractor_test.sh b/insights_sha_extractor_test.sh index ea40cd4e..18de87ed 100755 --- a/insights_sha_extractor_test.sh +++ b/insights_sha_extractor_test.sh @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +export PATH_TO_LOCAL_SHA_EXTRACTOR=${PATH_TO_LOCAL_SHA_EXTRACTOR:="../ccx-sha-extractor"} +export exit_trap_command="" + function prepare_venv() { echo "Preparing environment" # shellcheck disable=SC1091 @@ -23,12 +26,16 @@ function prepare_venv() { python3 "$(which pip3)" install --no-cache -r requirements.in || exit 1 python3 "$(which pip3)" install --no-cache -r requirements/insights_sha_extractor.txt || exit 1 - git clone --depth=1 git@gitlab.cee.redhat.com:ccx/ccx-sha-extractor.git - cd ccx-sha-extractor || exit + if [[ ! -d $PATH_TO_LOCAL_SHA_EXTRACTOR ]] ; then + git clone --depth=1 git@gitlab.cee.redhat.com:ccx/ccx-sha-extractor.git $PATH_TO_LOCAL_SHA_EXTRACTOR + add_trap "rm -rf ./ccx-sha-extractor" + fi + cwd=$(pwd) + cd $PATH_TO_LOCAL_SHA_EXTRACTOR || exit pip install --no-cache-dir -U pip setuptools wheel pip install --no-cache-dir -r requirements.txt pip install -e . - cd .. + cd $cwd echo "Environment ready" } @@ -56,17 +63,35 @@ function run_kafka() { done export kafka_cid + echo $kafka_cid + add_trap "docker kill ${kafka_cid}" } -function run_mock_s3(){ +function run_mock_s3() { uvicorn mocks.s3.s3:app & s3_pid=$! + add_trap "kill -9 $s3_pid" } -run_kafka +function cleanup { + eval "$exit_trap_command" +} -run_mock_s3 +function add_trap() { + local to_add=$1 + if [ -z $exit_trap_command ]; then + exit_trap_command="$to_add" + else + exit_trap_command="$exit_trap_command; $to_add" + fi + trap cleanup EXIT +} +if ! [ $ENV_DOCKER ] ; then + run_kafka +fi + +run_mock_s3 prepare_venv # shellcheck disable=SC2068 @@ -74,7 +99,3 @@ PYTHONDONTWRITEBYTECODE=1 python3 -m behave --no-capture \ --format=progress2 \ --tags=-skip --tags=-managed \ -D dump_errors=true @test_list/insights_sha_extractor.txt "$@" - -docker kill "$kafka_cid" -kill -9 $s3_pid -rm -rf ./ccx-sha-extractor diff --git a/run_in_docker.sh b/run_in_docker.sh index 82bdc7e6..e0ea8d83 100755 --- a/run_in_docker.sh +++ b/run_in_docker.sh @@ -71,10 +71,7 @@ copy_files() { copy_python_project "$cid" "$path_to_service" ;; "insights-sha-extractor-tests") - echo -e "\033[0;31mThese tests are not ready to be run. Aborting!\033[0m" - echo "This option will be enabled after https://issues.redhat.com/browse/CCXDEV-11895 is done." - exit 0 - # copy_python_project $cid $path_to_service + copy_python_project $cid $path_to_service ;; "notification-service-tests") copy_go_executable "$cid" "$path_to_service" "ccx-notification-service" @@ -103,7 +100,7 @@ docker_compose_profiles["exporter-tests"]="test-exporter" docker_compose_profiles["inference-service-tests"]="" docker_compose_profiles["insights-content-service-tests"]="" docker_compose_profiles["insights-content-template-renderer-tests"]="" -docker_compose_profiles["insights-sha-extractor-tests"]="text-sha-extractor" +docker_compose_profiles["insights-sha-extractor-tests"]="test-sha-extractor" docker_compose_profiles["notification-service-tests"]="test-notification-services" docker_compose_profiles["notification-writer-tests"]="test-notification-services" docker_compose_profiles["smart-proxy-tests"]=""