blob: 1e0118e23826d764a32d080a885ea8f96cad7458 [file] [log] [blame]
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001#!/bin/bash
2
3. ../common/test_env.sh
4
5echo "Test case started as: ${BASH_SOURCE[$i+1]} "$1 $2
6
7# Script containing all functions needed for auto testing of test cases
8# Arg: local [<image-tag>] ]| remote [<image-tag>] ]| remote-remove [<image-tag>]] | manual-container | manual-app
9
10START_ARG=$1
11IMAGE_TAG="latest"
12
13if [ $# -gt 1 ]; then
14 IMAGE_TAG=$2
15fi
16
17if [ $# -lt 1 ] || [ $# -gt 2 ]; then
18 echo "Expected arg: local [<image-tag>] ]| remote [<image-tag>] ]| remote-remove [<image-tag>]] | manual-container | manual-app"
19 exit 1
20elif [ $1 == "local" ]; then
21 if [ -z $DFC_LOCAL_IMAGE ]; then
22 echo "DFC_LOCAL_IMAGE not set in test_env"
23 exit 1
24 fi
25 DFC_IMAGE=$DFC_LOCAL_IMAGE":"$IMAGE_TAG
26elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
27 if [ -z $DFC_REMOTE_IMAGE ]; then
28 echo "DFC_REMOTE_IMAGE not set in test_env"
29 exit 1
30 fi
31 DFC_IMAGE=$DFC_REMOTE_IMAGE":"$IMAGE_TAG
32elif [ $1 == "manual-container" ] && [ $# -eq 1 ]; then
33 echo "DFC is expected to be started manually as a container with name 'dfc_app'"
34elif [ $1 == "manual-app" ] && [ $# -eq 1 ]; then
35 echo "DFC is expected to be started manually as a java application"
36else
37 echo "Expected arg: local [<image-tag>] ]| remote [<image-tag>] ]| remote-remove [<image-tag>]] | manual-container | manual-app"
38 exit 1
39fi
40
41# Set a description string for the test case
42if [ -z "$TC_ONELINE_DESCR" ]; then
43 TC_ONELINE_DESCR="<no-description>"
44 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
45fi
46
47# Counter for test suites
48if [ -f .tmp_tcsuite_ctr ]; then
49 tmpval=$(< .tmp_tcsuite_ctr)
50 ((tmpval++))
51 echo $tmpval > .tmp_tcsuite_ctr
52fi
53
54# Create a test case id, ATC (Auto Test Case), from the name of the test case script.
55# FTC1.sh -> ATC == FTC1
56ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
57
58# Create the logs dir if not already created in the current dir
59if [ ! -d "logs" ]; then
60 mkdir logs
61fi
62
63TESTLOGS=$PWD/logs
64
65# Create a log dir for the test case
66mkdir -p $TESTLOGS/$ATC
67
68# Clear the log dir for the test case
69rm $TESTLOGS/$ATC/*.log &> /dev/null
70
71# Log all output from the test case to a TC log
72TCLOG=$TESTLOGS/$ATC/TC.log
73exec &> >(tee ${TCLOG})
74
75#Variables for counting tests as well as passed and failed tests
76RES_TEST=0
77RES_PASS=0
78RES_FAIL=0
79TCTEST_START=$SECONDS
80
81echo "-------------------------------------------------------------------------------------------------"
82echo "----------------------------------- Test case: "$ATC
83echo "----------------------------------- Started: "$(date)
84echo "-------------------------------------------------------------------------------------------------"
85echo "-- Description: "$TC_ONELINE_DESCR
86echo "-------------------------------------------------------------------------------------------------"
87echo "----------------------------------- Test case setup -----------------------------------"
88
89if [ -z "$SIM_GROUP" ]; then
90 SIM_GROUP=$PWD/../simulator-group
91 if [ ! -d $SIM_GROUP ]; then
92 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the integration repo, but failed."
93 echo "Please set the SIM_GROUP manually in the test_env.sh"
94 exit 1
95 else
96 echo "SIM_GROUP auto set to: " $SIM_GROUP
97 fi
98elif [ $SIM_GROUP = *simulator_group ]; then
99 echo "Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the integration repo, check test_env.sh"
100 exit 1
101fi
102
103echo ""
104
105if [ $1 != "manual-container" ] && [ $1 != "manual-app" ]; then
106 echo -e "DFC image tag set to: \033[1m" $IMAGE_TAG"\033[0m"
107 echo "Configured image for DFC app (${1}): "$DFC_IMAGE
108 tmp_im=$(docker images ${DFC_IMAGE} | grep -v REPOSITORY)
109
110 if [ $1 == "local" ]; then
111 if [ -z "$tmp_im" ]; then
112 echo "Local image (non nexus) "$DFC_IMAGE" does not exist in local registry, need to be built"
113 exit 1
114 else
115 echo -e "DFC local image: \033[1m"$tmp_im"\033[0m"
116 echo "If the DFC image seem outdated, rebuild the image and run the test again."
117 fi
118 elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
119
120 if [ $1 == "remote-remove" ]; then
121 echo "Attempt to stop dfc_app container if running"
122 docker stop $(docker ps -q --filter name=dfc_app) &> /dev/null
123 docker rm $(docker ps -q --filter name=dfc_app) &> /dev/null
124 docker rmi $DFC_IMAGE &> /dev/null
125 tmp_im=""
126 fi
127 if [ -z "$tmp_im" ]; then
128 echo "Pulling DFC image from nexus: "$DFC_IMAGE
129 docker pull $DFC_IMAGE > /dev/null
130 tmp_im=$(docker images ${DFC_IMAGE} | grep -v REPOSITORY)
131 if [ -z "$tmp_im" ]; then
132 echo "Image could not be pulled"
133 exit 1
134 fi
135 echo -e "DFC image: \033[1m"$tmp_im"\033[0m"
136 else
137 echo -e "DFC image: \033[1m"$tmp_im"\033[0m"
138 echo "!! If the dfc image seem outdated, consider removing it from your docker registry and run the test again."
139 fi
140 fi
141fi
142
143echo ""
144
145echo "Building images for the simulators if needed, MR, DR and DR Redir simulators"
146curdir=$PWD
147cd $SIM_GROUP
148cd ../dr-sim
149docker build -t drsim_common:latest . &> /dev/null
150cd ../mr-sim
151docker build -t mrsim:latest . &> /dev/null
152cd ../simulator-group
153cp -r ../ftps-sftp-server/configuration .
154cp -r ../ftps-sftp-server/tls .
155cd $curdir
156
157echo ""
158
159echo "Local registry images for simulators:"
160echo "MR simulator " $(docker images | grep mrsim)
161echo "DR simulator: " $(docker images | grep drsim_common)
162echo "DR redir simulator: " $(docker images | grep drsim_common)
163echo "SFTP: " $(docker images | grep atmoz/sftp)
164echo "FTPS: " $(docker images | grep panubo/vsftpd)
165echo ""
166
167echo "----------------------------------- Test case steps -----------------------------------"
168
169# Print error info for the call in the parent script (test case). Arg: <error-message-to-print>
170# Not to be called from test script.
171print_err() {
172 echo ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[$i+2]} " line" ${BASH_LINENO[$i+1]}
173}
174# Execute curl using the host and variable. Arg: <host> <variable-name>
175# Returns the variable value (if success) and return code 0 or an error message and return code 1
176do_curl() {
177 res=$(curl -sw "%{http_code}" $1)
178 http_code="${res:${#res}-3}"
179 if [ ${#res} -eq 3 ]; then
180 echo "<no-response-from-server>"
181 return 1
182 else
183 if [ $http_code -lt 200 ] && [ $http_code -gt 299]; then
184 echo "<not found, resp:${http_code}>"
185 return 1
186 fi
187 echo "${res:0:${#res}-3}"
188 return 0
189 fi
190}
191
192# Test a simulator variable value towards target value using an condition operator with an optional timeout.
193# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done
194# immediately and sets pass or fail depending on the result of comparing variable and target using the operator.
195# Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> <timeout> - This test waits up to the timeout
196# before setting pass or fail depending on the result of comparing variable and target using the operator.
197# Not to be called from test script.
198
199var_test() {
200 if [ $# -eq 6 ]; then
201 echo -e "---- ${1} sim test criteria: \033[1m ${3} \033[0m ${4} ${5} within ${6} seconds ----"
202 ((RES_TEST++))
203 start=$SECONDS
204 ctr=0
205 for (( ; ; ))
206 do
207 result="$(do_curl $2$3)"
208 retcode=$?
209 result=${result//[[:blank:]]/} #Strip blanks
210 duration=$((SECONDS-start))
211 if [ $((ctr%30)) -eq 0 ]; then
212 echo -ne " Result=${result} after ${duration} seconds, DFC heartbeat="$(do_curl http://127.0.0.1:8100/heartbeat)
213 echo ""
214 else
215 echo -ne " Result=${result} after ${duration} seconds\033[0K\r"
216 fi
217 let ctr=ctr+1
218 if [ $retcode -ne 0 ]; then
219 if [ $duration -gt $6 ]; then
220 ((RES_FAIL++))
221 echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached in ${6} seconds, result = ${result} ----"
222 return
223 fi
224 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
225 ((RES_PASS++))
226 echo -e " Result=${result} after ${duration} seconds\033[0K\r"
227 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds ----"
228 return
229 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
230 ((RES_PASS++))
231 echo -e " Result=${result} after ${duration} seconds\033[0K\r"
232 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds, result = ${result} ----"
233 return
234 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
235 ((RES_PASS++))
236 echo -e " Result=${result} after ${duration} seconds\033[0K\r"
237 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds, result = ${result} ----"
238 return
239 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
240 ((RES_PASS++))
241 echo -e " Result=${result} after ${duration} seconds\033[0K\r"
242 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met in ${duration} seconds, result = ${result} ----"
243 return
244 else
245 if [ $duration -gt $6 ]; then
246 ((RES_FAIL++))
247 echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached in ${6} seconds, result = ${result} ----"
248 return
249 fi
250 fi
251 sleep 1
252 done
253 elif [ $# -eq 5 ]; then
254 echo -e "---- ${1} sim test criteria: \033[1m ${3} \033[0m ${4} ${5} ----"
255 ((RES_TEST++))
256 result="$(do_curl $2$3)"
257 retcode=$?
258 result=${result//[[:blank:]]/} #Strip blanks
259 if [ $retcode -ne 0 ]; then
260 ((RES_FAIL++))
261 echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached, result = ${result} ----"
262 elif [ $4 = "=" ] && [ "$result" -eq $5 ]; then
263 ((RES_PASS++))
264 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met"
265 elif [ $4 = ">" ] && [ "$result" -gt $5 ]; then
266 ((RES_PASS++))
267 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met, result = ${result} ----"
268 elif [ $4 = "<" ] && [ "$result" -lt $5 ]; then
269 ((RES_PASS++))
270 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met, result = ${result} ----"
271 elif [ $4 = "contain_str" ] && [[ $result =~ $5 ]]; then
272 ((RES_PASS++))
273 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met, result = ${result} ----"
274 else
275 ((RES_FAIL++))
276 echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${3} ${4} ${5} not reached, result = ${result} ----"
277 fi
278 else
279 echo "Wrong args to var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]"
280 exit 1
281 fi
282}
283# Stops a named container
284docker_stop() {
285 if [ $# -ne 1 ]; then
286 echo "docker_stop need 1 arg <container-name>"
287 exit 1
288 fi
289 tmp=$(docker stop $1 2>/dev/null)
290 if [ -z $tmp ] || [ $tmp != $1 ]; then
291 echo " ${1} container not stopped or not existing"
292 else
293 echo " ${1} container stopped"
294 fi
295}
296
297# Removes a named container
298docker_rm() {
299 if [ $# -ne 1 ]; then
300 echo "docker_rm need 1 arg <container-name>"
301 exit 1
302 fi
303 tmp=$(docker rm $1 2>/dev/null)
304 if [ -z $tmp ] || [ $tmp != $1 ]; then
305 echo " ${1} container not removed or not existing"
306 else
307 echo " ${1} container removed"
308 fi
309}
310
311start_dfc_image() {
312 echo "Starting DFC"
313 # Port mappning not needed since dfc is running in host mode
314 docker run -d --network="host" --name dfc_app $DFC_IMAGE > /dev/null
315 dfc_started=false
316 for i in {1..10}; do
317 if [ $(docker inspect --format '{{ .State.Running }}' dfc_app) ]
318 then
319 echo " Image: $(docker inspect --format '{{ .Config.Image }}' dfc_app)"
320 echo "DFC app Running"
321 dfc_started=true
322 break
323 else
324 echo sleep $i
325 fi
326 done
327 if ! [ $dfc_started ]; then
328 echo "DFC app could not be started"
329 exit 1
330 fi
331}
332
333#WFunction for waiting for named container to be started manually.
334wait_for_container() {
335 start=$SECONDS
336 if [ $# != 1 ]; then
337 echo "Need one arg: <container-name>"
338 exit 1
339 fi
340 echo "Waiting for container with name '${1}' to be started manually...."
341
342 for (( ; ; ))
343 do
344 if [ $(docker inspect --format '{{ .State.Running }}' $1 2> /dev/null) ]; then
345 echo "Container running: "$1
346 break
347 else
348 duration=$((SECONDS-start))
349 echo -ne " Waited ${duration} seconds\033[0K\r"
350 sleep 1
351 fi
352 done
353}
354
355#WFunction for waiting for named container to be stopped manually.
356wait_for_container_gone() {
357 start=$SECONDS
358 if [ $# != 1 ]; then
359 echo "Need one arg: <container-name>"
360 exit 1
361 fi
362 echo "Waiting for container with name '${1}' to be stopped manually...."
363
364 for (( ; ; ))
365 do
366 if [ $(docker inspect --format '{{ .State.Running }}' $1 2> /dev/null) ]; then
367 duration=$((SECONDS-start))
368 echo -ne " Waited ${duration} seconds\033[0K\r"
369 sleep 1
370 else
371 echo "Container stopped: "$1
372 break
373 fi
374 done
375}
376
377#Function for waiting to dfc to be started manually
378wait_for_dfc() {
379 read -p "Press enter to continue when dfc has been manually started"
380}
381
382#Function for waiting to dfc to be stopped manually
383wait_for_dfc_gone() {
384 read -p "Press enter to continue when dfc has been manually stopped"
385}
386
387#############################################################
388############## Functions for auto test scripts ##############
389#############################################################
390
391# Print the env variables needed for the simulators and their setup
392log_sim_settings() {
393 echo "Simulator settings"
394 echo "DR_TC= "$DR_TC
395 echo "DR_REDIR_TC= "$DR_REDIR_TC
396 echo "MR_TC= "$MR_TC
397 echo "BC_TC= "$BC_TC
398 echo "NUM_FTPFILES= "$NUM_FTPFILES
399 echo "NUM_PNFS= "$NUM_PNFS
400 echo "FILE_SIZE= "$FILE_SIZE
401 echo "FTP_TYPE= "$FTP_TYPE
402 echo ""
403}
404
405# Stop and remove all containers including dfc app and simulators
406clean_containers() {
407 echo "Stopping all containers, dfc app and simulators with name prefix 'dfc_'"
408 docker stop $(docker ps -q --filter name=dfc_) &> /dev/null
409 echo "Removing all containers, dfc app and simulators with name prefix 'dfc_'"
410 docker rm $(docker ps -a -q --filter name=dfc_) &> /dev/null
411 echo ""
412}
413
414# Start all simulators in the simulator group
415start_simulators() {
416 echo "Starting all simulators"
417 curdir=$PWD
418 cd $SIM_GROUP
419 $SIM_GROUP/simulators-start.sh
420 cd $curdir
421 echo ""
422}
423
424# Start the dfc application
425start_dfc() {
426
427 if [ $START_ARG == "local" ] || [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
428 start_dfc_image
429 elif [ $START_ARG == "manual-container" ]; then
430 wait_for_container dfc_app
431 elif [ $START_ARG == "manual-app" ]; then
432 wait_for_dfc
433 fi
434}
435
436# Stop and remove the dfc app container
437kill_dfc() {
438 echo "Killing DFC"
439
440 if [ $START_ARG == "local" ] || [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then
441 docker_stop dfc_app
442 docker_rm dfc_app
443 elif [ $START_ARG == "manual-container" ]; then
444 wait_for_container_gone dfc_app
445 elif [ $START_ARG == "manual-app" ]; then
446 wait_for_dfc_gone
447 fi
448}
449
450# Stop and remove the DR simulator container
451kill_dr() {
452 echo "Killing DR sim"
453 docker_stop dfc_dr-sim
454 docker_rm dfc_dr-sim
455}
456
457# Stop and remove the DR redir simulator container
458kill_drr() {
459 echo "Killing DR redir sim"
460 docker_stop dfc_dr-redir-sim
461 docker_rm dfc_dr-redir-sim
462}
463
464# Stop and remove the MR simulator container
465kill_mr() {
466 echo "Killing MR sim"
467 docker_stop dfc_mr-sim
468 docker_rm dfc_mr-sim
469}
470
471# Stop and remove the SFTP container
472kill_sftp() {
473 echo "Killing SFTP"
474 docker_stop dfc_sftp-server
475 docker_rm dfc_sftp-server
476}
477
478# Stop and remove the FTPS container
479kill_ftps() {
480 echo "Killing FTPS"
481 docker_stop dfc_ftpes-server-vsftpd
482 docker_rm dfc_ftpes-server-vsftpd
483}
484
485# Print a variable value from the MR simulator. Arg: <variable-name>
486mr_print() {
487 if [ $# != 1 ]; then
488 print_err "need one arg, <sim-param>"
489 exit 1
490 fi
491 echo -e "---- MR sim, \033[1m $1 \033[0m: $(do_curl http://127.0.0.1:2222/$1)"
492}
493
494# Print a variable value from the DR simulator. Arg: <variable-name>
495dr_print() {
496 if [ $# != 1 ]; then
497 print_err "need one arg, <sim-param>"
498 exit 1
499 fi
500 echo -e "---- DR sim, \033[1m $1 \033[0m: $(do_curl http://127.0.0.1:3906/$1)"
501}
502
503# Print a variable value from the DR redir simulator. Arg: <variable-name>
504drr_print() {
505 if [ $# != 1 ]; then
506 print_err "need one arg, <sim-param>"
507 exit 1
508 fi
509 echo -e "---- DR redir sim, \033[1m $1 \033[0m: $(do_curl http://127.0.0.1:3908/$1)"
510}
511# Print a variable value from dfc. Arg: <variable-name>
512dfc_print() {
513 if [ $# != 1 ]; then
514 print_err "need one arg, <dfc-param>"
515 exit 1
516 fi
517 echo -e "---- DFC, \033[1m $1 \033[0m: $(do_curl http://127.0.0.1:8100/$1)"
518}
519
520# Read a variable value from MR sim and send to stdout.
521mr_read() {
522 echo "$(do_curl http://127.0.0.1:2222/$1)"
523}
524
525# Read a variable value from DR sim and send to stdout.
526dr_read() {
527 echo "$(do_curl http://127.0.0.1:3906/$1)"
528}
529
530# Read a variable value from DR redir sim and send to stdout.
531drr_read() {
532 echo "$(do_curl http://127.0.0.1:3908/$1)"
533}
534
535
536# Sleep. Arg: <sleep-time-in-sec>
537sleep_wait() {
538 if [ $# != 1 ]; then
539 print_err "need one arg, <sleep-time-in-sec>"
540 exit 1
541 fi
542 echo "---- Sleep for " $1 " seconds ----"
543 start=$SECONDS
544 duration=$((SECONDS-start))
545 while [ $duration -lt $1 ]; do
546 echo -ne " Slept for ${duration} seconds\033[0K\r"
547 sleep 1
548 duration=$((SECONDS-start))
549 done
550}
551
552# Sleep and print dfc heartbeat. Arg: <sleep-time-in-sec>
553sleep_heartbeat() {
554 if [ $# != 1 ]; then
555 print_err "need one arg, <sleep-time-in-sec>"
556 exit 1
557 fi
558 echo "---- Sleep for " $1 " seconds ----"
559 start=$SECONDS
560 duration=$((SECONDS-start))
561 ctr=0
562 while [ $duration -lt $1 ]; do
563 if [ $((ctr%30)) -eq 0 ]; then
564 echo -ne " Slept for ${duration} seconds, \033[1m heartbeat \033[0m "$(do_curl http://127.0.0.1:8100/heartbeat)
565 echo ""
566 else
567 echo -ne " Slept for ${duration} seconds, \033[1m heartbeat \033[0m "$(do_curl http://127.0.0.1:8100/heartbeat)" \033[0K\r"
568 fi
569 let ctr=ctr+1
570 sleep 1
571 duration=$((SECONDS-start))
572 done
573 echo ""
574}
575
576# Tests if a variable value in the MR simulator is equal to a target value and and optional timeout.
577# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
578# equal to the target or not.
579# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
580# before setting pass or fail depending on if the variable value becomes equal to the target
581# value or not.
582mr_equal() {
583 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
584 var_test "MR" "http://127.0.0.1:2222/" $1 "=" $2 $3
585 else
586 print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]"
587 fi
588}
589
590# Tests if a variable value in the MR simulator is greater than a target value and and optional timeout.
591# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
592# greater than the target or not.
593# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
594# before setting pass or fail depending on if the variable value greater than the target
595# value or not.
596mr_greater() {
597 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
598 var_test "MR" "http://127.0.0.1:2222/" $1 ">" $2 $3
599 else
600 print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]"
601 fi
602}
603
604# Tests if a variable value in the MR simulator is less than a target value and and optional timeout.
605# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
606# less than the target or not.
607# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
608# before setting pass or fail depending on if the variable value less than the target
609# value or not.
610mr_less() {
611 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
612 var_test "MR" "http://127.0.0.1:2222/" $1 "<" $2 $3
613 else
614 print_err "Wrong args to mr_less, needs two or three args: <sim-param> <target-value> [ timeout ]"
615 fi
616}
617
618# Tests if a variable value in the MR simulator contains the target string and and optional timeout.
619# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable contains
620# the target or not.
621# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
622# before setting pass or fail depending on if the variable value contains the target
623# value or not.
624mr_contain_str() {
625 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
626 var_test "MR" "http://127.0.0.1:2222/" $1 "contain_str" $2 $3
627 else
628 print_err "Wrong args to mr_contain_str, needs two or three args: <sim-param> <target-value> [ timeout ]"
629 fi
630}
631
632# Tests if a variable value in the DR simulator is equal to a target value and and optional timeout.
633# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
634# equal to the target or not.
635# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
636# before setting pass or fail depending on if the variable value becomes equal to the target
637# value or not.
638dr_equal() {
639 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
640 var_test "DR" "http://127.0.0.1:3906/" $1 "=" $2 $3
641 else
642 print_err "Wrong args to dr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]"
643 fi
644}
645
646# Tests if a variable value in the DR simulator is greater than a target value and and optional timeout.
647# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
648# greater than the target or not.
649# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
650# before setting pass or fail depending on if the variable value greater than the target
651# value or not.
652dr_greater() {
653 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
654 var_test "DR" "http://127.0.0.1:3906/" $1 ">" $2 $3
655 else
656 print_err "Wrong args to dr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]"
657 fi
658}
659
660# Tests if a variable value in the DR simulator is less than a target value and and optional timeout.
661# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
662# less than the target or not.
663# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
664# before setting pass or fail depending on if the variable value less than the target
665# value or not.
666dr_less() {
667 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
668 var_test "DR" "http://127.0.0.1:3906/" $1 "<" $2 $3
669 else
670 print_err "Wrong args to dr_less, needs two or three args: <sim-param> <target-value> [ timeout ]"
671 fi
672}
673
674# Tests if a variable value in the DR Redir simulator is equal to a target value and and optional timeout.
675# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
676# equal to the target or not.
677# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
678# before setting pass or fail depending on if the variable value becomes equal to the target
679# value or not.
680drr_equal() {
681 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
682 var_test "DR REDIR" "http://127.0.0.1:3908/" $1 "=" $2 $3
683 else
684 print_err "Wrong args to drr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]"
685 fi
686}
687
688
689# Tests if a variable value in the DR Redir simulator is greater a target value and and optional timeout.
690# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
691# greater the target or not.
692# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
693# before setting pass or fail depending on if the variable value greater than the target
694# value or not.
695drr_greater() {
696 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
697 var_test "DR REDIR" "http://127.0.0.1:3908/" $1 ">" $2 $3
698 else
699 print_err "Wrong args to drr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]"
700 fi
701}
702
703# Tests if a variable value in the DR Redir simulator is less than a target value and and optional timeout.
704# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
705# less than the target or not.
706# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
707# before setting pass or fail depending on if the variable value less than the target
708# value or not.
709drr_less() {
710 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
711 var_test "DR REDIR" "http://127.0.0.1:3908/" $1 "<" $2 $3
712 else
713 print_err "Wrong args to drr_less, needs two or three args: <sim-param> <target-value> [ timeout ]"
714 fi
715}
716
717#Test is a variable in the DFC contains a substring. Arg: <variable-name> <substring-in-quotes>
718dfc_contain_str() {
719 if [ $# -eq 2 ]; then
720 echo -e "---- DFC test criteria: \033[1m ${1} \033[0m contains: ${2} ----"
721 ((RES_TEST++))
722 result="$(do_curl http://127.0.0.1:8100/${1})"
723 if [[ $result =~ $2 ]]; then
724 ((RES_PASS++))
725 echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met"
726 else
727 ((RES_FAIL++))
728 echo -e "---- \033[31m\033[1mFAIL\033[0m - Target ${1} not reached, result = ${result} ----"
729 fi
730 else
731 echo "Wrong args to dfc_contain_str, needs two arg: <dfc-variable> <str>"
732 exit 1
733 fi
734}
735
736# Store all dfc app and simulators log to the test case log dir. All logs gets a prefix to
737# separate logs stored at different steps in the test script. Arg: <tc-id> <log-prefix>
738store_logs() {
739 if [ $# != 1 ]; then
740 print_err "need one arg, <file-prefix>"
741 exit 1
742 fi
743 echo "Storing all container logs and dfc app log using prefix: "$1
744 if ! [ $START_ARG == "manual-app" ]; then
745 docker cp dfc_app:/var/log/ONAP/application.log $TESTLOGS/$ATC/$1_application.log
746 docker logs dfc_app > $TESTLOGS/$ATC/$1_dfc_app-docker.log 2>&1
747 fi
748 docker logs dfc_mr-sim > $TESTLOGS/$ATC/$1_dfc_mr-sim-docker.log 2>&1
749 docker logs dfc_dr-sim > $TESTLOGS/$ATC/$1_dfc_dr-sim-docker.log 2>&1
750 docker logs dfc_dr-redir-sim > $TESTLOGS/$ATC/$1_dfc_dr-redir-sim-docker.log 2>&1
751 docker logs dfc_ftpes-server-vsftpd > $TESTLOGS/$ATC/$1_dfc_ftpes-server-vsftpd.log 2>&1
752 docker logs dfc_sftp-server > $TESTLOGS/$ATC/$1_dfc_sftp-server.log 2>&1
753}
754# Check the dfc application log for WARN and ERR messages and print the count.
755check_dfc_log() {
756 echo "Checking dfc log /var/log/ONAP/application.log for WARNINGs and ERRORs, excluding messages from CONSUL"
757 foundentries=$(docker exec -it dfc_app grep WARN /var/log/ONAP/application.log | grep -iv CONSUL | wc -l)
758 if [ $? -ne 0 ];then
759 echo " Problem to search dfc log /var/log/ONAP/application.log"
760 else
761 if [ $foundentries -eq 0 ]; then
762 echo " No WARN entries found in dfc log /var/log/ONAP/application.log"
763 else
764 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in dfc log /var/log/ONAP/application.log"
765 fi
766 fi
767 foundentries=$(docker exec -it dfc_app grep ERR /var/log/ONAP/application.log | grep -iv CONSUL | wc -l)
768 if [ $? -ne 0 ];then
769 echo " Problem to search dfc log /var/log/ONAP/application.log"
770 else
771 if [ $foundentries -eq 0 ]; then
772 echo " No ERR entries found in dfc log /var/log/ONAP/application.log"
773 else
774 echo -e " Found \033[1m"$foundentries"\033[0m ERR entries in dfc log /var/log/ONAP/application.log"
775 fi
776 fi
777}
778
779print_all() {
780
781 echo "---- DFC and all sim variables"
782
783 dfc_print heartbeat
784
785 mr_print tc_info
786 mr_print execution_time
787 mr_print exe_time_first_poll
788 mr_print ctr_requests
789 mr_print ctr_responses
790 mr_print ctr_files
791 mr_print ctr_unique_files
792 mr_print ctr_events
793 mr_print ctr_unique_PNFs
794
795 dr_print tc_info
796 dr_print execution_time
797 dr_print ctr_publish_query
798 dr_print ctr_publish_query_published
799 dr_print ctr_publish_query_not_published
800 dr_print ctr_publish_req
801 dr_print ctr_publish_req_redirect
802 dr_print ctr_publish_req_published
803 dr_print ctr_published_files
804
805 drr_print tc_info
806 drr_print execution_time
807 drr_print ctr_publish_requests
808 drr_print ctr_publish_responses
809 drr_print dwl_volume
810 drr_print time_lastpublish
811}
812
813# Print the test result
814print_result() {
815
816 TCTEST_END=$SECONDS
817 duration=$((TCTEST_END-TCTEST_START))
818
819 echo "-------------------------------------------------------------------------------------------------"
820 echo "------------------------------------- Test case: "$ATC
821 echo "------------------------------------- Ended: "$(date)
822 echo "-------------------------------------------------------------------------------------------------"
823 echo "-- Description: "$TC_ONELINE_DESCR
824 echo "-- Execution time: " $duration " seconds"
825 echo "-------------------------------------------------------------------------------------------------"
826 echo "------------------------------------- RESULTS"
827 echo ""
828
829
830 total=$((RES_PASS+RES_FAIL))
831 if [ $RES_TEST -eq 0 ]; then
832 echo -e "\033[1mNo tests seem to have executed. Check the script....\033[0m"
833 elif [ $total != $RES_TEST ]; then
834 echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m"
835 elif [ $RES_PASS = $RES_TEST ]; then
836 echo -e "All tests \033[32m\033[1mPASS\033[0m"
837 # Update test suite counter
838 if [ -f .tmp_tcsuite_pass_ctr ]; then
839 tmpval=$(< .tmp_tcsuite_pass_ctr)
840 ((tmpval++))
841 echo $tmpval > .tmp_tcsuite_pass_ctr
842 fi
843 if [ -f .tmp_tcsuite_pass ]; then
844 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass
845 fi
846 else
847 echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m "
848 # Update test suite counter
849 if [ -f .tmp_tcsuite_fail_ctr ]; then
850 tmpval=$(< .tmp_tcsuite_fail_ctr)
851 ((tmpval++))
852 echo $tmpval > .tmp_tcsuite_fail_ctr
853 fi
854 if [ -f .tmp_tcsuite_fail ]; then
855 echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail
856 fi
857 fi
858
859 echo "++++ Number of tests: "$RES_TEST
860 echo "++++ Number of passed tests: "$RES_PASS
861 echo "++++ Number of failed tests: "$RES_FAIL
862 echo "------------------------------------- Test case complete ---------------------------------"
863 echo "-------------------------------------------------------------------------------------------------"
864 echo ""
865}