blob: 3ed51c911b9268f2590b53a1f9c49118fa23e2d5 [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/bin/bash
YongchaoWu9a84f512019-12-16 22:54:11 +01002
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003# ============LICENSE_START===============================================
4# Copyright (C) 2020 Nordix Foundation. All rights reserved.
5# ========================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ============LICENSE_END=================================================
18#
YongchaoWu9a84f512019-12-16 22:54:11 +010019
YongchaoWuffde6eb2020-01-17 13:58:51 +010020# This is a script that contains all the functions needed for auto test
BjornMagnussonXA575869c2020-09-14 21:28:54 +020021# Arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--ricsim-prefix <prefix> ] [ --env-file <environment-filename> ] [--use-local-image <app-nam> [<app-name>]*]
YongchaoWuffde6eb2020-01-17 13:58:51 +010022
BjornMagnussonXA72667f12020-04-24 09:20:18 +020023
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020024# Create a test case id, ATC (Auto Test Case), from the name of the test case script.
25# FTC1.sh -> ATC == FTC1
26ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
27
28#Create result file (containing '1' for error) for this test case
29#Will be replaced with a file containing '0' if all test cases pass
30echo "1" > "$PWD/.result$ATC.txt"
31
BjornMagnussonXA80a92002020-03-19 14:31:06 +010032#Formatting for 'echo' cmd
33BOLD="\033[1m"
34EBOLD="\033[0m"
35RED="\033[31m\033[1m"
36ERED="\033[0m"
37GREEN="\033[32m\033[1m"
38EGREEN="\033[0m"
39YELLOW="\033[33m\033[1m"
40EYELLOW="\033[0m"
BjornMagnussonXA72667f12020-04-24 09:20:18 +020041SAMELINE="\033[0K\r"
42
43tmp=$(which python3)
44if [ $? -ne 0 ] || [ -z tmp ]; then
45 echo -e $RED"python3 is required to run the test environment, pls install"$ERED
46 exit 1
47fi
48tmp=$(which docker)
49if [ $? -ne 0 ] || [ -z tmp ]; then
50 echo -e $RED"docker is required to run the test environment, pls install"$ERED
51 exit 1
52fi
YongchaoWu9a84f512019-12-16 22:54:11 +010053
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020054tmp=$(which docker-compose)
55if [ $? -ne 0 ] || [ -z tmp ]; then
56 echo -e $RED"docker-compose is required to run the test environment, pls install"$ERED
57 exit 1
58fi
59
BjornMagnussonXA80a92002020-03-19 14:31:06 +010060# Just resetting any previous echo formatting...
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020061echo -ne $EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +010062
BjornMagnussonXA575869c2020-09-14 21:28:54 +020063# default test environment variables
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +020064TEST_ENV_VAR_FILE=""
BjornMagnussonXA80a92002020-03-19 14:31:06 +010065
66echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@
67
BjornMagnussonXA80a92002020-03-19 14:31:06 +010068#Localhost constant
69LOCALHOST="http://localhost:"
70
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020071# Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
72ECS_RETRY_CODES=""
73
74# Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
BjornMagnussonXA80a92002020-03-19 14:31:06 +010075AGENT_RETRY_CODES=""
76
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020077# Var to contol if the agent runs in a container (normal = 0) or as application on the local machine ( = 1)
78AGENT_STAND_ALONE=0
79
BjornMagnussonXA80a92002020-03-19 14:31:06 +010080# Var to hold 'auto' in case containers shall be stopped when test case ends
81AUTO_CLEAN=""
YongchaoWu9a84f512019-12-16 22:54:11 +010082
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020083# Var to hold the app names to use local image for when running 'remote' or 'remote-remove'
84USE_LOCAL_IMAGES=""
85
BjornMagnussonXAad047782020-06-08 15:54:11 +020086# List of available apps to override with local image
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
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100131# Save create for current logs
132mkdir -p $TESTLOGS/$ATC/previous
133
134rm $TESTLOGS/$ATC/previous/*.log &> /dev/null
135rm $TESTLOGS/$ATC/previous/*.txt &> /dev/null
136rm $TESTLOGS/$ATC/previous/*.json &> /dev/null
137
138mv $TESTLOGS/$ATC/*.log $TESTLOGS/$ATC/previous &> /dev/null
139mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
140mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
141
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100142# Clear the log dir for the test case
143rm $TESTLOGS/$ATC/*.log &> /dev/null
144rm $TESTLOGS/$ATC/*.txt &> /dev/null
145rm $TESTLOGS/$ATC/*.json &> /dev/null
146
147# Log all output from the test case to a TC log
YongchaoWu9a84f512019-12-16 22:54:11 +0100148TCLOG=$TESTLOGS/$ATC/TC.log
149exec &> >(tee ${TCLOG})
150
151#Variables for counting tests as well as passed and failed tests
152RES_TEST=0
153RES_PASS=0
154RES_FAIL=0
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100155RES_CONF_FAIL=0
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200156RES_DEVIATION=0
157
158#File to keep deviation messages
159DEVIATION_FILE=".tmp_deviations"
160rm $DEVIATION_FILE &> /dev/null
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100161
162#Var for measuring execution time
YongchaoWu9a84f512019-12-16 22:54:11 +0100163TCTEST_START=$SECONDS
164
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200165#File to save timer measurement results
166TIMER_MEASUREMENTS=".timer_measurement.txt"
167echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS
168
169
YongchaoWu9a84f512019-12-16 22:54:11 +0100170echo "-------------------------------------------------------------------------------------------------"
171echo "----------------------------------- Test case: "$ATC
172echo "----------------------------------- Started: "$(date)
173echo "-------------------------------------------------------------------------------------------------"
174echo "-- Description: "$TC_ONELINE_DESCR
175echo "-------------------------------------------------------------------------------------------------"
176echo "----------------------------------- Test case setup -----------------------------------"
177
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200178START_ARG=$1
179paramerror=0
180if [ $# -lt 1 ]; then
181 paramerror=1
182fi
183if [ $paramerror -eq 0 ]; then
184 if [ "$1" != "remote" ] && [ "$1" != "remote-remove" ] && [ "$1" != "local" ]; then
185 paramerror=1
186 else
187 shift;
188 fi
189fi
BjornMagnussonXAad047782020-06-08 15:54:11 +0200190foundparm=0
191while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do
192 foundparm=1
193 if [ $paramerror -eq 0 ]; then
194 if [ "$1" == "auto-clean" ]; then
195 AUTO_CLEAN="auto"
196 echo "Option set - Auto clean at end of test script"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200197 shift;
BjornMagnussonXAad047782020-06-08 15:54:11 +0200198 foundparm=0
199 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200200 fi
BjornMagnussonXAad047782020-06-08 15:54:11 +0200201 if [ $paramerror -eq 0 ]; then
202 if [ "$1" == "--stop-at-error" ]; then
203 STOP_AT_ERROR=1
204 echo "Option set - Stop at first error"
205 shift;
206 foundparm=0
207 fi
208 fi
209 if [ $paramerror -eq 0 ]; then
210 if [ "$1" == "--ricsim-prefix" ]; then
211 shift;
212 RIC_SIM_PREFIX=$1
213 if [ -z "$1" ]; then
214 paramerror=1
215 else
216 echo "Option set - Overriding RIC_SIM_PREFIX with: "$1
217 shift;
218 foundparm=0
219 fi
220 fi
221 fi
222 if [ $paramerror -eq 0 ]; then
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200223 if [ "$1" == "--env-file" ]; then
224 shift;
225 TEST_ENV_VAR_FILE=$1
226 if [ -z "$1" ]; then
227 paramerror=1
228 else
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200229 echo "Option set - Reading test env from: "$1
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200230 shift;
231 foundparm=0
232 fi
233 fi
234 fi
235 if [ $paramerror -eq 0 ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +0200236 if [ "$1" == "--use-local-image" ]; then
237 USE_LOCAL_IMAGES=""
238 shift
239 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
240 USE_LOCAL_IMAGES=$USE_LOCAL_IMAGES" "$1
241 if [[ "$AVAILABLE_LOCAL_IMAGES_OVERRIDE" != *"$1"* ]]; then
242 paramerror=1
243 fi
244 shift;
245 done
246 foundparm=0
247 if [ -z "$USE_LOCAL_IMAGES" ]; then
248 paramerror=1
249 else
250 echo "Option set - Override remote images for app(s):"$USE_LOCAL_IMAGES
251 fi
252 fi
253 fi
254done
255echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200256
BjornMagnussonXAad047782020-06-08 15:54:11 +0200257#Still params left?
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200258if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
259 paramerror=1
260fi
261
262if [ $paramerror -eq 1 ]; then
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200263 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 +0200264 exit 1
265fi
266
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200267# sourcing the selected env variables for the test case
268if [ -f "$TEST_ENV_VAR_FILE" ]; then
269 echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD
270 . $TEST_ENV_VAR_FILE
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100271
272 if [ -z "$TEST_ENV_PROFILE" ] || [ -z "$SUPPORTED_PROFILES" ]; then
273 echo -e $YELLOW"This test case may no work with selected test env file. TEST_ENV_PROFILE is missing in test_env file or SUPPORTED_PROFILES is missing in test case file"$EYELLOW
274 else
275 if [[ "$SUPPORTED_PROFILES" == *"$TEST_ENV_PROFILE"* ]]; then
276 echo -e $GREEN"Test case support the selected test env file"$EGREEN
277 else
278 echo -e $RED"Test case does not support the selected test env file"$ERED
279 echo -e $RED"Exiting...."$ERED
280 exit 1
281 fi
282 fi
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200283else
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200284 echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200285 echo " Select one of following env var file matching the intended target of the test"
286 echo " Restart the test using the flag '--env-file <path-to-env-file>"
287 ls ../common/test_env* | indent1
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200288 exit 1
289fi
290
291#Vars for A1 interface version and container count
292G1_A1_VERSION=""
293G2_A1_VERSION=""
294G3_A1_VERSION=""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100295G4_A1_VERSION=""
296G5_A1_VERSION=""
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200297G1_COUNT=0
298G2_COUNT=0
299G3_COUNT=0
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100300G4_COUNT=0
301G5_COUNT=0
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200302
303# Vars to switch between http and https. Extra curl flag needed for https
304export RIC_SIM_HTTPX="http"
305export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
306export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
307export RIC_SIM_CERT_MOUNT_DIR="./cert"
308
309export MR_HTTPX="http"
310export MR_PORT=$MR_INTERNAL_PORT
311export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker net
312
313export CR_HTTPX="http"
314export CR_PORT=$CR_INTERNAL_PORT
315export CR_LOCAL_PORT=$CR_EXTERNAL_PORT #When CR is running outside the docker net
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100316export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200317
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200318export PROD_STUB_HTTPX="http"
319export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
320export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT #When CR is running outside the docker net
321export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
322
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200323export SDNC_HTTPX="http"
324export SDNC_PORT=$SDNC_INTERNAL_PORT
325export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net
326
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100327echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
YongchaoWu9a84f512019-12-16 22:54:11 +0100328
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100329#Temp var to check for image variable name errors
330IMAGE_ERR=0
331#Create a file with image info for later printing as a table
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200332image_list_file="./tmp/.image-list"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100333echo -e " Container\tImage\ttag" > $image_list_file
334
335# 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 +0200336# 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 +0100337__check_image_var() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200338 if [ $# -ne 6 ]; then
339 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 +0100340 ((IMAGE_ERR++))
341 return
342 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200343 __check_included_image $6
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200344 if [ $? -ne 0 ]; then
345 echo -e "$1\t<image-excluded>\t<no-tag>" >> $image_list_file
346 # Image is excluded since the corresponding app is not used in this test
347 return
348 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100349 tmp=${1}"\t"
350 #Create var from the input var names
351 image="${!4}"
352 tag="${!5}"
353
354 if [ -z $image ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200355 echo -e $RED"\$"$4" not set in $TEST_ENV_VAR_FILE"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100356 ((IMAGE_ERR++))
357 echo ""
358 tmp=$tmp"<no-image>\t"
359 else
360 tmp=$tmp$image"\t"
361 fi
362 if [ -z $tag ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200363 echo -e $RED"\$"$5" not set in $TEST_ENV_VAR_FILE"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100364 ((IMAGE_ERR++))
365 echo ""
366 tmp=$tmp"<no-tag>\t"
367 else
368 tmp=$tmp$tag
369 fi
370 echo -e "$tmp" >> $image_list_file
371 #Export the env var
372 export "${3}"=$image":"$tag
373
374 #echo " Configured image for ${1} (script start arg=${2}): "$image":"$tag
375}
376
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200377
378#Check if app local image shall override remote image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200379# Possible IDs for local image override: PA, CP, SDNC, RICSIM, ECS
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200380__check_image_local_override() {
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200381 for im in $USE_LOCAL_IMAGES; do
382 if [ "$1" == "$im" ]; then
383 return 1
384 fi
385 done
386 return 0
387}
388
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200389# Check if app uses image included in this test run
390# Returns 0 if image is included, 1 if not
391# Possible IDs for image inclusion: CBS, CONSUL, CP, CR, ECS, MR, PA, PRODSTUB, RICSIM, SDNC
392__check_included_image() {
393 for im in $INCLUDED_IMAGES; do
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200394 if [ "$1" == "$im" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200395 return 0
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200396 fi
397 done
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200398 return 1
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200399}
400
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100401# Check that image env setting are available
402echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200403
404if [ $START_ARG == "local" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100405
406 #Local agent image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200407 __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 +0100408
409 #Local Control Panel image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200410 __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 +0100411
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
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100414
415 #Local ric sim image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200416 __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 +0100417
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200418elif [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100419
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200420 __check_image_local_override 'PA'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200421 if [ $? -eq 0 ]; then
422 #Remote agent image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200423 __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 +0200424 else
425 #Local agent image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200426 __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 +0200427 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100428
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200429 __check_image_local_override 'CP'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200430 if [ $? -eq 0 ]; then
431 #Remote Control Panel image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200432 __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 +0200433 else
434 #Local Control Panel image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200435 __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 +0200436 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100437
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200438 __check_image_local_override 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200439 if [ $? -eq 0 ]; then
440 #Remote SDNC image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200441 __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 +0200442 else
443 #Local SNDC image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200444 __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 +0200445 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100446
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200447 __check_image_local_override 'RICSIM'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200448 if [ $? -eq 0 ]; then
449 #Remote ric sim image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200450 __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 +0200451 else
452 #Local ric sim image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200453 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG" RICSIM
454 fi
455
456 __check_image_local_override 'ECS'
457 if [ $? -eq 0 ]; then
458 #Remote ecs image
459 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_REMOTE_IMAGE" "ECS_REMOTE_IMAGE_TAG" ECS
460 else
461 #Local ecs image
462 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_LOCAL_IMAGE" "ECS_LOCAL_IMAGE_TAG" ECS
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200463 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100464
465else
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200466 #Should never get here....
467 echo "Unknow args: "$@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100468 exit 1
YongchaoWu9a84f512019-12-16 22:54:11 +0100469fi
470
YongchaoWu9a84f512019-12-16 22:54:11 +0100471
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100472# 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 +0200473__check_image_var " Message Router" $START_ARG "MRSTUB_IMAGE" "MRSTUB_LOCAL_IMAGE" "MRSTUB_LOCAL_IMAGE_TAG" MR
474__check_image_var " Callback Receiver" $START_ARG "CR_IMAGE" "CR_LOCAL_IMAGE" "CR_LOCAL_IMAGE_TAG" CR
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200475__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 +0200476__check_image_var " Consul" $START_ARG "CONSUL_IMAGE" "CONSUL_REMOTE_IMAGE" "CONSUL_REMOTE_IMAGE_TAG" CONSUL
477__check_image_var " CBS" $START_ARG "CBS_IMAGE" "CBS_REMOTE_IMAGE" "CBS_REMOTE_IMAGE_TAG" CBS
478__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 +0100479
480#Errors in image setting - exit
481if [ $IMAGE_ERR -ne 0 ]; then
482 exit 1
483fi
484
485#Print a tables of the image settings
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200486echo -e $BOLD"Images configured for start arg: "$START $EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100487column -t -s $'\t' $image_list_file
488
YongchaoWuf309b1b2020-01-22 13:24:48 +0100489echo ""
490
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100491
492#Set the SIM_GROUP var
493echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
494if [ -z "$SIM_GROUP" ]; then
495 SIM_GROUP=$PWD/../simulator-group
496 if [ ! -d $SIM_GROUP ]; then
497 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200498 echo -e $RED"Please set the SIM_GROUP manually in the applicable $TEST_ENV_VAR_FILE"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100499 exit 1
500 else
501 echo " SIM_GROUP auto set to: " $SIM_GROUP
502 fi
503elif [ $SIM_GROUP = *simulator_group ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200504 echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check $TEST_ENV_VAR_FILE"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100505 exit 1
506else
507 echo " SIM_GROUP env var already set to: " $SIM_GROUP
maximesson28ee8a52020-03-17 09:32:03 +0100508fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100509
510echo ""
511
512#Temp var to check for image pull errors
513IMAGE_ERR=0
514
515#Function to check if image exist and stop+remove the container+pull new images as needed
516#args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
517__check_and_pull_image() {
518
519 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
520 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
521 tmp_im=$(docker images --format $format_string ${4})
522
523 if [ $1 == "local" ]; then
524 if [ -z "$tmp_im" ]; then
525 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
526 ((IMAGE_ERR++))
527 return 1
528 else
529 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
530 fi
531 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
532 if [ $1 == "remote-remove" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200533 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100534 tmp="$(docker ps -aq --filter name=${3})"
535 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200536 docker stop $tmp &> ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100537 if [ $? -ne 0 ]; then
538 ((IMAGE_ERR++))
539 echo ""
540 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200541 cat ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100542 return 1
543 fi
544 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200545 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100546 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
547 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200548 docker rm $tmp &> ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100549 if [ $? -ne 0 ]; then
550 ((IMAGE_ERR++))
551 echo ""
552 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200553 cat ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100554 return 1
555 fi
556 fi
557 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200558 echo -ne " Removing image - ${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100559 tmp="$(docker images -q ${4})" &> /dev/null
560 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200561 docker rmi --force $4 &> ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100562 if [ $? -ne 0 ]; then
563 ((IMAGE_ERR++))
564 echo ""
565 echo -e $RED" Image could not be removed - try manual removal of the image"$ERED
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200566 cat ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100567 return 1
568 fi
569 echo -e " Removing image - "$GREEN"removed"$EGREEN
570 else
571 echo -e " Removing image - "$GREEN"image not in repository"$EGREEN
572 fi
573 tmp_im=""
574 fi
575 if [ -z "$tmp_im" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200576 echo -ne " Pulling image${SAMELINE}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200577 docker pull $4 &> ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100578 tmp_im=$(docker images ${4} | grep -v REPOSITORY)
579 if [ -z "$tmp_im" ]; then
580 echo ""
581 echo -e " Pulling image -$RED could not be pulled"$ERED
582 ((IMAGE_ERR++))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200583 cat ./tmp/.dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100584 return 1
585 fi
586 echo -e " Pulling image -$GREEN Pulled $EGREEN"
587 else
588 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
589 fi
590 fi
591 return 0
592}
593
594
595echo -e $BOLD"Pulling configured images, if needed"$EBOLD
596
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200597__check_included_image 'PA'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200598if [ $? -eq 0 ]; then
599 START_ARG_MOD=$START_ARG
600 __check_image_local_override 'PA'
601 if [ $? -eq 1 ]; then
602 START_ARG_MOD="local"
603 fi
604 app="Policy Agent"; __check_and_pull_image $START_ARG_MOD "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
605else
606 echo -e $YELLOW" Excluding PA image from image check/pull"$EYELLOW
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200607fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100608
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200609__check_included_image 'ECS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200610if [ $? -eq 0 ]; then
611 START_ARG_MOD=$START_ARG
612 __check_image_local_override 'ECS'
613 if [ $? -eq 1 ]; then
614 START_ARG_MOD="local"
615 fi
616 app="ECS"; __check_and_pull_image $START_ARG_MOD "$app" $ECS_APP_NAME $ECS_IMAGE
617else
618 echo -e $YELLOW" Excluding ECS image from image check/pull"$EYELLOW
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200619fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200620
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200621__check_included_image 'CP'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200622if [ $? -eq 0 ]; then
623 START_ARG_MOD=$START_ARG
624 __check_image_local_override 'CP'
625 if [ $? -eq 1 ]; then
626 START_ARG_MOD="local"
627 fi
628 app="Non-RT RIC Control Panel"; __check_and_pull_image $START_ARG_MOD "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
629else
630 echo -e $YELLOW" Excluding Non-RT RIC Control Panel image from image check/pull"$EYELLOW
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200631fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100632
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200633__check_included_image 'RICSIM'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200634if [ $? -eq 0 ]; then
635 START_ARG_MOD=$START_ARG
636 __check_image_local_override 'RICSIM'
637 if [ $? -eq 1 ]; then
638 START_ARG_MOD="local"
639 fi
640 app="Near-RT RIC Simulator"; __check_and_pull_image $START_ARG_MOD "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
641else
642 echo -e $YELLOW" Excluding Near-RT RIC Simulator image from image check/pull"$EYELLOW
643fi
644
645
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200646__check_included_image 'CONSUL'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200647if [ $? -eq 0 ]; then
648 app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
649else
650 echo -e $YELLOW" Excluding Consul image from image check/pull"$EYELLOW
651fi
652
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200653__check_included_image 'CBS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200654if [ $? -eq 0 ]; then
655 app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE
656else
657 echo -e $YELLOW" Excluding CBS image from image check/pull"$EYELLOW
658fi
659
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200660__check_included_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200661if [ $? -eq 0 ]; then
662 START_ARG_MOD=$START_ARG
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200663 __check_image_local_override 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200664 if [ $? -eq 1 ]; then
665 START_ARG_MOD="local"
666 fi
667 app="SDNC A1 Controller"; __check_and_pull_image $START_ARG_MOD "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
668 app="SDNC DB"; __check_and_pull_image $START_ARG "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
669else
670 echo -e $YELLOW" Excluding SDNC image and related DB image from image check/pull"$EYELLOW
671fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100672
673#Errors in image setting - exit
674if [ $IMAGE_ERR -ne 0 ]; then
675 echo ""
676 echo "#################################################################################################"
677 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 +0200678 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100679 echo "#################################################################################################"
680 echo ""
681 exit 1
682fi
683
684echo ""
685
686echo -e $BOLD"Building images needed for test"$EBOLD
687
688curdir=$PWD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200689__check_included_image 'MR'
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100690if [ $? -eq 0 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200691 cd $curdir
692 cd ../mrstub
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200693 echo " Building mrstub image: $MRSTUB_LOCAL_IMAGE:$MRSTUB_LOCAL_IMAGE_TAG"
694 docker build -t $MRSTUB_LOCAL_IMAGE . &> .dockererr
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200695 if [ $? -eq 0 ]; then
696 echo -e $GREEN" Build Ok"$EGREEN
697 else
698 echo -e $RED" Build Failed"$ERED
699 ((RES_CONF_FAIL++))
700 cat .dockererr
BjornMagnussonXA2791e082020-11-12 00:52:08 +0100701 echo -e $RED"Exiting...."$ERED
702 exit 1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200703 fi
704 cd $curdir
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100705else
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200706 echo -e $YELLOW" Excluding mrstub from image build"$EYELLOW
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100707fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100708
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200709__check_included_image 'CR'
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100710if [ $? -eq 0 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200711 cd ../cr
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200712 echo " Building Callback Receiver image: $CR_LOCAL_IMAGE:$CR_IMAGE_TAG"
713 docker build -t $CR_LOCAL_IMAGE . &> .dockererr
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200714 if [ $? -eq 0 ]; then
715 echo -e $GREEN" Build Ok"$EGREEN
716 else
717 echo -e $RED" Build Failed"$ERED
718 ((RES_CONF_FAIL++))
719 cat .dockererr
BjornMagnussonXA2791e082020-11-12 00:52:08 +0100720 echo -e $RED"Exiting...."$ERED
721 exit 1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200722 fi
723 cd $curdir
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100724else
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200725 echo -e $YELLOW" Excluding Callback Receiver from image build"$EYELLOW
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100726fi
YongchaoWuf309b1b2020-01-22 13:24:48 +0100727
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200728__check_included_image 'PRODSTUB'
729if [ $? -eq 0 ]; then
730 cd ../prodstub
731 echo " Building Producer stub image: $PROD_STUB_LOCAL_IMAGE:$PROD_STUB_LOCAL_IMAGE_TAG"
732 docker build -t $PROD_STUB_LOCAL_IMAGE . &> .dockererr
733 if [ $? -eq 0 ]; then
734 echo -e $GREEN" Build Ok"$EGREEN
735 else
736 echo -e $RED" Build Failed"$ERED
737 ((RES_CONF_FAIL++))
738 cat .dockererr
BjornMagnussonXA2791e082020-11-12 00:52:08 +0100739 echo -e $RED"Exiting...."$ERED
740 exit 1
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200741 fi
742 cd $curdir
743else
744 echo -e $YELLOW" Excluding Producer stub from image build"$EYELLOW
745fi
746
YongchaoWuf309b1b2020-01-22 13:24:48 +0100747echo ""
748
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100749# Create a table of the images used in the script
750echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
751
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200752docker_tmp_file=./tmp/.docker-images-table
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200753format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\\t{{.CreatedAt}}"
754echo -e " Application\tRepository\tTag\tCreated since\tSize\tCreated at" > $docker_tmp_file
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200755__check_included_image 'PA'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200756if [ $? -eq 0 ]; then
757 echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
758fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200759__check_included_image 'ECS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200760if [ $? -eq 0 ]; then
761 echo -e " ECS\t$(docker images --format $format_string $ECS_IMAGE)" >> $docker_tmp_file
762fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200763__check_included_image 'CP'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200764if [ $? -eq 0 ]; then
765 echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
766fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200767__check_included_image 'RICSIM'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200768if [ $? -eq 0 ]; then
769 echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
770fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200771__check_included_image 'MR'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200772if [ $? -eq 0 ]; then
773 echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
774fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200775__check_included_image 'CR'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200776if [ $? -eq 0 ]; then
777 echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
778fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200779__check_included_image 'PRODSTUB'
780if [ $? -eq 0 ]; then
781 echo -e " Produccer stub\t$(docker images --format $format_string $PROD_STUB_IMAGE)" >> $docker_tmp_file
782fi
783__check_included_image 'CONSUL'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200784if [ $? -eq 0 ]; then
785 echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
786fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200787__check_included_image 'CBS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200788if [ $? -eq 0 ]; then
789 echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
790fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200791__check_included_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200792if [ $? -eq 0 ]; then
793 echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
794 echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
795fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100796
797column -t -s $'\t' $docker_tmp_file
798
YongchaoWuf309b1b2020-01-22 13:24:48 +0100799echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +0100800
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100801echo -e $BOLD"======================================================="$EBOLD
802echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
803echo -e $BOLD"======================================================="$EBOLD
804echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +0100805
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100806# Function to print the test result, shall be the last cmd in a test script
807# args: -
808# (Function for test scripts)
809print_result() {
YongchaoWu9a84f512019-12-16 22:54:11 +0100810
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100811 TCTEST_END=$SECONDS
812 duration=$((TCTEST_END-TCTEST_START))
YongchaoWu9a84f512019-12-16 22:54:11 +0100813
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100814 echo "-------------------------------------------------------------------------------------------------"
815 echo "------------------------------------- Test case: "$ATC
816 echo "------------------------------------- Ended: "$(date)
817 echo "-------------------------------------------------------------------------------------------------"
818 echo "-- Description: "$TC_ONELINE_DESCR
819 echo "-- Execution time: " $duration " seconds"
BjornMagnussonXA2791e082020-11-12 00:52:08 +0100820 echo "-- Used env file: "$TEST_ENV_VAR_FILE
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100821 echo "-------------------------------------------------------------------------------------------------"
822 echo "------------------------------------- RESULTS"
YongchaoWu4e489b02020-02-24 09:18:16 +0100823 echo ""
YongchaoWu4e489b02020-02-24 09:18:16 +0100824
YongchaoWu21f17bb2020-03-05 12:44:08 +0100825
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200826 if [ $RES_DEVIATION -gt 0 ]; then
827 echo "Test case deviations"
828 echo "===================================="
829 cat $DEVIATION_FILE
830 fi
831 echo ""
832 echo "Timer measurement in the test script"
833 echo "===================================="
834 column -t -s $'\t' $TIMER_MEASUREMENTS
835 echo ""
836
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100837 total=$((RES_PASS+RES_FAIL))
838 if [ $RES_TEST -eq 0 ]; then
839 echo -e "\033[1mNo tests seem to have been executed. Check the script....\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 -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
844 elif [ $total != $RES_TEST ]; then
845 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
846 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
847 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
848 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
849 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
850 elif [ $RES_CONF_FAIL -ne 0 ]; then
851 echo -e "\033[1mOne or more configure regest has failed. Check the script log....\033[0m"
852 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
853 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
854 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
855 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
856 elif [ $RES_PASS = $RES_TEST ]; then
857 echo -e "All tests \033[32m\033[1mPASS\033[0m"
858 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
859 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
860 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
861 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
862 echo ""
YongchaoWu21f17bb2020-03-05 12:44:08 +0100863
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100864 # Update test suite counter
865 if [ -f .tmp_tcsuite_pass_ctr ]; then
866 tmpval=$(< .tmp_tcsuite_pass_ctr)
867 ((tmpval++))
868 echo $tmpval > .tmp_tcsuite_pass_ctr
869 fi
870 if [ -f .tmp_tcsuite_pass ]; then
871 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
872 fi
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200873 #Create file with OK exit code
874 echo "0" > "$PWD/.result$ATC.txt"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100875 else
876 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
877 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
878 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
879 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
880 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
881 echo ""
882 # Update test suite counter
883 if [ -f .tmp_tcsuite_fail_ctr ]; then
884 tmpval=$(< .tmp_tcsuite_fail_ctr)
885 ((tmpval++))
886 echo $tmpval > .tmp_tcsuite_fail_ctr
887 fi
888 if [ -f .tmp_tcsuite_fail ]; then
889 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
890 fi
YongchaoWu21f17bb2020-03-05 12:44:08 +0100891 fi
YongchaoWu21f17bb2020-03-05 12:44:08 +0100892
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100893 echo "++++ Number of tests: "$RES_TEST
894 echo "++++ Number of passed tests: "$RES_PASS
895 echo "++++ Number of failed tests: "$RES_FAIL
YongchaoWu4e489b02020-02-24 09:18:16 +0100896 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100897 echo "++++ Number of failed configs: "$RES_CONF_FAIL
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200898 echo ""
899 echo "++++ Number of test case deviations: "$RES_DEVIATION
900 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100901 echo "------------------------------------- Test case complete ---------------------------------"
902 echo "-------------------------------------------------------------------------------------------------"
YongchaoWu9a84f512019-12-16 22:54:11 +0100903 echo ""
904}
905
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100906#####################################################################
907###### Functions for start, configuring, stoping, cleaning etc ######
908#####################################################################
YongchaoWu21f17bb2020-03-05 12:44:08 +0100909
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200910# Start timer for time measurement
911# args - (any args will be printed though)
912start_timer() {
913 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
914 TC_TIMER=$SECONDS
915 echo " Timer started"
916}
917
918# Print the value of the time (in seconds)
919# args - <timer message to print> - timer value and message will be printed both on screen
920# and in the timer measurement report
921print_timer() {
922 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
923 if [ $# -lt 1 ]; then
924 ((RES_CONF_FAIL++))
925 __print_err "need 1 or more args, <timer message to print>" $@
926 exit 1
927 fi
928 duration=$(($SECONDS-$TC_TIMER))
929 if [ $duration -eq 0 ]; then
930 duration="<1 second"
931 else
932 duration=$duration" seconds"
933 fi
934 echo " Timer duration :" $duration
935
936 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
937}
938
939# Print the value of the time (in seconds) and reset the timer
940# args - <timer message to print> - timer value and message will be printed both on screen
941# and in the timer measurement report
942print_and_reset_timer() {
943 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
944 if [ $# -lt 1 ]; then
945 ((RES_CONF_FAIL++))
946 __print_err "need 1 or more args, <timer message to print>" $@
947 exit 1
948 fi
949 duration=$(($SECONDS-$TC_TIMER))" seconds"
950 if [ $duration -eq 0 ]; then
951 duration="<1 second"
952 else
953 duration=$duration" seconds"
954 fi
955 echo " Timer duration :" $duration
956 TC_TIMER=$SECONDS
957 echo " Timer reset"
958
959 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
960
961}
962# Print info about a deviations from intended tests
963# Each deviation counted is also printed in the testreport
964# args <deviation message to print>
965deviation() {
966 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
967 if [ $# -lt 1 ]; then
968 ((RES_CONF_FAIL++))
969 __print_err "need 1 or more args, <deviation message to print>" $@
970 exit 1
971 fi
972 ((RES_DEVIATION++))
973 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
974 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
975 echo ""
976}
YongchaoWu21f17bb2020-03-05 12:44:08 +0100977
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200978# Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
979__check_stop_at_error() {
980 if [ $STOP_AT_ERROR -eq 1 ]; then
981 echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
982 store_logs "STOP_AT_ERROR"
983 exit 1
984 fi
985 return 0
986}
987
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200988# Check if app name var is set. If so return the app name otherwise return "NOTSET"
989__check_app_name() {
990 if [ $# -eq 1 ]; then
991 echo $1
992 else
993 echo "NOTSET"
994 fi
995}
996
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100997# Stop and remove all containers
998# args: -
999# (Function for test scripts)
YongchaoWu9a84f512019-12-16 22:54:11 +01001000clean_containers() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001001
1002 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
1003
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001004 CONTAINTER_NAMES=("Policy Agent " $(__check_app_name $POLICY_AGENT_APP_NAME)\
1005 "ECS " $(__check_app_name $ECS_APP_NAME)\
1006 "Non-RT RIC Simulator(s)" $(__check_app_name $RIC_SIM_PREFIX)\
1007 "Message Router " $(__check_app_name $MR_APP_NAME)\
1008 "Callback Receiver " $(__check_app_name $CR_APP_NAME)\
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001009 "Producer stub " $(__check_app_name $PROD_STUB_APP_NAME)\
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001010 "Control Panel " $(__check_app_name $CONTROL_PANEL_APP_NAME)\
1011 "SDNC A1 Controller " $(__check_app_name $SDNC_APP_NAME)\
1012 "SDNC DB " $(__check_app_name $SDNC_DB_APP_NAME)\
1013 "CBS " $(__check_app_name $CBS_APP_NAME)\
1014 "Consul " $(__check_app_name $CONSUL_APP_NAME))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001015
1016 nw=0 # Calc max width of container name, to make a nice table
1017 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001018
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001019 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
1020 nw=${#CONTAINTER_NAMES[i]}
1021 fi
1022 done
1023
1024 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
1025 APP="${CONTAINTER_NAMES[i]}"
1026 CONTR="${CONTAINTER_NAMES[i+1]}"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001027 if [ $CONTR != "NOTSET" ]; then
1028 for((w=${#CONTR}; w<$nw; w=w+1)); do
1029 CONTR="$CONTR "
1030 done
1031 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
1032 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1033 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
1034 docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
1035 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
1036 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001037 done
1038
YongchaoWu9a84f512019-12-16 22:54:11 +01001039 echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001040
1041 echo -e $BOLD" Removing docker network"$EBOLD
1042 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
1043 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001044 docker network rm $DOCKER_SIM_NWNAME | indent2
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001045 if [ $? -ne 0 ]; then
1046 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
1047 exit 1
1048 fi
1049 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001050 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001051
1052 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001053 docker network prune --force | indent2
1054 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001055
1056 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001057 docker volume prune --force | indent2
1058 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001059
1060 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
1061 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001062 echo -e "$GREEN Done$EGREEN"
1063 echo ""
BjornMagnussonXAad047782020-06-08 15:54:11 +02001064
1065 CONTRS=$(docker ps | awk '$1 != "CONTAINER" { n++ }; END { print n+0 }')
1066 if [ $? -eq 0 ]; then
1067 if [ $CONTRS -ne 0 ]; then
1068 echo -e $RED"Containers running, may cause distubance to the test case"$ERED
1069 docker ps -a
1070 fi
1071 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001072}
1073
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001074# Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
1075# args: -
1076# (Function for test scripts)
1077auto_clean_containers() {
1078 echo
1079 if [ "$AUTO_CLEAN" == "auto" ]; then
1080 echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
1081 clean_containers
YongchaoWu9a84f512019-12-16 22:54:11 +01001082 fi
1083}
1084
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001085# Function to sleep a test case for a numner of seconds. Prints the optional text args as info
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001086# args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001087# (Function for test scripts)
1088sleep_wait() {
YongchaoWu9a84f512019-12-16 22:54:11 +01001089
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001090 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1091 if [ $# -lt 1 ]; then
1092 ((RES_CONF_FAIL++))
1093 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
1094 exit 1
1095 fi
1096 #echo "---- Sleep for " $1 " seconds ---- "$2
1097 start=$SECONDS
1098 duration=$((SECONDS-start))
1099 while [ $duration -lt $1 ]; do
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001100 echo -ne " Slept for ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001101 sleep 1
1102 duration=$((SECONDS-start))
1103 done
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001104 echo -ne " Slept for ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001105 echo ""
1106}
1107
1108# Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
1109# Not to be called from the test script itself.
1110__print_err() {
1111 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
1112 if [ $# -gt 1 ]; then
1113 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
1114 fi
1115}
1116
1117
1118# Helper function to get a the port of a specific ric simulatpor
1119# args: <ric-id>
1120# (Not for test scripts)
1121__find_sim_port() {
1122 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
ecaiyanlinux99a769b2020-05-15 13:58:02 +02001123 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
1124 res=$(eval $cmdstr)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001125 if [[ "$res" =~ ^[0-9]+$ ]]; then
1126 echo $res
1127 else
1128 echo "0"
1129 fi
1130}
1131
1132# Function to create the docker network for the test
1133# Not to be called from the test script itself.
1134__create_docker_network() {
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001135 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001136 if [ $? -ne 0 ]; then
1137 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
1138 return 1
1139 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001140 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001141 echo -e " Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
1142 docker network create $DOCKER_SIM_NWNAME | indent2
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001143 if [ $? -ne 0 ]; then
1144 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
1145 return 1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001146 else
1147 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001148 fi
1149 else
1150 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
1151 fi
1152}
1153
1154# Check if container is started by calling url on localhost using a port, expects response code 2XX
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001155# args: <container-name> <port> <url> https|https
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001156# Not to be called from the test script itself.
1157__check_container_start() {
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001158 paramError=0
1159 if [ $# -ne 4 ]; then
1160 paramError=1
1161 elif [ $4 != "http" ] && [ $4 != "https" ]; then
1162 paramError=1
1163 fi
1164 if [ $paramError -ne 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001165 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001166 __print_err "need 3 args, <container-name> <port> <url> https|https" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001167 return 1
1168 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001169 echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
YongchaoWu9a84f512019-12-16 22:54:11 +01001170 appname=$1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001171 localport=$2
1172 url=$3
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001173 if [[ $appname != "STANDALONE_"* ]] ; then
1174 app_started=0
1175 for i in {1..10}; do
1176 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
1177 echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
1178 app_started=1
1179 break
1180 else
1181 sleep $i
1182 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001183 done
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001184 if [ $app_started -eq 0 ]; then
1185 ((RES_CONF_FAIL++))
1186 echo ""
1187 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001188 echo -e $RED" Stopping script..."$ERED
1189 exit 1
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001190 fi
1191 if [ $localport -eq 0 ]; then
1192 while [ $localport -eq 0 ]; do
1193 echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
1194 localport=$(__find_sim_port $appname)
1195 sleep 1
1196 echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
1197 done
1198 echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
1199 echo ""
1200 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001201 fi
1202
1203 pa_st=false
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001204 echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001205 TSTART=$SECONDS
1206 for i in {1..50}; do
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001207 if [ $4 == "https" ]; then
1208 result="$(__do_curl "-k https://localhost:"${localport}${url})"
1209 else
1210 result="$(__do_curl $LOCALHOST${localport}${url})"
1211 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001212 if [ $? -eq 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001213 if [ ${#result} -gt 15 ]; then
1214 #If response is too long, truncate
1215 result="...response text too long, omitted"
1216 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001217 echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001218 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 +01001219 pa_st=true
1220 break
1221 else
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001222 TS_TMP=$SECONDS
1223 while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001224 echo -ne " Waiting for container ${appname} service status...$(($SECONDS-$TSTART)) seconds, retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001225 sleep 1
1226 done
YongchaoWu9a84f512019-12-16 22:54:11 +01001227 fi
1228 done
1229
1230 if [ "$pa_st" = "false" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001231 ((RES_CONF_FAIL++))
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001232 echo -e $RED" Container ${appname} did not respond to service status in $(($SECONDS-$TSTART)) seconds"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001233 return 0
1234 fi
1235
1236 echo ""
1237 return 0
1238}
1239
1240
1241# Function to start a container and wait until it responds on the given port and url.
1242#args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
1243__start_container() {
1244
1245 variableArgCount=$(($#-2))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001246 if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001247 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001248 __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 +01001249 exit 1
1250 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001251
1252 __create_docker_network
1253
1254 curdir=$PWD
1255 cd $SIM_GROUP
1256 cd $1
1257
1258 if [ "$2" == "NODOCKERARGS" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001259 docker-compose up -d &> .dockererr
1260 if [ $? -ne 0 ]; then
1261 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1262 cat .dockererr
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001263 echo -e $RED"Stopping script...."$ERED
1264 exit 1
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001265 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001266 elif [ "$2" == "STANDALONE" ]; then
1267 echo "Skipping docker-compose"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001268 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001269 docker-compose up -d $2 &> .dockererr
1270 if [ $? -ne 0 ]; then
1271 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1272 cat .dockererr
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001273 echo -e $RED"Stopping script...."$ERED
1274 exit 1
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001275 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001276 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001277 app_prefix=""
1278 if [ "$2" == "STANDALONE" ]; then
1279 app_prefix="STANDALONE_"
1280 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001281 shift; shift;
1282 cntr=0
1283 while [ $cntr -lt $variableArgCount ]; do
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001284 app=$app_prefix$1; shift;
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001285 port=$1; shift;
1286 url=$1; shift;
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001287 httpx=$1; shift;
1288 let cntr=cntr+4
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001289
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001290 __check_container_start "$app" "$port" "$url" $httpx
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001291 done
1292
1293 cd $curdir
1294 echo ""
1295 return 0
YongchaoWu9a84f512019-12-16 22:54:11 +01001296}
1297
BjornMagnussonXAad047782020-06-08 15:54:11 +02001298# Generate a UUID to use as prefix for policy ids
1299generate_uuid() {
1300 UUID=$(python3 -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
1301 #Reduce length to make space for serial id, us 'a' as marker where the serial id is added
1302 UUID=${UUID:0:${#UUID}-4}"a"
1303}
1304
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001305####################
1306### Consul functions
1307####################
1308
1309# Function to load config from a file into consul for the Policy Agent
1310# arg: <json-config-file>
1311# (Function for test scripts)
1312consul_config_app() {
1313
1314 echo -e $BOLD"Configuring Consul"$EBOLD
1315
1316 if [ $# -ne 1 ]; then
1317 ((RES_CONF_FAIL++))
1318 __print_err "need one arg, <json-config-file>" $@
1319 exit 1
1320 fi
1321
1322 echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1
1323
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001324 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
1325 result=$(__do_curl "$curlString")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001326 if [ $? -ne 0 ]; then
1327 echo -e $RED" FAIL - json config could not be loaded to consul" $ERED
1328 ((RES_CONF_FAIL++))
1329 return 1
1330 fi
1331 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001332 echo $body > "./tmp/.output"$1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001333
1334 if [ $? -ne 0 ]; then
1335 echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED
1336 ((RES_CONF_FAIL++))
1337 return 1
1338 else
1339 targetJson=$(< $1)
1340 targetJson="{\"config\":"$targetJson"}"
1341 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001342 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001343 if [ $res -ne 0 ]; then
1344 echo -e $RED" FAIL - policy json config read from consul/cbs is not equal to the intended json config...." $ERED
1345 ((RES_CONF_FAIL++))
1346 return 1
1347 else
1348 echo -e $GREEN" Config loaded ok to consul"$EGREEN
1349 fi
1350 fi
1351
1352 echo ""
1353
1354}
1355
1356# Function to perpare the consul configuration according to the current simulator configuration
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001357# args: SDNC|NOSDNC <output-file>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001358# (Function for test scripts)
1359prepare_consul_config() {
1360 echo -e $BOLD"Prepare Consul config"$EBOLD
1361
1362 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
1363
1364 if [ $# != 2 ]; then
1365 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001366 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001367 exit 1
1368 fi
1369
1370 if [ $1 == "SDNC" ]; then
1371 echo -e " Config$BOLD including SDNC$EBOLD configuration"
1372 elif [ $1 == "NOSDNC" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001373 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001374 else
1375 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001376 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001377 exit 1
1378 fi
1379
1380 config_json="\n {"
1381 if [ $1 == "SDNC" ]; then
1382 config_json=$config_json"\n \"controller\": ["
1383 config_json=$config_json"\n {"
1384 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001385 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1386 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://$SDNC_APP_NAME:$SDNC_PORT\","
1387 else
1388 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://localhost:$SDNC_LOCAL_PORT\","
1389 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001390 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
1391 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
1392 config_json=$config_json"\n }"
1393 config_json=$config_json"\n ],"
1394 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001395
1396 config_json=$config_json"\n \"streams_publishes\": {"
1397 config_json=$config_json"\n \"dmaap_publisher\": {"
1398 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1399 config_json=$config_json"\n \"dmaap_info\": {"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001400 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1401 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_WRITE_URL\""
1402 else
1403 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_WRITE_URL\""
1404 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001405 config_json=$config_json"\n }"
1406 config_json=$config_json"\n }"
1407 config_json=$config_json"\n },"
1408 config_json=$config_json"\n \"streams_subscribes\": {"
1409 config_json=$config_json"\n \"dmaap_subscriber\": {"
1410 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1411 config_json=$config_json"\n \"dmaap_info\": {"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001412 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1413 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_READ_URL\""
1414 else
1415 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_READ_URL\""
1416 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001417 config_json=$config_json"\n }"
1418 config_json=$config_json"\n }"
1419 config_json=$config_json"\n },"
1420
1421 config_json=$config_json"\n \"ric\": ["
1422
BjornMagnussonXAad047782020-06-08 15:54:11 +02001423 rics=$(docker ps | grep $RIC_SIM_PREFIX | awk '{print $NF}')
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001424
1425 if [ $? -ne 0 ] || [ -z "$rics" ]; then
1426 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
1427 ((RES_CONF_FAIL++))
1428 return 1
1429 fi
1430
1431 cntr=0
1432 for ric in $rics; do
1433 if [ $cntr -gt 0 ]; then
1434 config_json=$config_json"\n ,"
1435 fi
1436 config_json=$config_json"\n {"
1437 config_json=$config_json"\n \"name\": \"$ric\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001438 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1439 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
1440 else
1441 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://localhost:$(__find_sim_port $ric)\","
1442 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001443 if [ $1 == "SDNC" ]; then
1444 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
1445 fi
1446 config_json=$config_json"\n \"managedElementIds\": ["
1447 config_json=$config_json"\n \"me1_$ric\","
1448 config_json=$config_json"\n \"me2_$ric\""
1449 config_json=$config_json"\n ]"
1450 config_json=$config_json"\n }"
1451 let cntr=cntr+1
1452 done
1453
1454 config_json=$config_json"\n ]"
1455 config_json=$config_json"\n}"
1456
1457
1458 printf "$config_json">$2
1459
1460 echo ""
1461}
1462
1463
1464# Start Consul and CBS
1465# args: -
1466# (Function for test scripts)
1467start_consul_cbs() {
1468
1469 echo -e $BOLD"Starting Consul and CBS"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001470 __check_included_image 'CONSUL'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001471 if [ $? -eq 1 ]; then
1472 echo -e $RED"The Consul image has not been checked for this test run due to arg to the test script"$ERED
1473 echo -e $RED"Consul will not be started"$ERED
1474 exit
1475 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001476 __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" "http" \
1477 "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001478}
1479
1480###########################
1481### RIC Simulator functions
1482###########################
1483
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001484use_simulator_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001485 echo -e "Using $BOLD http $EBOLD towards the simulators"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001486 export RIC_SIM_HTTPX="http"
1487 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1488 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001489 echo ""
1490}
1491
1492use_simulator_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001493 echo -e "Using $BOLD https $EBOLD towards the simulators"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001494 export RIC_SIM_HTTPX="https"
1495 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1496 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001497 echo ""
1498}
1499
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001500# Start one group (ricsim_g1, ricsim_g2 .. ricsim_g5) with a number of RIC Simulators using a given A interface
BjornMagnussonXAad047782020-06-08 15:54:11 +02001501# 'ricsim' may be set on command line to other prefix
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001502# args: ricsim_g1|ricsim_g2|ricsim_g3|ricsim_g4|ricsim_g5 <count> <interface-id>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001503# (Function for test scripts)
1504start_ric_simulators() {
1505
1506 echo -e $BOLD"Starting RIC Simulators"$EBOLD
1507
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001508 __check_included_image 'RICSIM'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001509 if [ $? -eq 1 ]; then
1510 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
1511 echo -e $RED"The Near-RT RIC Simulartor(s) will not be started"$ERED
1512 exit
1513 fi
1514
BjornMagnussonXAad047782020-06-08 15:54:11 +02001515 RIC1=$RIC_SIM_PREFIX"_g1"
1516 RIC2=$RIC_SIM_PREFIX"_g2"
1517 RIC3=$RIC_SIM_PREFIX"_g3"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001518 RIC4=$RIC_SIM_PREFIX"_g4"
1519 RIC5=$RIC_SIM_PREFIX"_g5"
BjornMagnussonXAad047782020-06-08 15:54:11 +02001520
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001521 if [ $# != 3 ]; then
1522 ((RES_CONF_FAIL++))
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001523 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001524 exit 1
1525 fi
1526 echo " $2 simulators using basename: $1 on interface: $3"
1527 #Set env var for simulator count and A1 interface vesion for the given group
BjornMagnussonXAad047782020-06-08 15:54:11 +02001528 if [ $1 == "$RIC1" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001529 G1_COUNT=$2
1530 G1_A1_VERSION=$3
BjornMagnussonXAad047782020-06-08 15:54:11 +02001531 elif [ $1 == "$RIC2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001532 G2_COUNT=$2
1533 G2_A1_VERSION=$3
BjornMagnussonXAad047782020-06-08 15:54:11 +02001534 elif [ $1 == "$RIC3" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001535 G3_COUNT=$2
1536 G3_A1_VERSION=$3
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001537 elif [ $1 == "$RIC4" ]; then
1538 G4_COUNT=$2
1539 G4_A1_VERSION=$3
1540 elif [ $1 == "$RIC5" ]; then
1541 G5_COUNT=$2
1542 G5_A1_VERSION=$3
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001543 else
1544 ((RES_CONF_FAIL++))
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001545 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001546 exit 1
1547 fi
1548
1549 # Create .env file to compose project, all ric container will get this prefix
1550 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
1551
1552 export G1_A1_VERSION
1553 export G2_A1_VERSION
1554 export G3_A1_VERSION
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001555 export G4_A1_VERSION
1556 export G5_A1_VERSION
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001557
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001558 docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT --scale g4=$G4_COUNT --scale g5=$G5_COUNT"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001559 app_data=""
1560 cntr=1
1561 while [ $cntr -le $2 ]; do
1562 app=$1"_"$cntr
1563 port=0
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001564 app_data="$app_data $app $port / "$RIC_SIM_HTTPX
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001565 let cntr=cntr+1
1566 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001567 __start_container ric "$docker_args" $app_data
1568
1569}
1570
1571###########################
1572### Control Panel functions
1573###########################
1574
1575# Start the Control Panel container
1576# args: -
1577# (Function for test scripts)
1578start_control_panel() {
1579
1580 echo -e $BOLD"Starting Control Panel"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001581 __check_included_image 'CP'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001582 if [ $? -eq 1 ]; then
1583 echo -e $RED"The Control Panel image has not been checked for this test run due to arg to the test script"$ERED
1584 echo -e $RED"The Control Panel will not be started"$ERED
1585 exit
1586 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001587 __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001588
1589}
1590
1591##################
1592### SDNC functions
1593##################
1594
1595# Start the SDNC A1 Controller
1596# args: -
1597# (Function for test scripts)
1598start_sdnc() {
1599
1600 echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
1601
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001602 __check_included_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001603 if [ $? -eq 1 ]; then
1604 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
1605 echo -e $RED"SDNC will not be started"$ERED
1606 exit
1607 fi
1608
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001609 __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT $SDNC_ALIVE_URL "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001610
1611}
1612
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001613use_sdnc_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001614 echo -e "Using $BOLD http $EBOLD towards SDNC"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001615 export SDNC_HTTPX="http"
1616 export SDNC_PORT=$SDNC_INTERNAL_PORT
1617 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT
1618 echo ""
1619}
1620
1621use_sdnc_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001622 echo -e "Using $BOLD https $EBOLD towards SDNC"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001623 export SDNC_HTTPX="https"
1624 export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT
1625 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT
1626 echo ""
1627}
1628
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001629#####################
1630### MR stub functions
1631#####################
1632
1633# Start the Message Router stub interface in the simulator group
1634# args: -
1635# (Function for test scripts)
1636start_mr() {
1637
1638 echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001639 __check_included_image 'MR'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001640 if [ $? -eq 1 ]; then
1641 echo -e $RED"The Message Router image has not been checked for this test run due to arg to the test script"$ERED
1642 echo -e $RED"The Message Router will not be started"$ERED
1643 exit
1644 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001645 export MR_CERT_MOUNT_DIR="./cert"
1646 __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001647}
1648
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001649use_mr_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001650 echo -e "Using $BOLD http $EBOLD towards MR"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001651 export MR_HTTPX="http"
1652 export MR_PORT=$MR_INTERNAL_PORT
1653 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT
1654 echo ""
1655}
1656
1657use_mr_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001658 echo -e "Using $BOLD https $EBOLD towards MR"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001659 export MR_HTTPX="https"
1660 export MR_PORT=$MR_INTERNAL_SECURE_PORT
1661 export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT
1662 echo ""
1663}
1664
1665
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001666################
1667### CR functions
1668################
1669
1670# Start the Callback reciver in the simulator group
1671# args: -
1672# (Function for test scripts)
1673start_cr() {
1674
1675 echo -e $BOLD"Starting Callback Receiver"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001676 __check_included_image 'CR'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001677 if [ $? -eq 1 ]; then
1678 echo -e $RED"The Callback Receiver image has not been checked for this test run due to arg to the test script"$ERED
1679 echo -e $RED"The Callback Receiver will not be started"$ERED
1680 exit
1681 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001682 __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001683
1684}
1685
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001686use_cr_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001687 echo -e "Using $BOLD http $EBOLD towards CR"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001688 export CR_HTTPX="http"
1689 export CR_PORT=$CR_INTERNAL_PORT
1690 export CR_LOCAL_PORT=$CR_EXTERNAL_PORT
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001691 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001692 echo ""
1693}
1694
1695use_cr_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001696 echo -e "Using $BOLD https $EBOLD towards CR"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001697 export CR_HTTPX="https"
1698 export CR_PORT=$CR_INTERNAL_SECURE_PORT
1699 export CR_LOCAL_PORT=$CR_EXTERNAL_SECURE_PORT
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001700 export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001701 echo ""
1702}
1703
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001704###########################
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001705### Producer stub functions
1706###########################
1707
1708# Start the Producer stub in the simulator group
1709# args: -
1710# (Function for test scripts)
1711start_prod_stub() {
1712
1713 echo -e $BOLD"Starting Producer stub"$EBOLD
1714 __check_included_image 'PRODSTUB'
1715 if [ $? -eq 1 ]; then
1716 echo -e $RED"The Producer stub image has not been checked for this test run due to arg to the test script"$ERED
1717 echo -e $RED"The Producer stub will not be started"$ERED
1718 exit
1719 fi
1720 __start_container prodstub NODOCKERARGS $PROD_STUB_APP_NAME $PROD_STUB_EXTERNAL_PORT "/" "http"
1721
1722}
1723
1724use_prod_stub_http() {
1725 echo -e "Using $BOLD http $EBOLD towards Producer stub"
1726 export PROD_STUB_HTTPX="http"
1727 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
1728 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT
1729 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
1730 echo ""
1731}
1732
1733use_prod_stub_https() {
1734 echo -e "Using $BOLD https $EBOLD towards Producer stub"
1735 export PROD_STUB_HTTPX="https"
1736 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_SECURE_PORT
1737 export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_SECURE_PORT
1738 export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT
1739 echo ""
1740}
1741
1742###########################
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001743### Policy Agents functions
1744###########################
1745
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001746# Use an agent on the local machine instead of container
1747use_agent_stand_alone() {
1748 AGENT_STAND_ALONE=1
1749}
1750
1751# Start the policy agent
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001752# args: -
1753# (Function for test scripts)
1754start_policy_agent() {
1755
1756 echo -e $BOLD"Starting Policy Agent"$EBOLD
1757
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001758 if [ $AGENT_STAND_ALONE -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001759 __check_included_image 'PA'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001760 if [ $? -eq 1 ]; then
1761 echo -e $RED"The Policy Agent image has not been checked for this test run due to arg to the test script"$ERED
1762 echo -e $RED"The Policy Agent will not be started"$ERED
1763 exit
1764 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001765 __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1766 else
1767 echo -e $RED"The consul config produced by this test script (filename '<fullpath-to-autotest-dir>.output<file-name>"$ERED
1768 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
1769 echo -e $RED"application.yaml"$ERED
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001770 echo -e $RED"The application jar may need to be built before continuing"$ERED
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001771 echo -e $RED"The agent shall now be running on port $POLICY_AGENT_EXTERNAL_PORT for http"$ERED
1772
1773 read -p "<press any key to continue>"
1774 __start_container policy_agent "STANDALONE" $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1775 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001776
1777}
1778
1779# All calls to the agent will be directed to the agent REST interface from now on
1780# args: -
1781# (Function for test scripts)
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001782use_agent_rest_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001783 echo -e "Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001784 export ADAPTER=$RESTBASE
1785 echo ""
1786}
1787
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001788# All calls to the agent will be directed to the agent REST interface from now on
1789# args: -
1790# (Function for test scripts)
1791use_agent_rest_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001792 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001793 export ADAPTER=$RESTBASE_SECURE
1794 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001795 return 0
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001796}
1797
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001798# All calls to the agent will be directed to the agent dmaap interface over http from now on
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001799# args: -
1800# (Function for test scripts)
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001801use_agent_dmaap_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001802 echo -e "Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001803 export ADAPTER=$DMAAPBASE
1804 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001805 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001806}
1807
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001808# All calls to the agent will be directed to the agent dmaap interface over https from now on
1809# args: -
1810# (Function for test scripts)
1811use_agent_dmaap_https() {
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001812 echo -e "Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001813 export ADAPTER=$DMAAPBASE_SECURE
1814 echo ""
1815 return 0
1816}
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001817
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001818# Turn on debug level tracing in the agent
1819# args: -
1820# (Function for test scripts)
1821set_agent_debug() {
1822 echo -e $BOLD"Setting agent debug"$EBOLD
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02001823 actuator="/actuator/loggers/org.oransc.policyagent"
1824 if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
1825 actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
1826 fi
1827 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001828 result=$(__do_curl "$curlString")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001829 if [ $? -ne 0 ]; then
1830 __print_err "could not set debug mode" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001831 ((RES_CONF_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001832 return 1
1833 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001834 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001835 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001836}
1837
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001838# Turn on trace level tracing in the agent
1839# args: -
1840# (Function for test scripts)
1841set_agent_trace() {
1842 echo -e $BOLD"Setting agent trace"$EBOLD
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02001843 actuator="/actuator/loggers/org.oransc.policyagent"
1844 if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
1845 actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
1846 fi
1847 curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001848 result=$(__do_curl "$curlString")
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001849 if [ $? -ne 0 ]; then
1850 __print_err "could not set trace mode" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001851 ((RES_CONF_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001852 return 1
1853 fi
1854 echo ""
1855 return 0
1856}
1857
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001858# Perform curl retries when making direct call to the agent for the specified http response codes
1859# Speace separated list of http response codes
1860# args: [<response-code>]*
1861use_agent_retries() {
1862 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
1863 AGENT_RETRY_CODES=$@
1864 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001865 return
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001866}
1867
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001868###########################
1869### ECS functions
1870###########################
1871
1872# Start the ECS
1873# args: -
1874# (Function for test scripts)
1875start_ecs() {
1876
1877 echo -e $BOLD"Starting ECS"$EBOLD
BjornMagnussonXA2791e082020-11-12 00:52:08 +01001878
1879 curdir=$PWD
1880 cd $SIM_GROUP
1881 cd ecs
1882 cd $ECS_HOST_MNT_DIR
1883 if [ -d database ]; then
1884 echo -e $BOLD" Cleaning files in mounted dir: $PWD/database"$EBOLD
1885 rm database/* > /dev/null
1886 if [ $? -ne 0 ]; then
1887 echo -e $RED" Cannot remove database files in: $PWD"$ERED
1888 exit 1
1889 fi
1890 else
1891 echo " No files in mounted dir or dir does not exists"
1892 fi
1893 cd $curdir
1894
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001895 __check_included_image 'ECS'
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001896 if [ $? -eq 1 ]; then
1897 echo -e $RED"The ECS image has not been checked for this test run due to arg to the test script"$ERED
1898 echo -e $RED"ECS will not be started"$ERED
1899 exit
1900 fi
1901 export ECS_CERT_MOUNT_DIR="./cert"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001902 __start_container ecs NODOCKERARGS $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001903}
1904
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001905# Restart ECS
1906# args: -
1907# (Function for test scripts)
1908restart_ecs() {
1909 docker restart $ECS_APP_NAME &> ./tmp/.dockererr
1910 if [ $? -ne 0 ]; then
1911 __print_err "Could restart $ECS_APP_NAME" $@
1912 cat ./tmp/.dockererr
1913 ((RES_CONF_FAIL++))
1914 return 1
1915 fi
1916
1917 __check_container_start $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
1918 echo ""
1919 return 0
1920}
1921
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001922# All calls to ECS will be directed to the ECS REST interface from now on
1923# args: -
1924# (Function for test scripts)
1925use_ecs_rest_http() {
1926 echo -e "Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
1927 export ECS_ADAPTER=$ECS_RESTBASE
1928 echo ""
1929}
1930
1931# All calls to ECS will be directed to the ECS REST interface from now on
1932# args: -
1933# (Function for test scripts)
1934use_ecs_rest_https() {
1935 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
1936 export ECS_ADAPTER=$ECS_RESTBASE_SECURE
1937 echo ""
1938 return 0
1939}
1940
1941# All calls to ECS will be directed to the ECS dmaap interface over http from now on
1942# args: -
1943# (Function for test scripts)
1944use_ecs_dmaap_http() {
1945 echo -e "Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
1946 export ECS_ADAPTER=$ECS_DMAAPBASE
1947 echo ""
1948 return 0
1949}
1950
1951# All calls to ECS will be directed to the ECS dmaap interface over https from now on
1952# args: -
1953# (Function for test scripts)
1954use_ecs_dmaap_https() {
1955 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
1956 export ECS_ADAPTER=$ECS_DMAAPBASE_SECURE
1957 echo ""
1958 return 0
1959}
1960
1961# Turn on debug level tracing in ECS
1962# args: -
1963# (Function for test scripts)
1964set_ecs_debug() {
1965 echo -e $BOLD"Setting ecs debug"$EBOLD
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001966 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
1967 result=$(__do_curl "$curlString")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001968 if [ $? -ne 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001969 __print_err "Could not set debug mode" $@
1970 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001971 return 1
1972 fi
1973 echo ""
1974 return 0
1975}
1976
1977# Turn on trace level tracing in ECS
1978# args: -
1979# (Function for test scripts)
1980set_ecs_trace() {
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001981 echo -e $BOLD"Setting ecs trace"$EBOLD
1982 curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
1983 result=$(__do_curl "$curlString")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001984 if [ $? -ne 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001985 __print_err "Could not set trace mode" $@
1986 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001987 return 1
1988 fi
1989 echo ""
1990 return 0
1991}
1992
1993# Perform curl retries when making direct call to ECS for the specified http response codes
1994# Speace separated list of http response codes
1995# args: [<response-code>]*
1996use_agent_retries() {
1997 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
1998 ECS_AGENT_RETRY_CODES=$@
1999 echo ""
2000 return
2001}
2002
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002003#################
2004### Log functions
2005#################
2006
2007# Check the agent logs for WARNINGs and ERRORs
2008# args: -
2009# (Function for test scripts)
2010
YongchaoWu9a84f512019-12-16 22:54:11 +01002011check_policy_agent_logs() {
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002012 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
YongchaoWu9a84f512019-12-16 22:54:11 +01002013}
2014
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002015check_ecs_logs() {
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002016 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002017}
2018
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002019check_control_panel_logs() {
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002020 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH WARN ERR
2021}
2022
2023check_sdnc_logs() {
2024 __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
YongchaoWu9a84f512019-12-16 22:54:11 +01002025}
2026
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002027__check_container_logs() {
2028 dispname=$1
2029 appname=$2
2030 logpath=$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002031 warning=$4
2032 error=$5
2033
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002034 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
2035
2036 #tmp=$(docker ps | grep $appname)
2037 tmp=$(docker ps -q --filter name=$appname) #get the container id
2038 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
2039 echo $dispname" is not running, no check made"
2040 return
2041 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002042 foundentries="$(docker exec -t $tmp grep $warning $logpath | wc -l)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002043 if [ $? -ne 0 ];then
2044 echo " Problem to search $appname log $logpath"
2045 else
2046 if [ $foundentries -eq 0 ]; then
2047 echo " No WARN entries found in $appname log $logpath"
2048 else
2049 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
2050 fi
2051 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002052 foundentries="$(docker exec -t $tmp grep $error $logpath | wc -l)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002053 if [ $? -ne 0 ];then
2054 echo " Problem to search $appname log $logpath"
2055 else
2056 if [ $foundentries -eq 0 ]; then
2057 echo " No ERR entries found in $appname log $logpath"
2058 else
2059 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
2060 fi
2061 fi
2062 echo ""
2063}
2064
2065# Store all container logs and other logs in the log dir for the script
2066# Logs are stored with a prefix in case logs should be stored several times during a test
2067# args: <logfile-prefix>
2068# (Function for test scripts)
YongchaoWu9a84f512019-12-16 22:54:11 +01002069store_logs() {
2070 if [ $# != 1 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002071 ((RES_CONF_FAIL++))
2072 __print_err "need one arg, <file-prefix>" $@
YongchaoWu9a84f512019-12-16 22:54:11 +01002073 exit 1
2074 fi
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01002075 echo -e $BOLD"Storing all container logs in $TESTLOGS/$ATC using prefix: "$1$EBOLD
YongchaoWu9a84f512019-12-16 22:54:11 +01002076
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02002077 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002078
2079 __check_included_image 'CONSUL'
2080 if [ $? -eq 0 ]; then
2081 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
2082 fi
2083
2084 __check_included_image 'CBS'
2085 if [ $? -eq 0 ]; then
2086 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
2087 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
2088 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
2089 fi
2090
2091 __check_included_image 'PA'
2092 if [ $? -eq 0 ]; then
2093 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
2094 fi
2095
2096 __check_included_image 'ECS'
2097 if [ $? -eq 0 ]; then
2098 docker logs $ECS_APP_NAME > $TESTLOGS/$ATC/$1_ecs.log 2>&1
2099 fi
2100
2101 __check_included_image 'CP'
2102 if [ $? -eq 0 ]; then
2103 docker logs $CONTROL_PANEL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
2104 fi
2105
2106 __check_included_image 'MR'
2107 if [ $? -eq 0 ]; then
2108 docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
2109 fi
2110
2111 __check_included_image 'CR'
2112 if [ $? -eq 0 ]; then
2113 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
2114 fi
2115
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002116 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
2117
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002118 __check_included_image 'SDNC'
2119 if [ $? -eq 0 ]; then
2120 docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
2121 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002122
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002123 __check_included_image 'RICSIM'
2124 if [ $? -eq 0 ]; then
2125 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
2126 for ric in $rics; do
2127 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
2128 done
2129 fi
2130
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02002131 __check_included_image 'PRODSTUB'
2132 if [ $? -eq 0 ]; then
2133 docker logs $PROD_STUB_APP_NAME > $TESTLOGS/$ATC/$1_prodstub.log 2>&1
2134 fi
2135
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002136 echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +01002137}
2138
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002139###############
2140## Generic curl
2141###############
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002142# Generic curl function, assumes all 200-codes are ok
2143# args: <valid-curl-args-including full url>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002144# returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
2145# returns: The return code is 0 for ok and 1 for not ok
YongchaoWu9a84f512019-12-16 22:54:11 +01002146__do_curl() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002147 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002148 curlString="curl -skw %{http_code} $@"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002149 echo " CMD: $curlString" >> $HTTPLOG
2150 res=$($curlString)
2151 echo " RESP: $res" >> $HTTPLOG
YongchaoWu9a84f512019-12-16 22:54:11 +01002152 http_code="${res:${#res}-3}"
2153 if [ ${#res} -eq 3 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002154 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
2155 echo "<no-response-from-server>"
2156 return 1
2157 else
2158 echo "X2" >> $HTTPLOG
2159 return 0
2160 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01002161 else
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002162 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
YongchaoWu9a84f512019-12-16 22:54:11 +01002163 echo "<not found, resp:${http_code}>"
2164 return 1
2165 fi
2166 if [ $# -eq 2 ]; then
2167 echo "${res:0:${#res}-3}" | xargs
2168 else
2169 echo "${res:0:${#res}-3}"
2170 fi
2171
2172 return 0
2173 fi
2174}
2175
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002176#######################################
2177### Basic helper function for test cases
2178#######################################
2179
2180# Test a simulator container variable value towards target value using an condition operator with an optional timeout.
2181# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
2182# immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
2183# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
2184# before setting pass or fail depending on the result of comparing variable and target using the operator.
2185# 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.
2186# Not to be called from test script.
2187
2188__var_test() {
2189 checkjsonarraycount=0
2190
2191 if [ $# -eq 6 ]; then
2192 if [[ $3 == "json:"* ]]; then
2193 checkjsonarraycount=1
2194 fi
2195
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02002196 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002197 ((RES_TEST++))
2198 start=$SECONDS
2199 ctr=0
2200 for (( ; ; )); do
2201 if [ $checkjsonarraycount -eq 0 ]; then
2202 result="$(__do_curl $2$3)"
2203 retcode=$?
2204 result=${result//[[:blank:]]/} #Strip blanks
2205 else
2206 path=${3:5}
2207 result="$(__do_curl $2$path)"
2208 retcode=$?
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002209 echo "$result" > ./tmp/.tmp.curl.json
2210 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002211 fi
2212 duration=$((SECONDS-start))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002213 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002214 let ctr=ctr+1
2215 if [ $retcode -ne 0 ]; then
2216 if [ $duration -gt $6 ]; then
2217 ((RES_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002218 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002219 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002220 return
2221 fi
2222 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2223 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002224 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002225 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002226 return
2227 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2228 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002229 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002230 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002231 return
2232 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2233 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002234 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002235 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002236 return
2237 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2238 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002239 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002240 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002241 return
2242 else
2243 if [ $duration -gt $6 ]; then
2244 ((RES_FAIL++))
2245 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002246 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002247 return
2248 fi
2249 fi
2250 sleep 1
2251 done
2252 elif [ $# -eq 5 ]; then
2253 if [[ $3 == "json:"* ]]; then
2254 checkjsonarraycount=1
2255 fi
2256
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002257 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
2258 ((RES_TEST++))
2259 if [ $checkjsonarraycount -eq 0 ]; then
2260 result="$(__do_curl $2$3)"
2261 retcode=$?
2262 result=${result//[[:blank:]]/} #Strip blanks
2263 else
2264 path=${3:5}
2265 result="$(__do_curl $2$path)"
2266 retcode=$?
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002267 echo "$result" > ./tmp/.tmp.curl.json
2268 result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002269 fi
2270 if [ $retcode -ne 0 ]; then
2271 ((RES_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002272 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002273 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002274 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2275 ((RES_PASS++))
2276 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002277 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2278 ((RES_PASS++))
2279 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002280 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2281 ((RES_PASS++))
2282 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002283 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2284 ((RES_PASS++))
2285 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002286 else
2287 ((RES_FAIL++))
2288 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002289 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002290 fi
2291 else
2292 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
2293 echo "Got:" $@
2294 exit 1
2295 fi
2296}
2297
2298
2299### Generic test cases for varaible checking
2300
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002301# Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
2302# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2303# equal to the target or not.
2304# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2305# before setting pass or fail depending on if the variable value becomes equal to the target
2306# value or not.
2307# (Function for test scripts)
2308mr_equal() {
2309 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2310 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
2311 else
2312 ((RES_CONF_FAIL++))
2313 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2314 fi
2315}
2316
2317# Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
2318# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2319# greater than the target or not.
2320# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2321# before setting pass or fail depending on if the variable value becomes greater than the target
2322# value or not.
2323# (Function for test scripts)
2324mr_greater() {
2325 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002326 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 ">" $2 $3
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002327 else
2328 ((RES_CONF_FAIL++))
2329 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2330 fi
2331}
2332
2333# Read a variable value from MR sim and send to stdout. Arg: <variable-name>
2334mr_read() {
2335 echo "$(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"
2336}
2337
2338# Print a variable value from the MR stub.
2339# arg: <variable-name>
2340# (Function for test scripts)
2341mr_print() {
2342 if [ $# != 1 ]; then
2343 ((RES_CONF_FAIL++))
2344 __print_err "need one arg, <mr-param>" $@
2345 exit 1
2346 fi
2347 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"$EBOLD
2348}