Clean up setup and teardown processes for k6 tests 97/141397/9
authorhalil.cakal <halil.cakal@est.tech>
Thu, 26 Jun 2025 13:37:49 +0000 (14:37 +0100)
committerhalil.cakal <halil.cakal@est.tech>
Fri, 4 Jul 2025 14:17:13 +0000 (15:17 +0100)
- 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 <halil.cakal@est.tech>
14 files changed:
csit/plans/cps/setup.sh
docker-compose/README.md
docker-compose/dmi-services.yml
docker-compose/docker-compose.yml [moved from docker-compose/cps-base.yml with 92% similarity]
docs/csv/metrics.csv
k6-tests/README.md
k6-tests/k6-main.sh [moved from k6-tests/run-k6-tests.sh with 96% similarity]
k6-tests/make-logs.sh [changed mode: 0644->0755]
k6-tests/ncmp/config/kpi.json
k6-tests/ncmp/execute-k6-scenarios.sh [moved from k6-tests/ncmp/run-all-tests.sh with 97% similarity]
k6-tests/ncmp/scenarios-config.js [moved from k6-tests/ncmp/ncmp-test-runner.js with 100% similarity]
k6-tests/setup.sh
k6-tests/teardown.sh
test-tools/perf-test-ncmp-passthrough-read.sh

index b16a07d..b7e21bc 100755 (executable)
@@ -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.
index 91f0bc5..c1bbb4e 100644 (file)
@@ -49,23 +49,23 @@ mvn clean install -P<docker-profile>
 
 ## 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.
index 9288400..6e323c1 100644 (file)
 
 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
similarity index 92%
rename from docker-compose/cps-base.yml
rename to docker-compose/docker-compose.yml
index f3fe4f9..e9fd9da 100644 (file)
 
 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
 
index 25925dc..c5f7391 100644 (file)
@@ -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)"
index 84c5e03..44ad002 100644 (file)
@@ -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
 ```
similarity index 96%
rename from k6-tests/run-k6-tests.sh
rename to k6-tests/k6-main.sh
index 6c2416b..bc023d6 100755 (executable)
@@ -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!
old mode 100644 (file)
new mode 100755 (executable)
index 5f10053..13aba8c 100644 (file)
   },
   "thresholds": "#SCENARIO-THRESHOLDS#"
 }
-
similarity index 97%
rename from k6-tests/ncmp/run-all-tests.sh
rename to k6-tests/ncmp/execute-k6-scenarios.sh
index 7df8a7a..b050764 100755 (executable)
@@ -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
index 2dba82b..a2a6dfe 100755 (executable)
@@ -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" "$@"
 }
index 0f89652..0ee8af6 100755 (executable)
@@ -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
index 0879062..775f933 100755 (executable)
@@ -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"