From: halil.cakal Date: Thu, 26 Jun 2025 13:37:49 +0000 (+0100) Subject: Clean up setup and teardown processes for k6 tests X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=cafa840f982ac65fc9d31baa876169272185d59b;p=cps.git Clean up setup and teardown processes for k6 tests - rename cps-base.yml to docker-compose.yml to use minimum docker-compose commands efficiently - rename confusing file names: - run-k6-tests.sh to k6-main.sh - run-all-tests.sh to execute-k6-scenarios.sh - ncmp-test-runner.js to scenarios-config.js - cleanup teardown.sh - not only endurance but also kpi should remove all ONAP docker images since setup function always builds them! - Don't remove any other images (they don't belong ONAP) because it bring extra pulling time during the setup, and make the pipeline slower. - combine relevant methods into one - add cm avc event and v3 data node get metrics to metrics.csv file to prevent them commit always - add missing import for crypto Issue-ID: CPS-2861 Change-Id: If3d5cc8e33e5a5baa34834aaa178be7803dd5f7d Signed-off-by: halil.cakal --- diff --git a/csit/plans/cps/setup.sh b/csit/plans/cps/setup.sh index b16a07d246..b7e21bc1b3 100755 --- a/csit/plans/cps/setup.sh +++ b/csit/plans/cps/setup.sh @@ -32,8 +32,10 @@ export $(cut -d= -f1 $WORKSPACE/plans/cps/test.properties) ###################### setup cps-and-ncmp with dmi-services ############################ cd $CPS_HOME/docker-compose -# Start cps-base and dmi-services with docker compose, and wait for all containers to be healthy. -docker-compose -f cps-base.yml -f dmi-services.yml up -d --quiet-pull --wait || exit 1 +# Start default docker-compose and dmi-services, and wait for all containers to be healthy. +# Note: Since -f flag is used for dmi-services.yml, default docker-compose file should also be binded with -f flag, +# otherwise cps base services won't be running! +docker-compose -f docker-compose.yml -f dmi-services.yml up -d --quiet-pull --wait || exit 1 ###################### ROBOT Configurations ########################## # Pass variables required for Robot test suites in ROBOT_VARIABLES. diff --git a/docker-compose/README.md b/docker-compose/README.md index 91f0bc5ac4..c1bbb4e640 100644 --- a/docker-compose/README.md +++ b/docker-compose/README.md @@ -49,23 +49,23 @@ mvn clean install -P ## Running Docker Containers -`docker-compose/cps-base.yml` contains the base services required to run CPS and NCMP. +`docker-compose/docker-compose.yml` contains the base services required to run CPS and NCMP. This deployment can also be used for KPI test. Please run the following command from `docker-compose` folder: ```bash -docker-compose -f cps-base.yml up -d +docker-compose up -d or -docker-compose -f cps-base.yml --profile tracing up -d +docker-compose --profile tracing up -d ``` `docker-compose/dmi-services.yml` contains the DMI services including SDNC and PNF Simulator. This deployment is required for the CSIT test. ```bash -docker-compose -f cps-base.yml -f dmi-services.yml up -d +docker-compose -f docker-compose.yml -f dmi-services.yml up -d ``` To deploy services that are required for Endurance test, please use the following command: ```bash -docker-compose -f cps-base.yml --project-name endurance --env-file env/endurance.env up -d +docker-compose --project-name endurance --env-file env/endurance.env up -d ``` To stop any deployment, please replace `up -d` flag with `down` in the above commands. diff --git a/docker-compose/dmi-services.yml b/docker-compose/dmi-services.yml index 9288400cc1..6e323c167f 100644 --- a/docker-compose/dmi-services.yml +++ b/docker-compose/dmi-services.yml @@ -16,10 +16,6 @@ services: - ### docker-compose -f dmi-services.yml up -d -> run ONAP-DMI plugin, and related services such as SDNC, and PNF-Simulator - ### docker-compose -f dmi-services.yml down -> stop ONAP-DMI plugin, and related services - ### docker-compose -f cps-base.yml -f dmi-services.yml up -d -> run cps-and-ncmp with ONAP dmi-plugin - sdnc-db: container_name: sdnc-db image: mariadb:10.5 diff --git a/docker-compose/cps-base.yml b/docker-compose/docker-compose.yml similarity index 92% rename from docker-compose/cps-base.yml rename to docker-compose/docker-compose.yml index f3fe4f9624..e9fd9da60c 100644 --- a/docker-compose/cps-base.yml +++ b/docker-compose/docker-compose.yml @@ -18,11 +18,12 @@ services: - ### docker-compose -f cps-base.yml up -d -> run CPS with stubbed dmi-plugin (DMI-stub, and monitoring services for k6 testing) - ### docker-compose -f cps-base.yml --profile tracing up -d -> run CPS with stubbed dmi-plugin (DMI-stub for k6 testing with jaeger tracing) - ### docker-compose -f cps-base.yml -f dmi-services.yml up -d -> run CPS with dmi-plugin (cps-base, and ONAP-DMI services for CSIT testing) - ### docker-compose -f cps-base.yml --project-name endurance --env-file env/endurance.env up -d -> run CPS with DMI-stub for Endurance testing - ### docker-compose -f cps-base.yml --project-name endurance down --volumes -> stop and remove containers and volumes + ### docker-compose up -d -> run CPS with stubbed dmi-plugin (DMI-stub, and monitoring services for k6 testing) + ### docker-compose --profile tracing up -d -> run CPS with stubbed dmi-plugin (DMI-stub for k6 testing with jaeger tracing) + ### docker-compose -f dmi-services.yml up -d -> run ONAP-DMI plugin, and related services such as SDNC, and PNF-Simulator + ### docker-compose -f docker-compose.yml -f dmi-services.yml up -d -> run CPS with dmi-plugin (cps-base, and ONAP-DMI services for CSIT testing) + ### docker-compose --project-name endurance --env-file env/endurance.env up -d -> run CPS with DMI-stub for Endurance testing + ### docker-compose --project-name endurance down --volumes -> stop and remove containers and volumes ### To disable notification make notification.enabled to false and comment out kafka/zookeeper services ### DEBUG: Look for '### DEBUG' comments to enable CPS-NCMP debugging diff --git a/docs/csv/metrics.csv b/docs/csv/metrics.csv index 25925dc669..c5f739135f 100644 --- a/docs/csv/metrics.csv +++ b/docs/csv/metrics.csv @@ -9,6 +9,7 @@ "cps_ncmp_inventory_cm_handles_by_state{state=LOCKED}","Current number of cm handles in locked state" "cps_ncmp_inventory_cm_handles_by_state{state=DELETING}","Current number of cm handles in deleting state" "cps_ncmp_inventory_cm_handles_by_state{state=DELETED}","Number of cm handles that have been deleted since the application started" +"cps.ncmp.cmnotifications.consumeandforward","Time taken to forward CM AVC events" "cps.ncmp.dmi.get","Time taken to fetch the resource data from operational data store for given cm handle " "cps.ncmp.inventory.persistence.datanode.get","Time taken to get a data node (from ncmp dmi registry)" "cps.ncmp.inventory.persistence.datanode.get","Time taken to get a data node (from ncmp dmi registry)" @@ -21,6 +22,7 @@ "cps.data.controller.datanode.query.across.anchors","Time taken to query data nodes across anchors" "cps.data.controller.datanode.get.v1","Time taken to get data node" "cps.data.controller.datanode.get.v2","Time taken to get data node" +"cps.data.controller.datanode.get.v3","Time taken to get data node" "cps.delta.controller.get.delta","Time taken to get delta between anchors" "cps.delta.controller.get.delta","Time taken to get delta between anchors" "cps.module.persistence.schemaset.create","Time taken to store a schemaset (list of module references)" diff --git a/k6-tests/README.md b/k6-tests/README.md index 84c5e032af..44ad00240b 100644 --- a/k6-tests/README.md +++ b/k6-tests/README.md @@ -12,16 +12,16 @@ There are two test profiles that can be run with either: kpi or endurance. Run the main script. (The script assumes k6 and the relevant docker-compose have been installed). ```shell -./run-k6-tests.sh kpi +./k6-main.sh kpi ``` ## Running k6 tests manually Before running tests, ensure CPS/NCMP is running: ```shell -docker-compose -f docker-compose/cps-base.yml up -d +docker-compose -f docker-compose/docker-compose.yml up -d ``` To run an individual test from the command line, use ```shell -k6 run ncmp/ncmp-test-runner.js +k6 run ncmp/scenarios-config.js ``` diff --git a/k6-tests/run-k6-tests.sh b/k6-tests/k6-main.sh similarity index 96% rename from k6-tests/run-k6-tests.sh rename to k6-tests/k6-main.sh index 6c2416b9d8..bc023d6051 100755 --- a/k6-tests/run-k6-tests.sh +++ b/k6-tests/k6-main.sh @@ -45,7 +45,7 @@ echo "Test profile provided: $testProfile" # Run k6 test suite. ./setup.sh "$testProfile" -./ncmp/run-all-tests.sh "$testProfile" +./ncmp/execute-k6-scenarios.sh "$testProfile" NCMP_RESULT=$? # Note that the final steps are done in on_exit function after this exit! diff --git a/k6-tests/make-logs.sh b/k6-tests/make-logs.sh old mode 100644 new mode 100755 diff --git a/k6-tests/ncmp/config/kpi.json b/k6-tests/ncmp/config/kpi.json index 5f10053121..13aba8ccc0 100644 --- a/k6-tests/ncmp/config/kpi.json +++ b/k6-tests/ncmp/config/kpi.json @@ -171,4 +171,3 @@ }, "thresholds": "#SCENARIO-THRESHOLDS#" } - diff --git a/k6-tests/ncmp/run-all-tests.sh b/k6-tests/ncmp/execute-k6-scenarios.sh similarity index 97% rename from k6-tests/ncmp/run-all-tests.sh rename to k6-tests/ncmp/execute-k6-scenarios.sh index 7df8a7a2f9..b050764a7e 100755 --- a/k6-tests/ncmp/run-all-tests.sh +++ b/k6-tests/ncmp/execute-k6-scenarios.sh @@ -31,7 +31,7 @@ testProfile=$1 summaryFile="${testProfile}Summary.csv" KPI_METADATA_FILE="./config/test-kpi-metadata.json" KPI_CONFIG_FILE="./config/kpi.json" -NCMP_RUNNER_FILE="ncmp-test-runner.js" +SCENARIOS_CONFIG_SCRIPT="scenarios-config.js" echo echo "📢 Running NCMP K6 performance test for profile: [$testProfile]" @@ -87,9 +87,9 @@ awk -v trends="$trend_declarations" ' print $0 } } -' "$NCMP_RUNNER_FILE" > "$TMP_FILE" -mv "$TMP_FILE" "$NCMP_RUNNER_FILE" -echo "✅ Trend declarations inserted into [$NCMP_RUNNER_FILE]" +' "$SCENARIOS_CONFIG_SCRIPT" > "$TMP_FILE" +mv "$TMP_FILE" "$SCENARIOS_CONFIG_SCRIPT" +echo "✅ Trend declarations inserted into [$SCENARIOS_CONFIG_SCRIPT]" # If profile is KPI, generate threshold config too if [[ "$testProfile" == "kpi" ]]; then @@ -108,7 +108,7 @@ fi # ───────────────────────────────────────────────────────────── # 2️⃣ Run K6 and Capture Output # ───────────────────────────────────────────────────────────── -k6 run ncmp-test-runner.js -e TEST_PROFILE="$testProfile" > "$summaryFile" +k6 run scenarios-config.js -e TEST_PROFILE="$testProfile" > "$summaryFile" k6_exit_code=$? case $k6_exit_code in diff --git a/k6-tests/ncmp/ncmp-test-runner.js b/k6-tests/ncmp/scenarios-config.js similarity index 100% rename from k6-tests/ncmp/ncmp-test-runner.js rename to k6-tests/ncmp/scenarios-config.js diff --git a/k6-tests/setup.sh b/k6-tests/setup.sh index 2dba82b569..a2a6dfe0fd 100755 --- a/k6-tests/setup.sh +++ b/k6-tests/setup.sh @@ -25,7 +25,6 @@ testProfile=$1 # Set ENV and COMPOSE file paths ENV_FILE="../docker-compose/env/${testProfile}.env" -COMPOSE_FILE="../docker-compose/cps-base.yml" # Load environment variables from the selected .env file set -o allexport @@ -48,7 +47,7 @@ check_images "${IMAGES_TO_CHECK[@]}" # Define a function to encapsulate docker-compose command compose() { docker-compose \ - --file "$COMPOSE_FILE" \ + --file "../docker-compose/docker-compose.yml" \ --env-file "$ENV_FILE" \ --project-name "$testProfile" "$@" } diff --git a/k6-tests/teardown.sh b/k6-tests/teardown.sh index 0f89652f1e..0ee8af6b3e 100755 --- a/k6-tests/teardown.sh +++ b/k6-tests/teardown.sh @@ -23,37 +23,34 @@ chmod +x make-logs.sh ./make-logs.sh testProfile=$1 -docker_compose_shutdown_cmd="docker-compose -f ../docker-compose/cps-base.yml --project-name $testProfile down --volumes" -remove_onap_docker_images_cmd="docker images | grep "onap" | awk '{print $3}' | xargs docker rmi" +docker_compose_shutdown_cmd="docker-compose -f ../docker-compose/docker-compose.yml --project-name $testProfile down --volumes" -# Verify number of docker images after deletion on teardown of endurance testing -verify_docker_images() { - no_of_onap_docker_images=$(docker images | grep "onap" | wc -l) - if [[ "$no_of_onap_docker_images" -eq 0 ]]; then - echo "Successfully removed ONAP docker images!" - else - echo "Removing ONAP docker images failed." - fi +# All CPS docker images: +# nexus3.onap.org:10003/onap/cps-and-ncmp:latest +# nexus3.onap.org:10003/onap/dmi-stub:1.8.0-SNAPSHOT +# nexus3.onap.org:10003/onap/policy-executor-stub:latest +remove_cps_images() { + local cps_image_names=(cps-and-ncmp dmi-stub policy-executor-stub) + for cps_image_name in "${cps_image_names[@]}"; do + local image_path="nexus3.onap.org:10003/onap/$cps_image_name" + # list all image IDs for this repository (all tags) + image_tags=$(docker images -q "$image_path") + if [ -n "$image_tags" ]; then + echo "Removing images for $image_path..." + docker rmi -f $image_tags + fi + done } -# Remove all onap docker images -remove_all_onap_docker_images() { - no_of_onap_docker_images=$(docker images | grep "onap" | wc -l) - if [[ "$no_of_onap_docker_images" -ne 0 ]]; then - echo "Removing all ONAP docker images..." - eval "$remove_onap_docker_images_cmd" - verify_docker_images - fi -} - -# Set an environment variable CLEAN_DOCKER_IMAGES=1 to also remove docker images when done (used on jenkins job) +# Check env. variable CLEAN_DOCKER_IMAGES=1 to decide removing CPS images echo "Stopping, Removing containers and volumes for $testProfile tests..." if [[ "${CLEAN_DOCKER_IMAGES:-0}" -eq 1 ]]; then - echo "Also cleaning up all images" - eval "$docker_compose_shutdown_cmd --rmi all" - if [[ "$testProfile" == "endurance" ]]; then - remove_all_onap_docker_images - fi + # down the compose stack, then purge any remaining CPS images, + # regardless of any test profile! + eval "$docker_compose_shutdown_cmd" + echo "Also cleaning up all CPS images" + remove_cps_images else + # for local test operations eval "$docker_compose_shutdown_cmd" fi diff --git a/test-tools/perf-test-ncmp-passthrough-read.sh b/test-tools/perf-test-ncmp-passthrough-read.sh index 08790629cc..775f933db4 100755 --- a/test-tools/perf-test-ncmp-passthrough-read.sh +++ b/test-tools/perf-test-ncmp-passthrough-read.sh @@ -33,8 +33,8 @@ WARMUP_REQUESTS=600 MEASUREMENT_REQUESTS=240 SCRIPT_DIR=$(dirname -- "${BASH_SOURCE[0]}") -# Read DMI delay from cps-base.yml -DMI_DATA_DELAY=$(grep 'DATA_FOR_CM_HANDLE_DELAY_MS:' "$SCRIPT_DIR"/../docker-compose/cps-base.yml | grep -oE '[0-9]+') +# Read DMI delay from docker-compose.yml +READ_DATA_FOR_CM_HANDLE_DELAY_MS=$(grep 'READ_DATA_FOR_CM_HANDLE_DELAY_MS:' "$SCRIPT_DIR"/../docker-compose/docker-compose.yml | grep -oE '[0-9]+') function cmHandleExists() { local cmHandleId=$1 @@ -79,9 +79,9 @@ measureAverageResponseTimeInMillis "$WARMUP_REQUESTS" > /dev/null # Measure performance echo "Measuring average time of $MEASUREMENT_REQUESTS total requests, sending $PARALLEL_REQUESTS requests in parallel" ncmpResponseTime=$(measureAverageResponseTimeInMillis "$MEASUREMENT_REQUESTS") -ncmpOverhead=$(echo "$ncmpResponseTime - $DMI_DATA_DELAY" | bc) +ncmpOverhead=$(echo "$ncmpResponseTime - $READ_DATA_FOR_CM_HANDLE_DELAY_MS" | bc) # Report performance echo "Average response time from NCMP: $ncmpResponseTime ms" -echo "Average response time from DMI: $DMI_DATA_DELAY ms" +echo "Mocked DMI Read response delay: $READ_DATA_FOR_CM_HANDLE_DELAY_MS ms" echo "NCMP overhead: $ncmpOverhead ms"