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 RC"
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, setting 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 Prodstub 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 export RAPP_CAT_HTTPX="http"
416 export RAPP_CAT_PORT=$RAPP_CAT_INTERNAL_PORT
417 export RAPP_CAT_LOCAL_PORT=$RAPP_CAT_EXTERNAL_PORT #When Rapp catalogue is running outside the docker net
419 echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
421 #Temp var to check for image variable name errors
423 #Create a file with image info for later printing as a table
424 image_list_file="./tmp/.image-list"
425 echo -e " Container\tImage\ttag" > $image_list_file
427 # Check if image env var is set and if so export the env var with image to use (used by docker compose files)
428 # arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name> <app-short-name>
429 __check_image_var() {
430 if [ $# -ne 6 ]; then
431 echo "Expected arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name> <app-short-name>"
435 __check_included_image $6
436 if [ $? -ne 0 ]; then
437 echo -e "$1\t<image-excluded>\t<no-tag>" >> $image_list_file
438 # Image is excluded since the corresponding app is not used in this test
442 #Create var from the input var names
446 if [ -z $image ]; then
447 echo -e $RED"\$"$4" not set in $TEST_ENV_VAR_FILE"$ERED
450 tmp=$tmp"<no-image>\t"
455 echo -e $RED"\$"$5" not set in $TEST_ENV_VAR_FILE"$ERED
462 echo -e "$tmp" >> $image_list_file
464 export "${3}"=$image":"$tag
466 #echo " Configured image for ${1} (script start arg=${2}): "$image":"$tag
470 #Check if app local image shall override remote image
471 # Possible IDs for local image override: PA, CP, SDNC, RICSIM, ECS
472 __check_image_local_override() {
473 for im in $USE_LOCAL_IMAGES; do
474 if [ "$1" == "$im" ]; then
481 # Check if app uses image included in this test run
482 # Returns 0 if image is included, 1 if not
483 # Possible IDs for image inclusion: CBS, CONSUL, CP, CR, ECS, MR, PA, PRODSTUB, RICSIM, SDNC
484 __check_included_image() {
485 for im in $INCLUDED_IMAGES; do
486 if [ "$1" == "$im" ]; then
493 # Check that image env setting are available
496 if [ $START_ARG == "local" ]; then
499 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG" PA
501 #Local Control Panel image
502 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG" CP
505 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG" SDNC
508 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG" RICSIM
510 elif [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
512 __check_image_local_override 'PA'
513 if [ $? -eq 0 ]; then
515 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_REMOTE_IMAGE" "POLICY_AGENT_REMOTE_IMAGE_TAG" PA
518 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG" PA
521 __check_image_local_override 'CP'
522 if [ $? -eq 0 ]; then
523 #Remote Control Panel image
524 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE_TAG" CP
526 #Local Control Panel image
527 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG" CP
530 __check_image_local_override 'SDNC'
531 if [ $? -eq 0 ]; then
533 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE_TAG" SDNC
536 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG" SDNC
539 __check_image_local_override 'RICSIM'
540 if [ $? -eq 0 ]; then
541 #Remote ric sim image
542 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_REMOTE_IMAGE" "RIC_SIM_REMOTE_IMAGE_TAG" RICSIM
545 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG" RICSIM
548 __check_image_local_override 'ECS'
549 if [ $? -eq 0 ]; then
551 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_REMOTE_IMAGE" "ECS_REMOTE_IMAGE_TAG" ECS
554 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_LOCAL_IMAGE" "ECS_LOCAL_IMAGE_TAG" ECS
557 __check_image_local_override 'RC'
558 if [ $? -eq 0 ]; then
560 __check_image_var " RC" $START_ARG "RAPP_CAT_IMAGE" "RAPP_CAT_REMOTE_IMAGE" "RAPP_CAT_REMOTE_IMAGE_TAG" RC
563 __check_image_var " RC" $START_ARG "RAPP_CAT_IMAGE" "RAPP_CAT_LOCAL_IMAGE" "RAPP_CAT_LOCAL_IMAGE_TAG" RC
567 #Should never get here....
568 echo "Unknow args: "$@
573 # These images are not built as part of this project official images, just check that env vars are set correctly
574 __check_image_var " Message Router" $START_ARG "MRSTUB_IMAGE" "MRSTUB_LOCAL_IMAGE" "MRSTUB_LOCAL_IMAGE_TAG" MR
575 __check_image_var " Callback Receiver" $START_ARG "CR_IMAGE" "CR_LOCAL_IMAGE" "CR_LOCAL_IMAGE_TAG" CR
576 __check_image_var " Producer stub" $START_ARG "PROD_STUB_IMAGE" "PROD_STUB_LOCAL_IMAGE" "PROD_STUB_LOCAL_IMAGE_TAG" PRODSTUB
577 __check_image_var " Consul" $START_ARG "CONSUL_IMAGE" "CONSUL_REMOTE_IMAGE" "CONSUL_REMOTE_IMAGE_TAG" CONSUL
578 __check_image_var " CBS" $START_ARG "CBS_IMAGE" "CBS_REMOTE_IMAGE" "CBS_REMOTE_IMAGE_TAG" CBS
579 __check_image_var " SDNC DB" $START_ARG "SDNC_DB_IMAGE" "SDNC_DB_REMOTE_IMAGE" "SDNC_DB_REMOTE_IMAGE_TAG" SDNC #Uses sdnc app name
581 #Errors in image setting - exit
582 if [ $IMAGE_ERR -ne 0 ]; then
586 #Print a tables of the image settings
587 echo -e $BOLD"Images configured for start arg: "$START $EBOLD
588 column -t -s $'\t' $image_list_file
593 #Set the SIM_GROUP var
594 echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
595 if [ -z "$SIM_GROUP" ]; then
596 SIM_GROUP=$PWD/../simulator-group
597 if [ ! -d $SIM_GROUP ]; then
598 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
599 echo -e $RED"Please set the SIM_GROUP manually in the applicable $TEST_ENV_VAR_FILE"$ERED
602 echo " SIM_GROUP auto set to: " $SIM_GROUP
604 elif [ $SIM_GROUP = *simulator_group ]; then
605 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
608 echo " SIM_GROUP env var already set to: " $SIM_GROUP
613 #Temp var to check for image pull errors
616 #Function to check if image exist and stop+remove the container+pull new images as needed
617 #args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
618 __check_and_pull_image() {
620 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
621 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
622 tmp_im=$(docker images --format $format_string ${4})
624 if [ $1 == "local" ]; then
625 if [ -z "$tmp_im" ]; then
626 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
630 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
632 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
633 if [ $1 == "remote-remove" ]; then
634 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
635 tmp="$(docker ps -aq --filter name=${3})"
636 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
637 docker stop $tmp &> ./tmp/.dockererr
638 if [ $? -ne 0 ]; then
641 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
646 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
647 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
648 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
649 docker rm $tmp &> ./tmp/.dockererr
650 if [ $? -ne 0 ]; then
653 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
658 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
659 echo -ne " Removing image - ${SAMELINE}"
660 tmp="$(docker images -q ${4})" &> /dev/null
661 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
662 docker rmi --force $4 &> ./tmp/.dockererr
663 if [ $? -ne 0 ]; then
666 echo -e $RED" Image could not be removed - try manual removal of the image"$ERED
670 echo -e " Removing image - "$GREEN"removed"$EGREEN
672 echo -e " Removing image - "$GREEN"image not in repository"$EGREEN
676 if [ -z "$tmp_im" ]; then
677 echo -ne " Pulling image${SAMELINE}"
678 docker pull $4 &> ./tmp/.dockererr
679 tmp_im=$(docker images ${4} | grep -v REPOSITORY)
680 if [ -z "$tmp_im" ]; then
682 echo -e " Pulling image -$RED could not be pulled"$ERED
687 echo -e " Pulling image -$GREEN Pulled $EGREEN"
689 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
696 echo -e $BOLD"Pulling configured images, if needed"$EBOLD
698 __check_included_image 'PA'
699 if [ $? -eq 0 ]; then
700 START_ARG_MOD=$START_ARG
701 __check_image_local_override 'PA'
702 if [ $? -eq 1 ]; then
703 START_ARG_MOD="local"
705 app="Policy Agent"; __check_and_pull_image $START_ARG_MOD "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
707 echo -e $YELLOW" Excluding PA image from image check/pull"$EYELLOW
710 __check_included_image 'ECS'
711 if [ $? -eq 0 ]; then
712 START_ARG_MOD=$START_ARG
713 __check_image_local_override 'ECS'
714 if [ $? -eq 1 ]; then
715 START_ARG_MOD="local"
717 app="ECS"; __check_and_pull_image $START_ARG_MOD "$app" $ECS_APP_NAME $ECS_IMAGE
719 echo -e $YELLOW" Excluding ECS image from image check/pull"$EYELLOW
722 __check_included_image 'CP'
723 if [ $? -eq 0 ]; then
724 START_ARG_MOD=$START_ARG
725 __check_image_local_override 'CP'
726 if [ $? -eq 1 ]; then
727 START_ARG_MOD="local"
729 app="Non-RT RIC Control Panel"; __check_and_pull_image $START_ARG_MOD "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
731 echo -e $YELLOW" Excluding Non-RT RIC Control Panel image from image check/pull"$EYELLOW
734 __check_included_image 'RC'
735 if [ $? -eq 0 ]; then
736 START_ARG_MOD=$START_ARG
737 __check_image_local_override 'RC'
738 if [ $? -eq 1 ]; then
739 START_ARG_MOD="local"
741 app="RAPP Catalogue"; __check_and_pull_image $START_ARG_MOD "$app" $RAPP_CAT_APP_NAME $RAPP_CAT_IMAGE
743 echo -e $YELLOW" Excluding RAPP Catalogue image from image check/pull"$EYELLOW
746 __check_included_image 'RICSIM'
747 if [ $? -eq 0 ]; then
748 START_ARG_MOD=$START_ARG
749 __check_image_local_override 'RICSIM'
750 if [ $? -eq 1 ]; then
751 START_ARG_MOD="local"
753 app="Near-RT RIC Simulator"; __check_and_pull_image $START_ARG_MOD "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
755 echo -e $YELLOW" Excluding Near-RT RIC Simulator image from image check/pull"$EYELLOW
759 __check_included_image 'CONSUL'
760 if [ $? -eq 0 ]; then
761 app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
763 echo -e $YELLOW" Excluding Consul image from image check/pull"$EYELLOW
766 __check_included_image 'CBS'
767 if [ $? -eq 0 ]; then
768 app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE
770 echo -e $YELLOW" Excluding CBS image from image check/pull"$EYELLOW
773 __check_included_image 'SDNC'
774 if [ $? -eq 0 ]; then
775 START_ARG_MOD=$START_ARG
776 __check_image_local_override 'SDNC'
777 if [ $? -eq 1 ]; then
778 START_ARG_MOD="local"
780 app="SDNC A1 Controller"; __check_and_pull_image $START_ARG_MOD "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
781 app="SDNC DB"; __check_and_pull_image $START_ARG "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
783 echo -e $YELLOW" Excluding SDNC image and related DB image from image check/pull"$EYELLOW
786 #Errors in image setting - exit
787 if [ $IMAGE_ERR -ne 0 ]; then
789 echo "#################################################################################################"
790 echo -e $RED"One or more images could not be pulled or containers using the images could not be stopped/removed"$ERED
791 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
792 echo "#################################################################################################"
799 echo -e $BOLD"Building images needed for test"$EBOLD
802 __check_included_image 'MR'
803 if [ $? -eq 0 ]; then
806 echo " Building mrstub image: $MRSTUB_LOCAL_IMAGE:$MRSTUB_LOCAL_IMAGE_TAG"
807 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $MRSTUB_LOCAL_IMAGE . &> .dockererr
808 if [ $? -eq 0 ]; then
809 echo -e $GREEN" Build Ok"$EGREEN
811 echo -e $RED" Build Failed"$ERED
814 echo -e $RED"Exiting...."$ERED
819 echo -e $YELLOW" Excluding mrstub from image build"$EYELLOW
822 __check_included_image 'CR'
823 if [ $? -eq 0 ]; then
825 echo " Building Callback Receiver image: $CR_LOCAL_IMAGE:$CR_IMAGE_TAG"
826 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $CR_LOCAL_IMAGE . &> .dockererr
827 if [ $? -eq 0 ]; then
828 echo -e $GREEN" Build Ok"$EGREEN
830 echo -e $RED" Build Failed"$ERED
833 echo -e $RED"Exiting...."$ERED
838 echo -e $YELLOW" Excluding Callback Receiver from image build"$EYELLOW
841 __check_included_image 'PRODSTUB'
842 if [ $? -eq 0 ]; then
844 echo " Building Producer stub image: $PROD_STUB_LOCAL_IMAGE:$PROD_STUB_LOCAL_IMAGE_TAG"
845 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $PROD_STUB_LOCAL_IMAGE . &> .dockererr
846 if [ $? -eq 0 ]; then
847 echo -e $GREEN" Build Ok"$EGREEN
849 echo -e $RED" Build Failed"$ERED
852 echo -e $RED"Exiting...."$ERED
857 echo -e $YELLOW" Excluding Producer stub from image build"$EYELLOW
862 # Create a table of the images used in the script
863 echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
865 docker_tmp_file=./tmp/.docker-images-table
866 format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\\t{{.CreatedAt}}"
867 echo -e " Application\tRepository\tTag\tCreated since\tSize\tCreated at" > $docker_tmp_file
868 __check_included_image 'PA'
869 if [ $? -eq 0 ]; then
870 echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
872 __check_included_image 'ECS'
873 if [ $? -eq 0 ]; then
874 echo -e " ECS\t$(docker images --format $format_string $ECS_IMAGE)" >> $docker_tmp_file
876 __check_included_image 'CP'
877 if [ $? -eq 0 ]; then
878 echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
880 __check_included_image 'RICSIM'
881 if [ $? -eq 0 ]; then
882 echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
884 __check_included_image 'RC'
885 if [ $? -eq 0 ]; then
886 echo -e " RAPP Catalogue\t$(docker images --format $format_string $RAPP_CAT_IMAGE)" >> $docker_tmp_file
888 __check_included_image 'MR'
889 if [ $? -eq 0 ]; then
890 echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
892 __check_included_image 'CR'
893 if [ $? -eq 0 ]; then
894 echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
896 __check_included_image 'PRODSTUB'
897 if [ $? -eq 0 ]; then
898 echo -e " Produccer stub\t$(docker images --format $format_string $PROD_STUB_IMAGE)" >> $docker_tmp_file
900 __check_included_image 'CONSUL'
901 if [ $? -eq 0 ]; then
902 echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
904 __check_included_image 'CBS'
905 if [ $? -eq 0 ]; then
906 echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
908 __check_included_image 'SDNC'
909 if [ $? -eq 0 ]; then
910 echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
911 echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
914 column -t -s $'\t' $docker_tmp_file
918 echo -e $BOLD"======================================================="$EBOLD
919 echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
920 echo -e $BOLD"======================================================="$EBOLD
923 # Function to print the test result, shall be the last cmd in a test script
925 # (Function for test scripts)
929 duration=$((TCTEST_END-TCTEST_START))
931 echo "-------------------------------------------------------------------------------------------------"
932 echo "------------------------------------- Test case: "$ATC
933 echo "------------------------------------- Ended: "$(date)
934 echo "-------------------------------------------------------------------------------------------------"
935 echo "-- Description: "$TC_ONELINE_DESCR
936 echo "-- Execution time: " $duration " seconds"
937 echo "-- Used env file: "$TEST_ENV_VAR_FILE
938 echo "-------------------------------------------------------------------------------------------------"
939 echo "------------------------------------- RESULTS"
943 if [ $RES_DEVIATION -gt 0 ]; then
944 echo "Test case deviations"
945 echo "===================================="
949 echo "Timer measurement in the test script"
950 echo "===================================="
951 column -t -s $'\t' $TIMER_MEASUREMENTS
954 total=$((RES_PASS+RES_FAIL))
955 if [ $RES_TEST -eq 0 ]; then
956 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
957 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
958 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
959 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
960 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
961 elif [ $total != $RES_TEST ]; then
962 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
963 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
964 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
965 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
966 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
967 elif [ $RES_CONF_FAIL -ne 0 ]; then
968 echo -e "\033[1mOne or more configure regest has failed. Check the script log....\033[0m"
969 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
970 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
971 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
972 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
973 elif [ $RES_PASS = $RES_TEST ]; then
974 echo -e "All tests \033[32m\033[1mPASS\033[0m"
975 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
976 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
977 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
978 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
981 # Update test suite counter
982 if [ -f .tmp_tcsuite_pass_ctr ]; then
983 tmpval=$(< .tmp_tcsuite_pass_ctr)
985 echo $tmpval > .tmp_tcsuite_pass_ctr
987 if [ -f .tmp_tcsuite_pass ]; then
988 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
990 #Create file with OK exit code
991 echo "0" > "$PWD/.result$ATC.txt"
993 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
994 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
995 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
996 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
997 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
999 # Update test suite counter
1000 if [ -f .tmp_tcsuite_fail_ctr ]; then
1001 tmpval=$(< .tmp_tcsuite_fail_ctr)
1003 echo $tmpval > .tmp_tcsuite_fail_ctr
1005 if [ -f .tmp_tcsuite_fail ]; then
1006 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
1010 echo "++++ Number of tests: "$RES_TEST
1011 echo "++++ Number of passed tests: "$RES_PASS
1012 echo "++++ Number of failed tests: "$RES_FAIL
1014 echo "++++ Number of failed configs: "$RES_CONF_FAIL
1016 echo "++++ Number of test case deviations: "$RES_DEVIATION
1018 echo "------------------------------------- Test case complete ---------------------------------"
1019 echo "-------------------------------------------------------------------------------------------------"
1023 #####################################################################
1024 ###### Functions for start, configuring, stoping, cleaning etc ######
1025 #####################################################################
1027 # Start timer for time measurement
1028 # args - (any args will be printed though)
1030 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1032 echo " Timer started"
1035 # Print the value of the time (in seconds)
1036 # args - <timer message to print> - timer value and message will be printed both on screen
1037 # and in the timer measurement report
1039 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1040 if [ $# -lt 1 ]; then
1042 __print_err "need 1 or more args, <timer message to print>" $@
1045 duration=$(($SECONDS-$TC_TIMER))
1046 if [ $duration -eq 0 ]; then
1047 duration="<1 second"
1049 duration=$duration" seconds"
1051 echo " Timer duration :" $duration
1053 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
1056 # Print the value of the time (in seconds) and reset the timer
1057 # args - <timer message to print> - timer value and message will be printed both on screen
1058 # and in the timer measurement report
1059 print_and_reset_timer() {
1060 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1061 if [ $# -lt 1 ]; then
1063 __print_err "need 1 or more args, <timer message to print>" $@
1066 duration=$(($SECONDS-$TC_TIMER))" seconds"
1067 if [ $duration -eq 0 ]; then
1068 duration="<1 second"
1070 duration=$duration" seconds"
1072 echo " Timer duration :" $duration
1076 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
1079 # Print info about a deviations from intended tests
1080 # Each deviation counted is also printed in the testreport
1081 # args <deviation message to print>
1083 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
1084 if [ $# -lt 1 ]; then
1086 __print_err "need 1 or more args, <deviation message to print>" $@
1090 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
1091 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
1095 # Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
1096 __check_stop_at_error() {
1097 if [ $STOP_AT_ERROR -eq 1 ]; then
1098 echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
1099 store_logs "STOP_AT_ERROR"
1105 # Check if app name var is set. If so return the app name otherwise return "NOTSET"
1106 __check_app_name() {
1107 if [ $# -eq 1 ]; then
1114 # Stop and remove all containers
1116 # (Function for test scripts)
1117 clean_containers() {
1119 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
1121 CONTAINTER_NAMES=("Policy Agent " $(__check_app_name $POLICY_AGENT_APP_NAME)\
1122 "ECS " $(__check_app_name $ECS_APP_NAME)\
1123 "RAPP Catalogue " $(__check_app_name $RAPP_CAT_APP_NAME)\
1124 "Non-RT RIC Simulator(s)" $(__check_app_name $RIC_SIM_PREFIX)\
1125 "Message Router " $(__check_app_name $MR_APP_NAME)\
1126 "Callback Receiver " $(__check_app_name $CR_APP_NAME)\
1127 "Producer stub " $(__check_app_name $PROD_STUB_APP_NAME)\
1128 "Control Panel " $(__check_app_name $CONTROL_PANEL_APP_NAME)\
1129 "SDNC A1 Controller " $(__check_app_name $SDNC_APP_NAME)\
1130 "SDNC DB " $(__check_app_name $SDNC_DB_APP_NAME)\
1131 "CBS " $(__check_app_name $CBS_APP_NAME)\
1132 "Consul " $(__check_app_name $CONSUL_APP_NAME))
1134 nw=0 # Calc max width of container name, to make a nice table
1135 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
1137 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
1138 nw=${#CONTAINTER_NAMES[i]}
1142 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
1143 APP="${CONTAINTER_NAMES[i]}"
1144 CONTR="${CONTAINTER_NAMES[i+1]}"
1145 if [ $CONTR != "NOTSET" ]; then
1146 for((w=${#CONTR}; w<$nw; w=w+1)); do
1149 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
1150 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1151 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
1152 docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1153 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
1159 echo -e $BOLD" Removing docker network"$EBOLD
1160 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
1161 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
1162 docker network rm $DOCKER_SIM_NWNAME | indent2
1163 if [ $? -ne 0 ]; then
1164 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
1168 echo -e "$GREEN Done$EGREEN"
1170 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
1171 docker network prune --force | indent2
1172 echo -e "$GREEN Done$EGREEN"
1174 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
1175 docker volume prune --force | indent2
1176 echo -e "$GREEN Done$EGREEN"
1178 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
1179 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
1180 echo -e "$GREEN Done$EGREEN"
1183 CONTRS=$(docker ps | awk '$1 != "CONTAINER" { n++ }; END { print n+0 }')
1184 if [ $? -eq 0 ]; then
1185 if [ $CONTRS -ne 0 ]; then
1186 echo -e $RED"Containers running, may cause distubance to the test case"$ERED
1187 docker ps -a | indent1
1193 # Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
1195 # (Function for test scripts)
1196 auto_clean_containers() {
1198 if [ "$AUTO_CLEAN" == "auto" ]; then
1199 echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
1204 # Function to sleep a test case for a numner of seconds. Prints the optional text args as info
1205 # args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
1206 # (Function for test scripts)
1209 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1210 if [ $# -lt 1 ]; then
1212 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
1215 #echo "---- Sleep for " $1 " seconds ---- "$2
1217 duration=$((SECONDS-start))
1218 while [ $duration -lt $1 ]; do
1219 echo -ne " Slept for ${duration} seconds${SAMELINE}"
1221 duration=$((SECONDS-start))
1223 echo -ne " Slept for ${duration} seconds${SAMELINE}"
1227 # Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
1228 # Not to be called from the test script itself.
1230 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
1231 if [ $# -gt 1 ]; then
1232 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
1238 # Helper function to get a the port of a specific ric simulatpor
1240 # (Not for test scripts)
1242 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
1243 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
1245 if [[ "$res" =~ ^[0-9]+$ ]]; then
1252 # Function to create the docker network for the test
1253 # Not to be called from the test script itself.
1254 __create_docker_network() {
1255 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
1256 if [ $? -ne 0 ]; then
1257 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
1260 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
1261 echo -e " Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
1262 docker network create $DOCKER_SIM_NWNAME | indent2
1263 if [ $? -ne 0 ]; then
1264 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
1267 echo -e "$GREEN Done$EGREEN"
1270 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
1274 # Check if container is started by calling url on localhost using a port, expects response code 2XX
1275 # args: <container-name> <port> <url> https|https
1276 # Not to be called from the test script itself.
1277 __check_container_start() {
1279 if [ $# -ne 4 ]; then
1281 elif [ $4 != "http" ] && [ $4 != "https" ]; then
1284 if [ $paramError -ne 0 ]; then
1286 __print_err "need 3 args, <container-name> <port> <url> https|https" $@
1289 echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
1293 if [[ $appname != "STANDALONE_"* ]] ; then
1295 for i in {1..10}; do
1296 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
1297 echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
1304 if [ $app_started -eq 0 ]; then
1307 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
1308 echo -e $RED" Stopping script..."$ERED
1311 if [ $localport -eq 0 ]; then
1312 while [ $localport -eq 0 ]; do
1313 echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
1314 localport=$(__find_sim_port $appname)
1316 echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
1318 echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
1324 echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
1326 for i in {1..50}; do
1327 if [ $4 == "https" ]; then
1328 result="$(__do_curl "-k https://localhost:"${localport}${url})"
1330 result="$(__do_curl $LOCALHOST${localport}${url})"
1332 if [ $? -eq 0 ]; then
1333 if [ ${#result} -gt 15 ]; then
1334 #If response is too long, truncate
1335 result="...response text too long, omitted"
1337 echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
1338 echo -ne " Container $BOLD${appname}$EBOLD$GREEN is alive$EGREEN, responds to service status:$GREEN $result $EGREEN after $(($SECONDS-$TSTART)) seconds"
1343 while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
1344 echo -ne " Waiting for container ${appname} service status...$(($SECONDS-$TSTART)) seconds, retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
1350 if [ "$pa_st" = "false" ]; then
1352 echo -e $RED" Container ${appname} did not respond to service status in $(($SECONDS-$TSTART)) seconds"$ERED
1361 # Function to start a container and wait until it responds on the given port and url.
1362 #args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
1363 __start_container() {
1365 variableArgCount=$(($#-2))
1366 if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
1368 __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 ]*" $@
1372 __create_docker_network
1378 if [ "$2" == "NODOCKERARGS" ]; then
1379 docker-compose up -d &> .dockererr
1380 if [ $? -ne 0 ]; then
1381 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1383 echo -e $RED"Stopping script...."$ERED
1386 elif [ "$2" == "STANDALONE" ]; then
1387 echo "Skipping docker-compose"
1389 docker-compose up -d $2 &> .dockererr
1390 if [ $? -ne 0 ]; then
1391 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1393 echo -e $RED"Stopping script...."$ERED
1398 if [ "$2" == "STANDALONE" ]; then
1399 app_prefix="STANDALONE_"
1403 while [ $cntr -lt $variableArgCount ]; do
1404 app=$app_prefix$1; shift;
1410 __check_container_start "$app" "$port" "$url" $httpx
1418 # Generate a UUID to use as prefix for policy ids
1420 UUID=$(python3 -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
1421 #Reduce length to make space for serial id, us 'a' as marker where the serial id is added
1422 UUID=${UUID:0:${#UUID}-4}"a"
1425 ####################
1426 ### Consul functions
1427 ####################
1429 # Function to load config from a file into consul for the Policy Agent
1430 # arg: <json-config-file>
1431 # (Function for test scripts)
1432 consul_config_app() {
1434 echo -e $BOLD"Configuring Consul"$EBOLD
1436 if [ $# -ne 1 ]; then
1438 __print_err "need one arg, <json-config-file>" $@
1442 echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1
1444 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
1445 result=$(__do_curl "$curlString")
1446 if [ $? -ne 0 ]; then
1447 echo -e $RED" FAIL - json config could not be loaded to consul" $ERED
1451 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
1452 echo $body > "./tmp/.output"$1
1454 if [ $? -ne 0 ]; then
1455 echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED
1460 targetJson="{\"config\":"$targetJson"}"
1461 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1462 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1463 if [ $res -ne 0 ]; then
1464 echo -e $RED" FAIL - policy json config read from consul/cbs is not equal to the intended json config...." $ERED
1468 echo -e $GREEN" Config loaded ok to consul"$EGREEN
1476 # Function to perpare the consul configuration according to the current simulator configuration
1477 # args: SDNC|NOSDNC <output-file>
1478 # (Function for test scripts)
1479 prepare_consul_config() {
1480 echo -e $BOLD"Prepare Consul config"$EBOLD
1482 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
1484 if [ $# != 2 ]; then
1486 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
1490 if [ $1 == "SDNC" ]; then
1491 echo -e " Config$BOLD including SDNC$EBOLD configuration"
1492 elif [ $1 == "NOSDNC" ]; then
1493 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
1496 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
1501 if [ $1 == "SDNC" ]; then
1502 config_json=$config_json"\n \"controller\": ["
1503 config_json=$config_json"\n {"
1504 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
1505 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1506 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://$SDNC_APP_NAME:$SDNC_PORT\","
1508 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://localhost:$SDNC_LOCAL_PORT\","
1510 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
1511 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
1512 config_json=$config_json"\n }"
1513 config_json=$config_json"\n ],"
1516 config_json=$config_json"\n \"streams_publishes\": {"
1517 config_json=$config_json"\n \"dmaap_publisher\": {"
1518 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1519 config_json=$config_json"\n \"dmaap_info\": {"
1520 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1521 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_WRITE_URL\""
1523 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_WRITE_URL\""
1525 config_json=$config_json"\n }"
1526 config_json=$config_json"\n }"
1527 config_json=$config_json"\n },"
1528 config_json=$config_json"\n \"streams_subscribes\": {"
1529 config_json=$config_json"\n \"dmaap_subscriber\": {"
1530 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1531 config_json=$config_json"\n \"dmaap_info\": {"
1532 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1533 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_READ_URL\""
1535 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_READ_URL\""
1537 config_json=$config_json"\n }"
1538 config_json=$config_json"\n }"
1539 config_json=$config_json"\n },"
1541 config_json=$config_json"\n \"ric\": ["
1543 rics=$(docker ps | grep $RIC_SIM_PREFIX | awk '{print $NF}')
1545 if [ $? -ne 0 ] || [ -z "$rics" ]; then
1546 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
1552 for ric in $rics; do
1553 if [ $cntr -gt 0 ]; then
1554 config_json=$config_json"\n ,"
1556 config_json=$config_json"\n {"
1557 config_json=$config_json"\n \"name\": \"$ric\","
1558 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1559 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
1561 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://localhost:$(__find_sim_port $ric)\","
1563 if [ $1 == "SDNC" ]; then
1564 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
1566 config_json=$config_json"\n \"managedElementIds\": ["
1567 config_json=$config_json"\n \"me1_$ric\","
1568 config_json=$config_json"\n \"me2_$ric\""
1569 config_json=$config_json"\n ]"
1570 config_json=$config_json"\n }"
1574 config_json=$config_json"\n ]"
1575 config_json=$config_json"\n}"
1578 printf "$config_json">$2
1584 # Start Consul and CBS
1586 # (Function for test scripts)
1587 start_consul_cbs() {
1589 echo -e $BOLD"Starting Consul and CBS"$EBOLD
1590 __check_included_image 'CONSUL'
1591 if [ $? -eq 1 ]; then
1592 echo -e $RED"The Consul image has not been checked for this test run due to arg to the test script"$ERED
1593 echo -e $RED"Consul will not be started"$ERED
1596 __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" "http" \
1597 "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck" "http"
1600 ###########################
1601 ### RIC Simulator functions
1602 ###########################
1604 use_simulator_http() {
1605 echo -e $BOLD"RICSIM protocol setting"$EBOLD
1606 echo -e " Using $BOLD http $EBOLD towards the simulators"
1607 export RIC_SIM_HTTPX="http"
1608 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1609 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
1613 use_simulator_https() {
1614 echo -e $BOLD"RICSIM protocol setting"$EBOLD
1615 echo -e " Using $BOLD https $EBOLD towards the simulators"
1616 export RIC_SIM_HTTPX="https"
1617 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1618 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
1622 # Start one group (ricsim_g1, ricsim_g2 .. ricsim_g5) with a number of RIC Simulators using a given A interface
1623 # 'ricsim' may be set on command line to other prefix
1624 # args: ricsim_g1|ricsim_g2|ricsim_g3|ricsim_g4|ricsim_g5 <count> <interface-id>
1625 # (Function for test scripts)
1626 start_ric_simulators() {
1628 echo -e $BOLD"Starting RIC Simulators"$EBOLD
1630 __check_included_image 'RICSIM'
1631 if [ $? -eq 1 ]; then
1632 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
1633 echo -e $RED"The Near-RT RIC Simulartor(s) will not be started"$ERED
1637 RIC1=$RIC_SIM_PREFIX"_g1"
1638 RIC2=$RIC_SIM_PREFIX"_g2"
1639 RIC3=$RIC_SIM_PREFIX"_g3"
1640 RIC4=$RIC_SIM_PREFIX"_g4"
1641 RIC5=$RIC_SIM_PREFIX"_g5"
1643 if [ $# != 3 ]; then
1645 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
1648 echo " $2 simulators using basename: $1 on interface: $3"
1649 #Set env var for simulator count and A1 interface vesion for the given group
1650 if [ $1 == "$RIC1" ]; then
1653 elif [ $1 == "$RIC2" ]; then
1656 elif [ $1 == "$RIC3" ]; then
1659 elif [ $1 == "$RIC4" ]; then
1662 elif [ $1 == "$RIC5" ]; then
1667 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
1671 # Create .env file to compose project, all ric container will get this prefix
1672 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
1674 export G1_A1_VERSION
1675 export G2_A1_VERSION
1676 export G3_A1_VERSION
1677 export G4_A1_VERSION
1678 export G5_A1_VERSION
1680 docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT --scale g4=$G4_COUNT --scale g5=$G5_COUNT"
1683 while [ $cntr -le $2 ]; do
1686 app_data="$app_data $app $port / "$RIC_SIM_HTTPX
1689 __start_container ric "$docker_args" $app_data
1693 ###########################
1694 ### Control Panel functions
1695 ###########################
1697 # Start the Control Panel container
1699 # (Function for test scripts)
1700 start_control_panel() {
1702 echo -e $BOLD"Starting Control Panel"$EBOLD
1703 __check_included_image 'CP'
1704 if [ $? -eq 1 ]; then
1705 echo -e $RED"The Control Panel image has not been checked for this test run due to arg to the test script"$ERED
1706 echo -e $RED"The Control Panel will not be started"$ERED
1709 __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/" "http"
1713 ###########################
1715 ###########################
1717 # Start the RAPP Catalogue container
1719 # (Function for test scripts)
1720 start_rapp_catalogue() {
1722 echo -e $BOLD"Starting RAPP Catalogue"$EBOLD
1724 __check_included_image 'RC'
1725 if [ $? -eq 1 ]; then
1726 echo -e $RED"The RAPP Catalogue image has not been checked for this test run due to arg to the test script"$ERED
1727 echo -e $RED"The RAPP Catalogue will not be started"$ERED
1730 __start_container rapp_catalogue NODOCKERARGS $RAPP_CAT_APP_NAME $RAPP_CAT_EXTERNAL_PORT "/services" "http"
1733 use_rapp_catalogue_http() {
1734 echo -e $BOLD"RAPP Catalogue protocol setting"$EBOLD
1735 echo -e " Using $BOLD http $EBOLD towards the RAPP Catalogue"
1736 export RAPP_CAT_HTTPX="http"
1737 export RAPP_CAT_PORT=$RAPP_CAT_INTERNAL_PORT
1738 export RAPP_CAT_LOCAL_PORT=$RAPP_CAT_EXTERNAL_PORT
1742 use_rapp_catalogue_https() {
1743 echo -e $BOLD"RAPP Catalogue protocol setting"$EBOLD
1744 echo -e " Using $BOLD https $EBOLD towards the RAPP Catalogue"
1745 export RAPP_CAT_HTTPX="https"
1746 export RAPP_CAT_PORT=$RAPP_CAT_INTERNAL_PORT
1747 export RAPP_CAT_LOCAL_PORT=$RAPP_CAT_EXTERNAL_PORT
1755 # Start the SDNC A1 Controller
1757 # (Function for test scripts)
1760 echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
1762 __check_included_image 'SDNC'
1763 if [ $? -eq 1 ]; then
1764 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
1765 echo -e $RED"SDNC will not be started"$ERED
1769 __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT $SDNC_ALIVE_URL "http"
1774 echo -e $BOLD"SDNC protocol setting"$EBOLD
1775 echo -e " Using $BOLD http $EBOLD towards SDNC"
1776 export SDNC_HTTPX="http"
1777 export SDNC_PORT=$SDNC_INTERNAL_PORT
1778 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT
1783 echo -e $BOLD"SDNC protocol setting"$EBOLD
1784 echo -e " Using $BOLD https $EBOLD towards SDNC"
1785 export SDNC_HTTPX="https"
1786 export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT
1787 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT
1791 #####################
1792 ### MR stub functions
1793 #####################
1795 # Start the Message Router stub interface in the simulator group
1797 # (Function for test scripts)
1800 echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
1801 __check_included_image 'MR'
1802 if [ $? -eq 1 ]; then
1803 echo -e $RED"The Message Router image has not been checked for this test run due to arg to the test script"$ERED
1804 echo -e $RED"The Message Router will not be started"$ERED
1807 export MR_CERT_MOUNT_DIR="./cert"
1808 __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/" "http"
1812 echo -e $BOLD"MR protocol setting"$EBOLD
1813 echo -e " Using $BOLD http $EBOLD towards MR"
1814 export MR_HTTPX="http"
1815 export MR_PORT=$MR_INTERNAL_PORT
1816 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT
1821 echo -e $BOLD"MR protocol setting"$EBOLD
1822 echo -e " Using $BOLD https $EBOLD towards MR"
1823 export MR_HTTPX="https"
1824 export MR_PORT=$MR_INTERNAL_SECURE_PORT
1825 export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT
1834 # Start the Callback reciver in the simulator group
1836 # (Function for test scripts)
1839 echo -e $BOLD"Starting Callback Receiver"$EBOLD
1840 __check_included_image 'CR'
1841 if [ $? -eq 1 ]; then
1842 echo -e $RED"The Callback Receiver image has not been checked for this test run due to arg to the test script"$ERED
1843 echo -e $RED"The Callback Receiver will not be started"$ERED
1846 __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/" "http"
1851 echo -e $BOLD"CR protocol setting"$EBOLD
1852 echo -e " Using $BOLD http $EBOLD towards CR"
1853 export CR_HTTPX="http"
1854 export CR_PORT=$CR_INTERNAL_PORT
1855 export CR_LOCAL_PORT=$CR_EXTERNAL_PORT
1856 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
1861 echo -e $BOLD"CR protocol setting"$EBOLD
1862 echo -e " Using $BOLD https $EBOLD towards CR"
1863 export CR_HTTPX="https"
1864 export CR_PORT=$CR_INTERNAL_SECURE_PORT
1865 export CR_LOCAL_PORT=$CR_EXTERNAL_SECURE_PORT
1866 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
1870 ###########################
1871 ### Producer stub functions
1872 ###########################
1874 # Start the Producer stub in the simulator group
1876 # (Function for test scripts)
1879 echo -e $BOLD"Starting Producer stub"$EBOLD
1880 __check_included_image 'PRODSTUB'
1881 if [ $? -eq 1 ]; then
1882 echo -e $RED"The Producer stub image has not been checked for this test run due to arg to the test script"$ERED
1883 echo -e $RED"The Producer stub will not be started"$ERED
1886 __start_container prodstub NODOCKERARGS $PROD_STUB_APP_NAME $PROD_STUB_EXTERNAL_PORT "/" "http"
1890 use_prod_stub_http() {
1891 echo -e $BOLD"Producer stub protocol setting"$EBOLD
1892 echo -e " Using $BOLD http $EBOLD towards Producer stub"
1893 export PROD_STUB_HTTPX="http"
1894 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
1895 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT
1896 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
1900 use_prod_stub_https() {
1901 echo -e $BOLD"Producer stub protocol setting"$EBOLD
1902 echo -e " Using $BOLD https $EBOLD towards Producer stub"
1903 export PROD_STUB_HTTPX="https"
1904 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_SECURE_PORT
1905 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_SECURE_PORT
1906 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
1910 ###########################
1911 ### Policy Agents functions
1912 ###########################
1914 # Use an agent on the local machine instead of container
1915 use_agent_stand_alone() {
1919 # Start the policy agent
1921 # (Function for test scripts)
1922 start_policy_agent() {
1924 echo -e $BOLD"Starting Policy Agent"$EBOLD
1926 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1927 __check_included_image 'PA'
1928 if [ $? -eq 1 ]; then
1929 echo -e $RED"The Policy Agent image has not been checked for this test run due to arg to the test script"$ERED
1930 echo -e $RED"The Policy Agent will not be started"$ERED
1933 __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1935 echo -e $RED"The consul config produced by this test script (filename '<fullpath-to-autotest-dir>.output<file-name>"$ERED
1936 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
1937 echo -e $RED"application.yaml"$ERED
1938 echo -e $RED"The application jar may need to be built before continuing"$ERED
1939 echo -e $RED"The agent shall now be running on port $POLICY_AGENT_EXTERNAL_PORT for http"$ERED
1941 read -p "<press any key to continue>"
1942 __start_container policy_agent "STANDALONE" $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1947 # All calls to the agent will be directed to the agent REST interface from now on
1949 # (Function for test scripts)
1950 use_agent_rest_http() {
1951 echo -e $BOLD"Agent protocol setting"$EBOLD
1952 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
1953 export ADAPTER=$RESTBASE
1957 # All calls to the agent will be directed to the agent REST interface from now on
1959 # (Function for test scripts)
1960 use_agent_rest_https() {
1961 echo -e $BOLD"Agent protocol setting"$EBOLD
1962 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
1963 export ADAPTER=$RESTBASE_SECURE
1968 # All calls to the agent will be directed to the agent dmaap interface over http from now on
1970 # (Function for test scripts)
1971 use_agent_dmaap_http() {
1972 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
1973 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
1974 export ADAPTER=$DMAAPBASE
1979 # All calls to the agent will be directed to the agent dmaap interface over https from now on
1981 # (Function for test scripts)
1982 use_agent_dmaap_https() {
1983 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
1984 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
1985 export ADAPTER=$DMAAPBASE_SECURE
1990 # Turn on debug level tracing in the agent
1992 # (Function for test scripts)
1994 echo -e $BOLD"Setting agent debug logging"$EBOLD
1995 actuator="/actuator/loggers/org.oransc.policyagent"
1996 if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
1997 actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
1999 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
2000 result=$(__do_curl "$curlString")
2001 if [ $? -ne 0 ]; then
2002 __print_err "could not set debug mode" $@
2010 # Turn on trace level tracing in the agent
2012 # (Function for test scripts)
2014 echo -e $BOLD"Setting agent trace logging"$EBOLD
2015 actuator="/actuator/loggers/org.oransc.policyagent"
2016 if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
2017 actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
2019 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
2020 result=$(__do_curl "$curlString")
2021 if [ $? -ne 0 ]; then
2022 __print_err "could not set trace mode" $@
2030 # Perform curl retries when making direct call to the agent for the specified http response codes
2031 # Speace separated list of http response codes
2032 # args: [<response-code>]*
2033 use_agent_retries() {
2034 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
2035 AGENT_RETRY_CODES=$@
2040 ###########################
2042 ###########################
2046 # (Function for test scripts)
2049 echo -e $BOLD"Starting ECS"$EBOLD
2054 cd $ECS_HOST_MNT_DIR
2055 if [ -d database ]; then
2056 if [ "$(ls -A $DIR)" ]; then
2057 echo -e $BOLD" Cleaning files in mounted dir: $PWD/database"$EBOLD
2058 rm -rf database/* &> /dev/null
2059 if [ $? -ne 0 ]; then
2060 echo -e $RED" Cannot remove database files in: $PWD"$ERED
2065 echo " No files in mounted dir or dir does not exists"
2069 __check_included_image 'ECS'
2070 if [ $? -eq 1 ]; then
2071 echo -e $RED"The ECS image has not been checked for this test run due to arg to the test script"$ERED
2072 echo -e $RED"ECS will not be started"$ERED
2075 export ECS_CERT_MOUNT_DIR="./cert"
2076 __start_container ecs NODOCKERARGS $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
2081 # (Function for test scripts)
2083 echo -e $BOLD"Re-starting ECS"$EBOLD
2084 docker restart $ECS_APP_NAME &> ./tmp/.dockererr
2085 if [ $? -ne 0 ]; then
2086 __print_err "Could restart $ECS_APP_NAME" $@
2087 cat ./tmp/.dockererr
2092 __check_container_start $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
2097 # All calls to ECS will be directed to the ECS REST interface from now on
2099 # (Function for test scripts)
2100 use_ecs_rest_http() {
2101 echo -e $BOLD"ECS protocol setting"$EBOLD
2102 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
2103 export ECS_ADAPTER=$ECS_RESTBASE
2107 # All calls to ECS will be directed to the ECS REST interface from now on
2109 # (Function for test scripts)
2110 use_ecs_rest_https() {
2111 echo -e $BOLD"ECS protocol setting"$EBOLD
2112 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
2113 export ECS_ADAPTER=$ECS_RESTBASE_SECURE
2118 # All calls to ECS will be directed to the ECS dmaap interface over http from now on
2120 # (Function for test scripts)
2121 use_ecs_dmaap_http() {
2122 echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
2123 echo -e $RED" - NOT SUPPORTED - "$ERED
2124 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
2125 export ECS_ADAPTER=$ECS_DMAAPBASE
2130 # All calls to ECS will be directed to the ECS dmaap interface over https from now on
2132 # (Function for test scripts)
2133 use_ecs_dmaap_https() {
2134 echo -e $BOLD"RICSIM protocol setting"$EBOLD
2135 echo -e $RED" - NOT SUPPORTED - "$ERED
2136 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
2137 export ECS_ADAPTER=$ECS_DMAAPBASE_SECURE
2142 # Turn on debug level tracing in ECS
2144 # (Function for test scripts)
2146 echo -e $BOLD"Setting ecs debug logging"$EBOLD
2147 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
2148 result=$(__do_curl "$curlString")
2149 if [ $? -ne 0 ]; then
2150 __print_err "Could not set debug mode" $@
2158 # Turn on trace level tracing in ECS
2160 # (Function for test scripts)
2162 echo -e $BOLD"Setting ecs trace logging"$EBOLD
2163 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
2164 result=$(__do_curl "$curlString")
2165 if [ $? -ne 0 ]; then
2166 __print_err "Could not set trace mode" $@
2174 # Perform curl retries when making direct call to ECS for the specified http response codes
2175 # Speace separated list of http response codes
2176 # args: [<response-code>]*
2177 use_agent_retries() {
2178 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
2179 ECS_AGENT_RETRY_CODES=$@
2188 # Check the agent logs for WARNINGs and ERRORs
2190 # (Function for test scripts)
2192 check_policy_agent_logs() {
2193 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
2197 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
2200 check_control_panel_logs() {
2201 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH WARN ERR
2205 __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
2208 __check_container_logs() {
2215 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
2217 #tmp=$(docker ps | grep $appname)
2218 tmp=$(docker ps -q --filter name=$appname) #get the container id
2219 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
2220 echo $dispname" is not running, no check made"
2223 foundentries="$(docker exec -t $tmp grep $warning $logpath | wc -l)"
2224 if [ $? -ne 0 ];then
2225 echo " Problem to search $appname log $logpath"
2227 if [ $foundentries -eq 0 ]; then
2228 echo " No WARN entries found in $appname log $logpath"
2230 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
2233 foundentries="$(docker exec -t $tmp grep $error $logpath | wc -l)"
2234 if [ $? -ne 0 ];then
2235 echo " Problem to search $appname log $logpath"
2237 if [ $foundentries -eq 0 ]; then
2238 echo " No ERR entries found in $appname log $logpath"
2240 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
2246 # Store all container logs and other logs in the log dir for the script
2247 # Logs are stored with a prefix in case logs should be stored several times during a test
2248 # args: <logfile-prefix>
2249 # (Function for test scripts)
2251 if [ $# != 1 ]; then
2253 __print_err "need one arg, <file-prefix>" $@
2256 echo -e $BOLD"Storing all container logs in $TESTLOGS/$ATC using prefix: "$1$EBOLD
2258 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
2260 __check_included_image 'CONSUL'
2261 if [ $? -eq 0 ]; then
2262 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
2265 __check_included_image 'CBS'
2266 if [ $? -eq 0 ]; then
2267 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
2268 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
2269 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
2272 __check_included_image 'PA'
2273 if [ $? -eq 0 ]; then
2274 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
2277 __check_included_image 'ECS'
2278 if [ $? -eq 0 ]; then
2279 docker logs $ECS_APP_NAME > $TESTLOGS/$ATC/$1_ecs.log 2>&1
2282 __check_included_image 'CP'
2283 if [ $? -eq 0 ]; then
2284 docker logs $CONTROL_PANEL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
2287 __check_included_image 'MR'
2288 if [ $? -eq 0 ]; then
2289 docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
2292 __check_included_image 'CR'
2293 if [ $? -eq 0 ]; then
2294 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
2297 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
2299 __check_included_image 'SDNC'
2300 if [ $? -eq 0 ]; then
2301 docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
2304 __check_included_image 'RICSIM'
2305 if [ $? -eq 0 ]; then
2306 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
2307 for ric in $rics; do
2308 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
2312 __check_included_image 'PRODSTUB'
2313 if [ $? -eq 0 ]; then
2314 docker logs $PROD_STUB_APP_NAME > $TESTLOGS/$ATC/$1_prodstub.log 2>&1
2323 # Generic curl function, assumes all 200-codes are ok
2324 # args: <valid-curl-args-including full url>
2325 # returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
2326 # returns: The return code is 0 for ok and 1 for not ok
2328 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
2329 curlString="curl -skw %{http_code} $@"
2330 echo " CMD: $curlString" >> $HTTPLOG
2332 echo " RESP: $res" >> $HTTPLOG
2333 http_code="${res:${#res}-3}"
2334 if [ ${#res} -eq 3 ]; then
2335 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2336 echo "<no-response-from-server>"
2342 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2343 echo "<not found, resp:${http_code}>"
2346 if [ $# -eq 2 ]; then
2347 echo "${res:0:${#res}-3}" | xargs
2349 echo "${res:0:${#res}-3}"
2356 #######################################
2357 ### Basic helper function for test cases
2358 #######################################
2360 # Test a simulator container variable value towards target value using an condition operator with an optional timeout.
2361 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
2362 # immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
2363 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
2364 # before setting pass or fail depending on the result of comparing variable and target using the operator.
2365 # 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.
2366 # Not to be called from test script.
2369 checkjsonarraycount=0
2371 if [ $# -eq 6 ]; then
2372 if [[ $3 == "json:"* ]]; then
2373 checkjsonarraycount=1
2376 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
2378 ((TEST_SEQUENCE_NR++))
2382 if [ $checkjsonarraycount -eq 0 ]; then
2383 result="$(__do_curl $2$3)"
2385 result=${result//[[:blank:]]/} #Strip blanks
2388 result="$(__do_curl $2$path)"
2390 echo "$result" > ./tmp/.tmp.curl.json
2391 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
2393 duration=$((SECONDS-start))
2394 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
2396 if [ $retcode -ne 0 ]; then
2397 if [ $duration -gt $6 ]; then
2399 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
2400 __check_stop_at_error
2403 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2405 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2406 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2408 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2410 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2411 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2413 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2415 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2416 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2418 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2420 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2421 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2424 if [ $duration -gt $6 ]; then
2426 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
2427 __check_stop_at_error
2433 elif [ $# -eq 5 ]; then
2434 if [[ $3 == "json:"* ]]; then
2435 checkjsonarraycount=1
2438 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
2440 ((TEST_SEQUENCE_NR++))
2441 if [ $checkjsonarraycount -eq 0 ]; then
2442 result="$(__do_curl $2$3)"
2444 result=${result//[[:blank:]]/} #Strip blanks
2447 result="$(__do_curl $2$path)"
2449 echo "$result" > ./tmp/.tmp.curl.json
2450 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
2452 if [ $retcode -ne 0 ]; then
2454 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
2455 __check_stop_at_error
2456 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2458 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2459 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2461 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2462 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2464 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2465 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2467 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2470 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
2471 __check_stop_at_error
2474 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
2481 ### Generic test cases for varaible checking
2483 # Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
2484 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2485 # equal to the target or not.
2486 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2487 # before setting pass or fail depending on if the variable value becomes equal to the target
2489 # (Function for test scripts)
2491 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2492 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
2495 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2499 # Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
2500 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2501 # greater than the target or not.
2502 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2503 # before setting pass or fail depending on if the variable value becomes greater than the target
2505 # (Function for test scripts)
2507 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2508 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 ">" $2 $3
2511 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2515 # Read a variable value from MR sim and send to stdout. Arg: <variable-name>
2517 echo "$(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"
2520 # Print a variable value from the MR stub.
2521 # arg: <variable-name>
2522 # (Function for test scripts)
2524 if [ $# != 1 ]; then
2526 __print_err "need one arg, <mr-param>" $@
2529 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"$EBOLD