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
162 #Var for measuring execution time
163 TCTEST_START=$SECONDS
165 #File to save timer measurement results
166 TIMER_MEASUREMENTS=".timer_measurement.txt"
167 echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS
170 echo "-------------------------------------------------------------------------------------------------"
171 echo "----------------------------------- Test case: "$ATC
172 echo "----------------------------------- Started: "$(date)
173 echo "-------------------------------------------------------------------------------------------------"
174 echo "-- Description: "$TC_ONELINE_DESCR
175 echo "-------------------------------------------------------------------------------------------------"
176 echo "----------------------------------- Test case setup -----------------------------------"
180 if [ $# -lt 1 ]; then
183 if [ $paramerror -eq 0 ]; then
184 if [ "$1" != "remote" ] && [ "$1" != "remote-remove" ] && [ "$1" != "local" ]; then
191 while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do
193 if [ $paramerror -eq 0 ]; then
194 if [ "$1" == "auto-clean" ]; then
196 echo "Option set - Auto clean at end of test script"
201 if [ $paramerror -eq 0 ]; then
202 if [ "$1" == "--stop-at-error" ]; then
204 echo "Option set - Stop at first error"
209 if [ $paramerror -eq 0 ]; then
210 if [ "$1" == "--ricsim-prefix" ]; then
216 echo "Option set - Overriding RIC_SIM_PREFIX with: "$1
222 if [ $paramerror -eq 0 ]; then
223 if [ "$1" == "--env-file" ]; then
229 echo "Option set - Reading test env from: "$1
235 if [ $paramerror -eq 0 ]; then
236 if [ "$1" == "--use-local-image" ]; then
239 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
240 USE_LOCAL_IMAGES=$USE_LOCAL_IMAGES" "$1
241 if [[ "$AVAILABLE_LOCAL_IMAGES_OVERRIDE" != *"$1"* ]]; then
247 if [ -z "$USE_LOCAL_IMAGES" ]; then
250 echo "Option set - Override remote images for app(s):"$USE_LOCAL_IMAGES
258 if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
262 if [ $paramerror -eq 1 ]; then
263 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
267 # sourcing the selected env variables for the test case
268 if [ -f "$TEST_ENV_VAR_FILE" ]; then
269 echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD
272 if [ -z "$TEST_ENV_PROFILE" ] || [ -z "$SUPPORTED_PROFILES" ]; then
273 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
275 if [[ "$SUPPORTED_PROFILES" == *"$TEST_ENV_PROFILE"* ]]; then
276 echo -e $GREEN"Test case support the selected test env file"$EGREEN
278 echo -e $RED"Test case does not support the selected test env file"$ERED
279 echo -e $RED"Exiting...."$ERED
284 echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED
285 echo " Select one of following env var file matching the intended target of the test"
286 echo " Restart the test using the flag '--env-file <path-to-env-file>"
287 ls ../common/test_env* | indent1
291 #Vars for A1 interface version and container count
303 # Vars to switch between http and https. Extra curl flag needed for https
304 export RIC_SIM_HTTPX="http"
305 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
306 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
307 export RIC_SIM_CERT_MOUNT_DIR="./cert"
309 export MR_HTTPX="http"
310 export MR_PORT=$MR_INTERNAL_PORT
311 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker net
313 export CR_HTTPX="http"
314 export CR_PORT=$CR_INTERNAL_PORT
315 export CR_LOCAL_PORT=$CR_EXTERNAL_PORT #When CR is running outside the docker net
316 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
318 export PROD_STUB_HTTPX="http"
319 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
320 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT #When CR is running outside the docker net
321 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
323 export SDNC_HTTPX="http"
324 export SDNC_PORT=$SDNC_INTERNAL_PORT
325 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net
327 echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
329 #Temp var to check for image variable name errors
331 #Create a file with image info for later printing as a table
332 image_list_file="./tmp/.image-list"
333 echo -e " Container\tImage\ttag" > $image_list_file
335 # Check if image env var is set and if so export the env var with image to use (used by docker compose files)
336 # arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name> <app-short-name>
337 __check_image_var() {
338 if [ $# -ne 6 ]; then
339 echo "Expected arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name> <app-short-name>"
343 __check_included_image $6
344 if [ $? -ne 0 ]; then
345 echo -e "$1\t<image-excluded>\t<no-tag>" >> $image_list_file
346 # Image is excluded since the corresponding app is not used in this test
350 #Create var from the input var names
354 if [ -z $image ]; then
355 echo -e $RED"\$"$4" not set in $TEST_ENV_VAR_FILE"$ERED
358 tmp=$tmp"<no-image>\t"
363 echo -e $RED"\$"$5" not set in $TEST_ENV_VAR_FILE"$ERED
370 echo -e "$tmp" >> $image_list_file
372 export "${3}"=$image":"$tag
374 #echo " Configured image for ${1} (script start arg=${2}): "$image":"$tag
378 #Check if app local image shall override remote image
379 # Possible IDs for local image override: PA, CP, SDNC, RICSIM, ECS
380 __check_image_local_override() {
381 for im in $USE_LOCAL_IMAGES; do
382 if [ "$1" == "$im" ]; then
389 # Check if app uses image included in this test run
390 # Returns 0 if image is included, 1 if not
391 # Possible IDs for image inclusion: CBS, CONSUL, CP, CR, ECS, MR, PA, PRODSTUB, RICSIM, SDNC
392 __check_included_image() {
393 for im in $INCLUDED_IMAGES; do
394 if [ "$1" == "$im" ]; then
401 # Check that image env setting are available
404 if [ $START_ARG == "local" ]; then
407 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG" PA
409 #Local Control Panel image
410 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG" CP
413 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG" SDNC
416 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG" RICSIM
418 elif [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
420 __check_image_local_override 'PA'
421 if [ $? -eq 0 ]; then
423 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_REMOTE_IMAGE" "POLICY_AGENT_REMOTE_IMAGE_TAG" PA
426 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG" PA
429 __check_image_local_override 'CP'
430 if [ $? -eq 0 ]; then
431 #Remote Control Panel image
432 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE_TAG" CP
434 #Local Control Panel image
435 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG" CP
438 __check_image_local_override 'SDNC'
439 if [ $? -eq 0 ]; then
441 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE_TAG" SDNC
444 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG" SDNC
447 __check_image_local_override 'RICSIM'
448 if [ $? -eq 0 ]; then
449 #Remote ric sim image
450 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_REMOTE_IMAGE" "RIC_SIM_REMOTE_IMAGE_TAG" RICSIM
453 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG" RICSIM
456 __check_image_local_override 'ECS'
457 if [ $? -eq 0 ]; then
459 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_REMOTE_IMAGE" "ECS_REMOTE_IMAGE_TAG" ECS
462 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_LOCAL_IMAGE" "ECS_LOCAL_IMAGE_TAG" ECS
466 #Should never get here....
467 echo "Unknow args: "$@
472 # These images are not built as part of this project official images, just check that env vars are set correctly
473 __check_image_var " Message Router" $START_ARG "MRSTUB_IMAGE" "MRSTUB_LOCAL_IMAGE" "MRSTUB_LOCAL_IMAGE_TAG" MR
474 __check_image_var " Callback Receiver" $START_ARG "CR_IMAGE" "CR_LOCAL_IMAGE" "CR_LOCAL_IMAGE_TAG" CR
475 __check_image_var " Producer stub" $START_ARG "PROD_STUB_IMAGE" "PROD_STUB_LOCAL_IMAGE" "PROD_STUB_LOCAL_IMAGE_TAG" PRODSTUB
476 __check_image_var " Consul" $START_ARG "CONSUL_IMAGE" "CONSUL_REMOTE_IMAGE" "CONSUL_REMOTE_IMAGE_TAG" CONSUL
477 __check_image_var " CBS" $START_ARG "CBS_IMAGE" "CBS_REMOTE_IMAGE" "CBS_REMOTE_IMAGE_TAG" CBS
478 __check_image_var " SDNC DB" $START_ARG "SDNC_DB_IMAGE" "SDNC_DB_REMOTE_IMAGE" "SDNC_DB_REMOTE_IMAGE_TAG" SDNC #Uses sdnc app name
480 #Errors in image setting - exit
481 if [ $IMAGE_ERR -ne 0 ]; then
485 #Print a tables of the image settings
486 echo -e $BOLD"Images configured for start arg: "$START $EBOLD
487 column -t -s $'\t' $image_list_file
492 #Set the SIM_GROUP var
493 echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
494 if [ -z "$SIM_GROUP" ]; then
495 SIM_GROUP=$PWD/../simulator-group
496 if [ ! -d $SIM_GROUP ]; then
497 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
498 echo -e $RED"Please set the SIM_GROUP manually in the applicable $TEST_ENV_VAR_FILE"$ERED
501 echo " SIM_GROUP auto set to: " $SIM_GROUP
503 elif [ $SIM_GROUP = *simulator_group ]; then
504 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
507 echo " SIM_GROUP env var already set to: " $SIM_GROUP
512 #Temp var to check for image pull errors
515 #Function to check if image exist and stop+remove the container+pull new images as needed
516 #args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
517 __check_and_pull_image() {
519 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
520 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
521 tmp_im=$(docker images --format $format_string ${4})
523 if [ $1 == "local" ]; then
524 if [ -z "$tmp_im" ]; then
525 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
529 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
531 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
532 if [ $1 == "remote-remove" ]; then
533 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
534 tmp="$(docker ps -aq --filter name=${3})"
535 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
536 docker stop $tmp &> ./tmp/.dockererr
537 if [ $? -ne 0 ]; then
540 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
545 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
546 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
547 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
548 docker rm $tmp &> ./tmp/.dockererr
549 if [ $? -ne 0 ]; then
552 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
557 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
558 echo -ne " Removing image - ${SAMELINE}"
559 tmp="$(docker images -q ${4})" &> /dev/null
560 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
561 docker rmi --force $4 &> ./tmp/.dockererr
562 if [ $? -ne 0 ]; then
565 echo -e $RED" Image could not be removed - try manual removal of the image"$ERED
569 echo -e " Removing image - "$GREEN"removed"$EGREEN
571 echo -e " Removing image - "$GREEN"image not in repository"$EGREEN
575 if [ -z "$tmp_im" ]; then
576 echo -ne " Pulling image${SAMELINE}"
577 docker pull $4 &> ./tmp/.dockererr
578 tmp_im=$(docker images ${4} | grep -v REPOSITORY)
579 if [ -z "$tmp_im" ]; then
581 echo -e " Pulling image -$RED could not be pulled"$ERED
586 echo -e " Pulling image -$GREEN Pulled $EGREEN"
588 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
595 echo -e $BOLD"Pulling configured images, if needed"$EBOLD
597 __check_included_image 'PA'
598 if [ $? -eq 0 ]; then
599 START_ARG_MOD=$START_ARG
600 __check_image_local_override 'PA'
601 if [ $? -eq 1 ]; then
602 START_ARG_MOD="local"
604 app="Policy Agent"; __check_and_pull_image $START_ARG_MOD "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
606 echo -e $YELLOW" Excluding PA image from image check/pull"$EYELLOW
609 __check_included_image 'ECS'
610 if [ $? -eq 0 ]; then
611 START_ARG_MOD=$START_ARG
612 __check_image_local_override 'ECS'
613 if [ $? -eq 1 ]; then
614 START_ARG_MOD="local"
616 app="ECS"; __check_and_pull_image $START_ARG_MOD "$app" $ECS_APP_NAME $ECS_IMAGE
618 echo -e $YELLOW" Excluding ECS image from image check/pull"$EYELLOW
621 __check_included_image 'CP'
622 if [ $? -eq 0 ]; then
623 START_ARG_MOD=$START_ARG
624 __check_image_local_override 'CP'
625 if [ $? -eq 1 ]; then
626 START_ARG_MOD="local"
628 app="Non-RT RIC Control Panel"; __check_and_pull_image $START_ARG_MOD "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
630 echo -e $YELLOW" Excluding Non-RT RIC Control Panel image from image check/pull"$EYELLOW
633 __check_included_image 'RICSIM'
634 if [ $? -eq 0 ]; then
635 START_ARG_MOD=$START_ARG
636 __check_image_local_override 'RICSIM'
637 if [ $? -eq 1 ]; then
638 START_ARG_MOD="local"
640 app="Near-RT RIC Simulator"; __check_and_pull_image $START_ARG_MOD "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
642 echo -e $YELLOW" Excluding Near-RT RIC Simulator image from image check/pull"$EYELLOW
646 __check_included_image 'CONSUL'
647 if [ $? -eq 0 ]; then
648 app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
650 echo -e $YELLOW" Excluding Consul image from image check/pull"$EYELLOW
653 __check_included_image 'CBS'
654 if [ $? -eq 0 ]; then
655 app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE
657 echo -e $YELLOW" Excluding CBS image from image check/pull"$EYELLOW
660 __check_included_image 'SDNC'
661 if [ $? -eq 0 ]; then
662 START_ARG_MOD=$START_ARG
663 __check_image_local_override 'SDNC'
664 if [ $? -eq 1 ]; then
665 START_ARG_MOD="local"
667 app="SDNC A1 Controller"; __check_and_pull_image $START_ARG_MOD "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
668 app="SDNC DB"; __check_and_pull_image $START_ARG "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
670 echo -e $YELLOW" Excluding SDNC image and related DB image from image check/pull"$EYELLOW
673 #Errors in image setting - exit
674 if [ $IMAGE_ERR -ne 0 ]; then
676 echo "#################################################################################################"
677 echo -e $RED"One or more images could not be pulled or containers using the images could not be stopped/removed"$ERED
678 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
679 echo "#################################################################################################"
686 echo -e $BOLD"Building images needed for test"$EBOLD
689 __check_included_image 'MR'
690 if [ $? -eq 0 ]; then
693 echo " Building mrstub image: $MRSTUB_LOCAL_IMAGE:$MRSTUB_LOCAL_IMAGE_TAG"
694 docker build -t $MRSTUB_LOCAL_IMAGE . &> .dockererr
695 if [ $? -eq 0 ]; then
696 echo -e $GREEN" Build Ok"$EGREEN
698 echo -e $RED" Build Failed"$ERED
701 echo -e $RED"Exiting...."$ERED
706 echo -e $YELLOW" Excluding mrstub from image build"$EYELLOW
709 __check_included_image 'CR'
710 if [ $? -eq 0 ]; then
712 echo " Building Callback Receiver image: $CR_LOCAL_IMAGE:$CR_IMAGE_TAG"
713 docker build -t $CR_LOCAL_IMAGE . &> .dockererr
714 if [ $? -eq 0 ]; then
715 echo -e $GREEN" Build Ok"$EGREEN
717 echo -e $RED" Build Failed"$ERED
720 echo -e $RED"Exiting...."$ERED
725 echo -e $YELLOW" Excluding Callback Receiver from image build"$EYELLOW
728 __check_included_image 'PRODSTUB'
729 if [ $? -eq 0 ]; then
731 echo " Building Producer stub image: $PROD_STUB_LOCAL_IMAGE:$PROD_STUB_LOCAL_IMAGE_TAG"
732 docker build -t $PROD_STUB_LOCAL_IMAGE . &> .dockererr
733 if [ $? -eq 0 ]; then
734 echo -e $GREEN" Build Ok"$EGREEN
736 echo -e $RED" Build Failed"$ERED
739 echo -e $RED"Exiting...."$ERED
744 echo -e $YELLOW" Excluding Producer stub from image build"$EYELLOW
749 # Create a table of the images used in the script
750 echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
752 docker_tmp_file=./tmp/.docker-images-table
753 format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\\t{{.CreatedAt}}"
754 echo -e " Application\tRepository\tTag\tCreated since\tSize\tCreated at" > $docker_tmp_file
755 __check_included_image 'PA'
756 if [ $? -eq 0 ]; then
757 echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
759 __check_included_image 'ECS'
760 if [ $? -eq 0 ]; then
761 echo -e " ECS\t$(docker images --format $format_string $ECS_IMAGE)" >> $docker_tmp_file
763 __check_included_image 'CP'
764 if [ $? -eq 0 ]; then
765 echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
767 __check_included_image 'RICSIM'
768 if [ $? -eq 0 ]; then
769 echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
771 __check_included_image 'MR'
772 if [ $? -eq 0 ]; then
773 echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
775 __check_included_image 'CR'
776 if [ $? -eq 0 ]; then
777 echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
779 __check_included_image 'PRODSTUB'
780 if [ $? -eq 0 ]; then
781 echo -e " Produccer stub\t$(docker images --format $format_string $PROD_STUB_IMAGE)" >> $docker_tmp_file
783 __check_included_image 'CONSUL'
784 if [ $? -eq 0 ]; then
785 echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
787 __check_included_image 'CBS'
788 if [ $? -eq 0 ]; then
789 echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
791 __check_included_image 'SDNC'
792 if [ $? -eq 0 ]; then
793 echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
794 echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
797 column -t -s $'\t' $docker_tmp_file
801 echo -e $BOLD"======================================================="$EBOLD
802 echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
803 echo -e $BOLD"======================================================="$EBOLD
806 # Function to print the test result, shall be the last cmd in a test script
808 # (Function for test scripts)
812 duration=$((TCTEST_END-TCTEST_START))
814 echo "-------------------------------------------------------------------------------------------------"
815 echo "------------------------------------- Test case: "$ATC
816 echo "------------------------------------- Ended: "$(date)
817 echo "-------------------------------------------------------------------------------------------------"
818 echo "-- Description: "$TC_ONELINE_DESCR
819 echo "-- Execution time: " $duration " seconds"
820 echo "-- Used env file: "$TEST_ENV_VAR_FILE
821 echo "-------------------------------------------------------------------------------------------------"
822 echo "------------------------------------- RESULTS"
826 if [ $RES_DEVIATION -gt 0 ]; then
827 echo "Test case deviations"
828 echo "===================================="
832 echo "Timer measurement in the test script"
833 echo "===================================="
834 column -t -s $'\t' $TIMER_MEASUREMENTS
837 total=$((RES_PASS+RES_FAIL))
838 if [ $RES_TEST -eq 0 ]; then
839 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
840 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
841 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
842 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
843 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
844 elif [ $total != $RES_TEST ]; then
845 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
846 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
847 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
848 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
849 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
850 elif [ $RES_CONF_FAIL -ne 0 ]; then
851 echo -e "\033[1mOne or more configure regest has failed. Check the script log....\033[0m"
852 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
853 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
854 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
855 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
856 elif [ $RES_PASS = $RES_TEST ]; then
857 echo -e "All tests \033[32m\033[1mPASS\033[0m"
858 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
859 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
860 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
861 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
864 # Update test suite counter
865 if [ -f .tmp_tcsuite_pass_ctr ]; then
866 tmpval=$(< .tmp_tcsuite_pass_ctr)
868 echo $tmpval > .tmp_tcsuite_pass_ctr
870 if [ -f .tmp_tcsuite_pass ]; then
871 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
873 #Create file with OK exit code
874 echo "0" > "$PWD/.result$ATC.txt"
876 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
877 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
878 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
879 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
880 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
882 # Update test suite counter
883 if [ -f .tmp_tcsuite_fail_ctr ]; then
884 tmpval=$(< .tmp_tcsuite_fail_ctr)
886 echo $tmpval > .tmp_tcsuite_fail_ctr
888 if [ -f .tmp_tcsuite_fail ]; then
889 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
893 echo "++++ Number of tests: "$RES_TEST
894 echo "++++ Number of passed tests: "$RES_PASS
895 echo "++++ Number of failed tests: "$RES_FAIL
897 echo "++++ Number of failed configs: "$RES_CONF_FAIL
899 echo "++++ Number of test case deviations: "$RES_DEVIATION
901 echo "------------------------------------- Test case complete ---------------------------------"
902 echo "-------------------------------------------------------------------------------------------------"
906 #####################################################################
907 ###### Functions for start, configuring, stoping, cleaning etc ######
908 #####################################################################
910 # Start timer for time measurement
911 # args - (any args will be printed though)
913 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
915 echo " Timer started"
918 # Print the value of the time (in seconds)
919 # args - <timer message to print> - timer value and message will be printed both on screen
920 # and in the timer measurement report
922 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
923 if [ $# -lt 1 ]; then
925 __print_err "need 1 or more args, <timer message to print>" $@
928 duration=$(($SECONDS-$TC_TIMER))
929 if [ $duration -eq 0 ]; then
932 duration=$duration" seconds"
934 echo " Timer duration :" $duration
936 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
939 # Print the value of the time (in seconds) and reset the timer
940 # args - <timer message to print> - timer value and message will be printed both on screen
941 # and in the timer measurement report
942 print_and_reset_timer() {
943 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
944 if [ $# -lt 1 ]; then
946 __print_err "need 1 or more args, <timer message to print>" $@
949 duration=$(($SECONDS-$TC_TIMER))" seconds"
950 if [ $duration -eq 0 ]; then
953 duration=$duration" seconds"
955 echo " Timer duration :" $duration
959 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
962 # Print info about a deviations from intended tests
963 # Each deviation counted is also printed in the testreport
964 # args <deviation message to print>
966 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
967 if [ $# -lt 1 ]; then
969 __print_err "need 1 or more args, <deviation message to print>" $@
973 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
974 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
978 # Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
979 __check_stop_at_error() {
980 if [ $STOP_AT_ERROR -eq 1 ]; then
981 echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
982 store_logs "STOP_AT_ERROR"
988 # Check if app name var is set. If so return the app name otherwise return "NOTSET"
990 if [ $# -eq 1 ]; then
997 # Stop and remove all containers
999 # (Function for test scripts)
1000 clean_containers() {
1002 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
1004 CONTAINTER_NAMES=("Policy Agent " $(__check_app_name $POLICY_AGENT_APP_NAME)\
1005 "ECS " $(__check_app_name $ECS_APP_NAME)\
1006 "Non-RT RIC Simulator(s)" $(__check_app_name $RIC_SIM_PREFIX)\
1007 "Message Router " $(__check_app_name $MR_APP_NAME)\
1008 "Callback Receiver " $(__check_app_name $CR_APP_NAME)\
1009 "Producer stub " $(__check_app_name $PROD_STUB_APP_NAME)\
1010 "Control Panel " $(__check_app_name $CONTROL_PANEL_APP_NAME)\
1011 "SDNC A1 Controller " $(__check_app_name $SDNC_APP_NAME)\
1012 "SDNC DB " $(__check_app_name $SDNC_DB_APP_NAME)\
1013 "CBS " $(__check_app_name $CBS_APP_NAME)\
1014 "Consul " $(__check_app_name $CONSUL_APP_NAME))
1016 nw=0 # Calc max width of container name, to make a nice table
1017 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
1019 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
1020 nw=${#CONTAINTER_NAMES[i]}
1024 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
1025 APP="${CONTAINTER_NAMES[i]}"
1026 CONTR="${CONTAINTER_NAMES[i+1]}"
1027 if [ $CONTR != "NOTSET" ]; then
1028 for((w=${#CONTR}; w<$nw; w=w+1)); do
1031 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
1032 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1033 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
1034 docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1035 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
1041 echo -e $BOLD" Removing docker network"$EBOLD
1042 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
1043 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
1044 docker network rm $DOCKER_SIM_NWNAME | indent2
1045 if [ $? -ne 0 ]; then
1046 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
1050 echo -e "$GREEN Done$EGREEN"
1052 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
1053 docker network prune --force | indent2
1054 echo -e "$GREEN Done$EGREEN"
1056 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
1057 docker volume prune --force | indent2
1058 echo -e "$GREEN Done$EGREEN"
1060 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
1061 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
1062 echo -e "$GREEN Done$EGREEN"
1065 CONTRS=$(docker ps | awk '$1 != "CONTAINER" { n++ }; END { print n+0 }')
1066 if [ $? -eq 0 ]; then
1067 if [ $CONTRS -ne 0 ]; then
1068 echo -e $RED"Containers running, may cause distubance to the test case"$ERED
1074 # Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
1076 # (Function for test scripts)
1077 auto_clean_containers() {
1079 if [ "$AUTO_CLEAN" == "auto" ]; then
1080 echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
1085 # Function to sleep a test case for a numner of seconds. Prints the optional text args as info
1086 # args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
1087 # (Function for test scripts)
1090 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1091 if [ $# -lt 1 ]; then
1093 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
1096 #echo "---- Sleep for " $1 " seconds ---- "$2
1098 duration=$((SECONDS-start))
1099 while [ $duration -lt $1 ]; do
1100 echo -ne " Slept for ${duration} seconds${SAMELINE}"
1102 duration=$((SECONDS-start))
1104 echo -ne " Slept for ${duration} seconds${SAMELINE}"
1108 # Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
1109 # Not to be called from the test script itself.
1111 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
1112 if [ $# -gt 1 ]; then
1113 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
1118 # Helper function to get a the port of a specific ric simulatpor
1120 # (Not for test scripts)
1122 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
1123 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
1125 if [[ "$res" =~ ^[0-9]+$ ]]; then
1132 # Function to create the docker network for the test
1133 # Not to be called from the test script itself.
1134 __create_docker_network() {
1135 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
1136 if [ $? -ne 0 ]; then
1137 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
1140 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
1141 echo -e " Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
1142 docker network create $DOCKER_SIM_NWNAME | indent2
1143 if [ $? -ne 0 ]; then
1144 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
1147 echo -e "$GREEN Done$EGREEN"
1150 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
1154 # Check if container is started by calling url on localhost using a port, expects response code 2XX
1155 # args: <container-name> <port> <url> https|https
1156 # Not to be called from the test script itself.
1157 __check_container_start() {
1159 if [ $# -ne 4 ]; then
1161 elif [ $4 != "http" ] && [ $4 != "https" ]; then
1164 if [ $paramError -ne 0 ]; then
1166 __print_err "need 3 args, <container-name> <port> <url> https|https" $@
1169 echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
1173 if [[ $appname != "STANDALONE_"* ]] ; then
1175 for i in {1..10}; do
1176 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
1177 echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
1184 if [ $app_started -eq 0 ]; then
1187 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
1188 echo -e $RED" Stopping script..."$ERED
1191 if [ $localport -eq 0 ]; then
1192 while [ $localport -eq 0 ]; do
1193 echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
1194 localport=$(__find_sim_port $appname)
1196 echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
1198 echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
1204 echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
1206 for i in {1..50}; do
1207 if [ $4 == "https" ]; then
1208 result="$(__do_curl "-k https://localhost:"${localport}${url})"
1210 result="$(__do_curl $LOCALHOST${localport}${url})"
1212 if [ $? -eq 0 ]; then
1213 if [ ${#result} -gt 15 ]; then
1214 #If response is too long, truncate
1215 result="...response text too long, omitted"
1217 echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
1218 echo -ne " Container $BOLD${appname}$EBOLD$GREEN is alive$EGREEN, responds to service status:$GREEN $result $EGREEN after $(($SECONDS-$TSTART)) seconds"
1223 while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
1224 echo -ne " Waiting for container ${appname} service status...$(($SECONDS-$TSTART)) seconds, retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
1230 if [ "$pa_st" = "false" ]; then
1232 echo -e $RED" Container ${appname} did not respond to service status in $(($SECONDS-$TSTART)) seconds"$ERED
1241 # Function to start a container and wait until it responds on the given port and url.
1242 #args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
1243 __start_container() {
1245 variableArgCount=$(($#-2))
1246 if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
1248 __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 ]*" $@
1252 __create_docker_network
1258 if [ "$2" == "NODOCKERARGS" ]; then
1259 docker-compose up -d &> .dockererr
1260 if [ $? -ne 0 ]; then
1261 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1263 echo -e $RED"Stopping script...."$ERED
1266 elif [ "$2" == "STANDALONE" ]; then
1267 echo "Skipping docker-compose"
1269 docker-compose up -d $2 &> .dockererr
1270 if [ $? -ne 0 ]; then
1271 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1273 echo -e $RED"Stopping script...."$ERED
1278 if [ "$2" == "STANDALONE" ]; then
1279 app_prefix="STANDALONE_"
1283 while [ $cntr -lt $variableArgCount ]; do
1284 app=$app_prefix$1; shift;
1290 __check_container_start "$app" "$port" "$url" $httpx
1298 # Generate a UUID to use as prefix for policy ids
1300 UUID=$(python3 -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
1301 #Reduce length to make space for serial id, us 'a' as marker where the serial id is added
1302 UUID=${UUID:0:${#UUID}-4}"a"
1305 ####################
1306 ### Consul functions
1307 ####################
1309 # Function to load config from a file into consul for the Policy Agent
1310 # arg: <json-config-file>
1311 # (Function for test scripts)
1312 consul_config_app() {
1314 echo -e $BOLD"Configuring Consul"$EBOLD
1316 if [ $# -ne 1 ]; then
1318 __print_err "need one arg, <json-config-file>" $@
1322 echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1
1324 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
1325 result=$(__do_curl "$curlString")
1326 if [ $? -ne 0 ]; then
1327 echo -e $RED" FAIL - json config could not be loaded to consul" $ERED
1331 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
1332 echo $body > "./tmp/.output"$1
1334 if [ $? -ne 0 ]; then
1335 echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED
1340 targetJson="{\"config\":"$targetJson"}"
1341 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1342 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1343 if [ $res -ne 0 ]; then
1344 echo -e $RED" FAIL - policy json config read from consul/cbs is not equal to the intended json config...." $ERED
1348 echo -e $GREEN" Config loaded ok to consul"$EGREEN
1356 # Function to perpare the consul configuration according to the current simulator configuration
1357 # args: SDNC|NOSDNC <output-file>
1358 # (Function for test scripts)
1359 prepare_consul_config() {
1360 echo -e $BOLD"Prepare Consul config"$EBOLD
1362 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
1364 if [ $# != 2 ]; then
1366 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
1370 if [ $1 == "SDNC" ]; then
1371 echo -e " Config$BOLD including SDNC$EBOLD configuration"
1372 elif [ $1 == "NOSDNC" ]; then
1373 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
1376 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
1381 if [ $1 == "SDNC" ]; then
1382 config_json=$config_json"\n \"controller\": ["
1383 config_json=$config_json"\n {"
1384 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
1385 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1386 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://$SDNC_APP_NAME:$SDNC_PORT\","
1388 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://localhost:$SDNC_LOCAL_PORT\","
1390 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
1391 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
1392 config_json=$config_json"\n }"
1393 config_json=$config_json"\n ],"
1396 config_json=$config_json"\n \"streams_publishes\": {"
1397 config_json=$config_json"\n \"dmaap_publisher\": {"
1398 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1399 config_json=$config_json"\n \"dmaap_info\": {"
1400 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1401 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_WRITE_URL\""
1403 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_WRITE_URL\""
1405 config_json=$config_json"\n }"
1406 config_json=$config_json"\n }"
1407 config_json=$config_json"\n },"
1408 config_json=$config_json"\n \"streams_subscribes\": {"
1409 config_json=$config_json"\n \"dmaap_subscriber\": {"
1410 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1411 config_json=$config_json"\n \"dmaap_info\": {"
1412 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1413 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_READ_URL\""
1415 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_READ_URL\""
1417 config_json=$config_json"\n }"
1418 config_json=$config_json"\n }"
1419 config_json=$config_json"\n },"
1421 config_json=$config_json"\n \"ric\": ["
1423 rics=$(docker ps | grep $RIC_SIM_PREFIX | awk '{print $NF}')
1425 if [ $? -ne 0 ] || [ -z "$rics" ]; then
1426 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
1432 for ric in $rics; do
1433 if [ $cntr -gt 0 ]; then
1434 config_json=$config_json"\n ,"
1436 config_json=$config_json"\n {"
1437 config_json=$config_json"\n \"name\": \"$ric\","
1438 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1439 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
1441 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://localhost:$(__find_sim_port $ric)\","
1443 if [ $1 == "SDNC" ]; then
1444 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
1446 config_json=$config_json"\n \"managedElementIds\": ["
1447 config_json=$config_json"\n \"me1_$ric\","
1448 config_json=$config_json"\n \"me2_$ric\""
1449 config_json=$config_json"\n ]"
1450 config_json=$config_json"\n }"
1454 config_json=$config_json"\n ]"
1455 config_json=$config_json"\n}"
1458 printf "$config_json">$2
1464 # Start Consul and CBS
1466 # (Function for test scripts)
1467 start_consul_cbs() {
1469 echo -e $BOLD"Starting Consul and CBS"$EBOLD
1470 __check_included_image 'CONSUL'
1471 if [ $? -eq 1 ]; then
1472 echo -e $RED"The Consul image has not been checked for this test run due to arg to the test script"$ERED
1473 echo -e $RED"Consul will not be started"$ERED
1476 __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" "http" \
1477 "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck" "http"
1480 ###########################
1481 ### RIC Simulator functions
1482 ###########################
1484 use_simulator_http() {
1485 echo -e "Using $BOLD http $EBOLD towards the simulators"
1486 export RIC_SIM_HTTPX="http"
1487 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1488 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
1492 use_simulator_https() {
1493 echo -e "Using $BOLD https $EBOLD towards the simulators"
1494 export RIC_SIM_HTTPX="https"
1495 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1496 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
1500 # Start one group (ricsim_g1, ricsim_g2 .. ricsim_g5) with a number of RIC Simulators using a given A interface
1501 # 'ricsim' may be set on command line to other prefix
1502 # args: ricsim_g1|ricsim_g2|ricsim_g3|ricsim_g4|ricsim_g5 <count> <interface-id>
1503 # (Function for test scripts)
1504 start_ric_simulators() {
1506 echo -e $BOLD"Starting RIC Simulators"$EBOLD
1508 __check_included_image 'RICSIM'
1509 if [ $? -eq 1 ]; then
1510 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
1511 echo -e $RED"The Near-RT RIC Simulartor(s) will not be started"$ERED
1515 RIC1=$RIC_SIM_PREFIX"_g1"
1516 RIC2=$RIC_SIM_PREFIX"_g2"
1517 RIC3=$RIC_SIM_PREFIX"_g3"
1518 RIC4=$RIC_SIM_PREFIX"_g4"
1519 RIC5=$RIC_SIM_PREFIX"_g5"
1521 if [ $# != 3 ]; then
1523 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
1526 echo " $2 simulators using basename: $1 on interface: $3"
1527 #Set env var for simulator count and A1 interface vesion for the given group
1528 if [ $1 == "$RIC1" ]; then
1531 elif [ $1 == "$RIC2" ]; then
1534 elif [ $1 == "$RIC3" ]; then
1537 elif [ $1 == "$RIC4" ]; then
1540 elif [ $1 == "$RIC5" ]; then
1545 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
1549 # Create .env file to compose project, all ric container will get this prefix
1550 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
1552 export G1_A1_VERSION
1553 export G2_A1_VERSION
1554 export G3_A1_VERSION
1555 export G4_A1_VERSION
1556 export G5_A1_VERSION
1558 docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT --scale g4=$G4_COUNT --scale g5=$G5_COUNT"
1561 while [ $cntr -le $2 ]; do
1564 app_data="$app_data $app $port / "$RIC_SIM_HTTPX
1567 __start_container ric "$docker_args" $app_data
1571 ###########################
1572 ### Control Panel functions
1573 ###########################
1575 # Start the Control Panel container
1577 # (Function for test scripts)
1578 start_control_panel() {
1580 echo -e $BOLD"Starting Control Panel"$EBOLD
1581 __check_included_image 'CP'
1582 if [ $? -eq 1 ]; then
1583 echo -e $RED"The Control Panel image has not been checked for this test run due to arg to the test script"$ERED
1584 echo -e $RED"The Control Panel will not be started"$ERED
1587 __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/" "http"
1595 # Start the SDNC A1 Controller
1597 # (Function for test scripts)
1600 echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
1602 __check_included_image 'SDNC'
1603 if [ $? -eq 1 ]; then
1604 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
1605 echo -e $RED"SDNC will not be started"$ERED
1609 __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT $SDNC_ALIVE_URL "http"
1614 echo -e "Using $BOLD http $EBOLD towards SDNC"
1615 export SDNC_HTTPX="http"
1616 export SDNC_PORT=$SDNC_INTERNAL_PORT
1617 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT
1622 echo -e "Using $BOLD https $EBOLD towards SDNC"
1623 export SDNC_HTTPX="https"
1624 export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT
1625 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT
1629 #####################
1630 ### MR stub functions
1631 #####################
1633 # Start the Message Router stub interface in the simulator group
1635 # (Function for test scripts)
1638 echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
1639 __check_included_image 'MR'
1640 if [ $? -eq 1 ]; then
1641 echo -e $RED"The Message Router image has not been checked for this test run due to arg to the test script"$ERED
1642 echo -e $RED"The Message Router will not be started"$ERED
1645 export MR_CERT_MOUNT_DIR="./cert"
1646 __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/" "http"
1650 echo -e "Using $BOLD http $EBOLD towards MR"
1651 export MR_HTTPX="http"
1652 export MR_PORT=$MR_INTERNAL_PORT
1653 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT
1658 echo -e "Using $BOLD https $EBOLD towards MR"
1659 export MR_HTTPX="https"
1660 export MR_PORT=$MR_INTERNAL_SECURE_PORT
1661 export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT
1670 # Start the Callback reciver in the simulator group
1672 # (Function for test scripts)
1675 echo -e $BOLD"Starting Callback Receiver"$EBOLD
1676 __check_included_image 'CR'
1677 if [ $? -eq 1 ]; then
1678 echo -e $RED"The Callback Receiver image has not been checked for this test run due to arg to the test script"$ERED
1679 echo -e $RED"The Callback Receiver will not be started"$ERED
1682 __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/" "http"
1687 echo -e "Using $BOLD http $EBOLD towards CR"
1688 export CR_HTTPX="http"
1689 export CR_PORT=$CR_INTERNAL_PORT
1690 export CR_LOCAL_PORT=$CR_EXTERNAL_PORT
1691 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
1696 echo -e "Using $BOLD https $EBOLD towards CR"
1697 export CR_HTTPX="https"
1698 export CR_PORT=$CR_INTERNAL_SECURE_PORT
1699 export CR_LOCAL_PORT=$CR_EXTERNAL_SECURE_PORT
1700 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
1704 ###########################
1705 ### Producer stub functions
1706 ###########################
1708 # Start the Producer stub in the simulator group
1710 # (Function for test scripts)
1713 echo -e $BOLD"Starting Producer stub"$EBOLD
1714 __check_included_image 'PRODSTUB'
1715 if [ $? -eq 1 ]; then
1716 echo -e $RED"The Producer stub image has not been checked for this test run due to arg to the test script"$ERED
1717 echo -e $RED"The Producer stub will not be started"$ERED
1720 __start_container prodstub NODOCKERARGS $PROD_STUB_APP_NAME $PROD_STUB_EXTERNAL_PORT "/" "http"
1724 use_prod_stub_http() {
1725 echo -e "Using $BOLD http $EBOLD towards Producer stub"
1726 export PROD_STUB_HTTPX="http"
1727 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
1728 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT
1729 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
1733 use_prod_stub_https() {
1734 echo -e "Using $BOLD https $EBOLD towards Producer stub"
1735 export PROD_STUB_HTTPX="https"
1736 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_SECURE_PORT
1737 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_SECURE_PORT
1738 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
1742 ###########################
1743 ### Policy Agents functions
1744 ###########################
1746 # Use an agent on the local machine instead of container
1747 use_agent_stand_alone() {
1751 # Start the policy agent
1753 # (Function for test scripts)
1754 start_policy_agent() {
1756 echo -e $BOLD"Starting Policy Agent"$EBOLD
1758 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1759 __check_included_image 'PA'
1760 if [ $? -eq 1 ]; then
1761 echo -e $RED"The Policy Agent image has not been checked for this test run due to arg to the test script"$ERED
1762 echo -e $RED"The Policy Agent will not be started"$ERED
1765 __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1767 echo -e $RED"The consul config produced by this test script (filename '<fullpath-to-autotest-dir>.output<file-name>"$ERED
1768 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
1769 echo -e $RED"application.yaml"$ERED
1770 echo -e $RED"The application jar may need to be built before continuing"$ERED
1771 echo -e $RED"The agent shall now be running on port $POLICY_AGENT_EXTERNAL_PORT for http"$ERED
1773 read -p "<press any key to continue>"
1774 __start_container policy_agent "STANDALONE" $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1779 # All calls to the agent will be directed to the agent REST interface from now on
1781 # (Function for test scripts)
1782 use_agent_rest_http() {
1783 echo -e "Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
1784 export ADAPTER=$RESTBASE
1788 # All calls to the agent will be directed to the agent REST interface from now on
1790 # (Function for test scripts)
1791 use_agent_rest_https() {
1792 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
1793 export ADAPTER=$RESTBASE_SECURE
1798 # All calls to the agent will be directed to the agent dmaap interface over http from now on
1800 # (Function for test scripts)
1801 use_agent_dmaap_http() {
1802 echo -e "Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
1803 export ADAPTER=$DMAAPBASE
1808 # All calls to the agent will be directed to the agent dmaap interface over https from now on
1810 # (Function for test scripts)
1811 use_agent_dmaap_https() {
1812 echo -e "Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
1813 export ADAPTER=$DMAAPBASE_SECURE
1818 # Turn on debug level tracing in the agent
1820 # (Function for test scripts)
1822 echo -e $BOLD"Setting agent debug"$EBOLD
1823 actuator="/actuator/loggers/org.oransc.policyagent"
1824 if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
1825 actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
1827 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
1828 result=$(__do_curl "$curlString")
1829 if [ $? -ne 0 ]; then
1830 __print_err "could not set debug mode" $@
1838 # Turn on trace level tracing in the agent
1840 # (Function for test scripts)
1842 echo -e $BOLD"Setting agent trace"$EBOLD
1843 actuator="/actuator/loggers/org.oransc.policyagent"
1844 if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
1845 actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
1847 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
1848 result=$(__do_curl "$curlString")
1849 if [ $? -ne 0 ]; then
1850 __print_err "could not set trace mode" $@
1858 # Perform curl retries when making direct call to the agent for the specified http response codes
1859 # Speace separated list of http response codes
1860 # args: [<response-code>]*
1861 use_agent_retries() {
1862 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
1863 AGENT_RETRY_CODES=$@
1868 ###########################
1870 ###########################
1874 # (Function for test scripts)
1877 echo -e $BOLD"Starting ECS"$EBOLD
1882 cd $ECS_HOST_MNT_DIR
1883 if [ -d database ]; then
1884 echo -e $BOLD" Cleaning files in mounted dir: $PWD/database"$EBOLD
1885 rm database/* > /dev/null
1886 if [ $? -ne 0 ]; then
1887 echo -e $RED" Cannot remove database files in: $PWD"$ERED
1891 echo " No files in mounted dir or dir does not exists"
1895 __check_included_image 'ECS'
1896 if [ $? -eq 1 ]; then
1897 echo -e $RED"The ECS image has not been checked for this test run due to arg to the test script"$ERED
1898 echo -e $RED"ECS will not be started"$ERED
1901 export ECS_CERT_MOUNT_DIR="./cert"
1902 __start_container ecs NODOCKERARGS $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
1907 # (Function for test scripts)
1909 docker restart $ECS_APP_NAME &> ./tmp/.dockererr
1910 if [ $? -ne 0 ]; then
1911 __print_err "Could restart $ECS_APP_NAME" $@
1912 cat ./tmp/.dockererr
1917 __check_container_start $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
1922 # All calls to ECS will be directed to the ECS REST interface from now on
1924 # (Function for test scripts)
1925 use_ecs_rest_http() {
1926 echo -e "Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
1927 export ECS_ADAPTER=$ECS_RESTBASE
1931 # All calls to ECS will be directed to the ECS REST interface from now on
1933 # (Function for test scripts)
1934 use_ecs_rest_https() {
1935 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
1936 export ECS_ADAPTER=$ECS_RESTBASE_SECURE
1941 # All calls to ECS will be directed to the ECS dmaap interface over http from now on
1943 # (Function for test scripts)
1944 use_ecs_dmaap_http() {
1945 echo -e "Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
1946 export ECS_ADAPTER=$ECS_DMAAPBASE
1951 # All calls to ECS will be directed to the ECS dmaap interface over https from now on
1953 # (Function for test scripts)
1954 use_ecs_dmaap_https() {
1955 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
1956 export ECS_ADAPTER=$ECS_DMAAPBASE_SECURE
1961 # Turn on debug level tracing in ECS
1963 # (Function for test scripts)
1965 echo -e $BOLD"Setting ecs debug"$EBOLD
1966 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
1967 result=$(__do_curl "$curlString")
1968 if [ $? -ne 0 ]; then
1969 __print_err "Could not set debug mode" $@
1977 # Turn on trace level tracing in ECS
1979 # (Function for test scripts)
1981 echo -e $BOLD"Setting ecs trace"$EBOLD
1982 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
1983 result=$(__do_curl "$curlString")
1984 if [ $? -ne 0 ]; then
1985 __print_err "Could not set trace mode" $@
1993 # Perform curl retries when making direct call to ECS for the specified http response codes
1994 # Speace separated list of http response codes
1995 # args: [<response-code>]*
1996 use_agent_retries() {
1997 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
1998 ECS_AGENT_RETRY_CODES=$@
2007 # Check the agent logs for WARNINGs and ERRORs
2009 # (Function for test scripts)
2011 check_policy_agent_logs() {
2012 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
2016 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
2019 check_control_panel_logs() {
2020 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH WARN ERR
2024 __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
2027 __check_container_logs() {
2034 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
2036 #tmp=$(docker ps | grep $appname)
2037 tmp=$(docker ps -q --filter name=$appname) #get the container id
2038 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
2039 echo $dispname" is not running, no check made"
2042 foundentries="$(docker exec -t $tmp grep $warning $logpath | wc -l)"
2043 if [ $? -ne 0 ];then
2044 echo " Problem to search $appname log $logpath"
2046 if [ $foundentries -eq 0 ]; then
2047 echo " No WARN entries found in $appname log $logpath"
2049 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
2052 foundentries="$(docker exec -t $tmp grep $error $logpath | wc -l)"
2053 if [ $? -ne 0 ];then
2054 echo " Problem to search $appname log $logpath"
2056 if [ $foundentries -eq 0 ]; then
2057 echo " No ERR entries found in $appname log $logpath"
2059 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
2065 # Store all container logs and other logs in the log dir for the script
2066 # Logs are stored with a prefix in case logs should be stored several times during a test
2067 # args: <logfile-prefix>
2068 # (Function for test scripts)
2070 if [ $# != 1 ]; then
2072 __print_err "need one arg, <file-prefix>" $@
2075 echo -e $BOLD"Storing all container logs in $TESTLOGS/$ATC using prefix: "$1$EBOLD
2077 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
2079 __check_included_image 'CONSUL'
2080 if [ $? -eq 0 ]; then
2081 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
2084 __check_included_image 'CBS'
2085 if [ $? -eq 0 ]; then
2086 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
2087 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
2088 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
2091 __check_included_image 'PA'
2092 if [ $? -eq 0 ]; then
2093 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
2096 __check_included_image 'ECS'
2097 if [ $? -eq 0 ]; then
2098 docker logs $ECS_APP_NAME > $TESTLOGS/$ATC/$1_ecs.log 2>&1
2101 __check_included_image 'CP'
2102 if [ $? -eq 0 ]; then
2103 docker logs $CONTROL_PANEL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
2106 __check_included_image 'MR'
2107 if [ $? -eq 0 ]; then
2108 docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
2111 __check_included_image 'CR'
2112 if [ $? -eq 0 ]; then
2113 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
2116 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
2118 __check_included_image 'SDNC'
2119 if [ $? -eq 0 ]; then
2120 docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
2123 __check_included_image 'RICSIM'
2124 if [ $? -eq 0 ]; then
2125 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
2126 for ric in $rics; do
2127 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
2131 __check_included_image 'PRODSTUB'
2132 if [ $? -eq 0 ]; then
2133 docker logs $PROD_STUB_APP_NAME > $TESTLOGS/$ATC/$1_prodstub.log 2>&1
2142 # Generic curl function, assumes all 200-codes are ok
2143 # args: <valid-curl-args-including full url>
2144 # returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
2145 # returns: The return code is 0 for ok and 1 for not ok
2147 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
2148 curlString="curl -skw %{http_code} $@"
2149 echo " CMD: $curlString" >> $HTTPLOG
2151 echo " RESP: $res" >> $HTTPLOG
2152 http_code="${res:${#res}-3}"
2153 if [ ${#res} -eq 3 ]; then
2154 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2155 echo "<no-response-from-server>"
2158 echo "X2" >> $HTTPLOG
2162 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2163 echo "<not found, resp:${http_code}>"
2166 if [ $# -eq 2 ]; then
2167 echo "${res:0:${#res}-3}" | xargs
2169 echo "${res:0:${#res}-3}"
2176 #######################################
2177 ### Basic helper function for test cases
2178 #######################################
2180 # Test a simulator container variable value towards target value using an condition operator with an optional timeout.
2181 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
2182 # immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
2183 # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
2184 # before setting pass or fail depending on the result of comparing variable and target using the operator.
2185 # 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.
2186 # Not to be called from test script.
2189 checkjsonarraycount=0
2191 if [ $# -eq 6 ]; then
2192 if [[ $3 == "json:"* ]]; then
2193 checkjsonarraycount=1
2196 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
2201 if [ $checkjsonarraycount -eq 0 ]; then
2202 result="$(__do_curl $2$3)"
2204 result=${result//[[:blank:]]/} #Strip blanks
2207 result="$(__do_curl $2$path)"
2209 echo "$result" > ./tmp/.tmp.curl.json
2210 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
2212 duration=$((SECONDS-start))
2213 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
2215 if [ $retcode -ne 0 ]; then
2216 if [ $duration -gt $6 ]; then
2218 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
2219 __check_stop_at_error
2222 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2224 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2225 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2227 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2229 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2230 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2232 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2234 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2235 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2237 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2239 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
2240 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
2243 if [ $duration -gt $6 ]; then
2245 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
2246 __check_stop_at_error
2252 elif [ $# -eq 5 ]; then
2253 if [[ $3 == "json:"* ]]; then
2254 checkjsonarraycount=1
2257 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
2259 if [ $checkjsonarraycount -eq 0 ]; then
2260 result="$(__do_curl $2$3)"
2262 result=${result//[[:blank:]]/} #Strip blanks
2265 result="$(__do_curl $2$path)"
2267 echo "$result" > ./tmp/.tmp.curl.json
2268 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
2270 if [ $retcode -ne 0 ]; then
2272 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
2273 __check_stop_at_error
2274 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2276 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2277 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2279 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2280 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2282 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2283 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2285 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
2288 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
2289 __check_stop_at_error
2292 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
2299 ### Generic test cases for varaible checking
2301 # Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
2302 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2303 # equal to the target or not.
2304 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2305 # before setting pass or fail depending on if the variable value becomes equal to the target
2307 # (Function for test scripts)
2309 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2310 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
2313 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2317 # Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
2318 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2319 # greater than the target or not.
2320 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2321 # before setting pass or fail depending on if the variable value becomes greater than the target
2323 # (Function for test scripts)
2325 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2326 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 ">" $2 $3
2329 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2333 # Read a variable value from MR sim and send to stdout. Arg: <variable-name>
2335 echo "$(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"
2338 # Print a variable value from the MR stub.
2339 # arg: <variable-name>
2340 # (Function for test scripts)
2342 if [ $# != 1 ]; then
2344 __print_err "need one arg, <mr-param>" $@
2347 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"$EBOLD