-# (Function for test scripts)
-clean_containers() {
-
- echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
-
- CONTAINTER_NAMES=("Policy Agent " $(__check_app_name $POLICY_AGENT_APP_NAME)\
- "ECS " $(__check_app_name $ECS_APP_NAME)\
- "Non-RT RIC Simulator(s)" $(__check_app_name $RIC_SIM_PREFIX)\
- "Message Router " $(__check_app_name $MR_APP_NAME)\
- "Callback Receiver " $(__check_app_name $CR_APP_NAME)\
- "Producer stub " $(__check_app_name $PROD_STUB_APP_NAME)\
- "Control Panel " $(__check_app_name $CONTROL_PANEL_APP_NAME)\
- "SDNC A1 Controller " $(__check_app_name $SDNC_APP_NAME)\
- "SDNC DB " $(__check_app_name $SDNC_DB_APP_NAME)\
- "CBS " $(__check_app_name $CBS_APP_NAME)\
- "Consul " $(__check_app_name $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]}"
- if [ $CONTR != "NOTSET" ]; then
- 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}"
- fi
- 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 | indent2
- 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 "$GREEN Done$EGREEN"
-
- echo -e $BOLD" Removing all unused docker neworks"$EBOLD
- docker network prune --force | indent2
- echo -e "$GREEN Done$EGREEN"
-
- echo -e $BOLD" Removing all unused docker volumes"$EBOLD
- docker volume prune --force | indent2
- echo -e "$GREEN Done$EGREEN"
-
- echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
- docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
- echo -e "$GREEN Done$EGREEN"
- echo ""
-
- CONTRS=$(docker ps | awk '$1 != "CONTAINER" { n++ }; END { print n+0 }')
- if [ $? -eq 0 ]; then
- if [ $CONTRS -ne 0 ]; then
- echo -e $RED"Containers running, may cause distubance to the test case"$ERED
- docker ps -a | indent1
- echo ""
- fi
- fi
-}
-
-# 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
- ((RES_CONF_FAIL++))
-}
-
-
-# Helper function to get a the port of a specific ric simulatpor
-# args: <ric-id>