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 functions needed for auto test
21 # Arg: local|remote|remote-remove [auto-clean]
24 #Formatting for 'echo' cmd
29 GREEN="\033[32m\033[1m"
31 YELLOW="\033[33m\033[1m"
36 if [ $? -ne 0 ] || [ -z tmp ]; then
37 echo -e $RED"python3 is required to run the test environment, pls install"$ERED
41 if [ $? -ne 0 ] || [ -z tmp ]; then
42 echo -e $RED"docker is required to run the test environment, pls install"$ERED
46 tmp=$(which docker-compose)
47 if [ $? -ne 0 ] || [ -z tmp ]; then
48 echo -e $RED"docker-compose is required to run the test environment, pls install"$ERED
52 # Just resetting any previous echo formatting...
55 # source test environment variables
56 . ../common/test_env.sh
58 echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@
60 #Vars for A1 interface version and container count
68 # Vars to switch between http and https. Extra curl flag needed for https
69 export RIC_SIM_HTTPX="http"
70 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
71 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
72 export RIC_SIM_CERT_MOUNT_DIR="./cert"
74 export MR_HTTPX="http"
75 export MR_PORT=$MR_INTERNAL_PORT
76 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker net
78 export SDNC_HTTPX="http"
79 export SDNC_PORT=$SDNC_INTERNAL_PORT
80 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net
83 LOCALHOST="http://localhost:"
85 # Make curl retries for http response codes set in this env var, space separated list of codes
88 # Var to contol if the agent runs in a container (normal = 0) or as application on the local machine ( = 1)
91 # Var to hold 'auto' in case containers shall be stopped when test case ends
94 # Var to hold the app names to use local image for when running 'remote' or 'remote-remove'
97 # 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
100 # Set a description string for the test case
101 if [ -z "$TC_ONELINE_DESCR" ]; then
102 TC_ONELINE_DESCR="<no-description>"
103 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
106 # Counter for test suites
107 if [ -f .tmp_tcsuite_ctr ]; then
108 tmpval=$(< .tmp_tcsuite_ctr)
110 echo $tmpval > .tmp_tcsuite_ctr
113 # Create a test case id, ATC (Auto Test Case), from the name of the test case script.
114 # FTC1.sh -> ATC == FTC1
115 ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
117 # Create the logs dir if not already created in the current dir
118 if [ ! -d "logs" ]; then
123 # Create a http message log for this testcase
124 HTTPLOG=$PWD"/.httplog_"$ATC".txt"
127 #Create result file (containing '1' for error) for this test case
128 #Will be replaced with a file containing '0' if script is ok
130 echo "1" > "$PWD/.result$ATC.txt"
132 # Create a log dir for the test case
133 mkdir -p $TESTLOGS/$ATC
135 # Clear the log dir for the test case
136 rm $TESTLOGS/$ATC/*.log &> /dev/null
137 rm $TESTLOGS/$ATC/*.txt &> /dev/null
138 rm $TESTLOGS/$ATC/*.json &> /dev/null
140 # Log all output from the test case to a TC log
141 TCLOG=$TESTLOGS/$ATC/TC.log
142 exec &> >(tee ${TCLOG})
144 #Variables for counting tests as well as passed and failed tests
151 #File to keep deviation messages
152 DEVIATION_FILE=".tmp_deviations"
153 rm $DEVIATION_FILE &> /dev/null
155 #Var for measuring execution time
156 TCTEST_START=$SECONDS
158 #File to save timer measurement results
159 TIMER_MEASUREMENTS=".timer_measurement.txt"
160 echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS
163 echo "-------------------------------------------------------------------------------------------------"
164 echo "----------------------------------- Test case: "$ATC
165 echo "----------------------------------- Started: "$(date)
166 echo "-------------------------------------------------------------------------------------------------"
167 echo "-- Description: "$TC_ONELINE_DESCR
168 echo "-------------------------------------------------------------------------------------------------"
169 echo "----------------------------------- Test case setup -----------------------------------"
173 if [ $# -lt 1 ]; then
176 if [ $paramerror -eq 0 ]; then
177 if [ "$1" != "remote" ] && [ "$1" != "remote-remove" ] && [ "$1" != "local" ]; then
183 if [ $paramerror -eq 0 ]; then
184 if [ "$1" == "auto-clean" ]; then
189 if [ $paramerror -eq 0 ]; then
190 if [ "$1" == "--stop-at-error" ]; then
195 if [ $paramerror -eq 0 ]; then
196 if [ "$1" == "--use-local-image" ]; then
197 USE_LOCAL_IMAGES=${@:2}
198 while [ $# -gt 0 ]; do
204 if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
208 if [ $paramerror -eq 1 ]; then
209 echo -e $RED"Expected arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--use-local-image <app-nam> [<app-name>]*]"$ERED
213 echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
215 #Temp var to check for image variable name errors
217 #Create a file with image info for later printing as a table
218 image_list_file=".image-list"
219 echo -e " Container\tImage\ttag" > $image_list_file
221 # Check if image env var is set and if so export the env var with image to use (used by docker compose files)
222 # arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name>
223 __check_image_var() {
224 if [ $# -ne 5 ]; then
225 echo "Expected arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name>"
230 #Create var from the input var names
234 if [ -z $image ]; then
235 echo -e $RED"\$"$4" not set in test_env"$ERED
238 tmp=$tmp"<no-image>\t"
243 echo -e $RED"\$"$5" not set in test_env"$ERED
250 echo -e "$tmp" >> $image_list_file
252 export "${3}"=$image":"$tag
254 #echo " Configured image for ${1} (script start arg=${2}): "$image":"$tag
258 #Check if app local image shall override remote image
259 __check_image_local_override() {
260 for im in $USE_LOCAL_IMAGES; do
261 if [ "$1" == "$im" ]; then
268 #Check if app uses image excluded from this test run
269 __check_excluded_image() {
270 for im in $EXCLUDED_IMAGES; do
271 if [ "$1" == "$im" ]; then
278 # Check that image env setting are available
281 if [ $START_ARG == "local" ]; then
284 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG"
286 #Local Control Panel image
287 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG"
290 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG"
293 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG"
295 elif [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
297 __check_image_local_override 'PA'
298 if [ $? -eq 0 ]; then
300 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_REMOTE_IMAGE" "POLICY_AGENT_REMOTE_IMAGE_TAG"
303 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG"
306 __check_image_local_override 'CP'
307 if [ $? -eq 0 ]; then
308 #Remote Control Panel image
309 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE_TAG"
311 #Local Control Panel image
312 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG"
315 __check_image_local_override 'SDNC'
316 if [ $? -eq 0 ]; then
318 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE_TAG"
321 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG"
324 __check_image_local_override 'RICSIM'
325 if [ $? -eq 0 ]; then
326 #Remote ric sim image
327 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_REMOTE_IMAGE" "RIC_SIM_REMOTE_IMAGE_TAG"
330 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG"
334 #Should never get here....
335 echo "Unknow args: "$@
340 # These images are not built as part of this project official images, just check that env vars are set correctly
341 __check_image_var " Message Router" $START_ARG "MRSTUB_IMAGE" "MRSTUB_LOCAL_IMAGE" "MRSTUB_LOCAL_IMAGE_TAG"
342 __check_image_var " Callback Receiver" $START_ARG "CR_IMAGE" "CR_LOCAL_IMAGE" "CR_LOCAL_IMAGE_TAG"
343 __check_image_var " Consul" $START_ARG "CONSUL_IMAGE" "CONSUL_REMOTE_IMAGE" "CONSUL_REMOTE_IMAGE_TAG"
344 __check_image_var " CBS" $START_ARG "CBS_IMAGE" "CBS_REMOTE_IMAGE" "CBS_REMOTE_IMAGE_TAG"
345 __check_image_var " SDNC DB" $START_ARG "SDNC_DB_IMAGE" "SDNC_DB_REMOTE_IMAGE" "SDNC_DB_REMOTE_IMAGE_TAG"
346 __check_excluded_image 'SDNC_ONAP'
347 if [ $? -eq 0 ]; then
348 __check_image_var " SDNC ONAP A1 Adapter" $START_ARG "SDNC_ONAP_A1_ADAPTER_IMAGE" "SDNC_ONAP_A1_ADAPTER_REMOTE_IMAGE" "SDNC_ONAP_A1_ADAPTER_REMOTE_IMAGE_TAG"
349 __check_image_var " SDNC ONAP DB" $START_ARG "SDNC_ONAP_DB_IMAGE" "SDNC_ONAP_DB_REMOTE_IMAGE" "SDNC_ONAP_DB_REMOTE_IMAGE_TAG"
352 #Errors in image setting - exit
353 if [ $IMAGE_ERR -ne 0 ]; then
357 #Print a tables of the image settings
358 echo -e $BOLD"Images configured for start arg: "$START $EBOLD
359 column -t -s $'\t' $image_list_file
364 #Set the SIM_GROUP var
365 echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
366 if [ -z "$SIM_GROUP" ]; then
367 SIM_GROUP=$PWD/../simulator-group
368 if [ ! -d $SIM_GROUP ]; then
369 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
370 echo -e $RED"Please set the SIM_GROUP manually in the test_env.sh"$ERED
373 echo " SIM_GROUP auto set to: " $SIM_GROUP
375 elif [ $SIM_GROUP = *simulator_group ]; then
376 echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check common/test_env.sh"$ERED
379 echo " SIM_GROUP env var already set to: " $SIM_GROUP
384 #Temp var to check for image pull errors
387 #Function to check if image exist and stop+remove the container+pull new images as needed
388 #args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
389 __check_and_pull_image() {
391 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
392 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
393 tmp_im=$(docker images --format $format_string ${4})
395 if [ $1 == "local" ]; then
396 if [ -z "$tmp_im" ]; then
397 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
401 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
403 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
404 if [ $1 == "remote-remove" ]; then
405 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
406 tmp="$(docker ps -aq --filter name=${3})"
407 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
408 docker stop $tmp &> .dockererr
409 if [ $? -ne 0 ]; then
412 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
417 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
418 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
419 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
420 docker rm $tmp &> .dockererr
421 if [ $? -ne 0 ]; then
424 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
429 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
430 echo -ne " Removing image - ${SAMELINE}"
431 tmp="$(docker images -q ${4})" &> /dev/null
432 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
433 docker rmi $4 &> .dockererr
434 if [ $? -ne 0 ]; then
437 echo -e $RED" Image could not be removed - try manual removal of the image"$ERED
441 echo -e " Removing image - "$GREEN"removed"$EGREEN
443 echo -e " Removing image - "$GREEN"image not in repository"$EGREEN
447 if [ -z "$tmp_im" ]; then
448 echo -ne " Pulling image${SAMELINE}"
449 docker pull $4 &> .dockererr
450 tmp_im=$(docker images ${4} | grep -v REPOSITORY)
451 if [ -z "$tmp_im" ]; then
453 echo -e " Pulling image -$RED could not be pulled"$ERED
458 echo -e " Pulling image -$GREEN Pulled $EGREEN"
460 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
467 echo -e $BOLD"Pulling configured images, if needed"$EBOLD
469 START_ARG_MOD=$START_ARG
470 __check_image_local_override 'PA'
471 if [ $? -eq 1 ]; then
472 START_ARG_MOD="local"
474 app="Policy Agent"; __check_and_pull_image $START_ARG_MOD "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
476 START_ARG_MOD=$START_ARG
477 __check_image_local_override 'CP'
478 if [ $? -eq 1 ]; then
479 START_ARG_MOD="local"
481 app="Non-RT RIC Control Panel"; __check_and_pull_image $START_ARG_MOD "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
483 START_ARG_MOD=$START_ARG
484 __check_image_local_override 'RICSIM'
485 if [ $? -eq 1 ]; then
486 START_ARG_MOD="local"
488 app="Near-RT RIC Simulator"; __check_and_pull_image $START_ARG_MOD "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
490 app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
491 app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE
492 __check_excluded_image 'SDNC'
493 if [ $? -eq 0 ]; then
494 START_ARG_MOD=$START_ARG
495 __check_image_local_override 'SDNC'
496 if [ $? -eq 1 ]; then
497 START_ARG_MOD="local"
499 app="SDNC A1 Controller"; __check_and_pull_image $START_ARG_MOD "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
500 app="SDNC DB"; __check_and_pull_image $START_ARG "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
502 echo -e $YELLOW" Excluding SDNC image and related DB image from image check/pull"$EYELLOW
504 __check_excluded_image 'SDNC_ONAP'
505 if [ $? -eq 0 ]; then
506 app="SDNC ONAP A1 Adapter"; __check_and_pull_image $START_ARG "$app" $SDNC_ONAP_APP_NAME $SDNC_ONAP_A1_ADAPTER_IMAGE
507 app="SDNC ONAP DB"; __check_and_pull_image $START_ARG "$app" $SDNC_ONAP_APP_NAME $SDNC_ONAP_DB_IMAGE
509 echo -e $YELLOW" Excluding ONAP SDNC image and related DB image from image check/pull"$EYELLOW
511 # MR stub image not checked, will be built by this script - only local image
512 # CR stub image not checked, will be built by this script - only local image
515 #Errors in image setting - exit
516 if [ $IMAGE_ERR -ne 0 ]; then
518 echo "#################################################################################################"
519 echo -e $RED"One or more images could not be pulled or containers using the images could not be stopped/removed"$ERED
520 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
521 echo "#################################################################################################"
528 echo -e $BOLD"Building images needed for test"$EBOLD
533 echo " Building mrstub image: mrstub:latest"
534 docker build -t mrstub . &> .dockererr
535 if [ $? -eq 0 ]; then
536 echo -e $GREEN" Build Ok"$EGREEN
538 echo -e $RED" Build Failed"$ERED
545 echo " Building Callback Receiver image: callback-receiver:latest"
546 docker build -t callback-receiver . &> .dockererr
547 if [ $? -eq 0 ]; then
548 echo -e $GREEN" Build Ok"$EGREEN
550 echo -e $RED" Build Failed"$ERED
558 # Create a table of the images used in the script
559 echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
561 docker_tmp_file=.docker-images-table
562 format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}"
563 echo -e " Application\tRepository\tTag\tCreated Since\tSize" > $docker_tmp_file
564 echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
565 echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
566 echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
567 echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
568 echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
569 echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
570 echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
571 __check_excluded_image 'SDNC'
572 if [ $? -eq 0 ]; then
573 echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
574 echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
576 __check_excluded_image 'SDNC_ONAP'
577 if [ $? -eq 0 ]; then
578 echo -e " SDNC ONAP A1 Adapter\t$(docker images --format $format_string $SDNC_ONAP_A1_ADAPTER_IMAGE)" >> $docker_tmp_file
579 echo -e " SDNC ONAP DB\t$(docker images --format $format_string $SDNC_ONAP_DB_IMAGE)" >> $docker_tmp_file
582 column -t -s $'\t' $docker_tmp_file
586 echo -e $BOLD"======================================================="$EBOLD
587 echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
588 echo -e $BOLD"======================================================="$EBOLD
591 # Function to print the test result, shall be the last cmd in a test script
593 # (Function for test scripts)
597 duration=$((TCTEST_END-TCTEST_START))
599 echo "-------------------------------------------------------------------------------------------------"
600 echo "------------------------------------- Test case: "$ATC
601 echo "------------------------------------- Ended: "$(date)
602 echo "-------------------------------------------------------------------------------------------------"
603 echo "-- Description: "$TC_ONELINE_DESCR
604 echo "-- Execution time: " $duration " seconds"
605 echo "-------------------------------------------------------------------------------------------------"
606 echo "------------------------------------- RESULTS"
610 if [ $RES_DEVIATION -gt 0 ]; then
611 echo "Test case deviations"
612 echo "===================================="
616 echo "Timer measurement in the test script"
617 echo "===================================="
618 column -t -s $'\t' $TIMER_MEASUREMENTS
621 total=$((RES_PASS+RES_FAIL))
622 if [ $RES_TEST -eq 0 ]; then
623 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
624 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
625 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
626 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
627 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
628 elif [ $total != $RES_TEST ]; then
629 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
630 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
631 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
632 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
633 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
634 elif [ $RES_CONF_FAIL -ne 0 ]; then
635 echo -e "\033[1mOne or more configure regest has failed. Check the script log....\033[0m"
636 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
637 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
638 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
639 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
640 elif [ $RES_PASS = $RES_TEST ]; then
641 echo -e "All tests \033[32m\033[1mPASS\033[0m"
642 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
643 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
644 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
645 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
648 # Update test suite counter
649 if [ -f .tmp_tcsuite_pass_ctr ]; then
650 tmpval=$(< .tmp_tcsuite_pass_ctr)
652 echo $tmpval > .tmp_tcsuite_pass_ctr
654 if [ -f .tmp_tcsuite_pass ]; then
655 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
657 #Create file with OK exit code
658 echo "0" > "$PWD/.result$ATC.txt"
660 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
661 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
662 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
663 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
664 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
666 # Update test suite counter
667 if [ -f .tmp_tcsuite_fail_ctr ]; then
668 tmpval=$(< .tmp_tcsuite_fail_ctr)
670 echo $tmpval > .tmp_tcsuite_fail_ctr
672 if [ -f .tmp_tcsuite_fail ]; then
673 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
677 echo "++++ Number of tests: "$RES_TEST
678 echo "++++ Number of passed tests: "$RES_PASS
679 echo "++++ Number of failed tests: "$RES_FAIL
681 echo "++++ Number of failed configs: "$RES_CONF_FAIL
683 echo "++++ Number of test case deviations: "$RES_DEVIATION
685 echo "------------------------------------- Test case complete ---------------------------------"
686 echo "-------------------------------------------------------------------------------------------------"
690 #####################################################################
691 ###### Functions for start, configuring, stoping, cleaning etc ######
692 #####################################################################
694 # Start timer for time measurement
695 # args - (any args will be printed though)
697 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
699 echo " Timer started"
702 # Print the value of the time (in seconds)
703 # args - <timer message to print> - timer value and message will be printed both on screen
704 # and in the timer measurement report
706 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
707 if [ $# -lt 1 ]; then
709 __print_err "need 1 or more args, <timer message to print>" $@
712 duration=$(($SECONDS-$TC_TIMER))
713 if [ $duration -eq 0 ]; then
716 duration=$duration" seconds"
718 echo " Timer duration :" $duration
720 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
723 # Print the value of the time (in seconds) and reset the timer
724 # args - <timer message to print> - timer value and message will be printed both on screen
725 # and in the timer measurement report
726 print_and_reset_timer() {
727 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
728 if [ $# -lt 1 ]; then
730 __print_err "need 1 or more args, <timer message to print>" $@
733 duration=$(($SECONDS-$TC_TIMER))" seconds"
734 if [ $duration -eq 0 ]; then
737 duration=$duration" seconds"
739 echo " Timer duration :" $duration
743 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
746 # Print info about a deviations from intended tests
747 # Each deviation counted is also printed in the testreport
748 # args <deviation message to print>
750 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
751 if [ $# -lt 1 ]; then
753 __print_err "need 1 or more args, <deviation message to print>" $@
757 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
758 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
762 # Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
763 __check_stop_at_error() {
764 if [ $STOP_AT_ERROR -eq 1 ]; then
765 echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
766 store_logs "STOP_AT_ERROR"
772 # Stop and remove all containers
774 # (Function for test scripts)
777 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
779 CONTAINTER_NAMES=("Policy Agent " $POLICY_AGENT_APP_NAME\
780 "Non-RT RIC Simulator(s)" $RIC_SIM_PREFIX\
781 "Message Router " $MR_APP_NAME\
782 "Callback Receiver " $CR_APP_NAME\
783 "Control Panel " $CONTROL_PANEL_APP_NAME\
784 "SDNC A1 Controller " $SDNC_APP_NAME\
785 "SDNC DB " $SDNC_DB_APP_NAME\
786 "SDNC ONAP A1 Adapter " $SDNC_ONAP_APP_NAME\
787 "SDNC DB " $SDNC_ONAP_DB_APP_NAME\
788 "CBS " $CBS_APP_NAME\
789 "Consul " $CONSUL_APP_NAME)
791 nw=0 # Calc max width of container name, to make a nice table
792 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
793 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
794 nw=${#CONTAINTER_NAMES[i]}
798 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
799 APP="${CONTAINTER_NAMES[i]}"
800 CONTR="${CONTAINTER_NAMES[i+1]}"
801 for((w=${#CONTR}; w<$nw; w=w+1)); do
804 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
805 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
806 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
807 docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
808 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
813 echo -e $BOLD" Removing docker network"$EBOLD
814 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
815 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
816 docker network rm $DOCKER_SIM_NWNAME
817 if [ $? -ne 0 ]; then
818 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
823 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
824 docker network prune --force #&> /dev/null
826 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
827 docker volume prune --force #&> /dev/null
829 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
830 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
834 # Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
836 # (Function for test scripts)
837 auto_clean_containers() {
839 if [ "$AUTO_CLEAN" == "auto" ]; then
840 echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
845 # Function to sleep a test case for a numner of seconds. Prints the optional text args as info
846 # args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
847 # (Function for test scripts)
850 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
851 if [ $# -lt 1 ]; then
853 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
856 #echo "---- Sleep for " $1 " seconds ---- "$2
858 duration=$((SECONDS-start))
859 while [ $duration -lt $1 ]; do
860 echo -ne " Slept for ${duration} seconds${SAMELINE}"
862 duration=$((SECONDS-start))
864 echo -ne " Slept for ${duration} seconds${SAMELINE}"
868 # Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
869 # Not to be called from the test script itself.
871 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
872 if [ $# -gt 1 ]; then
873 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
878 # Helper function to get a the port of a specific ric simulatpor
880 # (Not for test scripts)
882 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
883 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
885 if [[ "$res" =~ ^[0-9]+$ ]]; then
892 # Function to create the docker network for the test
893 # Not to be called from the test script itself.
894 __create_docker_network() {
895 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
896 if [ $? -ne 0 ]; then
897 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
900 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
901 echo -e "Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
902 docker network create $DOCKER_SIM_NWNAME
903 if [ $? -ne 0 ]; then
904 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
908 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
912 # Check if container is started by calling url on localhost using a port, expects response code 2XX
913 # args: <container-name> <port> <url> https|https
914 # Not to be called from the test script itself.
915 __check_container_start() {
917 if [ $# -ne 4 ]; then
919 elif [ $4 != "http" ] && [ $4 != "https" ]; then
922 if [ $paramError -ne 0 ]; then
924 __print_err "need 3 args, <container-name> <port> <url> https|https" $@
927 echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
931 if [[ $appname != "STANDALONE_"* ]] ; then
934 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
935 echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
942 if [ $app_started -eq 0 ]; then
945 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
948 if [ $localport -eq 0 ]; then
949 while [ $localport -eq 0 ]; do
950 echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
951 localport=$(__find_sim_port $appname)
953 echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
955 echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
961 echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
964 if [ $4 == "https" ]; then
965 result="$(__do_curl "-k https://localhost:"${localport}${url})"
967 result="$(__do_curl $LOCALHOST${localport}${url})"
969 if [ $? -eq 0 ]; then
970 if [ ${#result} -gt 15 ]; then
971 #If response is too long, truncate
972 result="...response text too long, omitted"
974 echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
975 echo -ne " Container $BOLD${appname}$EBOLD$GREEN is alive$EGREEN, responds to service status:$GREEN $result $EGREEN after $(($SECONDS-$TSTART)) seconds"
980 while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
981 echo -ne " Waiting for container ${appname} service status...retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
987 if [ "$pa_st" = "false" ]; then
989 echo -e $RED" Container ${appname} did not respond to service status"$ERED
998 # Function to start a container and wait until it responds on the given port and url.
999 #args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
1000 __start_container() {
1002 variableArgCount=$(($#-2))
1003 if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
1005 __print_err "need 6 or more args, <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> http|https [<app-name> <port-number> <alive-url> http|https ]*" $@
1009 __create_docker_network
1015 if [ "$2" == "NODOCKERARGS" ]; then
1016 docker-compose up -d &> .dockererr
1017 if [ $? -ne 0 ]; then
1018 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1021 elif [ "$2" == "STANDALONE" ]; then
1022 echo "Skipping docker-compose"
1024 docker-compose up -d $2 &> .dockererr
1025 if [ $? -ne 0 ]; then
1026 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1031 if [ "$2" == "STANDALONE" ]; then
1032 app_prefix="STANDALONE_"
1036 while [ $cntr -lt $variableArgCount ]; do
1037 app=$app_prefix$1; shift;
1043 __check_container_start "$app" "$port" "$url" $httpx
1051 ####################
1052 ### Consul functions
1053 ####################
1055 # Function to load config from a file into consul for the Policy Agent
1056 # arg: <json-config-file>
1057 # (Function for test scripts)
1058 consul_config_app() {
1060 echo -e $BOLD"Configuring Consul"$EBOLD
1062 if [ $# -ne 1 ]; then
1064 __print_err "need one arg, <json-config-file>" $@
1068 echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1
1070 curl -s $LOCALHOST${CONSUL_EXTERNAL_PORT}/v1/kv/${POLICY_AGENT_APP_NAME}?dc=dc1 -X PUT -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'X-Requested-With: XMLHttpRequest' --data-binary "@"$1 >/dev/null
1071 if [ $? -ne 0 ]; then
1072 echo -e $RED" FAIL - json config could not be loaded to consul" $ERED
1076 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
1077 echo $body > ".output"$1
1079 if [ $? -ne 0 ]; then
1080 echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED
1085 targetJson="{\"config\":"$targetJson"}"
1086 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1087 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1088 if [ $res -ne 0 ]; then
1089 echo -e $RED" FAIL - policy json config read from consul/cbs is not equal to the intended json config...." $ERED
1093 echo -e $GREEN" Config loaded ok to consul"$EGREEN
1101 # Function to perpare the consul configuration according to the current simulator configuration
1102 # args: SDNC|SDNC_ONAP|NOSDNC <output-file>
1103 # (Function for test scripts)
1104 prepare_consul_config() {
1105 echo -e $BOLD"Prepare Consul config"$EBOLD
1107 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
1109 if [ $# != 2 ]; then
1111 __print_err "need two args, SDNC|SDNC_ONAP|NOSDNC <output-file>" $@
1115 if [ $1 == "SDNC" ]; then
1116 echo -e " Config$BOLD including SDNC$EBOLD configuration"
1117 elif [ $1 == "SDNC_ONAP" ]; then
1118 echo -e " Config$BOLD including SDNC ONAP$EBOLD configuration"
1119 elif [ $1 == "NOSDNC" ]; then
1120 echo -e " Config$BOLD excluding SDNC or SDNC ONAP$EBOLD configuration"
1123 __print_err "need two args, SDNC|SDNC_ONAP|NOSDNC <output-file>" $@
1128 if [ $1 == "SDNC" ]; then
1129 config_json=$config_json"\n \"controller\": ["
1130 config_json=$config_json"\n {"
1131 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
1132 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1133 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://$SDNC_APP_NAME:$SDNC_PORT\","
1135 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://localhost:$SDNC_LOCAL_PORT\","
1137 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
1138 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
1139 config_json=$config_json"\n }"
1140 config_json=$config_json"\n ],"
1142 if [ $1 == "SDNC_ONAP" ]; then
1143 config_json=$config_json"\n \"controller\": ["
1144 config_json=$config_json"\n {"
1145 config_json=$config_json"\n \"name\": \"$SDNC_ONAP_APP_NAME\","
1146 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1147 config_json=$config_json"\n \"baseUrl\": \"http://$SDNC_ONAP_APP_NAME:$SDNC_ONAP_INTERNAL_PORT\","
1149 config_json=$config_json"\n \"baseUrl\": \"http://localhost:$SDNC_ONAP_EXTERNAL_PORT\","
1151 config_json=$config_json"\n \"userName\": \"$SDNC_ONAP_USER\","
1152 config_json=$config_json"\n \"password\": \"$SDNC_ONAP_PWD\""
1153 config_json=$config_json"\n }"
1154 config_json=$config_json"\n ],"
1158 config_json=$config_json"\n \"streams_publishes\": {"
1159 config_json=$config_json"\n \"dmaap_publisher\": {"
1160 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1161 config_json=$config_json"\n \"dmaap_info\": {"
1162 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1163 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_WRITE_URL\""
1165 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_WRITE_URL\""
1167 config_json=$config_json"\n }"
1168 config_json=$config_json"\n }"
1169 config_json=$config_json"\n },"
1170 config_json=$config_json"\n \"streams_subscribes\": {"
1171 config_json=$config_json"\n \"dmaap_subscriber\": {"
1172 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1173 config_json=$config_json"\n \"dmaap_info\": {"
1174 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1175 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_READ_URL\""
1177 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_READ_URL\""
1179 config_json=$config_json"\n }"
1180 config_json=$config_json"\n }"
1181 config_json=$config_json"\n },"
1183 config_json=$config_json"\n \"ric\": ["
1185 rics=$(docker ps | grep ricsim | awk '{print $NF}')
1187 if [ $? -ne 0 ] || [ -z "$rics" ]; then
1188 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
1194 for ric in $rics; do
1195 if [ $cntr -gt 0 ]; then
1196 config_json=$config_json"\n ,"
1198 config_json=$config_json"\n {"
1199 config_json=$config_json"\n \"name\": \"$ric\","
1200 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1201 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
1203 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://localhost:$(__find_sim_port $ric)\","
1205 if [ $1 == "SDNC" ]; then
1206 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
1207 elif [ $1 == "SDNC_ONAP" ]; then
1208 config_json=$config_json"\n \"controller\": \"$SDNC_ONAP_APP_NAME\","
1210 config_json=$config_json"\n \"managedElementIds\": ["
1211 config_json=$config_json"\n \"me1_$ric\","
1212 config_json=$config_json"\n \"me2_$ric\""
1213 config_json=$config_json"\n ]"
1214 config_json=$config_json"\n }"
1218 config_json=$config_json"\n ]"
1219 config_json=$config_json"\n}"
1222 printf "$config_json">$2
1228 # Start Consul and CBS
1230 # (Function for test scripts)
1231 start_consul_cbs() {
1233 echo -e $BOLD"Starting Consul and CBS"$EBOLD
1235 __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" "http" \
1236 "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck" "http"
1239 ###########################
1240 ### RIC Simulator functions
1241 ###########################
1243 use_simulator_http() {
1244 echo -e "Using unsecure $BOLD http $EBOLD towards the simulators"
1245 export RIC_SIM_HTTPX="http"
1246 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1247 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
1251 use_simulator_https() {
1252 echo -e "Using secure $BOLD https $EBOLD towards the simulators"
1253 export RIC_SIM_HTTPX="https"
1254 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1255 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
1259 # Start one group (ricsim_g1, ricsim_g2 or ricsim_g3) with a number of RIC Simulators using a given A interface
1260 # args: ricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>
1261 # (Function for test scripts)
1262 start_ric_simulators() {
1264 echo -e $BOLD"Starting RIC Simulators"$EBOLD
1266 if [ $# != 3 ]; then
1268 __print_err "need three args, ricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>" $@
1271 echo " $2 simulators using basename: $1 on interface: $3"
1272 #Set env var for simulator count and A1 interface vesion for the given group
1273 if [ $1 == "ricsim_g1" ]; then
1276 elif [ $1 == "ricsim_g2" ]; then
1279 elif [ $1 == "ricsim_g3" ]; then
1284 __print_err "need three args, gricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>" $@
1288 # Create .env file to compose project, all ric container will get this prefix
1289 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
1291 export G1_A1_VERSION
1292 export G2_A1_VERSION
1293 export G3_A1_VERSION
1295 docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT"
1298 while [ $cntr -le $2 ]; do
1301 app_data="$app_data $app $port / "$RIC_SIM_HTTPX
1304 __start_container ric "$docker_args" $app_data
1308 ###########################
1309 ### Control Panel functions
1310 ###########################
1312 # Start the Control Panel container
1314 # (Function for test scripts)
1315 start_control_panel() {
1317 echo -e $BOLD"Starting Control Panel"$EBOLD
1319 __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/" "http"
1327 # Start the SDNC A1 Controller
1329 # (Function for test scripts)
1332 echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
1334 __check_excluded_image 'SDNC'
1335 if [ $? -eq 1 ]; then
1336 echo -e $RED"The image for SDNC and the related DB has not been checked for this test run due to arg to the test script"$ERED
1337 echo -e $RED"SDNC will not be started"$ERED
1341 __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT $SDNC_ALIVE_URL "http"
1346 echo -e $BOLD"Using http between agent and SDNC"$EBOLD
1347 export SDNC_HTTPX="http"
1348 export SDNC_PORT=$SDNC_INTERNAL_PORT
1349 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT
1354 echo -e $BOLD"Using https between agent and SDNC"$EBOLD
1355 export SDNC_HTTPX="https"
1356 export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT
1357 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT
1361 #######################
1362 ### SDNC ONAP functions
1363 #######################
1365 # Start the SDNC ONAP A1 Adapter
1367 # (Function for test scripts)
1370 echo -e $BOLD"Starting SDNC ONAP A1 Adapter"$EBOLD
1372 __check_excluded_image 'SDNC_ONAP'
1373 if [ $? -eq 1 ]; then
1374 echo -e $RED"The image for SDNC ONAP and the related DB has not been checked for this test run due to arg to the test script"$ERED
1375 echo -e $RED"SDNC ONAP will not be started"$ERED
1379 __start_container sdnc_onap NODOCKERARGS $SDNC_ONAP_APP_NAME $SDNC_ONAP_EXTERNAL_PORT $SDNC_ONAP_ALIVE_URL "http"
1383 # Configure the SDNC ONAP A1 Adapter
1385 # (Function for test scripts)
1386 config_sdnc_onap() {
1388 echo -e $BOLD"Configuring SDNC ONAP A1 Adapter"$EBOLD
1390 LOCALFILE=".sdnc_onap.prop"
1391 REMOTEFILE="/tmp/.sdnc_onap.prop"
1393 docker cp $SDNC_ONAP_APP_NAME:$SDNC_ONAP_PROPERTIES_FILE $LOCALFILE
1394 if [ $? -ne 0 ]; then
1395 echo -e $RED"Could not copy $SDNC_ONAP_PROPERTIES_FILE from $SDNC_ONAP_APP_NAME container"$ERED
1400 #Config of the prop file shall be inserted here
1402 #Copy file to /tmp and then to final destination, a trick to get correct permission of the file.
1404 docker cp $LOCALFILE $SDNC_ONAP_APP_NAME:$REMOTEFILE
1405 if [ $? -ne 0 ]; then
1406 echo -e $RED"Could not copy local $LOCALFILE to $REMOTEFILE in $SDNC_ONAP_APP_NAME container"$ERED
1410 docker exec -it $SDNC_ONAP_APP_NAME cp $REMOTEFILE $SDNC_ONAP_PROPERTIES_FILE
1411 if [ $? -ne 0 ]; then
1412 echo -e $RED"Could not copy $REMOTEFILE to $SDNC_ONAP_PROPERTIES_FILE in $SDNC_ONAP_APP_NAME container"$ERED
1417 #####################
1418 ### MR stub functions
1419 #####################
1421 # Start the Message Router stub interface in the simulator group
1423 # (Function for test scripts)
1426 echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
1427 export MR_CERT_MOUNT_DIR="./cert"
1428 __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/" "http"
1432 echo -e $BOLD"Using http between agent and MR"$EBOLD
1433 export MR_HTTPX="http"
1434 export MR_PORT=$MR_INTERNAL_PORT
1435 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT
1440 echo -e $BOLD"Using https between agent and MR"$EBOLD
1441 export MR_HTTPX="https"
1442 export MR_PORT=$MR_INTERNAL_SECURE_PORT
1443 export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT
1452 # Start the Callback reciver in the simulator group
1454 # (Function for test scripts)
1457 echo -e $BOLD"Starting Callback Receiver"$EBOLD
1459 __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/" "http"
1463 ###########################
1464 ### Policy Agents functions
1465 ###########################
1467 # Use an agent on the local machine instead of container
1468 use_agent_stand_alone() {
1472 # Start the policy agent
1474 # (Function for test scripts)
1475 start_policy_agent() {
1477 echo -e $BOLD"Starting Policy Agent"$EBOLD
1479 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1480 __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1482 echo -e $RED"The consul config produced by this test script (filename '<fullpath-to-autotest-dir>.output<file-name>"$ERED
1483 echo -e $RED"where the file name is the file in the consul_config_app command in this script) must be pointed out by the agent "$ERED
1484 echo -e $RED"application.yaml"$ERED
1485 echo -e $RED"The application jar may need to be built beforefor continuing"$ERED
1486 echo -e $RED"The agent shall now be running on port $POLICY_AGENT_EXTERNAL_PORT for http"$ERED
1488 read -p "<press any key to continue>"
1489 __start_container policy_agent "STANDALONE" $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1494 # All calls to the agent will be directed to the agent REST interface from now on
1496 # (Function for test scripts)
1497 use_agent_rest_http() {
1498 echo -e $BOLD"Using agent REST interface with http"$EBOLD
1499 export ADAPTER=$RESTBASE
1503 # All calls to the agent will be directed to the agent REST interface from now on
1505 # (Function for test scripts)
1506 use_agent_rest_https() {
1507 echo -e $BOLD"Using agent REST interface with https"$EBOLD
1508 export ADAPTER=$RESTBASE_SECURE
1513 # All calls to the agent will be directed to the agent dmaap interface from now on
1515 # (Function for test scripts)
1517 echo -e $BOLD"Agent using DMAAP interface"$EBOLD
1518 export ADAPTER=$DMAAPBASE
1524 # Turn on debug level tracing in the agent
1526 # (Function for test scripts)
1528 echo -e $BOLD"Setting agent debug"$EBOLD
1529 curl $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"debug"}' &> /dev/null
1530 if [ $? -ne 0 ]; then
1531 __print_err "could not set debug mode" $@
1538 # Turn on trace level tracing in the agent
1540 # (Function for test scripts)
1542 echo -e $BOLD"Setting agent trace"$EBOLD
1543 curl $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"trace"}' &> /dev/null
1544 if [ $? -ne 0 ]; then
1545 __print_err "could not set trace mode" $@
1552 # Perform curl retries when making direct call to the agent for the specified http response codes
1553 # Speace separated list of http response codes
1554 # args: [<response-code>]*
1555 use_agent_retries() {
1556 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
1557 AGENT_RETRY_CODES=$@
1566 # Check the agent logs for WARNINGs and ERRORs
1568 # (Function for test scripts)
1570 check_policy_agent_logs() {
1571 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH
1574 check_control_panel_logs() {
1575 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH
1578 __check_container_logs() {
1582 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
1584 #tmp=$(docker ps | grep $appname)
1585 tmp=$(docker ps -q --filter name=$appname) #get the container id
1586 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
1587 echo $dispname" is not running, no check made"
1590 foundentries="$(docker exec -it $tmp grep WARN $logpath | wc -l)"
1591 if [ $? -ne 0 ];then
1592 echo " Problem to search $appname log $logpath"
1594 if [ $foundentries -eq 0 ]; then
1595 echo " No WARN entries found in $appname log $logpath"
1597 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
1600 foundentries="$(docker exec -it $tmp grep ERR $logpath | wc -l)"
1601 if [ $? -ne 0 ];then
1602 echo " Problem to search $appname log $logpath"
1604 if [ $foundentries -eq 0 ]; then
1605 echo " No ERR entries found in $appname log $logpath"
1607 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
1613 # Store all container logs and other logs in the log dir for the script
1614 # Logs are stored with a prefix in case logs should be stored several times during a test
1615 # args: <logfile-prefix>
1616 # (Function for test scripts)
1618 if [ $# != 1 ]; then
1620 __print_err "need one arg, <file-prefix>" $@
1623 echo -e $BOLD"Storing all container logs, Policy Agent app log and consul config using prefix: "$1$EBOLD
1625 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
1626 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
1627 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
1628 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
1629 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
1630 docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
1631 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
1632 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
1634 docker exec -it $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
1636 docker exec -it $SDNC_ONAP_APP_NAME cat $SDNC_ONAP_KARAF_LOG > $TESTLOGS/$ATC/$1_SDNC_ONAP_karaf.log 2>&1
1638 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
1639 for ric in $rics; do
1640 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
1642 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
1643 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
1650 # Generic curl function, assumed all 200-codes are ok
1652 # returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
1653 # returns: The return code is 0 for ok and 1 for not ok
1655 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
1656 curlString="curl -skw %{http_code} $1"
1657 echo " CMD: $curlString" >> $HTTPLOG
1659 echo " RESP: $res" >> $HTTPLOG
1660 http_code="${res:${#res}-3}"
1661 if [ ${#res} -eq 3 ]; then
1662 echo "<no-response-from-server>"
1665 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
1666 echo "<not found, resp:${http_code}>"
1669 if [ $# -eq 2 ]; then
1670 echo "${res:0:${#res}-3}" | xargs
1672 echo "${res:0:${#res}-3}"
1679 #######################################
1680 ### Basic helper function for test cases
1681 #######################################
1683 # Test a simulator container variable value towards target value using an condition operator with an optional timeout.
1684 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
1685 # immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
1686 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
1687 # before setting pass or fail depending on the result of comparing variable and target using the operator.
1688 # 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.
1689 # Not to be called from test script.
1692 checkjsonarraycount=0
1694 if [ $# -eq 6 ]; then
1695 if [[ $3 == "json:"* ]]; then
1696 checkjsonarraycount=1
1699 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
1704 if [ $checkjsonarraycount -eq 0 ]; then
1705 result="$(__do_curl $2$3)"
1707 result=${result//[[:blank:]]/} #Strip blanks
1710 result="$(__do_curl $2$path)"
1712 echo "$result" > .tmp.curl.json
1713 result=$(python3 ../common/count_json_elements.py ".tmp.curl.json")
1715 duration=$((SECONDS-start))
1716 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
1718 if [ $retcode -ne 0 ]; then
1719 if [ $duration -gt $6 ]; then
1721 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
1722 __check_stop_at_error
1725 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
1727 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
1728 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
1730 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
1732 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
1733 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
1735 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
1737 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
1738 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
1740 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
1742 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
1743 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
1746 if [ $duration -gt $6 ]; then
1748 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
1749 __check_stop_at_error
1755 elif [ $# -eq 5 ]; then
1756 if [[ $3 == "json:"* ]]; then
1757 checkjsonarraycount=1
1760 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
1762 if [ $checkjsonarraycount -eq 0 ]; then
1763 result="$(__do_curl $2$3)"
1765 result=${result//[[:blank:]]/} #Strip blanks
1768 result="$(__do_curl $2$path)"
1770 echo "$result" > .tmp.curl.json
1771 result=$(python3 ../common/count_json_elements.py ".tmp.curl.json")
1773 if [ $retcode -ne 0 ]; then
1775 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
1776 __check_stop_at_error
1777 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
1779 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
1780 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
1782 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
1783 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
1785 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
1786 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
1788 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
1791 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
1792 __check_stop_at_error
1795 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
1802 ### Generic test cases for varaible checking
1804 # Tests if a variable value in the CR is equal to a target value and and optional timeout.
1805 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1806 # equal to the target or not.
1807 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1808 # before setting pass or fail depending on if the variable value becomes equal to the target
1810 # (Function for test scripts)
1812 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
1813 __var_test "CR" "$LOCALHOST$CR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
1816 __print_err "Wrong args to cr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
1820 # Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
1821 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1822 # equal to the target or not.
1823 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1824 # before setting pass or fail depending on if the variable value becomes equal to the target
1826 # (Function for test scripts)
1828 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
1829 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
1832 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
1836 # Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
1837 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1838 # greater than the target or not.
1839 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1840 # before setting pass or fail depending on if the variable value becomes greater than the target
1842 # (Function for test scripts)
1844 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
1845 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 ">" $2 $3
1848 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
1852 # Read a variable value from MR sim and send to stdout. Arg: <variable-name>
1854 echo "$(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"
1857 # Print a variable value from the MR stub.
1858 # arg: <variable-name>
1859 # (Function for test scripts)
1861 if [ $# != 1 ]; then
1863 __print_err "need one arg, <mr-param>" $@
1866 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"$EBOLD