blob: a90700aa58624e716ae3f07ead910c9442b374dc [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/bin/bash
YongchaoWu9a84f512019-12-16 22:54:11 +01002
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003# ============LICENSE_START===============================================
4# Copyright (C) 2020 Nordix Foundation. All rights reserved.
5# ========================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ============LICENSE_END=================================================
18#
YongchaoWu9a84f512019-12-16 22:54:11 +010019
YongchaoWuffde6eb2020-01-17 13:58:51 +010020# This is a script that contains all the functions needed for auto test
BjornMagnussonXA575869c2020-09-14 21:28:54 +020021# Arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--ricsim-prefix <prefix> ] [ --env-file <environment-filename> ] [--use-local-image <app-nam> [<app-name>]*]
YongchaoWuffde6eb2020-01-17 13:58:51 +010022
BjornMagnussonXA72667f12020-04-24 09:20:18 +020023
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020024# Create a test case id, ATC (Auto Test Case), from the name of the test case script.
25# FTC1.sh -> ATC == FTC1
26ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
27
28#Create result file (containing '1' for error) for this test case
29#Will be replaced with a file containing '0' if all test cases pass
30echo "1" > "$PWD/.result$ATC.txt"
31
BjornMagnussonXA80a92002020-03-19 14:31:06 +010032#Formatting for 'echo' cmd
33BOLD="\033[1m"
34EBOLD="\033[0m"
35RED="\033[31m\033[1m"
36ERED="\033[0m"
37GREEN="\033[32m\033[1m"
38EGREEN="\033[0m"
39YELLOW="\033[33m\033[1m"
40EYELLOW="\033[0m"
BjornMagnussonXA72667f12020-04-24 09:20:18 +020041SAMELINE="\033[0K\r"
42
43tmp=$(which python3)
44if [ $? -ne 0 ] || [ -z tmp ]; then
45 echo -e $RED"python3 is required to run the test environment, pls install"$ERED
46 exit 1
47fi
48tmp=$(which docker)
49if [ $? -ne 0 ] || [ -z tmp ]; then
50 echo -e $RED"docker is required to run the test environment, pls install"$ERED
51 exit 1
52fi
YongchaoWu9a84f512019-12-16 22:54:11 +010053
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020054tmp=$(which docker-compose)
55if [ $? -ne 0 ] || [ -z tmp ]; then
56 echo -e $RED"docker-compose is required to run the test environment, pls install"$ERED
57 exit 1
58fi
59
BjornMagnussonXA80a92002020-03-19 14:31:06 +010060# Just resetting any previous echo formatting...
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020061echo -ne $EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +010062
BjornMagnussonXA575869c2020-09-14 21:28:54 +020063# default test environment variables
64TEST_ENV_VAR_FILE="../common/test_env.sh"
BjornMagnussonXA80a92002020-03-19 14:31:06 +010065
66echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@
67
BjornMagnussonXA80a92002020-03-19 14:31:06 +010068#Localhost constant
69LOCALHOST="http://localhost:"
70
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020071# Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
72ECS_RETRY_CODES=""
73
74# Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
BjornMagnussonXA80a92002020-03-19 14:31:06 +010075AGENT_RETRY_CODES=""
76
BjornMagnussonXA70e878f2020-05-11 14:11:30 +020077# Var to contol if the agent runs in a container (normal = 0) or as application on the local machine ( = 1)
78AGENT_STAND_ALONE=0
79
BjornMagnussonXA80a92002020-03-19 14:31:06 +010080# Var to hold 'auto' in case containers shall be stopped when test case ends
81AUTO_CLEAN=""
YongchaoWu9a84f512019-12-16 22:54:11 +010082
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +020083# Var to hold the app names to use local image for when running 'remote' or 'remote-remove'
84USE_LOCAL_IMAGES=""
85
BjornMagnussonXAad047782020-06-08 15:54:11 +020086# List of available apps to override with local image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020087AVAILABLE_LOCAL_IMAGES_OVERRIDE="PA ECS CP SDNC RICSIM"
BjornMagnussonXAad047782020-06-08 15:54:11 +020088
BjornMagnussonXA048aaa12020-06-04 07:48:37 +020089# Use this var (STOP_AT_ERROR=1 in the test script) for debugging/trouble shooting to take all logs and exit at first FAIL test case
90STOP_AT_ERROR=0
91
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020092# Function to indent cmd output with one space
93indent1() { sed 's/^/ /'; }
94
95# Function to indent cmd output with two spaces
96indent2() { sed 's/^/ /'; }
97
YongchaoWu9a84f512019-12-16 22:54:11 +010098# Set a description string for the test case
99if [ -z "$TC_ONELINE_DESCR" ]; then
100 TC_ONELINE_DESCR="<no-description>"
101 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
102fi
103
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100104# Counter for test suites
105if [ -f .tmp_tcsuite_ctr ]; then
106 tmpval=$(< .tmp_tcsuite_ctr)
107 ((tmpval++))
108 echo $tmpval > .tmp_tcsuite_ctr
109fi
YongchaoWu9a84f512019-12-16 22:54:11 +0100110
YongchaoWu9a84f512019-12-16 22:54:11 +0100111# Create the logs dir if not already created in the current dir
112if [ ! -d "logs" ]; then
113 mkdir logs
114fi
YongchaoWu9a84f512019-12-16 22:54:11 +0100115TESTLOGS=$PWD/logs
116
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100117# Create a http message log for this testcase
118HTTPLOG=$PWD"/.httplog_"$ATC".txt"
119echo "" > $HTTPLOG
120
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200121
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100122# Create a log dir for the test case
YongchaoWu9a84f512019-12-16 22:54:11 +0100123mkdir -p $TESTLOGS/$ATC
124
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100125# Clear the log dir for the test case
126rm $TESTLOGS/$ATC/*.log &> /dev/null
127rm $TESTLOGS/$ATC/*.txt &> /dev/null
128rm $TESTLOGS/$ATC/*.json &> /dev/null
129
130# Log all output from the test case to a TC log
YongchaoWu9a84f512019-12-16 22:54:11 +0100131TCLOG=$TESTLOGS/$ATC/TC.log
132exec &> >(tee ${TCLOG})
133
134#Variables for counting tests as well as passed and failed tests
135RES_TEST=0
136RES_PASS=0
137RES_FAIL=0
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100138RES_CONF_FAIL=0
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200139RES_DEVIATION=0
140
141#File to keep deviation messages
142DEVIATION_FILE=".tmp_deviations"
143rm $DEVIATION_FILE &> /dev/null
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100144
145#Var for measuring execution time
YongchaoWu9a84f512019-12-16 22:54:11 +0100146TCTEST_START=$SECONDS
147
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200148#File to save timer measurement results
149TIMER_MEASUREMENTS=".timer_measurement.txt"
150echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS
151
152
YongchaoWu9a84f512019-12-16 22:54:11 +0100153echo "-------------------------------------------------------------------------------------------------"
154echo "----------------------------------- Test case: "$ATC
155echo "----------------------------------- Started: "$(date)
156echo "-------------------------------------------------------------------------------------------------"
157echo "-- Description: "$TC_ONELINE_DESCR
158echo "-------------------------------------------------------------------------------------------------"
159echo "----------------------------------- Test case setup -----------------------------------"
160
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200161START_ARG=$1
162paramerror=0
163if [ $# -lt 1 ]; then
164 paramerror=1
165fi
166if [ $paramerror -eq 0 ]; then
167 if [ "$1" != "remote" ] && [ "$1" != "remote-remove" ] && [ "$1" != "local" ]; then
168 paramerror=1
169 else
170 shift;
171 fi
172fi
BjornMagnussonXAad047782020-06-08 15:54:11 +0200173foundparm=0
174while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do
175 foundparm=1
176 if [ $paramerror -eq 0 ]; then
177 if [ "$1" == "auto-clean" ]; then
178 AUTO_CLEAN="auto"
179 echo "Option set - Auto clean at end of test script"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200180 shift;
BjornMagnussonXAad047782020-06-08 15:54:11 +0200181 foundparm=0
182 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200183 fi
BjornMagnussonXAad047782020-06-08 15:54:11 +0200184 if [ $paramerror -eq 0 ]; then
185 if [ "$1" == "--stop-at-error" ]; then
186 STOP_AT_ERROR=1
187 echo "Option set - Stop at first error"
188 shift;
189 foundparm=0
190 fi
191 fi
192 if [ $paramerror -eq 0 ]; then
193 if [ "$1" == "--ricsim-prefix" ]; then
194 shift;
195 RIC_SIM_PREFIX=$1
196 if [ -z "$1" ]; then
197 paramerror=1
198 else
199 echo "Option set - Overriding RIC_SIM_PREFIX with: "$1
200 shift;
201 foundparm=0
202 fi
203 fi
204 fi
205 if [ $paramerror -eq 0 ]; then
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200206 if [ "$1" == "--env-file" ]; then
207 shift;
208 TEST_ENV_VAR_FILE=$1
209 if [ -z "$1" ]; then
210 paramerror=1
211 else
212 echo "Option set - Overriding test_env.sh with: "$1
213 shift;
214 foundparm=0
215 fi
216 fi
217 fi
218 if [ $paramerror -eq 0 ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +0200219 if [ "$1" == "--use-local-image" ]; then
220 USE_LOCAL_IMAGES=""
221 shift
222 while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
223 USE_LOCAL_IMAGES=$USE_LOCAL_IMAGES" "$1
224 if [[ "$AVAILABLE_LOCAL_IMAGES_OVERRIDE" != *"$1"* ]]; then
225 paramerror=1
226 fi
227 shift;
228 done
229 foundparm=0
230 if [ -z "$USE_LOCAL_IMAGES" ]; then
231 paramerror=1
232 else
233 echo "Option set - Override remote images for app(s):"$USE_LOCAL_IMAGES
234 fi
235 fi
236 fi
237done
238echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200239
BjornMagnussonXAad047782020-06-08 15:54:11 +0200240#Still params left?
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200241if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
242 paramerror=1
243fi
244
245if [ $paramerror -eq 1 ]; then
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200246 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 +0200247 exit 1
248fi
249
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200250# sourcing the selected env variables for the test case
251if [ -f "$TEST_ENV_VAR_FILE" ]; then
252 echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD
253 . $TEST_ENV_VAR_FILE
254else
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200255 echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED
BjornMagnussonXA575869c2020-09-14 21:28:54 +0200256 exit 1
257fi
258
259#Vars for A1 interface version and container count
260G1_A1_VERSION=""
261G2_A1_VERSION=""
262G3_A1_VERSION=""
263G1_COUNT=0
264G2_COUNT=0
265G3_COUNT=0
266
267# Vars to switch between http and https. Extra curl flag needed for https
268export RIC_SIM_HTTPX="http"
269export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
270export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
271export RIC_SIM_CERT_MOUNT_DIR="./cert"
272
273export MR_HTTPX="http"
274export MR_PORT=$MR_INTERNAL_PORT
275export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker net
276
277export CR_HTTPX="http"
278export CR_PORT=$CR_INTERNAL_PORT
279export CR_LOCAL_PORT=$CR_EXTERNAL_PORT #When CR is running outside the docker net
280
281export SDNC_HTTPX="http"
282export SDNC_PORT=$SDNC_INTERNAL_PORT
283export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net
284
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100285echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
YongchaoWu9a84f512019-12-16 22:54:11 +0100286
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100287#Temp var to check for image variable name errors
288IMAGE_ERR=0
289#Create a file with image info for later printing as a table
290image_list_file=".image-list"
291echo -e " Container\tImage\ttag" > $image_list_file
292
293# 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 +0200294# 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 +0100295__check_image_var() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200296 if [ $# -ne 6 ]; then
297 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 +0100298 ((IMAGE_ERR++))
299 return
300 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200301 __check_excluded_image $6
302 if [ $? -ne 0 ]; then
303 echo -e "$1\t<image-excluded>\t<no-tag>" >> $image_list_file
304 # Image is excluded since the corresponding app is not used in this test
305 return
306 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100307 tmp=${1}"\t"
308 #Create var from the input var names
309 image="${!4}"
310 tag="${!5}"
311
312 if [ -z $image ]; then
313 echo -e $RED"\$"$4" not set in test_env"$ERED
314 ((IMAGE_ERR++))
315 echo ""
316 tmp=$tmp"<no-image>\t"
317 else
318 tmp=$tmp$image"\t"
319 fi
320 if [ -z $tag ]; then
321 echo -e $RED"\$"$5" not set in test_env"$ERED
322 ((IMAGE_ERR++))
323 echo ""
324 tmp=$tmp"<no-tag>\t"
325 else
326 tmp=$tmp$tag
327 fi
328 echo -e "$tmp" >> $image_list_file
329 #Export the env var
330 export "${3}"=$image":"$tag
331
332 #echo " Configured image for ${1} (script start arg=${2}): "$image":"$tag
333}
334
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200335
336#Check if app local image shall override remote image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200337# Possible IDs for local image override: PA, CP, SDNC, RICSIM, ECS
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200338__check_image_local_override() {
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200339 for im in $USE_LOCAL_IMAGES; do
340 if [ "$1" == "$im" ]; then
341 return 1
342 fi
343 done
344 return 0
345}
346
347#Check if app uses image excluded from this test run
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200348# Possible IDs for image exclusion: PA, CP, SDNC, RICSIM, MR, CR, CBS, CONSUL, ECS
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200349__check_excluded_image() {
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200350 for im in $EXCLUDED_IMAGES; do
351 if [ "$1" == "$im" ]; then
352 return 1
353 fi
354 done
355 return 0
356}
357
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100358# Check that image env setting are available
359echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200360
361if [ $START_ARG == "local" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100362
363 #Local agent image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200364 __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 +0100365
366 #Local Control Panel image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200367 __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 +0100368
369 #Local SNDC image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200370 __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 +0100371
372 #Local ric sim image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200373 __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 +0100374
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200375elif [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100376
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200377 __check_image_local_override 'PA'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200378 if [ $? -eq 0 ]; then
379 #Remote agent image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200380 __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 +0200381 else
382 #Local agent image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200383 __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 +0200384 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100385
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200386 __check_image_local_override 'CP'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200387 if [ $? -eq 0 ]; then
388 #Remote Control Panel image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200389 __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 +0200390 else
391 #Local Control Panel image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200392 __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 +0200393 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100394
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200395 __check_image_local_override 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200396 if [ $? -eq 0 ]; then
397 #Remote SDNC image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200398 __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 +0200399 else
400 #Local SNDC image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200401 __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 +0200402 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100403
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200404 __check_image_local_override 'RICSIM'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200405 if [ $? -eq 0 ]; then
406 #Remote ric sim image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200407 __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 +0200408 else
409 #Local ric sim image
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200410 __check_image_var " RIC Simulator" $START_ARG "RIC_SIM_IMAGE" "RIC_SIM_LOCAL_IMAGE" "RIC_SIM_LOCAL_IMAGE_TAG" RICSIM
411 fi
412
413 __check_image_local_override 'ECS'
414 if [ $? -eq 0 ]; then
415 #Remote ecs image
416 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_REMOTE_IMAGE" "ECS_REMOTE_IMAGE_TAG" ECS
417 else
418 #Local ecs image
419 __check_image_var " ECS" $START_ARG "ECS_IMAGE" "ECS_LOCAL_IMAGE" "ECS_LOCAL_IMAGE_TAG" ECS
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200420 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100421
422else
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200423 #Should never get here....
424 echo "Unknow args: "$@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100425 exit 1
YongchaoWu9a84f512019-12-16 22:54:11 +0100426fi
427
YongchaoWu9a84f512019-12-16 22:54:11 +0100428
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100429# 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 +0200430__check_image_var " Message Router" $START_ARG "MRSTUB_IMAGE" "MRSTUB_LOCAL_IMAGE" "MRSTUB_LOCAL_IMAGE_TAG" MR
431__check_image_var " Callback Receiver" $START_ARG "CR_IMAGE" "CR_LOCAL_IMAGE" "CR_LOCAL_IMAGE_TAG" CR
432__check_image_var " Consul" $START_ARG "CONSUL_IMAGE" "CONSUL_REMOTE_IMAGE" "CONSUL_REMOTE_IMAGE_TAG" CONSUL
433__check_image_var " CBS" $START_ARG "CBS_IMAGE" "CBS_REMOTE_IMAGE" "CBS_REMOTE_IMAGE_TAG" CBS
434__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 +0100435
436#Errors in image setting - exit
437if [ $IMAGE_ERR -ne 0 ]; then
438 exit 1
439fi
440
441#Print a tables of the image settings
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200442echo -e $BOLD"Images configured for start arg: "$START $EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100443column -t -s $'\t' $image_list_file
444
YongchaoWuf309b1b2020-01-22 13:24:48 +0100445echo ""
446
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100447
448#Set the SIM_GROUP var
449echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
450if [ -z "$SIM_GROUP" ]; then
451 SIM_GROUP=$PWD/../simulator-group
452 if [ ! -d $SIM_GROUP ]; then
453 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
454 echo -e $RED"Please set the SIM_GROUP manually in the test_env.sh"$ERED
455 exit 1
456 else
457 echo " SIM_GROUP auto set to: " $SIM_GROUP
458 fi
459elif [ $SIM_GROUP = *simulator_group ]; then
460 echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check common/test_env.sh"$ERED
461 exit 1
462else
463 echo " SIM_GROUP env var already set to: " $SIM_GROUP
maximesson28ee8a52020-03-17 09:32:03 +0100464fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100465
466echo ""
467
468#Temp var to check for image pull errors
469IMAGE_ERR=0
470
471#Function to check if image exist and stop+remove the container+pull new images as needed
472#args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag>
473__check_and_pull_image() {
474
475 echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$4$EBOLD"
476 format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
477 tmp_im=$(docker images --format $format_string ${4})
478
479 if [ $1 == "local" ]; then
480 if [ -z "$tmp_im" ]; then
481 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
482 ((IMAGE_ERR++))
483 return 1
484 else
485 echo -e " "$2" (local image): \033[1m"$4"\033[0m "$GREEN"OK"$EGREEN
486 fi
487 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
488 if [ $1 == "remote-remove" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200489 echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100490 tmp="$(docker ps -aq --filter name=${3})"
491 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200492 docker stop $tmp &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100493 if [ $? -ne 0 ]; then
494 ((IMAGE_ERR++))
495 echo ""
496 echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200497 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100498 return 1
499 fi
500 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200501 echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100502 tmp="$(docker ps -aq --filter name=${3})" &> /dev/null
503 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200504 docker rm $tmp &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100505 if [ $? -ne 0 ]; then
506 ((IMAGE_ERR++))
507 echo ""
508 echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200509 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100510 return 1
511 fi
512 fi
513 echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200514 echo -ne " Removing image - ${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100515 tmp="$(docker images -q ${4})" &> /dev/null
516 if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200517 docker rmi --force $4 &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100518 if [ $? -ne 0 ]; then
519 ((IMAGE_ERR++))
520 echo ""
521 echo -e $RED" Image could not be removed - try manual removal of the image"$ERED
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200522 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100523 return 1
524 fi
525 echo -e " Removing image - "$GREEN"removed"$EGREEN
526 else
527 echo -e " Removing image - "$GREEN"image not in repository"$EGREEN
528 fi
529 tmp_im=""
530 fi
531 if [ -z "$tmp_im" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200532 echo -ne " Pulling image${SAMELINE}"
533 docker pull $4 &> .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100534 tmp_im=$(docker images ${4} | grep -v REPOSITORY)
535 if [ -z "$tmp_im" ]; then
536 echo ""
537 echo -e " Pulling image -$RED could not be pulled"$ERED
538 ((IMAGE_ERR++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200539 cat .dockererr
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100540 return 1
541 fi
542 echo -e " Pulling image -$GREEN Pulled $EGREEN"
543 else
544 echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
545 fi
546 fi
547 return 0
548}
549
550
551echo -e $BOLD"Pulling configured images, if needed"$EBOLD
552
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200553__check_excluded_image 'PA'
554if [ $? -eq 0 ]; then
555 START_ARG_MOD=$START_ARG
556 __check_image_local_override 'PA'
557 if [ $? -eq 1 ]; then
558 START_ARG_MOD="local"
559 fi
560 app="Policy Agent"; __check_and_pull_image $START_ARG_MOD "$app" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
561else
562 echo -e $YELLOW" Excluding PA image from image check/pull"$EYELLOW
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200563fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100564
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200565__check_excluded_image 'ECS'
566if [ $? -eq 0 ]; then
567 START_ARG_MOD=$START_ARG
568 __check_image_local_override 'ECS'
569 if [ $? -eq 1 ]; then
570 START_ARG_MOD="local"
571 fi
572 app="ECS"; __check_and_pull_image $START_ARG_MOD "$app" $ECS_APP_NAME $ECS_IMAGE
573else
574 echo -e $YELLOW" Excluding ECS image from image check/pull"$EYELLOW
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200575fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200576
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200577__check_excluded_image 'CP'
578if [ $? -eq 0 ]; then
579 START_ARG_MOD=$START_ARG
580 __check_image_local_override 'CP'
581 if [ $? -eq 1 ]; then
582 START_ARG_MOD="local"
583 fi
584 app="Non-RT RIC Control Panel"; __check_and_pull_image $START_ARG_MOD "$app" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_IMAGE
585else
586 echo -e $YELLOW" Excluding Non-RT RIC Control Panel image from image check/pull"$EYELLOW
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200587fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100588
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200589__check_excluded_image 'RICSIM'
590if [ $? -eq 0 ]; then
591 START_ARG_MOD=$START_ARG
592 __check_image_local_override 'RICSIM'
593 if [ $? -eq 1 ]; then
594 START_ARG_MOD="local"
595 fi
596 app="Near-RT RIC Simulator"; __check_and_pull_image $START_ARG_MOD "$app" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE $RIC_SIM_IMAGE
597else
598 echo -e $YELLOW" Excluding Near-RT RIC Simulator image from image check/pull"$EYELLOW
599fi
600
601
602__check_excluded_image 'CONSUL'
603if [ $? -eq 0 ]; then
604 app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE
605else
606 echo -e $YELLOW" Excluding Consul image from image check/pull"$EYELLOW
607fi
608
609__check_excluded_image 'CBS'
610if [ $? -eq 0 ]; then
611 app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE
612else
613 echo -e $YELLOW" Excluding CBS image from image check/pull"$EYELLOW
614fi
615
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200616__check_excluded_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200617if [ $? -eq 0 ]; then
618 START_ARG_MOD=$START_ARG
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200619 __check_image_local_override 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200620 if [ $? -eq 1 ]; then
621 START_ARG_MOD="local"
622 fi
623 app="SDNC A1 Controller"; __check_and_pull_image $START_ARG_MOD "$app" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
624 app="SDNC DB"; __check_and_pull_image $START_ARG "$app" $SDNC_APP_NAME $SDNC_DB_IMAGE
625else
626 echo -e $YELLOW" Excluding SDNC image and related DB image from image check/pull"$EYELLOW
627fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100628
629#Errors in image setting - exit
630if [ $IMAGE_ERR -ne 0 ]; then
631 echo ""
632 echo "#################################################################################################"
633 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 +0200634 echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100635 echo "#################################################################################################"
636 echo ""
637 exit 1
638fi
639
640echo ""
641
642echo -e $BOLD"Building images needed for test"$EBOLD
643
644curdir=$PWD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200645__check_excluded_image 'MR'
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100646if [ $? -eq 0 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200647 cd $curdir
648 cd ../mrstub
649 echo " Building mrstub image: mrstub:latest"
650 docker build -t mrstub . &> .dockererr
651 if [ $? -eq 0 ]; then
652 echo -e $GREEN" Build Ok"$EGREEN
653 else
654 echo -e $RED" Build Failed"$ERED
655 ((RES_CONF_FAIL++))
656 cat .dockererr
657 fi
658 cd $curdir
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100659else
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200660 echo -e $YELLOW" Excluding mrstub from image build"$EYELLOW
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100661fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100662
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200663__check_excluded_image 'CR'
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100664if [ $? -eq 0 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200665 cd ../cr
666 echo " Building Callback Receiver image: callback-receiver:latest"
667 docker build -t callback-receiver . &> .dockererr
668 if [ $? -eq 0 ]; then
669 echo -e $GREEN" Build Ok"$EGREEN
670 else
671 echo -e $RED" Build Failed"$ERED
672 ((RES_CONF_FAIL++))
673 cat .dockererr
674 fi
675 cd $curdir
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100676else
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200677 echo -e $YELLOW" Excluding Callback Receiver from image build"$EYELLOW
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100678fi
YongchaoWuf309b1b2020-01-22 13:24:48 +0100679
680echo ""
681
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100682# Create a table of the images used in the script
683echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD
684
685docker_tmp_file=.docker-images-table
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200686format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\\t{{.CreatedAt}}"
687echo -e " Application\tRepository\tTag\tCreated since\tSize\tCreated at" > $docker_tmp_file
688__check_excluded_image 'PA'
689if [ $? -eq 0 ]; then
690 echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file
691fi
692__check_excluded_image 'ECS'
693if [ $? -eq 0 ]; then
694 echo -e " ECS\t$(docker images --format $format_string $ECS_IMAGE)" >> $docker_tmp_file
695fi
696__check_excluded_image 'CP'
697if [ $? -eq 0 ]; then
698 echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file
699fi
700__check_excluded_image 'RICSIM'
701if [ $? -eq 0 ]; then
702 echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file
703fi
704__check_excluded_image 'MR'
705if [ $? -eq 0 ]; then
706 echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file
707fi
708__check_excluded_image 'CR'
709if [ $? -eq 0 ]; then
710 echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file
711fi
712__check_excluded_image 'CONSUL'
713if [ $? -eq 0 ]; then
714 echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file
715fi
716__check_excluded_image 'CBS'
717if [ $? -eq 0 ]; then
718 echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file
719fi
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200720__check_excluded_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200721if [ $? -eq 0 ]; then
722 echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file
723 echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file
724fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100725
726column -t -s $'\t' $docker_tmp_file
727
YongchaoWuf309b1b2020-01-22 13:24:48 +0100728echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +0100729
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100730echo -e $BOLD"======================================================="$EBOLD
731echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
732echo -e $BOLD"======================================================="$EBOLD
733echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +0100734
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100735# Function to print the test result, shall be the last cmd in a test script
736# args: -
737# (Function for test scripts)
738print_result() {
YongchaoWu9a84f512019-12-16 22:54:11 +0100739
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100740 TCTEST_END=$SECONDS
741 duration=$((TCTEST_END-TCTEST_START))
YongchaoWu9a84f512019-12-16 22:54:11 +0100742
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100743 echo "-------------------------------------------------------------------------------------------------"
744 echo "------------------------------------- Test case: "$ATC
745 echo "------------------------------------- Ended: "$(date)
746 echo "-------------------------------------------------------------------------------------------------"
747 echo "-- Description: "$TC_ONELINE_DESCR
748 echo "-- Execution time: " $duration " seconds"
749 echo "-------------------------------------------------------------------------------------------------"
750 echo "------------------------------------- RESULTS"
YongchaoWu4e489b02020-02-24 09:18:16 +0100751 echo ""
YongchaoWu4e489b02020-02-24 09:18:16 +0100752
YongchaoWu21f17bb2020-03-05 12:44:08 +0100753
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200754 if [ $RES_DEVIATION -gt 0 ]; then
755 echo "Test case deviations"
756 echo "===================================="
757 cat $DEVIATION_FILE
758 fi
759 echo ""
760 echo "Timer measurement in the test script"
761 echo "===================================="
762 column -t -s $'\t' $TIMER_MEASUREMENTS
763 echo ""
764
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100765 total=$((RES_PASS+RES_FAIL))
766 if [ $RES_TEST -eq 0 ]; then
767 echo -e "\033[1mNo tests seem to have been executed. Check the script....\033[0m"
768 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
769 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
770 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
771 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
772 elif [ $total != $RES_TEST ]; then
773 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
774 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
775 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
776 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
777 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
778 elif [ $RES_CONF_FAIL -ne 0 ]; then
779 echo -e "\033[1mOne or more configure regest has failed. Check the script log....\033[0m"
780 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
781 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
782 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
783 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
784 elif [ $RES_PASS = $RES_TEST ]; then
785 echo -e "All tests \033[32m\033[1mPASS\033[0m"
786 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
787 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
788 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
789 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
790 echo ""
YongchaoWu21f17bb2020-03-05 12:44:08 +0100791
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100792 # Update test suite counter
793 if [ -f .tmp_tcsuite_pass_ctr ]; then
794 tmpval=$(< .tmp_tcsuite_pass_ctr)
795 ((tmpval++))
796 echo $tmpval > .tmp_tcsuite_pass_ctr
797 fi
798 if [ -f .tmp_tcsuite_pass ]; then
799 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
800 fi
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200801 #Create file with OK exit code
802 echo "0" > "$PWD/.result$ATC.txt"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100803 else
804 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
805 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
806 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
807 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
808 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
809 echo ""
810 # Update test suite counter
811 if [ -f .tmp_tcsuite_fail_ctr ]; then
812 tmpval=$(< .tmp_tcsuite_fail_ctr)
813 ((tmpval++))
814 echo $tmpval > .tmp_tcsuite_fail_ctr
815 fi
816 if [ -f .tmp_tcsuite_fail ]; then
817 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
818 fi
YongchaoWu21f17bb2020-03-05 12:44:08 +0100819 fi
YongchaoWu21f17bb2020-03-05 12:44:08 +0100820
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100821 echo "++++ Number of tests: "$RES_TEST
822 echo "++++ Number of passed tests: "$RES_PASS
823 echo "++++ Number of failed tests: "$RES_FAIL
YongchaoWu4e489b02020-02-24 09:18:16 +0100824 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100825 echo "++++ Number of failed configs: "$RES_CONF_FAIL
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200826 echo ""
827 echo "++++ Number of test case deviations: "$RES_DEVIATION
828 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100829 echo "------------------------------------- Test case complete ---------------------------------"
830 echo "-------------------------------------------------------------------------------------------------"
YongchaoWu9a84f512019-12-16 22:54:11 +0100831 echo ""
832}
833
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100834#####################################################################
835###### Functions for start, configuring, stoping, cleaning etc ######
836#####################################################################
YongchaoWu21f17bb2020-03-05 12:44:08 +0100837
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200838# Start timer for time measurement
839# args - (any args will be printed though)
840start_timer() {
841 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
842 TC_TIMER=$SECONDS
843 echo " Timer started"
844}
845
846# Print the value of the time (in seconds)
847# args - <timer message to print> - timer value and message will be printed both on screen
848# and in the timer measurement report
849print_timer() {
850 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
851 if [ $# -lt 1 ]; then
852 ((RES_CONF_FAIL++))
853 __print_err "need 1 or more args, <timer message to print>" $@
854 exit 1
855 fi
856 duration=$(($SECONDS-$TC_TIMER))
857 if [ $duration -eq 0 ]; then
858 duration="<1 second"
859 else
860 duration=$duration" seconds"
861 fi
862 echo " Timer duration :" $duration
863
864 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
865}
866
867# Print the value of the time (in seconds) and reset the timer
868# args - <timer message to print> - timer value and message will be printed both on screen
869# and in the timer measurement report
870print_and_reset_timer() {
871 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
872 if [ $# -lt 1 ]; then
873 ((RES_CONF_FAIL++))
874 __print_err "need 1 or more args, <timer message to print>" $@
875 exit 1
876 fi
877 duration=$(($SECONDS-$TC_TIMER))" seconds"
878 if [ $duration -eq 0 ]; then
879 duration="<1 second"
880 else
881 duration=$duration" seconds"
882 fi
883 echo " Timer duration :" $duration
884 TC_TIMER=$SECONDS
885 echo " Timer reset"
886
887 echo -e "${@:1} \t $duration" >> $TIMER_MEASUREMENTS
888
889}
890# Print info about a deviations from intended tests
891# Each deviation counted is also printed in the testreport
892# args <deviation message to print>
893deviation() {
894 echo -e $BOLD"DEVIATION(${BASH_LINENO[0]}): "${FUNCNAME[0]} $EBOLD
895 if [ $# -lt 1 ]; then
896 ((RES_CONF_FAIL++))
897 __print_err "need 1 or more args, <deviation message to print>" $@
898 exit 1
899 fi
900 ((RES_DEVIATION++))
901 echo -e $BOLD$YELLOW" Test case deviation: ${@:1}"$EYELLOW$EBOLD
902 echo "Line: ${BASH_LINENO[0]} - ${@:1}" >> $DEVIATION_FILE
903 echo ""
904}
YongchaoWu21f17bb2020-03-05 12:44:08 +0100905
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200906# Stop at first FAIL test case and take all logs - only for debugging/trouble shooting
907__check_stop_at_error() {
908 if [ $STOP_AT_ERROR -eq 1 ]; then
909 echo -e $RED"Test script configured to stop at first FAIL, taking all logs and stops"$ERED
910 store_logs "STOP_AT_ERROR"
911 exit 1
912 fi
913 return 0
914}
915
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200916# Check if app name var is set. If so return the app name otherwise return "NOTSET"
917__check_app_name() {
918 if [ $# -eq 1 ]; then
919 echo $1
920 else
921 echo "NOTSET"
922 fi
923}
924
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100925# Stop and remove all containers
926# args: -
927# (Function for test scripts)
YongchaoWu9a84f512019-12-16 22:54:11 +0100928clean_containers() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100929
930 echo -e $BOLD"Stopping and removing all running containers, by container name"$EBOLD
931
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200932 CONTAINTER_NAMES=("Policy Agent " $(__check_app_name $POLICY_AGENT_APP_NAME)\
933 "ECS " $(__check_app_name $ECS_APP_NAME)\
934 "Non-RT RIC Simulator(s)" $(__check_app_name $RIC_SIM_PREFIX)\
935 "Message Router " $(__check_app_name $MR_APP_NAME)\
936 "Callback Receiver " $(__check_app_name $CR_APP_NAME)\
937 "Control Panel " $(__check_app_name $CONTROL_PANEL_APP_NAME)\
938 "SDNC A1 Controller " $(__check_app_name $SDNC_APP_NAME)\
939 "SDNC DB " $(__check_app_name $SDNC_DB_APP_NAME)\
940 "CBS " $(__check_app_name $CBS_APP_NAME)\
941 "Consul " $(__check_app_name $CONSUL_APP_NAME))
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100942
943 nw=0 # Calc max width of container name, to make a nice table
944 for (( i=1; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200945
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100946 if [ ${#CONTAINTER_NAMES[i]} -gt $nw ]; then
947 nw=${#CONTAINTER_NAMES[i]}
948 fi
949 done
950
951 for (( i=0; i<${#CONTAINTER_NAMES[@]} ; i+=2 )) ; do
952 APP="${CONTAINTER_NAMES[i]}"
953 CONTR="${CONTAINTER_NAMES[i+1]}"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200954 if [ $CONTR != "NOTSET" ]; then
955 for((w=${#CONTR}; w<$nw; w=w+1)); do
956 CONTR="$CONTR "
957 done
958 echo -ne " $APP: $CONTR - ${GREEN}stopping${EGREEN}${SAMELINE}"
959 docker stop $(docker ps -qa --filter name=${CONTR}) &> /dev/null
960 echo -ne " $APP: $CONTR - ${GREEN}stopped${EGREEN}${SAMELINE}"
961 docker rm --force $(docker ps -qa --filter name=${CONTR}) &> /dev/null
962 echo -e " $APP: $CONTR - ${GREEN}stopped removed${EGREEN}"
963 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100964 done
965
YongchaoWu9a84f512019-12-16 22:54:11 +0100966 echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200967
968 echo -e $BOLD" Removing docker network"$EBOLD
969 TMP=$(docker network ls -q --filter name=$DOCKER_SIM_NWNAME)
970 if [ "$TMP" == $DOCKER_SIM_NWNAME ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200971 docker network rm $DOCKER_SIM_NWNAME | indent2
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200972 if [ $? -ne 0 ]; then
973 echo -e $RED" Cannot remove docker network. Manually remove or disconnect containers from $DOCKER_SIM_NWNAME"$ERED
974 exit 1
975 fi
976 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200977 echo -e "$GREEN Done$EGREEN"
978 echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200979
980 echo -e $BOLD" Removing all unused docker neworks"$EBOLD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200981 docker network prune --force | indent2
982 echo -e "$GREEN Done$EGREEN"
983 echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200984
985 echo -e $BOLD" Removing all unused docker volumes"$EBOLD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200986 docker volume prune --force | indent2
987 echo -e "$GREEN Done$EGREEN"
988 echo ""
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200989
990 echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD
991 docker rmi --force $(docker images -q -f dangling=true) &> /dev/null
992 echo ""
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200993 echo -e "$GREEN Done$EGREEN"
994 echo ""
BjornMagnussonXAad047782020-06-08 15:54:11 +0200995
996 CONTRS=$(docker ps | awk '$1 != "CONTAINER" { n++ }; END { print n+0 }')
997 if [ $? -eq 0 ]; then
998 if [ $CONTRS -ne 0 ]; then
999 echo -e $RED"Containers running, may cause distubance to the test case"$ERED
1000 docker ps -a
1001 fi
1002 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001003}
1004
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001005# Function stop and remove all container in the end of the test script, if the arg 'auto-clean' is given at test script start
1006# args: -
1007# (Function for test scripts)
1008auto_clean_containers() {
1009 echo
1010 if [ "$AUTO_CLEAN" == "auto" ]; then
1011 echo -e $BOLD"Initiating automatic cleaning of started containers"$EBOLD
1012 clean_containers
YongchaoWu9a84f512019-12-16 22:54:11 +01001013 fi
1014}
1015
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001016# Function to sleep a test case for a numner of seconds. Prints the optional text args as info
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001017# args: <sleep-time-in-sec> [any-text-in-quotes-to-be-printed]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001018# (Function for test scripts)
1019sleep_wait() {
YongchaoWu9a84f512019-12-16 22:54:11 +01001020
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001021 echo -e $BOLD"INFO(${BASH_LINENO[0]}): "${FUNCNAME[0]}"," $@ $EBOLD
1022 if [ $# -lt 1 ]; then
1023 ((RES_CONF_FAIL++))
1024 __print_err "need at least one arg, <sleep-time-in-sec> [any-text-to-printed]" $@
1025 exit 1
1026 fi
1027 #echo "---- Sleep for " $1 " seconds ---- "$2
1028 start=$SECONDS
1029 duration=$((SECONDS-start))
1030 while [ $duration -lt $1 ]; do
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001031 echo -ne " Slept for ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001032 sleep 1
1033 duration=$((SECONDS-start))
1034 done
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001035 echo -ne " Slept for ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001036 echo ""
1037}
1038
1039# Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
1040# Not to be called from the test script itself.
1041__print_err() {
1042 echo -e $RED ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[2]} " line" ${BASH_LINENO[1]} $ERED
1043 if [ $# -gt 1 ]; then
1044 echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED
1045 fi
1046}
1047
1048
1049# Helper function to get a the port of a specific ric simulatpor
1050# args: <ric-id>
1051# (Not for test scripts)
1052__find_sim_port() {
1053 name=$1" " #Space appended to prevent matching 10 if 1 is desired....
ecaiyanlinux99a769b2020-05-15 13:58:02 +02001054 cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}"
1055 res=$(eval $cmdstr)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001056 if [[ "$res" =~ ^[0-9]+$ ]]; then
1057 echo $res
1058 else
1059 echo "0"
1060 fi
1061}
1062
1063# Function to create the docker network for the test
1064# Not to be called from the test script itself.
1065__create_docker_network() {
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001066 tmp=$(docker network ls --format={{.Name}} --filter name=$DOCKER_SIM_NWNAME)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001067 if [ $? -ne 0 ]; then
1068 echo -e $RED" Could not check if docker network $DOCKER_SIM_NWNAME exists"$ERED
1069 return 1
1070 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001071 if [ "$tmp" != $DOCKER_SIM_NWNAME ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001072 echo -e " Creating docker network:$BOLD $DOCKER_SIM_NWNAME $EBOLD"
1073 docker network create $DOCKER_SIM_NWNAME | indent2
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001074 if [ $? -ne 0 ]; then
1075 echo -e $RED" Could not create docker network $DOCKER_SIM_NWNAME"$ERED
1076 return 1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001077 else
1078 echo -e "$GREEN Done$EGREEN"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001079 fi
1080 else
1081 echo -e " Docker network $DOCKER_SIM_NWNAME already exists$GREEN OK $EGREEN"
1082 fi
1083}
1084
1085# Check if container is started by calling url on localhost using a port, expects response code 2XX
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001086# args: <container-name> <port> <url> https|https
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001087# Not to be called from the test script itself.
1088__check_container_start() {
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001089 paramError=0
1090 if [ $# -ne 4 ]; then
1091 paramError=1
1092 elif [ $4 != "http" ] && [ $4 != "https" ]; then
1093 paramError=1
1094 fi
1095 if [ $paramError -ne 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001096 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001097 __print_err "need 3 args, <container-name> <port> <url> https|https" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001098 return 1
1099 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001100 echo -ne " Container $BOLD$1$EBOLD starting${SAMELINE}"
YongchaoWu9a84f512019-12-16 22:54:11 +01001101 appname=$1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001102 localport=$2
1103 url=$3
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001104 if [[ $appname != "STANDALONE_"* ]] ; then
1105 app_started=0
1106 for i in {1..10}; do
1107 if [ "$(docker inspect --format '{{ .State.Running }}' $appname)" == "true" ]; then
1108 echo -e " Container $BOLD$1$EBOLD$GREEN running$EGREEN on$BOLD image $(docker inspect --format '{{ .Config.Image }}' ${appname}) $EBOLD"
1109 app_started=1
1110 break
1111 else
1112 sleep $i
1113 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001114 done
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001115 if [ $app_started -eq 0 ]; then
1116 ((RES_CONF_FAIL++))
1117 echo ""
1118 echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
1119 return 1
1120 fi
1121 if [ $localport -eq 0 ]; then
1122 while [ $localport -eq 0 ]; do
1123 echo -ne " Waiting for container ${appname} to publish its ports...${SAMELINE}"
1124 localport=$(__find_sim_port $appname)
1125 sleep 1
1126 echo -ne " Waiting for container ${appname} to publish its ports...retrying....${SAMELINE}"
1127 done
1128 echo -ne " Waiting for container ${appname} to publish its ports...retrying....$GREEN OK $EGREEN"
1129 echo ""
1130 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001131 fi
1132
1133 pa_st=false
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001134 echo -ne " Waiting for container ${appname} service status...${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001135 TSTART=$SECONDS
1136 for i in {1..50}; do
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001137 if [ $4 == "https" ]; then
1138 result="$(__do_curl "-k https://localhost:"${localport}${url})"
1139 else
1140 result="$(__do_curl $LOCALHOST${localport}${url})"
1141 fi
YongchaoWu9a84f512019-12-16 22:54:11 +01001142 if [ $? -eq 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001143 if [ ${#result} -gt 15 ]; then
1144 #If response is too long, truncate
1145 result="...response text too long, omitted"
1146 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001147 echo -ne " Waiting for container $BOLD${appname}$EBOLD service status, result: $result${SAMELINE}"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001148 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 +01001149 pa_st=true
1150 break
1151 else
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001152 TS_TMP=$SECONDS
1153 while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
1154 echo -ne " Waiting for container ${appname} service status...retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}"
1155 sleep 1
1156 done
YongchaoWu9a84f512019-12-16 22:54:11 +01001157 fi
1158 done
1159
1160 if [ "$pa_st" = "false" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001161 ((RES_CONF_FAIL++))
1162 echo -e $RED" Container ${appname} did not respond to service status"$ERED
1163 return 0
1164 fi
1165
1166 echo ""
1167 return 0
1168}
1169
1170
1171# Function to start a container and wait until it responds on the given port and url.
1172#args: <docker-compose-dir> NODOCKERARGS|<docker-compose-arg> <app-name> <port-number> <alive-url> [<app-name> <port-number> <alive-url>]*
1173__start_container() {
1174
1175 variableArgCount=$(($#-2))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001176 if [ $# -lt 6 ] && [ [ $(($variableArgCount%4)) -ne 0 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001177 ((RES_CONF_FAIL++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001178 __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 +01001179 exit 1
1180 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001181
1182 __create_docker_network
1183
1184 curdir=$PWD
1185 cd $SIM_GROUP
1186 cd $1
1187
1188 if [ "$2" == "NODOCKERARGS" ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001189 docker-compose up -d &> .dockererr
1190 if [ $? -ne 0 ]; then
1191 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1192 cat .dockererr
1193 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001194 elif [ "$2" == "STANDALONE" ]; then
1195 echo "Skipping docker-compose"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001196 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001197 docker-compose up -d $2 &> .dockererr
1198 if [ $? -ne 0 ]; then
1199 echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
1200 cat .dockererr
1201 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001202 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001203 app_prefix=""
1204 if [ "$2" == "STANDALONE" ]; then
1205 app_prefix="STANDALONE_"
1206 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001207 shift; shift;
1208 cntr=0
1209 while [ $cntr -lt $variableArgCount ]; do
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001210 app=$app_prefix$1; shift;
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001211 port=$1; shift;
1212 url=$1; shift;
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001213 httpx=$1; shift;
1214 let cntr=cntr+4
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001215
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001216 __check_container_start "$app" "$port" "$url" $httpx
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001217 done
1218
1219 cd $curdir
1220 echo ""
1221 return 0
YongchaoWu9a84f512019-12-16 22:54:11 +01001222}
1223
BjornMagnussonXAad047782020-06-08 15:54:11 +02001224# Generate a UUID to use as prefix for policy ids
1225generate_uuid() {
1226 UUID=$(python3 -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
1227 #Reduce length to make space for serial id, us 'a' as marker where the serial id is added
1228 UUID=${UUID:0:${#UUID}-4}"a"
1229}
1230
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001231####################
1232### Consul functions
1233####################
1234
1235# Function to load config from a file into consul for the Policy Agent
1236# arg: <json-config-file>
1237# (Function for test scripts)
1238consul_config_app() {
1239
1240 echo -e $BOLD"Configuring Consul"$EBOLD
1241
1242 if [ $# -ne 1 ]; then
1243 ((RES_CONF_FAIL++))
1244 __print_err "need one arg, <json-config-file>" $@
1245 exit 1
1246 fi
1247
1248 echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1
1249
1250 curl -s $LOCALHOST${CONSUL_EXTERNAL_PORT}/v1/kv/${POLICY_AGENT_APP_NAME}?dc=dc1 -X PUT -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'X-Requested-With: XMLHttpRequest' --data-binary "@"$1 >/dev/null
1251 if [ $? -ne 0 ]; then
1252 echo -e $RED" FAIL - json config could not be loaded to consul" $ERED
1253 ((RES_CONF_FAIL++))
1254 return 1
1255 fi
1256 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001257 echo $body > ".output"$1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001258
1259 if [ $? -ne 0 ]; then
1260 echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED
1261 ((RES_CONF_FAIL++))
1262 return 1
1263 else
1264 targetJson=$(< $1)
1265 targetJson="{\"config\":"$targetJson"}"
1266 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001267 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001268 if [ $res -ne 0 ]; then
1269 echo -e $RED" FAIL - policy json config read from consul/cbs is not equal to the intended json config...." $ERED
1270 ((RES_CONF_FAIL++))
1271 return 1
1272 else
1273 echo -e $GREEN" Config loaded ok to consul"$EGREEN
1274 fi
1275 fi
1276
1277 echo ""
1278
1279}
1280
1281# Function to perpare the consul configuration according to the current simulator configuration
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001282# args: SDNC|NOSDNC <output-file>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001283# (Function for test scripts)
1284prepare_consul_config() {
1285 echo -e $BOLD"Prepare Consul config"$EBOLD
1286
1287 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
1288
1289 if [ $# != 2 ]; then
1290 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001291 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001292 exit 1
1293 fi
1294
1295 if [ $1 == "SDNC" ]; then
1296 echo -e " Config$BOLD including SDNC$EBOLD configuration"
1297 elif [ $1 == "NOSDNC" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001298 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001299 else
1300 ((RES_CONF_FAIL++))
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001301 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001302 exit 1
1303 fi
1304
1305 config_json="\n {"
1306 if [ $1 == "SDNC" ]; then
1307 config_json=$config_json"\n \"controller\": ["
1308 config_json=$config_json"\n {"
1309 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001310 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1311 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://$SDNC_APP_NAME:$SDNC_PORT\","
1312 else
1313 config_json=$config_json"\n \"baseUrl\": \"$SDNC_HTTPX://localhost:$SDNC_LOCAL_PORT\","
1314 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001315 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
1316 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
1317 config_json=$config_json"\n }"
1318 config_json=$config_json"\n ],"
1319 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001320
1321 config_json=$config_json"\n \"streams_publishes\": {"
1322 config_json=$config_json"\n \"dmaap_publisher\": {"
1323 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1324 config_json=$config_json"\n \"dmaap_info\": {"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001325 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1326 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_WRITE_URL\""
1327 else
1328 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_WRITE_URL\""
1329 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001330 config_json=$config_json"\n }"
1331 config_json=$config_json"\n }"
1332 config_json=$config_json"\n },"
1333 config_json=$config_json"\n \"streams_subscribes\": {"
1334 config_json=$config_json"\n \"dmaap_subscriber\": {"
1335 config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
1336 config_json=$config_json"\n \"dmaap_info\": {"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001337 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1338 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://$MR_APP_NAME:$MR_PORT$MR_READ_URL\""
1339 else
1340 config_json=$config_json"\n \"topic_url\": \"$MR_HTTPX://localhost:$MR_LOCAL_PORT$MR_READ_URL\""
1341 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001342 config_json=$config_json"\n }"
1343 config_json=$config_json"\n }"
1344 config_json=$config_json"\n },"
1345
1346 config_json=$config_json"\n \"ric\": ["
1347
BjornMagnussonXAad047782020-06-08 15:54:11 +02001348 rics=$(docker ps | grep $RIC_SIM_PREFIX | awk '{print $NF}')
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001349
1350 if [ $? -ne 0 ] || [ -z "$rics" ]; then
1351 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
1352 ((RES_CONF_FAIL++))
1353 return 1
1354 fi
1355
1356 cntr=0
1357 for ric in $rics; do
1358 if [ $cntr -gt 0 ]; then
1359 config_json=$config_json"\n ,"
1360 fi
1361 config_json=$config_json"\n {"
1362 config_json=$config_json"\n \"name\": \"$ric\","
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001363 if [ $AGENT_STAND_ALONE -eq 0 ]; then
1364 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
1365 else
1366 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://localhost:$(__find_sim_port $ric)\","
1367 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001368 if [ $1 == "SDNC" ]; then
1369 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
1370 fi
1371 config_json=$config_json"\n \"managedElementIds\": ["
1372 config_json=$config_json"\n \"me1_$ric\","
1373 config_json=$config_json"\n \"me2_$ric\""
1374 config_json=$config_json"\n ]"
1375 config_json=$config_json"\n }"
1376 let cntr=cntr+1
1377 done
1378
1379 config_json=$config_json"\n ]"
1380 config_json=$config_json"\n}"
1381
1382
1383 printf "$config_json">$2
1384
1385 echo ""
1386}
1387
1388
1389# Start Consul and CBS
1390# args: -
1391# (Function for test scripts)
1392start_consul_cbs() {
1393
1394 echo -e $BOLD"Starting Consul and CBS"$EBOLD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001395 __check_excluded_image 'CONSUL'
1396 if [ $? -eq 1 ]; then
1397 echo -e $RED"The Consul image has not been checked for this test run due to arg to the test script"$ERED
1398 echo -e $RED"Consul will not be started"$ERED
1399 exit
1400 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001401 __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" "http" \
1402 "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001403}
1404
1405###########################
1406### RIC Simulator functions
1407###########################
1408
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001409use_simulator_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001410 echo -e "Using $BOLD http $EBOLD towards the simulators"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001411 export RIC_SIM_HTTPX="http"
1412 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1413 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001414 echo ""
1415}
1416
1417use_simulator_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001418 echo -e "Using $BOLD https $EBOLD towards the simulators"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001419 export RIC_SIM_HTTPX="https"
1420 export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:"
1421 export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001422 echo ""
1423}
1424
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001425# Start one group (ricsim_g1, ricsim_g2 or ricsim_g3) with a number of RIC Simulators using a given A interface
BjornMagnussonXAad047782020-06-08 15:54:11 +02001426# 'ricsim' may be set on command line to other prefix
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001427# args: ricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>
1428# (Function for test scripts)
1429start_ric_simulators() {
1430
1431 echo -e $BOLD"Starting RIC Simulators"$EBOLD
1432
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001433 __check_excluded_image 'RICSIM'
1434 if [ $? -eq 1 ]; then
1435 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
1436 echo -e $RED"The Near-RT RIC Simulartor(s) will not be started"$ERED
1437 exit
1438 fi
1439
BjornMagnussonXAad047782020-06-08 15:54:11 +02001440 RIC1=$RIC_SIM_PREFIX"_g1"
1441 RIC2=$RIC_SIM_PREFIX"_g2"
1442 RIC3=$RIC_SIM_PREFIX"_g3"
1443
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001444 if [ $# != 3 ]; then
1445 ((RES_CONF_FAIL++))
BjornMagnussonXAad047782020-06-08 15:54:11 +02001446 __print_err "need three args, $RIC1|$RIC2|$RIC3 <count> <interface-id>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001447 exit 1
1448 fi
1449 echo " $2 simulators using basename: $1 on interface: $3"
1450 #Set env var for simulator count and A1 interface vesion for the given group
BjornMagnussonXAad047782020-06-08 15:54:11 +02001451 if [ $1 == "$RIC1" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001452 G1_COUNT=$2
1453 G1_A1_VERSION=$3
BjornMagnussonXAad047782020-06-08 15:54:11 +02001454 elif [ $1 == "$RIC2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001455 G2_COUNT=$2
1456 G2_A1_VERSION=$3
BjornMagnussonXAad047782020-06-08 15:54:11 +02001457 elif [ $1 == "$RIC3" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001458 G3_COUNT=$2
1459 G3_A1_VERSION=$3
1460 else
1461 ((RES_CONF_FAIL++))
BjornMagnussonXAad047782020-06-08 15:54:11 +02001462 __print_err "need three args, $RIC1|$RIC2|$RIC3 <count> <interface-id>" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001463 exit 1
1464 fi
1465
1466 # Create .env file to compose project, all ric container will get this prefix
1467 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
1468
1469 export G1_A1_VERSION
1470 export G2_A1_VERSION
1471 export G3_A1_VERSION
1472
1473 docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT"
1474 app_data=""
1475 cntr=1
1476 while [ $cntr -le $2 ]; do
1477 app=$1"_"$cntr
1478 port=0
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001479 app_data="$app_data $app $port / "$RIC_SIM_HTTPX
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001480 let cntr=cntr+1
1481 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001482 __start_container ric "$docker_args" $app_data
1483
1484}
1485
1486###########################
1487### Control Panel functions
1488###########################
1489
1490# Start the Control Panel container
1491# args: -
1492# (Function for test scripts)
1493start_control_panel() {
1494
1495 echo -e $BOLD"Starting Control Panel"$EBOLD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001496 __check_excluded_image 'CP'
1497 if [ $? -eq 1 ]; then
1498 echo -e $RED"The Control Panel image has not been checked for this test run due to arg to the test script"$ERED
1499 echo -e $RED"The Control Panel will not be started"$ERED
1500 exit
1501 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001502 __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001503
1504}
1505
1506##################
1507### SDNC functions
1508##################
1509
1510# Start the SDNC A1 Controller
1511# args: -
1512# (Function for test scripts)
1513start_sdnc() {
1514
1515 echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
1516
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001517 __check_excluded_image 'SDNC'
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001518 if [ $? -eq 1 ]; then
1519 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
1520 echo -e $RED"SDNC will not be started"$ERED
1521 exit
1522 fi
1523
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001524 __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT $SDNC_ALIVE_URL "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001525
1526}
1527
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001528use_sdnc_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001529 echo -e "Using $BOLD http $EBOLD towards SDNC"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001530 export SDNC_HTTPX="http"
1531 export SDNC_PORT=$SDNC_INTERNAL_PORT
1532 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT
1533 echo ""
1534}
1535
1536use_sdnc_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001537 echo -e "Using $BOLD https $EBOLD towards SDNC"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001538 export SDNC_HTTPX="https"
1539 export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT
1540 export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT
1541 echo ""
1542}
1543
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001544#####################
1545### MR stub functions
1546#####################
1547
1548# Start the Message Router stub interface in the simulator group
1549# args: -
1550# (Function for test scripts)
1551start_mr() {
1552
1553 echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001554 __check_excluded_image 'MR'
1555 if [ $? -eq 1 ]; then
1556 echo -e $RED"The Message Router image has not been checked for this test run due to arg to the test script"$ERED
1557 echo -e $RED"The Message Router will not be started"$ERED
1558 exit
1559 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001560 export MR_CERT_MOUNT_DIR="./cert"
1561 __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001562}
1563
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001564use_mr_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001565 echo -e "Using $BOLD http $EBOLD towards MR"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001566 export MR_HTTPX="http"
1567 export MR_PORT=$MR_INTERNAL_PORT
1568 export MR_LOCAL_PORT=$MR_EXTERNAL_PORT
1569 echo ""
1570}
1571
1572use_mr_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001573 echo -e "Using $BOLD https $EBOLD towards MR"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001574 export MR_HTTPX="https"
1575 export MR_PORT=$MR_INTERNAL_SECURE_PORT
1576 export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT
1577 echo ""
1578}
1579
1580
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001581################
1582### CR functions
1583################
1584
1585# Start the Callback reciver in the simulator group
1586# args: -
1587# (Function for test scripts)
1588start_cr() {
1589
1590 echo -e $BOLD"Starting Callback Receiver"$EBOLD
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001591 __check_excluded_image 'CR'
1592 if [ $? -eq 1 ]; then
1593 echo -e $RED"The Callback Receiver image has not been checked for this test run due to arg to the test script"$ERED
1594 echo -e $RED"The Callback Receiver will not be started"$ERED
1595 exit
1596 fi
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001597 __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/" "http"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001598
1599}
1600
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001601use_cr_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001602 echo -e "Using $BOLD http $EBOLD towards CR"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001603 export CR_HTTPX="http"
1604 export CR_PORT=$CR_INTERNAL_PORT
1605 export CR_LOCAL_PORT=$CR_EXTERNAL_PORT
1606 echo ""
1607}
1608
1609use_cr_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001610 echo -e "Using $BOLD https $EBOLD towards CR"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001611 export CR_HTTPX="https"
1612 export CR_PORT=$CR_INTERNAL_SECURE_PORT
1613 export CR_LOCAL_PORT=$CR_EXTERNAL_SECURE_PORT
1614 echo ""
1615}
1616
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001617###########################
1618### Policy Agents functions
1619###########################
1620
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001621# Use an agent on the local machine instead of container
1622use_agent_stand_alone() {
1623 AGENT_STAND_ALONE=1
1624}
1625
1626# Start the policy agent
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001627# args: -
1628# (Function for test scripts)
1629start_policy_agent() {
1630
1631 echo -e $BOLD"Starting Policy Agent"$EBOLD
1632
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001633 if [ $AGENT_STAND_ALONE -eq 0 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001634 __check_excluded_image 'PA'
1635 if [ $? -eq 1 ]; then
1636 echo -e $RED"The Policy Agent image has not been checked for this test run due to arg to the test script"$ERED
1637 echo -e $RED"The Policy Agent will not be started"$ERED
1638 exit
1639 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001640 __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1641 else
1642 echo -e $RED"The consul config produced by this test script (filename '<fullpath-to-autotest-dir>.output<file-name>"$ERED
1643 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
1644 echo -e $RED"application.yaml"$ERED
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001645 echo -e $RED"The application jar may need to be built before continuing"$ERED
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001646 echo -e $RED"The agent shall now be running on port $POLICY_AGENT_EXTERNAL_PORT for http"$ERED
1647
1648 read -p "<press any key to continue>"
1649 __start_container policy_agent "STANDALONE" $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status" "http"
1650 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001651
1652}
1653
1654# All calls to the agent will be directed to the agent REST interface from now on
1655# args: -
1656# (Function for test scripts)
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001657use_agent_rest_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001658 echo -e "Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001659 export ADAPTER=$RESTBASE
1660 echo ""
1661}
1662
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001663# All calls to the agent will be directed to the agent REST interface from now on
1664# args: -
1665# (Function for test scripts)
1666use_agent_rest_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001667 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001668 export ADAPTER=$RESTBASE_SECURE
1669 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001670 return 0
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001671}
1672
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001673# All calls to the agent will be directed to the agent dmaap interface over http from now on
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001674# args: -
1675# (Function for test scripts)
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001676use_agent_dmaap_http() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001677 echo -e "Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001678 export ADAPTER=$DMAAPBASE
1679 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001680 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001681}
1682
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001683# All calls to the agent will be directed to the agent dmaap interface over https from now on
1684# args: -
1685# (Function for test scripts)
1686use_agent_dmaap_https() {
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001687 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
BjornMagnussonXA496156d2020-08-10 14:16:24 +02001688 export ADAPTER=$DMAAPBASE_SECURE
1689 echo ""
1690 return 0
1691}
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001692
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001693# Turn on debug level tracing in the agent
1694# args: -
1695# (Function for test scripts)
1696set_agent_debug() {
1697 echo -e $BOLD"Setting agent debug"$EBOLD
1698 curl $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"debug"}' &> /dev/null
1699 if [ $? -ne 0 ]; then
1700 __print_err "could not set debug mode" $@
1701 return 1
1702 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001703 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001704 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001705}
1706
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001707# Turn on trace level tracing in the agent
1708# args: -
1709# (Function for test scripts)
1710set_agent_trace() {
1711 echo -e $BOLD"Setting agent trace"$EBOLD
1712 curl $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"trace"}' &> /dev/null
1713 if [ $? -ne 0 ]; then
1714 __print_err "could not set trace mode" $@
1715 return 1
1716 fi
1717 echo ""
1718 return 0
1719}
1720
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001721# Perform curl retries when making direct call to the agent for the specified http response codes
1722# Speace separated list of http response codes
1723# args: [<response-code>]*
1724use_agent_retries() {
1725 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
1726 AGENT_RETRY_CODES=$@
1727 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001728 return
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001729}
1730
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001731###########################
1732### ECS functions
1733###########################
1734
1735# Start the ECS
1736# args: -
1737# (Function for test scripts)
1738start_ecs() {
1739
1740 echo -e $BOLD"Starting ECS"$EBOLD
1741 __check_excluded_image 'ECS'
1742 if [ $? -eq 1 ]; then
1743 echo -e $RED"The ECS image has not been checked for this test run due to arg to the test script"$ERED
1744 echo -e $RED"ECS will not be started"$ERED
1745 exit
1746 fi
1747 export ECS_CERT_MOUNT_DIR="./cert"
1748 __start_container ecs NODOCKERARGS $ECS_APP_NAME $ECS_EXTERNAL_PORT "/ei-producer/v1/eiproducers" "http"
1749}
1750
1751# All calls to ECS will be directed to the ECS REST interface from now on
1752# args: -
1753# (Function for test scripts)
1754use_ecs_rest_http() {
1755 echo -e "Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
1756 export ECS_ADAPTER=$ECS_RESTBASE
1757 echo ""
1758}
1759
1760# All calls to ECS will be directed to the ECS REST interface from now on
1761# args: -
1762# (Function for test scripts)
1763use_ecs_rest_https() {
1764 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
1765 export ECS_ADAPTER=$ECS_RESTBASE_SECURE
1766 echo ""
1767 return 0
1768}
1769
1770# All calls to ECS will be directed to the ECS dmaap interface over http from now on
1771# args: -
1772# (Function for test scripts)
1773use_ecs_dmaap_http() {
1774 echo -e "Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
1775 export ECS_ADAPTER=$ECS_DMAAPBASE
1776 echo ""
1777 return 0
1778}
1779
1780# All calls to ECS will be directed to the ECS dmaap interface over https from now on
1781# args: -
1782# (Function for test scripts)
1783use_ecs_dmaap_https() {
1784 echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
1785 export ECS_ADAPTER=$ECS_DMAAPBASE_SECURE
1786 echo ""
1787 return 0
1788}
1789
1790# Turn on debug level tracing in ECS
1791# args: -
1792# (Function for test scripts)
1793set_ecs_debug() {
1794 echo -e $BOLD"Setting ecs debug"$EBOLD
1795 curl $LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"debug"}' &> /dev/null
1796 if [ $? -ne 0 ]; then
1797 __print_err "could not set debug mode" $@
1798 return 1
1799 fi
1800 echo ""
1801 return 0
1802}
1803
1804# Turn on trace level tracing in ECS
1805# args: -
1806# (Function for test scripts)
1807set_ecs_trace() {
1808 echo -e $BOLD"Setting agent trace"$EBOLD
1809 curl $LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"trace"}' &> /dev/null
1810 if [ $? -ne 0 ]; then
1811 __print_err "could not set trace mode" $@
1812 return 1
1813 fi
1814 echo ""
1815 return 0
1816}
1817
1818# Perform curl retries when making direct call to ECS for the specified http response codes
1819# Speace separated list of http response codes
1820# args: [<response-code>]*
1821use_agent_retries() {
1822 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
1823 ECS_AGENT_RETRY_CODES=$@
1824 echo ""
1825 return
1826}
1827
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001828#################
1829### Log functions
1830#################
1831
1832# Check the agent logs for WARNINGs and ERRORs
1833# args: -
1834# (Function for test scripts)
1835
YongchaoWu9a84f512019-12-16 22:54:11 +01001836check_policy_agent_logs() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001837 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH
YongchaoWu9a84f512019-12-16 22:54:11 +01001838}
1839
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001840check_ecs_logs() {
1841 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH
1842}
1843
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001844check_control_panel_logs() {
1845 __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH
YongchaoWu9a84f512019-12-16 22:54:11 +01001846}
1847
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001848__check_container_logs() {
1849 dispname=$1
1850 appname=$2
1851 logpath=$3
1852 echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
1853
1854 #tmp=$(docker ps | grep $appname)
1855 tmp=$(docker ps -q --filter name=$appname) #get the container id
1856 if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
1857 echo $dispname" is not running, no check made"
1858 return
1859 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001860 foundentries="$(docker exec $tmp grep WARN $logpath | wc -l)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001861 if [ $? -ne 0 ];then
1862 echo " Problem to search $appname log $logpath"
1863 else
1864 if [ $foundentries -eq 0 ]; then
1865 echo " No WARN entries found in $appname log $logpath"
1866 else
1867 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath"
1868 fi
1869 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001870 foundentries="$(docker exec $tmp grep ERR $logpath | wc -l)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001871 if [ $? -ne 0 ];then
1872 echo " Problem to search $appname log $logpath"
1873 else
1874 if [ $foundentries -eq 0 ]; then
1875 echo " No ERR entries found in $appname log $logpath"
1876 else
1877 echo -e $RED" Found \033[1m"$foundentries"\033[0m"$RED" ERR entries in $appname log $logpath"$ERED
1878 fi
1879 fi
1880 echo ""
1881}
1882
1883# Store all container logs and other logs in the log dir for the script
1884# Logs are stored with a prefix in case logs should be stored several times during a test
1885# args: <logfile-prefix>
1886# (Function for test scripts)
YongchaoWu9a84f512019-12-16 22:54:11 +01001887store_logs() {
1888 if [ $# != 1 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001889 ((RES_CONF_FAIL++))
1890 __print_err "need one arg, <file-prefix>" $@
YongchaoWu9a84f512019-12-16 22:54:11 +01001891 exit 1
1892 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001893 echo -e $BOLD"Storing all container logs using prefix: "$1$EBOLD
YongchaoWu9a84f512019-12-16 22:54:11 +01001894
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001895 docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001896 docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1
1897 docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1
1898 docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001899 docker logs $ECS_APP_NAME > $TESTLOGS/$ATC/$1_ecs.log 2>&1
1900 docker logs $CONTROL_PANEL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001901 docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1
1902 docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1
1903 cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1
1904
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001905 docker exec $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001906
1907 rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}")
1908 for ric in $rics; do
1909 docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1
1910 done
1911 body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)"
1912 echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1
1913 echo ""
YongchaoWu9a84f512019-12-16 22:54:11 +01001914}
1915
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001916###############
1917## Generic curl
1918###############
1919# Generic curl function, assumed all 200-codes are ok
1920# args: <url>
1921# returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
1922# returns: The return code is 0 for ok and 1 for not ok
YongchaoWu9a84f512019-12-16 22:54:11 +01001923__do_curl() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001924 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
1925 curlString="curl -skw %{http_code} $1"
1926 echo " CMD: $curlString" >> $HTTPLOG
1927 res=$($curlString)
1928 echo " RESP: $res" >> $HTTPLOG
YongchaoWu9a84f512019-12-16 22:54:11 +01001929 http_code="${res:${#res}-3}"
1930 if [ ${#res} -eq 3 ]; then
1931 echo "<no-response-from-server>"
1932 return 1
1933 else
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001934 if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
YongchaoWu9a84f512019-12-16 22:54:11 +01001935 echo "<not found, resp:${http_code}>"
1936 return 1
1937 fi
1938 if [ $# -eq 2 ]; then
1939 echo "${res:0:${#res}-3}" | xargs
1940 else
1941 echo "${res:0:${#res}-3}"
1942 fi
1943
1944 return 0
1945 fi
1946}
1947
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001948#######################################
1949### Basic helper function for test cases
1950#######################################
1951
1952# Test a simulator container variable value towards target value using an condition operator with an optional timeout.
1953# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
1954# immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
1955# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
1956# before setting pass or fail depending on the result of comparing variable and target using the operator.
1957# 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.
1958# Not to be called from test script.
1959
1960__var_test() {
1961 checkjsonarraycount=0
1962
1963 if [ $# -eq 6 ]; then
1964 if [[ $3 == "json:"* ]]; then
1965 checkjsonarraycount=1
1966 fi
1967
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001968 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001969 ((RES_TEST++))
1970 start=$SECONDS
1971 ctr=0
1972 for (( ; ; )); do
1973 if [ $checkjsonarraycount -eq 0 ]; then
1974 result="$(__do_curl $2$3)"
1975 retcode=$?
1976 result=${result//[[:blank:]]/} #Strip blanks
1977 else
1978 path=${3:5}
1979 result="$(__do_curl $2$path)"
1980 retcode=$?
1981 echo "$result" > .tmp.curl.json
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001982 result=$(python3 ../common/count_json_elements.py ".tmp.curl.json")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001983 fi
1984 duration=$((SECONDS-start))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001985 echo -ne " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001986 let ctr=ctr+1
1987 if [ $retcode -ne 0 ]; then
1988 if [ $duration -gt $6 ]; then
1989 ((RES_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001990 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001991 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001992 return
1993 fi
1994 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
1995 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001996 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001997 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001998 return
1999 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2000 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002001 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002002 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002003 return
2004 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2005 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002006 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002007 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002008 return
2009 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2010 ((RES_PASS++))
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002011 echo -e " Result=${result} after ${duration} seconds${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002012 echo -e $GREEN" PASS${EGREEN} - Result=${result} after ${duration} seconds"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002013 return
2014 else
2015 if [ $duration -gt $6 ]; then
2016 ((RES_FAIL++))
2017 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached in ${6} seconds, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002018 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002019 return
2020 fi
2021 fi
2022 sleep 1
2023 done
2024 elif [ $# -eq 5 ]; then
2025 if [[ $3 == "json:"* ]]; then
2026 checkjsonarraycount=1
2027 fi
2028
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002029 echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD
2030 ((RES_TEST++))
2031 if [ $checkjsonarraycount -eq 0 ]; then
2032 result="$(__do_curl $2$3)"
2033 retcode=$?
2034 result=${result//[[:blank:]]/} #Strip blanks
2035 else
2036 path=${3:5}
2037 result="$(__do_curl $2$path)"
2038 retcode=$?
2039 echo "$result" > .tmp.curl.json
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002040 result=$(python3 ../common/count_json_elements.py ".tmp.curl.json")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002041 fi
2042 if [ $retcode -ne 0 ]; then
2043 ((RES_FAIL++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002044 echo -e $RED" FAIL ${ERED}- ${3} ${4} ${5} not reached, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002045 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002046 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
2047 ((RES_PASS++))
2048 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002049 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
2050 ((RES_PASS++))
2051 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002052 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
2053 ((RES_PASS++))
2054 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002055 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
2056 ((RES_PASS++))
2057 echo -e $GREEN" PASS${EGREEN} - Result=${result}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002058 else
2059 ((RES_FAIL++))
2060 echo -e $RED" FAIL${ERED} - ${3} ${4} ${5} not reached, result = ${result}"
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02002061 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002062 fi
2063 else
2064 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
2065 echo "Got:" $@
2066 exit 1
2067 fi
2068}
2069
2070
2071### Generic test cases for varaible checking
2072
2073# Tests if a variable value in the CR is equal to a target value and and optional timeout.
2074# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2075# equal to the target or not.
2076# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2077# before setting pass or fail depending on if the variable value becomes equal to the target
2078# value or not.
2079# (Function for test scripts)
2080cr_equal() {
2081 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2082 __var_test "CR" "$LOCALHOST$CR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
2083 else
2084 ((RES_CONF_FAIL++))
2085 __print_err "Wrong args to cr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2086 fi
2087}
2088
2089# Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
2090# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2091# equal to the target or not.
2092# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2093# before setting pass or fail depending on if the variable value becomes equal to the target
2094# value or not.
2095# (Function for test scripts)
2096mr_equal() {
2097 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
2098 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
2099 else
2100 ((RES_CONF_FAIL++))
2101 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2102 fi
2103}
2104
2105# Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
2106# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
2107# greater than the target or not.
2108# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
2109# before setting pass or fail depending on if the variable value becomes greater than the target
2110# value or not.
2111# (Function for test scripts)
2112mr_greater() {
2113 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002114 __var_test "MR" "$LOCALHOST$MR_EXTERNAL_PORT/counter/" $1 ">" $2 $3
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002115 else
2116 ((RES_CONF_FAIL++))
2117 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
2118 fi
2119}
2120
2121# Read a variable value from MR sim and send to stdout. Arg: <variable-name>
2122mr_read() {
2123 echo "$(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"
2124}
2125
2126# Print a variable value from the MR stub.
2127# arg: <variable-name>
2128# (Function for test scripts)
2129mr_print() {
2130 if [ $# != 1 ]; then
2131 ((RES_CONF_FAIL++))
2132 __print_err "need one arg, <mr-param>" $@
2133 exit 1
2134 fi
2135 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $LOCALHOST$MR_EXTERNAL_PORT/counter/$1)"$EBOLD
2136}