- 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 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-quoteds-to-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"