blob: f2783f39501f1a0221f9494b424263f4cd64f3a6 [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
BjornMagnussonXA575869c2020-09-14 21:28:54 +020021# Arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--ricsim-prefix <prefix> ] [ --env-file <environment-filename> ] [--use-local-image <app-nam> [<app-name>]*]
YongchaoWuffde6eb2020-01-17 13:58:51 +010022
BjornMagnussonXA72667f12020-04-24 09:20:18 +020023
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020024# Create a test case id, ATC (Auto Test Case), from the name of the test case script.
25# FTC1.sh -> ATC == FTC1
26ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
27
28#Create result file (containing '1' for error) for this test case
29#Will be replaced with a file containing '0' if all test cases pass
30echo "1" > "$PWD/.result$ATC.txt"
31
BjornMagnussonXA80a92002020-03-19 14:31:06 +010032#Formatting for 'echo' cmd
33BOLD="\033[1m"
34EBOLD="\033[0m"
35RED="\033[31m\033[1m"
36ERED="\033[0m"
37GREEN="\033[32m\033[1m"
38EGREEN="\033[0m"
39YELLOW="\033[33m\033[1m"
40EYELLOW="\033[0m"
BjornMagnussonXA72667f12020-04-24 09:20:18 +020041SAMELINE="\033[0K\r"
42
43tmp=$(which python3)
44if [ $? -ne 0 ] || [ -z tmp ]; then
45 echo -e $RED"python3 is required to run the test environment, pls install"$ERED
46 exit 1
47fi
48tmp=$(which docker)
49if [ $? -ne 0 ] || [ -z tmp ]; then
50 echo -e $RED"docker is required to run the test environment, pls install"$ERED
51 exit 1
52fi
YongchaoWu9a84f512019-12-16 22:54:11 +010053
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020054tmp=$(which docker-compose)
55if [ $? -ne 0 ] || [ -z tmp ]; then
56 echo -e $RED"docker-compose is required to run the test environment, pls install"$ERED
57 exit 1
58fi
59
BjornMagnussonXA80a92002020-03-19 14:31:06 +010060# Just resetting any previous echo formatting...
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020061echo -ne $EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +010062
BjornMagnussonXA575869c2020-09-14 21:28:54 +020063# default test environment variables
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +020064TEST_ENV_VAR_FILE=""
BjornMagnussonXA80a92002020-03-19 14:31:06 +010065
66echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@
67
BjornMagnussonXA80a92002020-03-19 14:31:06 +010068#Localhost constant
69LOCALHOST="http://localhost:"
70
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020071# Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
72ECS_RETRY_CODES=""
73
74# Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
BjornMagnussonXA80a92002020-03-19 14:31:06 +010075AGENT_RETRY_CODES=""
76
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020077# Var to contol if the agent runs in a container (normal = 0) or as application on the local machine ( = 1)
78AGENT_STAND_ALONE=0
79
BjornMagnussonXA80a92002020-03-19 14:31:06 +010080# Var to hold 'auto' in case containers shall be stopped when test case ends
81AUTO_CLEAN=""
YongchaoWu9a84f512019-12-16 22:54:11 +010082
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020083# Var to hold the app names to use local image for when running 'remote' or 'remote-remove'
84USE_LOCAL_IMAGES=""
85
BjornMagnussonXAad047782020-06-08 15:54:11 +020086# List of available apps to override with local image
BjornMagnussonXAde4d0f82020-11-29 16:04:06 +010087AVAILABLE_LOCAL_IMAGES_OVERRIDE="PA ECS CP SDNC RICSIM RC"
BjornMagnussonXAad047782020-06-08 15:54:11 +020088
BjornMagnussonXA048aaa12020-06-04 07:48:37 +020089# 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
90STOP_AT_ERROR=0
91
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020092# Function to indent cmd output with one space
93indent1() { sed 's/^/ /'; }
94
95# Function to indent cmd output with two spaces
96indent2() { sed 's/^/ /'; }
97
YongchaoWu9a84f512019-12-16 22:54:11 +010098# Set a description string for the test case
99if [ -z "$TC_ONELINE_DESCR" ]; then
100 TC_ONELINE_DESCR="<no-description>"
101 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
102fi
103
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100104# Counter for test suites
105if [ -f .tmp_tcsuite_ctr ]; then
106 tmpval=$(< .tmp_tcsuite_ctr)
107 ((tmpval++))
108 echo $tmpval > .tmp_tcsuite_ctr
109fi
YongchaoWu9a84f512019-12-16 22:54:11 +0100110
YongchaoWu9a84f512019-12-16 22:54:11 +0100111# Create the logs dir if not already created in the current dir
112if [ ! -d "logs" ]; then
113 mkdir logs
114fi
YongchaoWu9a84f512019-12-16 22:54:11 +0100115TESTLOGS=$PWD/logs
116
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200117# Create the tmp dir for temporary files that is not needed after the test
118# hidden files for the test env is still stored in the current dir
119if [ ! -d "tmp" ]; then
120 mkdir tmp
121fi
122
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100123# Create a http message log for this testcase
124HTTPLOG=$PWD"/.httplog_"$ATC".txt"
125echo "" > $HTTPLOG
126
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200127
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100128# Create a log dir for the test case
YongchaoWu9a84f512019-12-16 22:54:11 +0100129mkdir -p $TESTLOGS/$ATC
130
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100131# Save create for current logs
132mkdir -p $TESTLOGS/$ATC/previous
133
134rm $TESTLOGS/$ATC/previous/*.log &> /dev/null
135rm $TESTLOGS/$ATC/previous/*.txt &> /dev/null
136rm $TESTLOGS/$ATC/previous/*.json &> /dev/null
137
138mv $TESTLOGS/$ATC/*.log $TESTLOGS/$ATC/previous &> /dev/null
139mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
140mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
141
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100142# Clear the log dir for the test case
143rm $TESTLOGS/$ATC/*.log &> /dev/null
144rm $TESTLOGS/$ATC/*.txt &> /dev/null
145rm $TESTLOGS/$ATC/*.json &> /dev/null
146
147# Log all output from the test case to a TC log
YongchaoWu9a84f512019-12-16 22:54:11 +0100148TCLOG=$TESTLOGS/$ATC/TC.log
149exec &> >(tee ${TCLOG})
150
151#Variables for counting tests as well as passed and failed tests
152RES_TEST=0
153RES_PASS=0
154RES_FAIL=0
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100155RES_CONF_FAIL=0
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200156RES_DEVIATION=0
157
158#File to keep deviation messages
159DEVIATION_FILE=".tmp_deviations"
160rm $DEVIATION_FILE &> /dev/null
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100161
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100162
163# Trap "command not found" and make the script fail
164trap_fnc() {
165
166 if [ $? -eq 127 ]; then
BjornMagnussonXAde4d0f82020-11-29 16:04:06 +0100167 echo -e $RED"Function not found, setting script to FAIL"$ERED
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100168 ((RES_CONF_FAIL++))
169 fi
170}
171trap trap_fnc ERR
172
173# Counter for tests
174TEST_SEQUENCE_NR=1
175
176__log_test_start() {
177 TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
178 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ $EBOLD
179 echo "TEST $TEST_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ >> $HTTPLOG
180 ((RES_TEST++))
181 ((TEST_SEQUENCE_NR++))
182}
183
184__log_test_fail_general() {
185 echo -e $RED" FAIL."$1 $ERED
186 ((RES_FAIL++))
187 __check_stop_at_error
188}
189
190__log_test_fail_status_code() {
191 echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED
192 ((RES_FAIL++))
193 __check_stop_at_error
194}
195
196__log_test_fail_body() {
197 echo -e $RED" FAIL, returned body not correct"$ERED
198 ((RES_FAIL++))
199 __check_stop_at_error
200}
201
202__log_test_fail_not_supported() {
203 echo -e $RED" FAIL, function not supported"$ERED
204 ((RES_FAIL++))
205 __check_stop_at_error
206}
207
208__log_test_pass() {
209 if [ $# -gt 0 ]; then
210 echo $@
211 fi
212 ((RES_PASS++))
213 echo -e $GREEN" PASS"$EGREEN
214}
215
216#Counter for configurations
217CONF_SEQUENCE_NR=1
218__log_conf_start() {
219 TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
220 echo -e $BOLD"CONF $CONF_SEQUENCE_NR (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ $EBOLD
221 echo "CONF $CONF_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ >> $HTTPLOG
222 ((CONF_SEQUENCE_NR++))
223}
224
225__log_conf_fail_general() {
226 echo -e $RED" FAIL."$1 $ERED
227 ((RES_CONF_FAIL++))
228 __check_stop_at_error
229}
230
231__log_conf_fail_status_code() {
232 echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED
233 ((RES_CONF_FAIL++))
234 __check_stop_at_error
235}
236
237__log_conf_fail_body() {
238 echo -e $RED" FAIL, returned body not correct"$ERED
239 ((RES_CONF_FAIL++))
240 __check_stop_at_error
241}
242
243__log_conf_ok() {
244 if [ $# -gt 0 ]; then
245 echo $@
246 fi
247 echo -e $GREEN" OK"$EGREEN
248}
249
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100250#Var for measuring execution time
YongchaoWu9a84f512019-12-16 22:54:11 +0100251TCTEST_START=$SECONDS
252
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200253#File to save timer measurement results
254TIMER_MEASUREMENTS=".timer_measurement.txt"
255echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS
256
257
YongchaoWu9a84f512019-12-16 22:54:11 +0100258echo "-------------------------------------------------------------------------------------------------"
259echo "----------------------------------- Test case: "$ATC
260echo "----------------------------------- Started: "$(date)
261echo "-------------------------------------------------------------------------------------------------"
262echo "-- Description: "$TC_ONELINE_DESCR
263echo "-------------------------------------------------------------------------------------------------"
264echo "----------------------------------- Test case setup -----------------------------------"
265
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200266START_ARG=$1
267paramerror=0
268if [ $# -lt 1 ]; then
269 paramerror=1
270fi
271if [ $paramerror -eq 0 ]; then
272 if [ "$1" != "remote" ] && [ "$1" != "remote-remove" ] && [ "$1" != "local" ]; then
273 paramerror=1
274 else
275 shift;
276 fi
277fi
BjornMagnussonXAad047782020-06-08 15:54:11 +0200278foundparm=0
279while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do
280 foundparm=1
281 if [ $paramerror -eq 0 ]; then
282 if [ "$1" == "auto-clean" ]; then
283 AUTO_CLEAN="auto"
284 echo "Option set - Auto clean at end of test script"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200285 shift;
BjornMagnussonXAad047782020-06-08 15:54:11 +0200286 foundparm=0
287 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200288 fi
BjornMagnussonXAad047782020-06-08 15:54:11 +0200289 if [ $paramerror -eq 0 ]; then
290 if [ "$1" == "--stop-at-error" ]; then
291 STOP_AT_ERROR=1
292 echo "Option set - Stop at first error"
293 shift;
294 foundparm=0
295 fi
296 fi
297 if [ $paramerror -eq 0 ]; then
298 if [ "$1" == "--ricsim-prefix" ]; then
299 shift;
300 RIC_SIM_PREFIX=$1
301 if [ -z "$1" ]; then
302 paramerror=1
303 else
304 echo "Option set - Overriding RIC_SIM_PREFIX with: "$1
305 shift;
306 foundparm=0
307 fi
308 fi
309 fi
310 if [ $paramerror -eq 0 ]; then
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200311 if [ "$1" == "--env-file" ]; then
312 shift;
313 TEST_ENV_VAR_FILE=$1
314 if [ -z "$1" ]; then
315 paramerror=1
316 else
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200317 echo "Option set - Reading test env from: "$1
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200318 shift;
319 foundparm=0
320 fi
321 fi
322 fi
323 if [ $paramerror -eq 0 ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +0200324 if [ "$1" == "--use-local-image" ]; then
325 USE_LOCAL_IMAGES=""
326 shift
327 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
328 USE_LOCAL_IMAGES=$USE_LOCAL_IMAGES" "$1
329 if [[ "$AVAILABLE_LOCAL_IMAGES_OVERRIDE" != *"$1"* ]]; then
330 paramerror=1
331 fi
332 shift;
333 done
334 foundparm=0
335 if [ -z "$USE_LOCAL_IMAGES" ]; then
336 paramerror=1
337 else
338 echo "Option set - Override remote images for app(s):"$USE_LOCAL_IMAGES
339 fi
340 fi
341 fi
342done
343echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200344
BjornMagnussonXAad047782020-06-08 15:54:11 +0200345#Still params left?
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200346if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
347 paramerror=1
348fi
349
350if [ $paramerror -eq 1 ]; then
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200351 echo -e $RED"Expected arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--ricsim-prefix <prefix> ] [ --env-file <environment-filename> ] [--use-local-image <app-nam> [<app-name>]*]"$ERED
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200352 exit 1
353fi
354
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200355# sourcing the selected env variables for the test case
356if [ -f "$TEST_ENV_VAR_FILE" ]; then
357 echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD
358 . $TEST_ENV_VAR_FILE
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100359
360 if [ -z "$TEST_ENV_PROFILE" ] || [ -z "$SUPPORTED_PROFILES" ]; then
361 echo -e $YELLOW"This test case may no work with selected test env file. TEST_ENV_PROFILE is missing in test_env file or SUPPORTED_PROFILES is missing in test case file"$EYELLOW
362 else
363 if [[ "$SUPPORTED_PROFILES" == *"$TEST_ENV_PROFILE"* ]]; then
364 echo -e $GREEN"Test case support the selected test env file"$EGREEN
365 else
366 echo -e $RED"Test case does not support the selected test env file"$ERED
367 echo -e $RED"Exiting...."$ERED
368 exit 1
369 fi
370 fi
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200371else
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200372 echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200373 echo " Select one of following env var file matching the intended target of the test"
374 echo " Restart the test using the flag '--env-file <path-to-env-file>"
375 ls ../common/test_env* | indent1
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200376 exit 1
377fi
378
379#Vars for A1 interface version and container count
380G1_A1_VERSION=""
381G2_A1_VERSION=""
382G3_A1_VERSION=""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100383G4_A1_VERSION=""
384G5_A1_VERSION=""
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200385G1_COUNT=0
386G2_COUNT=0
387G3_COUNT=0
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100388G4_COUNT=0
389G5_COUNT=0
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200390
391# Vars to switch between http and https. Extra curl flag needed for https
392export RIC_SIM_HTTPX="http"
393export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
394export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
395export RIC_SIM_CERT_MOUNT_DIR="./cert"
396
397export MR_HTTPX="http"
398export MR_PORT=$MR_INTERNAL_PORT
399export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker net
400
401export CR_HTTPX="http"
402export CR_PORT=$CR_INTERNAL_PORT
403export CR_LOCAL_PORT=$CR_EXTERNAL_PORT #When CR is running outside the docker net
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100404export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200405
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200406export PROD_STUB_HTTPX="http"
407export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
BjornMagnussonXAde4d0f82020-11-29 16:04:06 +0100408export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT #When Prodstub is running outside the docker net
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200409export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
410
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200411export SDNC_HTTPX="http"
412export SDNC_PORT=$SDNC_INTERNAL_PORT
413export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net
414
BjornMagnussonXAde4d0f82020-11-29 16:04:06 +0100415export RAPP_CAT_HTTPX="http"
416export RAPP_CAT_PORT=$RAPP_CAT_INTERNAL_PORT
417export RAPP_CAT_LOCAL_PORT=$RAPP_CAT_EXTERNAL_PORT #When Rapp catalogue is running outside the docker net
418
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100419echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
YongchaoWu9a84f512019-12-16 22:54:11 +0100420
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100421#Temp var to check for image variable name errors
422IMAGE_ERR=0
423#Create a file with image info for later printing as a table
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200424image_list_file="./tmp/.image-list"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100425echo -e " Container\tImage\ttag" > $image_list_file
426
427# Check if image env var is set and if so export the env var with image to use (used by docker compose files)
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200428# arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name> <app-short-name>
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100429__check_image_var() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200430 if [ $# -ne 6 ]; then
431 echo "Expected arg: <image name> <script start-arg> <target-variable-name> <image-variable-name> <image-tag-variable-name> <app-short-name>"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100432 ((IMAGE_ERR++))
433 return
434 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200435 __check_included_image $6
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200436 if [ $? -ne 0 ]; then
437 echo -e "$1\t<image-excluded>\t<no-tag>" >> $image_list_file
438 # Image is excluded since the corresponding app is not used in this test
439 return
440 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100441 tmp=${1}"\t"
442 #Create var from the input var names
443 image="${!4}"
444 tag="${!5}"
445
446 if [ -z $image ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200447 echo -e $RED"\$"$4" not set in $TEST_ENV_VAR_FILE"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100448 ((IMAGE_ERR++))
449 echo ""
450 tmp=$tmp"<no-image>\t"
451 else
452 tmp=$tmp$image"\t"
453 fi
454 if [ -z $tag ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200455 echo -e $RED"\$"$5" not set in $TEST_ENV_VAR_FILE"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100456 ((IMAGE_ERR++))
457 echo ""
458 tmp=$tmp"<no-tag>\t"
459 else
460 tmp=$tmp$tag
461 fi
462 echo -e "$tmp" >> $image_list_file
463 #Export the env var
464 export "${3}"=$image":"$tag
465
466 #echo " Configured image for ${1} (script start arg=${2}): "$image":"$tag
467}
468
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200469
470#Check if app local image shall override remote image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200471# Possible IDs for local image override: PA, CP, SDNC, RICSIM, ECS
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200472__check_image_local_override() {
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200473 for im in $USE_LOCAL_IMAGES; do
474 if [ "$1" == "$im" ]; then
475 return 1
476 fi
477 done
478 return 0
479}
480
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200481# Check if app uses image included in this test run
482# Returns 0 if image is included, 1 if not
483# Possible IDs for image inclusion: CBS, CONSUL, CP, CR, ECS, MR, PA, PRODSTUB, RICSIM, SDNC
484__check_included_image() {
485 for im in $INCLUDED_IMAGES; do
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200486 if [ "$1" == "$im" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200487 return 0
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200488 fi
489 done
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200490 return 1
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200491}
492
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100493# Check that image env setting are available
494echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200495
496if [ $START_ARG == "local" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100497
498 #Local agent image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200499 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG" PA
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100500
501 #Local Control Panel image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200502 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG" CP
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100503
504 #Local SNDC image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200505 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG" SDNC
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100506
507 #Local ric sim image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200508 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG" RICSIM
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100509
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200510elif [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100511
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200512 __check_image_local_override 'PA'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200513 if [ $? -eq 0 ]; then
514 #Remote agent image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200515 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_REMOTE_IMAGE" "POLICY_AGENT_REMOTE_IMAGE_TAG" PA
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200516 else
517 #Local agent image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200518 __check_image_var " Policy Agent" $START_ARG "POLICY_AGENT_IMAGE" "POLICY_AGENT_LOCAL_IMAGE" "POLICY_AGENT_LOCAL_IMAGE_TAG" PA
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200519 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100520
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200521 __check_image_local_override 'CP'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200522 if [ $? -eq 0 ]; then
523 #Remote Control Panel image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200524 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE" "CONTROL_PANEL_REMOTE_IMAGE_TAG" CP
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200525 else
526 #Local Control Panel image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200527 __check_image_var " Control Panel" $START_ARG "CONTROL_PANEL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE" "CONTROL_PANEL_LOCAL_IMAGE_TAG" CP
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200528 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100529
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200530 __check_image_local_override 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200531 if [ $? -eq 0 ]; then
532 #Remote SDNC image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200533 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE" "SDNC_A1_CONTROLLER_REMOTE_IMAGE_TAG" SDNC
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200534 else
535 #Local SNDC image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200536 __check_image_var " SDNC A1 Controller" $START_ARG "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE" "SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG" SDNC
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200537 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100538
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200539 __check_image_local_override 'RICSIM'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200540 if [ $? -eq 0 ]; then
541 #Remote ric sim image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200542 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_REMOTE_IMAGE" "RIC_SIM_REMOTE_IMAGE_TAG" RICSIM
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200543 else
544 #Local ric sim image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200545 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG" RICSIM
546 fi
547
548 __check_image_local_override 'ECS'
549 if [ $? -eq 0 ]; then
550 #Remote ecs image
551 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_REMOTE_IMAGE" "ECS_REMOTE_IMAGE_TAG" ECS
552 else
553 #Local ecs image
554 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_LOCAL_IMAGE" "ECS_LOCAL_IMAGE_TAG" ECS
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200555 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100556
BjornMagnussonXAde4d0f82020-11-29 16:04:06 +0100557 __check_image_local_override 'RC'
558 if [ $? -eq 0 ]; then
559 #Remote ecs image
560 __check_image_var " RC" $START_ARG "RAPP_CAT_IMAGE" "RAPP_CAT_REMOTE_IMAGE" "RAPP_CAT_REMOTE_IMAGE_TAG" RC
561 else
562 #Local ecs image
563 __check_image_var " RC" $START_ARG "RAPP_CAT_IMAGE" "RAPP_CAT_LOCAL_IMAGE" "RAPP_CAT_LOCAL_IMAGE_TAG" RC
564 fi
565
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100566else
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200567 #Should never get here....
568 echo "Unknow args: "$@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100569 exit 1
YongchaoWu9a84f512019-12-16 22:54:11 +0100570fi
571
YongchaoWu9a84f512019-12-16 22:54:11 +0100572
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100573# These images are not built as part of this project official images, just check that env vars are set correctly
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200574__check_image_var " Message Router" $START_ARG "MRSTUB_IMAGE" "MRSTUB_LOCAL_IMAGE" "MRSTUB_LOCAL_IMAGE_TAG" MR
575__check_image_var " Callback Receiver" $START_ARG "CR_IMAGE" "CR_LOCAL_IMAGE" "CR_LOCAL_IMAGE_TAG" CR
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200576__check_image_var " Producer stub" $START_ARG "PROD_STUB_IMAGE" "PROD_STUB_LOCAL_IMAGE" "PROD_STUB_LOCAL_IMAGE_TAG" PRODSTUB
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200577__check_image_var " Consul" $START_ARG "CONSUL_IMAGE" "CONSUL_REMOTE_IMAGE" "CONSUL_REMOTE_IMAGE_TAG" CONSUL
578__check_image_var " CBS" $START_ARG "CBS_IMAGE" "CBS_REMOTE_IMAGE" "CBS_REMOTE_IMAGE_TAG" CBS
579__check_image_var " SDNC DB" $START_ARG "SDNC_DB_IMAGE" "SDNC_DB_REMOTE_IMAGE" "SDNC_DB_REMOTE_IMAGE_TAG" SDNC #Uses sdnc app name
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100580
581#Errors in image setting - exit
582if [ $IMAGE_ERR -ne 0 ]; then
583 exit 1
584fi
585
586#Print a tables of the image settings
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200587echo -e $BOLD"Images configured for start arg: "$START $EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100588column -t -s $'\t' $image_list_file
589
YongchaoWuf309b1b2020-01-22 13:24:48 +0100590echo ""
591
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100592
593#Set the SIM_GROUP var
594echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
595if [ -z "$SIM_GROUP" ]; then
596 SIM_GROUP=$PWD/../simulator-group
597 if [ ! -d $SIM_GROUP ]; then
598 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200599 echo -e $RED"Please set the SIM_GROUP manually in the applicable $TEST_ENV_VAR_FILE"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100600 exit 1
601 else
602 echo " SIM_GROUP auto set to: " $SIM_GROUP
603 fi
604elif [ $SIM_GROUP = *simulator_group ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200605 echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check $TEST_ENV_VAR_FILE"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100606 exit 1
607else
608 echo " SIM_GROUP env var already set to: " $SIM_GROUP
maximesson28ee8a52020-03-17 09:32:03 +0100609fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100610
611echo ""
612
613#Temp var to check for image pull errors
614IMAGE_ERR=0
615
616#Function to check if image exist and stop+remove the container+pull new images as needed
617#args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
618__check_and_pull_image() {
619
620 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
621 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
622 tmp_im=$(docker images --format $format_string ${4})
623
624 if [ $1 == "local" ]; then
625 if [ -z "$tmp_im" ]; then
626 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
627 ((IMAGE_ERR++))
628 return 1
629 else
630 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
631 fi
632 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
633 if [ $1 == "remote-remove" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200634 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100635 tmp="$(docker ps -aq --filter name=${3})"
636 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200637 docker stop $tmp &> ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100638 if [ $? -ne 0 ]; then
639 ((IMAGE_ERR++))
640 echo ""
641 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200642 cat ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100643 return 1
644 fi
645 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200646 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100647 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
648 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200649 docker rm $tmp &> ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100650 if [ $? -ne 0 ]; then
651 ((IMAGE_ERR++))
652 echo ""
653 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200654 cat ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100655 return 1
656 fi
657 fi
658 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200659 echo -ne " Removing image - ${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100660 tmp="$(docker images -q ${4})" &> /dev/null
661 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200662 docker rmi --force $4 &> ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100663 if [ $? -ne 0 ]; then
664 ((IMAGE_ERR++))
665 echo ""
666 echo -e $RED" Image could not be removed - try manual removal of the image"$ERED
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200667 cat ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100668 return 1
669 fi
670 echo -e " Removing image - "$GREEN"removed"$EGREEN
671 else
672 echo -e " Removing image - "$GREEN"image not in repository"$EGREEN
673 fi
674 tmp_im=""
675 fi
676 if [ -z "$tmp_im" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200677 echo -ne " Pulling image${SAMELINE}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200678 docker pull $4 &> ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100679 tmp_im=$(docker images ${4} | grep -v REPOSITORY)
680 if [ -z "$tmp_im" ]; then
681 echo ""
682 echo -e " Pulling image -$RED could not be pulled"$ERED
683 ((IMAGE_ERR++))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200684 cat ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100685 return 1
686 fi
687 echo -e " Pulling image -$GREEN Pulled $EGREEN"
688 else
689 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
690 fi
691 fi
692 return 0
693}
694
695
696echo -e $BOLD"Pulling configured images, if needed"$EBOLD
697
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200698__check_included_image 'PA'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200699if [ $? -eq 0 ]; then
700 START_ARG_MOD=$START_ARG
701 __check_image_local_override 'PA'
702 if [ $? -eq 1 ]; then
703 START_ARG_MOD="local"
704 fi
705 app="Policy Agent"; __check_and_pull_image $START_ARG_MOD "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
706else
707 echo -e $YELLOW" Excluding PA image from image check/pull"$EYELLOW
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200708fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100709
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200710__check_included_image 'ECS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200711if [ $? -eq 0 ]; then
712 START_ARG_MOD=$START_ARG
713 __check_image_local_override 'ECS'
714 if [ $? -eq 1 ]; then
715 START_ARG_MOD="local"
716 fi
717 app="ECS"; __check_and_pull_image $START_ARG_MOD "$app" $ECS_APP_NAME $ECS_IMAGE
718else
719 echo -e $YELLOW" Excluding ECS image from image check/pull"$EYELLOW
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200720fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200721
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200722__check_included_image 'CP'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200723if [ $? -eq 0 ]; then
724 START_ARG_MOD=$START_ARG
725 __check_image_local_override 'CP'
726 if [ $? -eq 1 ]; then
727 START_ARG_MOD="local"
728 fi
729 app="Non-RT RIC Control Panel"; __check_and_pull_image $START_ARG_MOD "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
730else
731 echo -e $YELLOW" Excluding Non-RT RIC Control Panel image from image check/pull"$EYELLOW
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200732fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100733
BjornMagnussonXAde4d0f82020-11-29 16:04:06 +0100734__check_included_image 'RC'
735if [ $? -eq 0 ]; then
736 START_ARG_MOD=$START_ARG
737 __check_image_local_override 'RC'
738 if [ $? -eq 1 ]; then
739 START_ARG_MOD="local"
740 fi
741 app="RAPP Catalogue"; __check_and_pull_image $START_ARG_MOD "$app" $RAPP_CAT_APP_NAME $RAPP_CAT_IMAGE
742else
743 echo -e $YELLOW" Excluding RAPP Catalogue image from image check/pull"$EYELLOW
744fi
745
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200746__check_included_image 'RICSIM'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200747if [ $? -eq 0 ]; then
748 START_ARG_MOD=$START_ARG
749 __check_image_local_override 'RICSIM'
750 if [ $? -eq 1 ]; then
751 START_ARG_MOD="local"
752 fi
753 app="Near-RT RIC Simulator"; __check_and_pull_image $START_ARG_MOD "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
754else
755 echo -e $YELLOW" Excluding Near-RT RIC Simulator image from image check/pull"$EYELLOW
756fi
757
758
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200759__check_included_image 'CONSUL'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200760if [ $? -eq 0 ]; then
761 app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
762else
763 echo -e $YELLOW" Excluding Consul image from image check/pull"$EYELLOW
764fi
765
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200766__check_included_image 'CBS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200767if [ $? -eq 0 ]; then
768 app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE
769else
770 echo -e $YELLOW" Excluding CBS image from image check/pull"$EYELLOW
771fi
772
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200773__check_included_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200774if [ $? -eq 0 ]; then
775 START_ARG_MOD=$START_ARG
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200776 __check_image_local_override 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200777 if [ $? -eq 1 ]; then
778 START_ARG_MOD="local"
779 fi
780 app="SDNC A1 Controller"; __check_and_pull_image $START_ARG_MOD "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
781 app="SDNC DB"; __check_and_pull_image $START_ARG "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
782else
783 echo -e $YELLOW" Excluding SDNC image and related DB image from image check/pull"$EYELLOW
784fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100785
786#Errors in image setting - exit
787if [ $IMAGE_ERR -ne 0 ]; then
788 echo ""
789 echo "#################################################################################################"
790 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 +0200791 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100792 echo "#################################################################################################"
793 echo ""
794 exit 1
795fi
796
797echo ""
798
799echo -e $BOLD"Building images needed for test"$EBOLD
800
801curdir=$PWD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200802__check_included_image 'MR'
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100803if [ $? -eq 0 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200804 cd $curdir
805 cd ../mrstub
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200806 echo " Building mrstub image: $MRSTUB_LOCAL_IMAGE:$MRSTUB_LOCAL_IMAGE_TAG"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100807 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $MRSTUB_LOCAL_IMAGE . &> .dockererr
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200808 if [ $? -eq 0 ]; then
809 echo -e $GREEN" Build Ok"$EGREEN
810 else
811 echo -e $RED" Build Failed"$ERED
812 ((RES_CONF_FAIL++))
813 cat .dockererr
BjornMagnussonXA2791e082020-11-12 00:52:08 +0100814 echo -e $RED"Exiting...."$ERED
815 exit 1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200816 fi
817 cd $curdir
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100818else
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200819 echo -e $YELLOW" Excluding mrstub from image build"$EYELLOW
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100820fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100821
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200822__check_included_image 'CR'
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100823if [ $? -eq 0 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200824 cd ../cr
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200825 echo " Building Callback Receiver image: $CR_LOCAL_IMAGE:$CR_IMAGE_TAG"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100826 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $CR_LOCAL_IMAGE . &> .dockererr
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200827 if [ $? -eq 0 ]; then
828 echo -e $GREEN" Build Ok"$EGREEN
829 else
830 echo -e $RED" Build Failed"$ERED
831 ((RES_CONF_FAIL++))
832 cat .dockererr
BjornMagnussonXA2791e082020-11-12 00:52:08 +0100833 echo -e $RED"Exiting...."$ERED
834 exit 1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200835 fi
836 cd $curdir
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100837else
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200838 echo -e $YELLOW" Excluding Callback Receiver from image build"$EYELLOW
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100839fi
YongchaoWuf309b1b2020-01-22 13:24:48 +0100840
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200841__check_included_image 'PRODSTUB'
842if [ $? -eq 0 ]; then
843 cd ../prodstub
844 echo " Building Producer stub image: $PROD_STUB_LOCAL_IMAGE:$PROD_STUB_LOCAL_IMAGE_TAG"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100845 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $PROD_STUB_LOCAL_IMAGE . &> .dockererr
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200846 if [ $? -eq 0 ]; then
847 echo -e $GREEN" Build Ok"$EGREEN
848 else
849 echo -e $RED" Build Failed"$ERED
850 ((RES_CONF_FAIL++))
851 cat .dockererr
BjornMagnussonXA2791e082020-11-12 00:52:08 +0100852 echo -e $RED"Exiting...."$ERED
853 exit 1
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200854 fi
855 cd $curdir
856else
857 echo -e $YELLOW" Excluding Producer stub from image build"$EYELLOW
858fi
859
YongchaoWuf309b1b2020-01-22 13:24:48 +0100860echo ""
861
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100862# Create a table of the images used in the script
863echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
864
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200865docker_tmp_file=./tmp/.docker-images-table
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200866format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\\t{{.CreatedAt}}"
867echo -e " Application\tRepository\tTag\tCreated since\tSize\tCreated at" > $docker_tmp_file
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200868__check_included_image 'PA'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200869if [ $? -eq 0 ]; then
870 echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
871fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200872__check_included_image 'ECS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200873if [ $? -eq 0 ]; then
874 echo -e " ECS\t$(docker images --format $format_string $ECS_IMAGE)" >> $docker_tmp_file
875fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200876__check_included_image 'CP'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200877if [ $? -eq 0 ]; then
878 echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
879fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200880__check_included_image 'RICSIM'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200881if [ $? -eq 0 ]; then
882 echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
883fi
BjornMagnussonXAde4d0f82020-11-29 16:04:06 +0100884__check_included_image 'RC'
885if [ $? -eq 0 ]; then
886 echo -e " RAPP Catalogue\t$(docker images --format $format_string $RAPP_CAT_IMAGE)" >> $docker_tmp_file
887fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200888__check_included_image 'MR'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200889if [ $? -eq 0 ]; then
890 echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
891fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200892__check_included_image 'CR'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200893if [ $? -eq 0 ]; then
894 echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
895fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200896__check_included_image 'PRODSTUB'
897if [ $? -eq 0 ]; then
898 echo -e " Produccer stub\t$(docker images --format $format_string $PROD_STUB_IMAGE)" >> $docker_tmp_file
899fi
900__check_included_image 'CONSUL'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200901if [ $? -eq 0 ]; then
902 echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
903fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200904__check_included_image 'CBS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200905if [ $? -eq 0 ]; then
906 echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
907fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200908__check_included_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200909if [ $? -eq 0 ]; then
910 echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
911 echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
912fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100913
914column -t -s $'\t' $docker_tmp_file
915
YongchaoWuf309b1b2020-01-22 13:24:48 +0100916echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +0100917
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100918echo -e $BOLD"======================================================="$EBOLD
919echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
920echo -e $BOLD"======================================================="$EBOLD
921echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +0100922
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100923# Function to print the test result, shall be the last cmd in a test script
924# args: -
925# (Function for test scripts)
926print_result() {
YongchaoWu9a84f512019-12-16 22:54:11 +0100927
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100928 TCTEST_END=$SECONDS
929 duration=$((TCTEST_END-TCTEST_START))
YongchaoWu9a84f512019-12-16 22:54:11 +0100930
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100931 echo "-------------------------------------------------------------------------------------------------"
932 echo "------------------------------------- Test case: "$ATC
933 echo "------------------------------------- Ended: "$(date)
934 echo "-------------------------------------------------------------------------------------------------"
935 echo "-- Description: "$TC_ONELINE_DESCR
936 echo "-- Execution time: " $duration " seconds"
BjornMagnussonXA2791e082020-11-12 00:52:08 +0100937 echo "-- Used env file: "$TEST_ENV_VAR_FILE
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100938 echo "-------------------------------------------------------------------------------------------------"
939 echo "------------------------------------- RESULTS"
YongchaoWu4e489b02020-02-24 09:18:16 +0100940 echo ""
YongchaoWu4e489b02020-02-24 09:18:16 +0100941
YongchaoWu21f17bb2020-03-05 12:44:08 +0100942
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200943 if [ $RES_DEVIATION -gt 0 ]; then
944 echo "Test case deviations"
945 echo "===================================="
946 cat $DEVIATION_FILE
947 fi
948 echo ""
949 echo "Timer measurement in the test script"
950 echo "===================================="
951 column -t -s $'\t' $TIMER_MEASUREMENTS
952 echo ""
953
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100954 total=$((RES_PASS+RES_FAIL))
955 if [ $RES_TEST -eq 0 ]; then
956 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
957 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
958 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
959 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
960 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
961 elif [ $total != $RES_TEST ]; then
962 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
963 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
964 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
965 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
966 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
967 elif [ $RES_CONF_FAIL -ne 0 ]; then
968 echo -e "\033[1mOne or more configure regest has failed. Check the script log....\033[0m"
969 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
970 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
971 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
972 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
973 elif [ $RES_PASS = $RES_TEST ]; then
974 echo -e "All tests \033[32m\033[1mPASS\033[0m"
975 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
976 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
977 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
978 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
979 echo ""
YongchaoWu21f17bb2020-03-05 12:44:08 +0100980
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100981 # Update test suite counter
982 if [ -f .tmp_tcsuite_pass_ctr ]; then
983 tmpval=$(< .tmp_tcsuite_pass_ctr)
984 ((tmpval++))
985 echo $tmpval > .tmp_tcsuite_pass_ctr
986 fi
987 if [ -f .tmp_tcsuite_pass ]; then
988 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
989 fi
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200990 #Create file with OK exit code
991 echo "0" > "$PWD/.result$ATC.txt"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100992 else
993 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
994 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
995 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
996 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
997 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
998 echo ""
999 # Update test suite counter
1000 if [ -f .tmp_tcsuite_fail_ctr ]; then
1001 tmpval=$(< .tmp_tcsuite_fail_ctr)
1002 ((tmpval++))
1003 echo $tmpval > .tmp_tcsuite_fail_ctr
1004 fi
1005 if [ -f .tmp_tcsuite_fail ]; then
1006 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
1007 fi
YongchaoWu21f17bb2020-03-05 12:44:08 +01001008 fi
YongchaoWu21f17bb2020-03-05 12:44:08 +01001009
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001010 echo "++++ Number of tests: "$RES_TEST
1011 echo "++++ Number of passed tests: "$RES_PASS
1012 echo "++++ Number of failed tests: "$RES_FAIL
YongchaoWu4e489b02020-02-24 09:18:16 +01001013 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001014 echo "++++ Number of failed configs: "$RES_CONF_FAIL
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001015 echo ""
1016 echo "++++ Number of test case deviations: "$RES_DEVIATION
1017 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001018 echo "------------------------------------- Test case complete ---------------------------------"
1019 echo "-------------------------------------------------------------------------------------------------"
YongchaoWu9a84f512019-12-16 22:54:11 +01001020 echo ""
1021}
1022
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001023#####################################################################
1024###### Functions for start, configuring, stoping, cleaning etc ######
1025#####################################################################
YongchaoWu21f17bb2020-03-05 12:44:08 +01001026
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001027# Start timer for time measurement
1028# args - (any args will be printed though)
1029start_timer() {
1030 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1031 TC_TIMER=$SECONDS
1032 echo " Timer started"
1033}
1034
1035# Print the value of the time (in seconds)
1036# args - <timer message to print> - timer value and message will be printed both on screen
1037# and in the timer measurement report
1038print_timer() {
1039 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1040 if [ $# -lt 1 ]; then
1041 ((RES_CONF_FAIL++))
1042 __print_err "need 1 or more args, <timer message to print>" $@
1043 exit 1
1044 fi
1045 duration=$(($SECONDS-$TC_TIMER))
1046 if [ $duration -eq 0 ]; then
1047 duration="<1 second"
1048 else
1049 duration=$duration" seconds"
1050 fi
1051 echo " Timer duration :" $duration
1052
1053 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
1054}
1055
1056# Print the value of the time (in seconds) and reset the timer
1057# args - <timer message to print> - timer value and message will be printed both on screen
1058# and in the timer measurement report
1059print_and_reset_timer() {
1060 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1061 if [ $# -lt 1 ]; then
1062 ((RES_CONF_FAIL++))
1063 __print_err "need 1 or more args, <timer message to print>" $@
1064 exit 1
1065 fi
1066 duration=$(($SECONDS-$TC_TIMER))" seconds"
1067 if [ $duration -eq 0 ]; then
1068 duration="<1 second"
1069 else
1070 duration=$duration" seconds"
1071 fi
1072 echo " Timer duration :" $duration
1073 TC_TIMER=$SECONDS
1074 echo " Timer reset"
1075
1076 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
1077
1078}
1079# Print info about a deviations from intended tests
1080# Each deviation counted is also printed in the testreport
1081# args <deviation message to print>
1082deviation() {
1083 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
1084 if [ $# -lt 1 ]; then
1085 ((RES_CONF_FAIL++))
1086 __print_err "need 1 or more args, <deviation message to print>" $@
1087 exit 1
1088 fi
1089 ((RES_DEVIATION++))
1090 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
1091 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
1092 echo ""
1093}
YongchaoWu21f17bb2020-03-05 12:44:08 +01001094
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001095# Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
1096__check_stop_at_error() {
1097 if [ $STOP_AT_ERROR -eq 1 ]; then
1098 echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
1099 store_logs "STOP_AT_ERROR"
1100 exit 1
1101 fi
1102 return 0
1103}
1104
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001105# Check if app name var is set. If so return the app name otherwise return "NOTSET"
1106__check_app_name() {
1107 if [ $# -eq 1 ]; then
1108 echo $1
1109 else
1110 echo "NOTSET"
1111 fi
1112}
1113
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001114# Stop and remove all containers
1115# args: -
1116# (Function for test scripts)
YongchaoWu9a84f512019-12-16 22:54:11 +01001117clean_containers() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001118
1119 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
1120
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001121 CONTAINTER_NAMES=("Policy Agent " $(__check_app_name $POLICY_AGENT_APP_NAME)\
1122 "ECS " $(__check_app_name $ECS_APP_NAME)\
BjornMagnussonXAde4d0f82020-11-29 16:04:06 +01001123 "RAPP Catalogue " $(__check_app_name $RAPP_CAT_APP_NAME)\
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001124 "Non-RT RIC Simulator(s)" $(__check_app_name $RIC_SIM_PREFIX)\
1125 "Message Router " $(__check_app_name $MR_APP_NAME)\
1126 "Callback Receiver " $(__check_app_name $CR_APP_NAME)\
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001127 "Producer stub " $(__check_app_name $PROD_STUB_APP_NAME)\
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001128 "Control Panel " $(__check_app_name $CONTROL_PANEL_APP_NAME)\
1129 "SDNC A1 Controller " $(__check_app_name $SDNC_APP_NAME)\
1130 "SDNC DB " $(__check_app_name $SDNC_DB_APP_NAME)\
1131 "CBS " $(__check_app_name $CBS_APP_NAME)\
1132 "Consul " $(__check_app_name $CONSUL_APP_NAME))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001133
1134 nw=0 # Calc max width of container name, to make a nice table
1135 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001136
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001137 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
1138 nw=${#CONTAINTER_NAMES[i]}
1139 fi
1140 done
1141
1142 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
1143 APP="${CONTAINTER_NAMES[i]}"
1144 CONTR="${CONTAINTER_NAMES[i+1]}"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001145 if [ $CONTR != "NOTSET" ]; then
1146 for((w=${#CONTR}; w<$nw; w=w+1)); do
1147 CONTR="$CONTR "
1148 done
1149 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
1150 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1151 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
1152 docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1153 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
1154 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001155 done
1156
YongchaoWu9a84f512019-12-16 22:54:11 +01001157 echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001158
1159 echo -e $BOLD" Removing docker network"$EBOLD
1160 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
1161 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001162 docker network rm $DOCKER_SIM_NWNAME | indent2
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001163 if [ $? -ne 0 ]; then
1164 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
1165 exit 1
1166 fi
1167 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001168 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001169
1170 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001171 docker network prune --force | indent2
1172 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001173
1174 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001175 docker volume prune --force | indent2
1176 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001177
1178 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
1179 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001180 echo -e "$GREEN Done$EGREEN"
1181 echo ""
BjornMagnussonXAad047782020-06-08 15:54:11 +02001182
1183 CONTRS=$(docker ps | awk '$1 != "CONTAINER" { n++ }; END { print n+0 }')
1184 if [ $? -eq 0 ]; then
1185 if [ $CONTRS -ne 0 ]; then
1186 echo -e $RED"Containers running, may cause distubance to the test case"$ERED
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001187 docker ps -a | indent1
1188 echo ""
BjornMagnussonXAad047782020-06-08 15:54:11 +02001189 fi
1190 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001191}
1192
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001193# Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
1194# args: -
1195# (Function for test scripts)
1196auto_clean_containers() {
1197 echo
1198 if [ "$AUTO_CLEAN" == "auto" ]; then
1199 echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
1200 clean_containers
YongchaoWu9a84f512019-12-16 22:54:11 +01001201 fi
1202}
1203
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001204# Function to sleep a test case for a numner of seconds. Prints the optional text args as info
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001205# args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001206# (Function for test scripts)
1207sleep_wait() {
YongchaoWu9a84f512019-12-16 22:54:11 +01001208
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001209 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1210 if [ $# -lt 1 ]; then
1211 ((RES_CONF_FAIL++))
1212 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
1213 exit 1
1214 fi
1215 #echo "---- Sleep for " $1 " seconds ---- "$2
1216 start=$SECONDS
1217 duration=$((SECONDS-start))
1218 while [ $duration -lt $1 ]; do
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001219 echo -ne " Slept for ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001220 sleep 1
1221 duration=$((SECONDS-start))
1222 done
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001223 echo -ne " Slept for ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001224 echo ""
1225}
1226
1227# Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
1228# Not to be called from the test script itself.
1229__print_err() {
1230 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
1231 if [ $# -gt 1 ]; then
1232 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
1233 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001234 ((RES_CONF_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001235}
1236
1237
1238# Helper function to get a the port of a specific ric simulatpor
1239# args: <ric-id>
1240# (Not for test scripts)
1241__find_sim_port() {
1242 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
ecaiyanlinux99a769b2020-05-15 13:58:02 +02001243 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
1244 res=$(eval $cmdstr)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001245 if [[ "$res" =~ ^[0-9]+$ ]]; then
1246 echo $res
1247 else
1248 echo "0"
1249 fi
1250}
1251
1252# Function to create the docker network for the test
1253# Not to be called from the test script itself.
1254__create_docker_network() {
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001255 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001256 if [ $? -ne 0 ]; then
1257 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
1258 return 1
1259 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001260 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001261 echo -e " Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
1262 docker network create $DOCKER_SIM_NWNAME | indent2
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001263 if [ $? -ne 0 ]; then
1264 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
1265 return 1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001266 else
1267 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001268 fi
1269 else
1270 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
1271 fi
1272}
1273
1274# Check if container is started by calling url on localhost using a port, expects response code 2XX
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001275# args: <container-name> <port> <url> https|https
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001276# Not to be called from the test script itself.
1277__check_container_start() {
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001278 paramError=0
1279 if [ $# -ne 4 ]; then
1280 paramError=1
1281 elif [ $4 != "http" ] && [ $4 != "https" ]; then
1282 paramError=1
1283 fi
1284 if [ $paramError -ne 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001285 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001286 __print_err "need 3 args, <container-name> <port> <url> https|https" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001287 return 1
1288 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001289 echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
YongchaoWu9a84f512019-12-16 22:54:11 +01001290 appname=$1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001291 localport=$2
1292 url=$3
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001293 if [[ $appname != "STANDALONE_"* ]] ; then
1294 app_started=0
1295 for i in {1..10}; do
1296 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
1297 echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
1298 app_started=1
1299 break
1300 else
1301 sleep $i
1302 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001303 done
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001304 if [ $app_started -eq 0 ]; then
1305 ((RES_CONF_FAIL++))
1306 echo ""
1307 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001308 echo -e $RED" Stopping script..."$ERED
1309 exit 1
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001310 fi
1311 if [ $localport -eq 0 ]; then
1312 while [ $localport -eq 0 ]; do
1313 echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
1314 localport=$(__find_sim_port $appname)
1315 sleep 1
1316 echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
1317 done
1318 echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
1319 echo ""
1320 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001321 fi
1322
1323 pa_st=false
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001324 echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001325 TSTART=$SECONDS
1326 for i in {1..50}; do
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001327 if [ $4 == "https" ]; then
1328 result="$(__do_curl "-k https://localhost:"${localport}${url})"
1329 else
1330 result="$(__do_curl $LOCALHOST${localport}${url})"
1331 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001332 if [ $? -eq 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001333 if [ ${#result} -gt 15 ]; then
1334 #If response is too long, truncate
1335 result="...response text too long, omitted"
1336 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001337 echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001338 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 +01001339 pa_st=true
1340 break
1341 else
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001342 TS_TMP=$SECONDS
1343 while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001344 echo -ne " Waiting for container ${appname} service status...$(($SECONDS-$TSTART)) seconds, retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001345 sleep 1
1346 done
YongchaoWu9a84f512019-12-16 22:54:11 +01001347 fi
1348 done
1349
1350 if [ "$pa_st" = "false" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001351 ((RES_CONF_FAIL++))
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001352 echo -e $RED" Container ${appname} did not respond to service status in $(($SECONDS-$TSTART)) seconds"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001353 return 0
1354 fi
1355
1356 echo ""
1357 return 0
1358}
1359
1360
1361# Function to start a container and wait until it responds on the given port and url.
1362#args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
1363__start_container() {
1364
1365 variableArgCount=$(($#-2))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001366 if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001367 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001368 __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 +01001369 exit 1
1370 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001371
1372 __create_docker_network
1373
1374 curdir=$PWD
1375 cd $SIM_GROUP
1376 cd $1
1377
1378 if [ "$2" == "NODOCKERARGS" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001379 docker-compose up -d &> .dockererr
1380 if [ $? -ne 0 ]; then
1381 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1382 cat .dockererr
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001383 echo -e $RED"Stopping script...."$ERED
1384 exit 1
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001385 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001386 elif [ "$2" == "STANDALONE" ]; then
1387 echo "Skipping docker-compose"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001388 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001389 docker-compose up -d $2 &> .dockererr
1390 if [ $? -ne 0 ]; then
1391 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1392 cat .dockererr
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001393 echo -e $RED"Stopping script...."$ERED
1394 exit 1
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001395 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001396 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001397 app_prefix=""
1398 if [ "$2" == "STANDALONE" ]; then
1399 app_prefix="STANDALONE_"
1400 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001401 shift; shift;
1402 cntr=0
1403 while [ $cntr -lt $variableArgCount ]; do
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001404 app=$app_prefix$1; shift;
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001405 port=$1; shift;
1406 url=$1; shift;
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001407 httpx=$1; shift;
1408 let cntr=cntr+4
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001409
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001410 __check_container_start "$app" "$port" "$url" $httpx
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001411 done
1412
1413 cd $curdir
1414 echo ""
1415 return 0
YongchaoWu9a84f512019-12-16 22:54:11 +01001416}
1417
BjornMagnussonXAad047782020-06-08 15:54:11 +02001418# Generate a UUID to use as prefix for policy ids
1419generate_uuid() {
1420 UUID=$(python3 -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
1421 #Reduce length to make space for serial id, us 'a' as marker where the serial id is added
1422 UUID=${UUID:0:${#UUID}-4}"a"
1423}
1424
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001425####################
1426### Consul functions
1427####################
1428
1429# Function to load config from a file into consul for the Policy Agent
1430# arg: <json-config-file>
1431# (Function for test scripts)
1432consul_config_app() {
1433
1434 echo -e $BOLD"Configuring Consul"$EBOLD
1435
1436 if [ $# -ne 1 ]; then
1437 ((RES_CONF_FAIL++))
1438 __print_err "need one arg, <json-config-file>" $@
1439 exit 1
1440 fi
1441
1442 echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1
1443
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001444 curlString="$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
1445 result=$(__do_curl "$curlString")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001446 if [ $? -ne 0 ]; then
1447 echo -e $RED" FAIL - json config could not be loaded to consul" $ERED
1448 ((RES_CONF_FAIL++))
1449 return 1
1450 fi
1451 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001452 echo $body > "./tmp/.output"$1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001453
1454 if [ $? -ne 0 ]; then
1455 echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED
1456 ((RES_CONF_FAIL++))
1457 return 1
1458 else
1459 targetJson=$(< $1)
1460 targetJson="{\"config\":"$targetJson"}"
1461 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001462 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001463 if [ $res -ne 0 ]; then
1464 echo -e $RED" FAIL - policy json config read from consul/cbs is not equal to the intended json config...." $ERED
1465 ((RES_CONF_FAIL++))
1466 return 1
1467 else
1468 echo -e $GREEN" Config loaded ok to consul"$EGREEN
1469 fi
1470 fi
1471
1472 echo ""
1473
1474}
1475
1476# Function to perpare the consul configuration according to the current simulator configuration
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001477# args: SDNC|NOSDNC <output-file>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001478# (Function for test scripts)
1479prepare_consul_config() {
1480 echo -e $BOLD"Prepare Consul config"$EBOLD
1481
1482 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
1483
1484 if [ $# != 2 ]; then
1485 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001486 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001487 exit 1
1488 fi
1489
1490 if [ $1 == "SDNC" ]; then
1491 echo -e " Config$BOLD including SDNC$EBOLD configuration"
1492 elif [ $1 == "NOSDNC" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001493 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001494 else
1495 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001496 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001497 exit 1
1498 fi
1499
1500 config_json="\n {"
1501 if [ $1 == "SDNC" ]; then
1502 config_json=$config_json"\n \"controller\": ["
1503 config_json=$config_json"\n {"
1504 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001505 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1506 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://$SDNC_APP_NAME:$SDNC_PORT\","
1507 else
1508 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://localhost:$SDNC_LOCAL_PORT\","
1509 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001510 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
1511 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
1512 config_json=$config_json"\n }"
1513 config_json=$config_json"\n ],"
1514 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001515
1516 config_json=$config_json"\n \"streams_publishes\": {"
1517 config_json=$config_json"\n \"dmaap_publisher\": {"
1518 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1519 config_json=$config_json"\n \"dmaap_info\": {"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001520 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1521 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_WRITE_URL\""
1522 else
1523 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_WRITE_URL\""
1524 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001525 config_json=$config_json"\n }"
1526 config_json=$config_json"\n }"
1527 config_json=$config_json"\n },"
1528 config_json=$config_json"\n \"streams_subscribes\": {"
1529 config_json=$config_json"\n \"dmaap_subscriber\": {"
1530 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1531 config_json=$config_json"\n \"dmaap_info\": {"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001532 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1533 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_READ_URL\""
1534 else
1535 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_READ_URL\""
1536 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001537 config_json=$config_json"\n }"
1538 config_json=$config_json"\n }"
1539 config_json=$config_json"\n },"
1540
1541 config_json=$config_json"\n \"ric\": ["
1542
BjornMagnussonXAad047782020-06-08 15:54:11 +02001543 rics=$(docker ps | grep $RIC_SIM_PREFIX | awk '{print $NF}')
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001544
1545 if [ $? -ne 0 ] || [ -z "$rics" ]; then
1546 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
1547 ((RES_CONF_FAIL++))
1548 return 1
1549 fi
1550
1551 cntr=0
1552 for ric in $rics; do
1553 if [ $cntr -gt 0 ]; then
1554 config_json=$config_json"\n ,"
1555 fi
1556 config_json=$config_json"\n {"
1557 config_json=$config_json"\n \"name\": \"$ric\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001558 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1559 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
1560 else
1561 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://localhost:$(__find_sim_port $ric)\","
1562 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001563 if [ $1 == "SDNC" ]; then
1564 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
1565 fi
1566 config_json=$config_json"\n \"managedElementIds\": ["
1567 config_json=$config_json"\n \"me1_$ric\","
1568 config_json=$config_json"\n \"me2_$ric\""
1569 config_json=$config_json"\n ]"
1570 config_json=$config_json"\n }"
1571 let cntr=cntr+1
1572 done
1573
1574 config_json=$config_json"\n ]"
1575 config_json=$config_json"\n}"
1576
1577
1578 printf "$config_json">$2
1579
1580 echo ""
1581}
1582
1583
1584# Start Consul and CBS
1585# args: -
1586# (Function for test scripts)
1587start_consul_cbs() {
1588
1589 echo -e $BOLD"Starting Consul and CBS"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001590 __check_included_image 'CONSUL'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001591 if [ $? -eq 1 ]; then
1592 echo -e $RED"The Consul image has not been checked for this test run due to arg to the test script"$ERED
1593 echo -e $RED"Consul will not be started"$ERED
1594 exit
1595 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001596 __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" "http" \
1597 "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001598}
1599
1600###########################
1601### RIC Simulator functions
1602###########################
1603
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001604use_simulator_http() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001605 echo -e $BOLD"RICSIM protocol setting"$EBOLD
1606 echo -e " Using $BOLD http $EBOLD towards the simulators"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001607 export RIC_SIM_HTTPX="http"
1608 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1609 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001610 echo ""
1611}
1612
1613use_simulator_https() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001614 echo -e $BOLD"RICSIM protocol setting"$EBOLD
1615 echo -e " Using $BOLD https $EBOLD towards the simulators"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001616 export RIC_SIM_HTTPX="https"
1617 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1618 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001619 echo ""
1620}
1621
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001622# Start one group (ricsim_g1, ricsim_g2 .. ricsim_g5) with a number of RIC Simulators using a given A interface
BjornMagnussonXAad047782020-06-08 15:54:11 +02001623# 'ricsim' may be set on command line to other prefix
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001624# args: ricsim_g1|ricsim_g2|ricsim_g3|ricsim_g4|ricsim_g5 <count> <interface-id>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001625# (Function for test scripts)
1626start_ric_simulators() {
1627
1628 echo -e $BOLD"Starting RIC Simulators"$EBOLD
1629
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001630 __check_included_image 'RICSIM'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001631 if [ $? -eq 1 ]; then
1632 echo -e $RED"The Near-RT RIC Simulator image has not been checked for this test run due to arg to the test script"$ERED
1633 echo -e $RED"The Near-RT RIC Simulartor(s) will not be started"$ERED
1634 exit
1635 fi
1636
BjornMagnussonXAad047782020-06-08 15:54:11 +02001637 RIC1=$RIC_SIM_PREFIX"_g1"
1638 RIC2=$RIC_SIM_PREFIX"_g2"
1639 RIC3=$RIC_SIM_PREFIX"_g3"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001640 RIC4=$RIC_SIM_PREFIX"_g4"
1641 RIC5=$RIC_SIM_PREFIX"_g5"
BjornMagnussonXAad047782020-06-08 15:54:11 +02001642
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001643 if [ $# != 3 ]; then
1644 ((RES_CONF_FAIL++))
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001645 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001646 exit 1
1647 fi
1648 echo " $2 simulators using basename: $1 on interface: $3"
1649 #Set env var for simulator count and A1 interface vesion for the given group
BjornMagnussonXAad047782020-06-08 15:54:11 +02001650 if [ $1 == "$RIC1" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001651 G1_COUNT=$2
1652 G1_A1_VERSION=$3
BjornMagnussonXAad047782020-06-08 15:54:11 +02001653 elif [ $1 == "$RIC2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001654 G2_COUNT=$2
1655 G2_A1_VERSION=$3
BjornMagnussonXAad047782020-06-08 15:54:11 +02001656 elif [ $1 == "$RIC3" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001657 G3_COUNT=$2
1658 G3_A1_VERSION=$3
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001659 elif [ $1 == "$RIC4" ]; then
1660 G4_COUNT=$2
1661 G4_A1_VERSION=$3
1662 elif [ $1 == "$RIC5" ]; then
1663 G5_COUNT=$2
1664 G5_A1_VERSION=$3
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001665 else
1666 ((RES_CONF_FAIL++))
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001667 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001668 exit 1
1669 fi
1670
1671 # Create .env file to compose project, all ric container will get this prefix
1672 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
1673
1674 export G1_A1_VERSION
1675 export G2_A1_VERSION
1676 export G3_A1_VERSION
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001677 export G4_A1_VERSION
1678 export G5_A1_VERSION
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001679
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001680 docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT --scale g4=$G4_COUNT --scale g5=$G5_COUNT"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001681 app_data=""
1682 cntr=1
1683 while [ $cntr -le $2 ]; do
1684 app=$1"_"$cntr
1685 port=0
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001686 app_data="$app_data $app $port / "$RIC_SIM_HTTPX
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001687 let cntr=cntr+1
1688 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001689 __start_container ric "$docker_args" $app_data
1690
1691}
1692
1693###########################
1694### Control Panel functions
1695###########################
1696
1697# Start the Control Panel container
1698# args: -
1699# (Function for test scripts)
1700start_control_panel() {
1701
1702 echo -e $BOLD"Starting Control Panel"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001703 __check_included_image 'CP'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001704 if [ $? -eq 1 ]; then
1705 echo -e $RED"The Control Panel image has not been checked for this test run due to arg to the test script"$ERED
1706 echo -e $RED"The Control Panel will not be started"$ERED
1707 exit
1708 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001709 __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001710
1711}
1712
BjornMagnussonXAde4d0f82020-11-29 16:04:06 +01001713###########################
1714### RAPP Catalogue
1715###########################
1716
1717# Start the RAPP Catalogue container
1718# args: -
1719# (Function for test scripts)
1720start_rapp_catalogue() {
1721
1722 echo -e $BOLD"Starting RAPP Catalogue"$EBOLD
1723
1724 __check_included_image 'RC'
1725 if [ $? -eq 1 ]; then
1726 echo -e $RED"The RAPP Catalogue image has not been checked for this test run due to arg to the test script"$ERED
1727 echo -e $RED"The RAPP Catalogue will not be started"$ERED
1728 exit
1729 fi
1730 __start_container rapp_catalogue NODOCKERARGS $RAPP_CAT_APP_NAME $RAPP_CAT_EXTERNAL_PORT "/services" "http"
1731}
1732
1733use_rapp_catalogue_http() {
1734 echo -e $BOLD"RAPP Catalogue protocol setting"$EBOLD
1735 echo -e " Using $BOLD http $EBOLD towards the RAPP Catalogue"
1736 export RAPP_CAT_HTTPX="http"
1737 export RAPP_CAT_PORT=$RAPP_CAT_INTERNAL_PORT
1738 export RAPP_CAT_LOCAL_PORT=$RAPP_CAT_EXTERNAL_PORT
1739 echo ""
1740}
1741
1742use_rapp_catalogue_https() {
1743 echo -e $BOLD"RAPP Catalogue protocol setting"$EBOLD
1744 echo -e " Using $BOLD https $EBOLD towards the RAPP Catalogue"
1745 export RAPP_CAT_HTTPX="https"
1746 export RAPP_CAT_PORT=$RAPP_CAT_INTERNAL_PORT
1747 export RAPP_CAT_LOCAL_PORT=$RAPP_CAT_EXTERNAL_PORT
1748 echo ""
1749}
1750
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001751##################
1752### SDNC functions
1753##################
1754
1755# Start the SDNC A1 Controller
1756# args: -
1757# (Function for test scripts)
1758start_sdnc() {
1759
1760 echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
1761
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001762 __check_included_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001763 if [ $? -eq 1 ]; then
1764 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
1765 echo -e $RED"SDNC will not be started"$ERED
1766 exit
1767 fi
1768
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001769 __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT $SDNC_ALIVE_URL "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001770
1771}
1772
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001773use_sdnc_http() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001774 echo -e $BOLD"SDNC protocol setting"$EBOLD
1775 echo -e " Using $BOLD http $EBOLD towards SDNC"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001776 export SDNC_HTTPX="http"
1777 export SDNC_PORT=$SDNC_INTERNAL_PORT
1778 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT
1779 echo ""
1780}
1781
1782use_sdnc_https() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001783 echo -e $BOLD"SDNC protocol setting"$EBOLD
1784 echo -e " Using $BOLD https $EBOLD towards SDNC"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001785 export SDNC_HTTPX="https"
1786 export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT
1787 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT
1788 echo ""
1789}
1790
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001791#####################
1792### MR stub functions
1793#####################
1794
1795# Start the Message Router stub interface in the simulator group
1796# args: -
1797# (Function for test scripts)
1798start_mr() {
1799
1800 echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001801 __check_included_image 'MR'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001802 if [ $? -eq 1 ]; then
1803 echo -e $RED"The Message Router image has not been checked for this test run due to arg to the test script"$ERED
1804 echo -e $RED"The Message Router will not be started"$ERED
1805 exit
1806 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001807 export MR_CERT_MOUNT_DIR="./cert"
1808 __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001809}
1810
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001811use_mr_http() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001812 echo -e $BOLD"MR protocol setting"$EBOLD
1813 echo -e " Using $BOLD http $EBOLD towards MR"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001814 export MR_HTTPX="http"
1815 export MR_PORT=$MR_INTERNAL_PORT
1816 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT
1817 echo ""
1818}
1819
1820use_mr_https() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001821 echo -e $BOLD"MR protocol setting"$EBOLD
1822 echo -e " Using $BOLD https $EBOLD towards MR"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001823 export MR_HTTPX="https"
1824 export MR_PORT=$MR_INTERNAL_SECURE_PORT
1825 export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT
1826 echo ""
1827}
1828
1829
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001830################
1831### CR functions
1832################
1833
1834# Start the Callback reciver in the simulator group
1835# args: -
1836# (Function for test scripts)
1837start_cr() {
1838
1839 echo -e $BOLD"Starting Callback Receiver"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001840 __check_included_image 'CR'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001841 if [ $? -eq 1 ]; then
1842 echo -e $RED"The Callback Receiver image has not been checked for this test run due to arg to the test script"$ERED
1843 echo -e $RED"The Callback Receiver will not be started"$ERED
1844 exit
1845 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001846 __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001847
1848}
1849
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001850use_cr_http() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001851 echo -e $BOLD"CR protocol setting"$EBOLD
1852 echo -e " Using $BOLD http $EBOLD towards CR"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001853 export CR_HTTPX="http"
1854 export CR_PORT=$CR_INTERNAL_PORT
1855 export CR_LOCAL_PORT=$CR_EXTERNAL_PORT
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001856 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001857 echo ""
1858}
1859
1860use_cr_https() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001861 echo -e $BOLD"CR protocol setting"$EBOLD
1862 echo -e " Using $BOLD https $EBOLD towards CR"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001863 export CR_HTTPX="https"
1864 export CR_PORT=$CR_INTERNAL_SECURE_PORT
1865 export CR_LOCAL_PORT=$CR_EXTERNAL_SECURE_PORT
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001866 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001867 echo ""
1868}
1869
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001870###########################
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001871### Producer stub functions
1872###########################
1873
1874# Start the Producer stub in the simulator group
1875# args: -
1876# (Function for test scripts)
1877start_prod_stub() {
1878
1879 echo -e $BOLD"Starting Producer stub"$EBOLD
1880 __check_included_image 'PRODSTUB'
1881 if [ $? -eq 1 ]; then
1882 echo -e $RED"The Producer stub image has not been checked for this test run due to arg to the test script"$ERED
1883 echo -e $RED"The Producer stub will not be started"$ERED
1884 exit
1885 fi
1886 __start_container prodstub NODOCKERARGS $PROD_STUB_APP_NAME $PROD_STUB_EXTERNAL_PORT "/" "http"
1887
1888}
1889
1890use_prod_stub_http() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001891 echo -e $BOLD"Producer stub protocol setting"$EBOLD
1892 echo -e " Using $BOLD http $EBOLD towards Producer stub"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001893 export PROD_STUB_HTTPX="http"
1894 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
1895 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT
1896 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
1897 echo ""
1898}
1899
1900use_prod_stub_https() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001901 echo -e $BOLD"Producer stub protocol setting"$EBOLD
1902 echo -e " Using $BOLD https $EBOLD towards Producer stub"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001903 export PROD_STUB_HTTPX="https"
1904 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_SECURE_PORT
1905 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_SECURE_PORT
1906 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
1907 echo ""
1908}
1909
1910###########################
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001911### Policy Agents functions
1912###########################
1913
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001914# Use an agent on the local machine instead of container
1915use_agent_stand_alone() {
1916 AGENT_STAND_ALONE=1
1917}
1918
1919# Start the policy agent
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001920# args: -
1921# (Function for test scripts)
1922start_policy_agent() {
1923
1924 echo -e $BOLD"Starting Policy Agent"$EBOLD
1925
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001926 if [ $AGENT_STAND_ALONE -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001927 __check_included_image 'PA'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001928 if [ $? -eq 1 ]; then
1929 echo -e $RED"The Policy Agent image has not been checked for this test run due to arg to the test script"$ERED
1930 echo -e $RED"The Policy Agent will not be started"$ERED
1931 exit
1932 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001933 __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1934 else
1935 echo -e $RED"The consul config produced by this test script (filename '<fullpath-to-autotest-dir>.output<file-name>"$ERED
1936 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
1937 echo -e $RED"application.yaml"$ERED
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001938 echo -e $RED"The application jar may need to be built before continuing"$ERED
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001939 echo -e $RED"The agent shall now be running on port $POLICY_AGENT_EXTERNAL_PORT for http"$ERED
1940
1941 read -p "<press any key to continue>"
1942 __start_container policy_agent "STANDALONE" $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1943 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001944
1945}
1946
1947# All calls to the agent will be directed to the agent REST interface from now on
1948# args: -
1949# (Function for test scripts)
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001950use_agent_rest_http() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001951 echo -e $BOLD"Agent protocol setting"$EBOLD
1952 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001953 export ADAPTER=$RESTBASE
1954 echo ""
1955}
1956
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001957# All calls to the agent will be directed to the agent REST interface from now on
1958# args: -
1959# (Function for test scripts)
1960use_agent_rest_https() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001961 echo -e $BOLD"Agent protocol setting"$EBOLD
1962 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001963 export ADAPTER=$RESTBASE_SECURE
1964 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001965 return 0
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001966}
1967
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001968# All calls to the agent will be directed to the agent dmaap interface over http from now on
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001969# args: -
1970# (Function for test scripts)
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001971use_agent_dmaap_http() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001972 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
1973 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001974 export ADAPTER=$DMAAPBASE
1975 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001976 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001977}
1978
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001979# All calls to the agent will be directed to the agent dmaap interface over https from now on
1980# args: -
1981# (Function for test scripts)
1982use_agent_dmaap_https() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001983 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
1984 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001985 export ADAPTER=$DMAAPBASE_SECURE
1986 echo ""
1987 return 0
1988}
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001989
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001990# Turn on debug level tracing in the agent
1991# args: -
1992# (Function for test scripts)
1993set_agent_debug() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001994 echo -e $BOLD"Setting agent debug logging"$EBOLD
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02001995 actuator="/actuator/loggers/org.oransc.policyagent"
1996 if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
1997 actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
1998 fi
1999 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002000 result=$(__do_curl "$curlString")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002001 if [ $? -ne 0 ]; then
2002 __print_err "could not set debug mode" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002003 ((RES_CONF_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002004 return 1
2005 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002006 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02002007 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002008}
2009
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002010# Turn on trace level tracing in the agent
2011# args: -
2012# (Function for test scripts)
2013set_agent_trace() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002014 echo -e $BOLD"Setting agent trace logging"$EBOLD
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02002015 actuator="/actuator/loggers/org.oransc.policyagent"
2016 if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
2017 actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
2018 fi
2019 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002020 result=$(__do_curl "$curlString")
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002021 if [ $? -ne 0 ]; then
2022 __print_err "could not set trace mode" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002023 ((RES_CONF_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002024 return 1
2025 fi
2026 echo ""
2027 return 0
2028}
2029
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002030# Perform curl retries when making direct call to the agent for the specified http response codes
2031# Speace separated list of http response codes
2032# args: [<response-code>]*
2033use_agent_retries() {
2034 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
2035 AGENT_RETRY_CODES=$@
2036 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02002037 return
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002038}
2039
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002040###########################
2041### ECS functions
2042###########################
2043
2044# Start the ECS
2045# args: -
2046# (Function for test scripts)
2047start_ecs() {
2048
2049 echo -e $BOLD"Starting ECS"$EBOLD
BjornMagnussonXA2791e082020-11-12 00:52:08 +01002050
2051 curdir=$PWD
2052 cd $SIM_GROUP
2053 cd ecs
2054 cd $ECS_HOST_MNT_DIR
2055 if [ -d database ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002056 if [ "$(ls -A $DIR)" ]; then
2057 echo -e $BOLD" Cleaning files in mounted dir: $PWD/database"$EBOLD
2058 rm -rf database/* &> /dev/null
2059 if [ $? -ne 0 ]; then
2060 echo -e $RED" Cannot remove database files in: $PWD"$ERED
2061 exit 1
2062 fi
BjornMagnussonXA2791e082020-11-12 00:52:08 +01002063 fi
2064 else
2065 echo " No files in mounted dir or dir does not exists"
2066 fi
2067 cd $curdir
2068
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002069 __check_included_image 'ECS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002070 if [ $? -eq 1 ]; then
2071 echo -e $RED"The ECS image has not been checked for this test run due to arg to the test script"$ERED
2072 echo -e $RED"ECS will not be started"$ERED
2073 exit
2074 fi
2075 export ECS_CERT_MOUNT_DIR="./cert"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002076 __start_container ecs NODOCKERARGS $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002077}
2078
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01002079# Restart ECS
2080# args: -
2081# (Function for test scripts)
2082restart_ecs() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002083 echo -e $BOLD"Re-starting ECS"$EBOLD
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01002084 docker restart $ECS_APP_NAME &> ./tmp/.dockererr
2085 if [ $? -ne 0 ]; then
2086 __print_err "Could restart $ECS_APP_NAME" $@
2087 cat ./tmp/.dockererr
2088 ((RES_CONF_FAIL++))
2089 return 1
2090 fi
2091
2092 __check_container_start $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
2093 echo ""
2094 return 0
2095}
2096
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002097# All calls to ECS will be directed to the ECS REST interface from now on
2098# args: -
2099# (Function for test scripts)
2100use_ecs_rest_http() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002101 echo -e $BOLD"ECS protocol setting"$EBOLD
2102 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002103 export ECS_ADAPTER=$ECS_RESTBASE
2104 echo ""
2105}
2106
2107# All calls to ECS will be directed to the ECS REST interface from now on
2108# args: -
2109# (Function for test scripts)
2110use_ecs_rest_https() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002111 echo -e $BOLD"ECS protocol setting"$EBOLD
2112 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002113 export ECS_ADAPTER=$ECS_RESTBASE_SECURE
2114 echo ""
2115 return 0
2116}
2117
2118# All calls to ECS will be directed to the ECS dmaap interface over http from now on
2119# args: -
2120# (Function for test scripts)
2121use_ecs_dmaap_http() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002122 echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
2123 echo -e $RED" - NOT SUPPORTED - "$ERED
2124 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002125 export ECS_ADAPTER=$ECS_DMAAPBASE
2126 echo ""
2127 return 0
2128}
2129
2130# All calls to ECS will be directed to the ECS dmaap interface over https from now on
2131# args: -
2132# (Function for test scripts)
2133use_ecs_dmaap_https() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002134 echo -e $BOLD"RICSIM protocol setting"$EBOLD
2135 echo -e $RED" - NOT SUPPORTED - "$ERED
2136 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002137 export ECS_ADAPTER=$ECS_DMAAPBASE_SECURE
2138 echo ""
2139 return 0
2140}
2141
2142# Turn on debug level tracing in ECS
2143# args: -
2144# (Function for test scripts)
2145set_ecs_debug() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002146 echo -e $BOLD"Setting ecs debug logging"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002147 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
2148 result=$(__do_curl "$curlString")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002149 if [ $? -ne 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002150 __print_err "Could not set debug mode" $@
2151 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002152 return 1
2153 fi
2154 echo ""
2155 return 0
2156}
2157
2158# Turn on trace level tracing in ECS
2159# args: -
2160# (Function for test scripts)
2161set_ecs_trace() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002162 echo -e $BOLD"Setting ecs trace logging"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002163 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
2164 result=$(__do_curl "$curlString")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002165 if [ $? -ne 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002166 __print_err "Could not set trace mode" $@
2167 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002168 return 1
2169 fi
2170 echo ""
2171 return 0
2172}
2173
2174# Perform curl retries when making direct call to ECS for the specified http response codes
2175# Speace separated list of http response codes
2176# args: [<response-code>]*
2177use_agent_retries() {
2178 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
2179 ECS_AGENT_RETRY_CODES=$@
2180 echo ""
2181 return
2182}
2183
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002184#################
2185### Log functions
2186#################
2187
2188# Check the agent logs for WARNINGs and ERRORs
2189# args: -
2190# (Function for test scripts)
2191
YongchaoWu9a84f512019-12-16 22:54:11 +01002192check_policy_agent_logs() {
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002193 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
YongchaoWu9a84f512019-12-16 22:54:11 +01002194}
2195
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002196check_ecs_logs() {
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002197 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002198}
2199
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002200check_control_panel_logs() {
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002201 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH WARN ERR
2202}
2203
2204check_sdnc_logs() {
2205 __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
YongchaoWu9a84f512019-12-16 22:54:11 +01002206}
2207
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002208__check_container_logs() {
2209 dispname=$1
2210 appname=$2
2211 logpath=$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002212 warning=$4
2213 error=$5
2214
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002215 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
2216
2217 #tmp=$(docker ps | grep $appname)
2218 tmp=$(docker ps -q --filter name=$appname) #get the container id
2219 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
2220 echo $dispname" is not running, no check made"
2221 return
2222 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002223 foundentries="$(docker exec -t $tmp grep $warning $logpath | wc -l)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002224 if [ $? -ne 0 ];then
2225 echo " Problem to search $appname log $logpath"
2226 else
2227 if [ $foundentries -eq 0 ]; then
2228 echo " No WARN entries found in $appname log $logpath"
2229 else
2230 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
2231 fi
2232 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002233 foundentries="$(docker exec -t $tmp grep $error $logpath | wc -l)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002234 if [ $? -ne 0 ];then
2235 echo " Problem to search $appname log $logpath"
2236 else
2237 if [ $foundentries -eq 0 ]; then
2238 echo " No ERR entries found in $appname log $logpath"
2239 else
2240 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
2241 fi
2242 fi
2243 echo ""
2244}
2245
2246# Store all container logs and other logs in the log dir for the script
2247# Logs are stored with a prefix in case logs should be stored several times during a test
2248# args: <logfile-prefix>
2249# (Function for test scripts)
YongchaoWu9a84f512019-12-16 22:54:11 +01002250store_logs() {
2251 if [ $# != 1 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002252 ((RES_CONF_FAIL++))
2253 __print_err "need one arg, <file-prefix>" $@
YongchaoWu9a84f512019-12-16 22:54:11 +01002254 exit 1
2255 fi
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01002256 echo -e $BOLD"Storing all container logs in $TESTLOGS/$ATC using prefix: "$1$EBOLD
YongchaoWu9a84f512019-12-16 22:54:11 +01002257
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02002258 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002259
2260 __check_included_image 'CONSUL'
2261 if [ $? -eq 0 ]; then
2262 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
2263 fi
2264
2265 __check_included_image 'CBS'
2266 if [ $? -eq 0 ]; then
2267 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
2268 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
2269 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
2270 fi
2271
2272 __check_included_image 'PA'
2273 if [ $? -eq 0 ]; then
2274 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
2275 fi
2276
2277 __check_included_image 'ECS'
2278 if [ $? -eq 0 ]; then
2279 docker logs $ECS_APP_NAME > $TESTLOGS/$ATC/$1_ecs.log 2>&1
2280 fi
2281
2282 __check_included_image 'CP'
2283 if [ $? -eq 0 ]; then
2284 docker logs $CONTROL_PANEL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
2285 fi
2286
2287 __check_included_image 'MR'
2288 if [ $? -eq 0 ]; then
2289 docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
2290 fi
2291
2292 __check_included_image 'CR'
2293 if [ $? -eq 0 ]; then
2294 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
2295 fi
2296
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002297 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
2298
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002299 __check_included_image 'SDNC'
2300 if [ $? -eq 0 ]; then
2301 docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
2302 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002303
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002304 __check_included_image 'RICSIM'
2305 if [ $? -eq 0 ]; then
2306 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
2307 for ric in $rics; do
2308 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
2309 done
2310 fi
2311
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02002312 __check_included_image 'PRODSTUB'
2313 if [ $? -eq 0 ]; then
2314 docker logs $PROD_STUB_APP_NAME > $TESTLOGS/$ATC/$1_prodstub.log 2>&1
2315 fi
2316
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002317 echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +01002318}
2319
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002320###############
2321## Generic curl
2322###############
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002323# Generic curl function, assumes all 200-codes are ok
2324# args: <valid-curl-args-including full url>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002325# returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
2326# returns: The return code is 0 for ok and 1 for not ok
YongchaoWu9a84f512019-12-16 22:54:11 +01002327__do_curl() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002328 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002329 curlString="curl -skw %{http_code} $@"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002330 echo " CMD: $curlString" >> $HTTPLOG
2331 res=$($curlString)
2332 echo " RESP: $res" >> $HTTPLOG
YongchaoWu9a84f512019-12-16 22:54:11 +01002333 http_code="${res:${#res}-3}"
2334 if [ ${#res} -eq 3 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002335 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2336 echo "<no-response-from-server>"
2337 return 1
2338 else
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002339 return 0
2340 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01002341 else
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002342 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
YongchaoWu9a84f512019-12-16 22:54:11 +01002343 echo "<not found, resp:${http_code}>"
2344 return 1
2345 fi
2346 if [ $# -eq 2 ]; then
2347 echo "${res:0:${#res}-3}" | xargs
2348 else
2349 echo "${res:0:${#res}-3}"
2350 fi
2351
2352 return 0
2353 fi
2354}
2355
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002356#######################################
2357### Basic helper function for test cases
2358#######################################
2359
2360# Test a simulator container variable value towards target value using an condition operator with an optional timeout.
2361# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
2362# immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
2363# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
2364# before setting pass or fail depending on the result of comparing variable and target using the operator.
2365# 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.
2366# Not to be called from test script.
2367
2368__var_test() {
2369 checkjsonarraycount=0
2370
2371 if [ $# -eq 6 ]; then
2372 if [[ $3 == "json:"* ]]; then
2373 checkjsonarraycount=1
2374 fi
2375
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002376 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002377 ((RES_TEST++))
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002378 ((TEST_SEQUENCE_NR++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002379 start=$SECONDS
2380 ctr=0
2381 for (( ; ; )); do
2382 if [ $checkjsonarraycount -eq 0 ]; then
2383 result="$(__do_curl $2$3)"
2384 retcode=$?
2385 result=${result//[[:blank:]]/} #Strip blanks
2386 else
2387 path=${3:5}
2388 result="$(__do_curl $2$path)"
2389 retcode=$?
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002390 echo "$result" > ./tmp/.tmp.curl.json
2391 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002392 fi
2393 duration=$((SECONDS-start))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002394 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002395 let ctr=ctr+1
2396 if [ $retcode -ne 0 ]; then
2397 if [ $duration -gt $6 ]; then
2398 ((RES_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002399 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002400 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002401 return
2402 fi
2403 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2404 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002405 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002406 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002407 return
2408 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2409 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002410 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002411 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002412 return
2413 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2414 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002415 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002416 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002417 return
2418 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2419 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002420 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002421 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002422 return
2423 else
2424 if [ $duration -gt $6 ]; then
2425 ((RES_FAIL++))
2426 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002427 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002428 return
2429 fi
2430 fi
2431 sleep 1
2432 done
2433 elif [ $# -eq 5 ]; then
2434 if [[ $3 == "json:"* ]]; then
2435 checkjsonarraycount=1
2436 fi
2437
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002438 echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002439 ((RES_TEST++))
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002440 ((TEST_SEQUENCE_NR++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002441 if [ $checkjsonarraycount -eq 0 ]; then
2442 result="$(__do_curl $2$3)"
2443 retcode=$?
2444 result=${result//[[:blank:]]/} #Strip blanks
2445 else
2446 path=${3:5}
2447 result="$(__do_curl $2$path)"
2448 retcode=$?
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002449 echo "$result" > ./tmp/.tmp.curl.json
2450 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002451 fi
2452 if [ $retcode -ne 0 ]; then
2453 ((RES_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002454 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002455 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002456 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2457 ((RES_PASS++))
2458 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002459 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2460 ((RES_PASS++))
2461 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002462 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2463 ((RES_PASS++))
2464 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002465 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2466 ((RES_PASS++))
2467 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002468 else
2469 ((RES_FAIL++))
2470 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002471 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002472 fi
2473 else
2474 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
2475 echo "Got:" $@
2476 exit 1
2477 fi
2478}
2479
2480
2481### Generic test cases for varaible checking
2482
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002483# Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
2484# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2485# equal to the target or not.
2486# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2487# before setting pass or fail depending on if the variable value becomes equal to the target
2488# value or not.
2489# (Function for test scripts)
2490mr_equal() {
2491 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2492 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
2493 else
2494 ((RES_CONF_FAIL++))
2495 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2496 fi
2497}
2498
2499# Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
2500# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2501# greater than the target or not.
2502# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2503# before setting pass or fail depending on if the variable value becomes greater than the target
2504# value or not.
2505# (Function for test scripts)
2506mr_greater() {
2507 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002508 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 ">" $2 $3
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002509 else
2510 ((RES_CONF_FAIL++))
2511 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2512 fi
2513}
2514
2515# Read a variable value from MR sim and send to stdout. Arg: <variable-name>
2516mr_read() {
2517 echo "$(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"
2518}
2519
2520# Print a variable value from the MR stub.
2521# arg: <variable-name>
2522# (Function for test scripts)
2523mr_print() {
2524 if [ $# != 1 ]; then
2525 ((RES_CONF_FAIL++))
2526 __print_err "need one arg, <mr-param>" $@
2527 exit 1
2528 fi
2529 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"$EBOLD
2530}