- tmpval=$(< .tmp_tcsuite_fail_ctr)
- ((tmpval++))
- echo $tmpval > .tmp_tcsuite_fail_ctr
- fi
- if [ -f .tmp_tcsuite_fail ]; then
- echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
- fi
- fi
-
- echo "++++ Number of tests: "$RES_TEST
- echo "++++ Number of passed tests: "$RES_PASS
- echo "++++ Number of failed tests: "$RES_FAIL
- echo ""
- echo "++++ Number of failed configs: "$RES_CONF_FAIL
- echo ""
- echo "++++ Number of test case deviations: "$RES_DEVIATION
- echo ""
- echo "------------------------------------- Test case complete ---------------------------------"
- echo "-------------------------------------------------------------------------------------------------"
- echo ""
-}
-
-#####################################################################
-###### Functions for start, configuring, stoping, cleaning etc ######
-#####################################################################
-
-# Start timer for time measurement
-# args - (any args will be printed though)
-start_timer() {
- echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
- TC_TIMER=$SECONDS
- echo " Timer started"
-}
-
-# Print the value of the time (in seconds)
-# args - <timer message to print> - timer value and message will be printed both on screen
-# and in the timer measurement report
-print_timer() {
- echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
- if [ $# -lt 1 ]; then
- ((RES_CONF_FAIL++))
- __print_err "need 1 or more args, <timer message to print>" $@
- exit 1
- fi
- duration=$(($SECONDS-$TC_TIMER))
- if [ $duration -eq 0 ]; then
- duration="<1 second"
- else
- duration=$duration" seconds"
- fi
- echo " Timer duration :" $duration
-
- echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
-}
-
-# Print the value of the time (in seconds) and reset the timer
-# args - <timer message to print> - timer value and message will be printed both on screen
-# and in the timer measurement report
-print_and_reset_timer() {
- echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
- if [ $# -lt 1 ]; then
- ((RES_CONF_FAIL++))
- __print_err "need 1 or more args, <timer message to print>" $@
- exit 1
- fi
- duration=$(($SECONDS-$TC_TIMER))" seconds"
- if [ $duration -eq 0 ]; then
- duration="<1 second"
- else
- duration=$duration" seconds"
- fi
- echo " Timer duration :" $duration
- TC_TIMER=$SECONDS
- echo " Timer reset"
-
- echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
-
-}
-# Print info about a deviations from intended tests
-# Each deviation counted is also printed in the testreport
-# args <deviation message to print>
-deviation() {
- echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
- if [ $# -lt 1 ]; then
- ((RES_CONF_FAIL++))
- __print_err "need 1 or more args, <deviation message to print>" $@
- exit 1
- fi
- ((RES_DEVIATION++))
- echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
- echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
- echo ""
-}
-
-# Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
-__check_stop_at_error() {
- if [ $STOP_AT_ERROR -eq 1 ]; then
- echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
- store_logs "STOP_AT_ERROR"
- exit 1
- fi
- return 0
-}
-
-# Stop and remove all containers
-# args: -
-# (Function for test scripts)
-clean_containers() {
-
- echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
-
- CONTAINTER_NAMES=("Policy Agent " $POLICY_AGENT_APP_NAME\
- "Non-RT RIC Simulator(s)" $RIC_SIM_PREFIX\
- "Message Router " $MR_APP_NAME\
- "Callback Receiver " $CR_APP_NAME\
- "Control Panel " $CONTROL_PANEL_APP_NAME\
- "SDNC A1 Controller " $SDNC_APP_NAME\
- "SDNC DB " $SDNC_DB_APP_NAME\
- "SDNC ONAP A1 Adapter " $SDNC_ONAP_APP_NAME\
- "SDNC DB " $SDNC_ONAP_DB_APP_NAME\
- "CBS " $CBS_APP_NAME\
- "Consul " $CONSUL_APP_NAME)
-
- nw=0 # Calc max width of container name, to make a nice table
- for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
- if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
- nw=${#CONTAINTER_NAMES[i]}
- fi
- done
-
- for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
- APP="${CONTAINTER_NAMES[i]}"
- CONTR="${CONTAINTER_NAMES[i+1]}"
- for((w=${#CONTR}; w<$nw; w=w+1)); do
- CONTR="$CONTR "
- done
- echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
- docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
- echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
- docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
- echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
- done
-
- echo ""
-
- echo -e $BOLD" Removing docker network"$EBOLD
- TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
- if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
- docker network rm $DOCKER_SIM_NWNAME
- if [ $? -ne 0 ]; then
- echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
- exit 1
- fi
- fi
-
- echo -e $BOLD" Removing all unused docker neworks"$EBOLD
- docker network prune --force #&> /dev/null
-
- echo -e $BOLD" Removing all unused docker volumes"$EBOLD
- docker volume prune --force #&> /dev/null
-
- echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
- docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
- echo ""
-}
-
-# Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
-# args: -
-# (Function for test scripts)
-auto_clean_containers() {
- echo
- if [ "$AUTO_CLEAN" == "auto" ]; then
- echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
- clean_containers
- fi
-}
-
-# Function to sleep a test case for a numner of seconds. Prints the optional text args as info
-# args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
-# (Function for test scripts)
-sleep_wait() {
-
- echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
- if [ $# -lt 1 ]; then
- ((RES_CONF_FAIL++))
- __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
- exit 1
- fi
- #echo "---- Sleep for " $1 " seconds ---- "$2
- start=$SECONDS
- duration=$((SECONDS-start))
- while [ $duration -lt $1 ]; do
- echo -ne " Slept for ${duration} seconds${SAMELINE}"
- sleep 1
- duration=$((SECONDS-start))
- done
- echo -ne " Slept for ${duration} seconds${SAMELINE}"
- echo ""
-}
-
-# Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
-# Not to be called from the test script itself.
-__print_err() {
- echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
- if [ $# -gt 1 ]; then
- echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
- fi
-}
-
-
-# Helper function to get a the port of a specific ric simulatpor
-# args: <ric-id>
-# (Not for test scripts)
-__find_sim_port() {
- name=$1" " #Space appended to prevent matching 10 if 1 is desired....
- cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
- res=$(eval $cmdstr)
- if [[ "$res" =~ ^[0-9]+$ ]]; then
- echo $res
- else
- echo "0"
- fi
-}
-
-# Function to create the docker network for the test
-# Not to be called from the test script itself.
-__create_docker_network() {
- tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
- if [ $? -ne 0 ]; then
- echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
- return 1
- fi
- if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
- echo -e "Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
- docker network create $DOCKER_SIM_NWNAME
- if [ $? -ne 0 ]; then
- echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
- return 1
- fi
- else
- echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
- fi
-}
-
-# Check if container is started by calling url on localhost using a port, expects response code 2XX
-# args: <container-name> <port> <url> https|https
-# Not to be called from the test script itself.
-__check_container_start() {
- paramError=0
- if [ $# -ne 4 ]; then
- paramError=1
- elif [ $4 != "http" ] && [ $4 != "https" ]; then
- paramError=1
- fi
- if [ $paramError -ne 0 ]; then
- ((RES_CONF_FAIL++))
- __print_err "need 3 args, <container-name> <port> <url> https|https" $@
- return 1
- fi
- echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
- appname=$1
- localport=$2
- url=$3
- if [[ $appname != "STANDALONE_"* ]] ; then
- app_started=0
- for i in {1..10}; do
- if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
- echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
- app_started=1
- break
- else
- sleep $i
- fi
- done
- if [ $app_started -eq 0 ]; then
- ((RES_CONF_FAIL++))
- echo ""
- echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
- return 1
- fi
- if [ $localport -eq 0 ]; then
- while [ $localport -eq 0 ]; do
- echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
- localport=$(__find_sim_port $appname)
- sleep 1
- echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
- done
- echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
- echo ""
- fi
- fi
-
- pa_st=false
- echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
- TSTART=$SECONDS
- for i in {1..50}; do
- if [ $4 == "https" ]; then
- result="$(__do_curl "-k https://localhost:"${localport}${url})"
- else
- result="$(__do_curl $LOCALHOST${localport}${url})"
- fi
- if [ $? -eq 0 ]; then
- if [ ${#result} -gt 15 ]; then
- #If response is too long, truncate
- result="...response text too long, omitted"
- fi
- echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
- echo -ne " Container $BOLD${appname}$EBOLD$GREEN is alive$EGREEN, responds to service status:$GREEN $result $EGREEN after $(($SECONDS-$TSTART)) seconds"
- pa_st=true
- break
- else
- TS_TMP=$SECONDS
- while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
- echo -ne " Waiting for container ${appname} service status...retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
- sleep 1
- done
- fi
- done
-
- if [ "$pa_st" = "false" ]; then
- ((RES_CONF_FAIL++))
- echo -e $RED" Container ${appname} did not respond to service status"$ERED
- return 0
- fi
-
- echo ""
- return 0
-}
-
-
-# Function to start a container and wait until it responds on the given port and url.
-#args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
-__start_container() {
-
- variableArgCount=$(($#-2))
- if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
- ((RES_CONF_FAIL++))
- __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 ]*" $@
- exit 1
- fi
-
- __create_docker_network
-
- curdir=$PWD
- cd $SIM_GROUP
- cd $1
-
- if [ "$2" == "NODOCKERARGS" ]; then
- docker-compose up -d &> .dockererr
- if [ $? -ne 0 ]; then
- echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
- cat .dockererr