3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020 Nordix Foundation. All rights reserved.
5 # ========================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=================================================
20 # This is a script that contains all the common functions needed for auto test.
21 # Specific test function are defined in scripts XXXX_functions.sh
24 # List of short names for all supported apps, including simulators etc
25 APP_SHORT_NAMES="PA RICSIM SDNC CP ECS RC CBS CONSUL RC MRSTUB CR PRODSTUB"
28 echo "Args: remote|remote-remove --env-file <environment-filename> [release] [auto-clean] [--stop-at-error] "
29 echo " [--ricsim-prefix <prefix> ] [--use-local-image <app-nam>+] [--use-snapshot-image <app-nam>+]"
30 echo " [--use-staging-image <app-nam>+] [--use-release-image <app-nam>+]"
33 if [ $# -eq 1 ] && [ "$1" == "help" ]; then
35 if [ ! -z "$TC_ONELINE_DESCR" ]; then
36 echo "Test script description:"
37 echo $TC_ONELINE_DESCR
42 echo "remote - Use images from remote repositories. Can be overridden for individual images using the '--use_xxx' flags"
43 echo "remote-remove - Same as 'remote' but will also try to pull fresh images from remote repositories"
44 echo "--env-file - The script will use the supplied file to read environment variables from"
45 echo "release - If this flag is given the script will use release version of the images"
46 echo "auto-clean - If the function 'auto_clean_containers' is present in the end of the test script then all containers will be stopped and removed. If 'auto-clean' is not given then the function has no effect."
47 echo "--stop-at-error - The script will stop when the first failed test or configuration"
48 echo "--ricsim-prefix - The a1 simulator will use the supplied string as container prefix instead of 'ricsim'"
49 echo "--use-local-image - The script will use local images for the supplied apps, space separated list of app short names"
50 echo "--use-snapshot-image - The script will use images from the nexus snapshot repo for the supplied apps, space separated list of app short names"
51 echo "--use-staging-image - The script will use images from the nexus staging repo for the supplied apps, space separated list of app short names"
52 echo "--use-release-image - The script will use images from the nexus release repo for the supplied apps, space separated list of app short names"
54 echo "List of app short names supported: "$APP_SHORT_NAMES
60 # Create a test case id, ATC (Auto Test Case), from the name of the test case script.
61 # FTC1.sh -> ATC == FTC1
62 ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
64 #Create result file (containing '1' for error) for this test case
65 #Will be replaced with a file containing '0' if all test cases pass
66 echo "1" > "$PWD/.result$ATC.txt"
68 #Formatting for 'echo' cmd
73 GREEN="\033[32m\033[1m"
75 YELLOW="\033[33m\033[1m"
80 if [ $? -ne 0 ] || [ -z tmp ]; then
81 echo -e $RED"python3 is required to run the test environment, pls install"$ERED
85 if [ $? -ne 0 ] || [ -z tmp ]; then
86 echo -e $RED"docker is required to run the test environment, pls install"$ERED
90 tmp=$(which docker-compose)
91 if [ $? -ne 0 ] || [ -z tmp ]; then
92 echo -e $RED"docker-compose is required to run the test environment, pls install"$ERED
96 # Just resetting any previous echo formatting...
99 # default test environment variables
102 echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@
105 LOCALHOST="http://localhost:"
107 # Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
110 # Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
113 # Var to contol if the agent runs in a container (normal = 0) or as application on the local machine ( = 1)
116 # Var to hold 'auto' in case containers shall be stopped when test case ends
119 # Var to hold the app names to use local images for
122 # Var to hold the app names to use remote snapshot images for
123 USE_SNAPSHOT_IMAGES=""
125 # Var to hold the app names to use remote staging images for
126 USE_STAGING_IMAGES=""
128 # Var to hold the app names to use remote release images for
129 USE_RELEASE_IMAGES=""
131 # List of available apps to override with local or remote staging/snapshot/release image
132 AVAILABLE_IMAGES_OVERRIDE="PA ECS CP SDNC RICSIM RC"
134 # Use this var (STOP_AT_ERROR=1 in the test script) for debugging/trouble shooting to take all logs and exit at first FAIL test case
137 # The default value "DEV" indicate that development image tags (SNAPSHOT) and nexus repos (nexus port 10002) are used.
138 # The value "RELEASE" indicate that relase image tag and nexus repos (nexus port) are used
139 # Applies only to images defined in the test-env files with image names and tags defined as XXXX_RELEASE
142 # Function to indent cmd output with one space
143 indent1() { sed 's/^/ /'; }
145 # Function to indent cmd output with two spaces
146 indent2() { sed 's/^/ /'; }
148 # Set a description string for the test case
149 if [ -z "$TC_ONELINE_DESCR" ]; then
150 TC_ONELINE_DESCR="<no-description>"
151 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
154 # Counter for test suites
155 if [ -f .tmp_tcsuite_ctr ]; then
156 tmpval=$(< .tmp_tcsuite_ctr)
158 echo $tmpval > .tmp_tcsuite_ctr
161 # Create the logs dir if not already created in the current dir
162 if [ ! -d "logs" ]; then
167 # Create the tmp dir for temporary files that is not needed after the test
168 # hidden files for the test env is still stored in the current dir
169 if [ ! -d "tmp" ]; then
173 # Create a http message log for this testcase
174 HTTPLOG=$PWD"/.httplog_"$ATC".txt"
178 # Create a log dir for the test case
179 mkdir -p $TESTLOGS/$ATC
181 # Save create for current logs
182 mkdir -p $TESTLOGS/$ATC/previous
184 rm $TESTLOGS/$ATC/previous/*.log &> /dev/null
185 rm $TESTLOGS/$ATC/previous/*.txt &> /dev/null
186 rm $TESTLOGS/$ATC/previous/*.json &> /dev/null
188 mv $TESTLOGS/$ATC/*.log $TESTLOGS/$ATC/previous &> /dev/null
189 mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
190 mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
192 # Clear the log dir for the test case
193 rm $TESTLOGS/$ATC/*.log &> /dev/null
194 rm $TESTLOGS/$ATC/*.txt &> /dev/null
195 rm $TESTLOGS/$ATC/*.json &> /dev/null
197 # Log all output from the test case to a TC log
198 TCLOG=$TESTLOGS/$ATC/TC.log
199 exec &> >(tee ${TCLOG})
201 #Variables for counting tests as well as passed and failed tests
208 #File to keep deviation messages
209 DEVIATION_FILE=".tmp_deviations"
210 rm $DEVIATION_FILE &> /dev/null
213 # Trap "command not found" and make the script fail
216 if [ $? -eq 127 ]; then
217 echo -e $RED"Function not found, setting script to FAIL"$ERED
227 TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
228 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ $EBOLD
229 echo "TEST $TEST_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ >> $HTTPLOG
231 ((TEST_SEQUENCE_NR++))
234 __log_test_fail_general() {
235 echo -e $RED" FAIL."$1 $ERED
237 __check_stop_at_error
240 __log_test_fail_status_code() {
241 echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED
243 __check_stop_at_error
246 __log_test_fail_body() {
247 echo -e $RED" FAIL, returned body not correct"$ERED
249 __check_stop_at_error
252 __log_test_fail_not_supported() {
253 echo -e $RED" FAIL, function not supported"$ERED
255 __check_stop_at_error
259 if [ $# -gt 0 ]; then
263 echo -e $GREEN" PASS"$EGREEN
266 #Counter for configurations
269 TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
270 echo -e $BOLD"CONF $CONF_SEQUENCE_NR (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ $EBOLD
271 echo "CONF $CONF_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ >> $HTTPLOG
272 ((CONF_SEQUENCE_NR++))
275 __log_conf_fail_general() {
276 echo -e $RED" FAIL."$1 $ERED
278 __check_stop_at_error
281 __log_conf_fail_status_code() {
282 echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED
284 __check_stop_at_error
287 __log_conf_fail_body() {
288 echo -e $RED" FAIL, returned body not correct"$ERED
290 __check_stop_at_error
294 if [ $# -gt 0 ]; then
297 echo -e $GREEN" OK"$EGREEN
300 #Var for measuring execution time
301 TCTEST_START=$SECONDS
303 #File to save timer measurement results
304 TIMER_MEASUREMENTS=".timer_measurement.txt"
305 echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS
308 echo "-------------------------------------------------------------------------------------------------"
309 echo "----------------------------------- Test case: "$ATC
310 echo "----------------------------------- Started: "$(date)
311 echo "-------------------------------------------------------------------------------------------------"
312 echo "-- Description: "$TC_ONELINE_DESCR
313 echo "-------------------------------------------------------------------------------------------------"
314 echo "----------------------------------- Test case setup -----------------------------------"
319 if [ $# -lt 1 ]; then
322 if [ $paramerror -eq 0 ]; then
323 if [ "$1" != "remote" ] && [ "$1" != "remote-remove" ]; then
325 if [ -z "$paramerror_str" ]; then
326 paramerror_str="First arg shall be 'remote' or 'remote-remove'"
333 while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do
335 if [ $paramerror -eq 0 ]; then
336 if [ "$1" == "release" ]; then
337 IMAGE_CATEGORY="RELEASE"
338 echo "Option set - Release image tags used for applicable images "
343 if [ $paramerror -eq 0 ]; then
344 if [ "$1" == "auto-clean" ]; then
346 echo "Option set - Auto clean at end of test script"
351 if [ $paramerror -eq 0 ]; then
352 if [ "$1" == "--stop-at-error" ]; then
354 echo "Option set - Stop at first error"
359 if [ $paramerror -eq 0 ]; then
360 if [ "$1" == "--ricsim-prefix" ]; then
365 if [ -z "$paramerror_str" ]; then
366 paramerror_str="No prefix found for flag: '--ricsim-prefix'"
369 echo "Option set - Overriding RIC_SIM_PREFIX with: "$1
375 if [ $paramerror -eq 0 ]; then
376 if [ "$1" == "--env-file" ]; then
381 if [ -z "$paramerror_str" ]; then
382 paramerror_str="No env file found for flag: '--env-file'"
385 echo "Option set - Reading test env from: "$1
391 if [ $paramerror -eq 0 ]; then
392 if [ "$1" == "--use-local-image" ]; then
395 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
396 USE_LOCAL_IMAGES=$USE_LOCAL_IMAGES" "$1
397 if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
399 if [ -z "$paramerror_str" ]; then
400 paramerror_str="App name $1 is not available for local override for flag: '--use-local-image'"
406 if [ -z "$USE_LOCAL_IMAGES" ]; then
408 if [ -z "$paramerror_str" ]; then
409 paramerror_str="No app name found for flag: '--use-local-image'"
412 echo "Option set - Overriding with local images for app(s):"$USE_LOCAL_IMAGES
416 if [ $paramerror -eq 0 ]; then
417 if [ "$1" == "--use-snapshot-image" ]; then
418 USE_SNAPSHOT_IMAGES=""
420 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
421 USE_SNAPSHOT_IMAGES=$USE_SNAPSHOT_IMAGES" "$1
422 if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
424 if [ -z "$paramerror_str" ]; then
425 paramerror_str="App name $1 is not available for snapshot override for flag: '--use-snapshot-image'"
431 if [ -z "$USE_SNAPSHOT_IMAGES" ]; then
433 if [ -z "$paramerror_str" ]; then
434 paramerror_str="No app name found for flag: '--use-snapshot-image'"
437 echo "Option set - Overriding with snapshot images for app(s):"$USE_SNAPSHOT_IMAGES
441 if [ $paramerror -eq 0 ]; then
442 if [ "$1" == "--use-staging-image" ]; then
443 USE_STAGING_IMAGES=""
445 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
446 USE_STAGING_IMAGES=$USE_STAGING_IMAGES" "$1
447 if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
449 if [ -z "$paramerror_str" ]; then
450 paramerror_str="App name $1 is not available for staging override for flag: '--use-staging-image'"
456 if [ -z "$USE_STAGING_IMAGES" ]; then
458 if [ -z "$paramerror_str" ]; then
459 paramerror_str="No app name found for flag: '--use-staging-image'"
462 echo "Option set - Overriding with staging images for app(s):"$USE_STAGING_IMAGES
466 if [ $paramerror -eq 0 ]; then
467 if [ "$1" == "--use-release-image" ]; then
468 USE_RELEASE_IMAGES=""
470 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
471 USE_RELEASE_IMAGES=$USE_RELEASE_IMAGES" "$1
472 if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
474 if [ -z "$paramerror_str" ]; then
475 paramerror_str="App name $1 is not available for release override for flag: '--use-release-image'"
481 if [ -z "$USE_RELEASE_IMAGES" ]; then
483 if [ -z "$paramerror_str" ]; then
484 paramerror_str="No app name found for flag: '--use-release-image'"
487 echo "Option set - Overriding with release images for app(s):"$USE_RELEASE_IMAGES
495 if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
497 if [ -z "$paramerror_str" ]; then
498 paramerror_str="Unknown parameter(s): "$@
502 if [ $paramerror -eq 1 ]; then
503 echo -e $RED"Incorrect arg list: "$paramerror_str$ERED
508 # sourcing the selected env variables for the test case
509 if [ -f "$TEST_ENV_VAR_FILE" ]; then
510 echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD
513 if [ -z "$TEST_ENV_PROFILE" ] || [ -z "$SUPPORTED_PROFILES" ]; then
514 echo -e $YELLOW"This test case may not work with selected test env file. TEST_ENV_PROFILE is missing in test_env file or SUPPORTED_PROFILES is missing in test case file"$EYELLOW
516 if [[ "$SUPPORTED_PROFILES" == *"$TEST_ENV_PROFILE"* ]]; then
517 echo -e $GREEN"Test case support the selected test env file"$EGREEN
519 echo -e $RED"Test case does not support the selected test env file"$ERED
520 echo "Profile: "$TEST_ENV_PROFILE" Supported profiles: "$SUPPORTED_PROFILES
521 echo -e $RED"Exiting...."$ERED
526 echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED
527 echo " Select one of following env var file matching the intended target of the test"
528 echo " Restart the test using the flag '--env-file <path-to-env-file>"
529 ls ../common/test_env* | indent1
533 if [ -z "$PROJECT_IMAGES_APP_NAMES" ]; then
534 echo -e $RED"Var PROJECT_IMAGES_APP_NAMES must be defined in: "$TEST_ENV_VAR_FILE$ERED$ERED
539 #Vars for A1 interface version and container count
551 # Vars to switch between http and https. Extra curl flag needed for https
552 export RIC_SIM_HTTPX="http"
553 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
554 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
555 export RIC_SIM_CERT_MOUNT_DIR="./cert"
557 export MR_HTTPX="http"
558 export MR_PORT=$MR_INTERNAL_PORT
559 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker net
561 export CR_HTTPX="http"
562 export CR_PORT=$CR_INTERNAL_PORT
563 export CR_LOCAL_PORT=$CR_EXTERNAL_PORT #When CR is running outside the docker net
564 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
566 export PROD_STUB_HTTPX="http"
567 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
568 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT #When Prodstub is running outside the docker net
569 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
571 export SDNC_HTTPX="http"
572 export SDNC_PORT=$SDNC_INTERNAL_PORT
573 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net
575 export RAPP_CAT_HTTPX="http"
576 export RAPP_CAT_PORT=$RAPP_CAT_INTERNAL_PORT
577 export RAPP_CAT_LOCAL_PORT=$RAPP_CAT_EXTERNAL_PORT #When Rapp catalogue is running outside the docker net
579 echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
581 #Temp var to check for image variable name errors
583 #Create a file with image info for later printing as a table
584 image_list_file="./tmp/.image-list"
585 echo -e " Container\tImage\ttag\ttag-switch" > $image_list_file
587 # Check if image env var is set and if so export the env var with image to use (used by docker compose files)
588 # arg: <image name> <target-variable-name> <image-variable-name> <image-tag-variable-name> <tag-suffix> <app-short-name>
589 __check_and_create_image_var() {
590 if [ $# -ne 6 ]; then
591 echo "Expected arg: <image name> <target-variable-name> <image-variable-name> <image-tag-variable-name> <tag-suffix> <app-short-name>"
595 __check_included_image $6
596 if [ $? -ne 0 ]; then
597 echo -e "$1\t<image-excluded>\t<no-tag>" >> $image_list_file
598 # Image is excluded since the corresponding app is not used in this test
602 #Create var from the input var names
607 if [ -z $image ]; then
608 echo -e $RED"\$"$3" not set in $TEST_ENV_VAR_FILE"$ERED
611 tmp=$tmp"<no-image>\t"
613 #Add repo depending on image type
614 if [ "$5" == "REMOTE_RELEASE" ]; then
615 image=$NEXUS_RELEASE_REPO$image
617 if [ "$5" == "REMOTE" ]; then
618 image=$NEXUS_STAGING_REPO$image
620 if [ "$5" == "REMOTE_SNAPSHOT" ]; then
621 image=$NEXUS_SNAPSHOT_REPO$image
623 if [ "$5" == "REMOTE_PROXY" ]; then
624 image=$NEXUS_PROXY_REPO$image
626 if [ "$5" == "REMOTE_RELEASE_ONAP" ]; then
627 image=$NEXUS_RELEASE_REPO_ONAP$image
629 if [ "$5" == "REMOTE_RELEASE_ORAN" ]; then
630 image=$NEXUS_RELEASE_REPO_ORAN$image
632 #No nexus repo added for local images, tag: LOCAL
636 echo -e $RED"\$"$tmptag" not set in $TEST_ENV_VAR_FILE"$ERED
644 echo -e "$tmp" >> $image_list_file
646 export "${2}"=$image":"$tag
649 # Check if app uses image included in this test run
650 # Returns 0 if image is included, 1 if not
651 # Possible IDs for image inclusion: CBS, CONSUL, CP, CR, ECS, MR, PA, PRODSTUB, RICSIM, SDNC
652 __check_included_image() {
653 for im in $INCLUDED_IMAGES; do
654 if [ "$1" == "$im" ]; then
661 __check_image_local_override() {
662 for im in $USE_LOCAL_IMAGES; do
663 if [ "$1" == "$im" ]; then
670 # Check if app uses image override
671 # Returns the image/tag suffix LOCAL for local image or REMOTE/REMOTE_RELEASE/REMOTE_SNAPSHOT for staging/release/snapshot image
672 __check_image_override() {
674 for im in $ORAN_IMAGES_APP_NAMES; do
675 if [ "$1" == "$im" ]; then
676 echo "REMOTE_RELEASE_ORAN"
681 for im in $ONAP_IMAGES_APP_NAMES; do
682 if [ "$1" == "$im" ]; then
683 echo "REMOTE_RELEASE_ONAP"
689 for im in $PROJECT_IMAGES_APP_NAMES; do
690 if [ "$1" == "$im" ]; then
695 if [ $found -eq 0 ]; then
701 if [ $IMAGE_CATEGORY == "RELEASE" ]; then
702 suffix="REMOTE_RELEASE"
704 if [ $IMAGE_CATEGORY == "DEV" ]; then
708 for im in $USE_STAGING_IMAGES; do
709 if [ "$1" == "$im" ]; then
714 for im in $USE_RELEASE_IMAGES; do
715 if [ "$1" == "$im" ]; then
716 suffix="REMOTE_RELEASE"
720 for im in $USE_SNAPSHOT_IMAGES; do
721 if [ "$1" == "$im" ]; then
722 suffix="REMOTE_SNAPSHOT"
726 for im in $USE_LOCAL_IMAGES; do
727 if [ "$1" == "$im" ]; then
733 if [ $CTR -gt 1 ]; then
739 # Check that image env setting are available
743 IMAGE_SUFFIX=$(__check_image_override 'PA')
744 if [ $? -ne 0 ]; then
745 echo -e $RED"Image setting from cmd line not consistent for PA."$ERED
748 __check_and_create_image_var " Policy Agent" "POLICY_AGENT_IMAGE" "POLICY_AGENT_IMAGE_BASE" "POLICY_AGENT_IMAGE_TAG" $IMAGE_SUFFIX PA
750 #Remote Control Panel image
751 IMAGE_SUFFIX=$(__check_image_override 'CP')
752 if [ $? -ne 0 ]; then
753 echo -e $RED"Image setting from cmd line not consistent for CP."$ERED
756 __check_and_create_image_var " Control Panel" "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_IMAGE_BASE" "CONTROL_PANEL_IMAGE_TAG" $IMAGE_SUFFIX CP
759 IMAGE_SUFFIX=$(__check_image_override 'SDNC')
760 if [ $? -ne 0 ]; then
761 echo -e $RED"Image setting from cmd line not consistent for SDNC."$ERED
764 __check_and_create_image_var " SDNC A1 Controller" "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_IMAGE_BASE" "SDNC_A1_CONTROLLER_IMAGE_TAG" $IMAGE_SUFFIX SDNC
766 #Remote ric sim image
767 IMAGE_SUFFIX=$(__check_image_override 'RICSIM')
768 if [ $? -ne 0 ]; then
769 echo -e $RED"Image setting from cmd line not consistent for RICSIM."$ERED
772 __check_and_create_image_var " RIC Simulator" "RIC_SIM_IMAGE" "RIC_SIM_IMAGE_BASE" "RIC_SIM_IMAGE_TAG" $IMAGE_SUFFIX RICSIM
775 IMAGE_SUFFIX=$(__check_image_override 'ECS')
776 if [ $? -ne 0 ]; then
777 echo -e $RED"Image setting from cmd line not consistent for ECS."$EREDs
780 __check_and_create_image_var " ECS" "ECS_IMAGE" "ECS_IMAGE_BASE" "ECS_IMAGE_TAG" $IMAGE_SUFFIX ECS
783 IMAGE_SUFFIX=$(__check_image_override 'RC')
784 if [ $? -ne 0 ]; then
785 echo -e $RED"Image setting from cmd line not consistent for RC."$ERED
788 __check_and_create_image_var " RC" "RAPP_CAT_IMAGE" "RAPP_CAT_IMAGE_BASE" "RAPP_CAT_IMAGE_TAG" $IMAGE_SUFFIX RC
790 # These images are not built as part of this project official images, just check that env vars are set correctly
791 __check_and_create_image_var " Message Router" "MRSTUB_IMAGE" "MRSTUB_IMAGE_BASE" "MRSTUB_IMAGE_TAG" LOCAL MR
792 __check_and_create_image_var " Callback Receiver" "CR_IMAGE" "CR_IMAGE_BASE" "CR_IMAGE_TAG" LOCAL CR
793 __check_and_create_image_var " Producer stub" "PROD_STUB_IMAGE" "PROD_STUB_IMAGE_BASE" "PROD_STUB_IMAGE_TAG" LOCAL PRODSTUB
794 __check_and_create_image_var " Consul" "CONSUL_IMAGE" "CONSUL_IMAGE_BASE" "CONSUL_IMAGE_TAG" REMOTE_PROXY CONSUL
795 __check_and_create_image_var " CBS" "CBS_IMAGE" "CBS_IMAGE_BASE" "CBS_IMAGE_TAG" REMOTE_RELEASE_ONAP CBS
796 __check_and_create_image_var " SDNC DB" "SDNC_DB_IMAGE" "SDNC_DB_IMAGE_BASE" "SDNC_DB_IMAGE_TAG" REMOTE_PROXY SDNC #Uses sdnc app name
798 #Errors in image setting - exit
799 if [ $IMAGE_ERR -ne 0 ]; then
803 #Print a tables of the image settings
804 echo -e $BOLD"Images configured for start arg: "$START $EBOLD
805 column -t -s $'\t' $image_list_file
810 #Set the SIM_GROUP var
811 echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
812 if [ -z "$SIM_GROUP" ]; then
813 SIM_GROUP=$PWD/../simulator-group
814 if [ ! -d $SIM_GROUP ]; then
815 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
816 echo -e $RED"Please set the SIM_GROUP manually in the applicable $TEST_ENV_VAR_FILE"$ERED
819 echo " SIM_GROUP auto set to: " $SIM_GROUP
821 elif [ $SIM_GROUP = *simulator_group ]; then
822 echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check $TEST_ENV_VAR_FILE"$ERED
825 echo " SIM_GROUP env var already set to: " $SIM_GROUP
830 #Temp var to check for image pull errors
833 #Function to check if image exist and stop+remove the container+pull new images as needed
834 #args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
835 __check_and_pull_image() {
837 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
838 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
839 tmp_im=$(docker images --format $format_string ${4})
841 if [ $1 == "local" ]; then
842 if [ -z "$tmp_im" ]; then
843 echo -e " "$2" (local image): \033[1m"$4"\033[0m $RED does not exist in local registry, need to be built (or manually pulled)"$ERED
847 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
849 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
850 if [ $1 == "remote-remove" ]; then
851 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
852 tmp="$(docker ps -aq --filter name=${3})"
853 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
854 docker stop $tmp &> ./tmp/.dockererr
855 if [ $? -ne 0 ]; then
858 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
863 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
864 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
865 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
866 docker rm $tmp &> ./tmp/.dockererr
867 if [ $? -ne 0 ]; then
870 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
875 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
876 # echo -ne " Removing image - ${SAMELINE}"
877 # tmp="$(docker images -q ${4})" &> /dev/null
878 # if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
879 # docker rmi --force $4 &> ./tmp/.dockererr
880 # if [ $? -ne 0 ]; then
883 # echo -e $RED" Image could not be removed - try manual removal of the image"$ERED
884 # cat ./tmp/.dockererr
887 # echo -e " Removing image - "$GREEN"removed"$EGREEN
889 # echo -e " Removing image - "$GREEN"image not in repository"$EGREEN
893 if [ -z "$tmp_im" ]; then
894 echo -ne " Pulling image${SAMELINE}"
895 # docker pull $4 &> ./tmp/.dockererr
896 # tmp_im=$(docker images ${4} | grep -v REPOSITORY)
897 # if [ -z "$tmp_im" ]; then
899 # echo -e " Pulling image -$RED could not be pulled"$ERED
901 # cat ./tmp/.dockererr
904 # echo -e " Pulling image -$GREEN Pulled $EGREEN"
905 out=$(docker pull $4)
906 if [ $? -ne 0 ]; then
908 echo -e " Pulling image -$RED could not be pulled"$ERED
910 echo $out > ./tmp/.dockererr
914 echo $out > ./tmp/.dockererr
915 if [[ $out == *"up to date"* ]]; then
916 echo -e " Pulling image -$GREEN Image is up to date $EGREEN"
917 elif [[ $out == *"Downloaded newer image"* ]]; then
918 echo -e " Pulling image -$GREEN Newer image pulled $EGREEN"
920 echo -e " Pulling image -$GREEN Pulled $EGREEN"
923 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
930 echo -e $BOLD"Pulling configured images, if needed"$EBOLD
932 __check_included_image 'PA'
933 if [ $? -eq 0 ]; then
934 START_ARG_MOD=$START_ARG
935 __check_image_local_override 'PA'
936 if [ $? -eq 1 ]; then
937 START_ARG_MOD="local"
939 app="Policy Agent"; __check_and_pull_image $START_ARG_MOD "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
941 echo -e $YELLOW" Excluding PA image from image check/pull"$EYELLOW
944 __check_included_image 'ECS'
945 if [ $? -eq 0 ]; then
946 START_ARG_MOD=$START_ARG
947 __check_image_local_override 'ECS'
948 if [ $? -eq 1 ]; then
949 START_ARG_MOD="local"
951 app="ECS"; __check_and_pull_image $START_ARG_MOD "$app" $ECS_APP_NAME $ECS_IMAGE
953 echo -e $YELLOW" Excluding ECS image from image check/pull"$EYELLOW
956 __check_included_image 'CP'
957 if [ $? -eq 0 ]; then
958 START_ARG_MOD=$START_ARG
959 __check_image_local_override 'CP'
960 if [ $? -eq 1 ]; then
961 START_ARG_MOD="local"
963 app="Non-RT RIC Control Panel"; __check_and_pull_image $START_ARG_MOD "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
965 echo -e $YELLOW" Excluding Non-RT RIC Control Panel image from image check/pull"$EYELLOW
968 __check_included_image 'RC'
969 if [ $? -eq 0 ]; then
970 START_ARG_MOD=$START_ARG
971 __check_image_local_override 'RC'
972 if [ $? -eq 1 ]; then
973 START_ARG_MOD="local"
975 app="RAPP Catalogue"; __check_and_pull_image $START_ARG_MOD "$app" $RAPP_CAT_APP_NAME $RAPP_CAT_IMAGE
977 echo -e $YELLOW" Excluding RAPP Catalogue image from image check/pull"$EYELLOW
980 __check_included_image 'RICSIM'
981 if [ $? -eq 0 ]; then
982 START_ARG_MOD=$START_ARG
983 __check_image_local_override 'RICSIM'
984 if [ $? -eq 1 ]; then
985 START_ARG_MOD="local"
987 app="Near-RT RIC Simulator"; __check_and_pull_image $START_ARG_MOD "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
989 echo -e $YELLOW" Excluding Near-RT RIC Simulator image from image check/pull"$EYELLOW
993 __check_included_image 'CONSUL'
994 if [ $? -eq 0 ]; then
995 app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
997 echo -e $YELLOW" Excluding Consul image from image check/pull"$EYELLOW
1000 __check_included_image 'CBS'
1001 if [ $? -eq 0 ]; then
1002 app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE
1004 echo -e $YELLOW" Excluding CBS image from image check/pull"$EYELLOW
1007 __check_included_image 'SDNC'
1008 if [ $? -eq 0 ]; then
1009 START_ARG_MOD=$START_ARG
1010 __check_image_local_override 'SDNC'
1011 if [ $? -eq 1 ]; then
1012 START_ARG_MOD="local"
1014 app="SDNC A1 Controller"; __check_and_pull_image $START_ARG_MOD "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
1015 app="SDNC DB"; __check_and_pull_image $START_ARG "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
1017 echo -e $YELLOW" Excluding SDNC image and related DB image from image check/pull"$EYELLOW
1020 #Errors in image setting - exit
1021 if [ $IMAGE_ERR -ne 0 ]; then
1023 echo "#################################################################################################"
1024 echo -e $RED"One or more images could not be pulled or containers using the images could not be stopped/removed"$ERED
1025 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
1026 if [ $IMAGE_CATEGORY == "DEV" ]; then
1027 echo -e $RED"Note that SNAPSHOT images may be purged from nexus after a certain period."$ERED
1028 echo -e $RED"In that case, switch to use a released image instead."$ERED
1030 echo "#################################################################################################"
1037 echo -e $BOLD"Building images needed for test"$EBOLD
1040 __check_included_image 'MR'
1041 if [ $? -eq 0 ]; then
1044 echo " Building mrstub image: $MRSTUB_IMAGE:$MRSTUB_IMAGE_TAG_LOCAL"
1045 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $MRSTUB_IMAGE . &> .dockererr
1046 if [ $? -eq 0 ]; then
1047 echo -e $GREEN" Build Ok"$EGREEN
1049 echo -e $RED" Build Failed"$ERED
1052 echo -e $RED"Exiting...."$ERED
1057 echo -e $YELLOW" Excluding mrstub from image build"$EYELLOW
1060 __check_included_image 'CR'
1061 if [ $? -eq 0 ]; then
1063 echo " Building Callback Receiver image: $CR_IMAGE:$CR_IMAGE_TAG_LOCAL"
1064 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $CR_IMAGE . &> .dockererr
1065 if [ $? -eq 0 ]; then
1066 echo -e $GREEN" Build Ok"$EGREEN
1068 echo -e $RED" Build Failed"$ERED
1071 echo -e $RED"Exiting...."$ERED
1076 echo -e $YELLOW" Excluding Callback Receiver from image build"$EYELLOW
1079 __check_included_image 'PRODSTUB'
1080 if [ $? -eq 0 ]; then
1082 echo " Building Producer stub image: $PROD_STUB_IMAGE:$PROD_STUB_IMAGE_TAG_LOCAL"
1083 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $PROD_STUB_IMAGE . &> .dockererr
1084 if [ $? -eq 0 ]; then
1085 echo -e $GREEN" Build Ok"$EGREEN
1087 echo -e $RED" Build Failed"$ERED
1090 echo -e $RED"Exiting...."$ERED
1095 echo -e $YELLOW" Excluding Producer stub from image build"$EYELLOW
1100 # Create a table of the images used in the script
1101 echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
1103 docker_tmp_file=./tmp/.docker-images-table
1104 format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\\t{{.CreatedAt}}"
1105 echo -e " Application\tRepository\tTag\tCreated since\tSize\tCreated at" > $docker_tmp_file
1106 __check_included_image 'PA'
1107 if [ $? -eq 0 ]; then
1108 echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
1110 __check_included_image 'ECS'
1111 if [ $? -eq 0 ]; then
1112 echo -e " ECS\t$(docker images --format $format_string $ECS_IMAGE)" >> $docker_tmp_file
1114 __check_included_image 'CP'
1115 if [ $? -eq 0 ]; then
1116 echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
1118 __check_included_image 'RICSIM'
1119 if [ $? -eq 0 ]; then
1120 echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
1122 __check_included_image 'RC'
1123 if [ $? -eq 0 ]; then
1124 echo -e " RAPP Catalogue\t$(docker images --format $format_string $RAPP_CAT_IMAGE)" >> $docker_tmp_file
1126 __check_included_image 'MR'
1127 if [ $? -eq 0 ]; then
1128 echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
1130 __check_included_image 'CR'
1131 if [ $? -eq 0 ]; then
1132 echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
1134 __check_included_image 'PRODSTUB'
1135 if [ $? -eq 0 ]; then
1136 echo -e " Producer stub\t$(docker images --format $format_string $PROD_STUB_IMAGE)" >> $docker_tmp_file
1138 __check_included_image 'CONSUL'
1139 if [ $? -eq 0 ]; then
1140 echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
1142 __check_included_image 'CBS'
1143 if [ $? -eq 0 ]; then
1144 echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
1146 __check_included_image 'SDNC'
1147 if [ $? -eq 0 ]; then
1148 echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
1149 echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
1152 column -t -s $'\t' $docker_tmp_file
1156 echo -e $BOLD"======================================================="$EBOLD
1157 echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
1158 echo -e $BOLD"======================================================="$EBOLD
1161 # Function to print the test result, shall be the last cmd in a test script
1163 # (Function for test scripts)
1167 duration=$((TCTEST_END-TCTEST_START))
1169 echo "-------------------------------------------------------------------------------------------------"
1170 echo "------------------------------------- Test case: "$ATC
1171 echo "------------------------------------- Ended: "$(date)
1172 echo "-------------------------------------------------------------------------------------------------"
1173 echo "-- Description: "$TC_ONELINE_DESCR
1174 echo "-- Execution time: " $duration " seconds"
1175 echo "-- Used env file: "$TEST_ENV_VAR_FILE
1176 echo "-------------------------------------------------------------------------------------------------"
1177 echo "------------------------------------- RESULTS"
1181 if [ $RES_DEVIATION -gt 0 ]; then
1182 echo "Test case deviations"
1183 echo "===================================="
1187 echo "Timer measurement in the test script"
1188 echo "===================================="
1189 column -t -s $'\t' $TIMER_MEASUREMENTS
1192 total=$((RES_PASS+RES_FAIL))
1193 if [ $RES_TEST -eq 0 ]; then
1194 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
1195 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
1196 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
1197 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
1198 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
1199 elif [ $total != $RES_TEST ]; then
1200 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
1201 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
1202 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
1203 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
1204 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
1205 elif [ $RES_CONF_FAIL -ne 0 ]; then
1206 echo -e "\033[1mOne or more configure regest has failed. Check the script log....\033[0m"
1207 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
1208 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
1209 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
1210 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
1211 elif [ $RES_PASS = $RES_TEST ]; then
1212 echo -e "All tests \033[32m\033[1mPASS\033[0m"
1213 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
1214 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
1215 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
1216 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
1219 # Update test suite counter
1220 if [ -f .tmp_tcsuite_pass_ctr ]; then
1221 tmpval=$(< .tmp_tcsuite_pass_ctr)
1223 echo $tmpval > .tmp_tcsuite_pass_ctr
1225 if [ -f .tmp_tcsuite_pass ]; then
1226 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
1228 #Create file with OK exit code
1229 echo "0" > "$PWD/.result$ATC.txt"
1231 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
1232 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
1233 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
1234 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
1235 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
1237 # Update test suite counter
1238 if [ -f .tmp_tcsuite_fail_ctr ]; then
1239 tmpval=$(< .tmp_tcsuite_fail_ctr)
1241 echo $tmpval > .tmp_tcsuite_fail_ctr
1243 if [ -f .tmp_tcsuite_fail ]; then
1244 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
1248 echo "++++ Number of tests: "$RES_TEST
1249 echo "++++ Number of passed tests: "$RES_PASS
1250 echo "++++ Number of failed tests: "$RES_FAIL
1252 echo "++++ Number of failed configs: "$RES_CONF_FAIL
1254 echo "++++ Number of test case deviations: "$RES_DEVIATION
1256 echo "------------------------------------- Test case complete ---------------------------------"
1257 echo "-------------------------------------------------------------------------------------------------"
1261 #####################################################################
1262 ###### Functions for start, configuring, stoping, cleaning etc ######
1263 #####################################################################
1265 # Start timer for time measurement
1266 # args - (any args will be printed though)
1268 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1270 echo " Timer started"
1273 # Print the value of the time (in seconds)
1274 # args - <timer message to print> - timer value and message will be printed both on screen
1275 # and in the timer measurement report
1277 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1278 if [ $# -lt 1 ]; then
1280 __print_err "need 1 or more args, <timer message to print>" $@
1283 duration=$(($SECONDS-$TC_TIMER))
1284 if [ $duration -eq 0 ]; then
1285 duration="<1 second"
1287 duration=$duration" seconds"
1289 echo " Timer duration :" $duration
1291 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
1294 # Print the value of the time (in seconds) and reset the timer
1295 # args - <timer message to print> - timer value and message will be printed both on screen
1296 # and in the timer measurement report
1297 print_and_reset_timer() {
1298 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1299 if [ $# -lt 1 ]; then
1301 __print_err "need 1 or more args, <timer message to print>" $@
1304 duration=$(($SECONDS-$TC_TIMER))" seconds"
1305 if [ $duration -eq 0 ]; then
1306 duration="<1 second"
1308 duration=$duration" seconds"
1310 echo " Timer duration :" $duration
1314 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
1317 # Print info about a deviations from intended tests
1318 # Each deviation counted is also printed in the testreport
1319 # args <deviation message to print>
1321 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
1322 if [ $# -lt 1 ]; then
1324 __print_err "need 1 or more args, <deviation message to print>" $@
1328 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
1329 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
1333 # Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
1334 __check_stop_at_error() {
1335 if [ $STOP_AT_ERROR -eq 1 ]; then
1336 echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
1337 store_logs "STOP_AT_ERROR"
1343 # Check if app name var is set. If so return the app name otherwise return "NOTSET"
1344 __check_app_name() {
1345 if [ $# -eq 1 ]; then
1352 # Stop and remove all containers
1354 # (Function for test scripts)
1355 clean_containers() {
1357 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
1359 CONTAINTER_NAMES=("Policy Agent " $(__check_app_name $POLICY_AGENT_APP_NAME)\
1360 "ECS " $(__check_app_name $ECS_APP_NAME)\
1361 "RAPP Catalogue " $(__check_app_name $RAPP_CAT_APP_NAME)\
1362 "Non-RT RIC Simulator(s)" $(__check_app_name $RIC_SIM_PREFIX)\
1363 "Message Router " $(__check_app_name $MR_APP_NAME)\
1364 "Callback Receiver " $(__check_app_name $CR_APP_NAME)\
1365 "Producer stub " $(__check_app_name $PROD_STUB_APP_NAME)\
1366 "Control Panel " $(__check_app_name $CONTROL_PANEL_APP_NAME)\
1367 "SDNC A1 Controller " $(__check_app_name $SDNC_APP_NAME)\
1368 "SDNC DB " $(__check_app_name $SDNC_DB_APP_NAME)\
1369 "CBS " $(__check_app_name $CBS_APP_NAME)\
1370 "Consul " $(__check_app_name $CONSUL_APP_NAME))
1372 nw=0 # Calc max width of container name, to make a nice table
1373 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
1375 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
1376 nw=${#CONTAINTER_NAMES[i]}
1380 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
1381 APP="${CONTAINTER_NAMES[i]}"
1382 CONTR="${CONTAINTER_NAMES[i+1]}"
1383 if [ $CONTR != "NOTSET" ]; then
1384 for((w=${#CONTR}; w<$nw; w=w+1)); do
1387 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
1388 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1389 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
1390 docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1391 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
1397 echo -e $BOLD" Removing docker network"$EBOLD
1398 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
1399 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
1400 docker network rm $DOCKER_SIM_NWNAME | indent2
1401 if [ $? -ne 0 ]; then
1402 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
1406 echo -e "$GREEN Done$EGREEN"
1408 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
1409 docker network prune --force | indent2
1410 echo -e "$GREEN Done$EGREEN"
1412 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
1413 docker volume prune --force | indent2
1414 echo -e "$GREEN Done$EGREEN"
1416 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
1417 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
1418 echo -e "$GREEN Done$EGREEN"
1421 CONTRS=$(docker ps | awk '$1 != "CONTAINER" { n++ }; END { print n+0 }')
1422 if [ $? -eq 0 ]; then
1423 if [ $CONTRS -ne 0 ]; then
1424 echo -e $RED"Containers running, may cause distubance to the test case"$ERED
1425 docker ps -a | indent1
1431 # Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
1433 # (Function for test scripts)
1434 auto_clean_containers() {
1436 if [ "$AUTO_CLEAN" == "auto" ]; then
1437 echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
1442 # Function to sleep a test case for a numner of seconds. Prints the optional text args as info
1443 # args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
1444 # (Function for test scripts)
1447 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1448 if [ $# -lt 1 ]; then
1450 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
1453 #echo "---- Sleep for " $1 " seconds ---- "$2
1455 duration=$((SECONDS-start))
1456 while [ $duration -lt $1 ]; do
1457 echo -ne " Slept for ${duration} seconds${SAMELINE}"
1459 duration=$((SECONDS-start))
1461 echo -ne " Slept for ${duration} seconds${SAMELINE}"
1465 # Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
1466 # Not to be called from the test script itself.
1468 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
1469 if [ $# -gt 1 ]; then
1470 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
1476 # Helper function to get a the port of a specific ric simulatpor
1478 # (Not for test scripts)
1480 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
1481 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
1483 if [[ "$res" =~ ^[0-9]+$ ]]; then
1490 # Function to create the docker network for the test
1491 # Not to be called from the test script itself.
1492 __create_docker_network() {
1493 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
1494 if [ $? -ne 0 ]; then
1495 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
1498 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
1499 echo -e " Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
1500 docker network create $DOCKER_SIM_NWNAME | indent2
1501 if [ $? -ne 0 ]; then
1502 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
1505 echo -e "$GREEN Done$EGREEN"
1508 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
1512 # Check if container is started by calling url on localhost using a port, expects response code 2XX
1513 # args: <container-name> <port> <url> https|https
1514 # Not to be called from the test script itself.
1515 __check_container_start() {
1517 if [ $# -ne 4 ]; then
1519 elif [ $4 != "http" ] && [ $4 != "https" ]; then
1522 if [ $paramError -ne 0 ]; then
1524 __print_err "need 3 args, <container-name> <port> <url> https|https" $@
1527 echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
1531 if [[ $appname != "STANDALONE_"* ]] ; then
1533 for i in {1..10}; do
1534 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
1535 echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
1542 if [ $app_started -eq 0 ]; then
1545 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
1546 echo -e $RED" Stopping script..."$ERED
1549 if [ $localport -eq 0 ]; then
1550 while [ $localport -eq 0 ]; do
1551 echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
1552 localport=$(__find_sim_port $appname)
1554 echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
1556 echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
1562 echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
1564 for i in {1..50}; do
1565 if [ $4 == "https" ]; then
1566 result="$(__do_curl "-k https://localhost:"${localport}${url})"
1568 result="$(__do_curl $LOCALHOST${localport}${url})"
1570 if [ $? -eq 0 ]; then
1571 if [ ${#result} -gt 15 ]; then
1572 #If response is too long, truncate
1573 result="...response text too long, omitted"
1575 echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
1576 echo -ne " Container $BOLD${appname}$EBOLD$GREEN is alive$EGREEN, responds to service status:$GREEN $result $EGREEN after $(($SECONDS-$TSTART)) seconds"
1581 while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
1582 echo -ne " Waiting for container ${appname} service status...$(($SECONDS-$TSTART)) seconds, retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
1588 if [ "$pa_st" = "false" ]; then
1590 echo -e $RED" Container ${appname} did not respond to service status in $(($SECONDS-$TSTART)) seconds"$ERED
1599 # Function to start a container and wait until it responds on the given port and url.
1600 #args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
1601 __start_container() {
1603 variableArgCount=$(($#-2))
1604 if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
1606 __print_err "need 6 or more args, <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> http|https [<app-name> <port-number> <alive-url> http|https ]*" $@
1610 __create_docker_network
1616 if [ "$2" == "NODOCKERARGS" ]; then
1617 docker-compose up -d &> .dockererr
1618 if [ $? -ne 0 ]; then
1619 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1621 echo -e $RED"Stopping script...."$ERED
1624 elif [ "$2" == "STANDALONE" ]; then
1625 echo "Skipping docker-compose"
1627 docker-compose up -d $2 &> .dockererr
1628 if [ $? -ne 0 ]; then
1629 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1631 echo -e $RED"Stopping script...."$ERED
1636 if [ "$2" == "STANDALONE" ]; then
1637 app_prefix="STANDALONE_"
1641 while [ $cntr -lt $variableArgCount ]; do
1642 app=$app_prefix$1; shift;
1648 __check_container_start "$app" "$port" "$url" $httpx
1656 # Generate a UUID to use as prefix for policy ids
1658 UUID=$(python3 -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
1659 #Reduce length to make space for serial id, us 'a' as marker where the serial id is added
1660 UUID=${UUID:0:${#UUID}-4}"a"
1663 ####################
1664 ### Consul functions
1665 ####################
1667 # Function to load config from a file into consul for the Policy Agent
1668 # arg: <json-config-file>
1669 # (Function for test scripts)
1670 consul_config_app() {
1672 echo -e $BOLD"Configuring Consul"$EBOLD
1674 if [ $# -ne 1 ]; then
1676 __print_err "need one arg, <json-config-file>" $@
1680 echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1
1682 curlString="$LOCALHOST${CONSUL_EXTERNAL_PORT}/v1/kv/${POLICY_AGENT_APP_NAME}?dc=dc1 -X PUT -H Accept:application/json -H Content-Type:application/json -H X-Requested-With:XMLHttpRequest --data-binary @"$1
1683 result=$(__do_curl "$curlString")
1684 if [ $? -ne 0 ]; then
1685 echo -e $RED" FAIL - json config could not be loaded to consul" $ERED
1689 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
1690 echo $body > "./tmp/.output"$1
1692 if [ $? -ne 0 ]; then
1693 echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED
1698 targetJson="{\"config\":"$targetJson"}"
1699 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1700 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1701 if [ $res -ne 0 ]; then
1702 echo -e $RED" FAIL - policy json config read from consul/cbs is not equal to the intended json config...." $ERED
1706 echo -e $GREEN" Config loaded ok to consul"$EGREEN
1714 # Function to perpare the consul configuration according to the current simulator configuration
1715 # args: SDNC|NOSDNC <output-file>
1716 # (Function for test scripts)
1717 prepare_consul_config() {
1718 echo -e $BOLD"Prepare Consul config"$EBOLD
1720 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
1722 if [ $# != 2 ]; then
1724 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
1728 if [ $1 == "SDNC" ]; then
1729 echo -e " Config$BOLD including SDNC$EBOLD configuration"
1730 elif [ $1 == "NOSDNC" ]; then
1731 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
1734 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
1739 if [ $1 == "SDNC" ]; then
1740 config_json=$config_json"\n \"controller\": ["
1741 config_json=$config_json"\n {"
1742 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
1743 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1744 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://$SDNC_APP_NAME:$SDNC_PORT\","
1746 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://localhost:$SDNC_LOCAL_PORT\","
1748 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
1749 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
1750 config_json=$config_json"\n }"
1751 config_json=$config_json"\n ],"
1754 config_json=$config_json"\n \"streams_publishes\": {"
1755 config_json=$config_json"\n \"dmaap_publisher\": {"
1756 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1757 config_json=$config_json"\n \"dmaap_info\": {"
1758 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1759 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_WRITE_URL\""
1761 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_WRITE_URL\""
1763 config_json=$config_json"\n }"
1764 config_json=$config_json"\n }"
1765 config_json=$config_json"\n },"
1766 config_json=$config_json"\n \"streams_subscribes\": {"
1767 config_json=$config_json"\n \"dmaap_subscriber\": {"
1768 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1769 config_json=$config_json"\n \"dmaap_info\": {"
1770 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1771 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_READ_URL\""
1773 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_READ_URL\""
1775 config_json=$config_json"\n }"
1776 config_json=$config_json"\n }"
1777 config_json=$config_json"\n },"
1779 config_json=$config_json"\n \"ric\": ["
1781 rics=$(docker ps | grep $RIC_SIM_PREFIX | awk '{print $NF}')
1783 if [ $? -ne 0 ] || [ -z "$rics" ]; then
1784 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
1790 for ric in $rics; do
1791 if [ $cntr -gt 0 ]; then
1792 config_json=$config_json"\n ,"
1794 config_json=$config_json"\n {"
1795 config_json=$config_json"\n \"name\": \"$ric\","
1796 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1797 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
1799 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://localhost:$(__find_sim_port $ric)\","
1801 if [ $1 == "SDNC" ]; then
1802 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
1804 config_json=$config_json"\n \"managedElementIds\": ["
1805 config_json=$config_json"\n \"me1_$ric\","
1806 config_json=$config_json"\n \"me2_$ric\""
1807 config_json=$config_json"\n ]"
1808 config_json=$config_json"\n }"
1812 config_json=$config_json"\n ]"
1813 config_json=$config_json"\n}"
1816 printf "$config_json">$2
1822 # Start Consul and CBS
1824 # (Function for test scripts)
1825 start_consul_cbs() {
1827 echo -e $BOLD"Starting Consul and CBS"$EBOLD
1828 __check_included_image 'CONSUL'
1829 if [ $? -eq 1 ]; then
1830 echo -e $RED"The Consul image has not been checked for this test run due to arg to the test script"$ERED
1831 echo -e $RED"Consul will not be started"$ERED
1834 __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" "http" \
1835 "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck" "http"
1838 ###########################
1839 ### RIC Simulator functions
1840 ###########################
1842 use_simulator_http() {
1843 echo -e $BOLD"RICSIM protocol setting"$EBOLD
1844 echo -e " Using $BOLD http $EBOLD towards the simulators"
1845 export RIC_SIM_HTTPX="http"
1846 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1847 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
1851 use_simulator_https() {
1852 echo -e $BOLD"RICSIM protocol setting"$EBOLD
1853 echo -e " Using $BOLD https $EBOLD towards the simulators"
1854 export RIC_SIM_HTTPX="https"
1855 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1856 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
1860 # Start one group (ricsim_g1, ricsim_g2 .. ricsim_g5) with a number of RIC Simulators using a given A interface
1861 # 'ricsim' may be set on command line to other prefix
1862 # args: ricsim_g1|ricsim_g2|ricsim_g3|ricsim_g4|ricsim_g5 <count> <interface-id>
1863 # (Function for test scripts)
1864 start_ric_simulators() {
1866 echo -e $BOLD"Starting RIC Simulators"$EBOLD
1868 __check_included_image 'RICSIM'
1869 if [ $? -eq 1 ]; then
1870 echo -e $RED"The Near-RT RIC Simulator image has not been checked for this test run due to arg to the test script"$ERED
1871 echo -e $RED"The Near-RT RIC Simulartor(s) will not be started"$ERED
1875 RIC1=$RIC_SIM_PREFIX"_g1"
1876 RIC2=$RIC_SIM_PREFIX"_g2"
1877 RIC3=$RIC_SIM_PREFIX"_g3"
1878 RIC4=$RIC_SIM_PREFIX"_g4"
1879 RIC5=$RIC_SIM_PREFIX"_g5"
1881 if [ $# != 3 ]; then
1883 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
1886 echo " $2 simulators using basename: $1 on interface: $3"
1887 #Set env var for simulator count and A1 interface vesion for the given group
1888 if [ $1 == "$RIC1" ]; then
1891 elif [ $1 == "$RIC2" ]; then
1894 elif [ $1 == "$RIC3" ]; then
1897 elif [ $1 == "$RIC4" ]; then
1900 elif [ $1 == "$RIC5" ]; then
1905 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
1909 # Create .env file to compose project, all ric container will get this prefix
1910 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
1912 export G1_A1_VERSION
1913 export G2_A1_VERSION
1914 export G3_A1_VERSION
1915 export G4_A1_VERSION
1916 export G5_A1_VERSION
1918 docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT --scale g4=$G4_COUNT --scale g5=$G5_COUNT"
1921 while [ $cntr -le $2 ]; do
1924 app_data="$app_data $app $port / "$RIC_SIM_HTTPX
1927 __start_container ric "$docker_args" $app_data
1931 ###########################
1932 ### Control Panel functions
1933 ###########################
1935 # Start the Control Panel container
1937 # (Function for test scripts)
1938 start_control_panel() {
1940 echo -e $BOLD"Starting Control Panel"$EBOLD
1941 __check_included_image 'CP'
1942 if [ $? -eq 1 ]; then
1943 echo -e $RED"The Control Panel image has not been checked for this test run due to arg to the test script"$ERED
1944 echo -e $RED"The Control Panel will not be started"$ERED
1947 __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/" "http"
1951 ###########################
1953 ###########################
1955 # Start the RAPP Catalogue container
1957 # (Function for test scripts)
1958 start_rapp_catalogue() {
1960 echo -e $BOLD"Starting RAPP Catalogue"$EBOLD
1962 __check_included_image 'RC'
1963 if [ $? -eq 1 ]; then
1964 echo -e $RED"The RAPP Catalogue image has not been checked for this test run due to arg to the test script"$ERED
1965 echo -e $RED"The RAPP Catalogue will not be started"$ERED
1968 __start_container rapp_catalogue NODOCKERARGS $RAPP_CAT_APP_NAME $RAPP_CAT_EXTERNAL_PORT "/services" "http"
1971 use_rapp_catalogue_http() {
1972 echo -e $BOLD"RAPP Catalogue protocol setting"$EBOLD
1973 echo -e " Using $BOLD http $EBOLD towards the RAPP Catalogue"
1974 export RAPP_CAT_HTTPX="http"
1975 export RAPP_CAT_PORT=$RAPP_CAT_INTERNAL_PORT
1976 export RAPP_CAT_LOCAL_PORT=$RAPP_CAT_EXTERNAL_PORT
1980 use_rapp_catalogue_https() {
1981 echo -e $BOLD"RAPP Catalogue protocol setting"$EBOLD
1982 echo -e " Using $BOLD https $EBOLD towards the RAPP Catalogue"
1983 export RAPP_CAT_HTTPX="https"
1984 export RAPP_CAT_PORT=$RAPP_CAT_INTERNAL_PORT
1985 export RAPP_CAT_LOCAL_PORT=$RAPP_CAT_EXTERNAL_PORT
1993 # Start the SDNC A1 Controller
1995 # (Function for test scripts)
1998 echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
2000 __check_included_image 'SDNC'
2001 if [ $? -eq 1 ]; then
2002 echo -e $RED"The image for SDNC and the related DB has not been checked for this test run due to arg to the test script"$ERED
2003 echo -e $RED"SDNC will not be started"$ERED
2007 __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT $SDNC_ALIVE_URL "http"
2012 echo -e $BOLD"SDNC protocol setting"$EBOLD
2013 echo -e " Using $BOLD http $EBOLD towards SDNC"
2014 export SDNC_HTTPX="http"
2015 export SDNC_PORT=$SDNC_INTERNAL_PORT
2016 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT
2021 echo -e $BOLD"SDNC protocol setting"$EBOLD
2022 echo -e " Using $BOLD https $EBOLD towards SDNC"
2023 export SDNC_HTTPX="https"
2024 export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT
2025 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT
2029 #####################
2030 ### MR stub functions
2031 #####################
2033 # Start the Message Router stub interface in the simulator group
2035 # (Function for test scripts)
2038 echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
2039 __check_included_image 'MR'
2040 if [ $? -eq 1 ]; then
2041 echo -e $RED"The Message Router image has not been checked for this test run due to arg to the test script"$ERED
2042 echo -e $RED"The Message Router will not be started"$ERED
2045 export MR_CERT_MOUNT_DIR="./cert"
2046 __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/" "http"
2050 echo -e $BOLD"MR protocol setting"$EBOLD
2051 echo -e " Using $BOLD http $EBOLD towards MR"
2052 export MR_HTTPX="http"
2053 export MR_PORT=$MR_INTERNAL_PORT
2054 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT
2059 echo -e $BOLD"MR protocol setting"$EBOLD
2060 echo -e " Using $BOLD https $EBOLD towards MR"
2061 export MR_HTTPX="https"
2062 export MR_PORT=$MR_INTERNAL_SECURE_PORT
2063 export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT
2072 # Start the Callback reciver in the simulator group
2074 # (Function for test scripts)
2077 echo -e $BOLD"Starting Callback Receiver"$EBOLD
2078 __check_included_image 'CR'
2079 if [ $? -eq 1 ]; then
2080 echo -e $RED"The Callback Receiver image has not been checked for this test run due to arg to the test script"$ERED
2081 echo -e $RED"The Callback Receiver will not be started"$ERED
2084 __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/" "http"
2089 echo -e $BOLD"CR protocol setting"$EBOLD
2090 echo -e " Using $BOLD http $EBOLD towards CR"
2091 export CR_HTTPX="http"
2092 export CR_PORT=$CR_INTERNAL_PORT
2093 export CR_LOCAL_PORT=$CR_EXTERNAL_PORT
2094 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
2099 echo -e $BOLD"CR protocol setting"$EBOLD
2100 echo -e " Using $BOLD https $EBOLD towards CR"
2101 export CR_HTTPX="https"
2102 export CR_PORT=$CR_INTERNAL_SECURE_PORT
2103 export CR_LOCAL_PORT=$CR_EXTERNAL_SECURE_PORT
2104 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
2108 ###########################
2109 ### Producer stub functions
2110 ###########################
2112 # Start the Producer stub in the simulator group
2114 # (Function for test scripts)
2117 echo -e $BOLD"Starting Producer stub"$EBOLD
2118 __check_included_image 'PRODSTUB'
2119 if [ $? -eq 1 ]; then
2120 echo -e $RED"The Producer stub image has not been checked for this test run due to arg to the test script"$ERED
2121 echo -e $RED"The Producer stub will not be started"$ERED
2124 __start_container prodstub NODOCKERARGS $PROD_STUB_APP_NAME $PROD_STUB_EXTERNAL_PORT "/" "http"
2128 use_prod_stub_http() {
2129 echo -e $BOLD"Producer stub protocol setting"$EBOLD
2130 echo -e " Using $BOLD http $EBOLD towards Producer stub"
2131 export PROD_STUB_HTTPX="http"
2132 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
2133 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT
2134 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
2138 use_prod_stub_https() {
2139 echo -e $BOLD"Producer stub protocol setting"$EBOLD
2140 echo -e " Using $BOLD https $EBOLD towards Producer stub"
2141 export PROD_STUB_HTTPX="https"
2142 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_SECURE_PORT
2143 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_SECURE_PORT
2144 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
2148 ###########################
2149 ### Policy Agents functions
2150 ###########################
2152 # Use an agent on the local machine instead of container
2153 use_agent_stand_alone() {
2157 # Start the policy agent
2159 # (Function for test scripts)
2160 start_policy_agent() {
2162 echo -e $BOLD"Starting Policy Agent"$EBOLD
2164 if [ $AGENT_STAND_ALONE -eq 0 ]; then
2165 __check_included_image 'PA'
2166 if [ $? -eq 1 ]; then
2167 echo -e $RED"The Policy Agent image has not been checked for this test run due to arg to the test script"$ERED
2168 echo -e $RED"The Policy Agent will not be started"$ERED
2171 __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
2173 echo -e $RED"The consul config produced by this test script (filename '<fullpath-to-autotest-dir>.output<file-name>"$ERED
2174 echo -e $RED"where the file name is the file in the consul_config_app command in this script) must be pointed out by the agent "$ERED
2175 echo -e $RED"application.yaml"$ERED
2176 echo -e $RED"The application jar may need to be built before continuing"$ERED
2177 echo -e $RED"The agent shall now be running on port $POLICY_AGENT_EXTERNAL_PORT for http"$ERED
2179 read -p "<press any key to continue>"
2180 __start_container policy_agent "STANDALONE" $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
2185 # All calls to the agent will be directed to the agent REST interface from now on
2187 # (Function for test scripts)
2188 use_agent_rest_http() {
2189 echo -e $BOLD"Agent protocol setting"$EBOLD
2190 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
2191 export ADAPTER=$RESTBASE
2195 # All calls to the agent will be directed to the agent REST interface from now on
2197 # (Function for test scripts)
2198 use_agent_rest_https() {
2199 echo -e $BOLD"Agent protocol setting"$EBOLD
2200 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
2201 export ADAPTER=$RESTBASE_SECURE
2206 # All calls to the agent will be directed to the agent dmaap interface over http from now on
2208 # (Function for test scripts)
2209 use_agent_dmaap_http() {
2210 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
2211 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
2212 export ADAPTER=$DMAAPBASE
2217 # All calls to the agent will be directed to the agent dmaap interface over https from now on
2219 # (Function for test scripts)
2220 use_agent_dmaap_https() {
2221 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
2222 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
2223 export ADAPTER=$DMAAPBASE_SECURE
2228 # Turn on debug level tracing in the agent
2230 # (Function for test scripts)
2232 echo -e $BOLD"Setting agent debug logging"$EBOLD
2233 actuator="/actuator/loggers/org.oransc.policyagent"
2234 if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
2235 actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
2237 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
2238 result=$(__do_curl "$curlString")
2239 if [ $? -ne 0 ]; then
2240 __print_err "could not set debug mode" $@
2248 # Turn on trace level tracing in the agent
2250 # (Function for test scripts)
2252 echo -e $BOLD"Setting agent trace logging"$EBOLD
2253 actuator="/actuator/loggers/org.oransc.policyagent"
2254 if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
2255 actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
2257 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
2258 result=$(__do_curl "$curlString")
2259 if [ $? -ne 0 ]; then
2260 __print_err "could not set trace mode" $@
2268 # Perform curl retries when making direct call to the agent for the specified http response codes
2269 # Speace separated list of http response codes
2270 # args: [<response-code>]*
2271 use_agent_retries() {
2272 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
2273 AGENT_RETRY_CODES=$@
2278 ###########################
2280 ###########################
2284 # (Function for test scripts)
2287 echo -e $BOLD"Starting ECS"$EBOLD
2292 cd $ECS_HOST_MNT_DIR
2293 if [ -d database ]; then
2294 if [ "$(ls -A $DIR)" ]; then
2295 echo -e $BOLD" Cleaning files in mounted dir: $PWD/database"$EBOLD
2296 rm -rf database/* &> /dev/null
2297 if [ $? -ne 0 ]; then
2298 echo -e $RED" Cannot remove database files in: $PWD"$ERED
2303 echo " No files in mounted dir or dir does not exists"
2307 __check_included_image 'ECS'
2308 if [ $? -eq 1 ]; then
2309 echo -e $RED"The ECS image has not been checked for this test run due to arg to the test script"$ERED
2310 echo -e $RED"ECS will not be started"$ERED
2313 export ECS_CERT_MOUNT_DIR="./cert"
2314 __start_container ecs NODOCKERARGS $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
2319 # (Function for test scripts)
2321 echo -e $BOLD"Re-starting ECS"$EBOLD
2322 docker restart $ECS_APP_NAME &> ./tmp/.dockererr
2323 if [ $? -ne 0 ]; then
2324 __print_err "Could restart $ECS_APP_NAME" $@
2325 cat ./tmp/.dockererr
2330 __check_container_start $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
2335 # All calls to ECS will be directed to the ECS REST interface from now on
2337 # (Function for test scripts)
2338 use_ecs_rest_http() {
2339 echo -e $BOLD"ECS protocol setting"$EBOLD
2340 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
2341 export ECS_ADAPTER=$ECS_RESTBASE
2345 # All calls to ECS will be directed to the ECS REST interface from now on
2347 # (Function for test scripts)
2348 use_ecs_rest_https() {
2349 echo -e $BOLD"ECS protocol setting"$EBOLD
2350 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
2351 export ECS_ADAPTER=$ECS_RESTBASE_SECURE
2356 # All calls to ECS will be directed to the ECS dmaap interface over http from now on
2358 # (Function for test scripts)
2359 use_ecs_dmaap_http() {
2360 echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
2361 echo -e $RED" - NOT SUPPORTED - "$ERED
2362 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
2363 export ECS_ADAPTER=$ECS_DMAAPBASE
2368 # All calls to ECS will be directed to the ECS dmaap interface over https from now on
2370 # (Function for test scripts)
2371 use_ecs_dmaap_https() {
2372 echo -e $BOLD"RICSIM protocol setting"$EBOLD
2373 echo -e $RED" - NOT SUPPORTED - "$ERED
2374 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
2375 export ECS_ADAPTER=$ECS_DMAAPBASE_SECURE
2380 # Turn on debug level tracing in ECS
2382 # (Function for test scripts)
2384 echo -e $BOLD"Setting ecs debug logging"$EBOLD
2385 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
2386 result=$(__do_curl "$curlString")
2387 if [ $? -ne 0 ]; then
2388 __print_err "Could not set debug mode" $@
2396 # Turn on trace level tracing in ECS
2398 # (Function for test scripts)
2400 echo -e $BOLD"Setting ecs trace logging"$EBOLD
2401 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
2402 result=$(__do_curl "$curlString")
2403 if [ $? -ne 0 ]; then
2404 __print_err "Could not set trace mode" $@
2412 # Perform curl retries when making direct call to ECS for the specified http response codes
2413 # Speace separated list of http response codes
2414 # args: [<response-code>]*
2415 use_agent_retries() {
2416 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
2417 ECS_AGENT_RETRY_CODES=$@
2426 # Check the agent logs for WARNINGs and ERRORs
2428 # (Function for test scripts)
2430 check_policy_agent_logs() {
2431 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
2435 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
2438 check_control_panel_logs() {
2439 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH WARN ERR
2443 __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
2446 __check_container_logs() {
2453 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
2455 #tmp=$(docker ps | grep $appname)
2456 tmp=$(docker ps -q --filter name=$appname) #get the container id
2457 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
2458 echo $dispname" is not running, no check made"
2461 foundentries="$(docker exec -t $tmp grep $warning $logpath | wc -l)"
2462 if [ $? -ne 0 ];then
2463 echo " Problem to search $appname log $logpath"
2465 if [ $foundentries -eq 0 ]; then
2466 echo " No WARN entries found in $appname log $logpath"
2468 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
2471 foundentries="$(docker exec -t $tmp grep $error $logpath | wc -l)"
2472 if [ $? -ne 0 ];then
2473 echo " Problem to search $appname log $logpath"
2475 if [ $foundentries -eq 0 ]; then
2476 echo " No ERR entries found in $appname log $logpath"
2478 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
2484 # Store all container logs and other logs in the log dir for the script
2485 # Logs are stored with a prefix in case logs should be stored several times during a test
2486 # args: <logfile-prefix>
2487 # (Function for test scripts)
2489 if [ $# != 1 ]; then
2491 __print_err "need one arg, <file-prefix>" $@
2494 echo -e $BOLD"Storing all container logs in $TESTLOGS/$ATC using prefix: "$1$EBOLD
2496 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
2498 __check_included_image 'CONSUL'
2499 if [ $? -eq 0 ]; then
2500 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
2503 __check_included_image 'CBS'
2504 if [ $? -eq 0 ]; then
2505 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
2506 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
2507 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
2510 __check_included_image 'PA'
2511 if [ $? -eq 0 ]; then
2512 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
2515 __check_included_image 'ECS'
2516 if [ $? -eq 0 ]; then
2517 docker logs $ECS_APP_NAME > $TESTLOGS/$ATC/$1_ecs.log 2>&1
2520 __check_included_image 'CP'
2521 if [ $? -eq 0 ]; then
2522 docker logs $CONTROL_PANEL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
2525 __check_included_image 'MR'
2526 if [ $? -eq 0 ]; then
2527 docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
2530 __check_included_image 'CR'
2531 if [ $? -eq 0 ]; then
2532 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
2535 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
2537 __check_included_image 'SDNC'
2538 if [ $? -eq 0 ]; then
2539 docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
2542 __check_included_image 'RICSIM'
2543 if [ $? -eq 0 ]; then
2544 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
2545 for ric in $rics; do
2546 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
2550 __check_included_image 'PRODSTUB'
2551 if [ $? -eq 0 ]; then
2552 docker logs $PROD_STUB_APP_NAME > $TESTLOGS/$ATC/$1_prodstub.log 2>&1
2561 # Generic curl function, assumes all 200-codes are ok
2562 # args: <valid-curl-args-including full url>
2563 # returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
2564 # returns: The return code is 0 for ok and 1 for not ok
2566 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
2567 curlString="curl -skw %{http_code} $@"
2568 echo " CMD: $curlString" >> $HTTPLOG
2570 echo " RESP: $res" >> $HTTPLOG
2571 http_code="${res:${#res}-3}"
2572 if [ ${#res} -eq 3 ]; then
2573 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2574 echo "<no-response-from-server>"
2580 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2581 echo "<not found, resp:${http_code}>"
2584 if [ $# -eq 2 ]; then
2585 echo "${res:0:${#res}-3}" | xargs
2587 echo "${res:0:${#res}-3}"
2594 #######################################
2595 ### Basic helper function for test cases
2596 #######################################
2598 # Test a simulator container variable value towards target value using an condition operator with an optional timeout.
2599 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
2600 # immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
2601 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
2602 # before setting pass or fail depending on the result of comparing variable and target using the operator.
2603 # If the <variable-name> has the 'json:' prefix, the the variable will be used as url and the <target-value> will be compared towards the length of the json array in the response.
2604 # Not to be called from test script.
2607 checkjsonarraycount=0
2609 if [ $# -eq 6 ]; then
2610 if [[ $3 == "json:"* ]]; then
2611 checkjsonarraycount=1
2614 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
2616 ((TEST_SEQUENCE_NR++))
2620 if [ $checkjsonarraycount -eq 0 ]; then
2621 result="$(__do_curl $2$3)"
2623 result=${result//[[:blank:]]/} #Strip blanks
2626 result="$(__do_curl $2$path)"
2628 echo "$result" > ./tmp/.tmp.curl.json
2629 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
2631 duration=$((SECONDS-start))
2632 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
2634 if [ $retcode -ne 0 ]; then
2635 if [ $duration -gt $6 ]; then
2637 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
2638 __check_stop_at_error
2641 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2643 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2644 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2646 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2648 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2649 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2651 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2653 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2654 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2656 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2658 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2659 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2662 if [ $duration -gt $6 ]; then
2664 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
2665 __check_stop_at_error
2671 elif [ $# -eq 5 ]; then
2672 if [[ $3 == "json:"* ]]; then
2673 checkjsonarraycount=1
2676 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
2678 ((TEST_SEQUENCE_NR++))
2679 if [ $checkjsonarraycount -eq 0 ]; then
2680 result="$(__do_curl $2$3)"
2682 result=${result//[[:blank:]]/} #Strip blanks
2685 result="$(__do_curl $2$path)"
2687 echo "$result" > ./tmp/.tmp.curl.json
2688 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
2690 if [ $retcode -ne 0 ]; then
2692 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
2693 __check_stop_at_error
2694 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2696 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2697 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2699 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2700 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2702 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2703 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2705 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2708 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
2709 __check_stop_at_error
2712 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
2719 ### Generic test cases for varaible checking
2721 # Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
2722 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2723 # equal to the target or not.
2724 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2725 # before setting pass or fail depending on if the variable value becomes equal to the target
2727 # (Function for test scripts)
2729 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2730 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
2733 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2737 # Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
2738 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2739 # greater than the target or not.
2740 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2741 # before setting pass or fail depending on if the variable value becomes greater than the target
2743 # (Function for test scripts)
2745 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2746 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 ">" $2 $3
2749 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2753 # Read a variable value from MR sim and send to stdout. Arg: <variable-name>
2755 echo "$(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"
2758 # Print a variable value from the MR stub.
2759 # arg: <variable-name>
2760 # (Function for test scripts)
2762 if [ $# != 1 ]; then
2764 __print_err "need one arg, <mr-param>" $@
2767 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"$EBOLD