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
23 . ../common/api_curl.sh
25 # List of short names for all supported apps, including simulators etc
26 APP_SHORT_NAMES="PA RICSIM SDNC CP ECS RC CBS CONSUL RC MR DMAAPMR CR PRODSTUB"
29 echo "Args: remote|remote-remove docker|kube --env-file <environment-filename> [release] [auto-clean] [--stop-at-error] "
30 echo " [--ricsim-prefix <prefix> ] [--use-local-image <app-nam>+] [--use-snapshot-image <app-nam>+]"
31 echo " [--use-staging-image <app-nam>+] [--use-release-image <app-nam>+]"
34 if [ $# -eq 1 ] && [ "$1" == "help" ]; then
36 if [ ! -z "$TC_ONELINE_DESCR" ]; then
37 echo "Test script description:"
38 echo $TC_ONELINE_DESCR
43 echo "remote - Use images from remote repositories. Can be overridden for individual images using the '--use_xxx' flags"
44 echo "remote-remove - Same as 'remote' but will also try to pull fresh images from remote repositories"
45 echo "docker - Test executed in docker environment"
46 echo "kube - Test executed in kubernetes environment - requires an already started kubernetes environment"
47 echo "--env-file - The script will use the supplied file to read environment variables from"
48 echo "release - If this flag is given the script will use release version of the images"
49 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."
50 echo "--stop-at-error - The script will stop when the first failed test or configuration"
51 echo "--ricsim-prefix - The a1 simulator will use the supplied string as container prefix instead of 'ricsim'"
52 echo "--use-local-image - The script will use local images for the supplied apps, space separated list of app short names"
53 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"
54 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"
55 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"
57 echo "List of app short names supported: "$APP_SHORT_NAMES
61 # Create a test case id, ATC (Auto Test Case), from the name of the test case script.
62 # FTC1.sh -> ATC == FTC1
63 ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
65 #Create result file (containing '1' for error) for this test case
66 #Will be replaced with a file containing '0' if all test cases pass
67 echo "1" > "$PWD/.result$ATC.txt"
69 #Formatting for 'echo' cmd
74 GREEN="\033[32m\033[1m"
76 YELLOW="\033[33m\033[1m"
80 # Just resetting any previous echo formatting...
83 # default test environment variables
86 echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@
89 LOCALHOST_NAME="localhost"
90 LOCALHOST_HTTP="http://localhost"
91 LOCALHOST_HTTPS="https://localhost"
93 # Var to hold 'auto' in case containers shall be stopped when test case ends
96 # Var to hold the app names to use local images for
99 # Var to hold the app names to use remote snapshot images for
100 USE_SNAPSHOT_IMAGES=""
102 # Var to hold the app names to use remote staging images for
103 USE_STAGING_IMAGES=""
105 # Var to hold the app names to use remote release images for
106 USE_RELEASE_IMAGES=""
108 # List of available apps to override with local or remote staging/snapshot/release image
109 AVAILABLE_IMAGES_OVERRIDE="PA ECS CP SDNC RICSIM RC"
111 # 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
114 # The default value "DEV" indicate that development image tags (SNAPSHOT) and nexus repos (nexus port 10002) are used.
115 # The value "RELEASE" indicate that relase image tag and nexus repos (nexus port) are used
116 # Applies only to images defined in the test-env files with image names and tags defined as XXXX_RELEASE
119 # Function to indent cmd output with one space
120 indent1() { sed 's/^/ /'; }
122 # Function to indent cmd output with two spaces
123 indent2() { sed 's/^/ /'; }
125 # Set a description string for the test case
126 if [ -z "$TC_ONELINE_DESCR" ]; then
127 TC_ONELINE_DESCR="<no-description>"
128 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
131 # Counter for test suites
132 if [ -f .tmp_tcsuite_ctr ]; then
133 tmpval=$(< .tmp_tcsuite_ctr)
135 echo $tmpval > .tmp_tcsuite_ctr
138 # Create the logs dir if not already created in the current dir
139 if [ ! -d "logs" ]; then
144 # Create the tmp dir for temporary files that is not needed after the test
145 # hidden files for the test env is still stored in the current dir
146 if [ ! -d "tmp" ]; then
150 # Create a http message log for this testcase
151 HTTPLOG=$PWD"/.httplog_"$ATC".txt"
154 # Create a log dir for the test case
155 mkdir -p $TESTLOGS/$ATC
157 # Save create for current logs
158 mkdir -p $TESTLOGS/$ATC/previous
160 rm $TESTLOGS/$ATC/previous/*.log &> /dev/null
161 rm $TESTLOGS/$ATC/previous/*.txt &> /dev/null
162 rm $TESTLOGS/$ATC/previous/*.json &> /dev/null
164 mv $TESTLOGS/$ATC/*.log $TESTLOGS/$ATC/previous &> /dev/null
165 mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
166 mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
168 # Clear the log dir for the test case
169 rm $TESTLOGS/$ATC/*.log &> /dev/null
170 rm $TESTLOGS/$ATC/*.txt &> /dev/null
171 rm $TESTLOGS/$ATC/*.json &> /dev/null
173 # Log all output from the test case to a TC log
174 TCLOG=$TESTLOGS/$ATC/TC.log
175 exec &> >(tee ${TCLOG})
177 #Variables for counting tests as well as passed and failed tests
184 #File to keep deviation messages
185 DEVIATION_FILE=".tmp_deviations"
186 rm $DEVIATION_FILE &> /dev/null
188 # Trap "command not found" and make the script fail
191 if [ $? -eq 127 ]; then
192 echo -e $RED"Function not found, setting script to FAIL"$ERED
202 TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
203 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ $EBOLD
204 echo "TEST $TEST_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ >> $HTTPLOG
206 ((TEST_SEQUENCE_NR++))
209 __log_test_fail_general() {
210 echo -e $RED" FAIL."$1 $ERED
212 __check_stop_at_error
215 __log_test_fail_status_code() {
216 echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED
218 __check_stop_at_error
221 __log_test_fail_body() {
222 echo -e $RED" FAIL, returned body not correct"$ERED
224 __check_stop_at_error
227 __log_test_fail_not_supported() {
228 echo -e $RED" FAIL, function not supported"$ERED
230 __check_stop_at_error
234 if [ $# -gt 0 ]; then
238 echo -e $GREEN" PASS"$EGREEN
241 #Counter for configurations
244 TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
245 echo -e $BOLD"CONF $CONF_SEQUENCE_NR (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ $EBOLD
246 echo "CONF $CONF_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ >> $HTTPLOG
247 ((CONF_SEQUENCE_NR++))
250 __log_conf_fail_general() {
251 echo -e $RED" FAIL."$1 $ERED
253 __check_stop_at_error
256 __log_conf_fail_status_code() {
257 echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED
259 __check_stop_at_error
262 __log_conf_fail_body() {
263 echo -e $RED" FAIL, returned body not correct"$ERED
265 __check_stop_at_error
269 if [ $# -gt 0 ]; then
272 echo -e $GREEN" OK"$EGREEN
275 #Var for measuring execution time
276 TCTEST_START=$SECONDS
278 #File to save timer measurement results
279 TIMER_MEASUREMENTS=".timer_measurement.txt"
280 echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS
283 echo "-------------------------------------------------------------------------------------------------"
284 echo "----------------------------------- Test case: "$ATC
285 echo "----------------------------------- Started: "$(date)
286 echo "-------------------------------------------------------------------------------------------------"
287 echo "-- Description: "$TC_ONELINE_DESCR
288 echo "-------------------------------------------------------------------------------------------------"
289 echo "----------------------------------- Test case setup -----------------------------------"
294 if [ $# -lt 1 ]; then
297 if [ $paramerror -eq 0 ]; then
298 if [ "$1" != "remote" ] && [ "$1" != "remote-remove" ]; then
300 if [ -z "$paramerror_str" ]; then
301 paramerror_str="First arg shall be 'remote' or 'remote-remove'"
307 if [ $paramerror -eq 0 ]; then
308 if [ "$1" != "docker" ] && [ "$1" != "kube" ]; then
310 if [ -z "$paramerror_str" ]; then
311 paramerror_str="Second arg shall be 'docker' or 'kube'"
314 if [ $1 == "docker" ]; then
316 echo "Setting RUNMODE=DOCKER"
318 if [ $1 == "kube" ]; then
320 echo "Setting RUNMODE=KUBE"
326 while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do
328 if [ $paramerror -eq 0 ]; then
329 if [ "$1" == "release" ]; then
330 IMAGE_CATEGORY="RELEASE"
331 echo "Option set - Release image tags used for applicable images "
336 if [ $paramerror -eq 0 ]; then
337 if [ "$1" == "auto-clean" ]; then
339 echo "Option set - Auto clean at end of test script"
344 if [ $paramerror -eq 0 ]; then
345 if [ "$1" == "--stop-at-error" ]; then
347 echo "Option set - Stop at first error"
352 if [ $paramerror -eq 0 ]; then
353 if [ "$1" == "--ricsim-prefix" ]; then
355 TMP_RIC_SIM_PREFIX=$1 #RIC_SIM_PREFIX need to be updated after sourcing of the env file
358 if [ -z "$paramerror_str" ]; then
359 paramerror_str="No prefix found for flag: '--ricsim-prefix'"
362 echo "Option set - Overriding RIC_SIM_PREFIX with: "$1
368 if [ $paramerror -eq 0 ]; then
369 if [ "$1" == "--env-file" ]; then
374 if [ -z "$paramerror_str" ]; then
375 paramerror_str="No env file found for flag: '--env-file'"
378 echo "Option set - Reading test env from: "$1
384 if [ $paramerror -eq 0 ]; then
385 if [ "$1" == "--use-local-image" ]; then
388 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
389 USE_LOCAL_IMAGES=$USE_LOCAL_IMAGES" "$1
390 if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
392 if [ -z "$paramerror_str" ]; then
393 paramerror_str="App name $1 is not available for local override for flag: '--use-local-image'"
399 if [ -z "$USE_LOCAL_IMAGES" ]; then
401 if [ -z "$paramerror_str" ]; then
402 paramerror_str="No app name found for flag: '--use-local-image'"
405 echo "Option set - Overriding with local images for app(s):"$USE_LOCAL_IMAGES
409 if [ $paramerror -eq 0 ]; then
410 if [ "$1" == "--use-snapshot-image" ]; then
411 USE_SNAPSHOT_IMAGES=""
413 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
414 USE_SNAPSHOT_IMAGES=$USE_SNAPSHOT_IMAGES" "$1
415 if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
417 if [ -z "$paramerror_str" ]; then
418 paramerror_str="App name $1 is not available for snapshot override for flag: '--use-snapshot-image'"
424 if [ -z "$USE_SNAPSHOT_IMAGES" ]; then
426 if [ -z "$paramerror_str" ]; then
427 paramerror_str="No app name found for flag: '--use-snapshot-image'"
430 echo "Option set - Overriding with snapshot images for app(s):"$USE_SNAPSHOT_IMAGES
434 if [ $paramerror -eq 0 ]; then
435 if [ "$1" == "--use-staging-image" ]; then
436 USE_STAGING_IMAGES=""
438 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
439 USE_STAGING_IMAGES=$USE_STAGING_IMAGES" "$1
440 if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
442 if [ -z "$paramerror_str" ]; then
443 paramerror_str="App name $1 is not available for staging override for flag: '--use-staging-image'"
449 if [ -z "$USE_STAGING_IMAGES" ]; then
451 if [ -z "$paramerror_str" ]; then
452 paramerror_str="No app name found for flag: '--use-staging-image'"
455 echo "Option set - Overriding with staging images for app(s):"$USE_STAGING_IMAGES
459 if [ $paramerror -eq 0 ]; then
460 if [ "$1" == "--use-release-image" ]; then
461 USE_RELEASE_IMAGES=""
463 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
464 USE_RELEASE_IMAGES=$USE_RELEASE_IMAGES" "$1
465 if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
467 if [ -z "$paramerror_str" ]; then
468 paramerror_str="App name $1 is not available for release override for flag: '--use-release-image'"
474 if [ -z "$USE_RELEASE_IMAGES" ]; then
476 if [ -z "$paramerror_str" ]; then
477 paramerror_str="No app name found for flag: '--use-release-image'"
480 echo "Option set - Overriding with release images for app(s):"$USE_RELEASE_IMAGES
488 if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
490 if [ -z "$paramerror_str" ]; then
491 paramerror_str="Unknown parameter(s): "$@
495 if [ $paramerror -eq 1 ]; then
496 echo -e $RED"Incorrect arg list: "$paramerror_str$ERED
501 # sourcing the selected env variables for the test case
502 if [ -f "$TEST_ENV_VAR_FILE" ]; then
503 echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD
506 if [ -z "$TEST_ENV_PROFILE" ] || [ -z "$SUPPORTED_PROFILES" ]; then
507 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
510 for prof in $SUPPORTED_PROFILES; do
511 if [ "$TEST_ENV_PROFILE" == "$prof" ]; then
512 echo -e $GREEN"Test case supports the selected test env file"$EGREEN
516 if [ $found_profile -ne 1 ]; then
517 echo -e $RED"Test case does not support the selected test env file"$ERED
518 echo "Profile: "$TEST_ENV_PROFILE" Supported profiles: "$SUPPORTED_PROFILES
519 echo -e $RED"Exiting...."$ERED
524 echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED
525 echo " Select one of following env var file matching the intended target of the test"
526 echo " Restart the test using the flag '--env-file <path-to-env-file>"
527 ls ../common/test_env* | indent1
531 #This var need be preserved from the command line option, if set, when env var is sourced.
532 if [ ! -z "$TMP_RIC_SIM_PREFIX" ]; then
533 RIC_SIM_PREFIX=$TMP_RIC_SIM_PREFIX
536 if [ -z "$PROJECT_IMAGES_APP_NAMES" ]; then
537 echo -e $RED"Var PROJECT_IMAGES_APP_NAMES must be defined in: "$TEST_ENV_VAR_FILE $ERED
541 if [[ $SUPPORTED_RUNMODES != *"$RUNMODE"* ]]; then
542 echo -e $RED"This test script does not support RUNMODE $RUNMODE"$ERED
543 echo "Supported RUNMODEs: "$SUPPORTED_RUNMODES
547 # Choose list of included apps depending on run-mode
548 if [ $RUNMODE == "KUBE" ]; then
549 INCLUDED_IMAGES=$KUBE_INCLUDED_IMAGES
551 INCLUDED_IMAGES=$DOCKER_INCLUDED_IMAGES
554 # Check needed installed sw
556 if [ $? -ne 0 ] || [ -z tmp ]; then
557 echo -e $RED"python3 is required to run the test environment, pls install"$ERED
561 if [ $? -ne 0 ] || [ -z tmp ]; then
562 echo -e $RED"docker is required to run the test environment, pls install"$ERED
566 tmp=$(which docker-compose)
567 if [ $? -ne 0 ] || [ -z tmp ]; then
568 if [ $RUNMODE == "DOCKER" ]; then
569 echo -e $RED"docker-compose is required to run the test environment, pls install"$ERED
575 if [ $? -ne 0 ] || [ -z tmp ]; then
576 if [ $RUNMODE == "KUBE" ]; then
577 echo -e $RED"kubectl is required to run the test environment in kubernetes mode, pls install"$ERED
582 echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
584 #Temp var to check for image variable name errors
586 #Create a file with image info for later printing as a table
587 image_list_file="./tmp/.image-list"
588 echo -e " Container\tImage\ttag\ttag-switch" > $image_list_file
590 # Check if image env var is set and if so export the env var with image to use (used by docker compose files)
591 # arg: <image name> <target-variable-name> <image-variable-name> <image-tag-variable-name> <tag-suffix> <app-short-name>
592 __check_and_create_image_var() {
593 if [ $# -ne 6 ]; then
594 echo "Expected arg: <image name> <target-variable-name> <image-variable-name> <image-tag-variable-name> <tag-suffix> <app-short-name>"
598 __check_included_image $6
599 if [ $? -ne 0 ]; then
600 echo -e "$1\t<image-excluded>\t<no-tag>" >> $image_list_file
601 # Image is excluded since the corresponding app is not used in this test
605 #Create var from the input var names
610 if [ -z $image ]; then
611 echo -e $RED"\$"$3" not set in $TEST_ENV_VAR_FILE"$ERED
614 tmp=$tmp"<no-image>\t"
616 #Add repo depending on image type
617 if [ "$5" == "REMOTE_RELEASE" ]; then
618 image=$NEXUS_RELEASE_REPO$image
620 if [ "$5" == "REMOTE" ]; then
621 image=$NEXUS_STAGING_REPO$image
623 if [ "$5" == "REMOTE_SNAPSHOT" ]; then
624 image=$NEXUS_SNAPSHOT_REPO$image
626 if [ "$5" == "REMOTE_PROXY" ]; then
627 image=$NEXUS_PROXY_REPO$image
629 if [ "$5" == "REMOTE_RELEASE_ONAP" ]; then
630 image=$NEXUS_RELEASE_REPO_ONAP$image
632 if [ "$5" == "REMOTE_RELEASE_ORAN" ]; then
633 image=$NEXUS_RELEASE_REPO_ORAN$image
635 #No nexus repo added for local images, tag: LOCAL
639 echo -e $RED"\$"$tmptag" not set in $TEST_ENV_VAR_FILE"$ERED
647 echo -e "$tmp" >> $image_list_file
649 export "${2}"=$image":"$tag
652 # Check if app uses image included in this test run
653 # Returns 0 if image is included, 1 if not
654 __check_included_image() {
655 for im in $INCLUDED_IMAGES; do
656 if [ "$1" == "$im" ]; then
663 # Check if app is included in the prestarted set of apps
664 # Returns 0 if image is included, 1 if not
665 __check_prestarted_image() {
666 for im in $KUBE_PRESTARTED_IMAGES; do
667 if [ "$1" == "$im" ]; then
674 # Check if an app shall use a local image, based on the cmd parameters
675 __check_image_local_override() {
676 for im in $USE_LOCAL_IMAGES; do
677 if [ "$1" == "$im" ]; then
684 # Check if app uses image override
685 # Returns the image/tag suffix LOCAL for local image or REMOTE/REMOTE_RELEASE/REMOTE_SNAPSHOT for staging/release/snapshot image
686 __check_image_override() {
688 for im in $ORAN_IMAGES_APP_NAMES; do
689 if [ "$1" == "$im" ]; then
690 echo "REMOTE_RELEASE_ORAN"
695 for im in $ONAP_IMAGES_APP_NAMES; do
696 if [ "$1" == "$im" ]; then
697 echo "REMOTE_RELEASE_ONAP"
703 for im in $PROJECT_IMAGES_APP_NAMES; do
704 if [ "$1" == "$im" ]; then
709 if [ $found -eq 0 ]; then
715 if [ $IMAGE_CATEGORY == "RELEASE" ]; then
716 suffix="REMOTE_RELEASE"
718 if [ $IMAGE_CATEGORY == "DEV" ]; then
722 for im in $USE_STAGING_IMAGES; do
723 if [ "$1" == "$im" ]; then
728 for im in $USE_RELEASE_IMAGES; do
729 if [ "$1" == "$im" ]; then
730 suffix="REMOTE_RELEASE"
734 for im in $USE_SNAPSHOT_IMAGES; do
735 if [ "$1" == "$im" ]; then
736 suffix="REMOTE_SNAPSHOT"
740 for im in $USE_LOCAL_IMAGES; do
741 if [ "$1" == "$im" ]; then
747 if [ $CTR -gt 1 ]; then
753 # Check that image env setting are available
757 __check_included_image 'PA'
758 if [ $? -eq 0 ]; then
759 IMAGE_SUFFIX=$(__check_image_override 'PA')
760 if [ $? -ne 0 ]; then
761 echo -e $RED"Image setting from cmd line not consistent for PA."$ERED
764 __check_and_create_image_var " Policy Agent" "POLICY_AGENT_IMAGE" "POLICY_AGENT_IMAGE_BASE" "POLICY_AGENT_IMAGE_TAG" $IMAGE_SUFFIX PA
767 #Remote Control Panel image
768 __check_included_image 'CP'
769 if [ $? -eq 0 ]; then
770 IMAGE_SUFFIX=$(__check_image_override 'CP')
771 if [ $? -ne 0 ]; then
772 echo -e $RED"Image setting from cmd line not consistent for CP."$ERED
775 __check_and_create_image_var " Control Panel" "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_IMAGE_BASE" "CONTROL_PANEL_IMAGE_TAG" $IMAGE_SUFFIX CP
779 __check_included_image 'SDNC'
780 if [ $? -eq 0 ]; then
781 IMAGE_SUFFIX=$(__check_image_override 'SDNC')
782 if [ $? -ne 0 ]; then
783 echo -e $RED"Image setting from cmd line not consistent for SDNC."$ERED
786 __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
789 #Remote ric sim image
790 __check_included_image 'RICSIM'
791 if [ $? -eq 0 ]; then
792 IMAGE_SUFFIX=$(__check_image_override 'RICSIM')
793 if [ $? -ne 0 ]; then
794 echo -e $RED"Image setting from cmd line not consistent for RICSIM."$ERED
797 __check_and_create_image_var " RIC Simulator" "RIC_SIM_IMAGE" "RIC_SIM_IMAGE_BASE" "RIC_SIM_IMAGE_TAG" $IMAGE_SUFFIX RICSIM
801 __check_included_image 'ECS'
802 if [ $? -eq 0 ]; then
803 IMAGE_SUFFIX=$(__check_image_override 'ECS')
804 if [ $? -ne 0 ]; then
805 echo -e $RED"Image setting from cmd line not consistent for ECS."$EREDs
808 __check_and_create_image_var " ECS" "ECS_IMAGE" "ECS_IMAGE_BASE" "ECS_IMAGE_TAG" $IMAGE_SUFFIX ECS
812 __check_included_image 'RC'
813 if [ $? -eq 0 ]; then
814 IMAGE_SUFFIX=$(__check_image_override 'RC')
815 if [ $? -ne 0 ]; then
816 echo -e $RED"Image setting from cmd line not consistent for RC."$ERED
819 __check_and_create_image_var " RC" "RAPP_CAT_IMAGE" "RAPP_CAT_IMAGE_BASE" "RAPP_CAT_IMAGE_TAG" $IMAGE_SUFFIX RC
822 # These images are not built as part of this project official images, just check that env vars are set correctly
823 __check_included_image 'MR'
824 if [ $? -eq 0 ]; then
825 __check_and_create_image_var " Message Router stub" "MRSTUB_IMAGE" "MRSTUB_IMAGE_BASE" "MRSTUB_IMAGE_TAG" LOCAL MR
827 __check_included_image 'DMAAPMR'
828 if [ $? -eq 0 ]; then
829 __check_and_create_image_var " DMAAP Message Router" "ONAP_DMAAPMR_IMAGE" "ONAP_DMAAPMR_IMAGE_BASE" "ONAP_DMAAPMR_IMAGE_TAG" REMOTE_RELEASE_ONAP DMAAPMR
830 __check_and_create_image_var " ZooKeeper" "ONAP_ZOOKEEPER_IMAGE" "ONAP_ZOOKEEPER_IMAGE_BASE" "ONAP_ZOOKEEPER_IMAGE_TAG" REMOTE_RELEASE_ONAP DMAAPMR
831 __check_and_create_image_var " Kafka" "ONAP_KAFKA_IMAGE" "ONAP_KAFKA_IMAGE_BASE" "ONAP_KAFKA_IMAGE_TAG" REMOTE_RELEASE_ONAP DMAAPMR
833 __check_included_image 'CR'
834 if [ $? -eq 0 ]; then
835 __check_and_create_image_var " Callback Receiver" "CR_IMAGE" "CR_IMAGE_BASE" "CR_IMAGE_TAG" LOCAL CR
837 __check_included_image 'PRODSTUB'
838 if [ $? -eq 0 ]; then
839 __check_and_create_image_var " Producer stub" "PROD_STUB_IMAGE" "PROD_STUB_IMAGE_BASE" "PROD_STUB_IMAGE_TAG" LOCAL PRODSTUB
841 __check_included_image 'CONSUL'
842 if [ $? -eq 0 ]; then
843 __check_and_create_image_var " Consul" "CONSUL_IMAGE" "CONSUL_IMAGE_BASE" "CONSUL_IMAGE_TAG" REMOTE_PROXY CONSUL
845 __check_included_image 'CBS'
846 if [ $? -eq 0 ]; then
847 __check_and_create_image_var " CBS" "CBS_IMAGE" "CBS_IMAGE_BASE" "CBS_IMAGE_TAG" REMOTE_RELEASE_ONAP CBS
849 __check_included_image 'SDNC'
850 if [ $? -eq 0 ]; then
851 __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
853 __check_included_image 'HTTPPROXY'
854 if [ $? -eq 0 ]; then
855 __check_and_create_image_var " Http Proxy" "HTTP_PROXY_IMAGE" "HTTP_PROXY_IMAGE_BASE" "HTTP_PROXY_IMAGE_TAG" REMOTE_PROXY HTTPPROXY
858 #Errors in image setting - exit
859 if [ $IMAGE_ERR -ne 0 ]; then
863 #Print a tables of the image settings
864 echo -e $BOLD"Images configured for start arg: "$START $EBOLD
865 column -t -s $'\t' $image_list_file
870 #Set the SIM_GROUP var
871 echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
872 if [ -z "$SIM_GROUP" ]; then
873 SIM_GROUP=$PWD/../simulator-group
874 if [ ! -d $SIM_GROUP ]; then
875 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
876 echo -e $RED"Please set the SIM_GROUP manually in the applicable $TEST_ENV_VAR_FILE"$ERED
879 echo " SIM_GROUP auto set to: " $SIM_GROUP
881 elif [ $SIM_GROUP = *simulator_group ]; then
882 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
885 echo " SIM_GROUP env var already set to: " $SIM_GROUP
890 #Temp var to check for image pull errors
893 #Function to check if image exist and stop+remove the container+pull new images as needed
894 #args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
895 __check_and_pull_image() {
897 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
898 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
899 tmp_im=$(docker images --format $format_string ${4})
901 if [ $1 == "local" ]; then
902 if [ -z "$tmp_im" ]; then
903 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
907 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
909 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
910 if [ $1 == "remote-remove" ]; then
911 if [ $RUNMODE == "DOCKER" ]; then
912 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
913 tmp="$(docker ps -aq --filter name=${3})"
914 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
915 docker stop $tmp &> ./tmp/.dockererr
916 if [ $? -ne 0 ]; then
919 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
924 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
925 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
926 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
927 docker rm $tmp &> ./tmp/.dockererr
928 if [ $? -ne 0 ]; then
931 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
936 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
942 if [ -z "$tmp_im" ]; then
943 echo -ne " Pulling image${SAMELINE}"
944 out=$(docker pull $4)
945 if [ $? -ne 0 ]; then
947 echo -e " Pulling image -$RED could not be pulled"$ERED
949 echo $out > ./tmp/.dockererr
953 echo $out > ./tmp/.dockererr
954 if [[ $out == *"up to date"* ]]; then
955 echo -e " Pulling image -$GREEN Image is up to date $EGREEN"
956 elif [[ $out == *"Downloaded newer image"* ]]; then
957 echo -e " Pulling image -$GREEN Newer image pulled $EGREEN"
959 echo -e " Pulling image -$GREEN Pulled $EGREEN"
962 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
969 echo -e $BOLD"Pulling configured images, if needed"$EBOLD
971 __check_included_image 'PA'
972 if [ $? -eq 0 ]; then
973 START_ARG_MOD=$START_ARG
974 __check_image_local_override 'PA'
975 if [ $? -eq 1 ]; then
976 START_ARG_MOD="local"
978 app="Policy Agent"; __check_and_pull_image $START_ARG_MOD "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
980 echo -e $YELLOW" Excluding PA image from image check/pull"$EYELLOW
983 __check_included_image 'ECS'
984 if [ $? -eq 0 ]; then
985 START_ARG_MOD=$START_ARG
986 __check_image_local_override 'ECS'
987 if [ $? -eq 1 ]; then
988 START_ARG_MOD="local"
990 app="ECS"; __check_and_pull_image $START_ARG_MOD "$app" $ECS_APP_NAME $ECS_IMAGE
992 echo -e $YELLOW" Excluding ECS image from image check/pull"$EYELLOW
995 __check_included_image 'CP'
996 if [ $? -eq 0 ]; then
997 START_ARG_MOD=$START_ARG
998 __check_image_local_override 'CP'
999 if [ $? -eq 1 ]; then
1000 START_ARG_MOD="local"
1002 app="Non-RT RIC Control Panel"; __check_and_pull_image $START_ARG_MOD "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
1004 echo -e $YELLOW" Excluding Non-RT RIC Control Panel image from image check/pull"$EYELLOW
1007 __check_included_image 'RC'
1008 if [ $? -eq 0 ]; then
1009 START_ARG_MOD=$START_ARG
1010 __check_image_local_override 'RC'
1011 if [ $? -eq 1 ]; then
1012 START_ARG_MOD="local"
1014 app="RAPP Catalogue"; __check_and_pull_image $START_ARG_MOD "$app" $RAPP_CAT_APP_NAME $RAPP_CAT_IMAGE
1016 echo -e $YELLOW" Excluding RAPP Catalogue image from image check/pull"$EYELLOW
1019 __check_included_image 'RICSIM'
1020 if [ $? -eq 0 ]; then
1021 START_ARG_MOD=$START_ARG
1022 __check_image_local_override 'RICSIM'
1023 if [ $? -eq 1 ]; then
1024 START_ARG_MOD="local"
1026 app="Near-RT RIC Simulator"; __check_and_pull_image $START_ARG_MOD "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
1028 echo -e $YELLOW" Excluding Near-RT RIC Simulator image from image check/pull"$EYELLOW
1032 __check_included_image 'CONSUL'
1033 if [ $? -eq 0 ]; then
1034 app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
1036 echo -e $YELLOW" Excluding Consul image from image check/pull"$EYELLOW
1039 __check_included_image 'CBS'
1040 if [ $? -eq 0 ]; then
1041 app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE
1043 echo -e $YELLOW" Excluding CBS image from image check/pull"$EYELLOW
1046 __check_included_image 'SDNC'
1047 if [ $? -eq 0 ]; then
1048 START_ARG_MOD=$START_ARG
1049 __check_image_local_override 'SDNC'
1050 if [ $? -eq 1 ]; then
1051 START_ARG_MOD="local"
1053 app="SDNC A1 Controller"; __check_and_pull_image $START_ARG_MOD "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
1054 app="SDNC DB"; __check_and_pull_image $START_ARG "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
1056 echo -e $YELLOW" Excluding SDNC image and related DB image from image check/pull"$EYELLOW
1059 __check_included_image 'HTTPPROXY'
1060 if [ $? -eq 0 ]; then
1061 app="HTTPPROXY"; __check_and_pull_image $START_ARG "$app" $HTTP_PROXY_APP_NAME $HTTP_PROXY_IMAGE
1063 echo -e $YELLOW" Excluding Http Proxy image from image check/pull"$EYELLOW
1066 __check_included_image 'DMAAPMR'
1067 if [ $? -eq 0 ]; then
1068 app="DMAAP Message Router"; __check_and_pull_image $START_ARG "$app" $MR_DMAAP_APP_NAME $ONAP_DMAAPMR_IMAGE
1069 app="ZooKeeper"; __check_and_pull_image $START_ARG "$app" $MR_ZOOKEEPER_APP_NAME $ONAP_ZOOKEEPER_IMAGE
1070 app="Kafka"; __check_and_pull_image $START_ARG "$app" $MR_KAFKA_APP_NAME $ONAP_KAFKA_IMAGE
1072 echo -e $YELLOW" Excluding DMAAP MR image and images (zookeeper, kafka) from image check/pull"$EYELLOW
1075 #Errors in image setting - exit
1076 if [ $IMAGE_ERR -ne 0 ]; then
1078 echo "#################################################################################################"
1079 echo -e $RED"One or more images could not be pulled or containers using the images could not be stopped/removed"$ERED
1080 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
1081 if [ $IMAGE_CATEGORY == "DEV" ]; then
1082 echo -e $RED"Note that SNAPSHOT images may be purged from nexus after a certain period."$ERED
1083 echo -e $RED"In that case, switch to use a released image instead."$ERED
1085 echo "#################################################################################################"
1092 echo -e $BOLD"Building images needed for test"$EBOLD
1095 __check_included_image 'MR'
1096 if [ $? -eq 0 ]; then
1099 echo " Building mrstub image: $MRSTUB_IMAGE"
1100 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $MRSTUB_IMAGE . &> .dockererr
1101 if [ $? -eq 0 ]; then
1102 echo -e $GREEN" Build Ok"$EGREEN
1104 echo -e $RED" Build Failed"$ERED
1107 echo -e $RED"Exiting...."$ERED
1112 echo -e $YELLOW" Excluding mrstub from image build"$EYELLOW
1115 __check_included_image 'CR'
1116 if [ $? -eq 0 ]; then
1118 echo " Building Callback Receiver image: $CR_IMAGE"
1119 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $CR_IMAGE . &> .dockererr
1120 if [ $? -eq 0 ]; then
1121 echo -e $GREEN" Build Ok"$EGREEN
1123 echo -e $RED" Build Failed"$ERED
1126 echo -e $RED"Exiting...."$ERED
1131 echo -e $YELLOW" Excluding Callback Receiver from image build"$EYELLOW
1134 __check_included_image 'PRODSTUB'
1135 if [ $? -eq 0 ]; then
1137 echo " Building Producer stub image: $PROD_STUB_IMAGE"
1138 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $PROD_STUB_IMAGE . &> .dockererr
1139 if [ $? -eq 0 ]; then
1140 echo -e $GREEN" Build Ok"$EGREEN
1142 echo -e $RED" Build Failed"$ERED
1145 echo -e $RED"Exiting...."$ERED
1150 echo -e $YELLOW" Excluding Producer stub from image build"$EYELLOW
1155 # Create a table of the images used in the script
1156 echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
1158 docker_tmp_file=./tmp/.docker-images-table
1159 format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\\t{{.CreatedAt}}"
1160 echo -e " Application\tRepository\tTag\tCreated since\tSize\tCreated at" > $docker_tmp_file
1162 __check_included_image 'PA'
1163 if [ $? -eq 0 ]; then
1164 echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
1167 __check_included_image 'ECS'
1168 if [ $? -eq 0 ]; then
1169 echo -e " ECS\t$(docker images --format $format_string $ECS_IMAGE)" >> $docker_tmp_file
1171 __check_included_image 'CP'
1172 if [ $? -eq 0 ]; then
1173 echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
1175 __check_included_image 'RICSIM'
1176 if [ $? -eq 0 ]; then
1177 echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
1179 __check_included_image 'RC'
1180 if [ $? -eq 0 ]; then
1181 echo -e " RAPP Catalogue\t$(docker images --format $format_string $RAPP_CAT_IMAGE)" >> $docker_tmp_file
1183 __check_included_image 'MR'
1184 if [ $? -eq 0 ]; then
1185 echo -e " Message Router stub\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
1187 __check_included_image 'DMAAPMR'
1188 if [ $? -eq 0 ]; then
1189 echo -e " DMAAP Message Router\t$(docker images --format $format_string $ONAP_DMAAPMR_IMAGE)" >> $docker_tmp_file
1190 echo -e " ZooKeeper\t$(docker images --format $format_string $ONAP_ZOOKEEPER_IMAGE)" >> $docker_tmp_file
1191 echo -e " Kafka\t$(docker images --format $format_string $ONAP_KAFKA_IMAGE)" >> $docker_tmp_file
1193 __check_included_image 'CR'
1194 if [ $? -eq 0 ]; then
1195 echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
1197 __check_included_image 'PRODSTUB'
1198 if [ $? -eq 0 ]; then
1199 echo -e " Producer stub\t$(docker images --format $format_string $PROD_STUB_IMAGE)" >> $docker_tmp_file
1201 __check_included_image 'CONSUL'
1202 if [ $? -eq 0 ]; then
1203 echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
1205 __check_included_image 'CBS'
1206 if [ $? -eq 0 ]; then
1207 echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
1209 __check_included_image 'SDNC'
1210 if [ $? -eq 0 ]; then
1211 echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
1212 echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
1214 __check_included_image 'HTTPPROXY'
1215 if [ $? -eq 0 ]; then
1216 echo -e " Http Proxy\t$(docker images --format $format_string $HTTP_PROXY_IMAGE)" >> $docker_tmp_file
1219 column -t -s $'\t' $docker_tmp_file
1223 echo -e $BOLD"======================================================="$EBOLD
1224 echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
1225 echo -e $BOLD"======================================================="$EBOLD
1228 # Function to print the test result, shall be the last cmd in a test script
1230 # (Function for test scripts)
1234 duration=$((TCTEST_END-TCTEST_START))
1236 echo "-------------------------------------------------------------------------------------------------"
1237 echo "------------------------------------- Test case: "$ATC
1238 echo "------------------------------------- Ended: "$(date)
1239 echo "-------------------------------------------------------------------------------------------------"
1240 echo "-- Description: "$TC_ONELINE_DESCR
1241 echo "-- Execution time: " $duration " seconds"
1242 echo "-- Used env file: "$TEST_ENV_VAR_FILE
1243 echo "-------------------------------------------------------------------------------------------------"
1244 echo "------------------------------------- RESULTS"
1248 if [ $RES_DEVIATION -gt 0 ]; then
1249 echo "Test case deviations"
1250 echo "===================================="
1254 echo "Timer measurement in the test script"
1255 echo "===================================="
1256 column -t -s $'\t' $TIMER_MEASUREMENTS
1259 total=$((RES_PASS+RES_FAIL))
1260 if [ $RES_TEST -eq 0 ]; then
1261 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
1262 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
1263 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
1264 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
1265 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
1266 elif [ $total != $RES_TEST ]; then
1267 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
1268 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
1269 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
1270 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
1271 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
1272 elif [ $RES_CONF_FAIL -ne 0 ]; then
1273 echo -e "\033[1mOne or more configurations has failed. Check the script log....\033[0m"
1274 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
1275 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
1276 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
1277 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
1278 elif [ $RES_PASS = $RES_TEST ]; then
1279 echo -e "All tests \033[32m\033[1mPASS\033[0m"
1280 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
1281 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
1282 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
1283 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
1286 # Update test suite counter
1287 if [ -f .tmp_tcsuite_pass_ctr ]; then
1288 tmpval=$(< .tmp_tcsuite_pass_ctr)
1290 echo $tmpval > .tmp_tcsuite_pass_ctr
1292 if [ -f .tmp_tcsuite_pass ]; then
1293 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
1295 #Create file with OK exit code
1296 echo "0" > "$PWD/.result$ATC.txt"
1298 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
1299 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
1300 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
1301 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
1302 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
1304 # Update test suite counter
1305 if [ -f .tmp_tcsuite_fail_ctr ]; then
1306 tmpval=$(< .tmp_tcsuite_fail_ctr)
1308 echo $tmpval > .tmp_tcsuite_fail_ctr
1310 if [ -f .tmp_tcsuite_fail ]; then
1311 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
1315 echo "++++ Number of tests: "$RES_TEST
1316 echo "++++ Number of passed tests: "$RES_PASS
1317 echo "++++ Number of failed tests: "$RES_FAIL
1319 echo "++++ Number of failed configs: "$RES_CONF_FAIL
1321 echo "++++ Number of test case deviations: "$RES_DEVIATION
1323 echo "------------------------------------- Test case complete ---------------------------------"
1324 echo "-------------------------------------------------------------------------------------------------"
1328 #####################################################################
1329 ###### Functions for start, configuring, stoping, cleaning etc ######
1330 #####################################################################
1332 # Start timer for time measurement
1333 # args - (any args will be printed though)
1335 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1337 echo " Timer started"
1340 # Print the value of the time (in seconds)
1341 # args - <timer message to print> - timer value and message will be printed both on screen
1342 # and in the timer measurement report
1344 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1345 if [ $# -lt 1 ]; then
1347 __print_err "need 1 or more args, <timer message to print>" $@
1350 duration=$(($SECONDS-$TC_TIMER))
1351 if [ $duration -eq 0 ]; then
1352 duration="<1 second"
1354 duration=$duration" seconds"
1356 echo " Timer duration :" $duration
1358 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
1361 # Print the value of the time (in seconds) and reset the timer
1362 # args - <timer message to print> - timer value and message will be printed both on screen
1363 # and in the timer measurement report
1364 print_and_reset_timer() {
1365 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1366 if [ $# -lt 1 ]; then
1368 __print_err "need 1 or more args, <timer message to print>" $@
1371 duration=$(($SECONDS-$TC_TIMER))" seconds"
1372 if [ $duration -eq 0 ]; then
1373 duration="<1 second"
1375 duration=$duration" seconds"
1377 echo " Timer duration :" $duration
1381 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
1384 # Print info about a deviations from intended tests
1385 # Each deviation counted is also printed in the testreport
1386 # args <deviation message to print>
1388 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
1389 if [ $# -lt 1 ]; then
1391 __print_err "need 1 or more args, <deviation message to print>" $@
1395 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
1396 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
1400 # Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
1401 __check_stop_at_error() {
1402 if [ $STOP_AT_ERROR -eq 1 ]; then
1403 echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
1404 store_logs "STOP_AT_ERROR"
1410 # Check if app name var is set. If so return the app name otherwise return "NOTSET"
1411 __check_app_name() {
1412 if [ $# -eq 1 ]; then
1419 # Stop and remove all containers
1421 # (Not for test scripts)
1422 __clean_containers() {
1424 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
1426 CONTAINTER_NAMES=("Policy Agent " $(__check_app_name $POLICY_AGENT_APP_NAME)\
1427 "ECS " $(__check_app_name $ECS_APP_NAME)\
1428 "RAPP Catalogue " $(__check_app_name $RAPP_CAT_APP_NAME)\
1429 "Non-RT RIC Simulator(s)" $(__check_app_name $RIC_SIM_PREFIX)\
1430 "Message Router stub " $(__check_app_name $MR_STUB_APP_NAME)\
1431 "DMAAP Message Router " $(__check_app_name $MR_DMAAP_APP_NAME)\
1432 "Zookeeper " $(__check_app_name $MR_ZOOKEEPER_APP_NAME)\
1433 "Kafka " $(__check_app_name $MR_KAFKA_APP_NAME)\
1434 "Callback Receiver " $(__check_app_name $CR_APP_NAME)\
1435 "Producer stub " $(__check_app_name $PROD_STUB_APP_NAME)\
1436 "Control Panel " $(__check_app_name $CONTROL_PANEL_APP_NAME)\
1437 "SDNC A1 Controller " $(__check_app_name $SDNC_APP_NAME)\
1438 "SDNC DB " $(__check_app_name $SDNC_DB_APP_NAME)\
1439 "CBS " $(__check_app_name $CBS_APP_NAME)\
1440 "Consul " $(__check_app_name $CONSUL_APP_NAME)\
1441 "Http Proxy " $(__check_app_name $HTTP_PROXY_APP_NAME))
1443 nw=0 # Calc max width of container name, to make a nice table
1444 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
1446 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
1447 nw=${#CONTAINTER_NAMES[i]}
1451 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
1452 APP="${CONTAINTER_NAMES[i]}"
1453 CONTR="${CONTAINTER_NAMES[i+1]}"
1454 if [ $CONTR != "NOTSET" ]; then
1455 for((w=${#CONTR}; w<$nw; w=w+1)); do
1458 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
1459 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1460 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
1461 docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1462 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
1468 echo -e $BOLD" Removing docker network"$EBOLD
1469 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
1470 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
1471 docker network rm $DOCKER_SIM_NWNAME | indent2
1472 if [ $? -ne 0 ]; then
1473 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
1477 echo -e "$GREEN Done$EGREEN"
1479 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
1480 docker network prune --force | indent2
1481 echo -e "$GREEN Done$EGREEN"
1483 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
1484 docker volume prune --force | indent2
1485 echo -e "$GREEN Done$EGREEN"
1487 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
1488 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
1489 echo -e "$GREEN Done$EGREEN"
1492 CONTRS=$(docker ps | awk '$1 != "CONTAINER" { n++ }; END { print n+0 }')
1493 if [ $? -eq 0 ]; then
1494 if [ $CONTRS -ne 0 ]; then
1495 echo -e $RED"Containers running, may cause distubance to the test case"$ERED
1496 docker ps -a | indent1
1502 ###################################
1503 ### Functions for kube management
1504 ###################################
1506 # Scale a kube resource to a specific count
1507 # args: <resource-type> <resource-name> <namespace> <target-count>
1508 # (Not for test scripts)
1510 echo -ne " Setting $1 $2 replicas=$4 in namespace $3"$SAMELINE
1511 kubectl scale $1 $2 -n $3 --replicas=$4 1> /dev/null 2> ./tmp/kubeerr
1512 if [ $? -ne 0 ]; then
1513 echo -e " Setting $1 $2 replicas=$4 in namespace $3 $RED Failed $ERED"
1515 echo " Message: $(<./tmp/kubeerr)"
1518 echo -e " Setting $1 $2 replicas=$4 in namespace $3 $GREEN OK $EGREEN"
1523 for i in {1..500}; do
1524 count=$(kubectl get $1/$2 -n $3 -o jsonpath='{.status.replicas}' 2> /dev/null)
1526 if [ -z "$count" ]; then
1527 #No value is sometimes returned for some reason, in case the resource has replica 0
1530 if [ $retcode -ne 0 ]; then
1531 echo -e "$RED Cannot fetch current replica count for $1 $2 in namespace $3 $ERED"
1536 if [ $count -ne $4 ]; then
1537 echo -ne " Waiting for $1 $2 replicas=$4 in namespace $3. Replicas=$count after $(($SECONDS-$TSTART)) seconds $SAMELINE"
1540 echo -e " Waiting for $1 $2 replicas=$4 in namespace $3. Replicas=$count after $(($SECONDS-$TSTART)) seconds"
1541 echo -e " Replicas=$4 after $(($SECONDS-$TSTART)) seconds $GREEN OK $EGREEN"
1547 echo -e "$RED Replica count did not reach target replicas=$4. Failed with replicas=$count $ERED"
1552 # Scale all kube resource sets to 0 in a namespace for resources having a certain lable and label-id
1553 # This function does not wait for the resource to reach 0
1554 # args: <namespace> <label-name> <label-id>
1555 # (Not for test scripts)
1556 __kube_scale_all_resources() {
1560 resources="deployment replicaset statefulset"
1561 for restype in $resources; do
1562 result=$(kubectl get $restype -n $namespace -o jsonpath='{.items[?(@.metadata.labels.'$labelname'=="'$labelid'")].metadata.name}')
1563 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
1564 deleted_resourcetypes=$deleted_resourcetypes" "$restype
1565 for resid in $result; do
1566 echo -ne " Ordered caling $restype $resid from namespace $namespace with label $labelname=$labelid to 0"$SAMELINE
1567 kubectl scale $restype $resid -n $namespace --replicas=0 1> /dev/null 2> ./tmp/kubeerr
1568 echo -e " Ordered scaling $restype $resid from namespace $namespace with label $labelname=$labelid to 0 $GREEN OK $EGREEN"
1574 # Scale all kube resource sets to 0 in a namespace for resources having a certain lable and label-id
1575 # This function do wait for the resource to reach 0
1576 # args: <namespace> <label-name> <label-id>
1577 # (Not for test scripts)
1578 __kube_scale_and_wait_all_resources() {
1582 resources="deployment replicaset statefulset"
1584 while [ $scaled_all -ne 0 ]; do
1586 for restype in $resources; do
1587 result=$(kubectl get $restype -n $namespace -o jsonpath='{.items[?(@.metadata.labels.'$labelname'=="'$labelid'")].metadata.name}')
1588 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
1589 for resid in $result; do
1590 echo -e " Ordered scaling $restype $resid from namespace $namespace with label $labelname=$labelid to 0"
1591 kubectl scale $restype $resid -n $namespace --replicas=0 1> /dev/null 2> ./tmp/kubeerr
1594 while [ $count -ne 0 ]; do
1595 count=$(kubectl get $restype $resid -n $namespace -o jsonpath='{.status.replicas}' 2> /dev/null)
1596 echo -ne " Scaling $restype $resid from namespace $namespace with label $labelname=$labelid to 0,count=$count"$SAMELINE
1597 if [ $? -eq 0 ] && [ ! -z "$count" ]; then
1602 duration=$(($SECONDS-$T_START))
1603 if [ $duration -gt 100 ]; then
1604 #Forcring count 0, to avoid hanging for failed scaling
1609 echo -e " Scaled $restype $resid from namespace $namespace with label $labelname=$labelid to 0,count=$count $GREEN OK $EGREEN"
1616 # Remove all kube resources in a namespace for resources having a certain label and label-id
1617 # This function wait until the resources are gone. Scaling to 0 must have been ordered previously
1618 # args: <namespace> <label-name> <label-id>
1619 # (Not for test scripts)
1620 __kube_delete_all_resources() {
1624 resources="deployments replicaset statefulset services pods configmaps pvc"
1625 deleted_resourcetypes=""
1626 for restype in $resources; do
1627 result=$(kubectl get $restype -n $namespace -o jsonpath='{.items[?(@.metadata.labels.'$labelname'=="'$labelid'")].metadata.name}')
1628 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
1629 deleted_resourcetypes=$deleted_resourcetypes" "$restype
1630 for resid in $result; do
1631 if [ $restype == "replicaset" ] || [ $restype == "statefulset" ]; then
1633 while [ $count -ne 0 ]; do
1634 count=$(kubectl get $restype $resid -n $namespace -o jsonpath='{.status.replicas}' 2> /dev/null)
1635 echo -ne " Scaling $restype $resid from namespace $namespace with label $labelname=$labelid to 0,count=$count"$SAMELINE
1636 if [ $? -eq 0 ] && [ ! -z "$count" ]; then
1642 echo -e " Scaled $restype $resid from namespace $namespace with label $labelname=$labelid to 0,count=$count $GREEN OK $EGREEN"
1644 echo -ne " Deleting $restype $resid from namespace $namespace with label $labelname=$labelid "$SAMELINE
1645 kubectl delete $restype $resid -n $namespace 1> /dev/null 2> ./tmp/kubeerr
1646 if [ $? -eq 0 ]; then
1647 echo -e " Deleted $restype $resid from namespace $namespace with label $labelname=$labelid $GREEN OK $EGREEN"
1649 echo -e " Deleted $restype $resid from namespace $namespace with label $labelname=$labelid $GREEN Does not exist - OK $EGREEN"
1655 if [ ! -z "$deleted_resourcetypes" ]; then
1656 for restype in $deleted_resources; do
1657 echo -ne " Waiting for $restype in namespace $namespace with label $labelname=$labelid to be deleted..."$SAMELINE
1660 while [ ! -z "$result" ]; do
1662 result=$(kubectl get $restype -n $namespace -o jsonpath='{.items[?(@.metadata.labels.'$labelname'=="'$labelid'")].metadata.name}')
1663 echo -ne " Waiting for $restype in namespace $namespace with label $labelname=$labelid to be deleted...$(($SECONDS-$T_START)) seconds "$SAMELINE
1664 if [ -z "$result" ]; then
1665 echo -e " Waiting for $restype in namespace $namespace with label $labelname=$labelid to be deleted...$(($SECONDS-$T_START)) seconds $GREEN OK $EGREEN"
1666 elif [ $(($SECONDS-$T_START)) -gt 300 ]; then
1667 echo -e " Waiting for $restype in namespace $namespace with label $labelname=$labelid to be deleted...$(($SECONDS-$T_START)) seconds $RED Failed $ERED"
1675 # Creates a namespace if it does not exists
1677 # (Not for test scripts)
1678 __kube_create_namespace() {
1680 #Check if test namespace exists, if not create it
1681 kubectl get namespace $1 1> /dev/null 2> ./tmp/kubeerr
1682 if [ $? -ne 0 ]; then
1683 echo -ne " Creating namespace "$1 $SAMELINE
1684 kubectl create namespace $1 1> /dev/null 2> ./tmp/kubeerr
1685 if [ $? -ne 0 ]; then
1686 echo -e " Creating namespace $1 $RED$BOLD FAILED $EBOLD$ERED"
1688 echo " Message: $(<./tmp/kubeerr)"
1691 echo -e " Creating namespace $1 $GREEN$BOLD OK $EBOLD$EGREEN"
1694 echo -e " Creating namespace $1 $GREEN$BOLD Already exists, OK $EBOLD$EGREEN"
1699 # Find the host ip of an app (using the service resource)
1700 # args: <app-name> <namespace>
1701 # (Not for test scripts)
1702 __kube_get_service_host() {
1703 if [ $# -ne 2 ]; then
1705 __print_err "need 2 args, <app-name> <namespace>" $@
1708 for timeout in {1..60}; do
1709 host=$(kubectl get svc $1 -n $2 -o jsonpath='{.spec.clusterIP}')
1710 if [ $? -eq 0 ]; then
1711 if [ ! -z "$host" ]; then
1719 echo "host-not-found-fatal-error"
1723 # Translate ric name to kube host name
1726 get_kube_sim_host() {
1727 name=$(echo "$1" | tr '_' '-') #kube does not accept underscore in names
1728 #example gnb_1_2 -> gnb-1-2
1729 set_name=$(echo $name | rev | cut -d- -f2- | rev) # Cut index part of ric name to get the name of statefulset
1730 # example gnb-g1-2 -> gnb-g1 where gnb-g1-2 is the ric name and gnb-g1 is the set name
1731 echo $name"."$set_name"."$KUBE_NONRTRIC_NAMESPACE
1735 # Find the named port to an app (using the service resource)
1736 # args: <app-name> <namespace> <port-name>
1737 # (Not for test scripts)
1738 __kube_get_service_port() {
1739 if [ $# -ne 3 ]; then
1741 __print_err "need 3 args, <app-name> <namespace> <port-name>" $@
1745 for timeout in {1..60}; do
1746 port=$(kubectl get svc $1 -n $2 -o jsonpath='{...ports[?(@.name=="'$3'")].port}')
1747 if [ $? -eq 0 ]; then
1748 if [ ! -z "$port" ]; then
1760 # Create a kube resource from a yaml template
1761 # args: <resource-type> <resource-name> <template-yaml> <output-yaml>
1762 # (Not for test scripts)
1763 __kube_create_instance() {
1764 echo -ne " Creating $1 $2"$SAMELINE
1766 kubectl apply -f $4 1> /dev/null 2> ./tmp/kubeerr
1767 if [ $? -ne 0 ]; then
1769 echo -e " Creating $1 $2 $RED Failed $ERED"
1770 echo " Message: $(<./tmp/kubeerr)"
1773 echo -e " Creating $1 $2 $GREEN OK $EGREEN"
1777 # Function to create a configmap in kubernetes
1778 # args: <configmap-name> <namespace> <labelname> <labelid> <path-to-data-file> <path-to-output-yaml>
1779 # (Not for test scripts)
1780 __kube_create_configmap() {
1781 echo -ne " Creating configmap $1 "$SAMELINE
1782 envsubst < $5 > $5"_tmp"
1783 cp $5"_tmp" $5 #Need to copy back to orig file name since create configmap neeed the original file name
1784 kubectl create configmap $1 -n $2 --from-file=$5 --dry-run=client -o yaml > $6
1785 if [ $? -ne 0 ]; then
1786 echo -e " Creating configmap $1 $RED Failed $ERED"
1791 kubectl apply -f $6 1> /dev/null 2> ./tmp/kubeerr
1792 if [ $? -ne 0 ]; then
1793 echo -e " Creating configmap $1 $RED Apply failed $ERED"
1794 echo " Message: $(<./tmp/kubeerr)"
1798 kubectl label configmap $1 -n $2 $3"="$4 --overwrite 1> /dev/null 2> ./tmp/kubeerr
1799 if [ $? -ne 0 ]; then
1800 echo -e " Creating configmap $1 $RED Labeling failed $ERED"
1801 echo " Message: $(<./tmp/kubeerr)"
1805 # Log the resulting map
1806 kubectl get configmap $1 -n $2 -o yaml > $6
1808 echo -e " Creating configmap $1 $GREEN OK $EGREEN"
1812 # This function scales or deletes all resources for app selected by the testcase.
1814 # (Not for test scripts)
1816 echo -e $BOLD"Initialize kube services//pods/statefulsets/replicaset to initial state"$EBOLD
1818 # Scale prestarted or managed apps
1819 __check_prestarted_image 'RICSIM'
1820 if [ $? -eq 0 ]; then
1821 echo -e " Scaling all kube resources for app $BOLD RICSIM $EBOLD to 0"
1822 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-a1simulator
1824 echo -e " Scaling all kube resources for app $BOLD RICSIM $EBOLD to 0"
1825 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest RICSIM
1828 __check_prestarted_image 'PA'
1829 if [ $? -eq 0 ]; then
1830 echo -e " Scaling all kube resources for app $BOLD PA $EBOLD to 0"
1831 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-policymanagementservice
1833 echo -e " Scaling all kube resources for app $BOLD PA $EBOLD to 0"
1834 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
1837 __check_prestarted_image 'ECS'
1838 if [ $? -eq 0 ]; then
1839 echo -e " Scaling all kube resources for app $BOLD ECS $EBOLD to 0"
1840 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-enrichmentservice
1842 echo -e " Scaling all kube resources for app $BOLD ECS $EBOLD to 0"
1843 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
1846 __check_prestarted_image 'RC'
1847 if [ $? -eq 0 ]; then
1848 echo -e " Scaling all kube resources for app $BOLD RC $EBOLD to 0"
1849 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-rappcatalogueservice
1851 echo -e " Scaling all kube resources for app $BOLD RC $EBOLD to 0"
1852 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest RC
1855 __check_prestarted_image 'CP'
1856 if [ $? -eq 0 ]; then
1857 echo -e " CP replicas kept as is"
1859 echo -e " Scaling all kube resources for app $BOLD CP $EBOLD to 0"
1860 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest CP
1863 __check_prestarted_image 'SDNC'
1864 if [ $? -eq 0 ]; then
1865 echo -e " SDNC replicas kept as is"
1867 echo -e " Scaling all kube resources for app $BOLD SDNC $EBOLD to 0"
1868 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest SDNC
1871 __check_prestarted_image 'MR'
1872 if [ $? -eq 0 ]; then
1873 echo -e " MR replicas kept as is"
1875 echo -e " Scaling all kube resources for app $BOLD MR $EBOLD to 0"
1876 __kube_scale_all_resources $KUBE_ONAP_NAMESPACE autotest MR
1879 __check_prestarted_image 'DMAAPMR'
1880 if [ $? -eq 0 ]; then
1881 echo -e " DMAAP replicas kept as is"
1883 echo -e " Scaling all kube resources for app $BOLD DMAAPMR $EBOLD to 0"
1884 __kube_scale_all_resources $KUBE_ONAP_NAMESPACE autotest DMAAPMR
1887 echo -e " Scaling all kube resources for app $BOLD CR $EBOLD to 0"
1888 __kube_scale_all_resources $KUBE_SIM_NAMESPACE autotest CR
1890 echo -e " Scaling all kube resources for app $BOLD PRODSTUB $EBOLD to 0"
1891 __kube_scale_all_resources $KUBE_SIM_NAMESPACE autotest PRODSTUB
1893 echo -e " Scaling all kube resources for app $BOLD HTTPPROXY $EBOLD to 0"
1894 __kube_scale_all_resources $KUBE_SIM_NAMESPACE autotest HTTPPROXY
1897 ## Clean all managed apps
1899 __check_prestarted_image 'RICSIM'
1900 if [ $? -eq 1 ]; then
1901 echo -e " Deleting all kube resources for app $BOLD RICSIM $EBOLD"
1902 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest RICSIM
1905 __check_prestarted_image 'PA'
1906 if [ $? -eq 1 ]; then
1907 echo -e " Deleting all kube resources for app $BOLD PA $EBOLD"
1908 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
1911 __check_prestarted_image 'ECS'
1912 if [ $? -eq 1 ]; then
1913 echo -e " Deleting all kube resources for app $BOLD ECS $EBOLD"
1914 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
1917 __check_prestarted_image 'RC'
1918 if [ $? -eq 1 ]; then
1919 echo -e " Deleting all kube resources for app $BOLD RC $EBOLD"
1920 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest RC
1923 __check_prestarted_image 'CP'
1924 if [ $? -eq 1 ]; then
1925 echo -e " Deleting all kube resources for app $BOLD CP $EBOLD"
1926 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest CP
1929 __check_prestarted_image 'SDNC'
1930 if [ $? -eq 1 ]; then
1931 echo -e " Deleting all kube resources for app $BOLD SDNC $EBOLD"
1932 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest SDNC
1935 __check_prestarted_image 'MR'
1936 if [ $? -eq 1 ]; then
1937 echo -e " Deleting all kube resources for app $BOLD MR $EBOLD"
1938 __kube_delete_all_resources $KUBE_ONAP_NAMESPACE autotest MR
1941 __check_prestarted_image 'DMAAPMR'
1942 if [ $? -eq 1 ]; then
1943 echo -e " Deleting all kube resources for app $BOLD DMAAPMR $EBOLD"
1944 __kube_delete_all_resources $KUBE_ONAP_NAMESPACE autotest DMAAPMR
1947 echo -e " Deleting all kube resources for app $BOLD CR $EBOLD"
1948 __kube_delete_all_resources $KUBE_SIM_NAMESPACE autotest CR
1950 echo -e " Deleting all kube resources for app $BOLD PRODSTUB $EBOLD"
1951 __kube_delete_all_resources $KUBE_SIM_NAMESPACE autotest PRODSTUB
1953 echo -e " Deleting all kube resources for app $BOLD HTTPPROXY $EBOLD"
1954 __kube_delete_all_resources $KUBE_SIM_NAMESPACE autotest HTTPPROXY
1959 # # This function scales or deletes all resources for app selected by the testcase.
1961 # # (Not for test scripts)
1963 # echo -e $BOLD"Initialize kube services//pods/statefulsets/replicaset to initial state"$EBOLD
1965 # # Clean prestarted apps
1966 # __check_prestarted_image 'RICSIM'
1967 # if [ $? -eq 0 ]; then
1968 # echo -e " Scaling all kube resources for app $BOLD RICSIM $EBOLD to 0"
1969 # __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-a1simulator
1972 # __check_prestarted_image 'PA'
1973 # if [ $? -eq 0 ]; then
1974 # echo -e " Scaling all kube resources for app $BOLD PA $EBOLD to 0"
1975 # __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-policymanagementservice
1978 # __check_prestarted_image 'ECS'
1979 # if [ $? -eq 0 ]; then
1980 # echo -e " Scaling all kube resources for app $BOLD ECS $EBOLD to 0"
1981 # __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-enrichmentservice
1984 # __check_prestarted_image 'RC'
1985 # if [ $? -eq 0 ]; then
1986 # echo -e " Scaling all kube resources for app $BOLD RC $EBOLD to 0"
1987 # __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-rappcatalogueservice
1990 # __check_prestarted_image 'CP'
1991 # if [ $? -eq 0 ]; then
1992 # echo -e " CP replicas kept as is"
1995 # __check_prestarted_image 'SDNC'
1996 # if [ $? -eq 0 ]; then
1997 # echo -e " SDNC replicas kept as is"
2000 # __check_prestarted_image 'MR'
2001 # if [ $? -eq 0 ]; then
2002 # echo -e " MR replicas kept as is"
2006 # # Clean included apps - apps fully managed by the script
2008 # ## Scale all to zero
2009 # __check_included_image 'RICSIM'
2010 # if [ $? -eq 0 ]; then
2011 # echo -e " Scaling all kube resources for app $BOLD RICSIM $EBOLD to 0"
2012 # __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest RICSIM
2015 # __check_included_image 'PA'
2016 # if [ $? -eq 0 ]; then
2017 # echo -e " Scaling all kube resources for app $BOLD PA $EBOLD to 0"
2018 # __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
2021 # __check_included_image 'ECS'
2022 # if [ $? -eq 0 ]; then
2023 # echo -e " Scaling all kube resources for app $BOLD ECS $EBOLD to 0"
2024 # __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
2027 # __check_included_image 'RC'
2028 # if [ $? -eq 0 ]; then
2029 # echo -e " Scaling all kube resources for app $BOLD RC $EBOLD to 0"
2030 # __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest RC
2033 # __check_included_image 'CP'
2034 # if [ $? -eq 0 ]; then
2035 # echo -e " Scaling all kube resources for app $BOLD CP $EBOLD to 0"
2036 # __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest CP
2039 # __check_included_image 'SDNC'
2040 # if [ $? -eq 0 ]; then
2041 # echo -e " Scaling all kube resources for app $BOLD SDNC $EBOLD to 0"
2042 # __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest SDNC
2045 # __check_included_image 'CR'
2046 # if [ $? -eq 0 ]; then
2047 # echo -e " Scaling all kube resources for app $BOLD CR $EBOLD to 0"
2048 # __kube_scale_all_resources $KUBE_SIM_NAMESPACE autotest CR
2051 # __check_included_image 'MR'
2052 # if [ $? -eq 0 ]; then
2053 # echo -e " Scaling all kube resources for app $BOLD MR $EBOLD to 0"
2054 # __kube_scale_all_resources $KUBE_ONAP_NAMESPACE autotest MR
2057 # __check_included_image 'PRODSTUB'
2058 # if [ $? -eq 0 ]; then
2059 # echo -e " Scaling all kube resources for app $BOLD PRODSTUB $EBOLD to 0"
2060 # __kube_scale_all_resources $KUBE_SIM_NAMESPACE autotest PRODSTUB
2064 # ## Remove all resources
2066 # __check_included_image 'RICSIM'
2067 # if [ $? -eq 0 ]; then
2068 # echo -e " Deleting all kube resources for app $BOLD RICSIM $EBOLD"
2069 # __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest RICSIM
2072 # __check_included_image 'PA'
2073 # if [ $? -eq 0 ]; then
2074 # echo -e " Deleting all kube resources for app $BOLD PA $EBOLD"
2075 # __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
2078 # __check_included_image 'ECS'
2079 # if [ $? -eq 0 ]; then
2080 # echo -e " Deleting all kube resources for app $BOLD ECS $EBOLD"
2081 # __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
2084 # __check_included_image 'RC'
2085 # if [ $? -eq 0 ]; then
2086 # echo -e " Deleting all kube resources for app $BOLD RC $EBOLD"
2087 # __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest RC
2090 # __check_included_image 'CP'
2091 # if [ $? -eq 0 ]; then
2092 # echo -e " Deleting all kube resources for app $BOLD CP $EBOLD"
2093 # __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest CP
2096 # __check_included_image 'SDNC'
2097 # if [ $? -eq 0 ]; then
2098 # echo -e " Deleting all kube resources for app $BOLD SDNC $EBOLD"
2099 # __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest SDNC
2102 # __check_included_image 'CR'
2103 # if [ $? -eq 0 ]; then
2104 # echo -e " Deleting all kube resources for app $BOLD CR $EBOLD"
2105 # __kube_delete_all_resources $KUBE_SIM_NAMESPACE autotest CR
2108 # __check_included_image 'MR'
2109 # if [ $? -eq 0 ]; then
2110 # echo -e " Deleting all kube resources for app $BOLD MR $EBOLD"
2111 # __kube_delete_all_resources $KUBE_ONAP_NAMESPACE autotest MR
2114 # __check_included_image 'PRODSTUB'
2115 # if [ $? -eq 0 ]; then
2116 # echo -e " Deleting all kube resources for app $BOLD PRODSTUB $EBOLD"
2117 # __kube_delete_all_resources $KUBE_SIM_NAMESPACE autotest PRODSTUB
2123 # Function stop and remove all containers (docker) and services/deployments etc(kube)
2125 # Function for test script
2126 clean_environment() {
2127 if [ $RUNMODE == "KUBE" ]; then
2135 # Function stop and remove all containers (docker) and services/deployments etc(kube) in the end of the test script, if the arg 'auto-clean' is given at test script start
2137 # (Function for test scripts)
2138 auto_clean_environment() {
2140 if [ "$AUTO_CLEAN" == "auto" ]; then
2141 echo -e $BOLD"Initiating automatic cleaning of environment"$EBOLD
2146 # Function to sleep a test case for a numner of seconds. Prints the optional text args as info
2147 # args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
2148 # (Function for test scripts)
2151 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
2152 if [ $# -lt 1 ]; then
2154 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
2157 #echo "---- Sleep for " $1 " seconds ---- "$2
2159 duration=$((SECONDS-start))
2160 while [ $duration -lt $1 ]; do
2161 echo -ne " Slept for ${duration} seconds${SAMELINE}"
2163 duration=$((SECONDS-start))
2165 echo -ne " Slept for ${duration} seconds${SAMELINE}"
2169 # Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
2170 # Not to be called from the test script itself.
2172 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
2173 if [ $# -gt 1 ]; then
2174 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
2180 # Helper function to get a the port of a specific ric simulator
2182 # (Not for test scripts)
2184 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
2185 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
2187 if [[ "$res" =~ ^[0-9]+$ ]]; then
2194 # Helper function to get a the port and host name of a specific ric simulator
2196 # (Not for test scripts)
2198 if [ $RUNMODE == "KUBE" ]; then
2199 ricname=$(echo "$1" | tr '_' '-')
2200 for timeout in {1..60}; do
2201 host=$(kubectl get pod $ricname -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.status.podIP}' 2> /dev/null)
2202 if [ ! -z "$host" ]; then
2203 echo $RIC_SIM_HTTPX"://"$host":"$RIC_SIM_PORT
2208 echo "host-not-found-fatal-error"
2210 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
2211 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
2213 if [[ "$res" =~ ^[0-9]+$ ]]; then
2214 echo $RIC_SIM_HOST:$res
2223 # Function to create the docker network for the test
2224 # Not to be called from the test script itself.
2225 __create_docker_network() {
2226 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
2227 if [ $? -ne 0 ]; then
2228 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
2231 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
2232 echo -e " Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
2233 docker network create $DOCKER_SIM_NWNAME | indent2
2234 if [ $? -ne 0 ]; then
2235 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
2238 echo -e "$GREEN Done$EGREEN"
2241 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
2245 # Function to start container with docker-compose and wait until all are in state running.
2246 #args: <docker-compose-dir> <docker-compose-arg>|NODOCKERARGS <count> <app-name>+
2247 # (Not for test scripts)
2248 __start_container() {
2249 if [ $# -lt 4 ]; then
2251 __print_err "need 4 or more args, <docker-compose-dir> <docker-compose-arg>|NODOCKERARGS <count> <app-name>+" $@
2255 __create_docker_network
2267 if [ "$compose_args" == "NODOCKERARGS" ]; then
2268 docker-compose up -d &> .dockererr
2269 if [ $? -ne 0 ]; then
2270 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
2272 echo -e $RED"Stopping script...."$ERED
2276 docker-compose up -d $compose_args &> .dockererr
2277 if [ $? -ne 0 ]; then
2278 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
2280 echo -e $RED"Stopping script...."$ERED
2288 while [ $appindex -lt $appcount ]; do
2292 for i in {1..10}; do
2293 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
2294 echo -e " Container $BOLD${appname}$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
2301 if [ $app_started -eq 0 ]; then
2304 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
2305 echo -e $RED" Stopping script..."$ERED
2308 let appindex=appindex+1
2313 # Generate a UUID to use as prefix for policy ids
2315 UUID=$(python3 -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
2316 #Reduce length to make space for serial id, uses 'a' as marker where the serial id is added
2317 UUID=${UUID:0:${#UUID}-4}"a"
2321 # Function to check if container/service is responding to http/https
2322 # args: <container-name>|<service-name> url
2323 # (Not for test scripts)
2324 __check_service_start() {
2326 if [ $# -ne 2 ]; then
2328 __print_err "need 2 args, <container-name>|<service-name> url" $@
2332 if [ $RUNMODE == "KUBE" ]; then
2333 ENTITY="service/set/deployment"
2339 echo -ne " Container $BOLD${appname}$EBOLD starting${SAMELINE}"
2343 echo -ne " Waiting for ${ENTITY} ${appname} service status...${SAMELINE}"
2345 for i in {1..50}; do
2346 result="$(__do_curl $url)"
2347 if [ $? -eq 0 ]; then
2348 if [ ${#result} -gt 15 ]; then
2349 #If response is too long, truncate
2350 result="...response text too long, omitted"
2352 echo -ne " Waiting for {ENTITY} $BOLD${appname}$EBOLD service status on ${3}, result: $result${SAMELINE}"
2353 echo -ne " The ${ENTITY} $BOLD${appname}$EBOLD$GREEN is alive$EGREEN, responds to service status:$GREEN $result $EGREEN on ${url} after $(($SECONDS-$TSTART)) seconds"
2358 while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
2359 echo -ne " Waiting for ${ENTITY} ${appname} service status on ${url}...$(($SECONDS-$TSTART)) seconds, retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
2365 if [ "$pa_st" = "false" ]; then
2367 echo -e $RED" The ${ENTITY} ${appname} did not respond to service status on ${url} in $(($SECONDS-$TSTART)) seconds"$ERED
2380 # Check the agent logs for WARNINGs and ERRORs
2382 # (Function for test scripts)
2384 check_policy_agent_logs() {
2385 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
2389 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
2392 check_control_panel_logs() {
2393 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH WARN ERR
2397 __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
2400 __check_container_logs() {
2408 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
2410 if [ $RUNMODE == "KUBE" ]; then
2411 echo -e $YELLOW" Internal log for $dispname not checked in kube"$EYELLOW
2415 #tmp=$(docker ps | grep $appname)
2416 tmp=$(docker ps -q --filter name=$appname) #get the container id
2417 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
2418 echo $dispname" is not running, no check made"
2421 foundentries="$(docker exec -t $tmp grep $warning $logpath | wc -l)"
2422 if [ $? -ne 0 ];then
2423 echo " Problem to search $appname log $logpath"
2425 if [ $foundentries -eq 0 ]; then
2426 echo " No WARN entries found in $appname log $logpath"
2428 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
2431 foundentries="$(docker exec -t $tmp grep $error $logpath | wc -l)"
2432 if [ $? -ne 0 ];then
2433 echo " Problem to search $appname log $logpath"
2435 if [ $foundentries -eq 0 ]; then
2436 echo " No ERR entries found in $appname log $logpath"
2438 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
2444 # Store all container logs and other logs in the log dir for the script
2445 # Logs are stored with a prefix in case logs should be stored several times during a test
2446 # args: <logfile-prefix>
2447 # (Function for test scripts)
2449 if [ $# != 1 ]; then
2451 __print_err "need one arg, <file-prefix>" $@
2454 echo -e $BOLD"Storing all container logs in $TESTLOGS/$ATC using prefix: "$1$EBOLD
2456 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
2458 docker ps -a > $TESTLOGS/$ATC/$1_docker_ps.log 2>&1
2460 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
2462 if [ $RUNMODE == "DOCKER" ]; then
2463 __check_included_image 'CONSUL'
2464 if [ $? -eq 0 ]; then
2465 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
2468 __check_included_image 'CBS'
2469 if [ $? -eq 0 ]; then
2470 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
2471 body="$(__do_curl $LOCALHOST_HTTP:$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
2472 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
2475 __check_included_image 'PA'
2476 if [ $? -eq 0 ]; then
2477 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
2480 __check_included_image 'ECS'
2481 if [ $? -eq 0 ]; then
2482 docker logs $ECS_APP_NAME > $TESTLOGS/$ATC/$1_ecs.log 2>&1
2485 __check_included_image 'CP'
2486 if [ $? -eq 0 ]; then
2487 docker logs $CONTROL_PANEL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
2490 __check_included_image 'MR'
2491 if [ $? -eq 0 ]; then
2492 docker logs $MR_STUB_APP_NAME > $TESTLOGS/$ATC/$1_mr_stub.log 2>&1
2495 __check_included_image 'DMAAPSMR'
2496 if [ $? -eq 0 ]; then
2497 docker logs $MR_DMAAP_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
2498 docker logs $MR_KAFKA_APP_NAME > $TESTLOGS/$ATC/$1_mr_kafka.log 2>&1
2499 docker logs $MR_ZOOKEEPER_APP_NAME > $TESTLOGS/$ATC/$1_mr_zookeeper.log 2>&1
2503 __check_included_image 'CR'
2504 if [ $? -eq 0 ]; then
2505 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
2508 __check_included_image 'SDNC'
2509 if [ $? -eq 0 ]; then
2510 docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
2513 __check_included_image 'RICSIM'
2514 if [ $? -eq 0 ]; then
2515 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
2516 for ric in $rics; do
2517 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
2521 __check_included_image 'PRODSTUB'
2522 if [ $? -eq 0 ]; then
2523 docker logs $PROD_STUB_APP_NAME > $TESTLOGS/$ATC/$1_prodstub.log 2>&1
2526 if [ $RUNMODE == "KUBE" ]; then
2527 namespaces=$(kubectl get namespaces -o jsonpath='{.items[?(@.metadata.name)].metadata.name}')
2528 for nsid in $namespaces; do
2529 pods=$(kubectl get pods -n $nsid -o jsonpath='{.items[?(@.metadata.labels.autotest)].metadata.name}')
2530 for podid in $pods; do
2531 kubectl logs -n $nsid $podid > $TESTLOGS/$ATC/$1_${podid}.log
2541 # Generic curl function, assumes all 200-codes are ok
2542 # args: <valid-curl-args-including full url>
2543 # returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
2544 # returns: The return code is 0 for ok and 1 for not ok
2546 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
2547 curlString="curl -skw %{http_code} $@"
2548 echo " CMD: $curlString" >> $HTTPLOG
2550 echo " RESP: $res" >> $HTTPLOG
2551 http_code="${res:${#res}-3}"
2552 if [ ${#res} -eq 3 ]; then
2553 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2554 echo "<no-response-from-server>"
2560 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2561 echo "<not found, resp:${http_code}>"
2564 if [ $# -eq 2 ]; then
2565 echo "${res:0:${#res}-3}" | xargs
2567 echo "${res:0:${#res}-3}"
2574 #######################################
2575 ### Basic helper function for test cases
2576 #######################################
2578 # Test a simulator container variable value towards target value using an condition operator with an optional timeout.
2579 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
2580 # immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
2581 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
2582 # before setting pass or fail depending on the result of comparing variable and target using the operator.
2583 # 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.
2584 # Not to be called from test script.
2587 checkjsonarraycount=0
2589 if [ $# -eq 6 ]; then
2590 if [[ $3 == "json:"* ]]; then
2591 checkjsonarraycount=1
2594 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
2596 ((TEST_SEQUENCE_NR++))
2600 if [ $checkjsonarraycount -eq 0 ]; then
2601 result="$(__do_curl $2$3)"
2603 result=${result//[[:blank:]]/} #Strip blanks
2606 result="$(__do_curl $2$path)"
2608 echo "$result" > ./tmp/.tmp.curl.json
2609 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
2611 duration=$((SECONDS-start))
2612 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
2614 if [ $retcode -ne 0 ]; then
2615 if [ $duration -gt $6 ]; then
2617 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
2618 __check_stop_at_error
2621 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2623 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2624 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2626 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2628 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2629 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2631 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2633 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2634 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2636 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2638 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2639 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2642 if [ $duration -gt $6 ]; then
2644 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
2645 __check_stop_at_error
2651 elif [ $# -eq 5 ]; then
2652 if [[ $3 == "json:"* ]]; then
2653 checkjsonarraycount=1
2656 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
2658 ((TEST_SEQUENCE_NR++))
2659 if [ $checkjsonarraycount -eq 0 ]; then
2660 result="$(__do_curl $2$3)"
2662 result=${result//[[:blank:]]/} #Strip blanks
2665 result="$(__do_curl $2$path)"
2667 echo "$result" > ./tmp/.tmp.curl.json
2668 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
2670 if [ $retcode -ne 0 ]; then
2672 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
2673 __check_stop_at_error
2674 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2676 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2677 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2679 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2680 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2682 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2683 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2685 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2688 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
2689 __check_stop_at_error
2692 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"