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
24 . ../common/testengine_config.sh
27 echo "Args: remote|remote-remove docker|kube --env-file <environment-filename> [release] [auto-clean] [--stop-at-error] "
28 echo " [--ricsim-prefix <prefix> ] [--use-local-image <app-nam>+] [--use-snapshot-image <app-nam>+]"
29 echo " [--use-staging-image <app-nam>+] [--use-release-image <app-nam>+] [--image-repo <repo-address]"
30 echo " [--repo-policy local|remote] [--cluster-timeout <timeout-in seconds>] [--print-stats]"
31 echo " [--override <override-environment-filename> --pre-clean --gen-stats]"
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 <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"
56 echo "--image-repo - Url to optional image repo. Only locally built images will be re-tagged and pushed to this repo"
57 echo "--repo-policy - Policy controlling which images to re-tag and push if param --image-repo is set. Default is 'local'"
58 echo "--cluster-timeout - Optional timeout for cluster where it takes time to obtain external ip/host-name. Timeout in seconds. "
59 echo "--print-stats - Print current test stats after each test."
60 echo "--override <file> - Override setting from the file supplied by --env-file"
61 echo "--pre-clean - Will clean kube resouces when running docker and vice versa"
62 echo "--gen-stats - Collect container/pod runtime statistics"
65 echo "List of app short names supported: "$APP_SHORT_NAMES
70 # Create a test case id, ATC (Auto Test Case), from the name of the test case script.
71 # FTC1.sh -> ATC == FTC1
72 ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
74 #Create result file (containing '1' for error) for this test case
75 #Will be replaced with a file containing '0' if all test cases pass
76 echo "1" > "$PWD/.result$ATC.txt"
78 #Formatting for 'echo' cmd
83 GREEN="\033[32m\033[1m"
85 YELLOW="\033[33m\033[1m"
89 # Just resetting any previous echo formatting...
92 # default test environment variables
94 #Override env file, will be added on top of the above file
95 TEST_ENV_VAR_FILE_OVERRIDE=""
97 echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@
100 LOCALHOST_NAME="localhost"
101 LOCALHOST_HTTP="http://localhost"
102 LOCALHOST_HTTPS="https://localhost"
104 # Var to hold 'auto' in case containers shall be stopped when test case ends
107 # Var to indicate pre clean, if flag --pre-clean is set the script will clean kube resouces when running docker and vice versa
110 # Var to hold the app names to use local images for
113 # Var to hold the app names to use remote snapshot images for
114 USE_SNAPSHOT_IMAGES=""
116 # Var to hold the app names to use remote staging images for
117 USE_STAGING_IMAGES=""
119 # Var to hold the app names to use remote release images for
120 USE_RELEASE_IMAGES=""
123 # 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
126 # The default value "DEV" indicate that development image tags (SNAPSHOT) and nexus repos (nexus port 10002) are used.
127 # The value "RELEASE" indicate that relase image tag and nexus repos (nexus port) are used
128 # Applies only to images defined in the test-env files with image names and tags defined as XXXX_RELEASE
131 #Var to indicate docker-compose version, V1 or V2
132 #V1 names replicated containers <proj-name>_<service-name>_<index>
133 #V2 names replicated containers <proj-name>-<service-name>-<index>
134 DOCKER_COMPOSE_VERION="V1"
136 # Function to indent cmd output with one space
137 indent1() { sed 's/^/ /'; }
139 # Function to indent cmd output with two spaces
140 indent2() { sed 's/^/ /'; }
142 # Set a description string for the test case
143 if [ -z "$TC_ONELINE_DESCR" ]; then
144 TC_ONELINE_DESCR="<no-description>"
145 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
148 # Counter for test suites
149 if [ -f .tmp_tcsuite_ctr ]; then
150 tmpval=$(< .tmp_tcsuite_ctr)
152 echo $tmpval > .tmp_tcsuite_ctr
155 # Create the logs dir if not already created in the current dir
156 if [ ! -d "logs" ]; then
161 # Create the tmp dir for temporary files that is not needed after the test
162 # hidden files for the test env is still stored in the current dir
163 # files in the ./tmp is moved to ./tmp/prev when a new test is started
164 if [ ! -d "tmp" ]; then
169 if [ $? -ne 0 ]; then
170 echo "Cannot cd to $PWD/tmp"
171 echo "Dir cannot be created. Exiting...."
173 if [ ! -d "prev" ]; then
177 mv ./tmp/* ./tmp/prev 2> /dev/null
179 # Create a http message log for this testcase
180 HTTPLOG=$PWD"/.httplog_"$ATC".txt"
183 # Create a log dir for the test case
184 mkdir -p $TESTLOGS/$ATC
186 # Save create for current logs
187 mkdir -p $TESTLOGS/$ATC/previous
189 rm $TESTLOGS/$ATC/previous/*.log &> /dev/null
190 rm $TESTLOGS/$ATC/previous/*.txt &> /dev/null
191 rm $TESTLOGS/$ATC/previous/*.json &> /dev/null
193 mv $TESTLOGS/$ATC/*.log $TESTLOGS/$ATC/previous &> /dev/null
194 mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
195 mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
197 # Clear the log dir for the test case
198 rm $TESTLOGS/$ATC/*.log &> /dev/null
199 rm $TESTLOGS/$ATC/*.txt &> /dev/null
200 rm $TESTLOGS/$ATC/*.json &> /dev/null
202 # Log all output from the test case to a TC log
203 TCLOG=$TESTLOGS/$ATC/TC.log
204 exec &> >(tee ${TCLOG})
206 #Variables for counting tests as well as passed and failed tests
213 #Var to control if current stats shall be printed
214 PRINT_CURRENT_STATS=0
216 #Var to control if container/pod runtim statistics shall be collected
217 COLLECT_RUNTIME_STATS=0
219 #File to keep deviation messages
220 DEVIATION_FILE=".tmp_deviations"
221 rm $DEVIATION_FILE &> /dev/null
223 # Trap "command not found" and make the script fail
226 if [ $? -eq 127 ]; then
227 echo -e $RED"Function not found, setting script to FAIL"$ERED
229 __print_current_stats
234 # Trap to kill subprocesses
240 # Function to log the start of a test case
242 TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
243 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ $EBOLD
244 echo "TEST $TEST_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ >> $HTTPLOG
246 ((TEST_SEQUENCE_NR++))
249 # Function to print current statistics
250 __print_current_stats() {
251 if [ $PRINT_CURRENT_STATS -ne 0 ]; then
252 echo " Current stats - exe-time, tests, passes, fails, conf fails, deviations: $(($SECONDS-$TCTEST_START)), $RES_TEST, $RES_PASS, $RES_FAIL, $RES_CONF_FAIL, $RES_DEVIATION"
256 # General function to log a failed test case
257 __log_test_fail_general() {
258 echo -e $RED" FAIL."$1 $ERED
260 __print_current_stats
261 __check_stop_at_error
264 # Function to log a test case failed due to incorrect response code
265 __log_test_fail_status_code() {
266 echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED
268 __print_current_stats
269 __check_stop_at_error
272 # Function to log a test case failed due to incorrect response body
273 __log_test_fail_body() {
274 echo -e $RED" FAIL, returned body not correct"$ERED
276 __print_current_stats
277 __check_stop_at_error
280 # Function to log a test case that is not supported
281 __log_test_fail_not_supported() {
282 echo -e $RED" FAIL, function not supported"$ERED
284 __print_current_stats
285 __check_stop_at_error
288 # General function to log a passed test case
290 if [ $# -gt 0 ]; then
294 echo -e $GREEN" PASS"$EGREEN
295 __print_current_stats
298 #Counter for configurations
301 # Function to log the start of a configuration setup
303 TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
304 echo -e $BOLD"CONF $CONF_SEQUENCE_NR (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ $EBOLD
305 echo "CONF $CONF_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ >> $HTTPLOG
306 ((CONF_SEQUENCE_NR++))
309 # Function to log a failed configuration setup
310 __log_conf_fail_general() {
311 echo -e $RED" FAIL."$1 $ERED
313 __print_current_stats
314 __check_stop_at_error
317 # Function to log a failed configuration setup due to incorrect response code
318 __log_conf_fail_status_code() {
319 echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED
321 __print_current_stats
322 __check_stop_at_error
325 # Function to log a failed configuration setup due to incorrect response body
326 __log_conf_fail_body() {
327 echo -e $RED" FAIL, returned body not correct"$ERED
329 __print_current_stats
330 __check_stop_at_error
333 # Function to log a configuration that is not supported
334 __log_conf_fail_not_supported() {
335 echo -e $RED" FAIL, function not supported"$ERED$@
337 __print_current_stats
338 __check_stop_at_error
341 # Function to log a passed configuration setup
343 if [ $# -gt 0 ]; then
346 echo -e $GREEN" OK"$EGREEN
347 __print_current_stats
350 #Var for measuring execution time
351 TCTEST_START=$SECONDS
353 #Vars to hold the start time and timer text for a custom timer
354 TC_TIMER_STARTTIME=""
355 TC_TIMER_TIMER_TEXT=""
356 TC_TIMER_CURRENT_FAILS="" # Then numer of failed test when timer starts.
357 # Compared with the current number of fails at timer stop
358 # to judge the measurement reliability
360 #File to save timer measurement results
361 TIMER_MEASUREMENTS=".timer_measurement.txt"
362 echo -e "Activity \t Duration \t Info" > $TIMER_MEASUREMENTS
364 # If this is set, some images (control by the parameter repo-polcy) will be re-tagged and pushed to this repo before any
366 IMAGE_REPO_POLICY="local"
369 echo "-------------------------------------------------------------------------------------------------"
370 echo "----------------------------------- Test case: "$ATC
371 echo "----------------------------------- Started: "$(date)
372 echo "-------------------------------------------------------------------------------------------------"
373 echo "-- Description: "$TC_ONELINE_DESCR
374 echo "-------------------------------------------------------------------------------------------------"
375 echo "----------------------------------- Test case setup -----------------------------------"
377 echo "Setting AUTOTEST_HOME="$AUTOTEST_HOME
381 if [ $# -lt 1 ]; then
384 if [ $paramerror -eq 0 ]; then
385 if [ "$1" != "remote" ] && [ "$1" != "remote-remove" ]; then
387 if [ -z "$paramerror_str" ]; then
388 paramerror_str="First arg shall be 'remote' or 'remote-remove'"
394 if [ $paramerror -eq 0 ]; then
395 if [ "$1" != "docker" ] && [ "$1" != "kube" ]; then
397 if [ -z "$paramerror_str" ]; then
398 paramerror_str="Second arg shall be 'docker' or 'kube'"
401 if [ $1 == "docker" ]; then
403 echo "Setting RUNMODE=DOCKER"
405 if [ $1 == "kube" ]; then
407 echo "Setting RUNMODE=KUBE"
413 while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do
415 if [ $paramerror -eq 0 ]; then
416 if [ "$1" == "release" ]; then
417 IMAGE_CATEGORY="RELEASE"
418 echo "Option set - Release image tags used for applicable images "
423 if [ $paramerror -eq 0 ]; then
424 if [ "$1" == "auto-clean" ]; then
426 echo "Option set - Auto clean at end of test script"
431 if [ $paramerror -eq 0 ]; then
432 if [ "$1" == "--stop-at-error" ]; then
434 echo "Option set - Stop at first error"
439 if [ $paramerror -eq 0 ]; then
440 if [ "$1" == "--ricsim-prefix" ]; then
442 TMP_RIC_SIM_PREFIX=$1 #RIC_SIM_PREFIX need to be updated after sourcing of the env file
445 if [ -z "$paramerror_str" ]; then
446 paramerror_str="No prefix found for flag: '--ricsim-prefix'"
449 echo "Option set - Overriding RIC_SIM_PREFIX with: "$1
455 if [ $paramerror -eq 0 ]; then
456 if [ "$1" == "--env-file" ]; then
461 if [ -z "$paramerror_str" ]; then
462 paramerror_str="No env file found for flag: '--env-file'"
465 echo "Option set - Reading test env from: "$1
471 if [ $paramerror -eq 0 ]; then
472 if [ "$1" == "--use-local-image" ]; then
475 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
476 USE_LOCAL_IMAGES=$USE_LOCAL_IMAGES" "$1
477 if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
479 if [ -z "$paramerror_str" ]; then
480 paramerror_str="App name $1 is not available for local override for flag: '--use-local-image'"
486 if [ -z "$USE_LOCAL_IMAGES" ]; then
488 if [ -z "$paramerror_str" ]; then
489 paramerror_str="No app name found for flag: '--use-local-image'"
492 echo "Option set - Overriding with local images for app(s):"$USE_LOCAL_IMAGES
496 if [ $paramerror -eq 0 ]; then
497 if [ "$1" == "--use-snapshot-image" ]; then
498 USE_SNAPSHOT_IMAGES=""
500 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
501 USE_SNAPSHOT_IMAGES=$USE_SNAPSHOT_IMAGES" "$1
502 if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
504 if [ -z "$paramerror_str" ]; then
505 paramerror_str="App name $1 is not available for snapshot override for flag: '--use-snapshot-image'"
511 if [ -z "$USE_SNAPSHOT_IMAGES" ]; then
513 if [ -z "$paramerror_str" ]; then
514 paramerror_str="No app name found for flag: '--use-snapshot-image'"
517 echo "Option set - Overriding with snapshot images for app(s):"$USE_SNAPSHOT_IMAGES
521 if [ $paramerror -eq 0 ]; then
522 if [ "$1" == "--use-staging-image" ]; then
523 USE_STAGING_IMAGES=""
525 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
526 USE_STAGING_IMAGES=$USE_STAGING_IMAGES" "$1
527 if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
529 if [ -z "$paramerror_str" ]; then
530 paramerror_str="App name $1 is not available for staging override for flag: '--use-staging-image'"
536 if [ -z "$USE_STAGING_IMAGES" ]; then
538 if [ -z "$paramerror_str" ]; then
539 paramerror_str="No app name found for flag: '--use-staging-image'"
542 echo "Option set - Overriding with staging images for app(s):"$USE_STAGING_IMAGES
546 if [ $paramerror -eq 0 ]; then
547 if [ "$1" == "--use-release-image" ]; then
548 USE_RELEASE_IMAGES=""
550 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
551 USE_RELEASE_IMAGES=$USE_RELEASE_IMAGES" "$1
552 if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
554 if [ -z "$paramerror_str" ]; then
555 paramerror_str="App name $1 is not available for release override for flag: '--use-release-image'"
561 if [ -z "$USE_RELEASE_IMAGES" ]; then
563 if [ -z "$paramerror_str" ]; then
564 paramerror_str="No app name found for flag: '--use-release-image'"
567 echo "Option set - Overriding with release images for app(s):"$USE_RELEASE_IMAGES
571 if [ $paramerror -eq 0 ]; then
572 if [ "$1" == "--image-repo" ]; then
577 if [ -z "$paramerror_str" ]; then
578 paramerror_str="No image repo url found for : '--image-repo'"
581 echo "Option set - Image repo url: "$1
587 if [ $paramerror -eq 0 ]; then
588 if [ "$1" == "--repo-policy" ]; then
593 if [ -z "$paramerror_str" ]; then
594 paramerror_str="No policy found for : '--repo-policy'"
597 if [ "$1" == "local" ] || [ "$1" == "remote" ]; then
598 echo "Option set - Image repo policy: "$1
603 if [ -z "$paramerror_str" ]; then
604 paramerror_str="Repo policy shall be 'local' or 'remote'"
610 if [ $paramerror -eq 0 ]; then
611 if [ "$1" == "--cluster-timeout" ]; then
616 if [ -z "$paramerror_str" ]; then
617 paramerror_str="No timeout value found for : '--cluster-timeout'"
620 #Check if positive int
621 case ${CLUSTER_TIME_OUT#[+]} in
624 if [ -z "$paramerror_str" ]; then
625 paramerror_str="Value for '--cluster-timeout' not an int : "$CLUSTER_TIME_OUT
630 echo "Option set - Cluster timeout: "$1
636 if [ $paramerror -eq 0 ]; then
637 if [ "$1" == "--override" ]; then
639 TEST_ENV_VAR_FILE_OVERRIDE=$1
642 if [ -z "$paramerror_str" ]; then
643 paramerror_str="No env file found for flag: '--override'"
646 if [ ! -f $TEST_ENV_VAR_FILE_OVERRIDE ]; then
648 if [ -z "$paramerror_str" ]; then
649 paramerror_str="File for '--override' does not exist : "$TEST_ENV_VAR_FILE_OVERRIDE
652 echo "Option set - Override env from: "$1
658 if [ $paramerror -eq 0 ]; then
659 if [ "$1" == "--pre-clean" ]; then
661 echo "Option set - Pre-clean of kube/docker resouces"
666 if [ $paramerror -eq 0 ]; then
667 if [ "$1" == "--print-stats" ]; then
668 PRINT_CURRENT_STATS=1
669 echo "Option set - Print stats after every test-case and config"
674 if [ $paramerror -eq 0 ]; then
675 if [ "$1" == "--gen-stats" ]; then
676 COLLECT_RUNTIME_STATS=1
677 echo "Option set - Collect runtime statistics"
687 if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
689 if [ -z "$paramerror_str" ]; then
690 paramerror_str="Unknown parameter(s): "$@
694 if [ $paramerror -eq 1 ]; then
695 echo -e $RED"Incorrect arg list: "$paramerror_str$ERED
700 # sourcing the selected env variables for the test case
701 if [ -f "$TEST_ENV_VAR_FILE" ]; then
702 echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD
704 if [ ! -z "$TEST_ENV_VAR_FILE_OVERRIDE" ]; then
705 echo -e $BOLD"Sourcing override env vars from: "$TEST_ENV_VAR_FILE_OVERRIDE$EBOLD
706 . $TEST_ENV_VAR_FILE_OVERRIDE
709 if [ -z "$TEST_ENV_PROFILE" ] || [ -z "$SUPPORTED_PROFILES" ]; then
710 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
713 for prof in $SUPPORTED_PROFILES; do
714 if [ "$TEST_ENV_PROFILE" == "$prof" ]; then
715 echo -e $GREEN"Test case supports the selected test env file"$EGREEN
719 if [ $found_profile -ne 1 ]; then
720 echo -e $RED"Test case does not support the selected test env file"$ERED
721 echo "Profile: "$TEST_ENV_PROFILE" Supported profiles: "$SUPPORTED_PROFILES
722 echo -e $RED"Exiting...."$ERED
727 echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED
728 echo " Select one of following env var file matching the intended target of the test"
729 echo " Restart the test using the flag '--env-file <path-to-env-file>"
730 ls $AUTOTEST_HOME/../common/test_env* | indent1
734 #This var need be preserved from the command line option, if set, when env var is sourced.
735 if [ ! -z "$TMP_RIC_SIM_PREFIX" ]; then
736 RIC_SIM_PREFIX=$TMP_RIC_SIM_PREFIX
739 if [ -z "$PROJECT_IMAGES_APP_NAMES" ]; then
740 echo -e $RED"Var PROJECT_IMAGES_APP_NAMES must be defined in: "$TEST_ENV_VAR_FILE $ERED
744 if [[ $SUPPORTED_RUNMODES != *"$RUNMODE"* ]]; then
745 echo -e $RED"This test script does not support RUNMODE $RUNMODE"$ERED
746 echo "Supported RUNMODEs: "$SUPPORTED_RUNMODES
750 # Choose list of included apps depending on run-mode
751 if [ $RUNMODE == "KUBE" ]; then
752 INCLUDED_IMAGES=$KUBE_INCLUDED_IMAGES
754 INCLUDED_IMAGES=$DOCKER_INCLUDED_IMAGES
758 # auto adding system apps
760 echo -e $BOLD"Auto adding system apps"$EBOLD
761 if [ $RUNMODE == "KUBE" ]; then
762 INCLUDED_IMAGES=$INCLUDED_IMAGES" "$TESTENV_KUBE_SYSTEM_APPS
763 TMP_APPS=$TESTENV_KUBE_SYSTEM_APPS
765 INCLUDED_IMAGES=$INCLUDED_IMAGES" "$TESTENV_DOCKER_SYSTEM_APPS
766 TMP_APPS=$TESTENV_DOCKER_SYSTEM_APPS
768 if [ ! -z "$TMP_APPS" ]; then
769 for iapp in "$TMP_APPS"; do
770 file_pointer=$(echo $iapp | tr '[:upper:]' '[:lower:]')
771 file_pointer="../common/"$file_pointer"_api_functions.sh"
773 while [ ${#padded_iapp} -lt 16 ]; do
774 padded_iapp=$padded_iapp" "
776 echo " Auto-adding system app $padded_iapp Sourcing $file_pointer"
778 __added_apps=" $iapp "$__added_apps
784 if [ $RUNMODE == "KUBE" ]; then
785 TMP_APPS=$INCLUDED_IMAGES" "$KUBE_PRESTARTED_IMAGES
787 TMP_APPS=$INCLUDED_IMAGES
790 echo -e $BOLD"Auto adding included apps"$EBOLD
791 for iapp in $TMP_APPS; do
792 if [[ "$__added_apps" != *"$iapp"* ]]; then
793 file_pointer=$(echo $iapp | tr '[:upper:]' '[:lower:]')
794 file_pointer="../common/"$file_pointer"_api_functions.sh"
796 while [ ${#padded_iapp} -lt 16 ]; do
797 padded_iapp=$padded_iapp" "
799 echo " Auto-adding included app $padded_iapp Sourcing $file_pointer"
801 if [ ! -f "$file_pointer" ]; then
802 echo " Include file $file_pointer for app $iapp does not exist"
809 echo -e $BOLD"Test environment info"$EBOLD
811 # Check needed installed sw
814 if [ $? -ne 0 ] || [ -z "$tmp" ]; then
815 echo -e $RED"bash is required to run the test environment, pls install"$ERED
818 echo " bash is installed and using version:"
819 echo "$(bash --version)" | indent2
822 if [ $? -ne 0 ] || [ -z "$tmp" ]; then
823 echo -e $RED"python3 is required to run the test environment, pls install"$ERED
826 echo " python3 is installed and using version: $(python3 --version)"
829 if [ $? -ne 0 ] || [ -z "$tmp" ]; then
830 echo -e $RED"docker is required to run the test environment, pls install"$ERED
833 echo " docker is installed and using versions:"
834 echo " $(docker version --format 'Client version {{.Client.Version}} Server version {{.Server.Version}}')"
836 tmp=$(which docker-compose)
837 if [ $? -ne 0 ] || [ -z "$tmp" ]; then
838 if [ $RUNMODE == "DOCKER" ]; then
839 echo -e $RED"docker-compose is required to run the test environment, pls install"$ERED
843 tmp=$(docker-compose version --short)
844 echo " docker-compose installed and using version $tmp"
845 if [[ "$tmp" == *'v2'* ]]; then
846 DOCKER_COMPOSE_VERION="V2"
850 if [ $? -ne 0 ] || [ -z tmp ]; then
851 if [ $RUNMODE == "KUBE" ]; then
852 echo -e $RED"kubectl is required to run the test environment in kubernetes mode, pls install"$ERED
856 if [ $RUNMODE == "KUBE" ]; then
857 echo " kubectl is installed and using versions:"
858 echo $(kubectl version --short=true) | indent2
859 res=$(kubectl cluster-info 2>&1)
860 if [ $? -ne 0 ]; then
861 echo -e "$BOLD$RED############################################# $ERED$EBOLD"
862 echo -e $BOLD$RED"Command 'kubectl cluster-info' returned error $ERED$EBOLD"
863 echo -e "$BOLD$RED############################################# $ERED$EBOLD"
865 echo "kubectl response:"
868 echo "This script may have been started with user with no permission to run kubectl"
869 echo "Try running with 'sudo' or set 'KUBECONFIG'"
870 echo "Do either 1, 2 or 3 "
874 echo -e $BOLD"sudo <test-script-and-parameters>"$EBOLD
877 echo "Export KUBECONFIG and pass env to sudo - (replace user)"
878 echo -e $BOLD"export KUBECONFIG='/home/<user>/.kube/config'"$EBOLD
879 echo -e $BOLD"sudo -E <test-script-and-parameters>"$EBOLD
882 echo "Set KUBECONFIG inline (replace user)"
883 echo -e $BOLD"sudo KUBECONFIG='/home/<user>/.kube/config' <test-script-and-parameters>"$EBOLD
892 echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
894 #Temp var to check for image variable name errors
896 #Create a file with image info for later printing as a table
897 image_list_file="./tmp/.image-list"
898 echo -e "Application\tApp short name\tImage\ttag\ttag-switch" > $image_list_file
900 # Check if image env var is set and if so export the env var with image to use (used by docker compose files)
901 # arg: <app-short-name> <target-variable-name> <image-variable-name> <image-tag-variable-name> <tag-suffix> <image name>
902 __check_and_create_image_var() {
904 if [ $# -ne 6 ]; then
905 echo "Expected arg: <app-short-name> <target-variable-name> <image-variable-name> <image-tag-variable-name> <tag-suffix> <image name>"
910 __check_included_image $1
911 if [ $? -ne 0 ]; then
912 echo -e "$6\t$1\t<image-excluded>\t<no-tag>" >> $image_list_file
913 # Image is excluded since the corresponding app is not used in this test
917 #Create var from the input var names
922 optional_image_repo_target=""
924 if [ -z $image ]; then
925 __check_ignore_image $1
926 if [ $? -eq 0 ]; then
929 app_ds="<app ignored>"
931 echo -e "$app_ds\t$1\t<image-ignored>\t<no-tag>" >> $image_list_file
932 # Image is ignored since the corresponding the images is not set in the env file
933 __remove_included_image $1 # Remove the image from the list of included images
936 echo -e $RED"\$"$3" not set in $TEST_ENV_VAR_FILE"$ERED
939 tmp=$tmp"<no-image>\t"
942 optional_image_repo_target=$image
944 #Add repo depending on image type
945 if [ "$5" == "REMOTE_RELEASE" ]; then
946 image=$NEXUS_RELEASE_REPO$image
948 if [ "$5" == "REMOTE" ]; then
949 image=$NEXUS_STAGING_REPO$image
951 if [ "$5" == "REMOTE_SNAPSHOT" ]; then
952 image=$NEXUS_SNAPSHOT_REPO$image
954 if [ "$5" == "REMOTE_PROXY" ]; then
955 image=$NEXUS_PROXY_REPO$image
957 if [ "$5" == "REMOTE_RELEASE_ONAP" ]; then
958 image=$NEXUS_RELEASE_REPO_ONAP$image
960 if [ "$5" == "REMOTE_RELEASE_ORAN" ]; then
961 image=$NEXUS_RELEASE_REPO_ORAN$image
963 #No nexus repo added for local images, tag: LOCAL
967 echo -e $RED"\$"$tmptag" not set in $TEST_ENV_VAR_FILE"$ERED
975 echo -e "$tmp" >> $image_list_file
977 export "${2}"=$image":"$tag #Note, this var may be set to the value of the target value below in __check_and_pull_image
979 remote_or_local_push=false
980 if [ ! -z "$IMAGE_REPO_ADR" ] && [[ $5 != *"PROXY"* ]]; then
981 if [ $5 == "LOCAL" ]; then
982 remote_or_local_push=true
984 if [[ $5 == *"REMOTE"* ]]; then
985 if [ "$IMAGE_REPO_POLICY" == "remote" ]; then
986 remote_or_local_push=true
990 if $remote_or_local_push; then # Only re-tag and push images according to policy, if repo is given
991 export "${2}_SOURCE"=$image":"$tag #Var to keep the actual source image
992 if [[ $optional_image_repo_target == *"/"* ]]; then # Replace all / with _ for images to push to external repo
993 optional_image_repo_target_tmp=${optional_image_repo_target//\//_}
994 optional_image_repo_target=$optional_image_repo_target_tmp
996 export "${2}_TARGET"=$IMAGE_REPO_ADR"/"$optional_image_repo_target":"$tag #Create image + tag for optional image repo - pushed later if needed
998 export "${2}_SOURCE"=""
999 export "${2}_TARGET"=""
1003 # Check if app uses image included in this test run
1004 # Returns 0 if image is included, 1 if not
1005 __check_included_image() {
1006 for im in $INCLUDED_IMAGES; do
1007 if [ "$1" == "$im" ]; then
1014 # Check if app uses a project image
1015 # Returns 0 if image is included, 1 if not
1016 __check_project_image() {
1017 for im in $PROJECT_IMAGES; do
1018 if [ "$1" == "$im" ]; then
1025 # Check if app uses image built by the test script
1026 # Returns 0 if image is included, 1 if not
1027 __check_image_local_build() {
1028 for im in $LOCAL_IMAGE_BUILD; do
1029 if [ "$1" == "$im" ]; then
1036 # Check if app image is conditionally ignored in this test run
1037 # Returns 0 if image is conditionally ignored, 1 if not
1038 __check_ignore_image() {
1039 for im in $CONDITIONALLY_IGNORED_IMAGES; do
1040 if [ "$1" == "$im" ]; then
1047 # Removed image from included list of included images
1048 # Used when an image is marked as conditionally ignored
1049 __remove_included_image() {
1051 for im in $INCLUDED_IMAGES; do
1052 if [ "$1" != "$im" ]; then
1053 tmp_img_rem_list=$tmp_img_rem_list" "$im
1056 INCLUDED_IMAGES=$tmp_img_rem_list
1060 # Check if app is included in the prestarted set of apps
1061 # Returns 0 if image is included, 1 if not
1062 __check_prestarted_image() {
1063 for im in $KUBE_PRESTARTED_IMAGES; do
1064 if [ "$1" == "$im" ]; then
1071 # Check if an app shall use a local image, based on the cmd parameters
1072 __check_image_local_override() {
1073 for im in $USE_LOCAL_IMAGES; do
1074 if [ "$1" == "$im" ]; then
1081 # Check if app uses image override
1082 # Returns the image/tag suffix LOCAL for local image or REMOTE/REMOTE_RELEASE/REMOTE_SNAPSHOT for staging/release/snapshot image
1083 __check_image_override() {
1085 for im in $ORAN_IMAGES_APP_NAMES; do
1086 if [ "$1" == "$im" ]; then
1087 echo "REMOTE_RELEASE_ORAN"
1092 for im in $ONAP_IMAGES_APP_NAMES; do
1093 if [ "$1" == "$im" ]; then
1094 echo "REMOTE_RELEASE_ONAP"
1100 for im in $PROJECT_IMAGES_APP_NAMES; do
1101 if [ "$1" == "$im" ]; then
1106 if [ $found -eq 0 ]; then
1112 if [ $IMAGE_CATEGORY == "RELEASE" ]; then
1113 suffix="REMOTE_RELEASE"
1115 if [ $IMAGE_CATEGORY == "DEV" ]; then
1119 for im in $USE_STAGING_IMAGES; do
1120 if [ "$1" == "$im" ]; then
1125 for im in $USE_RELEASE_IMAGES; do
1126 if [ "$1" == "$im" ]; then
1127 suffix="REMOTE_RELEASE"
1131 for im in $USE_SNAPSHOT_IMAGES; do
1132 if [ "$1" == "$im" ]; then
1133 suffix="REMOTE_SNAPSHOT"
1137 for im in $USE_LOCAL_IMAGES; do
1138 if [ "$1" == "$im" ]; then
1144 if [ $CTR -gt 1 ]; then
1150 # Function to re-tag and image and push to another image repo
1151 __retag_and_push_image() {
1152 if [ ! -z "$IMAGE_REPO_ADR" ]; then
1153 source_image="${!1}"
1154 trg_var_name=$1_"TARGET" # This var is created in func __check_and_create_image_var
1155 target_image="${!trg_var_name}"
1157 if [ -z $target_image ]; then
1158 return 0 # Image with no target shall not be pushed
1161 echo -ne " Attempt to re-tag image to: ${BOLD}${target_image}${EBOLD}${SAMELINE}"
1162 tmp=$(docker image tag $source_image ${target_image} )
1163 if [ $? -ne 0 ]; then
1164 docker stop $tmp &> ./tmp/.dockererr
1167 echo -e " Attempt to re-tag image to: ${BOLD}${target_image}${EBOLD} - ${RED}Failed${ERED}"
1168 cat ./tmp/.dockererr
1171 echo -e " Attempt to re-tag image to: ${BOLD}${target_image}${EBOLD} - ${GREEN}OK${EGREEN}"
1173 echo -ne " Attempt to push re-tagged image: ${BOLD}${target_image}${EBOLD}${SAMELINE}"
1174 tmp=$(docker push ${target_image} )
1175 if [ $? -ne 0 ]; then
1176 docker stop $tmp &> ./tmp/.dockererr
1179 echo -e " Attempt to push re-tagged image: ${BOLD}${target_image}${EBOLD} - ${RED}Failed${ERED}"
1180 cat ./tmp/.dockererr
1183 echo -e " Attempt to push re-tagged image: ${BOLD}${target_image}${EBOLD} - ${GREEN}OK${EGREEN}"
1185 export "${1}"=$target_image
1190 #Function to check if image exist and stop+remove the container+pull new images as needed
1191 #args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag-var-name>
1192 __check_and_pull_image() {
1194 source_image="${!4}"
1196 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$source_image$EBOLD"
1197 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
1198 tmp_im=$(docker images --format $format_string $source_image)
1200 if [ $1 == "local" ]; then
1201 if [ -z "$tmp_im" ]; then
1202 echo -e " "$2" (local image): \033[1m"$source_image"\033[0m $RED does not exist in local registry, need to be built (or manually pulled)"$ERED
1206 echo -e " "$2" (local image): \033[1m"$source_image"\033[0m "$GREEN"OK"$EGREEN
1208 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
1209 if [ $1 == "remote-remove" ]; then
1210 if [ $RUNMODE == "DOCKER" ]; then
1211 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
1212 tmp=$(docker ps -aq --filter name=${3} --filter network=${DOCKER_SIM_NWNAME})
1213 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
1214 docker stop $tmp &> ./tmp/.dockererr
1215 if [ $? -ne 0 ]; then
1218 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
1219 cat ./tmp/.dockererr
1223 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
1224 tmp=$(docker ps -aq --filter name=${3} --filter network=${DOCKER_SIM_NWNAME}) &> /dev/null
1225 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
1226 docker rm $tmp &> ./tmp/.dockererr
1227 if [ $? -ne 0 ]; then
1230 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
1231 cat ./tmp/.dockererr
1235 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
1241 if [ -z "$tmp_im" ]; then
1242 echo -ne " Pulling image${SAMELINE}"
1243 out=$(docker pull $source_image)
1244 if [ $? -ne 0 ]; then
1246 echo -e " Pulling image -$RED could not be pulled"$ERED
1248 echo $out > ./tmp/.dockererr
1252 echo $out > ./tmp/.dockererr
1253 if [[ $out == *"up to date"* ]]; then
1254 echo -e " Pulling image -$GREEN Image is up to date $EGREEN"
1255 elif [[ $out == *"Downloaded newer image"* ]]; then
1256 echo -e " Pulling image -$GREEN Newer image pulled $EGREEN"
1258 echo -e " Pulling image -$GREEN Pulled $EGREEN"
1261 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
1265 __retag_and_push_image $4
1270 setup_testenvironment() {
1271 # Check that image env setting are available
1274 # Image var setup for all project images included in the test
1275 for imagename in $APP_SHORT_NAMES; do
1276 __check_included_image $imagename
1278 __check_project_image $imagename
1280 if [ $incl -eq 0 ]; then
1281 if [ $proj -eq 0 ]; then
1282 IMAGE_SUFFIX=$(__check_image_override $imagename)
1283 if [ $? -ne 0 ]; then
1284 echo -e $RED"Image setting from cmd line not consistent for $imagename."$ERED
1290 # A function name is created from the app short name
1291 # for example app short name 'ICS' -> produce the function
1292 # name __ICS_imagesetup
1293 # This function is called and is expected to exist in the imported
1294 # file for the ics test functions
1295 # The resulting function impl will call '__check_and_create_image_var' function
1296 # with appropriate parameters
1297 # If the image suffix is none, then the component decides the suffix
1298 function_pointer="__"$imagename"_imagesetup"
1299 $function_pointer $IMAGE_SUFFIX
1303 #Errors in image setting - exit
1304 if [ $IMAGE_ERR -ne 0 ]; then
1308 #Print a tables of the image settings
1309 echo -e $BOLD"Images configured for start arg: "$START_ARG $EBOLD
1310 column -t -s $'\t' $image_list_file | indent1
1314 #Set the SIM_GROUP var
1315 echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
1316 if [ -z "$SIM_GROUP" ]; then
1317 SIM_GROUP=$AUTOTEST_HOME/../simulator-group
1318 if [ ! -d $SIM_GROUP ]; then
1319 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
1320 echo -e $RED"Please set the SIM_GROUP manually in the applicable $TEST_ENV_VAR_FILE"$ERED
1323 echo " SIM_GROUP auto set to: " $SIM_GROUP
1325 elif [ $SIM_GROUP = *simulator_group ]; then
1326 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
1329 echo " SIM_GROUP env var already set to: " $SIM_GROUP
1334 #Temp var to check for image pull errors
1337 # The following sequence pull the configured images
1340 echo -e $BOLD"Pulling configured images, if needed"$EBOLD
1341 if [ ! -z "$IMAGE_REPO_ADR" ] && [ $IMAGE_REPO_POLICY == "local" ]; then
1342 echo -e $YELLOW" Excluding all remote image check/pull when running with image repo: $IMAGE_REPO_ADR and image policy $IMAGE_REPO_POLICY"$EYELLOW
1344 for imagename in $APP_SHORT_NAMES; do
1345 __check_included_image $imagename
1347 __check_project_image $imagename
1349 if [ $incl -eq 0 ]; then
1350 if [ $proj -eq 0 ]; then
1351 START_ARG_MOD=$START_ARG
1352 __check_image_local_override $imagename
1353 if [ $? -eq 1 ]; then
1354 START_ARG_MOD="local"
1357 START_ARG_MOD=$START_ARG
1359 __check_image_local_build $imagename
1360 #No pull of images built locally
1361 if [ $? -ne 0 ]; then
1362 # A function name is created from the app short name
1363 # for example app short name 'HTTPPROXY' -> produce the function
1364 # name __HTTPPROXY_imagesetup
1365 # This function is called and is expected to exist in the imported
1366 # file for the httpproxy test functions
1367 # The resulting function impl will call '__check_and_pull_image' function
1368 # with appropriate parameters
1369 function_pointer="__"$imagename"_imagepull"
1370 $function_pointer $START_ARG_MOD $START_ARG
1373 echo -e $YELLOW" Excluding $imagename image from image check/pull"$EYELLOW
1378 #Errors in image setting - exit
1379 if [ $IMAGE_ERR -ne 0 ]; then
1381 echo "#################################################################################################"
1382 echo -e $RED"One or more images could not be pulled or containers using the images could not be stopped/removed"$ERED
1383 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
1384 if [ $IMAGE_CATEGORY == "DEV" ]; then
1386 echo -e $RED"Note that SNAPSHOT and staging images may be purged from nexus after a certain period."$ERED
1387 echo -e $RED"In addition, the image may not have been updated in the current release so no SNAPSHOT or staging image exists"$ERED
1388 echo -e $RED"In these cases, switch to use a released image instead, use the flag '--use-release-image <App-short-name>'"$ERED
1389 echo -e $RED"Use the 'App-short-name' for the applicable image from the above table: 'Images configured for start arg'."$ERED
1391 echo "#################################################################################################"
1398 echo -e $BOLD"Building images needed for test"$EBOLD
1400 for imagename in $APP_SHORT_NAMES; do
1401 cd $AUTOTEST_HOME #Always reset to orig dir
1402 __check_image_local_build $imagename
1403 if [ $? -eq 0 ]; then
1404 __check_included_image $imagename
1405 if [ $? -eq 0 ]; then
1406 # A function name is created from the app short name
1407 # for example app short name 'MR' -> produce the function
1408 # name __MR_imagebuild
1409 # This function is called and is expected to exist in the imported
1410 # file for the mr test functions
1411 # The resulting function impl shall build the imagee
1412 function_pointer="__"$imagename"_imagebuild"
1416 echo -e $YELLOW" Excluding image for app $imagename from image build"$EYELLOW
1421 cd $AUTOTEST_HOME # Just to make sure...
1425 # Create a table of the images used in the script - from local repo
1426 echo -e $BOLD"Local docker registry images used in this test script"$EBOLD
1428 docker_tmp_file=./tmp/.docker-images-table
1429 format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\\t{{.CreatedAt}}"
1430 echo -e "Application\tRepository\tTag\tCreated since\tSize\tCreated at" > $docker_tmp_file
1432 for imagename in $APP_SHORT_NAMES; do
1433 __check_included_image $imagename
1434 if [ $? -eq 0 ]; then
1435 # Only print image data if image repo is null, or if image repo is set and image is local
1437 if [ -z "$IMAGE_REPO_ADR" ]; then
1440 __check_image_local_build $imagename
1441 if [ $? -eq 0 ]; then
1445 if [ $print_image_data -eq 1 ]; then
1446 # A function name is created from the app short name
1447 # for example app short name 'MR' -> produce the function
1448 # name __MR_imagebuild
1449 # This function is called and is expected to exist in the imported
1450 # file for the mr test functions
1451 # The resulting function impl shall build the imagee
1452 function_pointer="__"$imagename"_image_data"
1453 $function_pointer "$format_string" $docker_tmp_file
1458 column -t -s $'\t' $docker_tmp_file | indent1
1462 if [ ! -z "$IMAGE_REPO_ADR" ]; then
1464 # Create a table of the images used in the script - from remote repo
1465 echo -e $BOLD"Remote repo images used in this test script"$EBOLD
1466 echo -e $YELLOW"-- Note: These image will be pulled when the container starts. Images not managed by the test engine --"$EYELLOW
1468 docker_tmp_file=./tmp/.docker-images-table
1469 format_string="{{.Repository}}\\t{{.Tag}}"
1470 echo -e "Application\tRepository\tTag" > $docker_tmp_file
1472 for imagename in $APP_SHORT_NAMES; do
1473 __check_included_image $imagename
1474 if [ $? -eq 0 ]; then
1475 # Only print image data if image repo is null, or if image repo is set and image is local
1476 __check_image_local_build $imagename
1477 if [ $? -ne 0 ]; then
1478 # A function name is created from the app short name
1479 # for example app short name 'MR' -> produce the function
1480 # name __MR_imagebuild
1481 # This function is called and is expected to exist in the imported
1482 # file for the mr test functions
1483 # The resulting function impl shall build the imagee
1484 function_pointer="__"$imagename"_image_data"
1485 $function_pointer "$format_string" $docker_tmp_file
1490 column -t -s $'\t' $docker_tmp_file | indent1
1495 if [ $RUNMODE == "KUBE" ]; then
1497 echo "================================================================================="
1498 echo "================================================================================="
1500 if [ -z "$IMAGE_REPO_ADR" ]; then
1501 echo -e $YELLOW" The image pull policy is set to 'Never' - assuming a local image repo is available for all images"$EYELLOW
1502 echo -e " This setting only works on single node clusters on the local machine"
1503 echo -e " It does not work with multi-node clusters or remote clusters. "
1504 export KUBE_IMAGE_PULL_POLICY="Never"
1506 echo -e $YELLOW" The image pull policy is set to 'Always'"$EYELLOW
1507 echo -e " This setting work on local clusters, multi-node clusters and remote cluster. "
1508 echo -e " Only locally built images are managed. Remote images are always pulled from remote repos"
1509 echo -e " Pulling remote snapshot or staging images my in some case result in pulling newer image versions outside the control of the test engine"
1510 export KUBE_IMAGE_PULL_POLICY="Always"
1512 CLUSTER_IP=$(kubectl config view -o jsonpath={.clusters[0].cluster.server} | awk -F[/:] '{print $4}')
1513 echo -e $YELLOW" The cluster hostname/ip is: $CLUSTER_IP"$EYELLOW
1515 echo "================================================================================="
1516 echo "================================================================================="
1520 echo -e $BOLD"======================================================="$EBOLD
1521 echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
1522 echo -e $BOLD"======================================================="$EBOLD
1527 for imagename in $APP_SHORT_NAMES; do
1528 __check_included_image $imagename
1530 __check_prestarted_image $imagename
1532 if [ $retcode_i -eq 0 ] || [ $retcode_p -eq 0 ]; then
1533 # A function name is created from the app short name
1534 # for example app short name 'RICMSIM' -> produce the function
1535 # name __RICSIM__initial_setup
1536 # This function is called and is expected to exist in the imported
1537 # file for the ricsim test functions
1538 # The resulting function impl shall perform initial setup of port, host etc
1540 function_pointer="__"$imagename"_initial_setup"
1543 function_pointer="__"$imagename"_statisics_setup"
1544 LOG_STAT_ARGS=$LOG_STAT_ARGS" "$($function_pointer)
1548 if [ $COLLECT_RUNTIME_STATS -eq 1 ]; then
1549 ../common/genstat.sh $RUNMODE $SECONDS $TESTLOGS/$ATC/stat_data.csv $LOG_STAT_ARGS &
1554 # Function to print the test result, shall be the last cmd in a test script
1556 # (Function for test scripts)
1560 duration=$((TCTEST_END-TCTEST_START))
1562 echo "-------------------------------------------------------------------------------------------------"
1563 echo "------------------------------------- Test case: "$ATC
1564 echo "------------------------------------- Ended: "$(date)
1565 echo "-------------------------------------------------------------------------------------------------"
1566 echo "-- Description: "$TC_ONELINE_DESCR
1567 echo "-- Execution time: " $duration " seconds"
1568 echo "-- Used env file: "$TEST_ENV_VAR_FILE
1569 echo "-------------------------------------------------------------------------------------------------"
1570 echo "------------------------------------- RESULTS"
1574 if [ $RES_DEVIATION -gt 0 ]; then
1575 echo "Test case deviations"
1576 echo "===================================="
1580 echo "Timer measurement in the test script"
1581 echo "===================================="
1582 column -t -s $'\t' $TIMER_MEASUREMENTS
1583 if [ $RES_PASS != $RES_TEST ]; then
1584 echo -e $RED"Measurement may not be reliable when there are failed test - failures may cause long measurement values due to timeouts etc."$ERED
1588 if [ $COLLECT_RUNTIME_STATS -eq 1 ]; then
1589 echo "Runtime statistics collected in file: "$TESTLOGS/$ATC/stat_data.csv
1593 total=$((RES_PASS+RES_FAIL))
1594 if [ $RES_TEST -eq 0 ]; then
1595 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
1596 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
1597 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
1598 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
1599 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
1600 elif [ $total != $RES_TEST ]; then
1601 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
1602 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
1603 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
1604 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
1605 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
1606 elif [ $RES_CONF_FAIL -ne 0 ]; then
1607 echo -e "\033[1mOne or more configurations has failed. Check the script log....\033[0m"
1608 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
1609 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
1610 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
1611 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
1612 elif [ $RES_PASS = $RES_TEST ]; then
1613 echo -e "All tests \033[32m\033[1mPASS\033[0m"
1614 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
1615 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
1616 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
1617 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
1620 # Update test suite counter
1621 if [ -f .tmp_tcsuite_pass_ctr ]; then
1622 tmpval=$(< .tmp_tcsuite_pass_ctr)
1624 echo $tmpval > .tmp_tcsuite_pass_ctr
1626 if [ -f .tmp_tcsuite_pass ]; then
1627 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
1629 #Create file with OK exit code
1630 echo "0" > "$AUTOTEST_HOME/.result$ATC.txt"
1632 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
1633 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
1634 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
1635 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
1636 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
1638 # Update test suite counter
1639 if [ -f .tmp_tcsuite_fail_ctr ]; then
1640 tmpval=$(< .tmp_tcsuite_fail_ctr)
1642 echo $tmpval > .tmp_tcsuite_fail_ctr
1644 if [ -f .tmp_tcsuite_fail ]; then
1645 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
1649 echo "++++ Number of tests: "$RES_TEST
1650 echo "++++ Number of passed tests: "$RES_PASS
1651 echo "++++ Number of failed tests: "$RES_FAIL
1653 echo "++++ Number of failed configs: "$RES_CONF_FAIL
1655 echo "++++ Number of test case deviations: "$RES_DEVIATION
1657 echo "------------------------------------- Test case complete ---------------------------------"
1658 echo "-------------------------------------------------------------------------------------------------"
1662 #####################################################################
1663 ###### Functions for start, configuring, stoping, cleaning etc ######
1664 #####################################################################
1666 # Start timer for time measurement
1667 # args: <timer message to print> - timer value and message will be printed both on screen
1668 # and in the timer measurement report - if at least one "print_timer is called"
1670 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1671 TC_TIMER_STARTTIME=$SECONDS
1672 TC_TIMER_TIMER_TEXT="${@:1}"
1673 if [ $# -ne 1 ]; then
1674 __print_err "need 1 arg, <timer message to print>" $@
1675 TC_TIMER_TIMER_TEXT=${FUNCNAME[0]}":"${BASH_LINENO[0]}
1676 echo " Assigning timer name: "$TC_TIMER_TIMER_TEXT
1678 TC_TIMER_CURRENT_FAILS=$(($RES_FAIL+$RES_CONF_FAIL))
1679 echo " Timer started: $(date)"
1682 # Print the running timer the value of the time (in seconds)
1683 # Timer value and message will be printed both on screen and in the timer measurement report
1685 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $TC_TIMER_TIMER_TEXT $EBOLD
1686 if [ -z "$TC_TIMER_STARTTIME" ]; then
1687 __print_err "timer not started" $@
1690 duration=$(($SECONDS-$TC_TIMER_STARTTIME))
1691 if [ $duration -eq 0 ]; then
1692 duration="<1 second"
1694 duration=$duration" seconds"
1696 echo " Timer duration :" $duration
1698 if [ $(($RES_FAIL+$RES_CONF_FAIL)) -ne $TC_TIMER_CURRENT_FAILS ]; then
1699 res="Failures occured during test - timer not reliabled"
1702 echo -e "$TC_TIMER_TIMER_TEXT \t $duration \t $res" >> $TIMER_MEASUREMENTS
1705 # Print info about a deviations from intended tests
1706 # Each deviation counted is also printed in the testreport
1707 # args <deviation message to print>
1709 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
1710 if [ $# -lt 1 ]; then
1712 __print_err "need 1 or more args, <deviation message to print>" $@
1716 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
1717 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
1718 __print_current_stats
1722 # Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
1723 __check_stop_at_error() {
1724 if [ $STOP_AT_ERROR -eq 1 ]; then
1725 echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
1726 store_logs "STOP_AT_ERROR"
1732 # Stop and remove all containers
1734 # (Not for test scripts)
1735 __clean_containers() {
1737 echo -e $BOLD"Docker clean and stopping and removing all running containers, by container name"$EBOLD
1740 running_contr_file="./tmp/running_contr.txt"
1741 > $running_contr_file
1743 # Get list of all containers started by the test script
1744 for imagename in $APP_SHORT_NAMES; do
1745 docker ps -a --filter "label=nrttest_app=$imagename" --filter "network=$DOCKER_SIM_NWNAME" --format ' {{.Label "nrttest_dp"}}\n{{.Label "nrttest_app"}}\n{{.Names}}' >> $running_contr_file
1747 running_contr_file_empty="No docker containers running, started by previous test execution"
1748 if [ -s $running_contr_file ]; then
1749 running_contr_file_empty=""
1752 # Kill all containers started by the test env - to speed up shut down
1753 docker kill $(docker ps -a --filter "label=nrttest_app" --format '{{.Names}}') &> /dev/null
1755 tab_heading1="App display name"
1756 tab_heading2="App short name"
1757 tab_heading3="Container name"
1759 tab_heading1_len=${#tab_heading1}
1760 tab_heading2_len=${#tab_heading2}
1761 tab_heading3_len=${#tab_heading3}
1763 #Calc field lengths of each item in the list of containers
1765 if (( $cntr % 3 == 0 ));then
1766 if [ ${#p} -gt $tab_heading1_len ]; then
1767 tab_heading1_len=${#p}
1770 if (( $cntr % 3 == 1));then
1771 if [ ${#p} -gt $tab_heading2_len ]; then
1772 tab_heading2_len=${#p}
1775 if (( $cntr % 3 == 2));then
1776 if [ ${#p} -gt $tab_heading3_len ]; then
1777 tab_heading3_len=${#p}
1781 done <$running_contr_file
1783 let tab_heading1_len=tab_heading1_len+2
1784 while (( ${#tab_heading1} < $tab_heading1_len)); do
1785 tab_heading1="$tab_heading1"" "
1788 let tab_heading2_len=tab_heading2_len+2
1789 while (( ${#tab_heading2} < $tab_heading2_len)); do
1790 tab_heading2="$tab_heading2"" "
1793 let tab_heading3_len=tab_heading3_len+2
1794 while (( ${#tab_heading3} < $tab_heading3_len)); do
1795 tab_heading3="$tab_heading3"" "
1798 if [ ! -z "$running_contr_file_empty" ]; then
1799 echo $running_contr_file_empty | indent1
1801 echo " $tab_heading1$tab_heading2$tab_heading3"" Actions"
1804 if (( $cntr % 3 == 0 ));then
1807 heading_len=$tab_heading1_len
1809 if (( $cntr % 3 == 1));then
1811 heading_len=$tab_heading2_len
1813 if (( $cntr % 3 == 2));then
1816 heading_len=$tab_heading3_len
1818 while (( ${#heading} < $heading_len)); do
1819 heading="$heading"" "
1822 if (( $cntr % 3 == 2));then
1823 echo -ne $row$SAMELINE
1824 echo -ne " $row ${GREEN}stopping...${EGREEN}${SAMELINE}"
1825 docker stop $(docker ps -qa --filter name=${contr} --filter network=$DOCKER_SIM_NWNAME) &> /dev/null
1826 echo -ne " $row ${GREEN}stopped removing...${EGREEN}${SAMELINE}"
1827 docker rm --force $(docker ps -qa --filter name=${contr} --filter network=$DOCKER_SIM_NWNAME) &> /dev/null
1828 echo -e " $row ${GREEN}stopped removed ${EGREEN}"
1831 done <$running_contr_file
1836 echo -e $BOLD" Removing docker network"$EBOLD
1837 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
1838 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
1839 docker network rm $DOCKER_SIM_NWNAME | indent2
1840 if [ $? -ne 0 ]; then
1841 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
1845 echo -e "$GREEN Done$EGREEN"
1847 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
1848 docker network prune --force | indent2
1849 echo -e "$GREEN Done$EGREEN"
1851 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
1852 docker volume prune --force | indent2
1853 echo -e "$GREEN Done$EGREEN"
1855 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
1856 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
1857 echo -e "$GREEN Done$EGREEN"
1860 CONTRS=$(docker ps | awk '$1 != "CONTAINER" { n++ }; END { print n+0 }')
1861 if [ $? -eq 0 ]; then
1862 if [ $CONTRS -ne 0 ]; then
1863 echo -e $RED"Containers running, may cause distubance to the test case"$ERED
1864 docker ps -a | indent1
1870 ###################################
1871 ### Functions for kube management
1872 ###################################
1874 # Get resource type for scaling
1875 # args: <resource-name> <namespace>
1876 __kube_get_resource_type() {
1877 kubectl get deployment $1 -n $2 1> /dev/null 2> ./tmp/kubeerr
1878 if [ $? -eq 0 ]; then
1882 kubectl get sts $1 -n $2 1> /dev/null 2> ./tmp/kubeerr
1883 if [ $? -eq 0 ]; then
1887 echo "unknown-resource-type"
1891 # Scale a kube resource to a specific count
1892 # args: <resource-type> <resource-name> <namespace> <target-count>
1893 # (Not for test scripts)
1895 echo -ne " Setting $1 $2 replicas=$4 in namespace $3"$SAMELINE
1896 kubectl scale $1 $2 -n $3 --replicas=$4 1> /dev/null 2> ./tmp/kubeerr
1897 if [ $? -ne 0 ]; then
1898 echo -e " Setting $1 $2 replicas=$4 in namespace $3 $RED Failed $ERED"
1900 echo " Message: $(<./tmp/kubeerr)"
1903 echo -e " Setting $1 $2 replicas=$4 in namespace $3 $GREEN OK $EGREEN"
1908 for i in {1..500}; do
1909 count=$(kubectl get $1/$2 -n $3 -o jsonpath='{.status.replicas}' 2> /dev/null)
1911 if [ -z "$count" ]; then
1912 #No value is sometimes returned for some reason, in case the resource has replica 0
1915 if [ $retcode -ne 0 ]; then
1916 echo -e "$RED Cannot fetch current replica count for $1 $2 in namespace $3 $ERED"
1921 if [ $count -ne $4 ]; then
1922 echo -ne " Waiting for $1 $2 replicas=$4 in namespace $3. Replicas=$count after $(($SECONDS-$TSTART)) seconds $SAMELINE"
1925 echo -e " Waiting for $1 $2 replicas=$4 in namespace $3. Replicas=$count after $(($SECONDS-$TSTART)) seconds"
1926 echo -e " Replicas=$4 after $(($SECONDS-$TSTART)) seconds $GREEN OK $EGREEN"
1932 echo -e "$RED Replica count did not reach target replicas=$4. Failed with replicas=$count $ERED"
1937 # Scale all kube resource sets to 0 in a namespace for resources having a certain lable and label-id
1938 # This function does not wait for the resource to reach 0
1939 # args: <namespace> <label-name> <label-id>
1940 # (Not for test scripts)
1941 __kube_scale_all_resources() {
1945 resources="deployment replicaset statefulset"
1946 for restype in $resources; do
1947 result=$(kubectl get $restype -n $namespace -o jsonpath='{.items[?(@.metadata.labels.'$labelname'=="'$labelid'")].metadata.name}')
1948 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
1949 for resid in $result; do
1950 echo -ne " Ordered caling $restype $resid in namespace $namespace with label $labelname=$labelid to 0"$SAMELINE
1951 kubectl scale $restype $resid -n $namespace --replicas=0 1> /dev/null 2> ./tmp/kubeerr
1952 echo -e " Ordered scaling $restype $resid in namespace $namespace with label $labelname=$labelid to 0 $GREEN OK $EGREEN"
1958 # Scale all kube resource sets to 0 in a namespace for resources having a certain lable and an optional label-id
1959 # This function do wait for the resource to reach 0
1960 # args: <namespace> <label-name> [ <label-id> ]
1961 # (Not for test scripts)
1962 __kube_scale_and_wait_all_resources() {
1966 if [ -z "$3" ]; then
1967 echo " Attempt to scale - deployment replicaset statefulset - in namespace $namespace with label $labelname"
1969 echo " Attempt to scale - deployment replicaset statefulset - in namespace $namespace with label $labelname=$labelid"
1971 resources="deployment replicaset statefulset"
1973 while [ $scaled_all -ne 0 ]; do
1975 for restype in $resources; do
1976 if [ -z "$3" ]; then
1977 result=$(kubectl get $restype -n $namespace -o jsonpath='{.items[?(@.metadata.labels.'$labelname')].metadata.name}')
1979 result=$(kubectl get $restype -n $namespace -o jsonpath='{.items[?(@.metadata.labels.'$labelname'=="'$labelid'")].metadata.name}')
1981 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
1982 for resid in $result; do
1983 echo -e " Ordered scaling $restype $resid in namespace $namespace with label $labelname=$labelid to 0"
1984 kubectl scale $restype $resid -n $namespace --replicas=0 1> /dev/null 2> ./tmp/kubeerr
1987 while [ $count -ne 0 ]; do
1988 count=$(kubectl get $restype $resid -n $namespace -o jsonpath='{.status.replicas}' 2> /dev/null)
1989 echo -ne " Scaling $restype $resid in namespace $namespace with label $labelname=$labelid to 0, current count=$count"$SAMELINE
1990 if [ $? -eq 0 ] && [ ! -z "$count" ]; then
1995 duration=$(($SECONDS-$T_START))
1996 if [ $duration -gt 100 ]; then
1997 #Forcring count 0, to avoid hanging for failed scaling
2002 echo -e " Scaled $restype $resid in namespace $namespace with label $labelname=$labelid to 0, current count=$count $GREEN OK $EGREEN"
2009 # Remove all kube resources in a namespace for resources having a certain label and label-id
2010 # This function wait until the resources are gone. Scaling to 0 must have been ordered previously
2011 # args: <namespace> <label-name> <label-id>
2012 # (Not for test scripts)
2013 __kube_delete_all_resources() {
2017 resources="deployments replicaset statefulset services pods configmaps persistentvolumeclaims persistentvolumes"
2018 deleted_resourcetypes=""
2019 for restype in $resources; do
2020 ns_flag="-n $namespace"
2021 ns_text="in namespace $namespace"
2022 if [ $restype == "persistentvolumes" ]; then
2026 result=$(kubectl get $restype $ns_flag -o jsonpath='{.items[?(@.metadata.labels.'$labelname'=="'$labelid'")].metadata.name}')
2027 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
2028 deleted_resourcetypes=$deleted_resourcetypes" "$restype
2029 for resid in $result; do
2030 if [ $restype == "replicaset" ] || [ $restype == "statefulset" ]; then
2032 while [ $count -ne 0 ]; do
2033 count=$(kubectl get $restype $resid $ns_flag -o jsonpath='{.status.replicas}' 2> /dev/null)
2034 echo -ne " Scaling $restype $resid $ns_text with label $labelname=$labelid to 0, current count=$count"$SAMELINE
2035 if [ $? -eq 0 ] && [ ! -z "$count" ]; then
2041 echo -e " Scaled $restype $resid $ns_text with label $labelname=$labelid to 0, current count=$count $GREEN OK $EGREEN"
2043 echo -ne " Deleting $restype $resid $ns_text with label $labelname=$labelid "$SAMELINE
2044 kubectl delete --grace-period=1 $restype $resid $ns_flag 1> /dev/null 2> ./tmp/kubeerr
2045 if [ $? -eq 0 ]; then
2046 echo -e " Deleted $restype $resid $ns_text with label $labelname=$labelid $GREEN OK $EGREEN"
2048 echo -e " Deleted $restype $resid $ns_text with label $labelname=$labelid $GREEN Does not exist - OK $EGREEN"
2054 if [ ! -z "$deleted_resourcetypes" ]; then
2055 for restype in $deleted_resources; do
2056 ns_flag="-n $namespace"
2057 ns_text="in namespace $namespace"
2058 if [ $restype == "persistentvolumes" ]; then
2062 echo -ne " Waiting for $restype $ns_text with label $labelname=$labelid to be deleted..."$SAMELINE
2065 while [ ! -z "$result" ]; do
2067 result=$(kubectl get $restype $ns_flag -o jsonpath='{.items[?(@.metadata.labels.'$labelname'=="'$labelid'")].metadata.name}')
2068 echo -ne " Waiting for $restype $ns_text with label $labelname=$labelid to be deleted...$(($SECONDS-$T_START)) seconds "$SAMELINE
2069 if [ -z "$result" ]; then
2070 echo -e " Waiting for $restype $ns_text with label $labelname=$labelid to be deleted...$(($SECONDS-$T_START)) seconds $GREEN OK $EGREEN"
2071 elif [ $(($SECONDS-$T_START)) -gt 300 ]; then
2072 echo -e " Waiting for $restype $ns_text with label $labelname=$labelid to be deleted...$(($SECONDS-$T_START)) seconds $RED Failed $ERED"
2080 # Creates a namespace if it does not exists
2082 # (Not for test scripts)
2083 __kube_create_namespace() {
2085 #Check if test namespace exists, if not create it
2086 kubectl get namespace $1 1> /dev/null 2> ./tmp/kubeerr
2087 if [ $? -ne 0 ]; then
2088 echo -ne " Creating namespace "$1 $SAMELINE
2089 kubectl create namespace $1 1> /dev/null 2> ./tmp/kubeerr
2090 if [ $? -ne 0 ]; then
2091 echo -e " Creating namespace $1 $RED$BOLD FAILED $EBOLD$ERED"
2093 echo " Message: $(<./tmp/kubeerr)"
2096 echo -e " Creating namespace $1 $GREEN$BOLD OK $EBOLD$EGREEN"
2099 echo -e " Creating namespace $1 $GREEN$BOLD Already exists, OK $EBOLD$EGREEN"
2104 # Find the host ip of an app (using the service resource)
2105 # args: <app-name> <namespace>
2106 # (Not for test scripts)
2107 __kube_get_service_host() {
2108 if [ $# -ne 2 ]; then
2110 __print_err "need 2 args, <app-name> <namespace>" $@
2113 for timeout in {1..60}; do
2114 host=$(kubectl get svc $1 -n $2 -o jsonpath='{.spec.clusterIP}')
2115 if [ $? -eq 0 ]; then
2116 if [ ! -z "$host" ]; then
2124 echo "host-not-found-fatal-error"
2128 # Find the named port to an app (using the service resource)
2129 # args: <app-name> <namespace> <port-name>
2130 # (Not for test scripts)
2131 __kube_get_service_port() {
2132 if [ $# -ne 3 ]; then
2134 __print_err "need 3 args, <app-name> <namespace> <port-name>" $@
2138 for timeout in {1..60}; do
2139 port=$(kubectl get svc $1 -n $2 -o jsonpath='{...ports[?(@.name=="'$3'")].port}')
2140 if [ $? -eq 0 ]; then
2141 if [ ! -z "$port" ]; then
2153 # Find the named node port to an app (using the service resource)
2154 # args: <app-name> <namespace> <port-name>
2155 # (Not for test scripts)
2156 __kube_get_service_nodeport() {
2157 if [ $# -ne 3 ]; then
2159 __print_err "need 3 args, <app-name> <namespace> <port-name>" $@
2163 for timeout in {1..60}; do
2164 port=$(kubectl get svc $1 -n $2 -o jsonpath='{...ports[?(@.name=="'$3'")].nodePort}')
2165 if [ $? -eq 0 ]; then
2166 if [ ! -z "$port" ]; then
2178 # Create a kube resource from a yaml template
2179 # args: <resource-type> <resource-name> <template-yaml> <output-yaml>
2180 # (Not for test scripts)
2181 __kube_create_instance() {
2182 echo -ne " Creating $1 $2"$SAMELINE
2184 kubectl apply -f $4 1> /dev/null 2> ./tmp/kubeerr
2185 if [ $? -ne 0 ]; then
2187 echo -e " Creating $1 $2 $RED Failed $ERED"
2188 echo " Message: $(<./tmp/kubeerr)"
2191 echo -e " Creating $1 $2 $GREEN OK $EGREEN"
2195 # Function to create a configmap in kubernetes
2196 # args: <configmap-name> <namespace> <labelname> <labelid> <path-to-data-file> <path-to-output-yaml>
2197 # (Not for test scripts)
2198 __kube_create_configmap() {
2199 echo -ne " Creating configmap $1 "$SAMELINE
2200 envsubst < $5 > $5"_tmp"
2201 cp $5"_tmp" $5 #Need to copy back to orig file name since create configmap neeed the original file name
2202 kubectl create configmap $1 -n $2 --from-file=$5 --dry-run=client -o yaml > $6
2203 if [ $? -ne 0 ]; then
2204 echo -e " Creating configmap $1 $RED Failed $ERED"
2209 kubectl apply -f $6 1> /dev/null 2> ./tmp/kubeerr
2210 if [ $? -ne 0 ]; then
2211 echo -e " Creating configmap $1 $RED Apply failed $ERED"
2212 echo " Message: $(<./tmp/kubeerr)"
2216 kubectl label configmap $1 -n $2 $3"="$4 --overwrite 1> /dev/null 2> ./tmp/kubeerr
2217 if [ $? -ne 0 ]; then
2218 echo -e " Creating configmap $1 $RED Labeling failed $ERED"
2219 echo " Message: $(<./tmp/kubeerr)"
2223 # Log the resulting map
2224 kubectl get configmap $1 -n $2 -o yaml > $6
2226 echo -e " Creating configmap $1 $GREEN OK $EGREEN"
2230 # This function runs a kubectl cmd where a single output value is expected, for example get ip with jsonpath filter.
2231 # The function retries up to the timeout given in the cmd flag '--cluster-timeout'
2232 # args: <full kubectl cmd with parameters>
2233 # (Not for test scripts)
2234 __kube_cmd_with_timeout() {
2235 TS_TMP=$(($SECONDS+$CLUSTER_TIME_OUT))
2238 kube_cmd_result=$($@)
2239 if [ $? -ne 0 ]; then
2242 if [ $SECONDS -ge $TS_TMP ] || [ ! -z "$kube_cmd_result" ] ; then
2243 echo $kube_cmd_result
2250 # This function starts a pod that cleans a the contents of a path mounted as a pvc
2251 # After this action the pod should terminate
2252 # This should only be executed when the pod owning the pvc is not running
2253 # args: <appname> <namespace> <pvc-name> <path-to remove>
2254 # (Not for test scripts)
2255 __kube_clean_pvc() {
2257 #using env vars setup in pvccleaner_api_functions.sh
2259 export PVC_CLEANER_NAMESPACE=$2
2260 export PVC_CLEANER_CLAIMNAME=$3
2261 export PVC_CLEANER_RM_PATH=$4
2262 export PVC_CLEANER_APP_NAME
2263 input_yaml=$SIM_GROUP"/"$PVC_CLEANER_COMPOSE_DIR"/"pvc-cleaner.yaml
2264 output_yaml=$PWD/tmp/$2-pvc-cleaner.yaml
2266 envsubst < $input_yaml > $output_yaml
2268 kubectl delete -f $output_yaml 1> /dev/null 2> /dev/null # Delete the previous terminated pod - if existing
2270 __kube_create_instance pod $PVC_CLEANER_APP_NAME $input_yaml $output_yaml
2271 if [ $? -ne 0 ]; then
2272 echo $YELLOW" Could not clean pvc for app: $1 - persistent storage not clean - tests may not work"
2276 term_ts=$(($SECONDS+30))
2277 while [ $term_ts -gt $SECONDS ]; do
2278 pod_status=$(kubectl get pod pvc-cleaner -n $PVC_CLEANER_NAMESPACE --no-headers -o custom-columns=":status.phase")
2279 if [ "$pod_status" == "Succeeded" ]; then
2286 # This function scales or deletes all resources for app selected by the testcase.
2288 # (Not for test scripts)
2290 echo -e $BOLD"Initialize kube pods/statefulsets/replicaset to initial state"$EBOLD
2292 # Scale prestarted or managed apps
2293 for imagename in $APP_SHORT_NAMES; do
2294 # A function name is created from the app short name
2295 # for example app short name 'RICMSIM' -> produce the function
2296 # name __RICSIM_kube_scale_zero or __RICSIM_kube_scale_zero_and_wait
2297 # This function is called and is expected to exist in the imported
2298 # file for the ricsim test functions
2299 # The resulting function impl shall scale the resources to 0
2300 # For prestarted apps, the function waits until the resources are 0
2301 # For included (not prestated) apps, the scaling is just ordered
2302 __check_prestarted_image $imagename
2303 if [ $? -eq 0 ]; then
2304 function_pointer="__"$imagename"_kube_scale_zero_and_wait"
2305 echo -e " Scaling all kube resources for app $BOLD $imagename $EBOLD to 0"
2308 __check_included_image $imagename
2309 if [ $? -eq 0 ]; then
2310 function_pointer="__"$imagename"_kube_scale_zero"
2311 echo -e " Scaling all kube resources for app $BOLD $imagename $EBOLD to 0"
2317 # Delete managed apps
2318 for imagename in $APP_SHORT_NAMES; do
2319 __check_included_image $imagename
2320 if [ $? -eq 0 ]; then
2321 __check_prestarted_image $imagename
2322 if [ $? -ne 0 ]; then
2323 # A function name is created from the app short name
2324 # for example app short name 'RICMSIM' -> produce the function
2325 # name __RICSIM__kube_delete_all
2326 # This function is called and is expected to exist in the imported
2327 # file for the ricsim test functions
2328 # The resulting function impl shall delete all its resources
2329 function_pointer="__"$imagename"_kube_delete_all"
2330 echo -e " Deleting all kube resources for app $BOLD $imagename $EBOLD"
2339 # Function stop and remove all containers (docker) and services/deployments etc(kube)
2341 # Function for test script
2342 clean_environment() {
2343 if [ $RUNMODE == "KUBE" ]; then
2345 if [ $PRE_CLEAN -eq 1 ]; then
2346 echo " Cleaning docker resouces to free up resources, may take time..."
2347 ../common/clean_docker.sh 2&>1 /dev/null
2352 if [ $PRE_CLEAN -eq 1 ]; then
2353 echo " Cleaning kubernetes resouces to free up resources, may take time..."
2354 ../common/clean_kube.sh 2&>1 /dev/null
2360 # 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
2362 # (Function for test scripts)
2363 auto_clean_environment() {
2365 if [ "$AUTO_CLEAN" == "auto" ]; then
2366 echo -e $BOLD"Initiating automatic cleaning of environment"$EBOLD
2371 # Function to sleep a test case for a numner of seconds. Prints the optional text args as info
2372 # args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
2373 # (Function for test scripts)
2376 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
2377 if [ $# -lt 1 ]; then
2379 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
2382 #echo "---- Sleep for " $1 " seconds ---- "$2
2384 duration=$((SECONDS-start))
2385 while [ $duration -lt $1 ]; do
2386 echo -ne " Slept for ${duration} seconds${SAMELINE}"
2388 duration=$((SECONDS-start))
2390 echo -ne " Slept for ${duration} seconds${SAMELINE}"
2394 # Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
2395 # Not to be called from the test script itself.
2397 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
2398 if [ $# -gt 1 ]; then
2399 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
2404 # Function to create the docker network for the test
2405 # Not to be called from the test script itself.
2406 __create_docker_network() {
2407 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
2408 if [ $? -ne 0 ]; then
2409 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
2412 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
2413 echo -e " Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
2414 docker network create $DOCKER_SIM_NWNAME | indent2
2415 if [ $? -ne 0 ]; then
2416 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
2419 echo -e "$GREEN Done$EGREEN"
2422 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
2426 # Function to start container with docker-compose and wait until all are in state running.
2427 # If the <docker-compose-file> is empty, the default 'docker-compose.yml' is assumed.
2428 #args: <docker-compose-dir> <docker-compose-file> <docker-compose-arg>|NODOCKERARGS <count> <app-name>+
2429 # (Not for test scripts)
2430 __start_container() {
2432 if [ $# -lt 5 ]; then
2434 __print_err "need 5 or more args, <docker-compose-dir> <docker-compose-file> <docker-compose-arg>|NODOCKERARGS <count> <app-name>+" $@
2438 __create_docker_network
2446 if [ -z "$compose_file" ]; then
2447 compose_file="docker-compose.yml"
2455 envsubst < $compose_file > "gen_"$compose_file
2456 compose_file="gen_"$compose_file
2458 if [ "$compose_args" == "NODOCKERARGS" ]; then
2459 docker-compose -f $compose_file up -d &> .dockererr
2460 if [ $? -ne 0 ]; then
2461 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
2463 echo -e $RED"Stopping script...."$ERED
2467 docker-compose -f $compose_file up -d $compose_args &> .dockererr
2468 if [ $? -ne 0 ]; then
2469 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
2471 echo -e $RED"Stopping script...."$ERED
2479 while [ $appindex -lt $appcount ]; do
2483 for i in {1..10}; do
2484 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
2485 echo -e " Container $BOLD${appname}$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
2492 if [ $app_started -eq 0 ]; then
2495 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
2496 echo -e $RED" Stopping script..."$ERED
2499 let appindex=appindex+1
2504 # Function to check if container/service is responding to http/https
2505 # args: <container-name>|<service-name> url
2506 # (Not for test scripts)
2507 __check_service_start() {
2509 if [ $# -ne 2 ]; then
2511 __print_err "need 2 args, <container-name>|<service-name> url" $@
2515 if [ $RUNMODE == "KUBE" ]; then
2516 ENTITY="service/set/deployment"
2522 echo -ne " Container $BOLD${appname}$EBOLD starting${SAMELINE}"
2526 echo -ne " Waiting for ${ENTITY} ${appname} service status...${SAMELINE}"
2529 while (( $TSTART+600 > $SECONDS )); do
2530 result="$(__do_curl -m 10 $url)"
2531 if [ $? -eq 0 ]; then
2532 if [ ${#result} -gt 15 ]; then
2533 #If response is too long, truncate
2534 result="...response text too long, omitted"
2536 echo -ne " Waiting for {ENTITY} $BOLD${appname}$EBOLD service status on ${3}, result: $result${SAMELINE}"
2537 echo -ne " The ${ENTITY} $BOLD${appname}$EBOLD$GREEN is alive$EGREEN, responds to service status:$GREEN $result $EGREEN on ${url} after $(($SECONDS-$TSTART)) seconds"
2543 if (( $TS_OFFSET > 5 )); then
2546 while [ $(($TS_TMP+$TS_OFFSET)) -gt $SECONDS ]; do
2547 echo -ne " Waiting for ${ENTITY} ${appname} service status on ${url}...$(($SECONDS-$TSTART)) seconds, retrying in $(($TS_TMP+$TS_OFFSET-$SECONDS)) seconds ${SAMELINE}"
2551 let loop_ctr=loop_ctr+1
2554 if [ "$pa_st" = "false" ]; then
2556 echo -e $RED" The ${ENTITY} ${appname} did not respond to service status on ${url} in $(($SECONDS-$TSTART)) seconds"$ERED
2569 __check_container_logs() {
2577 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
2579 if [ $RUNMODE == "KUBE" ]; then
2580 echo -e $YELLOW" Internal log for $dispname not checked in kube"$EYELLOW
2584 #tmp=$(docker ps | grep $appname)
2585 tmp=$(docker ps -q --filter name=$appname) #get the container id
2586 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
2587 echo " "$dispname" is not running, no check made"
2590 foundentries="$(docker exec -t $tmp grep $warning $logpath | wc -l)"
2591 if [ $? -ne 0 ];then
2592 echo " Problem to search $appname log $logpath"
2594 if [ $foundentries -eq 0 ]; then
2595 echo " No WARN entries found in $appname log $logpath"
2597 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
2600 foundentries="$(docker exec -t $tmp grep $error $logpath | wc -l)"
2601 if [ $? -ne 0 ];then
2602 echo " Problem to search $appname log $logpath"
2604 if [ $foundentries -eq 0 ]; then
2605 echo " No ERR entries found in $appname log $logpath"
2607 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
2613 # Store all container logs and other logs in the log dir for the script
2614 # Logs are stored with a prefix in case logs should be stored several times during a test
2615 # args: <logfile-prefix>
2616 # (Function for test scripts)
2618 if [ $# != 1 ]; then
2620 __print_err "need one arg, <file-prefix>" $@
2623 echo -e $BOLD"Storing all docker/kube container logs and other test logs in $TESTLOGS/$ATC using prefix: "$1$EBOLD
2625 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
2627 docker ps -a > $TESTLOGS/$ATC/$1_docker_ps.log 2>&1
2629 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
2631 if [ $RUNMODE == "DOCKER" ]; then
2633 # Store docker logs for all container
2634 for imagename in $APP_SHORT_NAMES; do
2635 __check_included_image $imagename
2636 if [ $? -eq 0 ]; then
2637 # A function name is created from the app short name
2638 # for example app short name 'RICMSIM' -> produce the function
2639 # name __RICSIM__store_docker_logs
2640 # This function is called and is expected to exist in the imported
2641 # file for the ricsim test functions
2642 # The resulting function impl shall store the docker logs for each container
2643 function_pointer="__"$imagename"_store_docker_logs"
2644 $function_pointer "$TESTLOGS/$ATC/" $1
2648 if [ $RUNMODE == "KUBE" ]; then
2649 namespaces=$(kubectl get namespaces -o jsonpath='{.items[?(@.metadata.name)].metadata.name}')
2650 for nsid in $namespaces; do
2651 pods=$(kubectl get pods -n $nsid -o jsonpath='{.items[?(@.metadata.labels.autotest)].metadata.name}')
2652 for podid in $pods; do
2653 kubectl logs -n $nsid $podid > $TESTLOGS/$ATC/$1_${podid}.log
2663 # Generic curl function, assumes all 200-codes are ok
2664 # args: <valid-curl-args-including full url>
2665 # returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
2666 # returns: The return code is 0 for ok and 1 for not ok
2668 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
2670 if [ ! -z "$KUBE_PROXY_PATH" ]; then
2671 if [ $KUBE_PROXY_HTTPX == "http" ]; then
2672 proxyflag=" --proxy $KUBE_PROXY_PATH"
2674 proxyflag=" --proxy-insecure --proxy $KUBE_PROXY_PATH"
2677 curlString="curl -skw %{http_code} $proxyflag $@"
2678 echo " CMD: $curlString" >> $HTTPLOG
2681 echo " RESP: $res" >> $HTTPLOG
2682 echo " RETCODE: $retcode" >> $HTTPLOG
2683 if [ $retcode -ne 0 ]; then
2684 echo "<no-response-from-server>"
2687 http_code="${res:${#res}-3}"
2688 if [ ${#res} -eq 3 ]; then
2689 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2690 echo "<no-response-from-server>"
2696 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2697 echo "<not found, resp:${http_code}>"
2700 if [ $# -eq 2 ]; then
2701 echo "${res:0:${#res}-3}" | xargs
2703 echo "${res:0:${#res}-3}"
2710 #######################################
2711 ### Basic helper function for test cases
2712 #######################################
2714 # Test a simulator container variable value towards target value using an condition operator with an optional timeout.
2715 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
2716 # immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
2717 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
2718 # before setting pass or fail depending on the result of comparing variable and target using the operator.
2719 # 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.
2720 # Not to be called from test script.
2723 checkjsonarraycount=0
2724 TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
2725 if [ $# -eq 6 ]; then
2726 if [[ $3 == "json:"* ]]; then
2727 checkjsonarraycount=1
2730 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
2731 echo "TEST $TEST_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds" >> $HTTPLOG
2734 ((TEST_SEQUENCE_NR++))
2738 if [ $checkjsonarraycount -eq 0 ]; then
2739 result="$(__do_curl $2$3)"
2741 result=${result//[[:blank:]]/} #Strip blanks
2744 result="$(__do_curl $2$path)"
2746 echo "$result" > ./tmp/.tmp.curl.json
2747 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
2749 duration=$((SECONDS-start))
2750 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
2752 if [ $retcode -ne 0 ]; then
2753 if [ $duration -gt $6 ]; then
2755 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
2756 __print_current_stats
2757 __check_stop_at_error
2760 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2762 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2763 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2764 __print_current_stats
2766 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2768 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2769 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2770 __print_current_stats
2772 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2774 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2775 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2776 __print_current_stats
2778 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2780 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2781 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2782 __print_current_stats
2785 if [ $duration -gt $6 ]; then
2787 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
2788 __print_current_stats
2789 __check_stop_at_error
2795 elif [ $# -eq 5 ]; then
2796 if [[ $3 == "json:"* ]]; then
2797 checkjsonarraycount=1
2800 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
2801 echo "TEST $TEST_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}" >> $HTTPLOG
2803 ((TEST_SEQUENCE_NR++))
2804 if [ $checkjsonarraycount -eq 0 ]; then
2805 result="$(__do_curl $2$3)"
2807 result=${result//[[:blank:]]/} #Strip blanks
2810 result="$(__do_curl $2$path)"
2812 echo "$result" > ./tmp/.tmp.curl.json
2813 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
2815 if [ $retcode -ne 0 ]; then
2817 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
2818 __print_current_stats
2819 __check_stop_at_error
2820 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2822 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2823 __print_current_stats
2824 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2826 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2827 __print_current_stats
2828 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2830 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2831 __print_current_stats
2832 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2834 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2835 __print_current_stats
2838 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
2839 __print_current_stats
2840 __check_stop_at_error
2843 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"