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] [--stop-at-error] [--ricsim-prefix <prefix> ] [ --env-file <environment-filename> ] [--use-local-image <app-nam> [<app-name>]*]
24 # Create a test case id, ATC (Auto Test Case), from the name of the test case script.
25 # FTC1.sh -> ATC == FTC1
26 ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
28 #Create result file (containing '1' for error) for this test case
29 #Will be replaced with a file containing '0' if all test cases pass
30 echo "1" > "$PWD/.result$ATC.txt"
32 #Formatting for 'echo' cmd
37 GREEN="\033[32m\033[1m"
39 YELLOW="\033[33m\033[1m"
44 if [ $? -ne 0 ] || [ -z tmp ]; then
45 echo -e $RED"python3 is required to run the test environment, pls install"$ERED
49 if [ $? -ne 0 ] || [ -z tmp ]; then
50 echo -e $RED"docker is required to run the test environment, pls install"$ERED
54 tmp=$(which docker-compose)
55 if [ $? -ne 0 ] || [ -z tmp ]; then
56 echo -e $RED"docker-compose is required to run the test environment, pls install"$ERED
60 # Just resetting any previous echo formatting...
63 # default test environment variables
66 echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@
69 LOCALHOST="http://localhost:"
71 # Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
74 # Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
77 # Var to contol if the agent runs in a container (normal = 0) or as application on the local machine ( = 1)
80 # Var to hold 'auto' in case containers shall be stopped when test case ends
83 # Var to hold the app names to use local image for when running 'remote' or 'remote-remove'
86 # List of available apps to override with local image
87 AVAILABLE_LOCAL_IMAGES_OVERRIDE="PA ECS CP SDNC RICSIM"
89 # 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
92 # Function to indent cmd output with one space
93 indent1() { sed 's/^/ /'; }
95 # Function to indent cmd output with two spaces
96 indent2() { sed 's/^/ /'; }
98 # Set a description string for the test case
99 if [ -z "$TC_ONELINE_DESCR" ]; then
100 TC_ONELINE_DESCR="<no-description>"
101 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
104 # Counter for test suites
105 if [ -f .tmp_tcsuite_ctr ]; then
106 tmpval=$(< .tmp_tcsuite_ctr)
108 echo $tmpval > .tmp_tcsuite_ctr
111 # Create the logs dir if not already created in the current dir
112 if [ ! -d "logs" ]; then
117 # Create the tmp dir for temporary files that is not needed after the test
118 # hidden files for the test env is still stored in the current dir
119 if [ ! -d "tmp" ]; then
123 # Create a http message log for this testcase
124 HTTPLOG=$PWD"/.httplog_"$ATC".txt"
128 # Create a log dir for the test case
129 mkdir -p $TESTLOGS/$ATC
131 # Save create for current logs
132 mkdir -p $TESTLOGS/$ATC/previous
134 rm $TESTLOGS/$ATC/previous/*.log &> /dev/null
135 rm $TESTLOGS/$ATC/previous/*.txt &> /dev/null
136 rm $TESTLOGS/$ATC/previous/*.json &> /dev/null
138 mv $TESTLOGS/$ATC/*.log $TESTLOGS/$ATC/previous &> /dev/null
139 mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
140 mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
142 # Clear the log dir for the test case
143 rm $TESTLOGS/$ATC/*.log &> /dev/null
144 rm $TESTLOGS/$ATC/*.txt &> /dev/null
145 rm $TESTLOGS/$ATC/*.json &> /dev/null
147 # Log all output from the test case to a TC log
148 TCLOG=$TESTLOGS/$ATC/TC.log
149 exec &> >(tee ${TCLOG})
151 #Variables for counting tests as well as passed and failed tests
158 #File to keep deviation messages
159 DEVIATION_FILE=".tmp_deviations"
160 rm $DEVIATION_FILE &> /dev/null
163 # Trap "command not found" and make the script fail
166 if [ $? -eq 127 ]; then
167 echo -e $RED"Function not found, set script to FAIL"$ERED
177 TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
178 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ $EBOLD
179 echo "TEST $TEST_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ >> $HTTPLOG
181 ((TEST_SEQUENCE_NR++))
184 __log_test_fail_general() {
185 echo -e $RED" FAIL."$1 $ERED
187 __check_stop_at_error
190 __log_test_fail_status_code() {
191 echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED
193 __check_stop_at_error
196 __log_test_fail_body() {
197 echo -e $RED" FAIL, returned body not correct"$ERED
199 __check_stop_at_error
202 __log_test_fail_not_supported() {
203 echo -e $RED" FAIL, function not supported"$ERED
205 __check_stop_at_error
209 if [ $# -gt 0 ]; then
213 echo -e $GREEN" PASS"$EGREEN
216 #Counter for configurations
219 TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
220 echo -e $BOLD"CONF $CONF_SEQUENCE_NR (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ $EBOLD
221 echo "CONF $CONF_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ >> $HTTPLOG
222 ((CONF_SEQUENCE_NR++))
225 __log_conf_fail_general() {
226 echo -e $RED" FAIL."$1 $ERED
228 __check_stop_at_error
231 __log_conf_fail_status_code() {
232 echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED
234 __check_stop_at_error
237 __log_conf_fail_body() {
238 echo -e $RED" FAIL, returned body not correct"$ERED
240 __check_stop_at_error
244 if [ $# -gt 0 ]; then
247 echo -e $GREEN" OK"$EGREEN
250 #Var for measuring execution time
251 TCTEST_START=$SECONDS
253 #File to save timer measurement results
254 TIMER_MEASUREMENTS=".timer_measurement.txt"
255 echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS
258 echo "-------------------------------------------------------------------------------------------------"
259 echo "----------------------------------- Test case: "$ATC
260 echo "----------------------------------- Started: "$(date)
261 echo "-------------------------------------------------------------------------------------------------"
262 echo "-- Description: "$TC_ONELINE_DESCR
263 echo "-------------------------------------------------------------------------------------------------"
264 echo "----------------------------------- Test case setup -----------------------------------"
268 if [ $# -lt 1 ]; then
271 if [ $paramerror -eq 0 ]; then
272 if [ "$1" != "remote" ] && [ "$1" != "remote-remove" ] && [ "$1" != "local" ]; then
279 while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do
281 if [ $paramerror -eq 0 ]; then
282 if [ "$1" == "auto-clean" ]; then
284 echo "Option set - Auto clean at end of test script"
289 if [ $paramerror -eq 0 ]; then
290 if [ "$1" == "--stop-at-error" ]; then
292 echo "Option set - Stop at first error"
297 if [ $paramerror -eq 0 ]; then
298 if [ "$1" == "--ricsim-prefix" ]; then
304 echo "Option set - Overriding RIC_SIM_PREFIX with: "$1
310 if [ $paramerror -eq 0 ]; then
311 if [ "$1" == "--env-file" ]; then
317 echo "Option set - Reading test env from: "$1
323 if [ $paramerror -eq 0 ]; then
324 if [ "$1" == "--use-local-image" ]; then
327 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
328 USE_LOCAL_IMAGES=$USE_LOCAL_IMAGES" "$1
329 if [[ "$AVAILABLE_LOCAL_IMAGES_OVERRIDE" != *"$1"* ]]; then
335 if [ -z "$USE_LOCAL_IMAGES" ]; then
338 echo "Option set - Override remote images for app(s):"$USE_LOCAL_IMAGES
346 if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
350 if [ $paramerror -eq 1 ]; then
351 echo -e $RED"Expected arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--ricsim-prefix <prefix> ] [ --env-file <environment-filename> ] [--use-local-image <app-nam> [<app-name>]*]"$ERED
355 # sourcing the selected env variables for the test case
356 if [ -f "$TEST_ENV_VAR_FILE" ]; then
357 echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD
360 if [ -z "$TEST_ENV_PROFILE" ] || [ -z "$SUPPORTED_PROFILES" ]; then
361 echo -e $YELLOW"This test case may no work with selected test env file. TEST_ENV_PROFILE is missing in test_env file or SUPPORTED_PROFILES is missing in test case file"$EYELLOW
363 if [[ "$SUPPORTED_PROFILES" == *"$TEST_ENV_PROFILE"* ]]; then
364 echo -e $GREEN"Test case support the selected test env file"$EGREEN
366 echo -e $RED"Test case does not support the selected test env file"$ERED
367 echo -e $RED"Exiting...."$ERED
372 echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED
373 echo " Select one of following env var file matching the intended target of the test"
374 echo " Restart the test using the flag '--env-file <path-to-env-file>"
375 ls ../common/test_env* | indent1
379 #Vars for A1 interface version and container count
391 # Vars to switch between http and https. Extra curl flag needed for https
392 export RIC_SIM_HTTPX="http"
393 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
394 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
395 export RIC_SIM_CERT_MOUNT_DIR="./cert"
397 export MR_HTTPX="http"
398 export MR_PORT=$MR_INTERNAL_PORT
399 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker net
401 export CR_HTTPX="http"
402 export CR_PORT=$CR_INTERNAL_PORT
403 export CR_LOCAL_PORT=$CR_EXTERNAL_PORT #When CR is running outside the docker net
404 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
406 export PROD_STUB_HTTPX="http"
407 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
408 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT #When CR is running outside the docker net
409 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
411 export SDNC_HTTPX="http"
412 export SDNC_PORT=$SDNC_INTERNAL_PORT
413 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net
415 echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
417 #Temp var to check for image variable name errors
419 #Create a file with image info for later printing as a table
420 image_list_file="./tmp/.image-list"
421 echo -e " Container\tImage\ttag" > $image_list_file
423 # Check if image env var is set and if so export the env var with image to use (used by docker compose files)
424 # arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name> <app-short-name>
425 __check_image_var() {
426 if [ $# -ne 6 ]; then
427 echo "Expected arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name> <app-short-name>"
431 __check_included_image $6
432 if [ $? -ne 0 ]; then
433 echo -e "$1\t<image-excluded>\t<no-tag>" >> $image_list_file
434 # Image is excluded since the corresponding app is not used in this test
438 #Create var from the input var names
442 if [ -z $image ]; then
443 echo -e $RED"\$"$4" not set in $TEST_ENV_VAR_FILE"$ERED
446 tmp=$tmp"<no-image>\t"
451 echo -e $RED"\$"$5" not set in $TEST_ENV_VAR_FILE"$ERED
458 echo -e "$tmp" >> $image_list_file
460 export "${3}"=$image":"$tag
462 #echo " Configured image for ${1} (script start arg=${2}): "$image":"$tag
466 #Check if app local image shall override remote image
467 # Possible IDs for local image override: PA, CP, SDNC, RICSIM, ECS
468 __check_image_local_override() {
469 for im in $USE_LOCAL_IMAGES; do
470 if [ "$1" == "$im" ]; then
477 # Check if app uses image included in this test run
478 # Returns 0 if image is included, 1 if not
479 # Possible IDs for image inclusion: CBS, CONSUL, CP, CR, ECS, MR, PA, PRODSTUB, RICSIM, SDNC
480 __check_included_image() {
481 for im in $INCLUDED_IMAGES; do
482 if [ "$1" == "$im" ]; then
489 # Check that image env setting are available
492 if [ $START_ARG == "local" ]; then
495 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG" PA
497 #Local Control Panel image
498 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG" CP
501 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG" SDNC
504 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG" RICSIM
506 elif [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
508 __check_image_local_override 'PA'
509 if [ $? -eq 0 ]; then
511 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_REMOTE_IMAGE" "POLICY_AGENT_REMOTE_IMAGE_TAG" PA
514 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG" PA
517 __check_image_local_override 'CP'
518 if [ $? -eq 0 ]; then
519 #Remote Control Panel image
520 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE_TAG" CP
522 #Local Control Panel image
523 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG" CP
526 __check_image_local_override 'SDNC'
527 if [ $? -eq 0 ]; then
529 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE_TAG" SDNC
532 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG" SDNC
535 __check_image_local_override 'RICSIM'
536 if [ $? -eq 0 ]; then
537 #Remote ric sim image
538 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_REMOTE_IMAGE" "RIC_SIM_REMOTE_IMAGE_TAG" RICSIM
541 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG" RICSIM
544 __check_image_local_override 'ECS'
545 if [ $? -eq 0 ]; then
547 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_REMOTE_IMAGE" "ECS_REMOTE_IMAGE_TAG" ECS
550 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_LOCAL_IMAGE" "ECS_LOCAL_IMAGE_TAG" ECS
554 #Should never get here....
555 echo "Unknow args: "$@
560 # These images are not built as part of this project official images, just check that env vars are set correctly
561 __check_image_var " Message Router" $START_ARG "MRSTUB_IMAGE" "MRSTUB_LOCAL_IMAGE" "MRSTUB_LOCAL_IMAGE_TAG" MR
562 __check_image_var " Callback Receiver" $START_ARG "CR_IMAGE" "CR_LOCAL_IMAGE" "CR_LOCAL_IMAGE_TAG" CR
563 __check_image_var " Producer stub" $START_ARG "PROD_STUB_IMAGE" "PROD_STUB_LOCAL_IMAGE" "PROD_STUB_LOCAL_IMAGE_TAG" PRODSTUB
564 __check_image_var " Consul" $START_ARG "CONSUL_IMAGE" "CONSUL_REMOTE_IMAGE" "CONSUL_REMOTE_IMAGE_TAG" CONSUL
565 __check_image_var " CBS" $START_ARG "CBS_IMAGE" "CBS_REMOTE_IMAGE" "CBS_REMOTE_IMAGE_TAG" CBS
566 __check_image_var " SDNC DB" $START_ARG "SDNC_DB_IMAGE" "SDNC_DB_REMOTE_IMAGE" "SDNC_DB_REMOTE_IMAGE_TAG" SDNC #Uses sdnc app name
568 #Errors in image setting - exit
569 if [ $IMAGE_ERR -ne 0 ]; then
573 #Print a tables of the image settings
574 echo -e $BOLD"Images configured for start arg: "$START $EBOLD
575 column -t -s $'\t' $image_list_file
580 #Set the SIM_GROUP var
581 echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
582 if [ -z "$SIM_GROUP" ]; then
583 SIM_GROUP=$PWD/../simulator-group
584 if [ ! -d $SIM_GROUP ]; then
585 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
586 echo -e $RED"Please set the SIM_GROUP manually in the applicable $TEST_ENV_VAR_FILE"$ERED
589 echo " SIM_GROUP auto set to: " $SIM_GROUP
591 elif [ $SIM_GROUP = *simulator_group ]; then
592 echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check $TEST_ENV_VAR_FILE"$ERED
595 echo " SIM_GROUP env var already set to: " $SIM_GROUP
600 #Temp var to check for image pull errors
603 #Function to check if image exist and stop+remove the container+pull new images as needed
604 #args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
605 __check_and_pull_image() {
607 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
608 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
609 tmp_im=$(docker images --format $format_string ${4})
611 if [ $1 == "local" ]; then
612 if [ -z "$tmp_im" ]; then
613 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
617 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
619 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
620 if [ $1 == "remote-remove" ]; then
621 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
622 tmp="$(docker ps -aq --filter name=${3})"
623 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
624 docker stop $tmp &> ./tmp/.dockererr
625 if [ $? -ne 0 ]; then
628 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
633 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
634 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
635 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
636 docker rm $tmp &> ./tmp/.dockererr
637 if [ $? -ne 0 ]; then
640 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
645 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
646 echo -ne " Removing image - ${SAMELINE}"
647 tmp="$(docker images -q ${4})" &> /dev/null
648 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
649 docker rmi --force $4 &> ./tmp/.dockererr
650 if [ $? -ne 0 ]; then
653 echo -e $RED" Image could not be removed - try manual removal of the image"$ERED
657 echo -e " Removing image - "$GREEN"removed"$EGREEN
659 echo -e " Removing image - "$GREEN"image not in repository"$EGREEN
663 if [ -z "$tmp_im" ]; then
664 echo -ne " Pulling image${SAMELINE}"
665 docker pull $4 &> ./tmp/.dockererr
666 tmp_im=$(docker images ${4} | grep -v REPOSITORY)
667 if [ -z "$tmp_im" ]; then
669 echo -e " Pulling image -$RED could not be pulled"$ERED
674 echo -e " Pulling image -$GREEN Pulled $EGREEN"
676 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
683 echo -e $BOLD"Pulling configured images, if needed"$EBOLD
685 __check_included_image 'PA'
686 if [ $? -eq 0 ]; then
687 START_ARG_MOD=$START_ARG
688 __check_image_local_override 'PA'
689 if [ $? -eq 1 ]; then
690 START_ARG_MOD="local"
692 app="Policy Agent"; __check_and_pull_image $START_ARG_MOD "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
694 echo -e $YELLOW" Excluding PA image from image check/pull"$EYELLOW
697 __check_included_image 'ECS'
698 if [ $? -eq 0 ]; then
699 START_ARG_MOD=$START_ARG
700 __check_image_local_override 'ECS'
701 if [ $? -eq 1 ]; then
702 START_ARG_MOD="local"
704 app="ECS"; __check_and_pull_image $START_ARG_MOD "$app" $ECS_APP_NAME $ECS_IMAGE
706 echo -e $YELLOW" Excluding ECS image from image check/pull"$EYELLOW
709 __check_included_image 'CP'
710 if [ $? -eq 0 ]; then
711 START_ARG_MOD=$START_ARG
712 __check_image_local_override 'CP'
713 if [ $? -eq 1 ]; then
714 START_ARG_MOD="local"
716 app="Non-RT RIC Control Panel"; __check_and_pull_image $START_ARG_MOD "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
718 echo -e $YELLOW" Excluding Non-RT RIC Control Panel image from image check/pull"$EYELLOW
721 __check_included_image 'RICSIM'
722 if [ $? -eq 0 ]; then
723 START_ARG_MOD=$START_ARG
724 __check_image_local_override 'RICSIM'
725 if [ $? -eq 1 ]; then
726 START_ARG_MOD="local"
728 app="Near-RT RIC Simulator"; __check_and_pull_image $START_ARG_MOD "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
730 echo -e $YELLOW" Excluding Near-RT RIC Simulator image from image check/pull"$EYELLOW
734 __check_included_image 'CONSUL'
735 if [ $? -eq 0 ]; then
736 app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
738 echo -e $YELLOW" Excluding Consul image from image check/pull"$EYELLOW
741 __check_included_image 'CBS'
742 if [ $? -eq 0 ]; then
743 app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE
745 echo -e $YELLOW" Excluding CBS image from image check/pull"$EYELLOW
748 __check_included_image 'SDNC'
749 if [ $? -eq 0 ]; then
750 START_ARG_MOD=$START_ARG
751 __check_image_local_override 'SDNC'
752 if [ $? -eq 1 ]; then
753 START_ARG_MOD="local"
755 app="SDNC A1 Controller"; __check_and_pull_image $START_ARG_MOD "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
756 app="SDNC DB"; __check_and_pull_image $START_ARG "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
758 echo -e $YELLOW" Excluding SDNC image and related DB image from image check/pull"$EYELLOW
761 #Errors in image setting - exit
762 if [ $IMAGE_ERR -ne 0 ]; then
764 echo "#################################################################################################"
765 echo -e $RED"One or more images could not be pulled or containers using the images could not be stopped/removed"$ERED
766 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
767 echo "#################################################################################################"
774 echo -e $BOLD"Building images needed for test"$EBOLD
777 __check_included_image 'MR'
778 if [ $? -eq 0 ]; then
781 echo " Building mrstub image: $MRSTUB_LOCAL_IMAGE:$MRSTUB_LOCAL_IMAGE_TAG"
782 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $MRSTUB_LOCAL_IMAGE . &> .dockererr
783 if [ $? -eq 0 ]; then
784 echo -e $GREEN" Build Ok"$EGREEN
786 echo -e $RED" Build Failed"$ERED
789 echo -e $RED"Exiting...."$ERED
794 echo -e $YELLOW" Excluding mrstub from image build"$EYELLOW
797 __check_included_image 'CR'
798 if [ $? -eq 0 ]; then
800 echo " Building Callback Receiver image: $CR_LOCAL_IMAGE:$CR_IMAGE_TAG"
801 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $CR_LOCAL_IMAGE . &> .dockererr
802 if [ $? -eq 0 ]; then
803 echo -e $GREEN" Build Ok"$EGREEN
805 echo -e $RED" Build Failed"$ERED
808 echo -e $RED"Exiting...."$ERED
813 echo -e $YELLOW" Excluding Callback Receiver from image build"$EYELLOW
816 __check_included_image 'PRODSTUB'
817 if [ $? -eq 0 ]; then
819 echo " Building Producer stub image: $PROD_STUB_LOCAL_IMAGE:$PROD_STUB_LOCAL_IMAGE_TAG"
820 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $PROD_STUB_LOCAL_IMAGE . &> .dockererr
821 if [ $? -eq 0 ]; then
822 echo -e $GREEN" Build Ok"$EGREEN
824 echo -e $RED" Build Failed"$ERED
827 echo -e $RED"Exiting...."$ERED
832 echo -e $YELLOW" Excluding Producer stub from image build"$EYELLOW
837 # Create a table of the images used in the script
838 echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
840 docker_tmp_file=./tmp/.docker-images-table
841 format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\\t{{.CreatedAt}}"
842 echo -e " Application\tRepository\tTag\tCreated since\tSize\tCreated at" > $docker_tmp_file
843 __check_included_image 'PA'
844 if [ $? -eq 0 ]; then
845 echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
847 __check_included_image 'ECS'
848 if [ $? -eq 0 ]; then
849 echo -e " ECS\t$(docker images --format $format_string $ECS_IMAGE)" >> $docker_tmp_file
851 __check_included_image 'CP'
852 if [ $? -eq 0 ]; then
853 echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
855 __check_included_image 'RICSIM'
856 if [ $? -eq 0 ]; then
857 echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
859 __check_included_image 'MR'
860 if [ $? -eq 0 ]; then
861 echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
863 __check_included_image 'CR'
864 if [ $? -eq 0 ]; then
865 echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
867 __check_included_image 'PRODSTUB'
868 if [ $? -eq 0 ]; then
869 echo -e " Produccer stub\t$(docker images --format $format_string $PROD_STUB_IMAGE)" >> $docker_tmp_file
871 __check_included_image 'CONSUL'
872 if [ $? -eq 0 ]; then
873 echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
875 __check_included_image 'CBS'
876 if [ $? -eq 0 ]; then
877 echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
879 __check_included_image 'SDNC'
880 if [ $? -eq 0 ]; then
881 echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
882 echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
885 column -t -s $'\t' $docker_tmp_file
889 echo -e $BOLD"======================================================="$EBOLD
890 echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
891 echo -e $BOLD"======================================================="$EBOLD
894 # Function to print the test result, shall be the last cmd in a test script
896 # (Function for test scripts)
900 duration=$((TCTEST_END-TCTEST_START))
902 echo "-------------------------------------------------------------------------------------------------"
903 echo "------------------------------------- Test case: "$ATC
904 echo "------------------------------------- Ended: "$(date)
905 echo "-------------------------------------------------------------------------------------------------"
906 echo "-- Description: "$TC_ONELINE_DESCR
907 echo "-- Execution time: " $duration " seconds"
908 echo "-- Used env file: "$TEST_ENV_VAR_FILE
909 echo "-------------------------------------------------------------------------------------------------"
910 echo "------------------------------------- RESULTS"
914 if [ $RES_DEVIATION -gt 0 ]; then
915 echo "Test case deviations"
916 echo "===================================="
920 echo "Timer measurement in the test script"
921 echo "===================================="
922 column -t -s $'\t' $TIMER_MEASUREMENTS
925 total=$((RES_PASS+RES_FAIL))
926 if [ $RES_TEST -eq 0 ]; then
927 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
928 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
929 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
930 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
931 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
932 elif [ $total != $RES_TEST ]; then
933 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
934 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
935 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
936 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
937 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
938 elif [ $RES_CONF_FAIL -ne 0 ]; then
939 echo -e "\033[1mOne or more configure regest has failed. Check the script log....\033[0m"
940 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
941 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
942 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
943 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
944 elif [ $RES_PASS = $RES_TEST ]; then
945 echo -e "All tests \033[32m\033[1mPASS\033[0m"
946 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
947 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
948 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
949 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
952 # Update test suite counter
953 if [ -f .tmp_tcsuite_pass_ctr ]; then
954 tmpval=$(< .tmp_tcsuite_pass_ctr)
956 echo $tmpval > .tmp_tcsuite_pass_ctr
958 if [ -f .tmp_tcsuite_pass ]; then
959 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
961 #Create file with OK exit code
962 echo "0" > "$PWD/.result$ATC.txt"
964 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
965 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
966 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
967 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
968 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
970 # Update test suite counter
971 if [ -f .tmp_tcsuite_fail_ctr ]; then
972 tmpval=$(< .tmp_tcsuite_fail_ctr)
974 echo $tmpval > .tmp_tcsuite_fail_ctr
976 if [ -f .tmp_tcsuite_fail ]; then
977 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
981 echo "++++ Number of tests: "$RES_TEST
982 echo "++++ Number of passed tests: "$RES_PASS
983 echo "++++ Number of failed tests: "$RES_FAIL
985 echo "++++ Number of failed configs: "$RES_CONF_FAIL
987 echo "++++ Number of test case deviations: "$RES_DEVIATION
989 echo "------------------------------------- Test case complete ---------------------------------"
990 echo "-------------------------------------------------------------------------------------------------"
994 #####################################################################
995 ###### Functions for start, configuring, stoping, cleaning etc ######
996 #####################################################################
998 # Start timer for time measurement
999 # args - (any args will be printed though)
1001 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1003 echo " Timer started"
1006 # Print the value of the time (in seconds)
1007 # args - <timer message to print> - timer value and message will be printed both on screen
1008 # and in the timer measurement report
1010 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1011 if [ $# -lt 1 ]; then
1013 __print_err "need 1 or more args, <timer message to print>" $@
1016 duration=$(($SECONDS-$TC_TIMER))
1017 if [ $duration -eq 0 ]; then
1018 duration="<1 second"
1020 duration=$duration" seconds"
1022 echo " Timer duration :" $duration
1024 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
1027 # Print the value of the time (in seconds) and reset the timer
1028 # args - <timer message to print> - timer value and message will be printed both on screen
1029 # and in the timer measurement report
1030 print_and_reset_timer() {
1031 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1032 if [ $# -lt 1 ]; then
1034 __print_err "need 1 or more args, <timer message to print>" $@
1037 duration=$(($SECONDS-$TC_TIMER))" seconds"
1038 if [ $duration -eq 0 ]; then
1039 duration="<1 second"
1041 duration=$duration" seconds"
1043 echo " Timer duration :" $duration
1047 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
1050 # Print info about a deviations from intended tests
1051 # Each deviation counted is also printed in the testreport
1052 # args <deviation message to print>
1054 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
1055 if [ $# -lt 1 ]; then
1057 __print_err "need 1 or more args, <deviation message to print>" $@
1061 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
1062 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
1066 # Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
1067 __check_stop_at_error() {
1068 if [ $STOP_AT_ERROR -eq 1 ]; then
1069 echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
1070 store_logs "STOP_AT_ERROR"
1076 # Check if app name var is set. If so return the app name otherwise return "NOTSET"
1077 __check_app_name() {
1078 if [ $# -eq 1 ]; then
1085 # Stop and remove all containers
1087 # (Function for test scripts)
1088 clean_containers() {
1090 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
1092 CONTAINTER_NAMES=("Policy Agent " $(__check_app_name $POLICY_AGENT_APP_NAME)\
1093 "ECS " $(__check_app_name $ECS_APP_NAME)\
1094 "Non-RT RIC Simulator(s)" $(__check_app_name $RIC_SIM_PREFIX)\
1095 "Message Router " $(__check_app_name $MR_APP_NAME)\
1096 "Callback Receiver " $(__check_app_name $CR_APP_NAME)\
1097 "Producer stub " $(__check_app_name $PROD_STUB_APP_NAME)\
1098 "Control Panel " $(__check_app_name $CONTROL_PANEL_APP_NAME)\
1099 "SDNC A1 Controller " $(__check_app_name $SDNC_APP_NAME)\
1100 "SDNC DB " $(__check_app_name $SDNC_DB_APP_NAME)\
1101 "CBS " $(__check_app_name $CBS_APP_NAME)\
1102 "Consul " $(__check_app_name $CONSUL_APP_NAME))
1104 nw=0 # Calc max width of container name, to make a nice table
1105 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
1107 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
1108 nw=${#CONTAINTER_NAMES[i]}
1112 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
1113 APP="${CONTAINTER_NAMES[i]}"
1114 CONTR="${CONTAINTER_NAMES[i+1]}"
1115 if [ $CONTR != "NOTSET" ]; then
1116 for((w=${#CONTR}; w<$nw; w=w+1)); do
1119 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
1120 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1121 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
1122 docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1123 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
1129 echo -e $BOLD" Removing docker network"$EBOLD
1130 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
1131 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
1132 docker network rm $DOCKER_SIM_NWNAME | indent2
1133 if [ $? -ne 0 ]; then
1134 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
1138 echo -e "$GREEN Done$EGREEN"
1140 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
1141 docker network prune --force | indent2
1142 echo -e "$GREEN Done$EGREEN"
1144 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
1145 docker volume prune --force | indent2
1146 echo -e "$GREEN Done$EGREEN"
1148 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
1149 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
1150 echo -e "$GREEN Done$EGREEN"
1153 CONTRS=$(docker ps | awk '$1 != "CONTAINER" { n++ }; END { print n+0 }')
1154 if [ $? -eq 0 ]; then
1155 if [ $CONTRS -ne 0 ]; then
1156 echo -e $RED"Containers running, may cause distubance to the test case"$ERED
1157 docker ps -a | indent1
1163 # Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
1165 # (Function for test scripts)
1166 auto_clean_containers() {
1168 if [ "$AUTO_CLEAN" == "auto" ]; then
1169 echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
1174 # Function to sleep a test case for a numner of seconds. Prints the optional text args as info
1175 # args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
1176 # (Function for test scripts)
1179 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1180 if [ $# -lt 1 ]; then
1182 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
1185 #echo "---- Sleep for " $1 " seconds ---- "$2
1187 duration=$((SECONDS-start))
1188 while [ $duration -lt $1 ]; do
1189 echo -ne " Slept for ${duration} seconds${SAMELINE}"
1191 duration=$((SECONDS-start))
1193 echo -ne " Slept for ${duration} seconds${SAMELINE}"
1197 # Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
1198 # Not to be called from the test script itself.
1200 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
1201 if [ $# -gt 1 ]; then
1202 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
1208 # Helper function to get a the port of a specific ric simulatpor
1210 # (Not for test scripts)
1212 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
1213 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
1215 if [[ "$res" =~ ^[0-9]+$ ]]; then
1222 # Function to create the docker network for the test
1223 # Not to be called from the test script itself.
1224 __create_docker_network() {
1225 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
1226 if [ $? -ne 0 ]; then
1227 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
1230 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
1231 echo -e " Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
1232 docker network create $DOCKER_SIM_NWNAME | indent2
1233 if [ $? -ne 0 ]; then
1234 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
1237 echo -e "$GREEN Done$EGREEN"
1240 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
1244 # Check if container is started by calling url on localhost using a port, expects response code 2XX
1245 # args: <container-name> <port> <url> https|https
1246 # Not to be called from the test script itself.
1247 __check_container_start() {
1249 if [ $# -ne 4 ]; then
1251 elif [ $4 != "http" ] && [ $4 != "https" ]; then
1254 if [ $paramError -ne 0 ]; then
1256 __print_err "need 3 args, <container-name> <port> <url> https|https" $@
1259 echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
1263 if [[ $appname != "STANDALONE_"* ]] ; then
1265 for i in {1..10}; do
1266 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
1267 echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
1274 if [ $app_started -eq 0 ]; then
1277 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
1278 echo -e $RED" Stopping script..."$ERED
1281 if [ $localport -eq 0 ]; then
1282 while [ $localport -eq 0 ]; do
1283 echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
1284 localport=$(__find_sim_port $appname)
1286 echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
1288 echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
1294 echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
1296 for i in {1..50}; do
1297 if [ $4 == "https" ]; then
1298 result="$(__do_curl "-k https://localhost:"${localport}${url})"
1300 result="$(__do_curl $LOCALHOST${localport}${url})"
1302 if [ $? -eq 0 ]; then
1303 if [ ${#result} -gt 15 ]; then
1304 #If response is too long, truncate
1305 result="...response text too long, omitted"
1307 echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
1308 echo -ne " Container $BOLD${appname}$EBOLD$GREEN is alive$EGREEN, responds to service status:$GREEN $result $EGREEN after $(($SECONDS-$TSTART)) seconds"
1313 while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
1314 echo -ne " Waiting for container ${appname} service status...$(($SECONDS-$TSTART)) seconds, retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
1320 if [ "$pa_st" = "false" ]; then
1322 echo -e $RED" Container ${appname} did not respond to service status in $(($SECONDS-$TSTART)) seconds"$ERED
1331 # Function to start a container and wait until it responds on the given port and url.
1332 #args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
1333 __start_container() {
1335 variableArgCount=$(($#-2))
1336 if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
1338 __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 ]*" $@
1342 __create_docker_network
1348 if [ "$2" == "NODOCKERARGS" ]; then
1349 docker-compose up -d &> .dockererr
1350 if [ $? -ne 0 ]; then
1351 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1353 echo -e $RED"Stopping script...."$ERED
1356 elif [ "$2" == "STANDALONE" ]; then
1357 echo "Skipping docker-compose"
1359 docker-compose up -d $2 &> .dockererr
1360 if [ $? -ne 0 ]; then
1361 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1363 echo -e $RED"Stopping script...."$ERED
1368 if [ "$2" == "STANDALONE" ]; then
1369 app_prefix="STANDALONE_"
1373 while [ $cntr -lt $variableArgCount ]; do
1374 app=$app_prefix$1; shift;
1380 __check_container_start "$app" "$port" "$url" $httpx
1388 # Generate a UUID to use as prefix for policy ids
1390 UUID=$(python3 -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
1391 #Reduce length to make space for serial id, us 'a' as marker where the serial id is added
1392 UUID=${UUID:0:${#UUID}-4}"a"
1395 ####################
1396 ### Consul functions
1397 ####################
1399 # Function to load config from a file into consul for the Policy Agent
1400 # arg: <json-config-file>
1401 # (Function for test scripts)
1402 consul_config_app() {
1404 echo -e $BOLD"Configuring Consul"$EBOLD
1406 if [ $# -ne 1 ]; then
1408 __print_err "need one arg, <json-config-file>" $@
1412 echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1
1414 curlString="$LOCALHOST${CONSUL_EXTERNAL_PORT}/v1/kv/${POLICY_AGENT_APP_NAME}?dc=dc1 -X PUT -H Accept:application/json -H Content-Type:application/json -H X-Requested-With:XMLHttpRequest --data-binary @"$1
1415 result=$(__do_curl "$curlString")
1416 if [ $? -ne 0 ]; then
1417 echo -e $RED" FAIL - json config could not be loaded to consul" $ERED
1421 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
1422 echo $body > "./tmp/.output"$1
1424 if [ $? -ne 0 ]; then
1425 echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED
1430 targetJson="{\"config\":"$targetJson"}"
1431 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1432 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1433 if [ $res -ne 0 ]; then
1434 echo -e $RED" FAIL - policy json config read from consul/cbs is not equal to the intended json config...." $ERED
1438 echo -e $GREEN" Config loaded ok to consul"$EGREEN
1446 # Function to perpare the consul configuration according to the current simulator configuration
1447 # args: SDNC|NOSDNC <output-file>
1448 # (Function for test scripts)
1449 prepare_consul_config() {
1450 echo -e $BOLD"Prepare Consul config"$EBOLD
1452 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
1454 if [ $# != 2 ]; then
1456 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
1460 if [ $1 == "SDNC" ]; then
1461 echo -e " Config$BOLD including SDNC$EBOLD configuration"
1462 elif [ $1 == "NOSDNC" ]; then
1463 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
1466 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
1471 if [ $1 == "SDNC" ]; then
1472 config_json=$config_json"\n \"controller\": ["
1473 config_json=$config_json"\n {"
1474 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
1475 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1476 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://$SDNC_APP_NAME:$SDNC_PORT\","
1478 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://localhost:$SDNC_LOCAL_PORT\","
1480 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
1481 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
1482 config_json=$config_json"\n }"
1483 config_json=$config_json"\n ],"
1486 config_json=$config_json"\n \"streams_publishes\": {"
1487 config_json=$config_json"\n \"dmaap_publisher\": {"
1488 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1489 config_json=$config_json"\n \"dmaap_info\": {"
1490 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1491 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_WRITE_URL\""
1493 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_WRITE_URL\""
1495 config_json=$config_json"\n }"
1496 config_json=$config_json"\n }"
1497 config_json=$config_json"\n },"
1498 config_json=$config_json"\n \"streams_subscribes\": {"
1499 config_json=$config_json"\n \"dmaap_subscriber\": {"
1500 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1501 config_json=$config_json"\n \"dmaap_info\": {"
1502 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1503 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_READ_URL\""
1505 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_READ_URL\""
1507 config_json=$config_json"\n }"
1508 config_json=$config_json"\n }"
1509 config_json=$config_json"\n },"
1511 config_json=$config_json"\n \"ric\": ["
1513 rics=$(docker ps | grep $RIC_SIM_PREFIX | awk '{print $NF}')
1515 if [ $? -ne 0 ] || [ -z "$rics" ]; then
1516 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
1522 for ric in $rics; do
1523 if [ $cntr -gt 0 ]; then
1524 config_json=$config_json"\n ,"
1526 config_json=$config_json"\n {"
1527 config_json=$config_json"\n \"name\": \"$ric\","
1528 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1529 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
1531 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://localhost:$(__find_sim_port $ric)\","
1533 if [ $1 == "SDNC" ]; then
1534 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
1536 config_json=$config_json"\n \"managedElementIds\": ["
1537 config_json=$config_json"\n \"me1_$ric\","
1538 config_json=$config_json"\n \"me2_$ric\""
1539 config_json=$config_json"\n ]"
1540 config_json=$config_json"\n }"
1544 config_json=$config_json"\n ]"
1545 config_json=$config_json"\n}"
1548 printf "$config_json">$2
1554 # Start Consul and CBS
1556 # (Function for test scripts)
1557 start_consul_cbs() {
1559 echo -e $BOLD"Starting Consul and CBS"$EBOLD
1560 __check_included_image 'CONSUL'
1561 if [ $? -eq 1 ]; then
1562 echo -e $RED"The Consul image has not been checked for this test run due to arg to the test script"$ERED
1563 echo -e $RED"Consul will not be started"$ERED
1566 __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" "http" \
1567 "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck" "http"
1570 ###########################
1571 ### RIC Simulator functions
1572 ###########################
1574 use_simulator_http() {
1575 echo -e $BOLD"RICSIM protocol setting"$EBOLD
1576 echo -e " Using $BOLD http $EBOLD towards the simulators"
1577 export RIC_SIM_HTTPX="http"
1578 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1579 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
1583 use_simulator_https() {
1584 echo -e $BOLD"RICSIM protocol setting"$EBOLD
1585 echo -e " Using $BOLD https $EBOLD towards the simulators"
1586 export RIC_SIM_HTTPX="https"
1587 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1588 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
1592 # Start one group (ricsim_g1, ricsim_g2 .. ricsim_g5) with a number of RIC Simulators using a given A interface
1593 # 'ricsim' may be set on command line to other prefix
1594 # args: ricsim_g1|ricsim_g2|ricsim_g3|ricsim_g4|ricsim_g5 <count> <interface-id>
1595 # (Function for test scripts)
1596 start_ric_simulators() {
1598 echo -e $BOLD"Starting RIC Simulators"$EBOLD
1600 __check_included_image 'RICSIM'
1601 if [ $? -eq 1 ]; then
1602 echo -e $RED"The Near-RT RIC Simulator image has not been checked for this test run due to arg to the test script"$ERED
1603 echo -e $RED"The Near-RT RIC Simulartor(s) will not be started"$ERED
1607 RIC1=$RIC_SIM_PREFIX"_g1"
1608 RIC2=$RIC_SIM_PREFIX"_g2"
1609 RIC3=$RIC_SIM_PREFIX"_g3"
1610 RIC4=$RIC_SIM_PREFIX"_g4"
1611 RIC5=$RIC_SIM_PREFIX"_g5"
1613 if [ $# != 3 ]; then
1615 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
1618 echo " $2 simulators using basename: $1 on interface: $3"
1619 #Set env var for simulator count and A1 interface vesion for the given group
1620 if [ $1 == "$RIC1" ]; then
1623 elif [ $1 == "$RIC2" ]; then
1626 elif [ $1 == "$RIC3" ]; then
1629 elif [ $1 == "$RIC4" ]; then
1632 elif [ $1 == "$RIC5" ]; then
1637 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
1641 # Create .env file to compose project, all ric container will get this prefix
1642 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
1644 export G1_A1_VERSION
1645 export G2_A1_VERSION
1646 export G3_A1_VERSION
1647 export G4_A1_VERSION
1648 export G5_A1_VERSION
1650 docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT --scale g4=$G4_COUNT --scale g5=$G5_COUNT"
1653 while [ $cntr -le $2 ]; do
1656 app_data="$app_data $app $port / "$RIC_SIM_HTTPX
1659 __start_container ric "$docker_args" $app_data
1663 ###########################
1664 ### Control Panel functions
1665 ###########################
1667 # Start the Control Panel container
1669 # (Function for test scripts)
1670 start_control_panel() {
1672 echo -e $BOLD"Starting Control Panel"$EBOLD
1673 __check_included_image 'CP'
1674 if [ $? -eq 1 ]; then
1675 echo -e $RED"The Control Panel image has not been checked for this test run due to arg to the test script"$ERED
1676 echo -e $RED"The Control Panel will not be started"$ERED
1679 __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/" "http"
1687 # Start the SDNC A1 Controller
1689 # (Function for test scripts)
1692 echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
1694 __check_included_image 'SDNC'
1695 if [ $? -eq 1 ]; then
1696 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
1697 echo -e $RED"SDNC will not be started"$ERED
1701 __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT $SDNC_ALIVE_URL "http"
1706 echo -e $BOLD"SDNC protocol setting"$EBOLD
1707 echo -e " Using $BOLD http $EBOLD towards SDNC"
1708 export SDNC_HTTPX="http"
1709 export SDNC_PORT=$SDNC_INTERNAL_PORT
1710 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT
1715 echo -e $BOLD"SDNC protocol setting"$EBOLD
1716 echo -e " Using $BOLD https $EBOLD towards SDNC"
1717 export SDNC_HTTPX="https"
1718 export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT
1719 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT
1723 #####################
1724 ### MR stub functions
1725 #####################
1727 # Start the Message Router stub interface in the simulator group
1729 # (Function for test scripts)
1732 echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
1733 __check_included_image 'MR'
1734 if [ $? -eq 1 ]; then
1735 echo -e $RED"The Message Router image has not been checked for this test run due to arg to the test script"$ERED
1736 echo -e $RED"The Message Router will not be started"$ERED
1739 export MR_CERT_MOUNT_DIR="./cert"
1740 __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/" "http"
1744 echo -e $BOLD"MR protocol setting"$EBOLD
1745 echo -e " Using $BOLD http $EBOLD towards MR"
1746 export MR_HTTPX="http"
1747 export MR_PORT=$MR_INTERNAL_PORT
1748 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT
1753 echo -e $BOLD"MR protocol setting"$EBOLD
1754 echo -e " Using $BOLD https $EBOLD towards MR"
1755 export MR_HTTPX="https"
1756 export MR_PORT=$MR_INTERNAL_SECURE_PORT
1757 export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT
1766 # Start the Callback reciver in the simulator group
1768 # (Function for test scripts)
1771 echo -e $BOLD"Starting Callback Receiver"$EBOLD
1772 __check_included_image 'CR'
1773 if [ $? -eq 1 ]; then
1774 echo -e $RED"The Callback Receiver image has not been checked for this test run due to arg to the test script"$ERED
1775 echo -e $RED"The Callback Receiver will not be started"$ERED
1778 __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/" "http"
1783 echo -e $BOLD"CR protocol setting"$EBOLD
1784 echo -e " Using $BOLD http $EBOLD towards CR"
1785 export CR_HTTPX="http"
1786 export CR_PORT=$CR_INTERNAL_PORT
1787 export CR_LOCAL_PORT=$CR_EXTERNAL_PORT
1788 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
1793 echo -e $BOLD"CR protocol setting"$EBOLD
1794 echo -e " Using $BOLD https $EBOLD towards CR"
1795 export CR_HTTPX="https"
1796 export CR_PORT=$CR_INTERNAL_SECURE_PORT
1797 export CR_LOCAL_PORT=$CR_EXTERNAL_SECURE_PORT
1798 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
1802 ###########################
1803 ### Producer stub functions
1804 ###########################
1806 # Start the Producer stub in the simulator group
1808 # (Function for test scripts)
1811 echo -e $BOLD"Starting Producer stub"$EBOLD
1812 __check_included_image 'PRODSTUB'
1813 if [ $? -eq 1 ]; then
1814 echo -e $RED"The Producer stub image has not been checked for this test run due to arg to the test script"$ERED
1815 echo -e $RED"The Producer stub will not be started"$ERED
1818 __start_container prodstub NODOCKERARGS $PROD_STUB_APP_NAME $PROD_STUB_EXTERNAL_PORT "/" "http"
1822 use_prod_stub_http() {
1823 echo -e $BOLD"Producer stub protocol setting"$EBOLD
1824 echo -e " Using $BOLD http $EBOLD towards Producer stub"
1825 export PROD_STUB_HTTPX="http"
1826 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
1827 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT
1828 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
1832 use_prod_stub_https() {
1833 echo -e $BOLD"Producer stub protocol setting"$EBOLD
1834 echo -e " Using $BOLD https $EBOLD towards Producer stub"
1835 export PROD_STUB_HTTPX="https"
1836 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_SECURE_PORT
1837 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_SECURE_PORT
1838 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
1842 ###########################
1843 ### Policy Agents functions
1844 ###########################
1846 # Use an agent on the local machine instead of container
1847 use_agent_stand_alone() {
1851 # Start the policy agent
1853 # (Function for test scripts)
1854 start_policy_agent() {
1856 echo -e $BOLD"Starting Policy Agent"$EBOLD
1858 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1859 __check_included_image 'PA'
1860 if [ $? -eq 1 ]; then
1861 echo -e $RED"The Policy Agent image has not been checked for this test run due to arg to the test script"$ERED
1862 echo -e $RED"The Policy Agent will not be started"$ERED
1865 __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1867 echo -e $RED"The consul config produced by this test script (filename '<fullpath-to-autotest-dir>.output<file-name>"$ERED
1868 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
1869 echo -e $RED"application.yaml"$ERED
1870 echo -e $RED"The application jar may need to be built before continuing"$ERED
1871 echo -e $RED"The agent shall now be running on port $POLICY_AGENT_EXTERNAL_PORT for http"$ERED
1873 read -p "<press any key to continue>"
1874 __start_container policy_agent "STANDALONE" $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1879 # All calls to the agent will be directed to the agent REST interface from now on
1881 # (Function for test scripts)
1882 use_agent_rest_http() {
1883 echo -e $BOLD"Agent protocol setting"$EBOLD
1884 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
1885 export ADAPTER=$RESTBASE
1889 # All calls to the agent will be directed to the agent REST interface from now on
1891 # (Function for test scripts)
1892 use_agent_rest_https() {
1893 echo -e $BOLD"Agent protocol setting"$EBOLD
1894 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
1895 export ADAPTER=$RESTBASE_SECURE
1900 # All calls to the agent will be directed to the agent dmaap interface over http from now on
1902 # (Function for test scripts)
1903 use_agent_dmaap_http() {
1904 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
1905 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
1906 export ADAPTER=$DMAAPBASE
1911 # All calls to the agent will be directed to the agent dmaap interface over https from now on
1913 # (Function for test scripts)
1914 use_agent_dmaap_https() {
1915 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
1916 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
1917 export ADAPTER=$DMAAPBASE_SECURE
1922 # Turn on debug level tracing in the agent
1924 # (Function for test scripts)
1926 echo -e $BOLD"Setting agent debug logging"$EBOLD
1927 actuator="/actuator/loggers/org.oransc.policyagent"
1928 if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
1929 actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
1931 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
1932 result=$(__do_curl "$curlString")
1933 if [ $? -ne 0 ]; then
1934 __print_err "could not set debug mode" $@
1942 # Turn on trace level tracing in the agent
1944 # (Function for test scripts)
1946 echo -e $BOLD"Setting agent trace logging"$EBOLD
1947 actuator="/actuator/loggers/org.oransc.policyagent"
1948 if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
1949 actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
1951 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
1952 result=$(__do_curl "$curlString")
1953 if [ $? -ne 0 ]; then
1954 __print_err "could not set trace mode" $@
1962 # Perform curl retries when making direct call to the agent for the specified http response codes
1963 # Speace separated list of http response codes
1964 # args: [<response-code>]*
1965 use_agent_retries() {
1966 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
1967 AGENT_RETRY_CODES=$@
1972 ###########################
1974 ###########################
1978 # (Function for test scripts)
1981 echo -e $BOLD"Starting ECS"$EBOLD
1986 cd $ECS_HOST_MNT_DIR
1987 if [ -d database ]; then
1988 if [ "$(ls -A $DIR)" ]; then
1989 echo -e $BOLD" Cleaning files in mounted dir: $PWD/database"$EBOLD
1990 rm -rf database/* &> /dev/null
1991 if [ $? -ne 0 ]; then
1992 echo -e $RED" Cannot remove database files in: $PWD"$ERED
1997 echo " No files in mounted dir or dir does not exists"
2001 __check_included_image 'ECS'
2002 if [ $? -eq 1 ]; then
2003 echo -e $RED"The ECS image has not been checked for this test run due to arg to the test script"$ERED
2004 echo -e $RED"ECS will not be started"$ERED
2007 export ECS_CERT_MOUNT_DIR="./cert"
2008 __start_container ecs NODOCKERARGS $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
2013 # (Function for test scripts)
2015 echo -e $BOLD"Re-starting ECS"$EBOLD
2016 docker restart $ECS_APP_NAME &> ./tmp/.dockererr
2017 if [ $? -ne 0 ]; then
2018 __print_err "Could restart $ECS_APP_NAME" $@
2019 cat ./tmp/.dockererr
2024 __check_container_start $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
2029 # All calls to ECS will be directed to the ECS REST interface from now on
2031 # (Function for test scripts)
2032 use_ecs_rest_http() {
2033 echo -e $BOLD"ECS protocol setting"$EBOLD
2034 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
2035 export ECS_ADAPTER=$ECS_RESTBASE
2039 # All calls to ECS will be directed to the ECS REST interface from now on
2041 # (Function for test scripts)
2042 use_ecs_rest_https() {
2043 echo -e $BOLD"ECS protocol setting"$EBOLD
2044 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
2045 export ECS_ADAPTER=$ECS_RESTBASE_SECURE
2050 # All calls to ECS will be directed to the ECS dmaap interface over http from now on
2052 # (Function for test scripts)
2053 use_ecs_dmaap_http() {
2054 echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
2055 echo -e $RED" - NOT SUPPORTED - "$ERED
2056 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
2057 export ECS_ADAPTER=$ECS_DMAAPBASE
2062 # All calls to ECS will be directed to the ECS dmaap interface over https from now on
2064 # (Function for test scripts)
2065 use_ecs_dmaap_https() {
2066 echo -e $BOLD"RICSIM protocol setting"$EBOLD
2067 echo -e $RED" - NOT SUPPORTED - "$ERED
2068 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
2069 export ECS_ADAPTER=$ECS_DMAAPBASE_SECURE
2074 # Turn on debug level tracing in ECS
2076 # (Function for test scripts)
2078 echo -e $BOLD"Setting ecs debug logging"$EBOLD
2079 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
2080 result=$(__do_curl "$curlString")
2081 if [ $? -ne 0 ]; then
2082 __print_err "Could not set debug mode" $@
2090 # Turn on trace level tracing in ECS
2092 # (Function for test scripts)
2094 echo -e $BOLD"Setting ecs trace logging"$EBOLD
2095 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
2096 result=$(__do_curl "$curlString")
2097 if [ $? -ne 0 ]; then
2098 __print_err "Could not set trace mode" $@
2106 # Perform curl retries when making direct call to ECS for the specified http response codes
2107 # Speace separated list of http response codes
2108 # args: [<response-code>]*
2109 use_agent_retries() {
2110 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
2111 ECS_AGENT_RETRY_CODES=$@
2120 # Check the agent logs for WARNINGs and ERRORs
2122 # (Function for test scripts)
2124 check_policy_agent_logs() {
2125 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
2129 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
2132 check_control_panel_logs() {
2133 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH WARN ERR
2137 __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
2140 __check_container_logs() {
2147 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
2149 #tmp=$(docker ps | grep $appname)
2150 tmp=$(docker ps -q --filter name=$appname) #get the container id
2151 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
2152 echo $dispname" is not running, no check made"
2155 foundentries="$(docker exec -t $tmp grep $warning $logpath | wc -l)"
2156 if [ $? -ne 0 ];then
2157 echo " Problem to search $appname log $logpath"
2159 if [ $foundentries -eq 0 ]; then
2160 echo " No WARN entries found in $appname log $logpath"
2162 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
2165 foundentries="$(docker exec -t $tmp grep $error $logpath | wc -l)"
2166 if [ $? -ne 0 ];then
2167 echo " Problem to search $appname log $logpath"
2169 if [ $foundentries -eq 0 ]; then
2170 echo " No ERR entries found in $appname log $logpath"
2172 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
2178 # Store all container logs and other logs in the log dir for the script
2179 # Logs are stored with a prefix in case logs should be stored several times during a test
2180 # args: <logfile-prefix>
2181 # (Function for test scripts)
2183 if [ $# != 1 ]; then
2185 __print_err "need one arg, <file-prefix>" $@
2188 echo -e $BOLD"Storing all container logs in $TESTLOGS/$ATC using prefix: "$1$EBOLD
2190 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
2192 __check_included_image 'CONSUL'
2193 if [ $? -eq 0 ]; then
2194 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
2197 __check_included_image 'CBS'
2198 if [ $? -eq 0 ]; then
2199 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
2200 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
2201 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
2204 __check_included_image 'PA'
2205 if [ $? -eq 0 ]; then
2206 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
2209 __check_included_image 'ECS'
2210 if [ $? -eq 0 ]; then
2211 docker logs $ECS_APP_NAME > $TESTLOGS/$ATC/$1_ecs.log 2>&1
2214 __check_included_image 'CP'
2215 if [ $? -eq 0 ]; then
2216 docker logs $CONTROL_PANEL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
2219 __check_included_image 'MR'
2220 if [ $? -eq 0 ]; then
2221 docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
2224 __check_included_image 'CR'
2225 if [ $? -eq 0 ]; then
2226 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
2229 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
2231 __check_included_image 'SDNC'
2232 if [ $? -eq 0 ]; then
2233 docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
2236 __check_included_image 'RICSIM'
2237 if [ $? -eq 0 ]; then
2238 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
2239 for ric in $rics; do
2240 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
2244 __check_included_image 'PRODSTUB'
2245 if [ $? -eq 0 ]; then
2246 docker logs $PROD_STUB_APP_NAME > $TESTLOGS/$ATC/$1_prodstub.log 2>&1
2255 # Generic curl function, assumes all 200-codes are ok
2256 # args: <valid-curl-args-including full url>
2257 # returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
2258 # returns: The return code is 0 for ok and 1 for not ok
2260 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
2261 curlString="curl -skw %{http_code} $@"
2262 echo " CMD: $curlString" >> $HTTPLOG
2264 echo " RESP: $res" >> $HTTPLOG
2265 http_code="${res:${#res}-3}"
2266 if [ ${#res} -eq 3 ]; then
2267 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2268 echo "<no-response-from-server>"
2274 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2275 echo "<not found, resp:${http_code}>"
2278 if [ $# -eq 2 ]; then
2279 echo "${res:0:${#res}-3}" | xargs
2281 echo "${res:0:${#res}-3}"
2288 #######################################
2289 ### Basic helper function for test cases
2290 #######################################
2292 # Test a simulator container variable value towards target value using an condition operator with an optional timeout.
2293 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
2294 # immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
2295 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
2296 # before setting pass or fail depending on the result of comparing variable and target using the operator.
2297 # 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.
2298 # Not to be called from test script.
2301 checkjsonarraycount=0
2303 if [ $# -eq 6 ]; then
2304 if [[ $3 == "json:"* ]]; then
2305 checkjsonarraycount=1
2308 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
2310 ((TEST_SEQUENCE_NR++))
2314 if [ $checkjsonarraycount -eq 0 ]; then
2315 result="$(__do_curl $2$3)"
2317 result=${result//[[:blank:]]/} #Strip blanks
2320 result="$(__do_curl $2$path)"
2322 echo "$result" > ./tmp/.tmp.curl.json
2323 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
2325 duration=$((SECONDS-start))
2326 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
2328 if [ $retcode -ne 0 ]; then
2329 if [ $duration -gt $6 ]; then
2331 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
2332 __check_stop_at_error
2335 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2337 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2338 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2340 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2342 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2343 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2345 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2347 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2348 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2350 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2352 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2353 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2356 if [ $duration -gt $6 ]; then
2358 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
2359 __check_stop_at_error
2365 elif [ $# -eq 5 ]; then
2366 if [[ $3 == "json:"* ]]; then
2367 checkjsonarraycount=1
2370 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
2372 ((TEST_SEQUENCE_NR++))
2373 if [ $checkjsonarraycount -eq 0 ]; then
2374 result="$(__do_curl $2$3)"
2376 result=${result//[[:blank:]]/} #Strip blanks
2379 result="$(__do_curl $2$path)"
2381 echo "$result" > ./tmp/.tmp.curl.json
2382 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
2384 if [ $retcode -ne 0 ]; then
2386 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
2387 __check_stop_at_error
2388 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2390 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2391 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2393 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2394 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2396 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2397 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2399 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2402 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
2403 __check_stop_at_error
2406 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
2413 ### Generic test cases for varaible checking
2415 # Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
2416 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2417 # equal to the target or not.
2418 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2419 # before setting pass or fail depending on if the variable value becomes equal to the target
2421 # (Function for test scripts)
2423 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2424 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
2427 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2431 # Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
2432 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2433 # greater than the target or not.
2434 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2435 # before setting pass or fail depending on if the variable value becomes greater than the target
2437 # (Function for test scripts)
2439 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2440 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 ">" $2 $3
2443 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2447 # Read a variable value from MR sim and send to stdout. Arg: <variable-name>
2449 echo "$(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"
2452 # Print a variable value from the MR stub.
2453 # arg: <variable-name>
2454 # (Function for test scripts)
2456 if [ $# != 1 ]; then
2458 __print_err "need one arg, <mr-param>" $@
2461 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"$EBOLD