blob: 28c65d2681733ab1245eedf1c225325a2da56a74 [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/bin/bash
YongchaoWu9a84f512019-12-16 22:54:11 +01002
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003# ============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
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
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=================================================
18#
YongchaoWu9a84f512019-12-16 22:54:11 +010019
YongchaoWuffde6eb2020-01-17 13:58:51 +010020# This is a script that contains all the functions needed for auto test
BjornMagnussonXA80a92002020-03-19 14:31:06 +010021# Arg: local|remote|remote-remove [auto-clean]
YongchaoWuffde6eb2020-01-17 13:58:51 +010022
BjornMagnussonXA72667f12020-04-24 09:20:18 +020023
BjornMagnussonXA80a92002020-03-19 14:31:06 +010024#Formatting for 'echo' cmd
25BOLD="\033[1m"
26EBOLD="\033[0m"
27RED="\033[31m\033[1m"
28ERED="\033[0m"
29GREEN="\033[32m\033[1m"
30EGREEN="\033[0m"
31YELLOW="\033[33m\033[1m"
32EYELLOW="\033[0m"
BjornMagnussonXA72667f12020-04-24 09:20:18 +020033SAMELINE="\033[0K\r"
34
35tmp=$(which python3)
36if [ $? -ne 0 ] || [ -z tmp ]; then
37 echo -e $RED"python3 is required to run the test environment, pls install"$ERED
38 exit 1
39fi
40tmp=$(which docker)
41if [ $? -ne 0 ] || [ -z tmp ]; then
42 echo -e $RED"docker is required to run the test environment, pls install"$ERED
43 exit 1
44fi
YongchaoWu9a84f512019-12-16 22:54:11 +010045
BjornMagnussonXA80a92002020-03-19 14:31:06 +010046# Just resetting any previous echo formatting...
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020047echo -ne $EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +010048
49# source test environment variables
50. ../common/test_env.sh
51
52echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@
53
54#Vars for A1 interface version and container count
55G1_A1_VERSION=""
56G2_A1_VERSION=""
57G3_A1_VERSION=""
58G1_COUNT=0
59G2_COUNT=0
60G3_COUNT=0
61
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020062# Vars to switch between http and https. Extra curl flag needed for https
BjornMagnussonXA72667f12020-04-24 09:20:18 +020063export RIC_SIM_HTTPX="http"
64export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
65export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
66export RIC_SIM_CERT_MOUNT_DIR="./fakedir" #Fake dir so that the sim container does not find any cert
67
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020068export MR_HTTPX="http"
69export MR_PORT=$MR_INTERNAL_PORT
70export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker net
71
72export SDNC_HTTPX="http"
73export SDNC_PORT=$SDNC_INTERNAL_PORT
74export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net
75
BjornMagnussonXA80a92002020-03-19 14:31:06 +010076#Localhost constant
77LOCALHOST="http://localhost:"
78
79# Make curl retries for http response codes set in this env var, space separated list of codes
80AGENT_RETRY_CODES=""
81
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020082# Var to contol if the agent runs in a container (normal = 0) or as application on the local machine ( = 1)
83AGENT_STAND_ALONE=0
84
BjornMagnussonXA80a92002020-03-19 14:31:06 +010085# Var to hold 'auto' in case containers shall be stopped when test case ends
86AUTO_CLEAN=""
YongchaoWu9a84f512019-12-16 22:54:11 +010087
88# Set a description string for the test case
89if [ -z "$TC_ONELINE_DESCR" ]; then
90 TC_ONELINE_DESCR="<no-description>"
91 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
92fi
93
BjornMagnussonXA80a92002020-03-19 14:31:06 +010094# Counter for test suites
95if [ -f .tmp_tcsuite_ctr ]; then
96 tmpval=$(< .tmp_tcsuite_ctr)
97 ((tmpval++))
98 echo $tmpval > .tmp_tcsuite_ctr
99fi
YongchaoWu9a84f512019-12-16 22:54:11 +0100100
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100101# Create a test case id, ATC (Auto Test Case), from the name of the test case script.
102# FTC1.sh -> ATC == FTC1
103ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
YongchaoWu9a84f512019-12-16 22:54:11 +0100104
105# Create the logs dir if not already created in the current dir
106if [ ! -d "logs" ]; then
107 mkdir logs
108fi
YongchaoWu9a84f512019-12-16 22:54:11 +0100109TESTLOGS=$PWD/logs
110
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100111# Create a http message log for this testcase
112HTTPLOG=$PWD"/.httplog_"$ATC".txt"
113echo "" > $HTTPLOG
114
115# Create a log dir for the test case
YongchaoWu9a84f512019-12-16 22:54:11 +0100116mkdir -p $TESTLOGS/$ATC
117
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100118# Clear the log dir for the test case
119rm $TESTLOGS/$ATC/*.log &> /dev/null
120rm $TESTLOGS/$ATC/*.txt &> /dev/null
121rm $TESTLOGS/$ATC/*.json &> /dev/null
122
123# Log all output from the test case to a TC log
YongchaoWu9a84f512019-12-16 22:54:11 +0100124TCLOG=$TESTLOGS/$ATC/TC.log
125exec &> >(tee ${TCLOG})
126
127#Variables for counting tests as well as passed and failed tests
128RES_TEST=0
129RES_PASS=0
130RES_FAIL=0
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100131RES_CONF_FAIL=0
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200132RES_DEVIATION=0
133
134#File to keep deviation messages
135DEVIATION_FILE=".tmp_deviations"
136rm $DEVIATION_FILE &> /dev/null
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100137
138#Var for measuring execution time
YongchaoWu9a84f512019-12-16 22:54:11 +0100139TCTEST_START=$SECONDS
140
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200141#File to save timer measurement results
142TIMER_MEASUREMENTS=".timer_measurement.txt"
143echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS
144
145
YongchaoWu9a84f512019-12-16 22:54:11 +0100146echo "-------------------------------------------------------------------------------------------------"
147echo "----------------------------------- Test case: "$ATC
148echo "----------------------------------- Started: "$(date)
149echo "-------------------------------------------------------------------------------------------------"
150echo "-- Description: "$TC_ONELINE_DESCR
151echo "-------------------------------------------------------------------------------------------------"
152echo "----------------------------------- Test case setup -----------------------------------"
153
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100154echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
YongchaoWu9a84f512019-12-16 22:54:11 +0100155
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100156#Temp var to check for image variable name errors
157IMAGE_ERR=0
158#Create a file with image info for later printing as a table
159image_list_file=".image-list"
160echo -e " Container\tImage\ttag" > $image_list_file
161
162# Check if image env var is set and if so export the env var with image to use (used by docker compose files)
163# arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name>
164__check_image_var() {
165 if [ $# -ne 5 ]; then
166 echo "Expected arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name>"
167 ((IMAGE_ERR++))
168 return
169 fi
170 tmp=${1}"\t"
171 #Create var from the input var names
172 image="${!4}"
173 tag="${!5}"
174
175 if [ -z $image ]; then
176 echo -e $RED"\$"$4" not set in test_env"$ERED
177 ((IMAGE_ERR++))
178 echo ""
179 tmp=$tmp"<no-image>\t"
180 else
181 tmp=$tmp$image"\t"
182 fi
183 if [ -z $tag ]; then
184 echo -e $RED"\$"$5" not set in test_env"$ERED
185 ((IMAGE_ERR++))
186 echo ""
187 tmp=$tmp"<no-tag>\t"
188 else
189 tmp=$tmp$tag
190 fi
191 echo -e "$tmp" >> $image_list_file
192 #Export the env var
193 export "${3}"=$image":"$tag
194
195 #echo " Configured image for ${1} (script start arg=${2}): "$image":"$tag
196}
197
198# Check that image env setting are available
199echo ""
200if [ $# -lt 1 ] || [ $# -gt 2 ]; then
201 echo "Expected arg: local|remote|remote-remove [auto-clean]"
202 exit 1
203elif [ $1 == "local" ]; then
204
205 #Local agent image
206 __check_image_var " Policy Agent" $1 "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG"
207
208 #Local Control Panel image
209 __check_image_var " Control Panel" $1 "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG"
210
211 #Local SNDC image
212 __check_image_var " SDNC A1 Controller" $1 "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG"
213
214 #Local ric sim image
215 __check_image_var " RIC Simulator" $1 "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG"
216
217elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
218
219 #Remote agent image
220 __check_image_var " Policy Agent" $1 "POLICY_AGENT_IMAGE" "POLICY_AGENT_REMOTE_IMAGE" "POLICY_AGENT_REMOTE_IMAGE_TAG"
221
222 #Remote Control Panel image
223 __check_image_var " Control Panel" $1 "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE_TAG"
224
225 #Remote SDNC image
226 __check_image_var " SDNC A1 Controller" $1 "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE_TAG"
227
228 #Remote ric sim image
229 __check_image_var " RIC Simulator" $1 "RIC_SIM_IMAGE" "RIC_SIM_REMOTE_IMAGE" "RIC_SIM_REMOTE_IMAGE_TAG"
230
231else
232 echo "Expected arg: local|remote|remote-remove [auto-clean]"
233 exit 1
YongchaoWu9a84f512019-12-16 22:54:11 +0100234fi
235
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100236if [ $# -eq 2 ]; then
237 if [ $2 == "auto-clean" ]; then
238 echo "Stting automatic cleaning of container when test case ends"
239 AUTO_CLEAN="auto"
240 else
241 echo "Expected arg: local|remote|remote-remove [auto-clean]"
242 exit 1
YongchaoWu9a84f512019-12-16 22:54:11 +0100243 fi
244fi
245
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100246# These images are not built as part of this project official images, just check that env vars are set correctly
247__check_image_var " Message Router" $1 "MRSTUB_IMAGE" "MRSTUB_LOCAL_IMAGE" "MRSTUB_LOCAL_IMAGE_TAG"
248__check_image_var " Callback Receiver" $1 "CR_IMAGE" "CR_LOCAL_IMAGE" "CR_LOCAL_IMAGE_TAG"
249__check_image_var " Consul" $1 "CONSUL_IMAGE" "CONSUL_REMOTE_IMAGE" "CONSUL_REMOTE_IMAGE_TAG"
250__check_image_var " CBS" $1 "CBS_IMAGE" "CBS_REMOTE_IMAGE" "CBS_REMOTE_IMAGE_TAG"
251__check_image_var " SDNC DB" $1 "SDNC_DB_IMAGE" "SDNC_DB_REMOTE_IMAGE" "SDNC_DB_REMOTE_IMAGE_TAG"
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200252__check_image_var " SDNC ONAP A1 Adapter" $1 "SDNC_ONAP_A1_ADAPTER_IMAGE" "SDNC_ONAP_A1_ADAPTER_REMOTE_IMAGE" "SDNC_ONAP_A1_ADAPTER_REMOTE_IMAGE_TAG"
253__check_image_var " SDNC ONAP DB" $1 "SDNC_ONAP_DB_IMAGE" "SDNC_ONAP_DB_REMOTE_IMAGE" "SDNC_ONAP_DB_REMOTE_IMAGE_TAG"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100254
255#Errors in image setting - exit
256if [ $IMAGE_ERR -ne 0 ]; then
257 exit 1
258fi
259
260#Print a tables of the image settings
261echo -e $BOLD"Images configured for start arg: "$1 $EBOLD
262column -t -s $'\t' $image_list_file
263
YongchaoWuf309b1b2020-01-22 13:24:48 +0100264echo ""
265
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100266
267#Set the SIM_GROUP var
268echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
269if [ -z "$SIM_GROUP" ]; then
270 SIM_GROUP=$PWD/../simulator-group
271 if [ ! -d $SIM_GROUP ]; then
272 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
273 echo -e $RED"Please set the SIM_GROUP manually in the test_env.sh"$ERED
274 exit 1
275 else
276 echo " SIM_GROUP auto set to: " $SIM_GROUP
277 fi
278elif [ $SIM_GROUP = *simulator_group ]; then
279 echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check common/test_env.sh"$ERED
280 exit 1
281else
282 echo " SIM_GROUP env var already set to: " $SIM_GROUP
maximesson28ee8a52020-03-17 09:32:03 +0100283fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100284
285echo ""
286
287#Temp var to check for image pull errors
288IMAGE_ERR=0
289
290#Function to check if image exist and stop+remove the container+pull new images as needed
291#args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
292__check_and_pull_image() {
293
294 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
295 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
296 tmp_im=$(docker images --format $format_string ${4})
297
298 if [ $1 == "local" ]; then
299 if [ -z "$tmp_im" ]; then
300 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
301 ((IMAGE_ERR++))
302 return 1
303 else
304 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
305 fi
306 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
307 if [ $1 == "remote-remove" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200308 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100309 tmp="$(docker ps -aq --filter name=${3})"
310 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200311 docker stop $tmp &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100312 if [ $? -ne 0 ]; then
313 ((IMAGE_ERR++))
314 echo ""
315 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200316 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100317 return 1
318 fi
319 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200320 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100321 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
322 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200323 docker rm $tmp &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100324 if [ $? -ne 0 ]; then
325 ((IMAGE_ERR++))
326 echo ""
327 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200328 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100329 return 1
330 fi
331 fi
332 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200333 echo -ne " Removing image - ${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100334 tmp="$(docker images -q ${4})" &> /dev/null
335 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200336 docker rmi $4 &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100337 if [ $? -ne 0 ]; then
338 ((IMAGE_ERR++))
339 echo ""
340 echo -e $RED" Image could not be removed - try manual removal of the image"$ERED
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200341 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100342 return 1
343 fi
344 echo -e " Removing image - "$GREEN"removed"$EGREEN
345 else
346 echo -e " Removing image - "$GREEN"image not in repository"$EGREEN
347 fi
348 tmp_im=""
349 fi
350 if [ -z "$tmp_im" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200351 echo -ne " Pulling image${SAMELINE}"
352 docker pull $4 &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100353 tmp_im=$(docker images ${4} | grep -v REPOSITORY)
354 if [ -z "$tmp_im" ]; then
355 echo ""
356 echo -e " Pulling image -$RED could not be pulled"$ERED
357 ((IMAGE_ERR++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200358 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100359 return 1
360 fi
361 echo -e " Pulling image -$GREEN Pulled $EGREEN"
362 else
363 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
364 fi
365 fi
366 return 0
367}
368
369
370echo -e $BOLD"Pulling configured images, if needed"$EBOLD
371
372app="Policy Agent"; __check_and_pull_image $1 "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
373app="Non-RT RIC Control Panel"; __check_and_pull_image $1 "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
374app="SDNC A1 Controller"; __check_and_pull_image $1 "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
375app="Near-RT RIC Simulator"; __check_and_pull_image $1 "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
376
377app="Consul"; __check_and_pull_image $1 "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
378app="CBS"; __check_and_pull_image $1 "$app" $CBS_APP_NAME $CBS_IMAGE
379app="SDNC DB"; __check_and_pull_image $1 "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200380
381echo -e $YELLOW"SDNC ONAP image is skipped"$EYELLOW
382#app="SDNC ONAP A1 Adapter"; __check_and_pull_image $1 "$app" $SDNC_ONAP_APP_NAME $SDNC_ONAP_A1_ADAPTER_IMAGE
383#app="SDNC ONAP DB"; __check_and_pull_image $1 "$app" $SDNC_ONAP_APP_NAME $SDNC_ONAP_DB_IMAGE
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100384
385# MR stub image not checked, will be built by this script - only local image
386# CR stub image not checked, will be built by this script - only local image
387
388
389#Errors in image setting - exit
390if [ $IMAGE_ERR -ne 0 ]; then
391 echo ""
392 echo "#################################################################################################"
393 echo -e $RED"One or more images could not be pulled or containers using the images could not be stopped/removed"$ERED
394 echo "#################################################################################################"
395 echo ""
396 exit 1
397fi
398
399echo ""
400
401echo -e $BOLD"Building images needed for test"$EBOLD
402
403curdir=$PWD
404cd $curdir
405cd ../mrstub
406echo " Building mrstub image: mrstub:latest"
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200407docker build -t mrstub . &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100408if [ $? -eq 0 ]; then
409 echo -e $GREEN" Build Ok"$EGREEN
410else
411 echo -e $RED" Build Failed"$ERED
412 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200413 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100414fi
415cd $curdir
416
417cd ../cr
418echo " Building Callback Receiver image: callback-receiver:latest"
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200419docker build -t callback-receiver . &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100420if [ $? -eq 0 ]; then
421 echo -e $GREEN" Build Ok"$EGREEN
422else
423 echo -e $RED" Build Failed"$ERED
424 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200425 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100426fi
YongchaoWuf309b1b2020-01-22 13:24:48 +0100427cd $curdir
428
429echo ""
430
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100431# Create a table of the images used in the script
432echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
433
434docker_tmp_file=.docker-images-table
435format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}"
436echo -e " Application\tRepository\tTag\tCreated Since\tSize" > $docker_tmp_file
437echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
438echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
439echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
440echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
441echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
442echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
443echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
444echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
445echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200446echo -e " SDNC ONAP A1 Adapter\t$(docker images --format $format_string $SDNC_ONAP_A1_ADAPTER_IMAGE)" >> $docker_tmp_file
447echo -e " SDNC ONAP DB\t$(docker images --format $format_string $SDNC_ONAP_DB_IMAGE)" >> $docker_tmp_file
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100448
449column -t -s $'\t' $docker_tmp_file
450
YongchaoWuf309b1b2020-01-22 13:24:48 +0100451echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +0100452
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100453echo -e $BOLD"======================================================="$EBOLD
454echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
455echo -e $BOLD"======================================================="$EBOLD
456echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +0100457
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100458# Function to print the test result, shall be the last cmd in a test script
459# args: -
460# (Function for test scripts)
461print_result() {
YongchaoWu9a84f512019-12-16 22:54:11 +0100462
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100463 TCTEST_END=$SECONDS
464 duration=$((TCTEST_END-TCTEST_START))
YongchaoWu9a84f512019-12-16 22:54:11 +0100465
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100466 echo "-------------------------------------------------------------------------------------------------"
467 echo "------------------------------------- Test case: "$ATC
468 echo "------------------------------------- Ended: "$(date)
469 echo "-------------------------------------------------------------------------------------------------"
470 echo "-- Description: "$TC_ONELINE_DESCR
471 echo "-- Execution time: " $duration " seconds"
472 echo "-------------------------------------------------------------------------------------------------"
473 echo "------------------------------------- RESULTS"
YongchaoWu4e489b02020-02-24 09:18:16 +0100474 echo ""
YongchaoWu4e489b02020-02-24 09:18:16 +0100475
YongchaoWu21f17bb2020-03-05 12:44:08 +0100476
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100477 total=$((RES_PASS+RES_FAIL))
478 if [ $RES_TEST -eq 0 ]; then
479 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
480 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
481 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
482 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
483 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
484 elif [ $total != $RES_TEST ]; then
485 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
486 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
487 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
488 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
489 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
490 elif [ $RES_CONF_FAIL -ne 0 ]; then
491 echo -e "\033[1mOne or more configure regest has failed. Check the script log....\033[0m"
492 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
493 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
494 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
495 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
496 elif [ $RES_PASS = $RES_TEST ]; then
497 echo -e "All tests \033[32m\033[1mPASS\033[0m"
498 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
499 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
500 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
501 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
502 echo ""
YongchaoWu21f17bb2020-03-05 12:44:08 +0100503
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100504 # Update test suite counter
505 if [ -f .tmp_tcsuite_pass_ctr ]; then
506 tmpval=$(< .tmp_tcsuite_pass_ctr)
507 ((tmpval++))
508 echo $tmpval > .tmp_tcsuite_pass_ctr
509 fi
510 if [ -f .tmp_tcsuite_pass ]; then
511 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
512 fi
513 else
514 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
515 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
516 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
517 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
518 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
519 echo ""
520 # Update test suite counter
521 if [ -f .tmp_tcsuite_fail_ctr ]; then
522 tmpval=$(< .tmp_tcsuite_fail_ctr)
523 ((tmpval++))
524 echo $tmpval > .tmp_tcsuite_fail_ctr
525 fi
526 if [ -f .tmp_tcsuite_fail ]; then
527 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
528 fi
YongchaoWu21f17bb2020-03-05 12:44:08 +0100529 fi
YongchaoWu21f17bb2020-03-05 12:44:08 +0100530
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200531 if [ $RES_DEVIATION -gt 0 ]; then
532 echo "Test case deviations"
533 echo "===================================="
534 cat $DEVIATION_FILE
535 fi
536 echo ""
537 echo "Timer measurement in the test script"
538 echo "===================================="
539 column -t -s $'\t' $TIMER_MEASUREMENTS
540 echo ""
541
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100542 echo "++++ Number of tests: "$RES_TEST
543 echo "++++ Number of passed tests: "$RES_PASS
544 echo "++++ Number of failed tests: "$RES_FAIL
YongchaoWu4e489b02020-02-24 09:18:16 +0100545 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100546 echo "++++ Number of failed configs: "$RES_CONF_FAIL
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200547 echo ""
548 echo "++++ Number of test case deviations: "$RES_DEVIATION
549 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100550 echo "------------------------------------- Test case complete ---------------------------------"
551 echo "-------------------------------------------------------------------------------------------------"
YongchaoWu9a84f512019-12-16 22:54:11 +0100552 echo ""
553}
554
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100555#####################################################################
556###### Functions for start, configuring, stoping, cleaning etc ######
557#####################################################################
YongchaoWu21f17bb2020-03-05 12:44:08 +0100558
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200559# Start timer for time measurement
560# args - (any args will be printed though)
561start_timer() {
562 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
563 TC_TIMER=$SECONDS
564 echo " Timer started"
565}
566
567# Print the value of the time (in seconds)
568# args - <timer message to print> - timer value and message will be printed both on screen
569# and in the timer measurement report
570print_timer() {
571 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
572 if [ $# -lt 1 ]; then
573 ((RES_CONF_FAIL++))
574 __print_err "need 1 or more args, <timer message to print>" $@
575 exit 1
576 fi
577 duration=$(($SECONDS-$TC_TIMER))
578 if [ $duration -eq 0 ]; then
579 duration="<1 second"
580 else
581 duration=$duration" seconds"
582 fi
583 echo " Timer duration :" $duration
584
585 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
586}
587
588# Print the value of the time (in seconds) and reset the timer
589# args - <timer message to print> - timer value and message will be printed both on screen
590# and in the timer measurement report
591print_and_reset_timer() {
592 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
593 if [ $# -lt 1 ]; then
594 ((RES_CONF_FAIL++))
595 __print_err "need 1 or more args, <timer message to print>" $@
596 exit 1
597 fi
598 duration=$(($SECONDS-$TC_TIMER))" seconds"
599 if [ $duration -eq 0 ]; then
600 duration="<1 second"
601 else
602 duration=$duration" seconds"
603 fi
604 echo " Timer duration :" $duration
605 TC_TIMER=$SECONDS
606 echo " Timer reset"
607
608 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
609
610}
611# Print info about a deviations from intended tests
612# Each deviation counted is also printed in the testreport
613# args <deviation message to print>
614deviation() {
615 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
616 if [ $# -lt 1 ]; then
617 ((RES_CONF_FAIL++))
618 __print_err "need 1 or more args, <deviation message to print>" $@
619 exit 1
620 fi
621 ((RES_DEVIATION++))
622 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
623 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
624 echo ""
625}
YongchaoWu21f17bb2020-03-05 12:44:08 +0100626
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100627# Stop and remove all containers
628# args: -
629# (Function for test scripts)
YongchaoWu9a84f512019-12-16 22:54:11 +0100630clean_containers() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100631
632 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
633
634 CONTAINTER_NAMES=("Policy Agent " $POLICY_AGENT_APP_NAME\
635 "Non-RT RIC Simulator(s)" $RIC_SIM_PREFIX\
636 "Message Router " $MR_APP_NAME\
637 "Callback Receiver " $CR_APP_NAME\
638 "Control Panel " $CONTROL_PANEL_APP_NAME\
639 "SDNC A1 Controller " $SDNC_APP_NAME\
640 "SDNC DB " $SDNC_DB_APP_NAME\
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200641 "SDNC ONAP A1 Adapter " $SDNC_ONAP_APP_NAME\
642 "SDNC DB " $SDNC_ONAP_DB_APP_NAME\
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100643 "CBS " $CBS_APP_NAME\
644 "Consul " $CONSUL_APP_NAME)
645
646 nw=0 # Calc max width of container name, to make a nice table
647 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
648 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
649 nw=${#CONTAINTER_NAMES[i]}
650 fi
651 done
652
653 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
654 APP="${CONTAINTER_NAMES[i]}"
655 CONTR="${CONTAINTER_NAMES[i+1]}"
656 for((w=${#CONTR}; w<$nw; w=w+1)); do
657 CONTR="$CONTR "
658 done
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200659 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100660 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200661 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100662 docker rm $(docker ps -qa --filter name=${CONTR}) &> /dev/null
663 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
664 done
665
YongchaoWu9a84f512019-12-16 22:54:11 +0100666 echo ""
667}
668
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100669# Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
670# args: -
671# (Function for test scripts)
672auto_clean_containers() {
673 echo
674 if [ "$AUTO_CLEAN" == "auto" ]; then
675 echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
676 clean_containers
YongchaoWu9a84f512019-12-16 22:54:11 +0100677 fi
678}
679
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100680# Function to sleep a test case for a numner of seconds. Prints the optional text args as info
681# args: <sleep-time-in-sec> [any-text-in-quoteds-to-printed]
682# (Function for test scripts)
683sleep_wait() {
YongchaoWu9a84f512019-12-16 22:54:11 +0100684
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100685 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
686 if [ $# -lt 1 ]; then
687 ((RES_CONF_FAIL++))
688 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
689 exit 1
690 fi
691 #echo "---- Sleep for " $1 " seconds ---- "$2
692 start=$SECONDS
693 duration=$((SECONDS-start))
694 while [ $duration -lt $1 ]; do
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200695 echo -ne " Slept for ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100696 sleep 1
697 duration=$((SECONDS-start))
698 done
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200699 echo -ne " Slept for ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100700 echo ""
701}
702
703# Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
704# Not to be called from the test script itself.
705__print_err() {
706 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
707 if [ $# -gt 1 ]; then
708 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
709 fi
710}
711
712
713# Helper function to get a the port of a specific ric simulatpor
714# args: <ric-id>
715# (Not for test scripts)
716__find_sim_port() {
717 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
718 cmdstr="docker ps --filter name=${name} --format \"{{.Names}} {{.Ports}}\" | grep '${name}' | sed s/0.0.0.0:// | cut -f 2 -d ' ' | cut -f 1 -d '-'"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200719 cmdstr="docker ps --filter name=${name} --format \"{{.Names}} {{.Ports}}\" | grep '${name}' | cut -f 3 -d ',' | sed s/0.0.0.0:// | cut -f 2 -d ' ' | cut -f 1 -d '-'"
720
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100721 res=$(eval $cmdstr)
722 if [[ "$res" =~ ^[0-9]+$ ]]; then
723 echo $res
724 else
725 echo "0"
726 fi
727}
728
729# Function to create the docker network for the test
730# Not to be called from the test script itself.
731__create_docker_network() {
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200732 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100733 if [ $? -ne 0 ]; then
734 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
735 return 1
736 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200737 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100738 echo -e "Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
739 docker network create $DOCKER_SIM_NWNAME
740 if [ $? -ne 0 ]; then
741 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
742 return 1
743 fi
744 else
745 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
746 fi
747}
748
749# Check if container is started by calling url on localhost using a port, expects response code 2XX
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200750# args: <container-name> <port> <url> https|https
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100751# Not to be called from the test script itself.
752__check_container_start() {
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200753 paramError=0
754 if [ $# -ne 4 ]; then
755 paramError=1
756 elif [ $4 != "http" ] && [ $4 != "https" ]; then
757 paramError=1
758 fi
759 if [ $paramError -ne 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100760 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200761 __print_err "need 3 args, <container-name> <port> <url> https|https" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100762 return 1
763 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200764 echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
YongchaoWu9a84f512019-12-16 22:54:11 +0100765 appname=$1
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100766 localport=$2
767 url=$3
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200768 if [[ $appname != "STANDALONE_"* ]] ; then
769 app_started=0
770 for i in {1..10}; do
771 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
772 echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
773 app_started=1
774 break
775 else
776 sleep $i
777 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100778 done
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200779 if [ $app_started -eq 0 ]; then
780 ((RES_CONF_FAIL++))
781 echo ""
782 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
783 return 1
784 fi
785 if [ $localport -eq 0 ]; then
786 while [ $localport -eq 0 ]; do
787 echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
788 localport=$(__find_sim_port $appname)
789 sleep 1
790 echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
791 done
792 echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
793 echo ""
794 fi
YongchaoWu9a84f512019-12-16 22:54:11 +0100795 fi
796
797 pa_st=false
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200798 echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100799 for i in {1..20}; do
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200800 if [ $4 == "https" ]; then
801 result="$(__do_curl "-k https://localhost:"${localport}${url})"
802 else
803 result="$(__do_curl $LOCALHOST${localport}${url})"
804 fi
YongchaoWu9a84f512019-12-16 22:54:11 +0100805 if [ $? -eq 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100806 if [ ${#result} -gt 15 ]; then
807 #If response is too long, truncate
808 result="...response text too long, omitted"
809 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200810 echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100811 echo -ne " Container $BOLD${appname}$EBOLD$GREEN is alive$EGREEN, responds to service status:$GREEN $result $EGREEN"
YongchaoWu9a84f512019-12-16 22:54:11 +0100812 pa_st=true
813 break
814 else
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100815 #echo " Retrying in $i seconds"
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200816 echo -ne " Waiting for container ${appname} service status...retrying in $i seconds${SAMELINE}"
YongchaoWu9a84f512019-12-16 22:54:11 +0100817 sleep $i
818 fi
819 done
820
821 if [ "$pa_st" = "false" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100822 ((RES_CONF_FAIL++))
823 echo -e $RED" Container ${appname} did not respond to service status"$ERED
824 return 0
825 fi
826
827 echo ""
828 return 0
829}
830
831
832# Function to start a container and wait until it responds on the given port and url.
833#args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
834__start_container() {
835
836 variableArgCount=$(($#-2))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200837 if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100838 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200839 __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 ]*" $@
YongchaoWu9a84f512019-12-16 22:54:11 +0100840 exit 1
841 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100842
843 __create_docker_network
844
845 curdir=$PWD
846 cd $SIM_GROUP
847 cd $1
848
849 if [ "$2" == "NODOCKERARGS" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200850 docker-compose up -d &> .dockererr
851 if [ $? -ne 0 ]; then
852 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
853 cat .dockererr
854 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200855 elif [ "$2" == "STANDALONE" ]; then
856 echo "Skipping docker-compose"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100857 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200858 docker-compose up -d $2 &> .dockererr
859 if [ $? -ne 0 ]; then
860 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
861 cat .dockererr
862 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100863 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200864 app_prefix=""
865 if [ "$2" == "STANDALONE" ]; then
866 app_prefix="STANDALONE_"
867 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100868 shift; shift;
869 cntr=0
870 while [ $cntr -lt $variableArgCount ]; do
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200871 app=$app_prefix$1; shift;
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100872 port=$1; shift;
873 url=$1; shift;
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200874 httpx=$1; shift;
875 let cntr=cntr+4
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100876
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200877 __check_container_start "$app" "$port" "$url" $httpx
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100878 done
879
880 cd $curdir
881 echo ""
882 return 0
YongchaoWu9a84f512019-12-16 22:54:11 +0100883}
884
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100885####################
886### Consul functions
887####################
888
889# Function to load config from a file into consul for the Policy Agent
890# arg: <json-config-file>
891# (Function for test scripts)
892consul_config_app() {
893
894 echo -e $BOLD"Configuring Consul"$EBOLD
895
896 if [ $# -ne 1 ]; then
897 ((RES_CONF_FAIL++))
898 __print_err "need one arg, <json-config-file>" $@
899 exit 1
900 fi
901
902 echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1
903
904 curl -s $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 >/dev/null
905 if [ $? -ne 0 ]; then
906 echo -e $RED" FAIL - json config could not be loaded to consul" $ERED
907 ((RES_CONF_FAIL++))
908 return 1
909 fi
910 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200911 echo $body > ".output"$1
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100912
913 if [ $? -ne 0 ]; then
914 echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED
915 ((RES_CONF_FAIL++))
916 return 1
917 else
918 targetJson=$(< $1)
919 targetJson="{\"config\":"$targetJson"}"
920 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200921 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100922 if [ $res -ne 0 ]; then
923 echo -e $RED" FAIL - policy json config read from consul/cbs is not equal to the intended json config...." $ERED
924 ((RES_CONF_FAIL++))
925 return 1
926 else
927 echo -e $GREEN" Config loaded ok to consul"$EGREEN
928 fi
929 fi
930
931 echo ""
932
933}
934
935# Function to perpare the consul configuration according to the current simulator configuration
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200936# args: SDNC|SDNC_ONAP|NOSDNC <output-file>
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100937# (Function for test scripts)
938prepare_consul_config() {
939 echo -e $BOLD"Prepare Consul config"$EBOLD
940
941 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
942
943 if [ $# != 2 ]; then
944 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200945 __print_err "need two args, SDNC|SDNC_ONAP|NOSDNC <output-file>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100946 exit 1
947 fi
948
949 if [ $1 == "SDNC" ]; then
950 echo -e " Config$BOLD including SDNC$EBOLD configuration"
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200951 elif [ $1 == "SDNC_ONAP" ]; then
952 echo -e " Config$BOLD including SDNC ONAP$EBOLD configuration"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100953 elif [ $1 == "NOSDNC" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200954 echo -e " Config$BOLD excluding SDNC or SDNC ONAP$EBOLD configuration"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100955 else
956 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200957 __print_err "need two args, SDNC|SDNC_ONAP|NOSDNC <output-file>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100958 exit 1
959 fi
960
961 config_json="\n {"
962 if [ $1 == "SDNC" ]; then
963 config_json=$config_json"\n \"controller\": ["
964 config_json=$config_json"\n {"
965 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200966 if [ $AGENT_STAND_ALONE -eq 0 ]; then
967 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://$SDNC_APP_NAME:$SDNC_PORT\","
968 else
969 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://localhost:$SDNC_LOCAL_PORT\","
970 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100971 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
972 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
973 config_json=$config_json"\n }"
974 config_json=$config_json"\n ],"
975 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200976 if [ $1 == "SDNC_ONAP" ]; then
977 config_json=$config_json"\n \"controller\": ["
978 config_json=$config_json"\n {"
979 config_json=$config_json"\n \"name\": \"$SDNC_ONAP_APP_NAME\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200980 if [ $AGENT_STAND_ALONE -eq 0 ]; then
981 config_json=$config_json"\n \"baseUrl\": \"http://$SDNC_ONAP_APP_NAME:$SDNC_ONAP_INTERNAL_PORT\","
982 else
983 config_json=$config_json"\n \"baseUrl\": \"http://localhost:$SDNC_ONAP_EXTERNAL_PORT\","
984 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200985 config_json=$config_json"\n \"userName\": \"$SDNC_ONAP_USER\","
986 config_json=$config_json"\n \"password\": \"$SDNC_ONAP_PWD\""
987 config_json=$config_json"\n }"
988 config_json=$config_json"\n ],"
989 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100990
991
992 config_json=$config_json"\n \"streams_publishes\": {"
993 config_json=$config_json"\n \"dmaap_publisher\": {"
994 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
995 config_json=$config_json"\n \"dmaap_info\": {"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200996 if [ $AGENT_STAND_ALONE -eq 0 ]; then
997 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_WRITE_URL\""
998 else
999 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_WRITE_URL\""
1000 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001001 config_json=$config_json"\n }"
1002 config_json=$config_json"\n }"
1003 config_json=$config_json"\n },"
1004 config_json=$config_json"\n \"streams_subscribes\": {"
1005 config_json=$config_json"\n \"dmaap_subscriber\": {"
1006 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1007 config_json=$config_json"\n \"dmaap_info\": {"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001008 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1009 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_READ_URL\""
1010 else
1011 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_READ_URL\""
1012 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001013 config_json=$config_json"\n }"
1014 config_json=$config_json"\n }"
1015 config_json=$config_json"\n },"
1016
1017 config_json=$config_json"\n \"ric\": ["
1018
1019 rics=$(docker ps | grep ricsim | awk '{print $NF}')
1020
1021 if [ $? -ne 0 ] || [ -z "$rics" ]; then
1022 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
1023 ((RES_CONF_FAIL++))
1024 return 1
1025 fi
1026
1027 cntr=0
1028 for ric in $rics; do
1029 if [ $cntr -gt 0 ]; then
1030 config_json=$config_json"\n ,"
1031 fi
1032 config_json=$config_json"\n {"
1033 config_json=$config_json"\n \"name\": \"$ric\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001034 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1035 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
1036 else
1037 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://localhost:$(__find_sim_port $ric)\","
1038 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001039 if [ $1 == "SDNC" ]; then
1040 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001041 elif [ $1 == "SDNC_ONAP" ]; then
1042 config_json=$config_json"\n \"controller\": \"$SDNC_ONAP_APP_NAME\","
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001043 fi
1044 config_json=$config_json"\n \"managedElementIds\": ["
1045 config_json=$config_json"\n \"me1_$ric\","
1046 config_json=$config_json"\n \"me2_$ric\""
1047 config_json=$config_json"\n ]"
1048 config_json=$config_json"\n }"
1049 let cntr=cntr+1
1050 done
1051
1052 config_json=$config_json"\n ]"
1053 config_json=$config_json"\n}"
1054
1055
1056 printf "$config_json">$2
1057
1058 echo ""
1059}
1060
1061
1062# Start Consul and CBS
1063# args: -
1064# (Function for test scripts)
1065start_consul_cbs() {
1066
1067 echo -e $BOLD"Starting Consul and CBS"$EBOLD
1068
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001069 __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" "http" \
1070 "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001071}
1072
1073###########################
1074### RIC Simulator functions
1075###########################
1076
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001077use_simulator_http() {
1078 echo -e "Using unsecure $BOLD http $EBOLD towards the simulators"
1079 export RIC_SIM_HTTPX="http"
1080 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1081 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
1082 export RIC_SIM_CERT_MOUNT_DIR="./fakedir" #Fake dir so that the sim container does not find any cert
1083 echo ""
1084}
1085
1086use_simulator_https() {
1087 echo -e "Using secure $BOLD https $EBOLD towards the simulators"
1088 export RIC_SIM_HTTPX="https"
1089 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1090 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
1091 export RIC_SIM_CERT_MOUNT_DIR="./cert"
1092 echo ""
1093}
1094
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001095# Start one group (ricsim_g1, ricsim_g2 or ricsim_g3) with a number of RIC Simulators using a given A interface
1096# args: ricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>
1097# (Function for test scripts)
1098start_ric_simulators() {
1099
1100 echo -e $BOLD"Starting RIC Simulators"$EBOLD
1101
1102 if [ $# != 3 ]; then
1103 ((RES_CONF_FAIL++))
1104 __print_err "need three args, ricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>" $@
1105 exit 1
1106 fi
1107 echo " $2 simulators using basename: $1 on interface: $3"
1108 #Set env var for simulator count and A1 interface vesion for the given group
1109 if [ $1 == "ricsim_g1" ]; then
1110 G1_COUNT=$2
1111 G1_A1_VERSION=$3
1112 elif [ $1 == "ricsim_g2" ]; then
1113 G2_COUNT=$2
1114 G2_A1_VERSION=$3
1115 elif [ $1 == "ricsim_g3" ]; then
1116 G3_COUNT=$2
1117 G3_A1_VERSION=$3
1118 else
1119 ((RES_CONF_FAIL++))
1120 __print_err "need three args, gricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>" $@
1121 exit 1
1122 fi
1123
1124 # Create .env file to compose project, all ric container will get this prefix
1125 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
1126
1127 export G1_A1_VERSION
1128 export G2_A1_VERSION
1129 export G3_A1_VERSION
1130
1131 docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT"
1132 app_data=""
1133 cntr=1
1134 while [ $cntr -le $2 ]; do
1135 app=$1"_"$cntr
1136 port=0
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001137 app_data="$app_data $app $port / "$RIC_SIM_HTTPX
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001138 let cntr=cntr+1
1139 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001140 __start_container ric "$docker_args" $app_data
1141
1142}
1143
1144###########################
1145### Control Panel functions
1146###########################
1147
1148# Start the Control Panel container
1149# args: -
1150# (Function for test scripts)
1151start_control_panel() {
1152
1153 echo -e $BOLD"Starting Control Panel"$EBOLD
1154
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001155 __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001156
1157}
1158
1159##################
1160### SDNC functions
1161##################
1162
1163# Start the SDNC A1 Controller
1164# args: -
1165# (Function for test scripts)
1166start_sdnc() {
1167
1168 echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
1169
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001170 __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT $SDNC_ALIVE_URL "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001171
1172}
1173
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001174use_sdnc_http() {
1175 echo -e $BOLD"Using http between agent and SDNC"$EBOLD
1176 export SDNC_HTTPX="http"
1177 export SDNC_PORT=$SDNC_INTERNAL_PORT
1178 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT
1179 echo ""
1180}
1181
1182use_sdnc_https() {
1183 echo -e $BOLD"Using https between agent and SDNC"$EBOLD
1184 export SDNC_HTTPX="https"
1185 export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT
1186 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT
1187 echo ""
1188}
1189
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001190#######################
1191### SDNC ONAP functions
1192#######################
1193
1194# Start the SDNC ONAP A1 Adapter
1195# args: -
1196# (Function for test scripts)
1197start_sdnc_onap() {
1198
1199 echo -e $BOLD"Starting SDNC ONAP A1 Adapter"$EBOLD
1200
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001201 __start_container sdnc_onap NODOCKERARGS $SDNC_ONAP_APP_NAME $SDNC_ONAP_EXTERNAL_PORT $SDNC_ONAP_ALIVE_URL "http"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001202
1203}
1204
1205# Configure the SDNC ONAP A1 Adapter
1206# args: -
1207# (Function for test scripts)
1208config_sdnc_onap() {
1209
1210 echo -e $BOLD"Configuring SDNC ONAP A1 Adapter"$EBOLD
1211
1212 LOCALFILE=".sdnc_onap.prop"
1213 REMOTEFILE="/tmp/.sdnc_onap.prop"
1214
1215 docker cp $SDNC_ONAP_APP_NAME:$SDNC_ONAP_PROPERTIES_FILE $LOCALFILE
1216 if [ $? -ne 0 ]; then
1217 echo -e $RED"Could not copy $SDNC_ONAP_PROPERTIES_FILE from $SDNC_ONAP_APP_NAME container"$ERED
1218 exit 1
1219 fi
1220
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001221
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001222 #Config of the prop file shall be inserted here
1223
1224 #Copy file to /tmp and then to final destination, a trick to get correct permission of the file.
1225
1226 docker cp $LOCALFILE $SDNC_ONAP_APP_NAME:$REMOTEFILE
1227 if [ $? -ne 0 ]; then
1228 echo -e $RED"Could not copy local $LOCALFILE to $REMOTEFILE in $SDNC_ONAP_APP_NAME container"$ERED
1229 exit 1
1230 fi
1231
1232 docker exec -it $SDNC_ONAP_APP_NAME cp $REMOTEFILE $SDNC_ONAP_PROPERTIES_FILE
1233 if [ $? -ne 0 ]; then
1234 echo -e $RED"Could not copy $REMOTEFILE to $SDNC_ONAP_PROPERTIES_FILE in $SDNC_ONAP_APP_NAME container"$ERED
1235 exit 1
1236 fi
1237}
1238
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001239#####################
1240### MR stub functions
1241#####################
1242
1243# Start the Message Router stub interface in the simulator group
1244# args: -
1245# (Function for test scripts)
1246start_mr() {
1247
1248 echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001249 export MR_CERT_MOUNT_DIR="./cert"
1250 __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001251}
1252
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001253use_mr_http() {
1254 echo -e $BOLD"Using http between agent and MR"$EBOLD
1255 export MR_HTTPX="http"
1256 export MR_PORT=$MR_INTERNAL_PORT
1257 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT
1258 echo ""
1259}
1260
1261use_mr_https() {
1262 echo -e $BOLD"Using https between agent and MR"$EBOLD
1263 export MR_HTTPX="https"
1264 export MR_PORT=$MR_INTERNAL_SECURE_PORT
1265 export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT
1266 echo ""
1267}
1268
1269
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001270################
1271### CR functions
1272################
1273
1274# Start the Callback reciver in the simulator group
1275# args: -
1276# (Function for test scripts)
1277start_cr() {
1278
1279 echo -e $BOLD"Starting Callback Receiver"$EBOLD
1280
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001281 __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001282
1283}
1284
1285###########################
1286### Policy Agents functions
1287###########################
1288
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001289# Use an agent on the local machine instead of container
1290use_agent_stand_alone() {
1291 AGENT_STAND_ALONE=1
1292}
1293
1294# Start the policy agent
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001295# args: -
1296# (Function for test scripts)
1297start_policy_agent() {
1298
1299 echo -e $BOLD"Starting Policy Agent"$EBOLD
1300
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001301 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1302 __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1303 else
1304 echo -e $RED"The consul config produced by this test script (filename '<fullpath-to-autotest-dir>.output<file-name>"$ERED
1305 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
1306 echo -e $RED"application.yaml"$ERED
1307 echo -e $RED"The application jar may need to be built beforefor continuing"$ERED
1308 echo -e $RED"The agent shall now be running on port $POLICY_AGENT_EXTERNAL_PORT for http"$ERED
1309
1310 read -p "<press any key to continue>"
1311 __start_container policy_agent "STANDALONE" $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1312 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001313
1314}
1315
1316# All calls to the agent will be directed to the agent REST interface from now on
1317# args: -
1318# (Function for test scripts)
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001319use_agent_rest_http() {
1320 echo -e $BOLD"Using agent REST interface with http"$EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001321 export ADAPTER=$RESTBASE
1322 echo ""
1323}
1324
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001325# All calls to the agent will be directed to the agent REST interface from now on
1326# args: -
1327# (Function for test scripts)
1328use_agent_rest_https() {
1329 echo -e $BOLD"Using agent REST interface with https"$EBOLD
1330 export ADAPTER=$RESTBASE_SECURE
1331 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001332 return 0
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001333}
1334
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001335# All calls to the agent will be directed to the agent dmaap interface from now on
1336# args: -
1337# (Function for test scripts)
1338use_agent_dmaap() {
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001339 echo -e $BOLD"Agent using DMAAP interface"$EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001340 export ADAPTER=$DMAAPBASE
1341 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001342 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001343}
1344
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001345
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001346# Turn on debug level tracing in the agent
1347# args: -
1348# (Function for test scripts)
1349set_agent_debug() {
1350 echo -e $BOLD"Setting agent debug"$EBOLD
1351 curl $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"debug"}' &> /dev/null
1352 if [ $? -ne 0 ]; then
1353 __print_err "could not set debug mode" $@
1354 return 1
1355 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001356 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001357 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001358}
1359
1360# Perform curl retries when making direct call to the agent for the specified http response codes
1361# Speace separated list of http response codes
1362# args: [<response-code>]*
1363use_agent_retries() {
1364 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
1365 AGENT_RETRY_CODES=$@
1366 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001367 return
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001368}
1369
1370#################
1371### Log functions
1372#################
1373
1374# Check the agent logs for WARNINGs and ERRORs
1375# args: -
1376# (Function for test scripts)
1377
YongchaoWu9a84f512019-12-16 22:54:11 +01001378check_policy_agent_logs() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001379 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH
YongchaoWu9a84f512019-12-16 22:54:11 +01001380}
1381
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001382check_control_panel_logs() {
1383 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH
YongchaoWu9a84f512019-12-16 22:54:11 +01001384}
1385
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001386__check_container_logs() {
1387 dispname=$1
1388 appname=$2
1389 logpath=$3
1390 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
1391
1392 #tmp=$(docker ps | grep $appname)
1393 tmp=$(docker ps -q --filter name=$appname) #get the container id
1394 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
1395 echo $dispname" is not running, no check made"
1396 return
1397 fi
1398 foundentries="$(docker exec -it $tmp grep WARN $logpath | wc -l)"
1399 if [ $? -ne 0 ];then
1400 echo " Problem to search $appname log $logpath"
1401 else
1402 if [ $foundentries -eq 0 ]; then
1403 echo " No WARN entries found in $appname log $logpath"
1404 else
1405 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
1406 fi
1407 fi
1408 foundentries="$(docker exec -it $tmp grep ERR $logpath | wc -l)"
1409 if [ $? -ne 0 ];then
1410 echo " Problem to search $appname log $logpath"
1411 else
1412 if [ $foundentries -eq 0 ]; then
1413 echo " No ERR entries found in $appname log $logpath"
1414 else
1415 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
1416 fi
1417 fi
1418 echo ""
1419}
1420
1421# Store all container logs and other logs in the log dir for the script
1422# Logs are stored with a prefix in case logs should be stored several times during a test
1423# args: <logfile-prefix>
1424# (Function for test scripts)
YongchaoWu9a84f512019-12-16 22:54:11 +01001425store_logs() {
1426 if [ $# != 1 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001427 ((RES_CONF_FAIL++))
1428 __print_err "need one arg, <file-prefix>" $@
YongchaoWu9a84f512019-12-16 22:54:11 +01001429 exit 1
1430 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001431 echo -e $BOLD"Storing all container logs, Policy Agent app log and consul config using prefix: "$1$EBOLD
YongchaoWu9a84f512019-12-16 22:54:11 +01001432
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001433 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
1434 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
1435 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
1436 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
1437 docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
1438 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
1439 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
1440
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001441 docker exec -it $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
1442
1443 docker exec -it $SDNC_ONAP_APP_NAME cat $SDNC_ONAP_KARAF_LOG > $TESTLOGS/$ATC/$1_SDNC_ONAP_karaf.log 2>&1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001444
1445 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
1446 for ric in $rics; do
1447 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
1448 done
1449 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
1450 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
1451 echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +01001452}
1453
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001454###############
1455## Generic curl
1456###############
1457# Generic curl function, assumed all 200-codes are ok
1458# args: <url>
1459# returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
1460# returns: The return code is 0 for ok and 1 for not ok
YongchaoWu9a84f512019-12-16 22:54:11 +01001461__do_curl() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001462 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
1463 curlString="curl -skw %{http_code} $1"
1464 echo " CMD: $curlString" >> $HTTPLOG
1465 res=$($curlString)
1466 echo " RESP: $res" >> $HTTPLOG
YongchaoWu9a84f512019-12-16 22:54:11 +01001467 http_code="${res:${#res}-3}"
1468 if [ ${#res} -eq 3 ]; then
1469 echo "<no-response-from-server>"
1470 return 1
1471 else
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001472 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
YongchaoWu9a84f512019-12-16 22:54:11 +01001473 echo "<not found, resp:${http_code}>"
1474 return 1
1475 fi
1476 if [ $# -eq 2 ]; then
1477 echo "${res:0:${#res}-3}" | xargs
1478 else
1479 echo "${res:0:${#res}-3}"
1480 fi
1481
1482 return 0
1483 fi
1484}
1485
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001486#######################################
1487### Basic helper function for test cases
1488#######################################
1489
1490# Test a simulator container variable value towards target value using an condition operator with an optional timeout.
1491# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
1492# immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
1493# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
1494# before setting pass or fail depending on the result of comparing variable and target using the operator.
1495# 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.
1496# Not to be called from test script.
1497
1498__var_test() {
1499 checkjsonarraycount=0
1500
1501 if [ $# -eq 6 ]; then
1502 if [[ $3 == "json:"* ]]; then
1503 checkjsonarraycount=1
1504 fi
1505
1506 #echo -e "---- ${1} sim test criteria: \033[1m ${3} \033[0m ${4} ${5} within ${6} seconds ----"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001507 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001508 ((RES_TEST++))
1509 start=$SECONDS
1510 ctr=0
1511 for (( ; ; )); do
1512 if [ $checkjsonarraycount -eq 0 ]; then
1513 result="$(__do_curl $2$3)"
1514 retcode=$?
1515 result=${result//[[:blank:]]/} #Strip blanks
1516 else
1517 path=${3:5}
1518 result="$(__do_curl $2$path)"
1519 retcode=$?
1520 echo "$result" > .tmp.curl.json
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001521 result=$(python3 ../common/count_json_elements.py ".tmp.curl.json")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001522 fi
1523 duration=$((SECONDS-start))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001524 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001525 let ctr=ctr+1
1526 if [ $retcode -ne 0 ]; then
1527 if [ $duration -gt $6 ]; then
1528 ((RES_FAIL++))
1529 #echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached in ${6} seconds, result = ${result} ----"
1530 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
1531 return
1532 fi
1533 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
1534 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001535 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001536 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
1537 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds ----"
1538 return
1539 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
1540 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001541 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001542 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
1543 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds, result = ${result} ----"
1544 return
1545 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
1546 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001547 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001548 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
1549 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds, result = ${result} ----"
1550 return
1551 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
1552 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001553 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001554 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
1555 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds, result = ${result} ----"
1556 return
1557 else
1558 if [ $duration -gt $6 ]; then
1559 ((RES_FAIL++))
1560 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
1561 #echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached in ${6} seconds, result = ${result} ----"
1562 return
1563 fi
1564 fi
1565 sleep 1
1566 done
1567 elif [ $# -eq 5 ]; then
1568 if [[ $3 == "json:"* ]]; then
1569 checkjsonarraycount=1
1570 fi
1571
1572 #echo -e "---- ${1} sim test criteria: \033[1m ${3} \033[0m ${4} ${5} ----"
1573 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
1574 ((RES_TEST++))
1575 if [ $checkjsonarraycount -eq 0 ]; then
1576 result="$(__do_curl $2$3)"
1577 retcode=$?
1578 result=${result//[[:blank:]]/} #Strip blanks
1579 else
1580 path=${3:5}
1581 result="$(__do_curl $2$path)"
1582 retcode=$?
1583 echo "$result" > .tmp.curl.json
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001584 result=$(python3 ../common/count_json_elements.py ".tmp.curl.json")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001585 fi
1586 if [ $retcode -ne 0 ]; then
1587 ((RES_FAIL++))
1588 #echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached, result = ${result} ----"
1589 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
1590 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
1591 ((RES_PASS++))
1592 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
1593 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met"
1594 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
1595 ((RES_PASS++))
1596 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
1597 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met, result = ${result} ----"
1598 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
1599 ((RES_PASS++))
1600 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
1601 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met, result = ${result} ----"
1602 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
1603 ((RES_PASS++))
1604 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
1605 #echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met, result = ${result} ----"
1606 else
1607 ((RES_FAIL++))
1608 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
1609 #echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached, result = ${result} ----"
1610 fi
1611 else
1612 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
1613 echo "Got:" $@
1614 exit 1
1615 fi
1616}
1617
1618
1619### Generic test cases for varaible checking
1620
1621# Tests if a variable value in the CR is equal to a target value and and optional timeout.
1622# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1623# equal to the target or not.
1624# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1625# before setting pass or fail depending on if the variable value becomes equal to the target
1626# value or not.
1627# (Function for test scripts)
1628cr_equal() {
1629 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
1630 __var_test "CR" "$LOCALHOST$CR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
1631 else
1632 ((RES_CONF_FAIL++))
1633 __print_err "Wrong args to cr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
1634 fi
1635}
1636
1637# Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
1638# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1639# equal to the target or not.
1640# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1641# before setting pass or fail depending on if the variable value becomes equal to the target
1642# value or not.
1643# (Function for test scripts)
1644mr_equal() {
1645 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
1646 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
1647 else
1648 ((RES_CONF_FAIL++))
1649 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
1650 fi
1651}
1652
1653# Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
1654# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1655# greater than the target or not.
1656# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1657# before setting pass or fail depending on if the variable value becomes greater than the target
1658# value or not.
1659# (Function for test scripts)
1660mr_greater() {
1661 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001662 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 ">" $2 $3
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001663 else
1664 ((RES_CONF_FAIL++))
1665 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
1666 fi
1667}
1668
1669# Read a variable value from MR sim and send to stdout. Arg: <variable-name>
1670mr_read() {
1671 echo "$(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"
1672}
1673
1674# Print a variable value from the MR stub.
1675# arg: <variable-name>
1676# (Function for test scripts)
1677mr_print() {
1678 if [ $# != 1 ]; then
1679 ((RES_CONF_FAIL++))
1680 __print_err "need one arg, <mr-param>" $@
1681 exit 1
1682 fi
1683 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"$EBOLD
1684}