blob: deed26dfda628bd756fa3b7381e93ff96a76256e [file] [log] [blame]
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001#!/bin/bash
2
3. ../common/test_env.sh
4
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00005
6
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00007echo "Test case started as: ${BASH_SOURCE[$i+1]} "$1 $2
8
9# Script containing all functions needed for auto testing of test cases
10# Arg: local [<image-tag>] ]| remote [<image-tag>] ]| remote-remove [<image-tag>]] | manual-container | manual-app
11
BjornMagnussonXAa79a0432019-07-17 08:26:50 +000012STARTED_DFCS="" #DFC app names added to this var to keep track of started container in the script
BjornMagnussonXA42dcb262019-04-26 19:29:54 +000013START_ARG=$1
14IMAGE_TAG="latest"
15
16if [ $# -gt 1 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +000017 if [[ "$2" =~ ^1.1.* ]]; then
18 echo "This version of auto-test does not support DFC image version of 1.1.X"
19 exit 1
20 fi
BjornMagnussonXA42dcb262019-04-26 19:29:54 +000021 IMAGE_TAG=$2
22fi
23
24if [ $# -lt 1 ] || [ $# -gt 2 ]; then
25 echo "Expected arg: local [<image-tag>] ]| remote [<image-tag>] ]| remote-remove [<image-tag>]] | manual-container | manual-app"
26 exit 1
27elif [ $1 == "local" ]; then
28 if [ -z $DFC_LOCAL_IMAGE ]; then
29 echo "DFC_LOCAL_IMAGE not set in test_env"
30 exit 1
31 fi
32 DFC_IMAGE=$DFC_LOCAL_IMAGE":"$IMAGE_TAG
33elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
34 if [ -z $DFC_REMOTE_IMAGE ]; then
35 echo "DFC_REMOTE_IMAGE not set in test_env"
36 exit 1
37 fi
38 DFC_IMAGE=$DFC_REMOTE_IMAGE":"$IMAGE_TAG
39elif [ $1 == "manual-container" ] && [ $# -eq 1 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +000040 echo "DFC is expected to be started manually, when prompted, as a container with name 'dfc_app'<index> with and index in the range from 0 to '${DFC_MAX_IDX}'"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +000041elif [ $1 == "manual-app" ] && [ $# -eq 1 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +000042 echo "DFC is expected to be started manually, when prompted, as a java application"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +000043else
44 echo "Expected arg: local [<image-tag>] ]| remote [<image-tag>] ]| remote-remove [<image-tag>]] | manual-container | manual-app"
45 exit 1
46fi
47
48# Set a description string for the test case
49if [ -z "$TC_ONELINE_DESCR" ]; then
50 TC_ONELINE_DESCR="<no-description>"
51 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
52fi
53
54# Counter for test suites
55if [ -f .tmp_tcsuite_ctr ]; then
56 tmpval=$(< .tmp_tcsuite_ctr)
57 ((tmpval++))
58 echo $tmpval > .tmp_tcsuite_ctr
59fi
60
61# Create a test case id, ATC (Auto Test Case), from the name of the test case script.
62# FTC1.sh -> ATC == FTC1
63ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
64
65# Create the logs dir if not already created in the current dir
66if [ ! -d "logs" ]; then
67 mkdir logs
68fi
69
70TESTLOGS=$PWD/logs
71
72# Create a log dir for the test case
ecaiyanlinux796e8fe2019-08-21 12:10:33 +000073mkdir -p $TESTLOGS/$ATC
BjornMagnussonXA42dcb262019-04-26 19:29:54 +000074
75# Clear the log dir for the test case
76rm $TESTLOGS/$ATC/*.log &> /dev/null
77
78# Log all output from the test case to a TC log
79TCLOG=$TESTLOGS/$ATC/TC.log
80exec &> >(tee ${TCLOG})
81
82#Variables for counting tests as well as passed and failed tests
83RES_TEST=0
84RES_PASS=0
85RES_FAIL=0
86TCTEST_START=$SECONDS
87
88echo "-------------------------------------------------------------------------------------------------"
89echo "----------------------------------- Test case: "$ATC
90echo "----------------------------------- Started: "$(date)
91echo "-------------------------------------------------------------------------------------------------"
92echo "-- Description: "$TC_ONELINE_DESCR
93echo "-------------------------------------------------------------------------------------------------"
94echo "----------------------------------- Test case setup -----------------------------------"
95
96if [ -z "$SIM_GROUP" ]; then
97 SIM_GROUP=$PWD/../simulator-group
98 if [ ! -d $SIM_GROUP ]; then
99 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the integration repo, but failed."
100 echo "Please set the SIM_GROUP manually in the test_env.sh"
101 exit 1
ecaiyanlinux796e8fe2019-08-21 12:10:33 +0000102 else
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000103 echo "SIM_GROUP auto set to: " $SIM_GROUP
104 fi
105elif [ $SIM_GROUP = *simulator_group ]; then
106 echo "Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the integration repo, check test_env.sh"
107 exit 1
108fi
109
110echo ""
111
112if [ $1 != "manual-container" ] && [ $1 != "manual-app" ]; then
113 echo -e "DFC image tag set to: \033[1m" $IMAGE_TAG"\033[0m"
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000114 echo "Configured image for DFC app(s) (${1}): "$DFC_IMAGE
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000115 tmp_im=$(docker images ${DFC_IMAGE} | grep -v REPOSITORY)
116
117 if [ $1 == "local" ]; then
118 if [ -z "$tmp_im" ]; then
119 echo "Local image (non nexus) "$DFC_IMAGE" does not exist in local registry, need to be built"
120 exit 1
121 else
122 echo -e "DFC local image: \033[1m"$tmp_im"\033[0m"
123 echo "If the DFC image seem outdated, rebuild the image and run the test again."
124 fi
125 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
126
127 if [ $1 == "remote-remove" ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000128 echo "Attempt to stop dfc_app container(s) if running"
129 docker stop $(docker ps -q --filter name=${DFC_APP_BASE}]) &> /dev/null
130 docker rm $(docker ps -q --filter name=${DFC_APP_BASE}) &> /dev/null
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000131 docker rmi $DFC_IMAGE &> /dev/null
132 tmp_im=""
133 fi
134 if [ -z "$tmp_im" ]; then
135 echo "Pulling DFC image from nexus: "$DFC_IMAGE
136 docker pull $DFC_IMAGE > /dev/null
137 tmp_im=$(docker images ${DFC_IMAGE} | grep -v REPOSITORY)
138 if [ -z "$tmp_im" ]; then
139 echo "Image could not be pulled"
140 exit 1
141 fi
142 echo -e "DFC image: \033[1m"$tmp_im"\033[0m"
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000143 else
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000144 echo -e "DFC image: \033[1m"$tmp_im"\033[0m"
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000145 echo "!! If the dfc image seem outdated, consider removing it from your docker registry and run the test again. Or run the script with 'remote-remove'"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000146 fi
147 fi
148fi
149
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000150
151
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000152echo ""
153
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000154echo "Building images for the simulators if needed, MR, DR, DR Redir and FTPS simulators"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000155curdir=$PWD
156cd $SIM_GROUP
157cd ../dr-sim
158docker build -t drsim_common:latest . &> /dev/null
159cd ../mr-sim
160docker build -t mrsim:latest . &> /dev/null
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000161cd ../ftps-sftp-server
162docker build -t ftps_vsftpd:latest -f Dockerfile-ftps . &> /dev/null
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000163cd $curdir
164
165echo ""
166
167echo "Local registry images for simulators:"
168echo "MR simulator " $(docker images | grep mrsim)
169echo "DR simulator: " $(docker images | grep drsim_common)
170echo "DR redir simulator: " $(docker images | grep drsim_common)
171echo "SFTP: " $(docker images | grep atmoz/sftp)
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000172echo "FTPS: " $(docker images | grep ftps_vsftpd)
173echo "Consul: " $(docker images | grep consul)
174echo "CBS: " $(docker images | grep platform.configbinding.app)
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000175echo ""
176
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000177#Configure MR sim to use correct host:port for running dfc as an app or as a container
178#Configure DR sim with correct address for DR redirect simulator
179if [ $START_ARG == "manual-app" ]; then
180 export SFTP_SIMS=$SFTP_SIMS_LOCALHOST
181 export FTPS_SIMS=$FTPS_SIMS_LOCALHOST
182 export DR_REDIR_SIM="localhost"
183fi
184#else
185# export SFTP_SIMS=$SFTP_SIMS_CONTAINER
186# export FTPS_SIMS=$FTPS_SIMS_CONTAINER
187# export DR_REDIR_SIM="drsim_redir"
188#fi
189
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000190echo "----------------------------------- Test case steps -----------------------------------"
191
192# Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
193# Not to be called from test script.
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000194__print_err() {
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000195 echo ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[$i+2]} " line" ${BASH_LINENO[$i+1]}
196}
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000197# Execute curl using the host and variable. Arg: <host and variable-name> [ <flag-to-strip-new-line> ]
198#<flag-to-strip-new-line> may contain any string, it is just a flag
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000199# Returns the variable value (if success) and return code 0 or an error message and return code 1
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000200__do_curl() {
ecaiyanlinux796e8fe2019-08-21 12:10:33 +0000201 res=$(curl -skw "%{http_code}" $1)
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000202 http_code="${res:${#res}-3}"
203 if [ ${#res} -eq 3 ]; then
204 echo "<no-response-from-server>"
205 return 1
206 else
207 if [ $http_code -lt 200 ] && [ $http_code -gt 299]; then
208 echo "<not found, resp:${http_code}>"
209 return 1
210 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000211 if [ $# -eq 2 ]; then
212 echo "${res:0:${#res}-3}" | xargs
213 else
214 echo "${res:0:${#res}-3}"
215 fi
216
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000217 return 0
218 fi
219}
220
221# Test a simulator variable value towards target value using an condition operator with an optional timeout.
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000222# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000223# immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
224# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
225# before setting pass or fail depending on the result of comparing variable and target using the operator.
226# Not to be called from test script.
227
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000228__var_test() {
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000229 if [ $# -eq 6 ]; then
230 echo -e "---- ${1} sim test criteria: \033[1m ${3} \033[0m ${4} ${5} within ${6} seconds ----"
231 ((RES_TEST++))
232 start=$SECONDS
233 ctr=0
234 for (( ; ; ))
235 do
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000236 result="$(__do_curl $2$3)"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000237 retcode=$?
238 result=${result//[[:blank:]]/} #Strip blanks
239 duration=$((SECONDS-start))
240 if [ $((ctr%30)) -eq 0 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000241 echo " Result=${result} after ${duration} seconds"
242 for (( i=0; i<=$DFC_MAX_IDX; i++ )); do
243 if [[ $STARTED_DFCS =~ "_"$DFC_APP_BASE$i"_" ]]; then
244 echo " HB ${DFC_APP_BASE}${i}: $(__do_curl http://127.0.0.1:$(($DFC_PORT+$i))/status strip)"
245 fi
246 done
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000247 else
248 echo -ne " Result=${result} after ${duration} seconds\033[0K\r"
249 fi
250 let ctr=ctr+1
251 if [ $retcode -ne 0 ]; then
252 if [ $duration -gt $6 ]; then
253 ((RES_FAIL++))
254 echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached in ${6} seconds, result = ${result} ----"
255 return
256 fi
257 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
258 ((RES_PASS++))
259 echo -e " Result=${result} after ${duration} seconds\033[0K\r"
260 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds ----"
261 return
262 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
263 ((RES_PASS++))
264 echo -e " Result=${result} after ${duration} seconds\033[0K\r"
265 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds, result = ${result} ----"
266 return
267 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
268 ((RES_PASS++))
269 echo -e " Result=${result} after ${duration} seconds\033[0K\r"
270 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds, result = ${result} ----"
271 return
272 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
273 ((RES_PASS++))
274 echo -e " Result=${result} after ${duration} seconds\033[0K\r"
275 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds, result = ${result} ----"
276 return
277 else
278 if [ $duration -gt $6 ]; then
279 ((RES_FAIL++))
280 echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached in ${6} seconds, result = ${result} ----"
281 return
282 fi
283 fi
284 sleep 1
285 done
286 elif [ $# -eq 5 ]; then
287 echo -e "---- ${1} sim test criteria: \033[1m ${3} \033[0m ${4} ${5} ----"
288 ((RES_TEST++))
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000289 result="$(__do_curl $2$3)"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000290 retcode=$?
291 result=${result//[[:blank:]]/} #Strip blanks
292 if [ $retcode -ne 0 ]; then
293 ((RES_FAIL++))
294 echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached, result = ${result} ----"
295 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
296 ((RES_PASS++))
297 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met"
298 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
299 ((RES_PASS++))
300 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met, result = ${result} ----"
301 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
302 ((RES_PASS++))
303 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met, result = ${result} ----"
304 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
305 ((RES_PASS++))
306 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met, result = ${result} ----"
307 else
308 ((RES_FAIL++))
309 echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached, result = ${result} ----"
310 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000311 else
312 echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000313 exit 1
314 fi
315}
316# Stops a named container
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000317__docker_stop() {
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000318 if [ $# -ne 1 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000319 echo "__docker_stop need 1 arg <container-name>"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000320 exit 1
321 fi
322 tmp=$(docker stop $1 2>/dev/null)
323 if [ -z $tmp ] || [ $tmp != $1 ]; then
324 echo " ${1} container not stopped or not existing"
325 else
326 echo " ${1} container stopped"
327 fi
328}
329
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000330# Starts a named container (that has previously been stopped)
331__docker_start() {
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000332 if [ $# -ne 1 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000333 echo "__docker_start need 1 arg <container-name>"
334 exit 1
335 fi
336 tmp=$(docker start $1 2>/dev/null)
337 if [ -z $tmp ] || [ $tmp != $1 ]; then
338 echo " ${1} container not started or not existing"
339 else
340 echo " ${1} container started"
341 fi
342}
343
344# Removes a named container
345__docker_rm() {
346 if [ $# -ne 1 ]; then
347 echo "__docker_rm need 1 arg <container-name>"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000348 exit 1
349 fi
350 tmp=$(docker rm $1 2>/dev/null)
351 if [ -z $tmp ] || [ $tmp != $1 ]; then
352 echo " ${1} container not removed or not existing"
353 else
354 echo " ${1} container removed"
355 fi
356}
357
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000358__start_dfc_image() {
ecaiyanlinuxec8c60c2019-08-30 13:39:30 +0000359 set -x
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000360 if [ $# != 2 ]; then
361 __print_err "need tow args, <dfc-instance-name> 0.."$$DFC_MAX_IDX
362 exit 1
363 fi
364
365 if [ $2 -lt 0 ] || [ $2 -gt $DFC_MAX_IDX ]; then
366 __print_err "need two args, <dfc-instance-name> 0.."$DFC_MAX_IDX
367 exit 1
368 fi
369 appname=$1
370 localport=$(($DFC_PORT + $2))
371 localport_secure=$(($DFC_PORT_SECURE + $2))
372
373 echo "Creating docker network $DOCKER_SIM_NWNAME, if needed"
374
375 docker network ls| grep $DOCKER_SIM_NWNAME > /dev/null || docker network create $DOCKER_SIM_NWNAME
376
377 echo "Starting DFC: " $appname " with ports mapped to " $localport " and " $localport_secure " in docker network "$DOCKER_SIM_NWNAME
ecaiyanlinuxec8c60c2019-08-30 13:39:30 +0000378 docker run -d --volume $(pwd)/../simulator-group/tls/:/opt/app/datafile/etc/cert/ -p $localport":8100" -p $localport_secure":8433" --network=$DOCKER_SIM_NWNAME -e CONSUL_HOST=$CONSUL_HOST -e CONSUL_PORT=$CONSUL_PORT -e CONFIG_BINDING_SERVICE=$CONFIG_BINDING_SERVICE -e HOSTNAME=$appname --name $appname $DFC_IMAGE
379 sleep 3
380 set +x
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000381 dfc_started=false
382 for i in {1..10}; do
ecaiyanlinuxec8c60c2019-08-30 13:39:30 +0000383 if [ $(docker inspect --format '{{ .State.Running }}' $appname) ]
384 then
385 echo " Image: $(docker inspect --format '{{ .Config.Image }}' ${appname})"
386 echo "DFC container ${appname} running"
387 dfc_started=true
388 break
389 else
390 sleep $i
391 fi
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000392 done
393 if ! [ $dfc_started ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000394 echo "DFC container ${appname} could not be started"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000395 exit 1
396 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000397
398 dfc_hb=false
399 echo "Waiting for DFC ${appname} heartbeat..."
400 for i in {1..10}; do
401 result="$(__do_curl http://127.0.0.1:${localport}/heartbeat)"
402 if [ $? -eq 0 ]; then
403 echo "DFC ${appname} responds to heartbeat: " $result
404 dfc_hb=true
405 result="$(__do_curl http://127.0.0.1:${localport}/actuator/info)"
406 echo "DFC ${appname} image build info: " $result
407 break
408 else
409 sleep $i
410 fi
411 done
412
ecaiyanlinuxec8c60c2019-08-30 13:39:30 +0000413 if [ "$dfc_hb" = "false" ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000414 echo "DFC ${appname} did not respond to heartbeat"
ecaiyanlinuxec8c60c2019-08-30 13:39:30 +0000415 exit 1
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000416 fi
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000417}
418
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000419# Function for waiting for named container to be started manually.
420__wait_for_container() {
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000421 start=$SECONDS
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000422 if [ $# != 2 ]; then
423 echo "Need one arg: <container-name> <instance-id>"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000424 exit 1
425 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000426 http=$(($DFC_PORT+$2))
427 https=$((DFC_PORT_SECURE+$2))
428 echo "The container is expected to map its ports (8100/8433) to the following port visibile on the host: http port ${http} and https port ${https}"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000429 echo "Waiting for container with name '${1}' to be started manually...."
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000430
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000431 for (( ; ; ))
432 do
433 if [ $(docker inspect --format '{{ .State.Running }}' $1 2> /dev/null) ]; then
434 echo "Container running: "$1
435 break
436 else
437 duration=$((SECONDS-start))
438 echo -ne " Waited ${duration} seconds\033[0K\r"
439 sleep 1
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000440 fi
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000441 done
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000442
443 echo "Connecting container "$1" to simulator network "$DOCKER_SIM_NWNAME
444 docker network connect $DOCKER_SIM_NWNAME $1
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000445}
446
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000447#WFunction for waiting for named container to be stopped manually.
448__wait_for_container_gone() {
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000449 start=$SECONDS
450 if [ $# != 1 ]; then
451 echo "Need one arg: <container-name>"
452 exit 1
453 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000454 echo "Disconnecting container "$1" from simulator network "$DOCKER_SIM_NWNAME
455 docker network disconnect $DOCKER_SIM_NWNAME $1
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000456 echo "Waiting for container with name '${1}' to be stopped manually...."
457
458 for (( ; ; ))
459 do
460 if [ $(docker inspect --format '{{ .State.Running }}' $1 2> /dev/null) ]; then
461 duration=$((SECONDS-start))
462 echo -ne " Waited ${duration} seconds\033[0K\r"
463 sleep 1
464 else
465 echo "Container stopped: "$1
466 break
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000467 fi
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000468 done
469}
470
471#Function for waiting to dfc to be started manually
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000472__wait_for_dfc() {
473 http=$(($DFC_PORT+$2))
474 https=$((DFC_PORT_SECURE+$2))
475 echo "The app is expected to listen to http port ${http} and https port ${https}"
476 echo "The app shall use 'localhost' and '8500' for CONSUL_HOST and CONSUL_PORT."
477 echo "The app shale use 'config-binding-service-localhost' for CONFIG_BINDING_SERVICE"
478 echo "The app shall use ${1} for HOSTNAME."
479 read -p "Press enter to continue when app mapping to ${1} has been manually started"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000480}
481
482#Function for waiting to dfc to be stopped manually
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000483__wait_for_dfc_gone() {
484 read -p "Press enter to continue when when app mapping to ${1} has been manually stopped"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000485}
486
487#############################################################
488############## Functions for auto test scripts ##############
489#############################################################
490
491# Print the env variables needed for the simulators and their setup
492log_sim_settings() {
493 echo "Simulator settings"
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000494 echo "MR_TC= "$MR_TC
495 echo "MR_GROUPS= "$MR_GROUPS
496 echo "MR_FILE_PREFIX_MAPPING="$MR_FILE_PREFIX_MAPPING
497 echo "DR_TC= "$DR_TC
498 echo "DR_FEEDS= "$DR_FEEDS
499 echo "DR_REDIR_SIM= "$DR_REDIR_SIM
500 echo "DR_REDIR_TC= "$DR_REDIR_TC
501 echo "DR_REDIR_FEEDS= "$DR_REDIR_FEEDS
502
503 echo "NUM_FTPFILES= "$NUM_FTPFILES
504 echo "NUM_PNFS= "$NUM_PNFS
505 echo "FILE_SIZE= "$FILE_SIZE
506 echo "FTP_TYPE= "$FTP_TYPE
507 echo "FTP_FILE_PREFIXES= "$FTP_FILE_PREFIXES
508 echo "NUM_FTP_SERVERS= "$NUM_FTP_SERVERS
509 echo "SFTP_SIMS= "$SFTP_SIMS
510 echo "FTPS_SIMS= "$FTPS_SIMS
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000511 echo ""
512}
513
514# Stop and remove all containers including dfc app and simulators
515clean_containers() {
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000516 echo "Stopping all containers, dfc app(s) and simulators with name prefix 'dfc_'"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000517 docker stop $(docker ps -q --filter name=dfc_) &> /dev/null
518 echo "Removing all containers, dfc app and simulators with name prefix 'dfc_'"
519 docker rm $(docker ps -a -q --filter name=dfc_) &> /dev/null
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000520 echo "Removing unused docker networks with substring 'dfc' in network name"
521 docker network rm $(docker network ls -q --filter name=dfc)
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000522 echo ""
523}
524
525# Start all simulators in the simulator group
526start_simulators() {
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000527
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000528 echo "Starting all simulators"
529 curdir=$PWD
530 cd $SIM_GROUP
531 $SIM_GROUP/simulators-start.sh
532 cd $curdir
533 echo ""
534}
535
536# Start the dfc application
537start_dfc() {
538
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000539 if [ $# != 1 ]; then
540 __print_err "need one arg, <dfc-instance-id>"
541 exit 1
542 fi
543
544 if [ $1 -lt 0 ] || [ $1 -gt $DFC_MAX_IDX ]; then
545 __print_err "arg should be 0.."$DFC_MAX_IDX
546 exit 1
ecaiyanlinux796e8fe2019-08-21 12:10:33 +0000547 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000548 appname=$DFC_APP_BASE$1
549 STARTED_DFCS=$STARTED_DFCS"_"$appname"_"
550
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000551 if [ $START_ARG == "local" ] || [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000552 __start_dfc_image $appname $1
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000553 elif [ $START_ARG == "manual-container" ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000554 __wait_for_container $appname $1
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000555 elif [ $START_ARG == "manual-app" ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000556 __wait_for_dfc $appname $1
557 fi
558}
559
560# Configure consul with dfc config, args <app|dmaap> <dfc-instance-id> <json-file-path>
561# Not intended to be called directly by test scripts.
562__consul_config() {
563
564 if [ $# != 3 ]; then
565 __print_err "need three args, <app|dmaap> <dfc-instance-id> <json-file-path>"
566 exit 1
567 fi
568
569 if [ $2 -lt 0 ] || [ $2 -gt $DFC_MAX_IDX ]; then
570 __print_err "dfc-instance-id should be 0.."$DFC_MAX_IDX
571 exit 1
572 fi
573 if ! [ -f $3 ]; then
574 __print_err "json file does not extis: "$3
575 exit 1
576 fi
577
578 if [ $1 == "app" ]; then
579 appname=$DFC_APP_BASE$2
580 elif [ $1 == "dmaap" ]; then
581 appname=$DFC_APP_BASE$2":dmaap"
582 else
583 __print_err "config type should be 'app' or 'dmaap'"
584 exit 1
585 fi
586
587 echo "Configuring consul for " $appname " from " $3
588 curl -s http://127.0.0.1:${CONSUL_PORT}/v1/kv/${appname}?dc=dc1 -X PUT -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'X-Requested-With: XMLHttpRequest' --data-binary "@"$3 >/dev/null
589}
590
591# Configure consul with dfc app config, args <dfc-instance-id> <json-file-path>
592consul_config_app() {
593 if [ $START_ARG == "manual-app" ]; then
594 echo "Replacing 'mrsim' with 'localhost' in json app config for consul"
595 sed 's/mrsim/localhost/g' $2 > .tmp_app.json
596 __consul_config app $1 .tmp_app.json
597 else
598 __consul_config app $1 $2
599 fi
600}
601
602# Configure consul with dfc dmaap config, args <dfc-instance-id> <json-file-path>
603consul_config_dmaap() {
604 if [ $START_ARG == "manual-app" ]; then
605 echo "Replacing 'drsim' with 'localhost' in json dmaap config for consul"
606 sed 's/drsim/localhost/g' $2 > .tmp_dmaap.json
607 __consul_config dmaap $1 .tmp_dmaap.json
608 else
609 __consul_config dmaap $1 $2
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000610 fi
611}
612
613# Stop and remove the dfc app container
614kill_dfc() {
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000615
616 if [ $# != 1 ]; then
617 __print_err "need one arg, <dfc-instance-id>"
618 exit 1
619 fi
620
621 if [ $1 -lt 0 ] || [ $1 -gt $DFC_MAX_IDX ]; then
622 __print_err "arg should be 0.."$DFC_MAX_IDX
623 exit 1
624 fi
625 appname=$DFC_APP_BASE$1
626
627 echo "Killing DFC, instance id: "$1
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000628
629 if [ $START_ARG == "local" ] || [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000630 __docker_stop $appname
631 __docker_rm $appname
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000632 elif [ $START_ARG == "manual-container" ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000633 __wait_for_container_gone $appname
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000634 elif [ $START_ARG == "manual-app" ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000635 __wait_for_dfc_gone $appname
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000636 fi
637}
638
639# Stop and remove the DR simulator container
640kill_dr() {
641 echo "Killing DR sim"
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000642 __docker_stop dfc_dr-sim
643 __docker_rm dfc_dr-sim
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000644}
645
646# Stop and remove the DR redir simulator container
647kill_drr() {
648 echo "Killing DR redir sim"
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000649 __docker_stop dfc_dr-redir-sim
650 __docker_rm dfc_dr-redir-sim
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000651}
652
653# Stop and remove the MR simulator container
654kill_mr() {
655 echo "Killing MR sim"
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000656 __docker_stop dfc_mr-sim
657 __docker_rm dfc_mr-sim
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000658}
659
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000660# Stop and remove the SFTP container, arg: <sftp-instance-id>
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000661kill_sftp() {
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000662
663 if [ $# != 1 ]; then
664 __print_err "need one arg, <sftp-instance-id>"
665 exit 1
666 fi
667
668 if [ $1 -lt 0 ] || [ $1 -gt $FTP_MAX_IDX ]; then
669 __print_err "arg should be 0.."$FTP_MAX_IDX
670 exit 1
671 fi
672 appname=$SFTP_BASE$1
673
674 echo "Killing SFTP, instance id: "$1
675
676 __docker_stop $appname
677 __docker_rm $appname
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000678}
679
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000680# Stop SFTP container, arg: <sftp-instance-id>
681stop_sftp() {
682
683 if [ $# != 1 ]; then
684 __print_err "need one arg, <sftp-instance-id>"
685 exit 1
686 fi
687
688 if [ $1 -lt 0 ] || [ $1 -gt $FTP_MAX_IDX ]; then
689 __print_err "arg should be 0.."$FTP_MAX_IDX
690 exit 1
691 fi
692 appname=$SFTP_BASE$1
693
694 echo "Stopping SFTP, instance id: "$1
695
696 __docker_stop $appname
697}
698
699# Starts a stopped SFTP container, arg: <sftp-instance-id>
700start_sftp() {
701
702 if [ $# != 1 ]; then
703 __print_err "need one arg, <sftp-instance-id>"
704 exit 1
705 fi
706
707 if [ $1 -lt 0 ] || [ $1 -gt $FTP_MAX_IDX ]; then
708 __print_err "arg should be 0.."$FTP_MAX_IDX
709 exit 1
710 fi
711 appname=$SFTP_BASE$1
712
713 echo "Starting SFTP, instance id: "$1
714
715 __docker_start $appname
716}
717
718# Stop and remove the FTPS container, arg: <ftps-instance-id>
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000719kill_ftps() {
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000720
721 if [ $# != 1 ]; then
722 __print_err "need one arg, <ftpS-instance-id>"
723 exit 1
724 fi
725
726 if [ $1 -lt 0 ] || [ $1 -gt $FTP_MAX_IDX ]; then
727 __print_err "arg should be 0.."$FTP_MAX_IDX
728 exit 1
729 fi
730 appname=$FTPS_BASE$1
731
732 echo "Killing FTPS, instance id: "$1
733
734 __docker_stop $appname
735 __docker_rm $appname
736}
737
738# Stop FTPS container, arg: <ftps-instance-id>
739stop_ftps() {
740
741 if [ $# != 1 ]; then
742 __print_err "need one arg, <ftps-instance-id>"
743 exit 1
744 fi
745
746 if [ $1 -lt 0 ] || [ $1 -gt $FTP_MAX_IDX ]; then
747 __print_err "arg should be 0.."$FTP_MAX_IDX
748 exit 1
749 fi
750 appname=$FTPS_BASE$1
751
752 echo "Stopping FTPS, instance id: "$1
753
754 __docker_stop $appname
755}
756
757# Starts a stopped FTPS container, arg: <ftps-instance-id>
758start_ftps() {
759
760 if [ $# != 1 ]; then
761 __print_err "need one arg, <ftps-instance-id>"
762 exit 1
763 fi
764
765 if [ $1 -lt 0 ] || [ $1 -gt $FTP_MAX_IDX ]; then
766 __print_err "arg should be 0.."$FTP_MAX_IDX
767 exit 1
768 fi
769 appname=$FTPS_BASE$1
770
771 echo "Starting FTPS, instance id: "$1
772
773 __docker_start $appname
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000774}
775
776# Print a variable value from the MR simulator. Arg: <variable-name>
777mr_print() {
778 if [ $# != 1 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000779 __print_err "need one arg, <sim-param>"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000780 exit 1
781 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000782 echo -e "---- MR sim, \033[1m $1 \033[0m: $(__do_curl http://127.0.0.1:$MR_PORT/$1)"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000783}
784
ecaiyanlinux796e8fe2019-08-21 12:10:33 +0000785# Print a variable value from the MR https simulator. Arg: <variable-name>
786mr_secure_print() {
787 if [ $# != 1 ]; then
788 __print_err "need one arg, <sim-param>"
789 exit 1
790 fi
791 echo -e "---- MR sim, \033[1m $1 \033[0m: $(__do_curl https://127.0.0.1:$MR_PORT_SECURE/$1)"
792}
793
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000794# Print a variable value from the DR simulator. Arg: <variable-name>
795dr_print() {
796 if [ $# != 1 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000797 __print_err "need one arg, <sim-param>"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000798 exit 1
799 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000800 echo -e "---- DR sim, \033[1m $1 \033[0m: $(__do_curl http://127.0.0.1:$DR_PORT/$1)"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000801}
802
803# Print a variable value from the DR redir simulator. Arg: <variable-name>
804drr_print() {
805 if [ $# != 1 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000806 __print_err "need one arg, <sim-param>"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000807 exit 1
808 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000809 echo -e "---- DR redir sim, \033[1m $1 \033[0m: $(__do_curl http://127.0.0.1:$DRR_PORT/$1)"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000810}
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000811# Print a variable value from dfc. Arg: <dfc-instance-id> <variable-name>
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000812dfc_print() {
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000813 if [ $# != 2 ]; then
814 __print_err "need two args, <dfc-instance-id> <dfc-param>"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000815 exit 1
816 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000817 if [ $1 -lt 0 ] || [ $1 -gt $DFC_MAX_IDX ]; then
818 __print_err "dfc instance id should be in range 0.."DFC_MAX_IDX
819 exit 1
820 fi
821 localport=$(($DFC_PORT + $1))
822 appname=$DFC_APP_BASE$1
823 echo -e "---- DFC $appname, \033[1m $2 \033[0m: $(__do_curl http://127.0.0.1:$localport/$2)"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000824}
825
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000826# Read a variable value from MR sim and send to stdout. Arg: <variable-name>
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000827mr_read() {
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000828 echo "$(__do_curl http://127.0.0.1:$MR_PORT/$1)"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000829}
830
ecaiyanlinux796e8fe2019-08-21 12:10:33 +0000831# Read a variable value from MR https sim and send to stdout. Arg: <variable-name>
832mr_secure_read() {
833 echo "$(__do_curl https://127.0.0.1:$MR_PORT_SECURE/$1)"
834}
835
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000836# Read a variable value from DR sim and send to stdout. Arg: <variable-name>
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000837dr_read() {
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000838 echo "$(__do_curl http://127.0.0.1:$DR_PORT/$1)"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000839}
840
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000841# Read a variable value from DR redir sim and send to stdout. Arg: <variable-name>
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000842drr_read() {
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000843 echo "$(__do_curl http://127.0.0.1:$DRR_PORT/$1)"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000844}
845
846
847# Sleep. Arg: <sleep-time-in-sec>
848sleep_wait() {
849 if [ $# != 1 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000850 __print_err "need one arg, <sleep-time-in-sec>"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000851 exit 1
852 fi
853 echo "---- Sleep for " $1 " seconds ----"
854 start=$SECONDS
855 duration=$((SECONDS-start))
856 while [ $duration -lt $1 ]; do
857 echo -ne " Slept for ${duration} seconds\033[0K\r"
858 sleep 1
859 duration=$((SECONDS-start))
860 done
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000861 echo ""
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000862}
863
864# Sleep and print dfc heartbeat. Arg: <sleep-time-in-sec>
865sleep_heartbeat() {
866 if [ $# != 1 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000867 __print_err "need one arg, <sleep-time-in-sec>"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000868 exit 1
869 fi
870 echo "---- Sleep for " $1 " seconds ----"
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000871 echo ""
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000872 start=$SECONDS
873 duration=$((SECONDS-start))
874 ctr=0
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000875 rows=0
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000876 while [ $duration -lt $1 ]; do
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000877 if [ $rows -eq 0 ]; then
878 tput cuu1
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000879 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000880 rows=0
881 echo " Slept for ${duration} seconds"
882 if [ $((ctr%30)) -eq 0 ]; then
883 for (( i=0; i<=$DFC_MAX_IDX; i++ )); do
884 if [[ $STARTED_DFCS =~ "_"$DFC_APP_BASE$i"_" ]]; then
885 let rows=rows+1
886 echo " HB ${DFC_APP_BASE}${i}: $(__do_curl http://127.0.0.1:$(($DFC_PORT+$i))/heartbeat)"
887 fi
888 done
889 fi
890
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000891 let ctr=ctr+1
892 sleep 1
893 duration=$((SECONDS-start))
894 done
895 echo ""
896}
897
898# Tests if a variable value in the MR simulator is equal to a target value and and optional timeout.
899# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
900# equal to the target or not.
901# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
902# before setting pass or fail depending on if the variable value becomes equal to the target
903# value or not.
904mr_equal() {
905 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000906 __var_test "MR" "http://127.0.0.1:$MR_PORT/" $1 "=" $2 $3
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000907 else
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000908 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000909 fi
910}
911
ecaiyanlinux796e8fe2019-08-21 12:10:33 +0000912mr_secure_equal() {
913 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
914 __var_test "MR" "https://127.0.0.1:$MR_PORT_SECURE/" $1 "=" $2 $3
915 else
916 __print_err "Wrong args to mr_secure_equal, needs two or three args: <sim-param> <target-value> [ timeout ]"
917 fi
918}
919
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000920# Tests if a variable value in the MR simulator is greater than a target value and and optional timeout.
921# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
922# greater than the target or not.
923# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
924# before setting pass or fail depending on if the variable value greater than the target
925# value or not.
926mr_greater() {
927 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000928 __var_test "MR" "http://127.0.0.1:$MR_PORT/" $1 ">" $2 $3
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000929 else
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000930 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000931 fi
932}
933
ecaiyanlinux796e8fe2019-08-21 12:10:33 +0000934mr_secure_greater() {
935 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
936 __var_test "MR" "https://127.0.0.1:$MR_PORT_SECURE/" $1 ">" $2 $3
937 else
938 __print_err "Wrong args to mr_secure_greater, needs two or three args: <sim-param> <target-value> [ timeout ]"
939 fi
940}
941
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000942# Tests if a variable value in the MR simulator is less than a target value and and optional timeout.
943# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
944# less than the target or not.
945# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
946# before setting pass or fail depending on if the variable value less than the target
947# value or not.
948mr_less() {
949 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000950 __var_test "MR" "http://127.0.0.1:$MR_PORT/" $1 "<" $2 $3
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000951 else
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000952 __print_err "Wrong args to mr_less, needs two or three args: <sim-param> <target-value> [ timeout ]"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000953 fi
954}
ecaiyanlinux796e8fe2019-08-21 12:10:33 +0000955mr_secure_less() {
956 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
957 __var_test "MR" "https://127.0.0.1:$MR_PORT_SECURE/" $1 "<" $2 $3
958 else
959 __print_err "Wrong args to mr_secure_less, needs two or three args: <sim-param> <target-value> [ timeout ]"
960 fi
961}
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000962
963# Tests if a variable value in the MR simulator contains the target string and and optional timeout.
964# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable contains
965# the target or not.
966# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
967# before setting pass or fail depending on if the variable value contains the target
968# value or not.
969mr_contain_str() {
970 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000971 __var_test "MR" "http://127.0.0.1:$MR_PORT/" $1 "contain_str" $2 $3
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000972 else
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000973 __print_err "Wrong args to mr_contain_str, needs two or three args: <sim-param> <target-value> [ timeout ]"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000974 fi
975}
ecaiyanlinux796e8fe2019-08-21 12:10:33 +0000976mr_secure_contain_str() {
977 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
978 __var_test "MR" "https://127.0.0.1:$MR_PORT_SECURE/" $1 "contain_str" $2 $3
979 else
980 __print_err "Wrong args to mr_secure_contain_str, needs two or three args: <sim-param> <target-value> [ timeout ]"
981 fi
982}
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000983
984# Tests if a variable value in the DR simulator is equal to a target value and and optional timeout.
985# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
986# equal to the target or not.
987# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
988# before setting pass or fail depending on if the variable value becomes equal to the target
989# value or not.
990dr_equal() {
991 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000992 __var_test "DR" "http://127.0.0.1:$DR_PORT/" $1 "=" $2 $3
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000993 else
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000994 __print_err "Wrong args to dr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +0000995 fi
996}
997
998# Tests if a variable value in the DR simulator is greater than a target value and and optional timeout.
999# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1000# greater than the target or not.
1001# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1002# before setting pass or fail depending on if the variable value greater than the target
1003# value or not.
1004dr_greater() {
1005 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001006 __var_test "DR" "http://127.0.0.1:$DR_PORT/" $1 ">" $2 $3
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001007 else
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001008 __print_err "Wrong args to dr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001009 fi
1010}
1011
1012# Tests if a variable value in the DR simulator is less than a target value and and optional timeout.
1013# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1014# less than the target or not.
1015# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1016# before setting pass or fail depending on if the variable value less than the target
1017# value or not.
1018dr_less() {
1019 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001020 __var_test "DR" "http://127.0.0.1:$DR_PORT/" $1 "<" $2 $3
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001021 else
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001022 __print_err "Wrong args to dr_less, needs two or three args: <sim-param> <target-value> [ timeout ]"
1023 fi
1024}
1025
1026# Tests if a variable value in the DR simulator contains the target string and and optional timeout.
1027# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable contains
1028# the target or not.
1029# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1030# before setting pass or fail depending on if the variable value contains the target
1031# value or not.
1032dr_contain_str() {
1033 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
1034 __var_test "DR" "http://127.0.0.1:$DR_PORT/" $1 "contain_str" $2 $3
1035 else
1036 __print_err "Wrong args to dr_contain_str, needs two or three args: <sim-param> <target-value> [ timeout ]"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001037 fi
1038}
1039
1040# Tests if a variable value in the DR Redir simulator is equal to a target value and and optional timeout.
1041# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1042# equal to the target or not.
1043# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1044# before setting pass or fail depending on if the variable value becomes equal to the target
1045# value or not.
1046drr_equal() {
1047 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001048 __var_test "DR REDIR" "http://127.0.0.1:$DRR_PORT/" $1 "=" $2 $3
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001049 else
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001050 __print_err "Wrong args to drr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001051 fi
1052}
1053
1054
1055# Tests if a variable value in the DR Redir simulator is greater a target value and and optional timeout.
1056# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1057# greater the target or not.
1058# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1059# before setting pass or fail depending on if the variable value greater than the target
1060# value or not.
1061drr_greater() {
1062 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001063 __var_test "DR REDIR" "http://127.0.0.1:$DRR_PORT/" $1 ">" $2 $3
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001064 else
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001065 __print_err "Wrong args to drr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001066 fi
1067}
1068
1069# Tests if a variable value in the DR Redir simulator is less than a target value and and optional timeout.
1070# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
1071# less than the target or not.
1072# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1073# before setting pass or fail depending on if the variable value less than the target
1074# value or not.
1075drr_less() {
1076 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001077 __var_test "DR REDIR" "http://127.0.0.1:$DRR_PORT/" $1 "<" $2 $3
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001078 else
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001079 __print_err "Wrong args to drr_less, needs two or three args: <sim-param> <target-value> [ timeout ]"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001080 fi
1081}
1082
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001083# Tests if a variable value in the DR redir simulator contains the target string and and optional timeout.
1084# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable contains
1085# the target or not.
1086# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
1087# before setting pass or fail depending on if the variable value contains the target
1088# value or not.
1089drr_contain_str() {
1090 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
1091 __var_test "DR REDIR" "http://127.0.0.1:$DRR_PORT/" $1 "contain_str" $2 $3
1092 else
1093 __print_err "Wrong args to drr_contain_str, needs two or three args: <sim-param> <target-value> [ timeout ]"
1094 fi
1095}
1096
1097#Test if a variable in the DFC contains a substring. Arg: <dfc-index> <variable-name> <substring-in-quotes>
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001098dfc_contain_str() {
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001099 if [ $# -eq 3 ]; then
1100 if [ $1 -lt 0 ] || [ $1 -gt $DFC_MAX_IDX ]; then
1101 __print_err "arg should be 0.."$DFC_MAX_IDX
1102 exit 1
1103 fi
1104 appname=$DFC_APP_BASE$1
1105 localport=$(($DFC_PORT + $1))
1106 echo -e "---- DFC test criteria: $appname \033[1m ${2} \033[0m contains: ${3} ----"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001107 ((RES_TEST++))
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001108 result="$(__do_curl http://127.0.0.1:$localport/${2})"
1109 if [[ $result =~ $3 ]]; then
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001110 ((RES_PASS++))
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001111 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001112 else
1113 ((RES_FAIL++))
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001114 echo -e "---- \033[31m\033[1mFAIL\033[0m - Target '${3}' not reached, result = ${result} ----"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001115 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001116 else
1117 echo "Wrong args to dfc_contain_str, needs three arg: <dfc-index> <dfc-variable> <str>"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001118 exit 1
1119 fi
1120}
1121
1122# Store all dfc app and simulators log to the test case log dir. All logs gets a prefix to
1123# separate logs stored at different steps in the test script. Arg: <tc-id> <log-prefix>
1124store_logs() {
1125 if [ $# != 1 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001126 __print_err "need one arg, <file-prefix>"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001127 exit 1
1128 fi
1129 echo "Storing all container logs and dfc app log using prefix: "$1
1130 if ! [ $START_ARG == "manual-app" ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001131 for (( i=0; i<=$DFC_MAX_IDX; i++ )); do
1132 appname=$DFC_APP_BASE$i
1133 tmp=$(docker ps | grep $appname)
1134 if ! [ -z "$tmp" ]; then #Only stored logs from running DFC apps
1135 docker cp $appname:/var/log/ONAP/application.log $TESTLOGS/$ATC/${1}_${appname}_application.log
1136 docker logs $appname > $TESTLOGS/$ATC/$1_$appname-docker.log 2>&1
1137 fi
1138 done
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001139 fi
1140 docker logs dfc_mr-sim > $TESTLOGS/$ATC/$1_dfc_mr-sim-docker.log 2>&1
1141 docker logs dfc_dr-sim > $TESTLOGS/$ATC/$1_dfc_dr-sim-docker.log 2>&1
1142 docker logs dfc_dr-redir-sim > $TESTLOGS/$ATC/$1_dfc_dr-redir-sim-docker.log 2>&1
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001143
1144 for (( i=0; i<=$FTP_MAX_IDX; i++ )); do
1145 appname=$SFTP_BASE$i
1146 docker logs $appname > $TESTLOGS/$ATC/${1}_${appname}.log 2>&1
1147 appname=$FTPS_BASE$i
1148 docker logs $appname > $TESTLOGS/$ATC/${1}_${appname}.log 2>&1
1149 done
1150
1151 docker logs dfc_consul > $TESTLOGS/$ATC/$1_consul.log 2>&1
1152 docker logs dfc_cbs > $TESTLOGS/$ATC/$1_cbs.log 2>&1
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001153}
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001154# Check the dfc application log, for all dfc instances, for WARN and ERR messages and print the count.
1155check_dfc_logs() {
1156 for (( i=0; i<=$DFC_MAX_IDX; i++ )); do
1157 appname=$DFC_APP_BASE$i
1158 tmp=$(docker ps | grep $appname)
1159 if ! [ -z "$tmp" ]; then #Only check logs for running dfc_apps
1160 _check_dfc_log $appname
1161 fi
1162 done
1163}
1164
1165# Check dfc app log for one dfc instance, arg <dfc-app-name>
1166_check_dfc_log() {
1167 echo "Checking $1 log $DFC_LOGPATH for WARNINGs and ERRORs"
1168 foundentries=$(docker exec -it $1 grep WARN /var/log/ONAP/application.log | wc -l)
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001169 if [ $? -ne 0 ];then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001170 echo " Problem to search $1 log $DFC_LOGPATH"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001171 else
1172 if [ $foundentries -eq 0 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001173 echo " No WARN entries found in $1 log $DFC_LOGPATH"
1174 else
1175 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $1 log $DFC_LOGPATH"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001176 fi
1177 fi
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001178 foundentries=$(docker exec -it $1 grep ERR $DFC_LOGPATH | wc -l)
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001179 if [ $? -ne 0 ];then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001180 echo " Problem to search $1 log $DFC_LOGPATH"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001181 else
1182 if [ $foundentries -eq 0 ]; then
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001183 echo " No ERR entries found in $1 log $DFC_LOGPATH"
1184 else
1185 echo -e " Found \033[1m"$foundentries"\033[0m ERR entries in $1 log $DFC_LOGPATH"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001186 fi
1187 fi
1188}
1189
1190print_all() {
1191
1192 echo "---- DFC and all sim variables"
1193
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001194 for (( i=0; i<=$DFC_MAX_IDX; i++ )); do
1195 appname=$DFC_APP_BASE$i
1196 tmp=$(docker ps | grep $appname)
1197 if ! [ -z "$tmp" ]; then #Only check running dfc_apps
1198 dfc_print $i status
1199 fi
1200 done
1201
1202
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001203 mr_print tc_info
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001204 mr_print status
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001205 mr_print execution_time
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001206 mr_print groups
1207 mr_print changeids
1208 mr_print fileprefixes
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001209 mr_print exe_time_first_poll
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001210 mr_print groups/exe_time_first_poll
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001211 mr_print ctr_requests
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001212 mr_print groups/ctr_requests
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001213 mr_print ctr_responses
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001214 mr_print groups/ctr_responses
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001215 mr_print ctr_files
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001216 mr_print groups/ctr_files
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001217 mr_print ctr_unique_files
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001218 mr_print groups/ctr_unique_files
1219 mr_print groups/ctr_events
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001220 mr_print ctr_events
1221 mr_print ctr_unique_PNFs
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001222 mr_print groups/ctr_unique_PNFs
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001223
1224 dr_print tc_info
1225 dr_print execution_time
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001226 dr_print feeds
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001227 dr_print ctr_publish_query
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001228 dr_print feeds/ctr_publish_query
1229 dr_print ctr_publish_query_bad_file_prefix
1230 dr_print feeds/ctr_publish_query_bad_file_prefix
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001231 dr_print ctr_publish_query_published
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001232 dr_print feeds/ctr_publish_query_published
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001233 dr_print ctr_publish_query_not_published
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001234 dr_print feeds/ctr_publish_query_not_published
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001235 dr_print ctr_publish_req
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001236 dr_print feeds/ctr_publish_req
1237 dr_print ctr_publish_req_bad_file_prefix
1238 dr_print feeds/ctr_publish_req_bad_file_prefix
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001239 dr_print ctr_publish_req_redirect
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001240 dr_print feeds/ctr_publish_req_redirect
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001241 dr_print ctr_publish_req_published
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001242 dr_print feeds/ctr_publish_req_published
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001243 dr_print ctr_published_files
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001244 dr_print feeds/ctr_published_files
1245 dr_print ctr_double_publish
1246 dr_print feeds/ctr_double_publish
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001247
1248 drr_print tc_info
1249 drr_print execution_time
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001250 drr_print feeds
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001251 drr_print ctr_publish_requests
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001252 drr_print feeds/ctr_publish_requests
1253 drr_print ctr_publish_requests_bad_file_prefix
1254 drr_print feeds/ctr_publish_requests_bad_file_prefix
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001255 drr_print ctr_publish_responses
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001256 drr_print feeds/ctr_publish_responses
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001257 drr_print dwl_volume
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001258 drr_print feeds/dwl_volume
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001259 drr_print time_lastpublish
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001260 drr_print feeds/time_lastpublish
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001261}
1262
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001263# Print the test result
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001264print_result() {
1265
1266 TCTEST_END=$SECONDS
1267 duration=$((TCTEST_END-TCTEST_START))
1268
1269 echo "-------------------------------------------------------------------------------------------------"
1270 echo "------------------------------------- Test case: "$ATC
1271 echo "------------------------------------- Ended: "$(date)
1272 echo "-------------------------------------------------------------------------------------------------"
1273 echo "-- Description: "$TC_ONELINE_DESCR
1274 echo "-- Execution time: " $duration " seconds"
1275 echo "-------------------------------------------------------------------------------------------------"
1276 echo "------------------------------------- RESULTS"
1277 echo ""
1278
1279
1280 total=$((RES_PASS+RES_FAIL))
1281 if [ $RES_TEST -eq 0 ]; then
1282 echo -e "\033[1mNo tests seem to have executed. Check the script....\033[0m"
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001283 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
1284 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
1285 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
1286 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001287 elif [ $total != $RES_TEST ]; then
1288 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001289 echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m"
1290 echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m"
1291 echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m"
1292 echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m"
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001293 elif [ $RES_PASS = $RES_TEST ]; then
1294 echo -e "All tests \033[32m\033[1mPASS\033[0m"
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001295 echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m"
1296 echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m"
1297 echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m"
1298 echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m"
1299 echo ""
1300
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001301 # Update test suite counter
1302 if [ -f .tmp_tcsuite_pass_ctr ]; then
1303 tmpval=$(< .tmp_tcsuite_pass_ctr)
1304 ((tmpval++))
1305 echo $tmpval > .tmp_tcsuite_pass_ctr
1306 fi
1307 if [ -f .tmp_tcsuite_pass ]; then
1308 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
1309 fi
1310 else
1311 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001312 echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m"
1313 echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m"
1314 echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m"
1315 echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m"
1316 echo ""
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001317 # Update test suite counter
1318 if [ -f .tmp_tcsuite_fail_ctr ]; then
1319 tmpval=$(< .tmp_tcsuite_fail_ctr)
1320 ((tmpval++))
1321 echo $tmpval > .tmp_tcsuite_fail_ctr
1322 fi
1323 if [ -f .tmp_tcsuite_fail ]; then
1324 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
1325 fi
1326 fi
1327
1328 echo "++++ Number of tests: "$RES_TEST
1329 echo "++++ Number of passed tests: "$RES_PASS
1330 echo "++++ Number of failed tests: "$RES_FAIL
1331 echo "------------------------------------- Test case complete ---------------------------------"
1332 echo "-------------------------------------------------------------------------------------------------"
1333 echo ""
1334}