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 # Set a description string for the test case
98 if [ -z "$TC_ONELINE_DESCR" ]; then
99 TC_ONELINE_DESCR="<no-description>"
100 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
103 # Counter for test suites
104 if [ -f .tmp_tcsuite_ctr ]; then
105 tmpval=$(< .tmp_tcsuite_ctr)
107 echo $tmpval > .tmp_tcsuite_ctr
110 # Create a test case id, ATC (Auto Test Case), from the name of the test case script.
111 # FTC1.sh -> ATC == FTC1
112 ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
114 # Create the logs dir if not already created in the current dir
115 if [ ! -d "logs" ]; then
120 # Create a http message log for this testcase
121 HTTPLOG=$PWD"/.httplog_"$ATC".txt"
124 # Create a log dir for the test case
125 mkdir -p $TESTLOGS/$ATC
127 # Clear the log dir for the test case
128 rm $TESTLOGS/$ATC/*.log &> /dev/null
129 rm $TESTLOGS/$ATC/*.txt &> /dev/null
130 rm $TESTLOGS/$ATC/*.json &> /dev/null
132 # Log all output from the test case to a TC log
133 TCLOG=$TESTLOGS/$ATC/TC.log
134 exec &> >(tee ${TCLOG})
136 #Variables for counting tests as well as passed and failed tests
143 #File to keep deviation messages
144 DEVIATION_FILE=".tmp_deviations"
145 rm $DEVIATION_FILE &> /dev/null
147 #Var for measuring execution time
148 TCTEST_START=$SECONDS
150 #File to save timer measurement results
151 TIMER_MEASUREMENTS=".timer_measurement.txt"
152 echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS
155 echo "-------------------------------------------------------------------------------------------------"
156 echo "----------------------------------- Test case: "$ATC
157 echo "----------------------------------- Started: "$(date)
158 echo "-------------------------------------------------------------------------------------------------"
159 echo "-- Description: "$TC_ONELINE_DESCR
160 echo "-------------------------------------------------------------------------------------------------"
161 echo "----------------------------------- Test case setup -----------------------------------"
165 if [ $# -lt 1 ]; then
168 if [ $paramerror -eq 0 ]; then
169 if [ "$1" != "remote" ] && [ "$1" != "remote-remove" ] && [ "$1" != "local" ]; then
175 if [ $paramerror -eq 0 ]; then
176 if [ "$1" == "auto-clean" ]; then
181 if [ $paramerror -eq 0 ]; then
182 if [ "$1" == "-use-local-image" ]; then
183 USE_LOCAL_IMAGES=${@:2}
184 while [ $# -gt 0 ]; do
190 if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
194 if [ $paramerror -eq 1 ]; then
195 echo -e $RED"Expected arg: local|remote|remote-remove [auto-clean] [-use-local-image <app-nam> [<app-name>]]"$ERED
199 echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
201 #Temp var to check for image variable name errors
203 #Create a file with image info for later printing as a table
204 image_list_file=".image-list"
205 echo -e " Container\tImage\ttag" > $image_list_file
207 # Check if image env var is set and if so export the env var with image to use (used by docker compose files)
208 # arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name>
209 __check_image_var() {
210 if [ $# -ne 5 ]; then
211 echo "Expected arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name>"
216 #Create var from the input var names
220 if [ -z $image ]; then
221 echo -e $RED"\$"$4" not set in test_env"$ERED
224 tmp=$tmp"<no-image>\t"
229 echo -e $RED"\$"$5" not set in test_env"$ERED
236 echo -e "$tmp" >> $image_list_file
238 export "${3}"=$image":"$tag
240 #echo " Configured image for ${1} (script start arg=${2}): "$image":"$tag
244 #Check if app local image shall override remote image
245 check_image_local_override() {
246 for im in $USE_LOCAL_IMAGES; do
247 if [ "$1" == "$im" ]; then
254 #Check if app uses image excluded from this test run
255 check_excluded_image() {
256 for im in $EXCLUDED_IMAGES; do
257 if [ "$1" == "$im" ]; then
264 # Check that image env setting are available
267 if [ $START_ARG == "local" ]; then
270 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG"
272 #Local Control Panel image
273 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG"
276 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG"
279 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG"
281 elif [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
283 check_image_local_override 'PA'
284 if [ $? -eq 0 ]; then
286 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_REMOTE_IMAGE" "POLICY_AGENT_REMOTE_IMAGE_TAG"
289 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG"
292 check_image_local_override 'CP'
293 if [ $? -eq 0 ]; then
294 #Remote Control Panel image
295 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE_TAG"
297 #Local Control Panel image
298 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG"
301 check_image_local_override 'SDNC'
302 if [ $? -eq 0 ]; then
304 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE_TAG"
307 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG"
310 check_image_local_override 'RICSIM'
311 if [ $? -eq 0 ]; then
312 #Remote ric sim image
313 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_REMOTE_IMAGE" "RIC_SIM_REMOTE_IMAGE_TAG"
316 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG"
320 #Should never get here....
321 echo "Unknow args: "$@
326 # These images are not built as part of this project official images, just check that env vars are set correctly
327 __check_image_var " Message Router" $START_ARG "MRSTUB_IMAGE" "MRSTUB_LOCAL_IMAGE" "MRSTUB_LOCAL_IMAGE_TAG"
328 __check_image_var " Callback Receiver" $START_ARG "CR_IMAGE" "CR_LOCAL_IMAGE" "CR_LOCAL_IMAGE_TAG"
329 __check_image_var " Consul" $START_ARG "CONSUL_IMAGE" "CONSUL_REMOTE_IMAGE" "CONSUL_REMOTE_IMAGE_TAG"
330 __check_image_var " CBS" $START_ARG "CBS_IMAGE" "CBS_REMOTE_IMAGE" "CBS_REMOTE_IMAGE_TAG"
331 __check_image_var " SDNC DB" $START_ARG "SDNC_DB_IMAGE" "SDNC_DB_REMOTE_IMAGE" "SDNC_DB_REMOTE_IMAGE_TAG"
332 check_excluded_image 'SDNC_ONAP'
333 if [ $? -eq 0 ]; then
334 __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"
335 __check_image_var " SDNC ONAP DB" $START_ARG "SDNC_ONAP_DB_IMAGE" "SDNC_ONAP_DB_REMOTE_IMAGE" "SDNC_ONAP_DB_REMOTE_IMAGE_TAG"
338 #Errors in image setting - exit
339 if [ $IMAGE_ERR -ne 0 ]; then
343 #Print a tables of the image settings
344 echo -e $BOLD"Images configured for start arg: "$START $EBOLD
345 column -t -s $'\t' $image_list_file
350 #Set the SIM_GROUP var
351 echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
352 if [ -z "$SIM_GROUP" ]; then
353 SIM_GROUP=$PWD/../simulator-group
354 if [ ! -d $SIM_GROUP ]; then
355 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
356 echo -e $RED"Please set the SIM_GROUP manually in the test_env.sh"$ERED
359 echo " SIM_GROUP auto set to: " $SIM_GROUP
361 elif [ $SIM_GROUP = *simulator_group ]; then
362 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
365 echo " SIM_GROUP env var already set to: " $SIM_GROUP
370 #Temp var to check for image pull errors
373 #Function to check if image exist and stop+remove the container+pull new images as needed
374 #args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
375 __check_and_pull_image() {
377 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
378 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
379 tmp_im=$(docker images --format $format_string ${4})
381 if [ $1 == "local" ]; then
382 if [ -z "$tmp_im" ]; then
383 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
387 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
389 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
390 if [ $1 == "remote-remove" ]; then
391 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
392 tmp="$(docker ps -aq --filter name=${3})"
393 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
394 docker stop $tmp &> .dockererr
395 if [ $? -ne 0 ]; then
398 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
403 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
404 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
405 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
406 docker rm $tmp &> .dockererr
407 if [ $? -ne 0 ]; then
410 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
415 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
416 echo -ne " Removing image - ${SAMELINE}"
417 tmp="$(docker images -q ${4})" &> /dev/null
418 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
419 docker rmi $4 &> .dockererr
420 if [ $? -ne 0 ]; then
423 echo -e $RED" Image could not be removed - try manual removal of the image"$ERED
427 echo -e " Removing image - "$GREEN"removed"$EGREEN
429 echo -e " Removing image - "$GREEN"image not in repository"$EGREEN
433 if [ -z "$tmp_im" ]; then
434 echo -ne " Pulling image${SAMELINE}"
435 docker pull $4 &> .dockererr
436 tmp_im=$(docker images ${4} | grep -v REPOSITORY)
437 if [ -z "$tmp_im" ]; then
439 echo -e " Pulling image -$RED could not be pulled"$ERED
444 echo -e " Pulling image -$GREEN Pulled $EGREEN"
446 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
453 echo -e $BOLD"Pulling configured images, if needed"$EBOLD
455 START_ARG_MOD=$START_ARG
456 check_image_local_override 'PA'
457 if [ $? -eq 1 ]; then
458 START_ARG_MOD="local"
460 app="Policy Agent"; __check_and_pull_image $START_ARG_MOD "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
462 START_ARG_MOD=$START_ARG
463 check_image_local_override 'CP'
464 if [ $? -eq 1 ]; then
465 START_ARG_MOD="local"
467 app="Non-RT RIC Control Panel"; __check_and_pull_image $START_ARG_MOD "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
469 START_ARG_MOD=$START_ARG
470 check_image_local_override 'RICSIM'
471 if [ $? -eq 1 ]; then
472 START_ARG_MOD="local"
474 app="Near-RT RIC Simulator"; __check_and_pull_image $START_ARG_MOD "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
476 app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
477 app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE
478 check_excluded_image 'SDNC'
479 if [ $? -eq 0 ]; then
480 START_ARG_MOD=$START_ARG
481 check_image_local_override 'SDNC'
482 if [ $? -eq 1 ]; then
483 START_ARG_MOD="local"
485 app="SDNC A1 Controller"; __check_and_pull_image $START_ARG_MOD "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
486 app="SDNC DB"; __check_and_pull_image $START_ARG "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
488 echo -e $YELLOW" Excluding SDNC image and related DB image from image check/pull"$EYELLOW
490 check_excluded_image 'SDNC_ONAP'
491 if [ $? -eq 0 ]; then
492 app="SDNC ONAP A1 Adapter"; __check_and_pull_image $START_ARG "$app" $SDNC_ONAP_APP_NAME $SDNC_ONAP_A1_ADAPTER_IMAGE
493 app="SDNC ONAP DB"; __check_and_pull_image $START_ARG "$app" $SDNC_ONAP_APP_NAME $SDNC_ONAP_DB_IMAGE
495 echo -e $YELLOW" Excluding ONAP SDNC image and related DB image from image check/pull"$EYELLOW
497 # MR stub image not checked, will be built by this script - only local image
498 # CR stub image not checked, will be built by this script - only local image
501 #Errors in image setting - exit
502 if [ $IMAGE_ERR -ne 0 ]; then
504 echo "#################################################################################################"
505 echo -e $RED"One or more images could not be pulled or containers using the images could not be stopped/removed"$ERED
506 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
507 echo "#################################################################################################"
514 echo -e $BOLD"Building images needed for test"$EBOLD
519 echo " Building mrstub image: mrstub:latest"
520 docker build -t mrstub . &> .dockererr
521 if [ $? -eq 0 ]; then
522 echo -e $GREEN" Build Ok"$EGREEN
524 echo -e $RED" Build Failed"$ERED
531 echo " Building Callback Receiver image: callback-receiver:latest"
532 docker build -t callback-receiver . &> .dockererr
533 if [ $? -eq 0 ]; then
534 echo -e $GREEN" Build Ok"$EGREEN
536 echo -e $RED" Build Failed"$ERED
544 # Create a table of the images used in the script
545 echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
547 docker_tmp_file=.docker-images-table
548 format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}"
549 echo -e " Application\tRepository\tTag\tCreated Since\tSize" > $docker_tmp_file
550 echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
551 echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
552 echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
553 echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
554 echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
555 echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
556 echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
557 check_excluded_image 'SDNC'
558 if [ $? -eq 0 ]; then
559 echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
560 echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
562 check_excluded_image 'SDNC_ONAP'
563 if [ $? -eq 0 ]; then
564 echo -e " SDNC ONAP A1 Adapter\t$(docker images --format $format_string $SDNC_ONAP_A1_ADAPTER_IMAGE)" >> $docker_tmp_file
565 echo -e " SDNC ONAP DB\t$(docker images --format $format_string $SDNC_ONAP_DB_IMAGE)" >> $docker_tmp_file
568 column -t -s $'\t' $docker_tmp_file
572 echo -e $BOLD"======================================================="$EBOLD
573 echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
574 echo -e $BOLD"======================================================="$EBOLD
577 # Function to print the test result, shall be the last cmd in a test script
579 # (Function for test scripts)
583 duration=$((TCTEST_END-TCTEST_START))
585 echo "-------------------------------------------------------------------------------------------------"
586 echo "------------------------------------- Test case: "$ATC
587 echo "------------------------------------- Ended: "$(date)
588 echo "-------------------------------------------------------------------------------------------------"
589 echo "-- Description: "$TC_ONELINE_DESCR
590 echo "-- Execution time: " $duration " seconds"
591 echo "-------------------------------------------------------------------------------------------------"
592 echo "------------------------------------- RESULTS"
596 if [ $RES_DEVIATION -gt 0 ]; then
597 echo "Test case deviations"
598 echo "===================================="
602 echo "Timer measurement in the test script"
603 echo "===================================="
604 column -t -s $'\t' $TIMER_MEASUREMENTS
607 total=$((RES_PASS+RES_FAIL))
608 if [ $RES_TEST -eq 0 ]; then
609 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
610 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
611 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
612 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
613 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
614 elif [ $total != $RES_TEST ]; then
615 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
616 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
617 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
618 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
619 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
620 elif [ $RES_CONF_FAIL -ne 0 ]; then
621 echo -e "\033[1mOne or more configure regest has failed. Check the script log....\033[0m"
622 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
623 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
624 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
625 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
626 elif [ $RES_PASS = $RES_TEST ]; then
627 echo -e "All tests \033[32m\033[1mPASS\033[0m"
628 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
629 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
630 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
631 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
634 # Update test suite counter
635 if [ -f .tmp_tcsuite_pass_ctr ]; then
636 tmpval=$(< .tmp_tcsuite_pass_ctr)
638 echo $tmpval > .tmp_tcsuite_pass_ctr
640 if [ -f .tmp_tcsuite_pass ]; then
641 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
644 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
645 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
646 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
647 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
648 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
650 # Update test suite counter
651 if [ -f .tmp_tcsuite_fail_ctr ]; then
652 tmpval=$(< .tmp_tcsuite_fail_ctr)
654 echo $tmpval > .tmp_tcsuite_fail_ctr
656 if [ -f .tmp_tcsuite_fail ]; then
657 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
661 echo "++++ Number of tests: "$RES_TEST
662 echo "++++ Number of passed tests: "$RES_PASS
663 echo "++++ Number of failed tests: "$RES_FAIL
665 echo "++++ Number of failed configs: "$RES_CONF_FAIL
667 echo "++++ Number of test case deviations: "$RES_DEVIATION
669 echo "------------------------------------- Test case complete ---------------------------------"
670 echo "-------------------------------------------------------------------------------------------------"
674 #####################################################################
675 ###### Functions for start, configuring, stoping, cleaning etc ######
676 #####################################################################
678 # Start timer for time measurement
679 # args - (any args will be printed though)
681 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
683 echo " Timer started"
686 # Print the value of the time (in seconds)
687 # args - <timer message to print> - timer value and message will be printed both on screen
688 # and in the timer measurement report
690 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
691 if [ $# -lt 1 ]; then
693 __print_err "need 1 or more args, <timer message to print>" $@
696 duration=$(($SECONDS-$TC_TIMER))
697 if [ $duration -eq 0 ]; then
700 duration=$duration" seconds"
702 echo " Timer duration :" $duration
704 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
707 # Print the value of the time (in seconds) and reset the timer
708 # args - <timer message to print> - timer value and message will be printed both on screen
709 # and in the timer measurement report
710 print_and_reset_timer() {
711 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
712 if [ $# -lt 1 ]; then
714 __print_err "need 1 or more args, <timer message to print>" $@
717 duration=$(($SECONDS-$TC_TIMER))" seconds"
718 if [ $duration -eq 0 ]; then
721 duration=$duration" seconds"
723 echo " Timer duration :" $duration
727 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
730 # Print info about a deviations from intended tests
731 # Each deviation counted is also printed in the testreport
732 # args <deviation message to print>
734 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
735 if [ $# -lt 1 ]; then
737 __print_err "need 1 or more args, <deviation message to print>" $@
741 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
742 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
746 # Stop and remove all containers
748 # (Function for test scripts)
751 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
753 CONTAINTER_NAMES=("Policy Agent " $POLICY_AGENT_APP_NAME\
754 "Non-RT RIC Simulator(s)" $RIC_SIM_PREFIX\
755 "Message Router " $MR_APP_NAME\
756 "Callback Receiver " $CR_APP_NAME\
757 "Control Panel " $CONTROL_PANEL_APP_NAME\
758 "SDNC A1 Controller " $SDNC_APP_NAME\
759 "SDNC DB " $SDNC_DB_APP_NAME\
760 "SDNC ONAP A1 Adapter " $SDNC_ONAP_APP_NAME\
761 "SDNC DB " $SDNC_ONAP_DB_APP_NAME\
762 "CBS " $CBS_APP_NAME\
763 "Consul " $CONSUL_APP_NAME)
765 nw=0 # Calc max width of container name, to make a nice table
766 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
767 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
768 nw=${#CONTAINTER_NAMES[i]}
772 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
773 APP="${CONTAINTER_NAMES[i]}"
774 CONTR="${CONTAINTER_NAMES[i+1]}"
775 for((w=${#CONTR}; w<$nw; w=w+1)); do
778 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
779 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
780 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
781 docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
782 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
787 echo -e $BOLD" Removing docker network"$EBOLD
788 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
789 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
790 docker network rm $DOCKER_SIM_NWNAME
791 if [ $? -ne 0 ]; then
792 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
797 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
798 docker network prune --force #&> /dev/null
800 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
801 docker volume prune --force #&> /dev/null
803 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
804 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
808 # Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
810 # (Function for test scripts)
811 auto_clean_containers() {
813 if [ "$AUTO_CLEAN" == "auto" ]; then
814 echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
819 # Function to sleep a test case for a numner of seconds. Prints the optional text args as info
820 # args: <sleep-time-in-sec> [any-text-in-quoteds-to-printed]
821 # (Function for test scripts)
824 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
825 if [ $# -lt 1 ]; then
827 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
830 #echo "---- Sleep for " $1 " seconds ---- "$2
832 duration=$((SECONDS-start))
833 while [ $duration -lt $1 ]; do
834 echo -ne " Slept for ${duration} seconds${SAMELINE}"
836 duration=$((SECONDS-start))
838 echo -ne " Slept for ${duration} seconds${SAMELINE}"
842 # Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
843 # Not to be called from the test script itself.
845 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
846 if [ $# -gt 1 ]; then
847 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
852 # Helper function to get a the port of a specific ric simulatpor
854 # (Not for test scripts)
856 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
857 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
859 if [[ "$res" =~ ^[0-9]+$ ]]; then
866 # Function to create the docker network for the test
867 # Not to be called from the test script itself.
868 __create_docker_network() {
869 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
870 if [ $? -ne 0 ]; then
871 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
874 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
875 echo -e "Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
876 docker network create $DOCKER_SIM_NWNAME
877 if [ $? -ne 0 ]; then
878 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
882 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
886 # Check if container is started by calling url on localhost using a port, expects response code 2XX
887 # args: <container-name> <port> <url> https|https
888 # Not to be called from the test script itself.
889 __check_container_start() {
891 if [ $# -ne 4 ]; then
893 elif [ $4 != "http" ] && [ $4 != "https" ]; then
896 if [ $paramError -ne 0 ]; then
898 __print_err "need 3 args, <container-name> <port> <url> https|https" $@
901 echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
905 if [[ $appname != "STANDALONE_"* ]] ; then
908 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
909 echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
916 if [ $app_started -eq 0 ]; then
919 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
922 if [ $localport -eq 0 ]; then
923 while [ $localport -eq 0 ]; do
924 echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
925 localport=$(__find_sim_port $appname)
927 echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
929 echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
935 echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
938 if [ $4 == "https" ]; then
939 result="$(__do_curl "-k https://localhost:"${localport}${url})"
941 result="$(__do_curl $LOCALHOST${localport}${url})"
943 if [ $? -eq 0 ]; then
944 if [ ${#result} -gt 15 ]; then
945 #If response is too long, truncate
946 result="...response text too long, omitted"
948 echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
949 echo -ne " Container $BOLD${appname}$EBOLD$GREEN is alive$EGREEN, responds to service status:$GREEN $result $EGREEN after $(($SECONDS-$TSTART)) seconds"
954 while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
955 echo -ne " Waiting for container ${appname} service status...retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
961 if [ "$pa_st" = "false" ]; then
963 echo -e $RED" Container ${appname} did not respond to service status"$ERED
972 # Function to start a container and wait until it responds on the given port and url.
973 #args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
974 __start_container() {
976 variableArgCount=$(($#-2))
977 if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
979 __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 ]*" $@
983 __create_docker_network
989 if [ "$2" == "NODOCKERARGS" ]; then
990 docker-compose up -d &> .dockererr
991 if [ $? -ne 0 ]; then
992 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
995 elif [ "$2" == "STANDALONE" ]; then
996 echo "Skipping docker-compose"
998 docker-compose up -d $2 &> .dockererr
999 if [ $? -ne 0 ]; then
1000 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1005 if [ "$2" == "STANDALONE" ]; then
1006 app_prefix="STANDALONE_"
1010 while [ $cntr -lt $variableArgCount ]; do
1011 app=$app_prefix$1; shift;
1017 __check_container_start "$app" "$port" "$url" $httpx
1025 ####################
1026 ### Consul functions
1027 ####################
1029 # Function to load config from a file into consul for the Policy Agent
1030 # arg: <json-config-file>
1031 # (Function for test scripts)
1032 consul_config_app() {
1034 echo -e $BOLD"Configuring Consul"$EBOLD
1036 if [ $# -ne 1 ]; then
1038 __print_err "need one arg, <json-config-file>" $@
1042 echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1
1044 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
1045 if [ $? -ne 0 ]; then
1046 echo -e $RED" FAIL - json config could not be loaded to consul" $ERED
1050 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
1051 echo $body > ".output"$1
1053 if [ $? -ne 0 ]; then
1054 echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED
1059 targetJson="{\"config\":"$targetJson"}"
1060 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1061 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1062 if [ $res -ne 0 ]; then
1063 echo -e $RED" FAIL - policy json config read from consul/cbs is not equal to the intended json config...." $ERED
1067 echo -e $GREEN" Config loaded ok to consul"$EGREEN
1075 # Function to perpare the consul configuration according to the current simulator configuration
1076 # args: SDNC|SDNC_ONAP|NOSDNC <output-file>
1077 # (Function for test scripts)
1078 prepare_consul_config() {
1079 echo -e $BOLD"Prepare Consul config"$EBOLD
1081 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
1083 if [ $# != 2 ]; then
1085 __print_err "need two args, SDNC|SDNC_ONAP|NOSDNC <output-file>" $@
1089 if [ $1 == "SDNC" ]; then
1090 echo -e " Config$BOLD including SDNC$EBOLD configuration"
1091 elif [ $1 == "SDNC_ONAP" ]; then
1092 echo -e " Config$BOLD including SDNC ONAP$EBOLD configuration"
1093 elif [ $1 == "NOSDNC" ]; then
1094 echo -e " Config$BOLD excluding SDNC or SDNC ONAP$EBOLD configuration"
1097 __print_err "need two args, SDNC|SDNC_ONAP|NOSDNC <output-file>" $@
1102 if [ $1 == "SDNC" ]; then
1103 config_json=$config_json"\n \"controller\": ["
1104 config_json=$config_json"\n {"
1105 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
1106 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1107 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://$SDNC_APP_NAME:$SDNC_PORT\","
1109 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://localhost:$SDNC_LOCAL_PORT\","
1111 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
1112 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
1113 config_json=$config_json"\n }"
1114 config_json=$config_json"\n ],"
1116 if [ $1 == "SDNC_ONAP" ]; then
1117 config_json=$config_json"\n \"controller\": ["
1118 config_json=$config_json"\n {"
1119 config_json=$config_json"\n \"name\": \"$SDNC_ONAP_APP_NAME\","
1120 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1121 config_json=$config_json"\n \"baseUrl\": \"http://$SDNC_ONAP_APP_NAME:$SDNC_ONAP_INTERNAL_PORT\","
1123 config_json=$config_json"\n \"baseUrl\": \"http://localhost:$SDNC_ONAP_EXTERNAL_PORT\","
1125 config_json=$config_json"\n \"userName\": \"$SDNC_ONAP_USER\","
1126 config_json=$config_json"\n \"password\": \"$SDNC_ONAP_PWD\""
1127 config_json=$config_json"\n }"
1128 config_json=$config_json"\n ],"
1132 config_json=$config_json"\n \"streams_publishes\": {"
1133 config_json=$config_json"\n \"dmaap_publisher\": {"
1134 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1135 config_json=$config_json"\n \"dmaap_info\": {"
1136 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1137 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_WRITE_URL\""
1139 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_WRITE_URL\""
1141 config_json=$config_json"\n }"
1142 config_json=$config_json"\n }"
1143 config_json=$config_json"\n },"
1144 config_json=$config_json"\n \"streams_subscribes\": {"
1145 config_json=$config_json"\n \"dmaap_subscriber\": {"
1146 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1147 config_json=$config_json"\n \"dmaap_info\": {"
1148 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1149 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_READ_URL\""
1151 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_READ_URL\""
1153 config_json=$config_json"\n }"
1154 config_json=$config_json"\n }"
1155 config_json=$config_json"\n },"
1157 config_json=$config_json"\n \"ric\": ["
1159 rics=$(docker ps | grep ricsim | awk '{print $NF}')
1161 if [ $? -ne 0 ] || [ -z "$rics" ]; then
1162 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
1168 for ric in $rics; do
1169 if [ $cntr -gt 0 ]; then
1170 config_json=$config_json"\n ,"
1172 config_json=$config_json"\n {"
1173 config_json=$config_json"\n \"name\": \"$ric\","
1174 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1175 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
1177 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://localhost:$(__find_sim_port $ric)\","
1179 if [ $1 == "SDNC" ]; then
1180 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
1181 elif [ $1 == "SDNC_ONAP" ]; then
1182 config_json=$config_json"\n \"controller\": \"$SDNC_ONAP_APP_NAME\","
1184 config_json=$config_json"\n \"managedElementIds\": ["
1185 config_json=$config_json"\n \"me1_$ric\","
1186 config_json=$config_json"\n \"me2_$ric\""
1187 config_json=$config_json"\n ]"
1188 config_json=$config_json"\n }"
1192 config_json=$config_json"\n ]"
1193 config_json=$config_json"\n}"
1196 printf "$config_json">$2
1202 # Start Consul and CBS
1204 # (Function for test scripts)
1205 start_consul_cbs() {
1207 echo -e $BOLD"Starting Consul and CBS"$EBOLD
1209 __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" "http" \
1210 "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck" "http"
1213 ###########################
1214 ### RIC Simulator functions
1215 ###########################
1217 use_simulator_http() {
1218 echo -e "Using unsecure $BOLD http $EBOLD towards the simulators"
1219 export RIC_SIM_HTTPX="http"
1220 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1221 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
1225 use_simulator_https() {
1226 echo -e "Using secure $BOLD https $EBOLD towards the simulators"
1227 export RIC_SIM_HTTPX="https"
1228 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1229 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
1233 # Start one group (ricsim_g1, ricsim_g2 or ricsim_g3) with a number of RIC Simulators using a given A interface
1234 # args: ricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>
1235 # (Function for test scripts)
1236 start_ric_simulators() {
1238 echo -e $BOLD"Starting RIC Simulators"$EBOLD
1240 if [ $# != 3 ]; then
1242 __print_err "need three args, ricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>" $@
1245 echo " $2 simulators using basename: $1 on interface: $3"
1246 #Set env var for simulator count and A1 interface vesion for the given group
1247 if [ $1 == "ricsim_g1" ]; then
1250 elif [ $1 == "ricsim_g2" ]; then
1253 elif [ $1 == "ricsim_g3" ]; then
1258 __print_err "need three args, gricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>" $@
1262 # Create .env file to compose project, all ric container will get this prefix
1263 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
1265 export G1_A1_VERSION
1266 export G2_A1_VERSION
1267 export G3_A1_VERSION
1269 docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT"
1272 while [ $cntr -le $2 ]; do
1275 app_data="$app_data $app $port / "$RIC_SIM_HTTPX
1278 __start_container ric "$docker_args" $app_data
1282 ###########################
1283 ### Control Panel functions
1284 ###########################
1286 # Start the Control Panel container
1288 # (Function for test scripts)
1289 start_control_panel() {
1291 echo -e $BOLD"Starting Control Panel"$EBOLD
1293 __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/" "http"
1301 # Start the SDNC A1 Controller
1303 # (Function for test scripts)
1306 echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
1308 check_excluded_image 'SDNC'
1309 if [ $? -eq 1 ]; then
1310 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
1311 echo -e $RED"SDNC will not be started"$ERED
1315 __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT $SDNC_ALIVE_URL "http"
1320 echo -e $BOLD"Using http between agent and SDNC"$EBOLD
1321 export SDNC_HTTPX="http"
1322 export SDNC_PORT=$SDNC_INTERNAL_PORT
1323 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT
1328 echo -e $BOLD"Using https between agent and SDNC"$EBOLD
1329 export SDNC_HTTPX="https"
1330 export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT
1331 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT
1335 #######################
1336 ### SDNC ONAP functions
1337 #######################
1339 # Start the SDNC ONAP A1 Adapter
1341 # (Function for test scripts)
1344 echo -e $BOLD"Starting SDNC ONAP A1 Adapter"$EBOLD
1346 check_excluded_image 'SDNC_ONAP'
1347 if [ $? -eq 1 ]; then
1348 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
1349 echo -e $RED"SDNC ONAP will not be started"$ERED
1353 __start_container sdnc_onap NODOCKERARGS $SDNC_ONAP_APP_NAME $SDNC_ONAP_EXTERNAL_PORT $SDNC_ONAP_ALIVE_URL "http"
1357 # Configure the SDNC ONAP A1 Adapter
1359 # (Function for test scripts)
1360 config_sdnc_onap() {
1362 echo -e $BOLD"Configuring SDNC ONAP A1 Adapter"$EBOLD
1364 LOCALFILE=".sdnc_onap.prop"
1365 REMOTEFILE="/tmp/.sdnc_onap.prop"
1367 docker cp $SDNC_ONAP_APP_NAME:$SDNC_ONAP_PROPERTIES_FILE $LOCALFILE
1368 if [ $? -ne 0 ]; then
1369 echo -e $RED"Could not copy $SDNC_ONAP_PROPERTIES_FILE from $SDNC_ONAP_APP_NAME container"$ERED
1374 #Config of the prop file shall be inserted here
1376 #Copy file to /tmp and then to final destination, a trick to get correct permission of the file.
1378 docker cp $LOCALFILE $SDNC_ONAP_APP_NAME:$REMOTEFILE
1379 if [ $? -ne 0 ]; then
1380 echo -e $RED"Could not copy local $LOCALFILE to $REMOTEFILE in $SDNC_ONAP_APP_NAME container"$ERED
1384 docker exec -it $SDNC_ONAP_APP_NAME cp $REMOTEFILE $SDNC_ONAP_PROPERTIES_FILE
1385 if [ $? -ne 0 ]; then
1386 echo -e $RED"Could not copy $REMOTEFILE to $SDNC_ONAP_PROPERTIES_FILE in $SDNC_ONAP_APP_NAME container"$ERED
1391 #####################
1392 ### MR stub functions
1393 #####################
1395 # Start the Message Router stub interface in the simulator group
1397 # (Function for test scripts)
1400 echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
1401 export MR_CERT_MOUNT_DIR="./cert"
1402 __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/" "http"
1406 echo -e $BOLD"Using http between agent and MR"$EBOLD
1407 export MR_HTTPX="http"
1408 export MR_PORT=$MR_INTERNAL_PORT
1409 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT
1414 echo -e $BOLD"Using https between agent and MR"$EBOLD
1415 export MR_HTTPX="https"
1416 export MR_PORT=$MR_INTERNAL_SECURE_PORT
1417 export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT
1426 # Start the Callback reciver in the simulator group
1428 # (Function for test scripts)
1431 echo -e $BOLD"Starting Callback Receiver"$EBOLD
1433 __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/" "http"
1437 ###########################
1438 ### Policy Agents functions
1439 ###########################
1441 # Use an agent on the local machine instead of container
1442 use_agent_stand_alone() {
1446 # Start the policy agent
1448 # (Function for test scripts)
1449 start_policy_agent() {
1451 echo -e $BOLD"Starting Policy Agent"$EBOLD
1453 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1454 __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1456 echo -e $RED"The consul config produced by this test script (filename '<fullpath-to-autotest-dir>.output<file-name>"$ERED
1457 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
1458 echo -e $RED"application.yaml"$ERED
1459 echo -e $RED"The application jar may need to be built beforefor continuing"$ERED
1460 echo -e $RED"The agent shall now be running on port $POLICY_AGENT_EXTERNAL_PORT for http"$ERED
1462 read -p "<press any key to continue>"
1463 __start_container policy_agent "STANDALONE" $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1468 # All calls to the agent will be directed to the agent REST interface from now on
1470 # (Function for test scripts)
1471 use_agent_rest_http() {
1472 echo -e $BOLD"Using agent REST interface with http"$EBOLD
1473 export ADAPTER=$RESTBASE
1477 # All calls to the agent will be directed to the agent REST interface from now on
1479 # (Function for test scripts)
1480 use_agent_rest_https() {
1481 echo -e $BOLD"Using agent REST interface with https"$EBOLD
1482 export ADAPTER=$RESTBASE_SECURE
1487 # All calls to the agent will be directed to the agent dmaap interface from now on
1489 # (Function for test scripts)
1491 echo -e $BOLD"Agent using DMAAP interface"$EBOLD
1492 export ADAPTER=$DMAAPBASE
1498 # Turn on debug level tracing in the agent
1500 # (Function for test scripts)
1502 echo -e $BOLD"Setting agent debug"$EBOLD
1503 curl $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"debug"}' &> /dev/null
1504 if [ $? -ne 0 ]; then
1505 __print_err "could not set debug mode" $@
1512 # Perform curl retries when making direct call to the agent for the specified http response codes
1513 # Speace separated list of http response codes
1514 # args: [<response-code>]*
1515 use_agent_retries() {
1516 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
1517 AGENT_RETRY_CODES=$@
1526 # Check the agent logs for WARNINGs and ERRORs
1528 # (Function for test scripts)
1530 check_policy_agent_logs() {
1531 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH
1534 check_control_panel_logs() {
1535 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH
1538 __check_container_logs() {
1542 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
1544 #tmp=$(docker ps | grep $appname)
1545 tmp=$(docker ps -q --filter name=$appname) #get the container id
1546 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
1547 echo $dispname" is not running, no check made"
1550 foundentries="$(docker exec -it $tmp grep WARN $logpath | wc -l)"
1551 if [ $? -ne 0 ];then
1552 echo " Problem to search $appname log $logpath"
1554 if [ $foundentries -eq 0 ]; then
1555 echo " No WARN entries found in $appname log $logpath"
1557 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
1560 foundentries="$(docker exec -it $tmp grep ERR $logpath | wc -l)"
1561 if [ $? -ne 0 ];then
1562 echo " Problem to search $appname log $logpath"
1564 if [ $foundentries -eq 0 ]; then
1565 echo " No ERR entries found in $appname log $logpath"
1567 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
1573 # Store all container logs and other logs in the log dir for the script
1574 # Logs are stored with a prefix in case logs should be stored several times during a test
1575 # args: <logfile-prefix>
1576 # (Function for test scripts)
1578 if [ $# != 1 ]; then
1580 __print_err "need one arg, <file-prefix>" $@
1583 echo -e $BOLD"Storing all container logs, Policy Agent app log and consul config using prefix: "$1$EBOLD
1585 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
1586 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
1587 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
1588 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
1589 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
1590 docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
1591 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
1592 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
1594 docker exec -it $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
1596 docker exec -it $SDNC_ONAP_APP_NAME cat $SDNC_ONAP_KARAF_LOG > $TESTLOGS/$ATC/$1_SDNC_ONAP_karaf.log 2>&1
1598 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
1599 for ric in $rics; do
1600 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
1602 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
1603 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
1610 # Generic curl function, assumed all 200-codes are ok
1612 # returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
1613 # returns: The return code is 0 for ok and 1 for not ok
1615 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
1616 curlString="curl -skw %{http_code} $1"
1617 echo " CMD: $curlString" >> $HTTPLOG
1619 echo " RESP: $res" >> $HTTPLOG
1620 http_code="${res:${#res}-3}"
1621 if [ ${#res} -eq 3 ]; then
1622 echo "<no-response-from-server>"
1625 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
1626 echo "<not found, resp:${http_code}>"
1629 if [ $# -eq 2 ]; then
1630 echo "${res:0:${#res}-3}" | xargs
1632 echo "${res:0:${#res}-3}"
1639 #######################################
1640 ### Basic helper function for test cases
1641 #######################################
1643 # Test a simulator container variable value towards target value using an condition operator with an optional timeout.
1644 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
1645 # immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
1646 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
1647 # before setting pass or fail depending on the result of comparing variable and target using the operator.
1648 # 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.
1649 # Not to be called from test script.
1652 checkjsonarraycount=0
1654 if [ $# -eq 6 ]; then
1655 if [[ $3 == "json:"* ]]; then
1656 checkjsonarraycount=1
1659 #echo -e "---- ${1} sim test criteria: \033[1m ${3} \033[0m ${4} ${5} within ${6} seconds ----"
1660 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
1665 if [ $checkjsonarraycount -eq 0 ]; then
1666 result="$(__do_curl $2$3)"
1668 result=${result//[[:blank:]]/} #Strip blanks
1671 result="$(__do_curl $2$path)"
1673 echo "$result" > .tmp.curl.json
1674 result=$(python3 ../common/count_json_elements.py ".tmp.curl.json")
1676 duration=$((SECONDS-start))
1677 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
1679 if [ $retcode -ne 0 ]; then
1680 if [ $duration -gt $6 ]; then
1682 #echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached in ${6} seconds, result = ${result} ----"
1683 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
1686 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
1688 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
1689 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
1690 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds ----"
1692 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
1694 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
1695 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
1696 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds, result = ${result} ----"
1698 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
1700 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
1701 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
1702 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds, result = ${result} ----"
1704 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
1706 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
1707 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
1708 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds, result = ${result} ----"
1711 if [ $duration -gt $6 ]; then
1713 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
1714 #echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached in ${6} seconds, result = ${result} ----"
1720 elif [ $# -eq 5 ]; then
1721 if [[ $3 == "json:"* ]]; then
1722 checkjsonarraycount=1
1725 #echo -e "---- ${1} sim test criteria: \033[1m ${3} \033[0m ${4} ${5} ----"
1726 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
1728 if [ $checkjsonarraycount -eq 0 ]; then
1729 result="$(__do_curl $2$3)"
1731 result=${result//[[:blank:]]/} #Strip blanks
1734 result="$(__do_curl $2$path)"
1736 echo "$result" > .tmp.curl.json
1737 result=$(python3 ../common/count_json_elements.py ".tmp.curl.json")
1739 if [ $retcode -ne 0 ]; then
1741 #echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached, result = ${result} ----"
1742 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
1743 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
1745 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
1746 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met"
1747 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
1749 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
1750 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met, result = ${result} ----"
1751 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
1753 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
1754 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met, result = ${result} ----"
1755 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
1757 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
1758 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met, result = ${result} ----"
1761 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
1762 #echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached, result = ${result} ----"
1765 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
1772 ### Generic test cases for varaible checking
1774 # Tests if a variable value in the CR is equal to a target value and and optional timeout.
1775 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1776 # equal to the target or not.
1777 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1778 # before setting pass or fail depending on if the variable value becomes equal to the target
1780 # (Function for test scripts)
1782 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
1783 __var_test "CR" "$LOCALHOST$CR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
1786 __print_err "Wrong args to cr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
1790 # Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
1791 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1792 # equal to the target or not.
1793 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1794 # before setting pass or fail depending on if the variable value becomes equal to the target
1796 # (Function for test scripts)
1798 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
1799 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
1802 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
1806 # Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
1807 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1808 # greater than the target or not.
1809 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1810 # before setting pass or fail depending on if the variable value becomes greater than the target
1812 # (Function for test scripts)
1814 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
1815 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 ">" $2 $3
1818 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
1822 # Read a variable value from MR sim and send to stdout. Arg: <variable-name>
1824 echo "$(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"
1827 # Print a variable value from the MR stub.
1828 # arg: <variable-name>
1829 # (Function for test scripts)
1831 if [ $# != 1 ]; then
1833 __print_err "need one arg, <mr-param>" $@
1836 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"$EBOLD