blob: d694ef10c487742430293dd98cbeb8c37d822e18 [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
BjornMagnussonXAad047782020-06-08 15:54:11 +020021# Arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--ricsim-prefix <prefix> ] [--use-local-image <app-nam> [<app-name>]*]
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
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020046tmp=$(which docker-compose)
47if [ $? -ne 0 ] || [ -z tmp ]; then
48 echo -e $RED"docker-compose is required to run the test environment, pls install"$ERED
49 exit 1
50fi
51
BjornMagnussonXA80a92002020-03-19 14:31:06 +010052# Just resetting any previous echo formatting...
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020053echo -ne $EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +010054
55# source test environment variables
56. ../common/test_env.sh
57
58echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@
59
60#Vars for A1 interface version and container count
61G1_A1_VERSION=""
62G2_A1_VERSION=""
63G3_A1_VERSION=""
64G1_COUNT=0
65G2_COUNT=0
66G3_COUNT=0
67
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020068# Vars to switch between http and https. Extra curl flag needed for https
BjornMagnussonXA72667f12020-04-24 09:20:18 +020069export RIC_SIM_HTTPX="http"
70export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
71export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
ecaiyanlinux99a769b2020-05-15 13:58:02 +020072export RIC_SIM_CERT_MOUNT_DIR="./cert"
BjornMagnussonXA72667f12020-04-24 09:20:18 +020073
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020074export MR_HTTPX="http"
75export MR_PORT=$MR_INTERNAL_PORT
76export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker net
77
78export SDNC_HTTPX="http"
79export SDNC_PORT=$SDNC_INTERNAL_PORT
80export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net
81
BjornMagnussonXA80a92002020-03-19 14:31:06 +010082#Localhost constant
83LOCALHOST="http://localhost:"
84
85# Make curl retries for http response codes set in this env var, space separated list of codes
86AGENT_RETRY_CODES=""
87
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020088# Var to contol if the agent runs in a container (normal = 0) or as application on the local machine ( = 1)
89AGENT_STAND_ALONE=0
90
BjornMagnussonXA80a92002020-03-19 14:31:06 +010091# Var to hold 'auto' in case containers shall be stopped when test case ends
92AUTO_CLEAN=""
YongchaoWu9a84f512019-12-16 22:54:11 +010093
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020094# Var to hold the app names to use local image for when running 'remote' or 'remote-remove'
95USE_LOCAL_IMAGES=""
96
BjornMagnussonXAad047782020-06-08 15:54:11 +020097# List of available apps to override with local image
98AVAILABLE_LOCAL_IMAGES_OVERRIDE="PA CP SDNC RICSIM"
99
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200100# Use this var (STOP_AT_ERROR=1 in the test script) for debugging/trouble shooting to take all logs and exit at first FAIL test case
101STOP_AT_ERROR=0
102
YongchaoWu9a84f512019-12-16 22:54:11 +0100103# Set a description string for the test case
104if [ -z "$TC_ONELINE_DESCR" ]; then
105 TC_ONELINE_DESCR="<no-description>"
106 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
107fi
108
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100109# Counter for test suites
110if [ -f .tmp_tcsuite_ctr ]; then
111 tmpval=$(< .tmp_tcsuite_ctr)
112 ((tmpval++))
113 echo $tmpval > .tmp_tcsuite_ctr
114fi
YongchaoWu9a84f512019-12-16 22:54:11 +0100115
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100116# Create a test case id, ATC (Auto Test Case), from the name of the test case script.
117# FTC1.sh -> ATC == FTC1
118ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
YongchaoWu9a84f512019-12-16 22:54:11 +0100119
120# Create the logs dir if not already created in the current dir
121if [ ! -d "logs" ]; then
122 mkdir logs
123fi
YongchaoWu9a84f512019-12-16 22:54:11 +0100124TESTLOGS=$PWD/logs
125
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100126# Create a http message log for this testcase
127HTTPLOG=$PWD"/.httplog_"$ATC".txt"
128echo "" > $HTTPLOG
129
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200130#Create result file (containing '1' for error) for this test case
131#Will be replaced with a file containing '0' if script is ok
132
133echo "1" > "$PWD/.result$ATC.txt"
134
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100135# Create a log dir for the test case
YongchaoWu9a84f512019-12-16 22:54:11 +0100136mkdir -p $TESTLOGS/$ATC
137
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100138# Clear the log dir for the test case
139rm $TESTLOGS/$ATC/*.log &> /dev/null
140rm $TESTLOGS/$ATC/*.txt &> /dev/null
141rm $TESTLOGS/$ATC/*.json &> /dev/null
142
143# Log all output from the test case to a TC log
YongchaoWu9a84f512019-12-16 22:54:11 +0100144TCLOG=$TESTLOGS/$ATC/TC.log
145exec &> >(tee ${TCLOG})
146
147#Variables for counting tests as well as passed and failed tests
148RES_TEST=0
149RES_PASS=0
150RES_FAIL=0
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100151RES_CONF_FAIL=0
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200152RES_DEVIATION=0
153
154#File to keep deviation messages
155DEVIATION_FILE=".tmp_deviations"
156rm $DEVIATION_FILE &> /dev/null
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100157
158#Var for measuring execution time
YongchaoWu9a84f512019-12-16 22:54:11 +0100159TCTEST_START=$SECONDS
160
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200161#File to save timer measurement results
162TIMER_MEASUREMENTS=".timer_measurement.txt"
163echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS
164
165
YongchaoWu9a84f512019-12-16 22:54:11 +0100166echo "-------------------------------------------------------------------------------------------------"
167echo "----------------------------------- Test case: "$ATC
168echo "----------------------------------- Started: "$(date)
169echo "-------------------------------------------------------------------------------------------------"
170echo "-- Description: "$TC_ONELINE_DESCR
171echo "-------------------------------------------------------------------------------------------------"
172echo "----------------------------------- Test case setup -----------------------------------"
173
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200174START_ARG=$1
175paramerror=0
176if [ $# -lt 1 ]; then
177 paramerror=1
178fi
179if [ $paramerror -eq 0 ]; then
180 if [ "$1" != "remote" ] && [ "$1" != "remote-remove" ] && [ "$1" != "local" ]; then
181 paramerror=1
182 else
183 shift;
184 fi
185fi
BjornMagnussonXAad047782020-06-08 15:54:11 +0200186foundparm=0
187while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do
188 foundparm=1
189 if [ $paramerror -eq 0 ]; then
190 if [ "$1" == "auto-clean" ]; then
191 AUTO_CLEAN="auto"
192 echo "Option set - Auto clean at end of test script"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200193 shift;
BjornMagnussonXAad047782020-06-08 15:54:11 +0200194 foundparm=0
195 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200196 fi
BjornMagnussonXAad047782020-06-08 15:54:11 +0200197 if [ $paramerror -eq 0 ]; then
198 if [ "$1" == "--stop-at-error" ]; then
199 STOP_AT_ERROR=1
200 echo "Option set - Stop at first error"
201 shift;
202 foundparm=0
203 fi
204 fi
205 if [ $paramerror -eq 0 ]; then
206 if [ "$1" == "--ricsim-prefix" ]; then
207 shift;
208 RIC_SIM_PREFIX=$1
209 if [ -z "$1" ]; then
210 paramerror=1
211 else
212 echo "Option set - Overriding RIC_SIM_PREFIX with: "$1
213 shift;
214 foundparm=0
215 fi
216 fi
217 fi
218 if [ $paramerror -eq 0 ]; then
219 if [ "$1" == "--use-local-image" ]; then
220 USE_LOCAL_IMAGES=""
221 shift
222 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
223 USE_LOCAL_IMAGES=$USE_LOCAL_IMAGES" "$1
224 if [[ "$AVAILABLE_LOCAL_IMAGES_OVERRIDE" != *"$1"* ]]; then
225 paramerror=1
226 fi
227 shift;
228 done
229 foundparm=0
230 if [ -z "$USE_LOCAL_IMAGES" ]; then
231 paramerror=1
232 else
233 echo "Option set - Override remote images for app(s):"$USE_LOCAL_IMAGES
234 fi
235 fi
236 fi
237done
238echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200239
BjornMagnussonXAad047782020-06-08 15:54:11 +0200240#Still params left?
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200241if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
242 paramerror=1
243fi
244
245if [ $paramerror -eq 1 ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +0200246 echo -e $RED"Expected arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--ricsim-prefix <prefix> ] [--use-local-image <app-nam> [<app-name>]*]"$ERED
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200247 exit 1
248fi
249
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100250echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
YongchaoWu9a84f512019-12-16 22:54:11 +0100251
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100252#Temp var to check for image variable name errors
253IMAGE_ERR=0
254#Create a file with image info for later printing as a table
255image_list_file=".image-list"
256echo -e " Container\tImage\ttag" > $image_list_file
257
258# Check if image env var is set and if so export the env var with image to use (used by docker compose files)
259# arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name>
260__check_image_var() {
261 if [ $# -ne 5 ]; then
262 echo "Expected arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name>"
263 ((IMAGE_ERR++))
264 return
265 fi
266 tmp=${1}"\t"
267 #Create var from the input var names
268 image="${!4}"
269 tag="${!5}"
270
271 if [ -z $image ]; then
272 echo -e $RED"\$"$4" not set in test_env"$ERED
273 ((IMAGE_ERR++))
274 echo ""
275 tmp=$tmp"<no-image>\t"
276 else
277 tmp=$tmp$image"\t"
278 fi
279 if [ -z $tag ]; then
280 echo -e $RED"\$"$5" not set in test_env"$ERED
281 ((IMAGE_ERR++))
282 echo ""
283 tmp=$tmp"<no-tag>\t"
284 else
285 tmp=$tmp$tag
286 fi
287 echo -e "$tmp" >> $image_list_file
288 #Export the env var
289 export "${3}"=$image":"$tag
290
291 #echo " Configured image for ${1} (script start arg=${2}): "$image":"$tag
292}
293
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200294
295#Check if app local image shall override remote image
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200296__check_image_local_override() {
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200297 for im in $USE_LOCAL_IMAGES; do
298 if [ "$1" == "$im" ]; then
299 return 1
300 fi
301 done
302 return 0
303}
304
305#Check if app uses image excluded from this test run
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200306__check_excluded_image() {
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200307 for im in $EXCLUDED_IMAGES; do
308 if [ "$1" == "$im" ]; then
309 return 1
310 fi
311 done
312 return 0
313}
314
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100315# Check that image env setting are available
316echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200317
318if [ $START_ARG == "local" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100319
320 #Local agent image
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200321 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100322
323 #Local Control Panel image
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200324 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100325
326 #Local SNDC image
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200327 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100328
329 #Local ric sim image
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200330 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100331
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200332elif [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100333
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200334 __check_image_local_override 'PA'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200335 if [ $? -eq 0 ]; then
336 #Remote agent image
337 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_REMOTE_IMAGE" "POLICY_AGENT_REMOTE_IMAGE_TAG"
338 else
339 #Local agent image
340 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG"
341 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100342
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200343 __check_image_local_override 'CP'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200344 if [ $? -eq 0 ]; then
345 #Remote Control Panel image
346 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE_TAG"
347 else
348 #Local Control Panel image
349 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG"
350 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100351
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200352 __check_image_local_override 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200353 if [ $? -eq 0 ]; then
354 #Remote SDNC image
355 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE_TAG"
356 else
357 #Local SNDC image
358 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG"
359 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100360
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200361 __check_image_local_override 'RICSIM'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200362 if [ $? -eq 0 ]; then
363 #Remote ric sim image
364 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_REMOTE_IMAGE" "RIC_SIM_REMOTE_IMAGE_TAG"
365 else
366 #Local ric sim image
367 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG"
368 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100369
370else
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200371 #Should never get here....
372 echo "Unknow args: "$@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100373 exit 1
YongchaoWu9a84f512019-12-16 22:54:11 +0100374fi
375
YongchaoWu9a84f512019-12-16 22:54:11 +0100376
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100377# These images are not built as part of this project official images, just check that env vars are set correctly
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200378__check_image_var " Message Router" $START_ARG "MRSTUB_IMAGE" "MRSTUB_LOCAL_IMAGE" "MRSTUB_LOCAL_IMAGE_TAG"
379__check_image_var " Callback Receiver" $START_ARG "CR_IMAGE" "CR_LOCAL_IMAGE" "CR_LOCAL_IMAGE_TAG"
380__check_image_var " Consul" $START_ARG "CONSUL_IMAGE" "CONSUL_REMOTE_IMAGE" "CONSUL_REMOTE_IMAGE_TAG"
381__check_image_var " CBS" $START_ARG "CBS_IMAGE" "CBS_REMOTE_IMAGE" "CBS_REMOTE_IMAGE_TAG"
382__check_image_var " SDNC DB" $START_ARG "SDNC_DB_IMAGE" "SDNC_DB_REMOTE_IMAGE" "SDNC_DB_REMOTE_IMAGE_TAG"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200383__check_excluded_image 'SDNC_ONAP'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200384if [ $? -eq 0 ]; then
385 __check_image_var " SDNC ONAP A1 Adapter" $START_ARG "SDNC_ONAP_A1_ADAPTER_IMAGE" "SDNC_ONAP_A1_ADAPTER_REMOTE_IMAGE" "SDNC_ONAP_A1_ADAPTER_REMOTE_IMAGE_TAG"
386 __check_image_var " SDNC ONAP DB" $START_ARG "SDNC_ONAP_DB_IMAGE" "SDNC_ONAP_DB_REMOTE_IMAGE" "SDNC_ONAP_DB_REMOTE_IMAGE_TAG"
387fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100388
389#Errors in image setting - exit
390if [ $IMAGE_ERR -ne 0 ]; then
391 exit 1
392fi
393
394#Print a tables of the image settings
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200395echo -e $BOLD"Images configured for start arg: "$START $EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100396column -t -s $'\t' $image_list_file
397
YongchaoWuf309b1b2020-01-22 13:24:48 +0100398echo ""
399
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100400
401#Set the SIM_GROUP var
402echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
403if [ -z "$SIM_GROUP" ]; then
404 SIM_GROUP=$PWD/../simulator-group
405 if [ ! -d $SIM_GROUP ]; then
406 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
407 echo -e $RED"Please set the SIM_GROUP manually in the test_env.sh"$ERED
408 exit 1
409 else
410 echo " SIM_GROUP auto set to: " $SIM_GROUP
411 fi
412elif [ $SIM_GROUP = *simulator_group ]; then
413 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
414 exit 1
415else
416 echo " SIM_GROUP env var already set to: " $SIM_GROUP
maximesson28ee8a52020-03-17 09:32:03 +0100417fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100418
419echo ""
420
421#Temp var to check for image pull errors
422IMAGE_ERR=0
423
424#Function to check if image exist and stop+remove the container+pull new images as needed
425#args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
426__check_and_pull_image() {
427
428 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
429 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
430 tmp_im=$(docker images --format $format_string ${4})
431
432 if [ $1 == "local" ]; then
433 if [ -z "$tmp_im" ]; then
434 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
435 ((IMAGE_ERR++))
436 return 1
437 else
438 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
439 fi
440 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
441 if [ $1 == "remote-remove" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200442 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100443 tmp="$(docker ps -aq --filter name=${3})"
444 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200445 docker stop $tmp &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100446 if [ $? -ne 0 ]; then
447 ((IMAGE_ERR++))
448 echo ""
449 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200450 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100451 return 1
452 fi
453 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200454 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100455 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
456 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200457 docker rm $tmp &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100458 if [ $? -ne 0 ]; then
459 ((IMAGE_ERR++))
460 echo ""
461 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200462 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100463 return 1
464 fi
465 fi
466 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200467 echo -ne " Removing image - ${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100468 tmp="$(docker images -q ${4})" &> /dev/null
469 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200470 docker rmi $4 &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100471 if [ $? -ne 0 ]; then
472 ((IMAGE_ERR++))
473 echo ""
474 echo -e $RED" Image could not be removed - try manual removal of the image"$ERED
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200475 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100476 return 1
477 fi
478 echo -e " Removing image - "$GREEN"removed"$EGREEN
479 else
480 echo -e " Removing image - "$GREEN"image not in repository"$EGREEN
481 fi
482 tmp_im=""
483 fi
484 if [ -z "$tmp_im" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200485 echo -ne " Pulling image${SAMELINE}"
486 docker pull $4 &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100487 tmp_im=$(docker images ${4} | grep -v REPOSITORY)
488 if [ -z "$tmp_im" ]; then
489 echo ""
490 echo -e " Pulling image -$RED could not be pulled"$ERED
491 ((IMAGE_ERR++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200492 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100493 return 1
494 fi
495 echo -e " Pulling image -$GREEN Pulled $EGREEN"
496 else
497 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
498 fi
499 fi
500 return 0
501}
502
503
504echo -e $BOLD"Pulling configured images, if needed"$EBOLD
505
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200506START_ARG_MOD=$START_ARG
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200507__check_image_local_override 'PA'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200508if [ $? -eq 1 ]; then
509 START_ARG_MOD="local"
510fi
511app="Policy Agent"; __check_and_pull_image $START_ARG_MOD "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100512
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200513START_ARG_MOD=$START_ARG
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200514__check_image_local_override 'CP'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200515if [ $? -eq 1 ]; then
516 START_ARG_MOD="local"
517fi
518app="Non-RT RIC Control Panel"; __check_and_pull_image $START_ARG_MOD "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200519
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200520START_ARG_MOD=$START_ARG
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200521__check_image_local_override 'RICSIM'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200522if [ $? -eq 1 ]; then
523 START_ARG_MOD="local"
524fi
525app="Near-RT RIC Simulator"; __check_and_pull_image $START_ARG_MOD "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100526
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200527app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
528app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200529__check_excluded_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200530if [ $? -eq 0 ]; then
531 START_ARG_MOD=$START_ARG
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200532 __check_image_local_override 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200533 if [ $? -eq 1 ]; then
534 START_ARG_MOD="local"
535 fi
536 app="SDNC A1 Controller"; __check_and_pull_image $START_ARG_MOD "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
537 app="SDNC DB"; __check_and_pull_image $START_ARG "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
538else
539 echo -e $YELLOW" Excluding SDNC image and related DB image from image check/pull"$EYELLOW
540fi
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200541__check_excluded_image 'SDNC_ONAP'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200542if [ $? -eq 0 ]; then
543 app="SDNC ONAP A1 Adapter"; __check_and_pull_image $START_ARG "$app" $SDNC_ONAP_APP_NAME $SDNC_ONAP_A1_ADAPTER_IMAGE
544 app="SDNC ONAP DB"; __check_and_pull_image $START_ARG "$app" $SDNC_ONAP_APP_NAME $SDNC_ONAP_DB_IMAGE
545else
546 echo -e $YELLOW" Excluding ONAP SDNC image and related DB image from image check/pull"$EYELLOW
547fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100548# MR stub image not checked, will be built by this script - only local image
549# CR stub image not checked, will be built by this script - only local image
550
551
552#Errors in image setting - exit
553if [ $IMAGE_ERR -ne 0 ]; then
554 echo ""
555 echo "#################################################################################################"
556 echo -e $RED"One or more images could not be pulled or containers using the images could not be stopped/removed"$ERED
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200557 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100558 echo "#################################################################################################"
559 echo ""
560 exit 1
561fi
562
563echo ""
564
565echo -e $BOLD"Building images needed for test"$EBOLD
566
567curdir=$PWD
568cd $curdir
569cd ../mrstub
570echo " Building mrstub image: mrstub:latest"
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200571docker build -t mrstub . &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100572if [ $? -eq 0 ]; then
573 echo -e $GREEN" Build Ok"$EGREEN
574else
575 echo -e $RED" Build Failed"$ERED
576 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200577 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100578fi
579cd $curdir
580
581cd ../cr
582echo " Building Callback Receiver image: callback-receiver:latest"
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200583docker build -t callback-receiver . &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100584if [ $? -eq 0 ]; then
585 echo -e $GREEN" Build Ok"$EGREEN
586else
587 echo -e $RED" Build Failed"$ERED
588 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200589 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100590fi
YongchaoWuf309b1b2020-01-22 13:24:48 +0100591cd $curdir
592
593echo ""
594
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100595# Create a table of the images used in the script
596echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
597
598docker_tmp_file=.docker-images-table
599format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}"
600echo -e " Application\tRepository\tTag\tCreated Since\tSize" > $docker_tmp_file
601echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
602echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100603echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
604echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
605echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
606echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
607echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200608__check_excluded_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200609if [ $? -eq 0 ]; then
610 echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
611 echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
612fi
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200613__check_excluded_image 'SDNC_ONAP'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200614if [ $? -eq 0 ]; then
615 echo -e " SDNC ONAP A1 Adapter\t$(docker images --format $format_string $SDNC_ONAP_A1_ADAPTER_IMAGE)" >> $docker_tmp_file
616 echo -e " SDNC ONAP DB\t$(docker images --format $format_string $SDNC_ONAP_DB_IMAGE)" >> $docker_tmp_file
617fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100618
619column -t -s $'\t' $docker_tmp_file
620
YongchaoWuf309b1b2020-01-22 13:24:48 +0100621echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +0100622
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100623echo -e $BOLD"======================================================="$EBOLD
624echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
625echo -e $BOLD"======================================================="$EBOLD
626echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +0100627
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100628# Function to print the test result, shall be the last cmd in a test script
629# args: -
630# (Function for test scripts)
631print_result() {
YongchaoWu9a84f512019-12-16 22:54:11 +0100632
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100633 TCTEST_END=$SECONDS
634 duration=$((TCTEST_END-TCTEST_START))
YongchaoWu9a84f512019-12-16 22:54:11 +0100635
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100636 echo "-------------------------------------------------------------------------------------------------"
637 echo "------------------------------------- Test case: "$ATC
638 echo "------------------------------------- Ended: "$(date)
639 echo "-------------------------------------------------------------------------------------------------"
640 echo "-- Description: "$TC_ONELINE_DESCR
641 echo "-- Execution time: " $duration " seconds"
642 echo "-------------------------------------------------------------------------------------------------"
643 echo "------------------------------------- RESULTS"
YongchaoWu4e489b02020-02-24 09:18:16 +0100644 echo ""
YongchaoWu4e489b02020-02-24 09:18:16 +0100645
YongchaoWu21f17bb2020-03-05 12:44:08 +0100646
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200647 if [ $RES_DEVIATION -gt 0 ]; then
648 echo "Test case deviations"
649 echo "===================================="
650 cat $DEVIATION_FILE
651 fi
652 echo ""
653 echo "Timer measurement in the test script"
654 echo "===================================="
655 column -t -s $'\t' $TIMER_MEASUREMENTS
656 echo ""
657
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100658 total=$((RES_PASS+RES_FAIL))
659 if [ $RES_TEST -eq 0 ]; then
660 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
661 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
662 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
663 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
664 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
665 elif [ $total != $RES_TEST ]; then
666 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
667 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
668 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
669 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
670 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
671 elif [ $RES_CONF_FAIL -ne 0 ]; then
672 echo -e "\033[1mOne or more configure regest has failed. Check the script log....\033[0m"
673 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
674 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
675 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
676 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
677 elif [ $RES_PASS = $RES_TEST ]; then
678 echo -e "All tests \033[32m\033[1mPASS\033[0m"
679 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
680 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
681 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
682 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
683 echo ""
YongchaoWu21f17bb2020-03-05 12:44:08 +0100684
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100685 # Update test suite counter
686 if [ -f .tmp_tcsuite_pass_ctr ]; then
687 tmpval=$(< .tmp_tcsuite_pass_ctr)
688 ((tmpval++))
689 echo $tmpval > .tmp_tcsuite_pass_ctr
690 fi
691 if [ -f .tmp_tcsuite_pass ]; then
692 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
693 fi
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200694 #Create file with OK exit code
695 echo "0" > "$PWD/.result$ATC.txt"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100696 else
697 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
698 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
699 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
700 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
701 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
702 echo ""
703 # Update test suite counter
704 if [ -f .tmp_tcsuite_fail_ctr ]; then
705 tmpval=$(< .tmp_tcsuite_fail_ctr)
706 ((tmpval++))
707 echo $tmpval > .tmp_tcsuite_fail_ctr
708 fi
709 if [ -f .tmp_tcsuite_fail ]; then
710 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
711 fi
YongchaoWu21f17bb2020-03-05 12:44:08 +0100712 fi
YongchaoWu21f17bb2020-03-05 12:44:08 +0100713
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100714 echo "++++ Number of tests: "$RES_TEST
715 echo "++++ Number of passed tests: "$RES_PASS
716 echo "++++ Number of failed tests: "$RES_FAIL
YongchaoWu4e489b02020-02-24 09:18:16 +0100717 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100718 echo "++++ Number of failed configs: "$RES_CONF_FAIL
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200719 echo ""
720 echo "++++ Number of test case deviations: "$RES_DEVIATION
721 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100722 echo "------------------------------------- Test case complete ---------------------------------"
723 echo "-------------------------------------------------------------------------------------------------"
YongchaoWu9a84f512019-12-16 22:54:11 +0100724 echo ""
725}
726
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100727#####################################################################
728###### Functions for start, configuring, stoping, cleaning etc ######
729#####################################################################
YongchaoWu21f17bb2020-03-05 12:44:08 +0100730
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200731# Start timer for time measurement
732# args - (any args will be printed though)
733start_timer() {
734 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
735 TC_TIMER=$SECONDS
736 echo " Timer started"
737}
738
739# Print the value of the time (in seconds)
740# args - <timer message to print> - timer value and message will be printed both on screen
741# and in the timer measurement report
742print_timer() {
743 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
744 if [ $# -lt 1 ]; then
745 ((RES_CONF_FAIL++))
746 __print_err "need 1 or more args, <timer message to print>" $@
747 exit 1
748 fi
749 duration=$(($SECONDS-$TC_TIMER))
750 if [ $duration -eq 0 ]; then
751 duration="<1 second"
752 else
753 duration=$duration" seconds"
754 fi
755 echo " Timer duration :" $duration
756
757 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
758}
759
760# Print the value of the time (in seconds) and reset the timer
761# args - <timer message to print> - timer value and message will be printed both on screen
762# and in the timer measurement report
763print_and_reset_timer() {
764 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
765 if [ $# -lt 1 ]; then
766 ((RES_CONF_FAIL++))
767 __print_err "need 1 or more args, <timer message to print>" $@
768 exit 1
769 fi
770 duration=$(($SECONDS-$TC_TIMER))" seconds"
771 if [ $duration -eq 0 ]; then
772 duration="<1 second"
773 else
774 duration=$duration" seconds"
775 fi
776 echo " Timer duration :" $duration
777 TC_TIMER=$SECONDS
778 echo " Timer reset"
779
780 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
781
782}
783# Print info about a deviations from intended tests
784# Each deviation counted is also printed in the testreport
785# args <deviation message to print>
786deviation() {
787 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
788 if [ $# -lt 1 ]; then
789 ((RES_CONF_FAIL++))
790 __print_err "need 1 or more args, <deviation message to print>" $@
791 exit 1
792 fi
793 ((RES_DEVIATION++))
794 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
795 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
796 echo ""
797}
YongchaoWu21f17bb2020-03-05 12:44:08 +0100798
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200799# Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
800__check_stop_at_error() {
801 if [ $STOP_AT_ERROR -eq 1 ]; then
802 echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
803 store_logs "STOP_AT_ERROR"
804 exit 1
805 fi
806 return 0
807}
808
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100809# Stop and remove all containers
810# args: -
811# (Function for test scripts)
YongchaoWu9a84f512019-12-16 22:54:11 +0100812clean_containers() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100813
814 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
815
816 CONTAINTER_NAMES=("Policy Agent " $POLICY_AGENT_APP_NAME\
817 "Non-RT RIC Simulator(s)" $RIC_SIM_PREFIX\
818 "Message Router " $MR_APP_NAME\
819 "Callback Receiver " $CR_APP_NAME\
820 "Control Panel " $CONTROL_PANEL_APP_NAME\
821 "SDNC A1 Controller " $SDNC_APP_NAME\
822 "SDNC DB " $SDNC_DB_APP_NAME\
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200823 "SDNC ONAP A1 Adapter " $SDNC_ONAP_APP_NAME\
824 "SDNC DB " $SDNC_ONAP_DB_APP_NAME\
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100825 "CBS " $CBS_APP_NAME\
826 "Consul " $CONSUL_APP_NAME)
827
828 nw=0 # Calc max width of container name, to make a nice table
829 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
830 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
831 nw=${#CONTAINTER_NAMES[i]}
832 fi
833 done
834
835 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
836 APP="${CONTAINTER_NAMES[i]}"
837 CONTR="${CONTAINTER_NAMES[i+1]}"
838 for((w=${#CONTR}; w<$nw; w=w+1)); do
839 CONTR="$CONTR "
840 done
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200841 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100842 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200843 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200844 docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100845 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
846 done
847
YongchaoWu9a84f512019-12-16 22:54:11 +0100848 echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200849
850 echo -e $BOLD" Removing docker network"$EBOLD
851 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
852 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
853 docker network rm $DOCKER_SIM_NWNAME
854 if [ $? -ne 0 ]; then
855 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
856 exit 1
857 fi
858 fi
859
860 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
861 docker network prune --force #&> /dev/null
862
863 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
864 docker volume prune --force #&> /dev/null
865
866 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
867 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
868 echo ""
BjornMagnussonXAad047782020-06-08 15:54:11 +0200869
870 CONTRS=$(docker ps | awk '$1 != "CONTAINER" { n++ }; END { print n+0 }')
871 if [ $? -eq 0 ]; then
872 if [ $CONTRS -ne 0 ]; then
873 echo -e $RED"Containers running, may cause distubance to the test case"$ERED
874 docker ps -a
875 fi
876 fi
YongchaoWu9a84f512019-12-16 22:54:11 +0100877}
878
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100879# Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
880# args: -
881# (Function for test scripts)
882auto_clean_containers() {
883 echo
884 if [ "$AUTO_CLEAN" == "auto" ]; then
885 echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
886 clean_containers
YongchaoWu9a84f512019-12-16 22:54:11 +0100887 fi
888}
889
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100890# Function to sleep a test case for a numner of seconds. Prints the optional text args as info
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200891# args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100892# (Function for test scripts)
893sleep_wait() {
YongchaoWu9a84f512019-12-16 22:54:11 +0100894
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100895 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
896 if [ $# -lt 1 ]; then
897 ((RES_CONF_FAIL++))
898 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
899 exit 1
900 fi
901 #echo "---- Sleep for " $1 " seconds ---- "$2
902 start=$SECONDS
903 duration=$((SECONDS-start))
904 while [ $duration -lt $1 ]; do
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200905 echo -ne " Slept for ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100906 sleep 1
907 duration=$((SECONDS-start))
908 done
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200909 echo -ne " Slept for ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100910 echo ""
911}
912
913# Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
914# Not to be called from the test script itself.
915__print_err() {
916 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
917 if [ $# -gt 1 ]; then
918 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
919 fi
920}
921
922
923# Helper function to get a the port of a specific ric simulatpor
924# args: <ric-id>
925# (Not for test scripts)
926__find_sim_port() {
927 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
ecaiyanlinux99a769b2020-05-15 13:58:02 +0200928 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
929 res=$(eval $cmdstr)
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100930 if [[ "$res" =~ ^[0-9]+$ ]]; then
931 echo $res
932 else
933 echo "0"
934 fi
935}
936
937# Function to create the docker network for the test
938# Not to be called from the test script itself.
939__create_docker_network() {
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200940 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100941 if [ $? -ne 0 ]; then
942 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
943 return 1
944 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200945 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100946 echo -e "Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
947 docker network create $DOCKER_SIM_NWNAME
948 if [ $? -ne 0 ]; then
949 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
950 return 1
951 fi
952 else
953 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
954 fi
955}
956
957# Check if container is started by calling url on localhost using a port, expects response code 2XX
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200958# args: <container-name> <port> <url> https|https
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100959# Not to be called from the test script itself.
960__check_container_start() {
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200961 paramError=0
962 if [ $# -ne 4 ]; then
963 paramError=1
964 elif [ $4 != "http" ] && [ $4 != "https" ]; then
965 paramError=1
966 fi
967 if [ $paramError -ne 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100968 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200969 __print_err "need 3 args, <container-name> <port> <url> https|https" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100970 return 1
971 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200972 echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
YongchaoWu9a84f512019-12-16 22:54:11 +0100973 appname=$1
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100974 localport=$2
975 url=$3
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200976 if [[ $appname != "STANDALONE_"* ]] ; then
977 app_started=0
978 for i in {1..10}; do
979 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
980 echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
981 app_started=1
982 break
983 else
984 sleep $i
985 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100986 done
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200987 if [ $app_started -eq 0 ]; then
988 ((RES_CONF_FAIL++))
989 echo ""
990 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
991 return 1
992 fi
993 if [ $localport -eq 0 ]; then
994 while [ $localport -eq 0 ]; do
995 echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
996 localport=$(__find_sim_port $appname)
997 sleep 1
998 echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
999 done
1000 echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
1001 echo ""
1002 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001003 fi
1004
1005 pa_st=false
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001006 echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001007 TSTART=$SECONDS
1008 for i in {1..50}; do
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001009 if [ $4 == "https" ]; then
1010 result="$(__do_curl "-k https://localhost:"${localport}${url})"
1011 else
1012 result="$(__do_curl $LOCALHOST${localport}${url})"
1013 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001014 if [ $? -eq 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001015 if [ ${#result} -gt 15 ]; then
1016 #If response is too long, truncate
1017 result="...response text too long, omitted"
1018 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001019 echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001020 echo -ne " Container $BOLD${appname}$EBOLD$GREEN is alive$EGREEN, responds to service status:$GREEN $result $EGREEN after $(($SECONDS-$TSTART)) seconds"
YongchaoWu9a84f512019-12-16 22:54:11 +01001021 pa_st=true
1022 break
1023 else
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001024 TS_TMP=$SECONDS
1025 while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
1026 echo -ne " Waiting for container ${appname} service status...retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
1027 sleep 1
1028 done
YongchaoWu9a84f512019-12-16 22:54:11 +01001029 fi
1030 done
1031
1032 if [ "$pa_st" = "false" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001033 ((RES_CONF_FAIL++))
1034 echo -e $RED" Container ${appname} did not respond to service status"$ERED
1035 return 0
1036 fi
1037
1038 echo ""
1039 return 0
1040}
1041
1042
1043# Function to start a container and wait until it responds on the given port and url.
1044#args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
1045__start_container() {
1046
1047 variableArgCount=$(($#-2))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001048 if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001049 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001050 __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 +01001051 exit 1
1052 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001053
1054 __create_docker_network
1055
1056 curdir=$PWD
1057 cd $SIM_GROUP
1058 cd $1
1059
1060 if [ "$2" == "NODOCKERARGS" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001061 docker-compose up -d &> .dockererr
1062 if [ $? -ne 0 ]; then
1063 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1064 cat .dockererr
1065 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001066 elif [ "$2" == "STANDALONE" ]; then
1067 echo "Skipping docker-compose"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001068 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001069 docker-compose up -d $2 &> .dockererr
1070 if [ $? -ne 0 ]; then
1071 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1072 cat .dockererr
1073 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001074 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001075 app_prefix=""
1076 if [ "$2" == "STANDALONE" ]; then
1077 app_prefix="STANDALONE_"
1078 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001079 shift; shift;
1080 cntr=0
1081 while [ $cntr -lt $variableArgCount ]; do
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001082 app=$app_prefix$1; shift;
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001083 port=$1; shift;
1084 url=$1; shift;
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001085 httpx=$1; shift;
1086 let cntr=cntr+4
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001087
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001088 __check_container_start "$app" "$port" "$url" $httpx
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001089 done
1090
1091 cd $curdir
1092 echo ""
1093 return 0
YongchaoWu9a84f512019-12-16 22:54:11 +01001094}
1095
BjornMagnussonXAad047782020-06-08 15:54:11 +02001096# Generate a UUID to use as prefix for policy ids
1097generate_uuid() {
1098 UUID=$(python3 -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
1099 #Reduce length to make space for serial id, us 'a' as marker where the serial id is added
1100 UUID=${UUID:0:${#UUID}-4}"a"
1101}
1102
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001103####################
1104### Consul functions
1105####################
1106
1107# Function to load config from a file into consul for the Policy Agent
1108# arg: <json-config-file>
1109# (Function for test scripts)
1110consul_config_app() {
1111
1112 echo -e $BOLD"Configuring Consul"$EBOLD
1113
1114 if [ $# -ne 1 ]; then
1115 ((RES_CONF_FAIL++))
1116 __print_err "need one arg, <json-config-file>" $@
1117 exit 1
1118 fi
1119
1120 echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1
1121
1122 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
1123 if [ $? -ne 0 ]; then
1124 echo -e $RED" FAIL - json config could not be loaded to consul" $ERED
1125 ((RES_CONF_FAIL++))
1126 return 1
1127 fi
1128 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001129 echo $body > ".output"$1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001130
1131 if [ $? -ne 0 ]; then
1132 echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED
1133 ((RES_CONF_FAIL++))
1134 return 1
1135 else
1136 targetJson=$(< $1)
1137 targetJson="{\"config\":"$targetJson"}"
1138 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001139 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001140 if [ $res -ne 0 ]; then
1141 echo -e $RED" FAIL - policy json config read from consul/cbs is not equal to the intended json config...." $ERED
1142 ((RES_CONF_FAIL++))
1143 return 1
1144 else
1145 echo -e $GREEN" Config loaded ok to consul"$EGREEN
1146 fi
1147 fi
1148
1149 echo ""
1150
1151}
1152
1153# Function to perpare the consul configuration according to the current simulator configuration
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001154# args: SDNC|SDNC_ONAP|NOSDNC <output-file>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001155# (Function for test scripts)
1156prepare_consul_config() {
1157 echo -e $BOLD"Prepare Consul config"$EBOLD
1158
1159 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
1160
1161 if [ $# != 2 ]; then
1162 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001163 __print_err "need two args, SDNC|SDNC_ONAP|NOSDNC <output-file>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001164 exit 1
1165 fi
1166
1167 if [ $1 == "SDNC" ]; then
1168 echo -e " Config$BOLD including SDNC$EBOLD configuration"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001169 elif [ $1 == "SDNC_ONAP" ]; then
1170 echo -e " Config$BOLD including SDNC ONAP$EBOLD configuration"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001171 elif [ $1 == "NOSDNC" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001172 echo -e " Config$BOLD excluding SDNC or SDNC ONAP$EBOLD configuration"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001173 else
1174 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001175 __print_err "need two args, SDNC|SDNC_ONAP|NOSDNC <output-file>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001176 exit 1
1177 fi
1178
1179 config_json="\n {"
1180 if [ $1 == "SDNC" ]; then
1181 config_json=$config_json"\n \"controller\": ["
1182 config_json=$config_json"\n {"
1183 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001184 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1185 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://$SDNC_APP_NAME:$SDNC_PORT\","
1186 else
1187 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://localhost:$SDNC_LOCAL_PORT\","
1188 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001189 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
1190 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
1191 config_json=$config_json"\n }"
1192 config_json=$config_json"\n ],"
1193 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001194 if [ $1 == "SDNC_ONAP" ]; then
1195 config_json=$config_json"\n \"controller\": ["
1196 config_json=$config_json"\n {"
1197 config_json=$config_json"\n \"name\": \"$SDNC_ONAP_APP_NAME\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001198 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1199 config_json=$config_json"\n \"baseUrl\": \"http://$SDNC_ONAP_APP_NAME:$SDNC_ONAP_INTERNAL_PORT\","
1200 else
1201 config_json=$config_json"\n \"baseUrl\": \"http://localhost:$SDNC_ONAP_EXTERNAL_PORT\","
1202 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001203 config_json=$config_json"\n \"userName\": \"$SDNC_ONAP_USER\","
1204 config_json=$config_json"\n \"password\": \"$SDNC_ONAP_PWD\""
1205 config_json=$config_json"\n }"
1206 config_json=$config_json"\n ],"
1207 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001208
1209
1210 config_json=$config_json"\n \"streams_publishes\": {"
1211 config_json=$config_json"\n \"dmaap_publisher\": {"
1212 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1213 config_json=$config_json"\n \"dmaap_info\": {"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001214 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1215 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_WRITE_URL\""
1216 else
1217 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_WRITE_URL\""
1218 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001219 config_json=$config_json"\n }"
1220 config_json=$config_json"\n }"
1221 config_json=$config_json"\n },"
1222 config_json=$config_json"\n \"streams_subscribes\": {"
1223 config_json=$config_json"\n \"dmaap_subscriber\": {"
1224 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1225 config_json=$config_json"\n \"dmaap_info\": {"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001226 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1227 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_READ_URL\""
1228 else
1229 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_READ_URL\""
1230 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001231 config_json=$config_json"\n }"
1232 config_json=$config_json"\n }"
1233 config_json=$config_json"\n },"
1234
1235 config_json=$config_json"\n \"ric\": ["
1236
BjornMagnussonXAad047782020-06-08 15:54:11 +02001237 rics=$(docker ps | grep $RIC_SIM_PREFIX | awk '{print $NF}')
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001238
1239 if [ $? -ne 0 ] || [ -z "$rics" ]; then
1240 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
1241 ((RES_CONF_FAIL++))
1242 return 1
1243 fi
1244
1245 cntr=0
1246 for ric in $rics; do
1247 if [ $cntr -gt 0 ]; then
1248 config_json=$config_json"\n ,"
1249 fi
1250 config_json=$config_json"\n {"
1251 config_json=$config_json"\n \"name\": \"$ric\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001252 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1253 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
1254 else
1255 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://localhost:$(__find_sim_port $ric)\","
1256 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001257 if [ $1 == "SDNC" ]; then
1258 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001259 elif [ $1 == "SDNC_ONAP" ]; then
1260 config_json=$config_json"\n \"controller\": \"$SDNC_ONAP_APP_NAME\","
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001261 fi
1262 config_json=$config_json"\n \"managedElementIds\": ["
1263 config_json=$config_json"\n \"me1_$ric\","
1264 config_json=$config_json"\n \"me2_$ric\""
1265 config_json=$config_json"\n ]"
1266 config_json=$config_json"\n }"
1267 let cntr=cntr+1
1268 done
1269
1270 config_json=$config_json"\n ]"
1271 config_json=$config_json"\n}"
1272
1273
1274 printf "$config_json">$2
1275
1276 echo ""
1277}
1278
1279
1280# Start Consul and CBS
1281# args: -
1282# (Function for test scripts)
1283start_consul_cbs() {
1284
1285 echo -e $BOLD"Starting Consul and CBS"$EBOLD
1286
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001287 __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" "http" \
1288 "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001289}
1290
1291###########################
1292### RIC Simulator functions
1293###########################
1294
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001295use_simulator_http() {
1296 echo -e "Using unsecure $BOLD http $EBOLD towards the simulators"
1297 export RIC_SIM_HTTPX="http"
1298 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1299 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001300 echo ""
1301}
1302
1303use_simulator_https() {
1304 echo -e "Using secure $BOLD https $EBOLD towards the simulators"
1305 export RIC_SIM_HTTPX="https"
1306 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1307 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001308 echo ""
1309}
1310
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001311# Start one group (ricsim_g1, ricsim_g2 or ricsim_g3) with a number of RIC Simulators using a given A interface
BjornMagnussonXAad047782020-06-08 15:54:11 +02001312# 'ricsim' may be set on command line to other prefix
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001313# args: ricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>
1314# (Function for test scripts)
1315start_ric_simulators() {
1316
1317 echo -e $BOLD"Starting RIC Simulators"$EBOLD
1318
BjornMagnussonXAad047782020-06-08 15:54:11 +02001319 RIC1=$RIC_SIM_PREFIX"_g1"
1320 RIC2=$RIC_SIM_PREFIX"_g2"
1321 RIC3=$RIC_SIM_PREFIX"_g3"
1322
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001323 if [ $# != 3 ]; then
1324 ((RES_CONF_FAIL++))
BjornMagnussonXAad047782020-06-08 15:54:11 +02001325 __print_err "need three args, $RIC1|$RIC2|$RIC3 <count> <interface-id>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001326 exit 1
1327 fi
1328 echo " $2 simulators using basename: $1 on interface: $3"
1329 #Set env var for simulator count and A1 interface vesion for the given group
BjornMagnussonXAad047782020-06-08 15:54:11 +02001330 if [ $1 == "$RIC1" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001331 G1_COUNT=$2
1332 G1_A1_VERSION=$3
BjornMagnussonXAad047782020-06-08 15:54:11 +02001333 elif [ $1 == "$RIC2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001334 G2_COUNT=$2
1335 G2_A1_VERSION=$3
BjornMagnussonXAad047782020-06-08 15:54:11 +02001336 elif [ $1 == "$RIC3" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001337 G3_COUNT=$2
1338 G3_A1_VERSION=$3
1339 else
1340 ((RES_CONF_FAIL++))
BjornMagnussonXAad047782020-06-08 15:54:11 +02001341 __print_err "need three args, $RIC1|$RIC2|$RIC3 <count> <interface-id>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001342 exit 1
1343 fi
1344
1345 # Create .env file to compose project, all ric container will get this prefix
1346 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
1347
1348 export G1_A1_VERSION
1349 export G2_A1_VERSION
1350 export G3_A1_VERSION
1351
1352 docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT"
1353 app_data=""
1354 cntr=1
1355 while [ $cntr -le $2 ]; do
1356 app=$1"_"$cntr
1357 port=0
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001358 app_data="$app_data $app $port / "$RIC_SIM_HTTPX
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001359 let cntr=cntr+1
1360 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001361 __start_container ric "$docker_args" $app_data
1362
1363}
1364
1365###########################
1366### Control Panel functions
1367###########################
1368
1369# Start the Control Panel container
1370# args: -
1371# (Function for test scripts)
1372start_control_panel() {
1373
1374 echo -e $BOLD"Starting Control Panel"$EBOLD
1375
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001376 __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001377
1378}
1379
1380##################
1381### SDNC functions
1382##################
1383
1384# Start the SDNC A1 Controller
1385# args: -
1386# (Function for test scripts)
1387start_sdnc() {
1388
1389 echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
1390
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001391 __check_excluded_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001392 if [ $? -eq 1 ]; then
1393 echo -e $RED"The image for SDNC and the related DB has not been checked for this test run due to arg to the test script"$ERED
1394 echo -e $RED"SDNC will not be started"$ERED
1395 exit
1396 fi
1397
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001398 __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT $SDNC_ALIVE_URL "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001399
1400}
1401
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001402use_sdnc_http() {
1403 echo -e $BOLD"Using http between agent and SDNC"$EBOLD
1404 export SDNC_HTTPX="http"
1405 export SDNC_PORT=$SDNC_INTERNAL_PORT
1406 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT
1407 echo ""
1408}
1409
1410use_sdnc_https() {
1411 echo -e $BOLD"Using https between agent and SDNC"$EBOLD
1412 export SDNC_HTTPX="https"
1413 export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT
1414 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT
1415 echo ""
1416}
1417
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001418#######################
1419### SDNC ONAP functions
1420#######################
1421
1422# Start the SDNC ONAP A1 Adapter
1423# args: -
1424# (Function for test scripts)
1425start_sdnc_onap() {
1426
1427 echo -e $BOLD"Starting SDNC ONAP A1 Adapter"$EBOLD
1428
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001429 __check_excluded_image 'SDNC_ONAP'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001430 if [ $? -eq 1 ]; then
1431 echo -e $RED"The image for SDNC ONAP and the related DB has not been checked for this test run due to arg to the test script"$ERED
1432 echo -e $RED"SDNC ONAP will not be started"$ERED
1433 exit
1434 fi
1435
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001436 __start_container sdnc_onap NODOCKERARGS $SDNC_ONAP_APP_NAME $SDNC_ONAP_EXTERNAL_PORT $SDNC_ONAP_ALIVE_URL "http"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001437
1438}
1439
1440# Configure the SDNC ONAP A1 Adapter
1441# args: -
1442# (Function for test scripts)
1443config_sdnc_onap() {
1444
1445 echo -e $BOLD"Configuring SDNC ONAP A1 Adapter"$EBOLD
1446
1447 LOCALFILE=".sdnc_onap.prop"
1448 REMOTEFILE="/tmp/.sdnc_onap.prop"
1449
1450 docker cp $SDNC_ONAP_APP_NAME:$SDNC_ONAP_PROPERTIES_FILE $LOCALFILE
1451 if [ $? -ne 0 ]; then
1452 echo -e $RED"Could not copy $SDNC_ONAP_PROPERTIES_FILE from $SDNC_ONAP_APP_NAME container"$ERED
1453 exit 1
1454 fi
1455
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001456
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001457 #Config of the prop file shall be inserted here
1458
1459 #Copy file to /tmp and then to final destination, a trick to get correct permission of the file.
1460
1461 docker cp $LOCALFILE $SDNC_ONAP_APP_NAME:$REMOTEFILE
1462 if [ $? -ne 0 ]; then
1463 echo -e $RED"Could not copy local $LOCALFILE to $REMOTEFILE in $SDNC_ONAP_APP_NAME container"$ERED
1464 exit 1
1465 fi
1466
1467 docker exec -it $SDNC_ONAP_APP_NAME cp $REMOTEFILE $SDNC_ONAP_PROPERTIES_FILE
1468 if [ $? -ne 0 ]; then
1469 echo -e $RED"Could not copy $REMOTEFILE to $SDNC_ONAP_PROPERTIES_FILE in $SDNC_ONAP_APP_NAME container"$ERED
1470 exit 1
1471 fi
1472}
1473
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001474#####################
1475### MR stub functions
1476#####################
1477
1478# Start the Message Router stub interface in the simulator group
1479# args: -
1480# (Function for test scripts)
1481start_mr() {
1482
1483 echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001484 export MR_CERT_MOUNT_DIR="./cert"
1485 __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001486}
1487
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001488use_mr_http() {
1489 echo -e $BOLD"Using http between agent and MR"$EBOLD
1490 export MR_HTTPX="http"
1491 export MR_PORT=$MR_INTERNAL_PORT
1492 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT
1493 echo ""
1494}
1495
1496use_mr_https() {
1497 echo -e $BOLD"Using https between agent and MR"$EBOLD
1498 export MR_HTTPX="https"
1499 export MR_PORT=$MR_INTERNAL_SECURE_PORT
1500 export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT
1501 echo ""
1502}
1503
1504
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001505################
1506### CR functions
1507################
1508
1509# Start the Callback reciver in the simulator group
1510# args: -
1511# (Function for test scripts)
1512start_cr() {
1513
1514 echo -e $BOLD"Starting Callback Receiver"$EBOLD
1515
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001516 __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001517
1518}
1519
1520###########################
1521### Policy Agents functions
1522###########################
1523
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001524# Use an agent on the local machine instead of container
1525use_agent_stand_alone() {
1526 AGENT_STAND_ALONE=1
1527}
1528
1529# Start the policy agent
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001530# args: -
1531# (Function for test scripts)
1532start_policy_agent() {
1533
1534 echo -e $BOLD"Starting Policy Agent"$EBOLD
1535
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001536 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1537 __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1538 else
1539 echo -e $RED"The consul config produced by this test script (filename '<fullpath-to-autotest-dir>.output<file-name>"$ERED
1540 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
1541 echo -e $RED"application.yaml"$ERED
1542 echo -e $RED"The application jar may need to be built beforefor continuing"$ERED
1543 echo -e $RED"The agent shall now be running on port $POLICY_AGENT_EXTERNAL_PORT for http"$ERED
1544
1545 read -p "<press any key to continue>"
1546 __start_container policy_agent "STANDALONE" $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1547 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001548
1549}
1550
1551# All calls to the agent will be directed to the agent REST interface from now on
1552# args: -
1553# (Function for test scripts)
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001554use_agent_rest_http() {
1555 echo -e $BOLD"Using agent REST interface with http"$EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001556 export ADAPTER=$RESTBASE
1557 echo ""
1558}
1559
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001560# All calls to the agent will be directed to the agent REST interface from now on
1561# args: -
1562# (Function for test scripts)
1563use_agent_rest_https() {
1564 echo -e $BOLD"Using agent REST interface with https"$EBOLD
1565 export ADAPTER=$RESTBASE_SECURE
1566 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001567 return 0
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001568}
1569
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001570# All calls to the agent will be directed to the agent dmaap interface from now on
1571# args: -
1572# (Function for test scripts)
1573use_agent_dmaap() {
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001574 echo -e $BOLD"Agent using DMAAP interface"$EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001575 export ADAPTER=$DMAAPBASE
1576 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001577 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001578}
1579
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001580
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001581# Turn on debug level tracing in the agent
1582# args: -
1583# (Function for test scripts)
1584set_agent_debug() {
1585 echo -e $BOLD"Setting agent debug"$EBOLD
1586 curl $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"debug"}' &> /dev/null
1587 if [ $? -ne 0 ]; then
1588 __print_err "could not set debug mode" $@
1589 return 1
1590 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001591 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001592 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001593}
1594
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001595# Turn on trace level tracing in the agent
1596# args: -
1597# (Function for test scripts)
1598set_agent_trace() {
1599 echo -e $BOLD"Setting agent trace"$EBOLD
1600 curl $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"trace"}' &> /dev/null
1601 if [ $? -ne 0 ]; then
1602 __print_err "could not set trace mode" $@
1603 return 1
1604 fi
1605 echo ""
1606 return 0
1607}
1608
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001609# Perform curl retries when making direct call to the agent for the specified http response codes
1610# Speace separated list of http response codes
1611# args: [<response-code>]*
1612use_agent_retries() {
1613 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
1614 AGENT_RETRY_CODES=$@
1615 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001616 return
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001617}
1618
1619#################
1620### Log functions
1621#################
1622
1623# Check the agent logs for WARNINGs and ERRORs
1624# args: -
1625# (Function for test scripts)
1626
YongchaoWu9a84f512019-12-16 22:54:11 +01001627check_policy_agent_logs() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001628 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH
YongchaoWu9a84f512019-12-16 22:54:11 +01001629}
1630
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001631check_control_panel_logs() {
1632 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH
YongchaoWu9a84f512019-12-16 22:54:11 +01001633}
1634
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001635__check_container_logs() {
1636 dispname=$1
1637 appname=$2
1638 logpath=$3
1639 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
1640
1641 #tmp=$(docker ps | grep $appname)
1642 tmp=$(docker ps -q --filter name=$appname) #get the container id
1643 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
1644 echo $dispname" is not running, no check made"
1645 return
1646 fi
1647 foundentries="$(docker exec -it $tmp grep WARN $logpath | wc -l)"
1648 if [ $? -ne 0 ];then
1649 echo " Problem to search $appname log $logpath"
1650 else
1651 if [ $foundentries -eq 0 ]; then
1652 echo " No WARN entries found in $appname log $logpath"
1653 else
1654 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
1655 fi
1656 fi
1657 foundentries="$(docker exec -it $tmp grep ERR $logpath | wc -l)"
1658 if [ $? -ne 0 ];then
1659 echo " Problem to search $appname log $logpath"
1660 else
1661 if [ $foundentries -eq 0 ]; then
1662 echo " No ERR entries found in $appname log $logpath"
1663 else
1664 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
1665 fi
1666 fi
1667 echo ""
1668}
1669
1670# Store all container logs and other logs in the log dir for the script
1671# Logs are stored with a prefix in case logs should be stored several times during a test
1672# args: <logfile-prefix>
1673# (Function for test scripts)
YongchaoWu9a84f512019-12-16 22:54:11 +01001674store_logs() {
1675 if [ $# != 1 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001676 ((RES_CONF_FAIL++))
1677 __print_err "need one arg, <file-prefix>" $@
YongchaoWu9a84f512019-12-16 22:54:11 +01001678 exit 1
1679 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001680 echo -e $BOLD"Storing all container logs, Policy Agent app log and consul config using prefix: "$1$EBOLD
YongchaoWu9a84f512019-12-16 22:54:11 +01001681
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001682 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001683 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
1684 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
1685 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
1686 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
1687 docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
1688 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
1689 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
1690
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001691 docker exec -it $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
1692
1693 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 +01001694
1695 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
1696 for ric in $rics; do
1697 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
1698 done
1699 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
1700 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
1701 echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +01001702}
1703
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001704###############
1705## Generic curl
1706###############
1707# Generic curl function, assumed all 200-codes are ok
1708# args: <url>
1709# returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
1710# returns: The return code is 0 for ok and 1 for not ok
YongchaoWu9a84f512019-12-16 22:54:11 +01001711__do_curl() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001712 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
1713 curlString="curl -skw %{http_code} $1"
1714 echo " CMD: $curlString" >> $HTTPLOG
1715 res=$($curlString)
1716 echo " RESP: $res" >> $HTTPLOG
YongchaoWu9a84f512019-12-16 22:54:11 +01001717 http_code="${res:${#res}-3}"
1718 if [ ${#res} -eq 3 ]; then
1719 echo "<no-response-from-server>"
1720 return 1
1721 else
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001722 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
YongchaoWu9a84f512019-12-16 22:54:11 +01001723 echo "<not found, resp:${http_code}>"
1724 return 1
1725 fi
1726 if [ $# -eq 2 ]; then
1727 echo "${res:0:${#res}-3}" | xargs
1728 else
1729 echo "${res:0:${#res}-3}"
1730 fi
1731
1732 return 0
1733 fi
1734}
1735
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001736#######################################
1737### Basic helper function for test cases
1738#######################################
1739
1740# Test a simulator container variable value towards target value using an condition operator with an optional timeout.
1741# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
1742# immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
1743# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
1744# before setting pass or fail depending on the result of comparing variable and target using the operator.
1745# 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.
1746# Not to be called from test script.
1747
1748__var_test() {
1749 checkjsonarraycount=0
1750
1751 if [ $# -eq 6 ]; then
1752 if [[ $3 == "json:"* ]]; then
1753 checkjsonarraycount=1
1754 fi
1755
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001756 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001757 ((RES_TEST++))
1758 start=$SECONDS
1759 ctr=0
1760 for (( ; ; )); do
1761 if [ $checkjsonarraycount -eq 0 ]; then
1762 result="$(__do_curl $2$3)"
1763 retcode=$?
1764 result=${result//[[:blank:]]/} #Strip blanks
1765 else
1766 path=${3:5}
1767 result="$(__do_curl $2$path)"
1768 retcode=$?
1769 echo "$result" > .tmp.curl.json
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001770 result=$(python3 ../common/count_json_elements.py ".tmp.curl.json")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001771 fi
1772 duration=$((SECONDS-start))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001773 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001774 let ctr=ctr+1
1775 if [ $retcode -ne 0 ]; then
1776 if [ $duration -gt $6 ]; then
1777 ((RES_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001778 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001779 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001780 return
1781 fi
1782 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
1783 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001784 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001785 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001786 return
1787 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
1788 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001789 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001790 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001791 return
1792 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
1793 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001794 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001795 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001796 return
1797 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
1798 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001799 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001800 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001801 return
1802 else
1803 if [ $duration -gt $6 ]; then
1804 ((RES_FAIL++))
1805 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001806 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001807 return
1808 fi
1809 fi
1810 sleep 1
1811 done
1812 elif [ $# -eq 5 ]; then
1813 if [[ $3 == "json:"* ]]; then
1814 checkjsonarraycount=1
1815 fi
1816
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001817 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
1818 ((RES_TEST++))
1819 if [ $checkjsonarraycount -eq 0 ]; then
1820 result="$(__do_curl $2$3)"
1821 retcode=$?
1822 result=${result//[[:blank:]]/} #Strip blanks
1823 else
1824 path=${3:5}
1825 result="$(__do_curl $2$path)"
1826 retcode=$?
1827 echo "$result" > .tmp.curl.json
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001828 result=$(python3 ../common/count_json_elements.py ".tmp.curl.json")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001829 fi
1830 if [ $retcode -ne 0 ]; then
1831 ((RES_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001832 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001833 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001834 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
1835 ((RES_PASS++))
1836 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001837 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
1838 ((RES_PASS++))
1839 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001840 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
1841 ((RES_PASS++))
1842 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001843 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
1844 ((RES_PASS++))
1845 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001846 else
1847 ((RES_FAIL++))
1848 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001849 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001850 fi
1851 else
1852 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
1853 echo "Got:" $@
1854 exit 1
1855 fi
1856}
1857
1858
1859### Generic test cases for varaible checking
1860
1861# Tests if a variable value in the CR is equal to a target value and and optional timeout.
1862# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1863# equal to the target or not.
1864# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1865# before setting pass or fail depending on if the variable value becomes equal to the target
1866# value or not.
1867# (Function for test scripts)
1868cr_equal() {
1869 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
1870 __var_test "CR" "$LOCALHOST$CR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
1871 else
1872 ((RES_CONF_FAIL++))
1873 __print_err "Wrong args to cr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
1874 fi
1875}
1876
1877# Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
1878# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1879# equal to the target or not.
1880# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1881# before setting pass or fail depending on if the variable value becomes equal to the target
1882# value or not.
1883# (Function for test scripts)
1884mr_equal() {
1885 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
1886 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
1887 else
1888 ((RES_CONF_FAIL++))
1889 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
1890 fi
1891}
1892
1893# Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
1894# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1895# greater than the target or not.
1896# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1897# before setting pass or fail depending on if the variable value becomes greater than the target
1898# value or not.
1899# (Function for test scripts)
1900mr_greater() {
1901 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001902 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 ">" $2 $3
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001903 else
1904 ((RES_CONF_FAIL++))
1905 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
1906 fi
1907}
1908
1909# Read a variable value from MR sim and send to stdout. Arg: <variable-name>
1910mr_read() {
1911 echo "$(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"
1912}
1913
1914# Print a variable value from the MR stub.
1915# arg: <variable-name>
1916# (Function for test scripts)
1917mr_print() {
1918 if [ $# != 1 ]; then
1919 ((RES_CONF_FAIL++))
1920 __print_err "need one arg, <mr-param>" $@
1921 exit 1
1922 fi
1923 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"$EBOLD
1924}