blob: ed02c7b10b4245a7fe4aa2608c0db3d335470110 [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
64TEST_ENV_VAR_FILE="../common/test_env.sh"
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
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020087AVAILABLE_LOCAL_IMAGES_OVERRIDE="PA ECS CP SDNC RICSIM"
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
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100131# Clear the log dir for the test case
132rm $TESTLOGS/$ATC/*.log &> /dev/null
133rm $TESTLOGS/$ATC/*.txt &> /dev/null
134rm $TESTLOGS/$ATC/*.json &> /dev/null
135
136# Log all output from the test case to a TC log
YongchaoWu9a84f512019-12-16 22:54:11 +0100137TCLOG=$TESTLOGS/$ATC/TC.log
138exec &> >(tee ${TCLOG})
139
140#Variables for counting tests as well as passed and failed tests
141RES_TEST=0
142RES_PASS=0
143RES_FAIL=0
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100144RES_CONF_FAIL=0
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200145RES_DEVIATION=0
146
147#File to keep deviation messages
148DEVIATION_FILE=".tmp_deviations"
149rm $DEVIATION_FILE &> /dev/null
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100150
151#Var for measuring execution time
YongchaoWu9a84f512019-12-16 22:54:11 +0100152TCTEST_START=$SECONDS
153
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200154#File to save timer measurement results
155TIMER_MEASUREMENTS=".timer_measurement.txt"
156echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS
157
158
YongchaoWu9a84f512019-12-16 22:54:11 +0100159echo "-------------------------------------------------------------------------------------------------"
160echo "----------------------------------- Test case: "$ATC
161echo "----------------------------------- Started: "$(date)
162echo "-------------------------------------------------------------------------------------------------"
163echo "-- Description: "$TC_ONELINE_DESCR
164echo "-------------------------------------------------------------------------------------------------"
165echo "----------------------------------- Test case setup -----------------------------------"
166
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200167START_ARG=$1
168paramerror=0
169if [ $# -lt 1 ]; then
170 paramerror=1
171fi
172if [ $paramerror -eq 0 ]; then
173 if [ "$1" != "remote" ] && [ "$1" != "remote-remove" ] && [ "$1" != "local" ]; then
174 paramerror=1
175 else
176 shift;
177 fi
178fi
BjornMagnussonXAad047782020-06-08 15:54:11 +0200179foundparm=0
180while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do
181 foundparm=1
182 if [ $paramerror -eq 0 ]; then
183 if [ "$1" == "auto-clean" ]; then
184 AUTO_CLEAN="auto"
185 echo "Option set - Auto clean at end of test script"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200186 shift;
BjornMagnussonXAad047782020-06-08 15:54:11 +0200187 foundparm=0
188 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200189 fi
BjornMagnussonXAad047782020-06-08 15:54:11 +0200190 if [ $paramerror -eq 0 ]; then
191 if [ "$1" == "--stop-at-error" ]; then
192 STOP_AT_ERROR=1
193 echo "Option set - Stop at first error"
194 shift;
195 foundparm=0
196 fi
197 fi
198 if [ $paramerror -eq 0 ]; then
199 if [ "$1" == "--ricsim-prefix" ]; then
200 shift;
201 RIC_SIM_PREFIX=$1
202 if [ -z "$1" ]; then
203 paramerror=1
204 else
205 echo "Option set - Overriding RIC_SIM_PREFIX with: "$1
206 shift;
207 foundparm=0
208 fi
209 fi
210 fi
211 if [ $paramerror -eq 0 ]; then
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200212 if [ "$1" == "--env-file" ]; then
213 shift;
214 TEST_ENV_VAR_FILE=$1
215 if [ -z "$1" ]; then
216 paramerror=1
217 else
218 echo "Option set - Overriding test_env.sh with: "$1
219 shift;
220 foundparm=0
221 fi
222 fi
223 fi
224 if [ $paramerror -eq 0 ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +0200225 if [ "$1" == "--use-local-image" ]; then
226 USE_LOCAL_IMAGES=""
227 shift
228 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
229 USE_LOCAL_IMAGES=$USE_LOCAL_IMAGES" "$1
230 if [[ "$AVAILABLE_LOCAL_IMAGES_OVERRIDE" != *"$1"* ]]; then
231 paramerror=1
232 fi
233 shift;
234 done
235 foundparm=0
236 if [ -z "$USE_LOCAL_IMAGES" ]; then
237 paramerror=1
238 else
239 echo "Option set - Override remote images for app(s):"$USE_LOCAL_IMAGES
240 fi
241 fi
242 fi
243done
244echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200245
BjornMagnussonXAad047782020-06-08 15:54:11 +0200246#Still params left?
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200247if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
248 paramerror=1
249fi
250
251if [ $paramerror -eq 1 ]; then
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200252 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 +0200253 exit 1
254fi
255
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200256# sourcing the selected env variables for the test case
257if [ -f "$TEST_ENV_VAR_FILE" ]; then
258 echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD
259 . $TEST_ENV_VAR_FILE
260else
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200261 echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200262 exit 1
263fi
264
265#Vars for A1 interface version and container count
266G1_A1_VERSION=""
267G2_A1_VERSION=""
268G3_A1_VERSION=""
269G1_COUNT=0
270G2_COUNT=0
271G3_COUNT=0
272
273# Vars to switch between http and https. Extra curl flag needed for https
274export RIC_SIM_HTTPX="http"
275export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
276export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
277export RIC_SIM_CERT_MOUNT_DIR="./cert"
278
279export MR_HTTPX="http"
280export MR_PORT=$MR_INTERNAL_PORT
281export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker net
282
283export CR_HTTPX="http"
284export CR_PORT=$CR_INTERNAL_PORT
285export CR_LOCAL_PORT=$CR_EXTERNAL_PORT #When CR is running outside the docker net
286
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200287export PROD_STUB_HTTPX="http"
288export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
289export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT #When CR is running outside the docker net
290export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
291
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200292export SDNC_HTTPX="http"
293export SDNC_PORT=$SDNC_INTERNAL_PORT
294export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net
295
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100296echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
YongchaoWu9a84f512019-12-16 22:54:11 +0100297
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100298#Temp var to check for image variable name errors
299IMAGE_ERR=0
300#Create a file with image info for later printing as a table
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200301image_list_file="./tmp/.image-list"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100302echo -e " Container\tImage\ttag" > $image_list_file
303
304# 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 +0200305# 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 +0100306__check_image_var() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200307 if [ $# -ne 6 ]; then
308 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 +0100309 ((IMAGE_ERR++))
310 return
311 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200312 __check_included_image $6
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200313 if [ $? -ne 0 ]; then
314 echo -e "$1\t<image-excluded>\t<no-tag>" >> $image_list_file
315 # Image is excluded since the corresponding app is not used in this test
316 return
317 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100318 tmp=${1}"\t"
319 #Create var from the input var names
320 image="${!4}"
321 tag="${!5}"
322
323 if [ -z $image ]; then
324 echo -e $RED"\$"$4" not set in test_env"$ERED
325 ((IMAGE_ERR++))
326 echo ""
327 tmp=$tmp"<no-image>\t"
328 else
329 tmp=$tmp$image"\t"
330 fi
331 if [ -z $tag ]; then
332 echo -e $RED"\$"$5" not set in test_env"$ERED
333 ((IMAGE_ERR++))
334 echo ""
335 tmp=$tmp"<no-tag>\t"
336 else
337 tmp=$tmp$tag
338 fi
339 echo -e "$tmp" >> $image_list_file
340 #Export the env var
341 export "${3}"=$image":"$tag
342
343 #echo " Configured image for ${1} (script start arg=${2}): "$image":"$tag
344}
345
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200346
347#Check if app local image shall override remote image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200348# Possible IDs for local image override: PA, CP, SDNC, RICSIM, ECS
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200349__check_image_local_override() {
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200350 for im in $USE_LOCAL_IMAGES; do
351 if [ "$1" == "$im" ]; then
352 return 1
353 fi
354 done
355 return 0
356}
357
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200358# Check if app uses image included in this test run
359# Returns 0 if image is included, 1 if not
360# Possible IDs for image inclusion: CBS, CONSUL, CP, CR, ECS, MR, PA, PRODSTUB, RICSIM, SDNC
361__check_included_image() {
362 for im in $INCLUDED_IMAGES; do
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200363 if [ "$1" == "$im" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200364 return 0
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200365 fi
366 done
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200367 return 1
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200368}
369
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100370# Check that image env setting are available
371echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200372
373if [ $START_ARG == "local" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100374
375 #Local agent image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200376 __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 +0100377
378 #Local Control Panel image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200379 __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 +0100380
381 #Local SNDC image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200382 __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 +0100383
384 #Local ric sim image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200385 __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 +0100386
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200387elif [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100388
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200389 __check_image_local_override 'PA'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200390 if [ $? -eq 0 ]; then
391 #Remote agent image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200392 __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 +0200393 else
394 #Local agent image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200395 __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 +0200396 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100397
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200398 __check_image_local_override 'CP'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200399 if [ $? -eq 0 ]; then
400 #Remote Control Panel image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200401 __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 +0200402 else
403 #Local Control Panel image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200404 __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 +0200405 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100406
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200407 __check_image_local_override 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200408 if [ $? -eq 0 ]; then
409 #Remote SDNC image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200410 __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 +0200411 else
412 #Local SNDC image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200413 __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 +0200414 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100415
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200416 __check_image_local_override 'RICSIM'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200417 if [ $? -eq 0 ]; then
418 #Remote ric sim image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200419 __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 +0200420 else
421 #Local ric sim image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200422 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG" RICSIM
423 fi
424
425 __check_image_local_override 'ECS'
426 if [ $? -eq 0 ]; then
427 #Remote ecs image
428 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_REMOTE_IMAGE" "ECS_REMOTE_IMAGE_TAG" ECS
429 else
430 #Local ecs image
431 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_LOCAL_IMAGE" "ECS_LOCAL_IMAGE_TAG" ECS
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200432 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100433
434else
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200435 #Should never get here....
436 echo "Unknow args: "$@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100437 exit 1
YongchaoWu9a84f512019-12-16 22:54:11 +0100438fi
439
YongchaoWu9a84f512019-12-16 22:54:11 +0100440
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100441# 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 +0200442__check_image_var " Message Router" $START_ARG "MRSTUB_IMAGE" "MRSTUB_LOCAL_IMAGE" "MRSTUB_LOCAL_IMAGE_TAG" MR
443__check_image_var " Callback Receiver" $START_ARG "CR_IMAGE" "CR_LOCAL_IMAGE" "CR_LOCAL_IMAGE_TAG" CR
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200444__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 +0200445__check_image_var " Consul" $START_ARG "CONSUL_IMAGE" "CONSUL_REMOTE_IMAGE" "CONSUL_REMOTE_IMAGE_TAG" CONSUL
446__check_image_var " CBS" $START_ARG "CBS_IMAGE" "CBS_REMOTE_IMAGE" "CBS_REMOTE_IMAGE_TAG" CBS
447__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 +0100448
449#Errors in image setting - exit
450if [ $IMAGE_ERR -ne 0 ]; then
451 exit 1
452fi
453
454#Print a tables of the image settings
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200455echo -e $BOLD"Images configured for start arg: "$START $EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100456column -t -s $'\t' $image_list_file
457
YongchaoWuf309b1b2020-01-22 13:24:48 +0100458echo ""
459
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100460
461#Set the SIM_GROUP var
462echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
463if [ -z "$SIM_GROUP" ]; then
464 SIM_GROUP=$PWD/../simulator-group
465 if [ ! -d $SIM_GROUP ]; then
466 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
467 echo -e $RED"Please set the SIM_GROUP manually in the test_env.sh"$ERED
468 exit 1
469 else
470 echo " SIM_GROUP auto set to: " $SIM_GROUP
471 fi
472elif [ $SIM_GROUP = *simulator_group ]; then
473 echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check common/test_env.sh"$ERED
474 exit 1
475else
476 echo " SIM_GROUP env var already set to: " $SIM_GROUP
maximesson28ee8a52020-03-17 09:32:03 +0100477fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100478
479echo ""
480
481#Temp var to check for image pull errors
482IMAGE_ERR=0
483
484#Function to check if image exist and stop+remove the container+pull new images as needed
485#args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
486__check_and_pull_image() {
487
488 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
489 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
490 tmp_im=$(docker images --format $format_string ${4})
491
492 if [ $1 == "local" ]; then
493 if [ -z "$tmp_im" ]; then
494 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
495 ((IMAGE_ERR++))
496 return 1
497 else
498 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
499 fi
500 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
501 if [ $1 == "remote-remove" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200502 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100503 tmp="$(docker ps -aq --filter name=${3})"
504 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200505 docker stop $tmp &> ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100506 if [ $? -ne 0 ]; then
507 ((IMAGE_ERR++))
508 echo ""
509 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200510 cat ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100511 return 1
512 fi
513 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200514 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100515 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
516 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200517 docker rm $tmp &> ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100518 if [ $? -ne 0 ]; then
519 ((IMAGE_ERR++))
520 echo ""
521 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200522 cat ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100523 return 1
524 fi
525 fi
526 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200527 echo -ne " Removing image - ${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100528 tmp="$(docker images -q ${4})" &> /dev/null
529 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200530 docker rmi --force $4 &> ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100531 if [ $? -ne 0 ]; then
532 ((IMAGE_ERR++))
533 echo ""
534 echo -e $RED" Image could not be removed - try manual removal of the image"$ERED
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200535 cat ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100536 return 1
537 fi
538 echo -e " Removing image - "$GREEN"removed"$EGREEN
539 else
540 echo -e " Removing image - "$GREEN"image not in repository"$EGREEN
541 fi
542 tmp_im=""
543 fi
544 if [ -z "$tmp_im" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200545 echo -ne " Pulling image${SAMELINE}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200546 docker pull $4 &> ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100547 tmp_im=$(docker images ${4} | grep -v REPOSITORY)
548 if [ -z "$tmp_im" ]; then
549 echo ""
550 echo -e " Pulling image -$RED could not be pulled"$ERED
551 ((IMAGE_ERR++))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200552 cat ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100553 return 1
554 fi
555 echo -e " Pulling image -$GREEN Pulled $EGREEN"
556 else
557 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
558 fi
559 fi
560 return 0
561}
562
563
564echo -e $BOLD"Pulling configured images, if needed"$EBOLD
565
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200566__check_included_image 'PA'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200567if [ $? -eq 0 ]; then
568 START_ARG_MOD=$START_ARG
569 __check_image_local_override 'PA'
570 if [ $? -eq 1 ]; then
571 START_ARG_MOD="local"
572 fi
573 app="Policy Agent"; __check_and_pull_image $START_ARG_MOD "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
574else
575 echo -e $YELLOW" Excluding PA image from image check/pull"$EYELLOW
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200576fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100577
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200578__check_included_image 'ECS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200579if [ $? -eq 0 ]; then
580 START_ARG_MOD=$START_ARG
581 __check_image_local_override 'ECS'
582 if [ $? -eq 1 ]; then
583 START_ARG_MOD="local"
584 fi
585 app="ECS"; __check_and_pull_image $START_ARG_MOD "$app" $ECS_APP_NAME $ECS_IMAGE
586else
587 echo -e $YELLOW" Excluding ECS image from image check/pull"$EYELLOW
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200588fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200589
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200590__check_included_image 'CP'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200591if [ $? -eq 0 ]; then
592 START_ARG_MOD=$START_ARG
593 __check_image_local_override 'CP'
594 if [ $? -eq 1 ]; then
595 START_ARG_MOD="local"
596 fi
597 app="Non-RT RIC Control Panel"; __check_and_pull_image $START_ARG_MOD "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
598else
599 echo -e $YELLOW" Excluding Non-RT RIC Control Panel image from image check/pull"$EYELLOW
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200600fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100601
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200602__check_included_image 'RICSIM'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200603if [ $? -eq 0 ]; then
604 START_ARG_MOD=$START_ARG
605 __check_image_local_override 'RICSIM'
606 if [ $? -eq 1 ]; then
607 START_ARG_MOD="local"
608 fi
609 app="Near-RT RIC Simulator"; __check_and_pull_image $START_ARG_MOD "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
610else
611 echo -e $YELLOW" Excluding Near-RT RIC Simulator image from image check/pull"$EYELLOW
612fi
613
614
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200615__check_included_image 'CONSUL'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200616if [ $? -eq 0 ]; then
617 app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
618else
619 echo -e $YELLOW" Excluding Consul image from image check/pull"$EYELLOW
620fi
621
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200622__check_included_image 'CBS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200623if [ $? -eq 0 ]; then
624 app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE
625else
626 echo -e $YELLOW" Excluding CBS image from image check/pull"$EYELLOW
627fi
628
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200629__check_included_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200630if [ $? -eq 0 ]; then
631 START_ARG_MOD=$START_ARG
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200632 __check_image_local_override 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200633 if [ $? -eq 1 ]; then
634 START_ARG_MOD="local"
635 fi
636 app="SDNC A1 Controller"; __check_and_pull_image $START_ARG_MOD "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
637 app="SDNC DB"; __check_and_pull_image $START_ARG "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
638else
639 echo -e $YELLOW" Excluding SDNC image and related DB image from image check/pull"$EYELLOW
640fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100641
642#Errors in image setting - exit
643if [ $IMAGE_ERR -ne 0 ]; then
644 echo ""
645 echo "#################################################################################################"
646 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 +0200647 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100648 echo "#################################################################################################"
649 echo ""
650 exit 1
651fi
652
653echo ""
654
655echo -e $BOLD"Building images needed for test"$EBOLD
656
657curdir=$PWD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200658__check_included_image 'MR'
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100659if [ $? -eq 0 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200660 cd $curdir
661 cd ../mrstub
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200662 echo " Building mrstub image: $MRSTUB_LOCAL_IMAGE:$MRSTUB_LOCAL_IMAGE_TAG"
663 docker build -t $MRSTUB_LOCAL_IMAGE . &> .dockererr
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200664 if [ $? -eq 0 ]; then
665 echo -e $GREEN" Build Ok"$EGREEN
666 else
667 echo -e $RED" Build Failed"$ERED
668 ((RES_CONF_FAIL++))
669 cat .dockererr
670 fi
671 cd $curdir
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100672else
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200673 echo -e $YELLOW" Excluding mrstub from image build"$EYELLOW
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100674fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100675
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200676__check_included_image 'CR'
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100677if [ $? -eq 0 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200678 cd ../cr
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200679 echo " Building Callback Receiver image: $CR_LOCAL_IMAGE:$CR_IMAGE_TAG"
680 docker build -t $CR_LOCAL_IMAGE . &> .dockererr
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200681 if [ $? -eq 0 ]; then
682 echo -e $GREEN" Build Ok"$EGREEN
683 else
684 echo -e $RED" Build Failed"$ERED
685 ((RES_CONF_FAIL++))
686 cat .dockererr
687 fi
688 cd $curdir
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100689else
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200690 echo -e $YELLOW" Excluding Callback Receiver from image build"$EYELLOW
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100691fi
YongchaoWuf309b1b2020-01-22 13:24:48 +0100692
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200693__check_included_image 'PRODSTUB'
694if [ $? -eq 0 ]; then
695 cd ../prodstub
696 echo " Building Producer stub image: $PROD_STUB_LOCAL_IMAGE:$PROD_STUB_LOCAL_IMAGE_TAG"
697 docker build -t $PROD_STUB_LOCAL_IMAGE . &> .dockererr
698 if [ $? -eq 0 ]; then
699 echo -e $GREEN" Build Ok"$EGREEN
700 else
701 echo -e $RED" Build Failed"$ERED
702 ((RES_CONF_FAIL++))
703 cat .dockererr
704 fi
705 cd $curdir
706else
707 echo -e $YELLOW" Excluding Producer stub from image build"$EYELLOW
708fi
709
YongchaoWuf309b1b2020-01-22 13:24:48 +0100710echo ""
711
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100712# Create a table of the images used in the script
713echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
714
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200715docker_tmp_file=./tmp/.docker-images-table
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200716format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\\t{{.CreatedAt}}"
717echo -e " Application\tRepository\tTag\tCreated since\tSize\tCreated at" > $docker_tmp_file
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200718__check_included_image 'PA'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200719if [ $? -eq 0 ]; then
720 echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
721fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200722__check_included_image 'ECS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200723if [ $? -eq 0 ]; then
724 echo -e " ECS\t$(docker images --format $format_string $ECS_IMAGE)" >> $docker_tmp_file
725fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200726__check_included_image 'CP'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200727if [ $? -eq 0 ]; then
728 echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
729fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200730__check_included_image 'RICSIM'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200731if [ $? -eq 0 ]; then
732 echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
733fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200734__check_included_image 'MR'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200735if [ $? -eq 0 ]; then
736 echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
737fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200738__check_included_image 'CR'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200739if [ $? -eq 0 ]; then
740 echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
741fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200742__check_included_image 'PRODSTUB'
743if [ $? -eq 0 ]; then
744 echo -e " Produccer stub\t$(docker images --format $format_string $PROD_STUB_IMAGE)" >> $docker_tmp_file
745fi
746__check_included_image 'CONSUL'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200747if [ $? -eq 0 ]; then
748 echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
749fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200750__check_included_image 'CBS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200751if [ $? -eq 0 ]; then
752 echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
753fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200754__check_included_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200755if [ $? -eq 0 ]; then
756 echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
757 echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
758fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100759
760column -t -s $'\t' $docker_tmp_file
761
YongchaoWuf309b1b2020-01-22 13:24:48 +0100762echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +0100763
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100764echo -e $BOLD"======================================================="$EBOLD
765echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
766echo -e $BOLD"======================================================="$EBOLD
767echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +0100768
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100769# Function to print the test result, shall be the last cmd in a test script
770# args: -
771# (Function for test scripts)
772print_result() {
YongchaoWu9a84f512019-12-16 22:54:11 +0100773
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100774 TCTEST_END=$SECONDS
775 duration=$((TCTEST_END-TCTEST_START))
YongchaoWu9a84f512019-12-16 22:54:11 +0100776
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100777 echo "-------------------------------------------------------------------------------------------------"
778 echo "------------------------------------- Test case: "$ATC
779 echo "------------------------------------- Ended: "$(date)
780 echo "-------------------------------------------------------------------------------------------------"
781 echo "-- Description: "$TC_ONELINE_DESCR
782 echo "-- Execution time: " $duration " seconds"
783 echo "-------------------------------------------------------------------------------------------------"
784 echo "------------------------------------- RESULTS"
YongchaoWu4e489b02020-02-24 09:18:16 +0100785 echo ""
YongchaoWu4e489b02020-02-24 09:18:16 +0100786
YongchaoWu21f17bb2020-03-05 12:44:08 +0100787
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200788 if [ $RES_DEVIATION -gt 0 ]; then
789 echo "Test case deviations"
790 echo "===================================="
791 cat $DEVIATION_FILE
792 fi
793 echo ""
794 echo "Timer measurement in the test script"
795 echo "===================================="
796 column -t -s $'\t' $TIMER_MEASUREMENTS
797 echo ""
798
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100799 total=$((RES_PASS+RES_FAIL))
800 if [ $RES_TEST -eq 0 ]; then
801 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
802 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
803 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
804 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
805 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
806 elif [ $total != $RES_TEST ]; then
807 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
808 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
809 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
810 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
811 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
812 elif [ $RES_CONF_FAIL -ne 0 ]; then
813 echo -e "\033[1mOne or more configure regest has failed. Check the script log....\033[0m"
814 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
815 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
816 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
817 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
818 elif [ $RES_PASS = $RES_TEST ]; then
819 echo -e "All tests \033[32m\033[1mPASS\033[0m"
820 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
821 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
822 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
823 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
824 echo ""
YongchaoWu21f17bb2020-03-05 12:44:08 +0100825
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100826 # Update test suite counter
827 if [ -f .tmp_tcsuite_pass_ctr ]; then
828 tmpval=$(< .tmp_tcsuite_pass_ctr)
829 ((tmpval++))
830 echo $tmpval > .tmp_tcsuite_pass_ctr
831 fi
832 if [ -f .tmp_tcsuite_pass ]; then
833 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
834 fi
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200835 #Create file with OK exit code
836 echo "0" > "$PWD/.result$ATC.txt"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100837 else
838 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
839 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
840 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
841 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
842 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
843 echo ""
844 # Update test suite counter
845 if [ -f .tmp_tcsuite_fail_ctr ]; then
846 tmpval=$(< .tmp_tcsuite_fail_ctr)
847 ((tmpval++))
848 echo $tmpval > .tmp_tcsuite_fail_ctr
849 fi
850 if [ -f .tmp_tcsuite_fail ]; then
851 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
852 fi
YongchaoWu21f17bb2020-03-05 12:44:08 +0100853 fi
YongchaoWu21f17bb2020-03-05 12:44:08 +0100854
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100855 echo "++++ Number of tests: "$RES_TEST
856 echo "++++ Number of passed tests: "$RES_PASS
857 echo "++++ Number of failed tests: "$RES_FAIL
YongchaoWu4e489b02020-02-24 09:18:16 +0100858 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100859 echo "++++ Number of failed configs: "$RES_CONF_FAIL
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200860 echo ""
861 echo "++++ Number of test case deviations: "$RES_DEVIATION
862 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100863 echo "------------------------------------- Test case complete ---------------------------------"
864 echo "-------------------------------------------------------------------------------------------------"
YongchaoWu9a84f512019-12-16 22:54:11 +0100865 echo ""
866}
867
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100868#####################################################################
869###### Functions for start, configuring, stoping, cleaning etc ######
870#####################################################################
YongchaoWu21f17bb2020-03-05 12:44:08 +0100871
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200872# Start timer for time measurement
873# args - (any args will be printed though)
874start_timer() {
875 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
876 TC_TIMER=$SECONDS
877 echo " Timer started"
878}
879
880# Print the value of the time (in seconds)
881# args - <timer message to print> - timer value and message will be printed both on screen
882# and in the timer measurement report
883print_timer() {
884 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
885 if [ $# -lt 1 ]; then
886 ((RES_CONF_FAIL++))
887 __print_err "need 1 or more args, <timer message to print>" $@
888 exit 1
889 fi
890 duration=$(($SECONDS-$TC_TIMER))
891 if [ $duration -eq 0 ]; then
892 duration="<1 second"
893 else
894 duration=$duration" seconds"
895 fi
896 echo " Timer duration :" $duration
897
898 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
899}
900
901# Print the value of the time (in seconds) and reset the timer
902# args - <timer message to print> - timer value and message will be printed both on screen
903# and in the timer measurement report
904print_and_reset_timer() {
905 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
906 if [ $# -lt 1 ]; then
907 ((RES_CONF_FAIL++))
908 __print_err "need 1 or more args, <timer message to print>" $@
909 exit 1
910 fi
911 duration=$(($SECONDS-$TC_TIMER))" seconds"
912 if [ $duration -eq 0 ]; then
913 duration="<1 second"
914 else
915 duration=$duration" seconds"
916 fi
917 echo " Timer duration :" $duration
918 TC_TIMER=$SECONDS
919 echo " Timer reset"
920
921 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
922
923}
924# Print info about a deviations from intended tests
925# Each deviation counted is also printed in the testreport
926# args <deviation message to print>
927deviation() {
928 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
929 if [ $# -lt 1 ]; then
930 ((RES_CONF_FAIL++))
931 __print_err "need 1 or more args, <deviation message to print>" $@
932 exit 1
933 fi
934 ((RES_DEVIATION++))
935 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
936 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
937 echo ""
938}
YongchaoWu21f17bb2020-03-05 12:44:08 +0100939
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200940# Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
941__check_stop_at_error() {
942 if [ $STOP_AT_ERROR -eq 1 ]; then
943 echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
944 store_logs "STOP_AT_ERROR"
945 exit 1
946 fi
947 return 0
948}
949
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200950# Check if app name var is set. If so return the app name otherwise return "NOTSET"
951__check_app_name() {
952 if [ $# -eq 1 ]; then
953 echo $1
954 else
955 echo "NOTSET"
956 fi
957}
958
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100959# Stop and remove all containers
960# args: -
961# (Function for test scripts)
YongchaoWu9a84f512019-12-16 22:54:11 +0100962clean_containers() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100963
964 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
965
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200966 CONTAINTER_NAMES=("Policy Agent " $(__check_app_name $POLICY_AGENT_APP_NAME)\
967 "ECS " $(__check_app_name $ECS_APP_NAME)\
968 "Non-RT RIC Simulator(s)" $(__check_app_name $RIC_SIM_PREFIX)\
969 "Message Router " $(__check_app_name $MR_APP_NAME)\
970 "Callback Receiver " $(__check_app_name $CR_APP_NAME)\
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200971 "Producer stub " $(__check_app_name $PROD_STUB_APP_NAME)\
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200972 "Control Panel " $(__check_app_name $CONTROL_PANEL_APP_NAME)\
973 "SDNC A1 Controller " $(__check_app_name $SDNC_APP_NAME)\
974 "SDNC DB " $(__check_app_name $SDNC_DB_APP_NAME)\
975 "CBS " $(__check_app_name $CBS_APP_NAME)\
976 "Consul " $(__check_app_name $CONSUL_APP_NAME))
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100977
978 nw=0 # Calc max width of container name, to make a nice table
979 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200980
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100981 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
982 nw=${#CONTAINTER_NAMES[i]}
983 fi
984 done
985
986 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
987 APP="${CONTAINTER_NAMES[i]}"
988 CONTR="${CONTAINTER_NAMES[i+1]}"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200989 if [ $CONTR != "NOTSET" ]; then
990 for((w=${#CONTR}; w<$nw; w=w+1)); do
991 CONTR="$CONTR "
992 done
993 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
994 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
995 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
996 docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
997 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
998 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100999 done
1000
YongchaoWu9a84f512019-12-16 22:54:11 +01001001 echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001002
1003 echo -e $BOLD" Removing docker network"$EBOLD
1004 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
1005 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001006 docker network rm $DOCKER_SIM_NWNAME | indent2
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001007 if [ $? -ne 0 ]; then
1008 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
1009 exit 1
1010 fi
1011 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001012 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001013
1014 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001015 docker network prune --force | indent2
1016 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001017
1018 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001019 docker volume prune --force | indent2
1020 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001021
1022 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
1023 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001024 echo -e "$GREEN Done$EGREEN"
1025 echo ""
BjornMagnussonXAad047782020-06-08 15:54:11 +02001026
1027 CONTRS=$(docker ps | awk '$1 != "CONTAINER" { n++ }; END { print n+0 }')
1028 if [ $? -eq 0 ]; then
1029 if [ $CONTRS -ne 0 ]; then
1030 echo -e $RED"Containers running, may cause distubance to the test case"$ERED
1031 docker ps -a
1032 fi
1033 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001034}
1035
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001036# Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
1037# args: -
1038# (Function for test scripts)
1039auto_clean_containers() {
1040 echo
1041 if [ "$AUTO_CLEAN" == "auto" ]; then
1042 echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
1043 clean_containers
YongchaoWu9a84f512019-12-16 22:54:11 +01001044 fi
1045}
1046
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001047# Function to sleep a test case for a numner of seconds. Prints the optional text args as info
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001048# args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001049# (Function for test scripts)
1050sleep_wait() {
YongchaoWu9a84f512019-12-16 22:54:11 +01001051
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001052 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1053 if [ $# -lt 1 ]; then
1054 ((RES_CONF_FAIL++))
1055 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
1056 exit 1
1057 fi
1058 #echo "---- Sleep for " $1 " seconds ---- "$2
1059 start=$SECONDS
1060 duration=$((SECONDS-start))
1061 while [ $duration -lt $1 ]; do
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001062 echo -ne " Slept for ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001063 sleep 1
1064 duration=$((SECONDS-start))
1065 done
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001066 echo -ne " Slept for ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001067 echo ""
1068}
1069
1070# Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
1071# Not to be called from the test script itself.
1072__print_err() {
1073 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
1074 if [ $# -gt 1 ]; then
1075 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
1076 fi
1077}
1078
1079
1080# Helper function to get a the port of a specific ric simulatpor
1081# args: <ric-id>
1082# (Not for test scripts)
1083__find_sim_port() {
1084 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
ecaiyanlinux99a769b2020-05-15 13:58:02 +02001085 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
1086 res=$(eval $cmdstr)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001087 if [[ "$res" =~ ^[0-9]+$ ]]; then
1088 echo $res
1089 else
1090 echo "0"
1091 fi
1092}
1093
1094# Function to create the docker network for the test
1095# Not to be called from the test script itself.
1096__create_docker_network() {
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001097 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001098 if [ $? -ne 0 ]; then
1099 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
1100 return 1
1101 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001102 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001103 echo -e " Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
1104 docker network create $DOCKER_SIM_NWNAME | indent2
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001105 if [ $? -ne 0 ]; then
1106 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
1107 return 1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001108 else
1109 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001110 fi
1111 else
1112 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
1113 fi
1114}
1115
1116# Check if container is started by calling url on localhost using a port, expects response code 2XX
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001117# args: <container-name> <port> <url> https|https
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001118# Not to be called from the test script itself.
1119__check_container_start() {
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001120 paramError=0
1121 if [ $# -ne 4 ]; then
1122 paramError=1
1123 elif [ $4 != "http" ] && [ $4 != "https" ]; then
1124 paramError=1
1125 fi
1126 if [ $paramError -ne 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001127 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001128 __print_err "need 3 args, <container-name> <port> <url> https|https" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001129 return 1
1130 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001131 echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
YongchaoWu9a84f512019-12-16 22:54:11 +01001132 appname=$1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001133 localport=$2
1134 url=$3
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001135 if [[ $appname != "STANDALONE_"* ]] ; then
1136 app_started=0
1137 for i in {1..10}; do
1138 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
1139 echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
1140 app_started=1
1141 break
1142 else
1143 sleep $i
1144 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001145 done
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001146 if [ $app_started -eq 0 ]; then
1147 ((RES_CONF_FAIL++))
1148 echo ""
1149 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
1150 return 1
1151 fi
1152 if [ $localport -eq 0 ]; then
1153 while [ $localport -eq 0 ]; do
1154 echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
1155 localport=$(__find_sim_port $appname)
1156 sleep 1
1157 echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
1158 done
1159 echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
1160 echo ""
1161 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001162 fi
1163
1164 pa_st=false
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001165 echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001166 TSTART=$SECONDS
1167 for i in {1..50}; do
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001168 if [ $4 == "https" ]; then
1169 result="$(__do_curl "-k https://localhost:"${localport}${url})"
1170 else
1171 result="$(__do_curl $LOCALHOST${localport}${url})"
1172 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001173 if [ $? -eq 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001174 if [ ${#result} -gt 15 ]; then
1175 #If response is too long, truncate
1176 result="...response text too long, omitted"
1177 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001178 echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001179 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 +01001180 pa_st=true
1181 break
1182 else
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001183 TS_TMP=$SECONDS
1184 while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
1185 echo -ne " Waiting for container ${appname} service status...retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
1186 sleep 1
1187 done
YongchaoWu9a84f512019-12-16 22:54:11 +01001188 fi
1189 done
1190
1191 if [ "$pa_st" = "false" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001192 ((RES_CONF_FAIL++))
1193 echo -e $RED" Container ${appname} did not respond to service status"$ERED
1194 return 0
1195 fi
1196
1197 echo ""
1198 return 0
1199}
1200
1201
1202# Function to start a container and wait until it responds on the given port and url.
1203#args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
1204__start_container() {
1205
1206 variableArgCount=$(($#-2))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001207 if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001208 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001209 __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 +01001210 exit 1
1211 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001212
1213 __create_docker_network
1214
1215 curdir=$PWD
1216 cd $SIM_GROUP
1217 cd $1
1218
1219 if [ "$2" == "NODOCKERARGS" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001220 docker-compose up -d &> .dockererr
1221 if [ $? -ne 0 ]; then
1222 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1223 cat .dockererr
1224 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001225 elif [ "$2" == "STANDALONE" ]; then
1226 echo "Skipping docker-compose"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001227 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001228 docker-compose up -d $2 &> .dockererr
1229 if [ $? -ne 0 ]; then
1230 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1231 cat .dockererr
1232 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001233 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001234 app_prefix=""
1235 if [ "$2" == "STANDALONE" ]; then
1236 app_prefix="STANDALONE_"
1237 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001238 shift; shift;
1239 cntr=0
1240 while [ $cntr -lt $variableArgCount ]; do
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001241 app=$app_prefix$1; shift;
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001242 port=$1; shift;
1243 url=$1; shift;
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001244 httpx=$1; shift;
1245 let cntr=cntr+4
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001246
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001247 __check_container_start "$app" "$port" "$url" $httpx
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001248 done
1249
1250 cd $curdir
1251 echo ""
1252 return 0
YongchaoWu9a84f512019-12-16 22:54:11 +01001253}
1254
BjornMagnussonXAad047782020-06-08 15:54:11 +02001255# Generate a UUID to use as prefix for policy ids
1256generate_uuid() {
1257 UUID=$(python3 -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
1258 #Reduce length to make space for serial id, us 'a' as marker where the serial id is added
1259 UUID=${UUID:0:${#UUID}-4}"a"
1260}
1261
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001262####################
1263### Consul functions
1264####################
1265
1266# Function to load config from a file into consul for the Policy Agent
1267# arg: <json-config-file>
1268# (Function for test scripts)
1269consul_config_app() {
1270
1271 echo -e $BOLD"Configuring Consul"$EBOLD
1272
1273 if [ $# -ne 1 ]; then
1274 ((RES_CONF_FAIL++))
1275 __print_err "need one arg, <json-config-file>" $@
1276 exit 1
1277 fi
1278
1279 echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1
1280
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001281 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
1282 result=$(__do_curl "$curlString")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001283 if [ $? -ne 0 ]; then
1284 echo -e $RED" FAIL - json config could not be loaded to consul" $ERED
1285 ((RES_CONF_FAIL++))
1286 return 1
1287 fi
1288 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001289 echo $body > "./tmp/.output"$1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001290
1291 if [ $? -ne 0 ]; then
1292 echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED
1293 ((RES_CONF_FAIL++))
1294 return 1
1295 else
1296 targetJson=$(< $1)
1297 targetJson="{\"config\":"$targetJson"}"
1298 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001299 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001300 if [ $res -ne 0 ]; then
1301 echo -e $RED" FAIL - policy json config read from consul/cbs is not equal to the intended json config...." $ERED
1302 ((RES_CONF_FAIL++))
1303 return 1
1304 else
1305 echo -e $GREEN" Config loaded ok to consul"$EGREEN
1306 fi
1307 fi
1308
1309 echo ""
1310
1311}
1312
1313# Function to perpare the consul configuration according to the current simulator configuration
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001314# args: SDNC|NOSDNC <output-file>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001315# (Function for test scripts)
1316prepare_consul_config() {
1317 echo -e $BOLD"Prepare Consul config"$EBOLD
1318
1319 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
1320
1321 if [ $# != 2 ]; then
1322 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001323 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001324 exit 1
1325 fi
1326
1327 if [ $1 == "SDNC" ]; then
1328 echo -e " Config$BOLD including SDNC$EBOLD configuration"
1329 elif [ $1 == "NOSDNC" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001330 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001331 else
1332 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001333 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001334 exit 1
1335 fi
1336
1337 config_json="\n {"
1338 if [ $1 == "SDNC" ]; then
1339 config_json=$config_json"\n \"controller\": ["
1340 config_json=$config_json"\n {"
1341 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001342 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1343 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://$SDNC_APP_NAME:$SDNC_PORT\","
1344 else
1345 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://localhost:$SDNC_LOCAL_PORT\","
1346 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001347 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
1348 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
1349 config_json=$config_json"\n }"
1350 config_json=$config_json"\n ],"
1351 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001352
1353 config_json=$config_json"\n \"streams_publishes\": {"
1354 config_json=$config_json"\n \"dmaap_publisher\": {"
1355 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1356 config_json=$config_json"\n \"dmaap_info\": {"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001357 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1358 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_WRITE_URL\""
1359 else
1360 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_WRITE_URL\""
1361 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001362 config_json=$config_json"\n }"
1363 config_json=$config_json"\n }"
1364 config_json=$config_json"\n },"
1365 config_json=$config_json"\n \"streams_subscribes\": {"
1366 config_json=$config_json"\n \"dmaap_subscriber\": {"
1367 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1368 config_json=$config_json"\n \"dmaap_info\": {"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001369 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1370 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_READ_URL\""
1371 else
1372 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_READ_URL\""
1373 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001374 config_json=$config_json"\n }"
1375 config_json=$config_json"\n }"
1376 config_json=$config_json"\n },"
1377
1378 config_json=$config_json"\n \"ric\": ["
1379
BjornMagnussonXAad047782020-06-08 15:54:11 +02001380 rics=$(docker ps | grep $RIC_SIM_PREFIX | awk '{print $NF}')
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001381
1382 if [ $? -ne 0 ] || [ -z "$rics" ]; then
1383 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
1384 ((RES_CONF_FAIL++))
1385 return 1
1386 fi
1387
1388 cntr=0
1389 for ric in $rics; do
1390 if [ $cntr -gt 0 ]; then
1391 config_json=$config_json"\n ,"
1392 fi
1393 config_json=$config_json"\n {"
1394 config_json=$config_json"\n \"name\": \"$ric\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001395 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1396 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
1397 else
1398 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://localhost:$(__find_sim_port $ric)\","
1399 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001400 if [ $1 == "SDNC" ]; then
1401 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
1402 fi
1403 config_json=$config_json"\n \"managedElementIds\": ["
1404 config_json=$config_json"\n \"me1_$ric\","
1405 config_json=$config_json"\n \"me2_$ric\""
1406 config_json=$config_json"\n ]"
1407 config_json=$config_json"\n }"
1408 let cntr=cntr+1
1409 done
1410
1411 config_json=$config_json"\n ]"
1412 config_json=$config_json"\n}"
1413
1414
1415 printf "$config_json">$2
1416
1417 echo ""
1418}
1419
1420
1421# Start Consul and CBS
1422# args: -
1423# (Function for test scripts)
1424start_consul_cbs() {
1425
1426 echo -e $BOLD"Starting Consul and CBS"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001427 __check_included_image 'CONSUL'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001428 if [ $? -eq 1 ]; then
1429 echo -e $RED"The Consul image has not been checked for this test run due to arg to the test script"$ERED
1430 echo -e $RED"Consul will not be started"$ERED
1431 exit
1432 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001433 __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" "http" \
1434 "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001435}
1436
1437###########################
1438### RIC Simulator functions
1439###########################
1440
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001441use_simulator_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001442 echo -e "Using $BOLD http $EBOLD towards the simulators"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001443 export RIC_SIM_HTTPX="http"
1444 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1445 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001446 echo ""
1447}
1448
1449use_simulator_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001450 echo -e "Using $BOLD https $EBOLD towards the simulators"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001451 export RIC_SIM_HTTPX="https"
1452 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1453 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001454 echo ""
1455}
1456
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001457# Start one group (ricsim_g1, ricsim_g2 or ricsim_g3) with a number of RIC Simulators using a given A interface
BjornMagnussonXAad047782020-06-08 15:54:11 +02001458# 'ricsim' may be set on command line to other prefix
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001459# args: ricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>
1460# (Function for test scripts)
1461start_ric_simulators() {
1462
1463 echo -e $BOLD"Starting RIC Simulators"$EBOLD
1464
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001465 __check_included_image 'RICSIM'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001466 if [ $? -eq 1 ]; then
1467 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
1468 echo -e $RED"The Near-RT RIC Simulartor(s) will not be started"$ERED
1469 exit
1470 fi
1471
BjornMagnussonXAad047782020-06-08 15:54:11 +02001472 RIC1=$RIC_SIM_PREFIX"_g1"
1473 RIC2=$RIC_SIM_PREFIX"_g2"
1474 RIC3=$RIC_SIM_PREFIX"_g3"
1475
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001476 if [ $# != 3 ]; then
1477 ((RES_CONF_FAIL++))
BjornMagnussonXAad047782020-06-08 15:54:11 +02001478 __print_err "need three args, $RIC1|$RIC2|$RIC3 <count> <interface-id>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001479 exit 1
1480 fi
1481 echo " $2 simulators using basename: $1 on interface: $3"
1482 #Set env var for simulator count and A1 interface vesion for the given group
BjornMagnussonXAad047782020-06-08 15:54:11 +02001483 if [ $1 == "$RIC1" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001484 G1_COUNT=$2
1485 G1_A1_VERSION=$3
BjornMagnussonXAad047782020-06-08 15:54:11 +02001486 elif [ $1 == "$RIC2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001487 G2_COUNT=$2
1488 G2_A1_VERSION=$3
BjornMagnussonXAad047782020-06-08 15:54:11 +02001489 elif [ $1 == "$RIC3" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001490 G3_COUNT=$2
1491 G3_A1_VERSION=$3
1492 else
1493 ((RES_CONF_FAIL++))
BjornMagnussonXAad047782020-06-08 15:54:11 +02001494 __print_err "need three args, $RIC1|$RIC2|$RIC3 <count> <interface-id>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001495 exit 1
1496 fi
1497
1498 # Create .env file to compose project, all ric container will get this prefix
1499 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
1500
1501 export G1_A1_VERSION
1502 export G2_A1_VERSION
1503 export G3_A1_VERSION
1504
1505 docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT"
1506 app_data=""
1507 cntr=1
1508 while [ $cntr -le $2 ]; do
1509 app=$1"_"$cntr
1510 port=0
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001511 app_data="$app_data $app $port / "$RIC_SIM_HTTPX
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001512 let cntr=cntr+1
1513 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001514 __start_container ric "$docker_args" $app_data
1515
1516}
1517
1518###########################
1519### Control Panel functions
1520###########################
1521
1522# Start the Control Panel container
1523# args: -
1524# (Function for test scripts)
1525start_control_panel() {
1526
1527 echo -e $BOLD"Starting Control Panel"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001528 __check_included_image 'CP'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001529 if [ $? -eq 1 ]; then
1530 echo -e $RED"The Control Panel image has not been checked for this test run due to arg to the test script"$ERED
1531 echo -e $RED"The Control Panel will not be started"$ERED
1532 exit
1533 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001534 __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001535
1536}
1537
1538##################
1539### SDNC functions
1540##################
1541
1542# Start the SDNC A1 Controller
1543# args: -
1544# (Function for test scripts)
1545start_sdnc() {
1546
1547 echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
1548
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001549 __check_included_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001550 if [ $? -eq 1 ]; then
1551 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
1552 echo -e $RED"SDNC will not be started"$ERED
1553 exit
1554 fi
1555
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001556 __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT $SDNC_ALIVE_URL "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001557
1558}
1559
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001560use_sdnc_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001561 echo -e "Using $BOLD http $EBOLD towards SDNC"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001562 export SDNC_HTTPX="http"
1563 export SDNC_PORT=$SDNC_INTERNAL_PORT
1564 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT
1565 echo ""
1566}
1567
1568use_sdnc_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001569 echo -e "Using $BOLD https $EBOLD towards SDNC"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001570 export SDNC_HTTPX="https"
1571 export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT
1572 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT
1573 echo ""
1574}
1575
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001576#####################
1577### MR stub functions
1578#####################
1579
1580# Start the Message Router stub interface in the simulator group
1581# args: -
1582# (Function for test scripts)
1583start_mr() {
1584
1585 echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001586 __check_included_image 'MR'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001587 if [ $? -eq 1 ]; then
1588 echo -e $RED"The Message Router image has not been checked for this test run due to arg to the test script"$ERED
1589 echo -e $RED"The Message Router will not be started"$ERED
1590 exit
1591 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001592 export MR_CERT_MOUNT_DIR="./cert"
1593 __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001594}
1595
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001596use_mr_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001597 echo -e "Using $BOLD http $EBOLD towards MR"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001598 export MR_HTTPX="http"
1599 export MR_PORT=$MR_INTERNAL_PORT
1600 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT
1601 echo ""
1602}
1603
1604use_mr_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001605 echo -e "Using $BOLD https $EBOLD towards MR"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001606 export MR_HTTPX="https"
1607 export MR_PORT=$MR_INTERNAL_SECURE_PORT
1608 export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT
1609 echo ""
1610}
1611
1612
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001613################
1614### CR functions
1615################
1616
1617# Start the Callback reciver in the simulator group
1618# args: -
1619# (Function for test scripts)
1620start_cr() {
1621
1622 echo -e $BOLD"Starting Callback Receiver"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001623 __check_included_image 'CR'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001624 if [ $? -eq 1 ]; then
1625 echo -e $RED"The Callback Receiver image has not been checked for this test run due to arg to the test script"$ERED
1626 echo -e $RED"The Callback Receiver will not be started"$ERED
1627 exit
1628 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001629 __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001630
1631}
1632
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001633use_cr_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001634 echo -e "Using $BOLD http $EBOLD towards CR"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001635 export CR_HTTPX="http"
1636 export CR_PORT=$CR_INTERNAL_PORT
1637 export CR_LOCAL_PORT=$CR_EXTERNAL_PORT
1638 echo ""
1639}
1640
1641use_cr_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001642 echo -e "Using $BOLD https $EBOLD towards CR"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001643 export CR_HTTPX="https"
1644 export CR_PORT=$CR_INTERNAL_SECURE_PORT
1645 export CR_LOCAL_PORT=$CR_EXTERNAL_SECURE_PORT
1646 echo ""
1647}
1648
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001649###########################
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001650### Producer stub functions
1651###########################
1652
1653# Start the Producer stub in the simulator group
1654# args: -
1655# (Function for test scripts)
1656start_prod_stub() {
1657
1658 echo -e $BOLD"Starting Producer stub"$EBOLD
1659 __check_included_image 'PRODSTUB'
1660 if [ $? -eq 1 ]; then
1661 echo -e $RED"The Producer stub image has not been checked for this test run due to arg to the test script"$ERED
1662 echo -e $RED"The Producer stub will not be started"$ERED
1663 exit
1664 fi
1665 __start_container prodstub NODOCKERARGS $PROD_STUB_APP_NAME $PROD_STUB_EXTERNAL_PORT "/" "http"
1666
1667}
1668
1669use_prod_stub_http() {
1670 echo -e "Using $BOLD http $EBOLD towards Producer stub"
1671 export PROD_STUB_HTTPX="http"
1672 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
1673 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT
1674 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
1675 echo ""
1676}
1677
1678use_prod_stub_https() {
1679 echo -e "Using $BOLD https $EBOLD towards Producer stub"
1680 export PROD_STUB_HTTPX="https"
1681 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_SECURE_PORT
1682 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_SECURE_PORT
1683 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
1684 echo ""
1685}
1686
1687###########################
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001688### Policy Agents functions
1689###########################
1690
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001691# Use an agent on the local machine instead of container
1692use_agent_stand_alone() {
1693 AGENT_STAND_ALONE=1
1694}
1695
1696# Start the policy agent
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001697# args: -
1698# (Function for test scripts)
1699start_policy_agent() {
1700
1701 echo -e $BOLD"Starting Policy Agent"$EBOLD
1702
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001703 if [ $AGENT_STAND_ALONE -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001704 __check_included_image 'PA'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001705 if [ $? -eq 1 ]; then
1706 echo -e $RED"The Policy Agent image has not been checked for this test run due to arg to the test script"$ERED
1707 echo -e $RED"The Policy Agent will not be started"$ERED
1708 exit
1709 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001710 __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1711 else
1712 echo -e $RED"The consul config produced by this test script (filename '<fullpath-to-autotest-dir>.output<file-name>"$ERED
1713 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
1714 echo -e $RED"application.yaml"$ERED
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001715 echo -e $RED"The application jar may need to be built before continuing"$ERED
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001716 echo -e $RED"The agent shall now be running on port $POLICY_AGENT_EXTERNAL_PORT for http"$ERED
1717
1718 read -p "<press any key to continue>"
1719 __start_container policy_agent "STANDALONE" $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1720 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001721
1722}
1723
1724# All calls to the agent will be directed to the agent REST interface from now on
1725# args: -
1726# (Function for test scripts)
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001727use_agent_rest_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001728 echo -e "Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001729 export ADAPTER=$RESTBASE
1730 echo ""
1731}
1732
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001733# All calls to the agent will be directed to the agent REST interface from now on
1734# args: -
1735# (Function for test scripts)
1736use_agent_rest_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001737 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001738 export ADAPTER=$RESTBASE_SECURE
1739 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001740 return 0
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001741}
1742
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001743# All calls to the agent will be directed to the agent dmaap interface over http from now on
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001744# args: -
1745# (Function for test scripts)
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001746use_agent_dmaap_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001747 echo -e "Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001748 export ADAPTER=$DMAAPBASE
1749 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001750 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001751}
1752
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001753# All calls to the agent will be directed to the agent dmaap interface over https from now on
1754# args: -
1755# (Function for test scripts)
1756use_agent_dmaap_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001757 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001758 export ADAPTER=$DMAAPBASE_SECURE
1759 echo ""
1760 return 0
1761}
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001762
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001763# Turn on debug level tracing in the agent
1764# args: -
1765# (Function for test scripts)
1766set_agent_debug() {
1767 echo -e $BOLD"Setting agent debug"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001768 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
1769 result=$(__do_curl "$curlString")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001770 if [ $? -ne 0 ]; then
1771 __print_err "could not set debug mode" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001772 ((RES_CONF_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001773 return 1
1774 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001775 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001776 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001777}
1778
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001779# Turn on trace level tracing in the agent
1780# args: -
1781# (Function for test scripts)
1782set_agent_trace() {
1783 echo -e $BOLD"Setting agent trace"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001784 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
1785 result=$(__do_curl "$curlString")
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001786 if [ $? -ne 0 ]; then
1787 __print_err "could not set trace mode" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001788 ((RES_CONF_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001789 return 1
1790 fi
1791 echo ""
1792 return 0
1793}
1794
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001795# Perform curl retries when making direct call to the agent for the specified http response codes
1796# Speace separated list of http response codes
1797# args: [<response-code>]*
1798use_agent_retries() {
1799 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
1800 AGENT_RETRY_CODES=$@
1801 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001802 return
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001803}
1804
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001805###########################
1806### ECS functions
1807###########################
1808
1809# Start the ECS
1810# args: -
1811# (Function for test scripts)
1812start_ecs() {
1813
1814 echo -e $BOLD"Starting ECS"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001815 __check_included_image 'ECS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001816 if [ $? -eq 1 ]; then
1817 echo -e $RED"The ECS image has not been checked for this test run due to arg to the test script"$ERED
1818 echo -e $RED"ECS will not be started"$ERED
1819 exit
1820 fi
1821 export ECS_CERT_MOUNT_DIR="./cert"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001822 __start_container ecs NODOCKERARGS $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001823}
1824
1825# All calls to ECS will be directed to the ECS REST interface from now on
1826# args: -
1827# (Function for test scripts)
1828use_ecs_rest_http() {
1829 echo -e "Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
1830 export ECS_ADAPTER=$ECS_RESTBASE
1831 echo ""
1832}
1833
1834# All calls to ECS will be directed to the ECS REST interface from now on
1835# args: -
1836# (Function for test scripts)
1837use_ecs_rest_https() {
1838 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
1839 export ECS_ADAPTER=$ECS_RESTBASE_SECURE
1840 echo ""
1841 return 0
1842}
1843
1844# All calls to ECS will be directed to the ECS dmaap interface over http from now on
1845# args: -
1846# (Function for test scripts)
1847use_ecs_dmaap_http() {
1848 echo -e "Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
1849 export ECS_ADAPTER=$ECS_DMAAPBASE
1850 echo ""
1851 return 0
1852}
1853
1854# All calls to ECS will be directed to the ECS dmaap interface over https from now on
1855# args: -
1856# (Function for test scripts)
1857use_ecs_dmaap_https() {
1858 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
1859 export ECS_ADAPTER=$ECS_DMAAPBASE_SECURE
1860 echo ""
1861 return 0
1862}
1863
1864# Turn on debug level tracing in ECS
1865# args: -
1866# (Function for test scripts)
1867set_ecs_debug() {
1868 echo -e $BOLD"Setting ecs debug"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001869 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
1870 result=$(__do_curl "$curlString")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001871 if [ $? -ne 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001872 __print_err "Could not set debug mode" $@
1873 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001874 return 1
1875 fi
1876 echo ""
1877 return 0
1878}
1879
1880# Turn on trace level tracing in ECS
1881# args: -
1882# (Function for test scripts)
1883set_ecs_trace() {
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001884 echo -e $BOLD"Setting ecs trace"$EBOLD
1885 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
1886 result=$(__do_curl "$curlString")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001887 if [ $? -ne 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001888 __print_err "Could not set trace mode" $@
1889 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001890 return 1
1891 fi
1892 echo ""
1893 return 0
1894}
1895
1896# Perform curl retries when making direct call to ECS for the specified http response codes
1897# Speace separated list of http response codes
1898# args: [<response-code>]*
1899use_agent_retries() {
1900 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
1901 ECS_AGENT_RETRY_CODES=$@
1902 echo ""
1903 return
1904}
1905
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001906#################
1907### Log functions
1908#################
1909
1910# Check the agent logs for WARNINGs and ERRORs
1911# args: -
1912# (Function for test scripts)
1913
YongchaoWu9a84f512019-12-16 22:54:11 +01001914check_policy_agent_logs() {
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001915 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
YongchaoWu9a84f512019-12-16 22:54:11 +01001916}
1917
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001918check_ecs_logs() {
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001919 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001920}
1921
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001922check_control_panel_logs() {
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001923 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH WARN ERR
1924}
1925
1926check_sdnc_logs() {
1927 __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
YongchaoWu9a84f512019-12-16 22:54:11 +01001928}
1929
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001930__check_container_logs() {
1931 dispname=$1
1932 appname=$2
1933 logpath=$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001934 warning=$4
1935 error=$5
1936
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001937 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
1938
1939 #tmp=$(docker ps | grep $appname)
1940 tmp=$(docker ps -q --filter name=$appname) #get the container id
1941 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
1942 echo $dispname" is not running, no check made"
1943 return
1944 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001945 foundentries="$(docker exec -t $tmp grep $warning $logpath | wc -l)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001946 if [ $? -ne 0 ];then
1947 echo " Problem to search $appname log $logpath"
1948 else
1949 if [ $foundentries -eq 0 ]; then
1950 echo " No WARN entries found in $appname log $logpath"
1951 else
1952 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
1953 fi
1954 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001955 foundentries="$(docker exec -t $tmp grep $error $logpath | wc -l)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001956 if [ $? -ne 0 ];then
1957 echo " Problem to search $appname log $logpath"
1958 else
1959 if [ $foundentries -eq 0 ]; then
1960 echo " No ERR entries found in $appname log $logpath"
1961 else
1962 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
1963 fi
1964 fi
1965 echo ""
1966}
1967
1968# Store all container logs and other logs in the log dir for the script
1969# Logs are stored with a prefix in case logs should be stored several times during a test
1970# args: <logfile-prefix>
1971# (Function for test scripts)
YongchaoWu9a84f512019-12-16 22:54:11 +01001972store_logs() {
1973 if [ $# != 1 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001974 ((RES_CONF_FAIL++))
1975 __print_err "need one arg, <file-prefix>" $@
YongchaoWu9a84f512019-12-16 22:54:11 +01001976 exit 1
1977 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001978 echo -e $BOLD"Storing all container logs using prefix: "$1$EBOLD
YongchaoWu9a84f512019-12-16 22:54:11 +01001979
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001980 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001981
1982 __check_included_image 'CONSUL'
1983 if [ $? -eq 0 ]; then
1984 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
1985 fi
1986
1987 __check_included_image 'CBS'
1988 if [ $? -eq 0 ]; then
1989 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
1990 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
1991 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
1992 fi
1993
1994 __check_included_image 'PA'
1995 if [ $? -eq 0 ]; then
1996 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
1997 fi
1998
1999 __check_included_image 'ECS'
2000 if [ $? -eq 0 ]; then
2001 docker logs $ECS_APP_NAME > $TESTLOGS/$ATC/$1_ecs.log 2>&1
2002 fi
2003
2004 __check_included_image 'CP'
2005 if [ $? -eq 0 ]; then
2006 docker logs $CONTROL_PANEL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
2007 fi
2008
2009 __check_included_image 'MR'
2010 if [ $? -eq 0 ]; then
2011 docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
2012 fi
2013
2014 __check_included_image 'CR'
2015 if [ $? -eq 0 ]; then
2016 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
2017 fi
2018
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002019 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
2020
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002021 __check_included_image 'SDNC'
2022 if [ $? -eq 0 ]; then
2023 docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
2024 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002025
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002026 __check_included_image 'RICSIM'
2027 if [ $? -eq 0 ]; then
2028 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
2029 for ric in $rics; do
2030 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
2031 done
2032 fi
2033
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002034 echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +01002035}
2036
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002037###############
2038## Generic curl
2039###############
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002040# Generic curl function, assumes all 200-codes are ok
2041# args: <valid-curl-args-including full url>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002042# returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
2043# returns: The return code is 0 for ok and 1 for not ok
YongchaoWu9a84f512019-12-16 22:54:11 +01002044__do_curl() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002045 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002046 curlString="curl -skw %{http_code} $@"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002047 echo " CMD: $curlString" >> $HTTPLOG
2048 res=$($curlString)
2049 echo " RESP: $res" >> $HTTPLOG
YongchaoWu9a84f512019-12-16 22:54:11 +01002050 http_code="${res:${#res}-3}"
2051 if [ ${#res} -eq 3 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002052 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2053 echo "<no-response-from-server>"
2054 return 1
2055 else
2056 echo "X2" >> $HTTPLOG
2057 return 0
2058 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01002059 else
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002060 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
YongchaoWu9a84f512019-12-16 22:54:11 +01002061 echo "<not found, resp:${http_code}>"
2062 return 1
2063 fi
2064 if [ $# -eq 2 ]; then
2065 echo "${res:0:${#res}-3}" | xargs
2066 else
2067 echo "${res:0:${#res}-3}"
2068 fi
2069
2070 return 0
2071 fi
2072}
2073
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002074#######################################
2075### Basic helper function for test cases
2076#######################################
2077
2078# Test a simulator container variable value towards target value using an condition operator with an optional timeout.
2079# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
2080# immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
2081# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
2082# before setting pass or fail depending on the result of comparing variable and target using the operator.
2083# 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.
2084# Not to be called from test script.
2085
2086__var_test() {
2087 checkjsonarraycount=0
2088
2089 if [ $# -eq 6 ]; then
2090 if [[ $3 == "json:"* ]]; then
2091 checkjsonarraycount=1
2092 fi
2093
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02002094 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002095 ((RES_TEST++))
2096 start=$SECONDS
2097 ctr=0
2098 for (( ; ; )); do
2099 if [ $checkjsonarraycount -eq 0 ]; then
2100 result="$(__do_curl $2$3)"
2101 retcode=$?
2102 result=${result//[[:blank:]]/} #Strip blanks
2103 else
2104 path=${3:5}
2105 result="$(__do_curl $2$path)"
2106 retcode=$?
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002107 echo "$result" > ./tmp/.tmp.curl.json
2108 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002109 fi
2110 duration=$((SECONDS-start))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002111 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002112 let ctr=ctr+1
2113 if [ $retcode -ne 0 ]; then
2114 if [ $duration -gt $6 ]; then
2115 ((RES_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002116 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002117 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002118 return
2119 fi
2120 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2121 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002122 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002123 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002124 return
2125 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2126 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002127 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002128 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002129 return
2130 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2131 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002132 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002133 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002134 return
2135 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2136 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002137 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002138 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002139 return
2140 else
2141 if [ $duration -gt $6 ]; then
2142 ((RES_FAIL++))
2143 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002144 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002145 return
2146 fi
2147 fi
2148 sleep 1
2149 done
2150 elif [ $# -eq 5 ]; then
2151 if [[ $3 == "json:"* ]]; then
2152 checkjsonarraycount=1
2153 fi
2154
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002155 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
2156 ((RES_TEST++))
2157 if [ $checkjsonarraycount -eq 0 ]; then
2158 result="$(__do_curl $2$3)"
2159 retcode=$?
2160 result=${result//[[:blank:]]/} #Strip blanks
2161 else
2162 path=${3:5}
2163 result="$(__do_curl $2$path)"
2164 retcode=$?
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002165 echo "$result" > ./tmp/.tmp.curl.json
2166 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002167 fi
2168 if [ $retcode -ne 0 ]; then
2169 ((RES_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002170 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002171 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002172 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2173 ((RES_PASS++))
2174 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002175 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2176 ((RES_PASS++))
2177 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002178 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2179 ((RES_PASS++))
2180 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002181 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2182 ((RES_PASS++))
2183 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002184 else
2185 ((RES_FAIL++))
2186 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002187 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002188 fi
2189 else
2190 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
2191 echo "Got:" $@
2192 exit 1
2193 fi
2194}
2195
2196
2197### Generic test cases for varaible checking
2198
2199# Tests if a variable value in the CR is equal to a target value and and optional timeout.
2200# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2201# equal to the target or not.
2202# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2203# before setting pass or fail depending on if the variable value becomes equal to the target
2204# value or not.
2205# (Function for test scripts)
2206cr_equal() {
2207 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2208 __var_test "CR" "$LOCALHOST$CR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
2209 else
2210 ((RES_CONF_FAIL++))
2211 __print_err "Wrong args to cr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2212 fi
2213}
2214
2215# Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
2216# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2217# equal to the target or not.
2218# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2219# before setting pass or fail depending on if the variable value becomes equal to the target
2220# value or not.
2221# (Function for test scripts)
2222mr_equal() {
2223 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2224 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
2225 else
2226 ((RES_CONF_FAIL++))
2227 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2228 fi
2229}
2230
2231# Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
2232# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2233# greater than the target or not.
2234# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2235# before setting pass or fail depending on if the variable value becomes greater than the target
2236# value or not.
2237# (Function for test scripts)
2238mr_greater() {
2239 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002240 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 ">" $2 $3
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002241 else
2242 ((RES_CONF_FAIL++))
2243 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2244 fi
2245}
2246
2247# Read a variable value from MR sim and send to stdout. Arg: <variable-name>
2248mr_read() {
2249 echo "$(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"
2250}
2251
2252# Print a variable value from the MR stub.
2253# arg: <variable-name>
2254# (Function for test scripts)
2255mr_print() {
2256 if [ $# != 1 ]; then
2257 ((RES_CONF_FAIL++))
2258 __print_err "need one arg, <mr-param>" $@
2259 exit 1
2260 fi
2261 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"$EBOLD
2262}