BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | . ../common/test_env.sh |
| 4 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 5 | |
| 6 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 7 | echo "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 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 12 | STARTED_DFCS="" #DFC app names added to this var to keep track of started container in the script |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 13 | START_ARG=$1 |
| 14 | IMAGE_TAG="latest" |
| 15 | |
| 16 | if [ $# -gt 1 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 17 | 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 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 21 | IMAGE_TAG=$2 |
| 22 | fi |
| 23 | |
| 24 | if [ $# -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 |
| 27 | elif [ $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 |
| 33 | elif [ $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 |
| 39 | elif [ $1 == "manual-container" ] && [ $# -eq 1 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 40 | 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}'" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 41 | elif [ $1 == "manual-app" ] && [ $# -eq 1 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 42 | echo "DFC is expected to be started manually, when prompted, as a java application" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 43 | else |
| 44 | echo "Expected arg: local [<image-tag>] ]| remote [<image-tag>] ]| remote-remove [<image-tag>]] | manual-container | manual-app" |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | # Set a description string for the test case |
| 49 | if [ -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 |
| 52 | fi |
| 53 | |
| 54 | # Counter for test suites |
| 55 | if [ -f .tmp_tcsuite_ctr ]; then |
| 56 | tmpval=$(< .tmp_tcsuite_ctr) |
| 57 | ((tmpval++)) |
| 58 | echo $tmpval > .tmp_tcsuite_ctr |
| 59 | fi |
| 60 | |
| 61 | # Create a test case id, ATC (Auto Test Case), from the name of the test case script. |
| 62 | # FTC1.sh -> ATC == FTC1 |
| 63 | ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh) |
| 64 | |
| 65 | # Create the logs dir if not already created in the current dir |
| 66 | if [ ! -d "logs" ]; then |
| 67 | mkdir logs |
| 68 | fi |
| 69 | |
| 70 | TESTLOGS=$PWD/logs |
| 71 | |
| 72 | # Create a log dir for the test case |
ecaiyanlinux | 796e8fe | 2019-08-21 12:10:33 +0000 | [diff] [blame] | 73 | mkdir -p $TESTLOGS/$ATC |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 74 | |
| 75 | # Clear the log dir for the test case |
| 76 | rm $TESTLOGS/$ATC/*.log &> /dev/null |
| 77 | |
| 78 | # Log all output from the test case to a TC log |
| 79 | TCLOG=$TESTLOGS/$ATC/TC.log |
| 80 | exec &> >(tee ${TCLOG}) |
| 81 | |
| 82 | #Variables for counting tests as well as passed and failed tests |
| 83 | RES_TEST=0 |
| 84 | RES_PASS=0 |
| 85 | RES_FAIL=0 |
| 86 | TCTEST_START=$SECONDS |
| 87 | |
| 88 | echo "-------------------------------------------------------------------------------------------------" |
| 89 | echo "----------------------------------- Test case: "$ATC |
| 90 | echo "----------------------------------- Started: "$(date) |
| 91 | echo "-------------------------------------------------------------------------------------------------" |
| 92 | echo "-- Description: "$TC_ONELINE_DESCR |
| 93 | echo "-------------------------------------------------------------------------------------------------" |
| 94 | echo "----------------------------------- Test case setup -----------------------------------" |
| 95 | |
| 96 | if [ -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 |
ecaiyanlinux | 796e8fe | 2019-08-21 12:10:33 +0000 | [diff] [blame] | 102 | else |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 103 | echo "SIM_GROUP auto set to: " $SIM_GROUP |
| 104 | fi |
| 105 | elif [ $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 |
| 108 | fi |
| 109 | |
| 110 | echo "" |
| 111 | |
| 112 | if [ $1 != "manual-container" ] && [ $1 != "manual-app" ]; then |
| 113 | echo -e "DFC image tag set to: \033[1m" $IMAGE_TAG"\033[0m" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 114 | echo "Configured image for DFC app(s) (${1}): "$DFC_IMAGE |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 115 | 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 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 128 | 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 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 131 | 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" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 143 | else |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 144 | echo -e "DFC image: \033[1m"$tmp_im"\033[0m" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 145 | 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'" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 146 | fi |
| 147 | fi |
| 148 | fi |
| 149 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 150 | |
| 151 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 152 | echo "" |
| 153 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 154 | echo "Building images for the simulators if needed, MR, DR, DR Redir and FTPS simulators" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 155 | curdir=$PWD |
| 156 | cd $SIM_GROUP |
| 157 | cd ../dr-sim |
| 158 | docker build -t drsim_common:latest . &> /dev/null |
| 159 | cd ../mr-sim |
| 160 | docker build -t mrsim:latest . &> /dev/null |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 161 | cd ../ftps-sftp-server |
| 162 | docker build -t ftps_vsftpd:latest -f Dockerfile-ftps . &> /dev/null |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 163 | cd $curdir |
| 164 | |
| 165 | echo "" |
| 166 | |
| 167 | echo "Local registry images for simulators:" |
| 168 | echo "MR simulator " $(docker images | grep mrsim) |
| 169 | echo "DR simulator: " $(docker images | grep drsim_common) |
| 170 | echo "DR redir simulator: " $(docker images | grep drsim_common) |
| 171 | echo "SFTP: " $(docker images | grep atmoz/sftp) |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 172 | echo "FTPS: " $(docker images | grep ftps_vsftpd) |
| 173 | echo "Consul: " $(docker images | grep consul) |
| 174 | echo "CBS: " $(docker images | grep platform.configbinding.app) |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 175 | echo "" |
| 176 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 177 | #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 |
| 179 | if [ $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" |
| 183 | fi |
| 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 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 190 | echo "----------------------------------- 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. |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 194 | __print_err() { |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 195 | echo ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[$i+2]} " line" ${BASH_LINENO[$i+1]} |
| 196 | } |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 197 | # 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 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 199 | # Returns the variable value (if success) and return code 0 or an error message and return code 1 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 200 | __do_curl() { |
ecaiyanlinux | 796e8fe | 2019-08-21 12:10:33 +0000 | [diff] [blame] | 201 | res=$(curl -skw "%{http_code}" $1) |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 202 | 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 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 211 | if [ $# -eq 2 ]; then |
| 212 | echo "${res:0:${#res}-3}" | xargs |
| 213 | else |
| 214 | echo "${res:0:${#res}-3}" |
| 215 | fi |
| 216 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 217 | return 0 |
| 218 | fi |
| 219 | } |
| 220 | |
| 221 | # Test a simulator variable value towards target value using an condition operator with an optional timeout. |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 222 | # Arg: <simulator-name> <host> <variable-name> <condition-operator> <target-value> - This test is done |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 223 | # 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 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 228 | __var_test() { |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 229 | 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 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 236 | result="$(__do_curl $2$3)" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 237 | retcode=$? |
| 238 | result=${result//[[:blank:]]/} #Strip blanks |
| 239 | duration=$((SECONDS-start)) |
| 240 | if [ $((ctr%30)) -eq 0 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 241 | 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 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 247 | 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++)) |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 289 | result="$(__do_curl $2$3)" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 290 | 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 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 311 | else |
| 312 | echo "Wrong args to __var_test, needs five or six args: <simulator-name> <host> <variable-name> <condition-operator> <target-value> [ <timeout> ]" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 313 | exit 1 |
| 314 | fi |
| 315 | } |
| 316 | # Stops a named container |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 317 | __docker_stop() { |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 318 | if [ $# -ne 1 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 319 | echo "__docker_stop need 1 arg <container-name>" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 320 | 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 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 330 | # Starts a named container (that has previously been stopped) |
| 331 | __docker_start() { |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 332 | if [ $# -ne 1 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 333 | 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>" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 348 | 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 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 358 | __start_dfc_image() { |
ecaiyanlinux | ec8c60c | 2019-08-30 13:39:30 +0000 | [diff] [blame] | 359 | set -x |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 360 | 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 |
ecaiyanlinux | ec8c60c | 2019-08-30 13:39:30 +0000 | [diff] [blame] | 378 | 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 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 381 | dfc_started=false |
| 382 | for i in {1..10}; do |
ecaiyanlinux | ec8c60c | 2019-08-30 13:39:30 +0000 | [diff] [blame] | 383 | 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 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 392 | done |
| 393 | if ! [ $dfc_started ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 394 | echo "DFC container ${appname} could not be started" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 395 | exit 1 |
| 396 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 397 | |
| 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 | |
ecaiyanlinux | ec8c60c | 2019-08-30 13:39:30 +0000 | [diff] [blame] | 413 | if [ "$dfc_hb" = "false" ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 414 | echo "DFC ${appname} did not respond to heartbeat" |
ecaiyanlinux | ec8c60c | 2019-08-30 13:39:30 +0000 | [diff] [blame] | 415 | exit 1 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 416 | fi |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 417 | } |
| 418 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 419 | # Function for waiting for named container to be started manually. |
| 420 | __wait_for_container() { |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 421 | start=$SECONDS |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 422 | if [ $# != 2 ]; then |
| 423 | echo "Need one arg: <container-name> <instance-id>" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 424 | exit 1 |
| 425 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 426 | 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}" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 429 | echo "Waiting for container with name '${1}' to be started manually...." |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 430 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 431 | 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 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 440 | fi |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 441 | done |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 442 | |
| 443 | echo "Connecting container "$1" to simulator network "$DOCKER_SIM_NWNAME |
| 444 | docker network connect $DOCKER_SIM_NWNAME $1 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 445 | } |
| 446 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 447 | #WFunction for waiting for named container to be stopped manually. |
| 448 | __wait_for_container_gone() { |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 449 | start=$SECONDS |
| 450 | if [ $# != 1 ]; then |
| 451 | echo "Need one arg: <container-name>" |
| 452 | exit 1 |
| 453 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 454 | echo "Disconnecting container "$1" from simulator network "$DOCKER_SIM_NWNAME |
| 455 | docker network disconnect $DOCKER_SIM_NWNAME $1 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 456 | 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 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 467 | fi |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 468 | done |
| 469 | } |
| 470 | |
| 471 | #Function for waiting to dfc to be started manually |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 472 | __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" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | #Function for waiting to dfc to be stopped manually |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 483 | __wait_for_dfc_gone() { |
| 484 | read -p "Press enter to continue when when app mapping to ${1} has been manually stopped" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | ############################################################# |
| 488 | ############## Functions for auto test scripts ############## |
| 489 | ############################################################# |
| 490 | |
| 491 | # Print the env variables needed for the simulators and their setup |
| 492 | log_sim_settings() { |
| 493 | echo "Simulator settings" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 494 | 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 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 511 | echo "" |
| 512 | } |
| 513 | |
| 514 | # Stop and remove all containers including dfc app and simulators |
| 515 | clean_containers() { |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 516 | echo "Stopping all containers, dfc app(s) and simulators with name prefix 'dfc_'" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 517 | 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 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 520 | echo "Removing unused docker networks with substring 'dfc' in network name" |
| 521 | docker network rm $(docker network ls -q --filter name=dfc) |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 522 | echo "" |
| 523 | } |
| 524 | |
| 525 | # Start all simulators in the simulator group |
| 526 | start_simulators() { |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 527 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 528 | 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 |
| 537 | start_dfc() { |
| 538 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 539 | 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 |
ecaiyanlinux | 796e8fe | 2019-08-21 12:10:33 +0000 | [diff] [blame] | 547 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 548 | appname=$DFC_APP_BASE$1 |
| 549 | STARTED_DFCS=$STARTED_DFCS"_"$appname"_" |
| 550 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 551 | if [ $START_ARG == "local" ] || [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 552 | __start_dfc_image $appname $1 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 553 | elif [ $START_ARG == "manual-container" ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 554 | __wait_for_container $appname $1 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 555 | elif [ $START_ARG == "manual-app" ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 556 | __wait_for_dfc $appname $1 |
| 557 | fi |
| 558 | } |
| 559 | |
maximesson | 69311bf | 2019-08-30 14:05:15 +0000 | [diff] [blame] | 560 | # Configure consul with dfc config, args <dfc-instance-id> <json-file-path> |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 561 | # Not intended to be called directly by test scripts. |
| 562 | __consul_config() { |
| 563 | |
maximesson | 69311bf | 2019-08-30 14:05:15 +0000 | [diff] [blame] | 564 | if [ $# != 2 ]; then |
| 565 | __print_err "need two args, <dfc-instance-id> <json-file-path>" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 566 | exit 1 |
| 567 | fi |
| 568 | |
maximesson | 69311bf | 2019-08-30 14:05:15 +0000 | [diff] [blame] | 569 | if [ $1 -lt 0 ] || [ $1 -gt $DFC_MAX_IDX ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 570 | __print_err "dfc-instance-id should be 0.."$DFC_MAX_IDX |
| 571 | exit 1 |
| 572 | fi |
maximesson | 69311bf | 2019-08-30 14:05:15 +0000 | [diff] [blame] | 573 | if ! [ -f $2 ]; then |
| 574 | __print_err "json file does not extis: "$2 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 575 | exit 1 |
| 576 | fi |
| 577 | |
maximesson | 69311bf | 2019-08-30 14:05:15 +0000 | [diff] [blame] | 578 | appname=$DFC_APP_BASE$1 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 579 | |
maximesson | 69311bf | 2019-08-30 14:05:15 +0000 | [diff] [blame] | 580 | echo "Configuring consul for " $appname " from " $2 |
| 581 | 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 "@"$2 >/dev/null |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | # Configure consul with dfc app config, args <dfc-instance-id> <json-file-path> |
| 585 | consul_config_app() { |
| 586 | if [ $START_ARG == "manual-app" ]; then |
| 587 | echo "Replacing 'mrsim' with 'localhost' in json app config for consul" |
| 588 | sed 's/mrsim/localhost/g' $2 > .tmp_app.json |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 589 | echo "Replacing 'drsim' with 'localhost' in json dmaap config for consul" |
maximesson | 69311bf | 2019-08-30 14:05:15 +0000 | [diff] [blame] | 590 | sed 's/drsim/localhost/g' .tmp_app.json > .app.json |
| 591 | __consul_config $1 .app.json |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 592 | else |
maximesson | 69311bf | 2019-08-30 14:05:15 +0000 | [diff] [blame] | 593 | __consul_config $1 $2 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 594 | fi |
| 595 | } |
| 596 | |
| 597 | # Stop and remove the dfc app container |
| 598 | kill_dfc() { |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 599 | |
| 600 | if [ $# != 1 ]; then |
| 601 | __print_err "need one arg, <dfc-instance-id>" |
| 602 | exit 1 |
| 603 | fi |
| 604 | |
| 605 | if [ $1 -lt 0 ] || [ $1 -gt $DFC_MAX_IDX ]; then |
| 606 | __print_err "arg should be 0.."$DFC_MAX_IDX |
| 607 | exit 1 |
| 608 | fi |
| 609 | appname=$DFC_APP_BASE$1 |
| 610 | |
| 611 | echo "Killing DFC, instance id: "$1 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 612 | |
| 613 | if [ $START_ARG == "local" ] || [ $START_ARG == "remote" ] || [ $START_ARG == "remote-remove" ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 614 | __docker_stop $appname |
| 615 | __docker_rm $appname |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 616 | elif [ $START_ARG == "manual-container" ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 617 | __wait_for_container_gone $appname |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 618 | elif [ $START_ARG == "manual-app" ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 619 | __wait_for_dfc_gone $appname |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 620 | fi |
| 621 | } |
| 622 | |
| 623 | # Stop and remove the DR simulator container |
| 624 | kill_dr() { |
| 625 | echo "Killing DR sim" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 626 | __docker_stop dfc_dr-sim |
| 627 | __docker_rm dfc_dr-sim |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | # Stop and remove the DR redir simulator container |
| 631 | kill_drr() { |
| 632 | echo "Killing DR redir sim" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 633 | __docker_stop dfc_dr-redir-sim |
| 634 | __docker_rm dfc_dr-redir-sim |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | # Stop and remove the MR simulator container |
| 638 | kill_mr() { |
| 639 | echo "Killing MR sim" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 640 | __docker_stop dfc_mr-sim |
| 641 | __docker_rm dfc_mr-sim |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 642 | } |
| 643 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 644 | # Stop and remove the SFTP container, arg: <sftp-instance-id> |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 645 | kill_sftp() { |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 646 | |
| 647 | if [ $# != 1 ]; then |
| 648 | __print_err "need one arg, <sftp-instance-id>" |
| 649 | exit 1 |
| 650 | fi |
| 651 | |
| 652 | if [ $1 -lt 0 ] || [ $1 -gt $FTP_MAX_IDX ]; then |
| 653 | __print_err "arg should be 0.."$FTP_MAX_IDX |
| 654 | exit 1 |
| 655 | fi |
| 656 | appname=$SFTP_BASE$1 |
| 657 | |
| 658 | echo "Killing SFTP, instance id: "$1 |
| 659 | |
| 660 | __docker_stop $appname |
| 661 | __docker_rm $appname |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 662 | } |
| 663 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 664 | # Stop SFTP container, arg: <sftp-instance-id> |
| 665 | stop_sftp() { |
| 666 | |
| 667 | if [ $# != 1 ]; then |
| 668 | __print_err "need one arg, <sftp-instance-id>" |
| 669 | exit 1 |
| 670 | fi |
| 671 | |
| 672 | if [ $1 -lt 0 ] || [ $1 -gt $FTP_MAX_IDX ]; then |
| 673 | __print_err "arg should be 0.."$FTP_MAX_IDX |
| 674 | exit 1 |
| 675 | fi |
| 676 | appname=$SFTP_BASE$1 |
| 677 | |
| 678 | echo "Stopping SFTP, instance id: "$1 |
| 679 | |
| 680 | __docker_stop $appname |
| 681 | } |
| 682 | |
| 683 | # Starts a stopped SFTP container, arg: <sftp-instance-id> |
| 684 | start_sftp() { |
| 685 | |
| 686 | if [ $# != 1 ]; then |
| 687 | __print_err "need one arg, <sftp-instance-id>" |
| 688 | exit 1 |
| 689 | fi |
| 690 | |
| 691 | if [ $1 -lt 0 ] || [ $1 -gt $FTP_MAX_IDX ]; then |
| 692 | __print_err "arg should be 0.."$FTP_MAX_IDX |
| 693 | exit 1 |
| 694 | fi |
| 695 | appname=$SFTP_BASE$1 |
| 696 | |
| 697 | echo "Starting SFTP, instance id: "$1 |
| 698 | |
| 699 | __docker_start $appname |
| 700 | } |
| 701 | |
| 702 | # Stop and remove the FTPS container, arg: <ftps-instance-id> |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 703 | kill_ftps() { |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 704 | |
| 705 | if [ $# != 1 ]; then |
| 706 | __print_err "need one arg, <ftpS-instance-id>" |
| 707 | exit 1 |
| 708 | fi |
| 709 | |
| 710 | if [ $1 -lt 0 ] || [ $1 -gt $FTP_MAX_IDX ]; then |
| 711 | __print_err "arg should be 0.."$FTP_MAX_IDX |
| 712 | exit 1 |
| 713 | fi |
| 714 | appname=$FTPS_BASE$1 |
| 715 | |
| 716 | echo "Killing FTPS, instance id: "$1 |
| 717 | |
| 718 | __docker_stop $appname |
| 719 | __docker_rm $appname |
| 720 | } |
| 721 | |
| 722 | # Stop FTPS container, arg: <ftps-instance-id> |
| 723 | stop_ftps() { |
| 724 | |
| 725 | if [ $# != 1 ]; then |
| 726 | __print_err "need one arg, <ftps-instance-id>" |
| 727 | exit 1 |
| 728 | fi |
| 729 | |
| 730 | if [ $1 -lt 0 ] || [ $1 -gt $FTP_MAX_IDX ]; then |
| 731 | __print_err "arg should be 0.."$FTP_MAX_IDX |
| 732 | exit 1 |
| 733 | fi |
| 734 | appname=$FTPS_BASE$1 |
| 735 | |
| 736 | echo "Stopping FTPS, instance id: "$1 |
| 737 | |
| 738 | __docker_stop $appname |
| 739 | } |
| 740 | |
| 741 | # Starts a stopped FTPS container, arg: <ftps-instance-id> |
| 742 | start_ftps() { |
| 743 | |
| 744 | if [ $# != 1 ]; then |
| 745 | __print_err "need one arg, <ftps-instance-id>" |
| 746 | exit 1 |
| 747 | fi |
| 748 | |
| 749 | if [ $1 -lt 0 ] || [ $1 -gt $FTP_MAX_IDX ]; then |
| 750 | __print_err "arg should be 0.."$FTP_MAX_IDX |
| 751 | exit 1 |
| 752 | fi |
| 753 | appname=$FTPS_BASE$1 |
| 754 | |
| 755 | echo "Starting FTPS, instance id: "$1 |
| 756 | |
| 757 | __docker_start $appname |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | # Print a variable value from the MR simulator. Arg: <variable-name> |
| 761 | mr_print() { |
| 762 | if [ $# != 1 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 763 | __print_err "need one arg, <sim-param>" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 764 | exit 1 |
| 765 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 766 | echo -e "---- MR sim, \033[1m $1 \033[0m: $(__do_curl http://127.0.0.1:$MR_PORT/$1)" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 767 | } |
| 768 | |
ecaiyanlinux | 796e8fe | 2019-08-21 12:10:33 +0000 | [diff] [blame] | 769 | # Print a variable value from the MR https simulator. Arg: <variable-name> |
| 770 | mr_secure_print() { |
| 771 | if [ $# != 1 ]; then |
| 772 | __print_err "need one arg, <sim-param>" |
| 773 | exit 1 |
| 774 | fi |
| 775 | echo -e "---- MR sim, \033[1m $1 \033[0m: $(__do_curl https://127.0.0.1:$MR_PORT_SECURE/$1)" |
| 776 | } |
| 777 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 778 | # Print a variable value from the DR simulator. Arg: <variable-name> |
| 779 | dr_print() { |
| 780 | if [ $# != 1 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 781 | __print_err "need one arg, <sim-param>" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 782 | exit 1 |
| 783 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 784 | echo -e "---- DR sim, \033[1m $1 \033[0m: $(__do_curl http://127.0.0.1:$DR_PORT/$1)" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | # Print a variable value from the DR redir simulator. Arg: <variable-name> |
| 788 | drr_print() { |
| 789 | if [ $# != 1 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 790 | __print_err "need one arg, <sim-param>" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 791 | exit 1 |
| 792 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 793 | echo -e "---- DR redir sim, \033[1m $1 \033[0m: $(__do_curl http://127.0.0.1:$DRR_PORT/$1)" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 794 | } |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 795 | # Print a variable value from dfc. Arg: <dfc-instance-id> <variable-name> |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 796 | dfc_print() { |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 797 | if [ $# != 2 ]; then |
| 798 | __print_err "need two args, <dfc-instance-id> <dfc-param>" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 799 | exit 1 |
| 800 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 801 | if [ $1 -lt 0 ] || [ $1 -gt $DFC_MAX_IDX ]; then |
| 802 | __print_err "dfc instance id should be in range 0.."DFC_MAX_IDX |
| 803 | exit 1 |
| 804 | fi |
| 805 | localport=$(($DFC_PORT + $1)) |
| 806 | appname=$DFC_APP_BASE$1 |
| 807 | echo -e "---- DFC $appname, \033[1m $2 \033[0m: $(__do_curl http://127.0.0.1:$localport/$2)" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 808 | } |
| 809 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 810 | # Read a variable value from MR sim and send to stdout. Arg: <variable-name> |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 811 | mr_read() { |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 812 | echo "$(__do_curl http://127.0.0.1:$MR_PORT/$1)" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 813 | } |
| 814 | |
ecaiyanlinux | 796e8fe | 2019-08-21 12:10:33 +0000 | [diff] [blame] | 815 | # Read a variable value from MR https sim and send to stdout. Arg: <variable-name> |
| 816 | mr_secure_read() { |
| 817 | echo "$(__do_curl https://127.0.0.1:$MR_PORT_SECURE/$1)" |
| 818 | } |
| 819 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 820 | # Read a variable value from DR sim and send to stdout. Arg: <variable-name> |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 821 | dr_read() { |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 822 | echo "$(__do_curl http://127.0.0.1:$DR_PORT/$1)" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 823 | } |
| 824 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 825 | # Read a variable value from DR redir sim and send to stdout. Arg: <variable-name> |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 826 | drr_read() { |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 827 | echo "$(__do_curl http://127.0.0.1:$DRR_PORT/$1)" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | |
| 831 | # Sleep. Arg: <sleep-time-in-sec> |
| 832 | sleep_wait() { |
| 833 | if [ $# != 1 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 834 | __print_err "need one arg, <sleep-time-in-sec>" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 835 | exit 1 |
| 836 | fi |
| 837 | echo "---- Sleep for " $1 " seconds ----" |
| 838 | start=$SECONDS |
| 839 | duration=$((SECONDS-start)) |
| 840 | while [ $duration -lt $1 ]; do |
| 841 | echo -ne " Slept for ${duration} seconds\033[0K\r" |
| 842 | sleep 1 |
| 843 | duration=$((SECONDS-start)) |
| 844 | done |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 845 | echo "" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | # Sleep and print dfc heartbeat. Arg: <sleep-time-in-sec> |
| 849 | sleep_heartbeat() { |
| 850 | if [ $# != 1 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 851 | __print_err "need one arg, <sleep-time-in-sec>" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 852 | exit 1 |
| 853 | fi |
| 854 | echo "---- Sleep for " $1 " seconds ----" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 855 | echo "" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 856 | start=$SECONDS |
| 857 | duration=$((SECONDS-start)) |
| 858 | ctr=0 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 859 | rows=0 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 860 | while [ $duration -lt $1 ]; do |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 861 | if [ $rows -eq 0 ]; then |
| 862 | tput cuu1 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 863 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 864 | rows=0 |
| 865 | echo " Slept for ${duration} seconds" |
| 866 | if [ $((ctr%30)) -eq 0 ]; then |
| 867 | for (( i=0; i<=$DFC_MAX_IDX; i++ )); do |
| 868 | if [[ $STARTED_DFCS =~ "_"$DFC_APP_BASE$i"_" ]]; then |
| 869 | let rows=rows+1 |
| 870 | echo " HB ${DFC_APP_BASE}${i}: $(__do_curl http://127.0.0.1:$(($DFC_PORT+$i))/heartbeat)" |
| 871 | fi |
| 872 | done |
| 873 | fi |
| 874 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 875 | let ctr=ctr+1 |
| 876 | sleep 1 |
| 877 | duration=$((SECONDS-start)) |
| 878 | done |
| 879 | echo "" |
| 880 | } |
| 881 | |
| 882 | # Tests if a variable value in the MR simulator is equal to a target value and and optional timeout. |
| 883 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 884 | # equal to the target or not. |
| 885 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 886 | # before setting pass or fail depending on if the variable value becomes equal to the target |
| 887 | # value or not. |
| 888 | mr_equal() { |
| 889 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 890 | __var_test "MR" "http://127.0.0.1:$MR_PORT/" $1 "=" $2 $3 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 891 | else |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 892 | __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 893 | fi |
| 894 | } |
| 895 | |
ecaiyanlinux | 796e8fe | 2019-08-21 12:10:33 +0000 | [diff] [blame] | 896 | mr_secure_equal() { |
| 897 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 898 | __var_test "MR" "https://127.0.0.1:$MR_PORT_SECURE/" $1 "=" $2 $3 |
| 899 | else |
| 900 | __print_err "Wrong args to mr_secure_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" |
| 901 | fi |
| 902 | } |
| 903 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 904 | # Tests if a variable value in the MR simulator is greater than a target value and and optional timeout. |
| 905 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 906 | # greater than the target or not. |
| 907 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 908 | # before setting pass or fail depending on if the variable value greater than the target |
| 909 | # value or not. |
| 910 | mr_greater() { |
| 911 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 912 | __var_test "MR" "http://127.0.0.1:$MR_PORT/" $1 ">" $2 $3 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 913 | else |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 914 | __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 915 | fi |
| 916 | } |
| 917 | |
ecaiyanlinux | 796e8fe | 2019-08-21 12:10:33 +0000 | [diff] [blame] | 918 | mr_secure_greater() { |
| 919 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 920 | __var_test "MR" "https://127.0.0.1:$MR_PORT_SECURE/" $1 ">" $2 $3 |
| 921 | else |
| 922 | __print_err "Wrong args to mr_secure_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" |
| 923 | fi |
| 924 | } |
| 925 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 926 | # Tests if a variable value in the MR simulator is less than a target value and and optional timeout. |
| 927 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 928 | # less than the target or not. |
| 929 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 930 | # before setting pass or fail depending on if the variable value less than the target |
| 931 | # value or not. |
| 932 | mr_less() { |
| 933 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 934 | __var_test "MR" "http://127.0.0.1:$MR_PORT/" $1 "<" $2 $3 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 935 | else |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 936 | __print_err "Wrong args to mr_less, needs two or three args: <sim-param> <target-value> [ timeout ]" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 937 | fi |
| 938 | } |
ecaiyanlinux | 796e8fe | 2019-08-21 12:10:33 +0000 | [diff] [blame] | 939 | mr_secure_less() { |
| 940 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 941 | __var_test "MR" "https://127.0.0.1:$MR_PORT_SECURE/" $1 "<" $2 $3 |
| 942 | else |
| 943 | __print_err "Wrong args to mr_secure_less, needs two or three args: <sim-param> <target-value> [ timeout ]" |
| 944 | fi |
| 945 | } |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 946 | |
| 947 | # Tests if a variable value in the MR simulator contains the target string and and optional timeout. |
| 948 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable contains |
| 949 | # the target or not. |
| 950 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 951 | # before setting pass or fail depending on if the variable value contains the target |
| 952 | # value or not. |
| 953 | mr_contain_str() { |
| 954 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 955 | __var_test "MR" "http://127.0.0.1:$MR_PORT/" $1 "contain_str" $2 $3 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 956 | else |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 957 | __print_err "Wrong args to mr_contain_str, needs two or three args: <sim-param> <target-value> [ timeout ]" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 958 | fi |
| 959 | } |
ecaiyanlinux | 796e8fe | 2019-08-21 12:10:33 +0000 | [diff] [blame] | 960 | mr_secure_contain_str() { |
| 961 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 962 | __var_test "MR" "https://127.0.0.1:$MR_PORT_SECURE/" $1 "contain_str" $2 $3 |
| 963 | else |
| 964 | __print_err "Wrong args to mr_secure_contain_str, needs two or three args: <sim-param> <target-value> [ timeout ]" |
| 965 | fi |
| 966 | } |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 967 | |
| 968 | # Tests if a variable value in the DR simulator is equal to a target value and and optional timeout. |
| 969 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 970 | # equal to the target or not. |
| 971 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 972 | # before setting pass or fail depending on if the variable value becomes equal to the target |
| 973 | # value or not. |
| 974 | dr_equal() { |
| 975 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 976 | __var_test "DR" "http://127.0.0.1:$DR_PORT/" $1 "=" $2 $3 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 977 | else |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 978 | __print_err "Wrong args to dr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 979 | fi |
| 980 | } |
| 981 | |
| 982 | # Tests if a variable value in the DR simulator is greater than a target value and and optional timeout. |
| 983 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 984 | # greater than the target or not. |
| 985 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 986 | # before setting pass or fail depending on if the variable value greater than the target |
| 987 | # value or not. |
| 988 | dr_greater() { |
| 989 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 990 | __var_test "DR" "http://127.0.0.1:$DR_PORT/" $1 ">" $2 $3 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 991 | else |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 992 | __print_err "Wrong args to dr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 993 | fi |
| 994 | } |
| 995 | |
| 996 | # Tests if a variable value in the DR simulator is less than a target value and and optional timeout. |
| 997 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 998 | # less than the target or not. |
| 999 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 1000 | # before setting pass or fail depending on if the variable value less than the target |
| 1001 | # value or not. |
| 1002 | dr_less() { |
| 1003 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1004 | __var_test "DR" "http://127.0.0.1:$DR_PORT/" $1 "<" $2 $3 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1005 | else |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1006 | __print_err "Wrong args to dr_less, needs two or three args: <sim-param> <target-value> [ timeout ]" |
| 1007 | fi |
| 1008 | } |
| 1009 | |
| 1010 | # Tests if a variable value in the DR simulator contains the target string and and optional timeout. |
| 1011 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable contains |
| 1012 | # the target or not. |
| 1013 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 1014 | # before setting pass or fail depending on if the variable value contains the target |
| 1015 | # value or not. |
| 1016 | dr_contain_str() { |
| 1017 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 1018 | __var_test "DR" "http://127.0.0.1:$DR_PORT/" $1 "contain_str" $2 $3 |
| 1019 | else |
| 1020 | __print_err "Wrong args to dr_contain_str, needs two or three args: <sim-param> <target-value> [ timeout ]" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1021 | fi |
| 1022 | } |
| 1023 | |
| 1024 | # Tests if a variable value in the DR Redir simulator is equal to a target value and and optional timeout. |
| 1025 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 1026 | # equal to the target or not. |
| 1027 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 1028 | # before setting pass or fail depending on if the variable value becomes equal to the target |
| 1029 | # value or not. |
| 1030 | drr_equal() { |
| 1031 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1032 | __var_test "DR REDIR" "http://127.0.0.1:$DRR_PORT/" $1 "=" $2 $3 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1033 | else |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1034 | __print_err "Wrong args to drr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1035 | fi |
| 1036 | } |
| 1037 | |
| 1038 | |
| 1039 | # Tests if a variable value in the DR Redir simulator is greater a target value and and optional timeout. |
| 1040 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 1041 | # greater the target or not. |
| 1042 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 1043 | # before setting pass or fail depending on if the variable value greater than the target |
| 1044 | # value or not. |
| 1045 | drr_greater() { |
| 1046 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1047 | __var_test "DR REDIR" "http://127.0.0.1:$DRR_PORT/" $1 ">" $2 $3 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1048 | else |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1049 | __print_err "Wrong args to drr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1050 | fi |
| 1051 | } |
| 1052 | |
| 1053 | # Tests if a variable value in the DR Redir simulator is less than a target value and and optional timeout. |
| 1054 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 1055 | # less than the target or not. |
| 1056 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 1057 | # before setting pass or fail depending on if the variable value less than the target |
| 1058 | # value or not. |
| 1059 | drr_less() { |
| 1060 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1061 | __var_test "DR REDIR" "http://127.0.0.1:$DRR_PORT/" $1 "<" $2 $3 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1062 | else |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1063 | __print_err "Wrong args to drr_less, needs two or three args: <sim-param> <target-value> [ timeout ]" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1064 | fi |
| 1065 | } |
| 1066 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1067 | # Tests if a variable value in the DR redir simulator contains the target string and and optional timeout. |
| 1068 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable contains |
| 1069 | # the target or not. |
| 1070 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 1071 | # before setting pass or fail depending on if the variable value contains the target |
| 1072 | # value or not. |
| 1073 | drr_contain_str() { |
| 1074 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 1075 | __var_test "DR REDIR" "http://127.0.0.1:$DRR_PORT/" $1 "contain_str" $2 $3 |
| 1076 | else |
| 1077 | __print_err "Wrong args to drr_contain_str, needs two or three args: <sim-param> <target-value> [ timeout ]" |
| 1078 | fi |
| 1079 | } |
| 1080 | |
| 1081 | #Test if a variable in the DFC contains a substring. Arg: <dfc-index> <variable-name> <substring-in-quotes> |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1082 | dfc_contain_str() { |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1083 | if [ $# -eq 3 ]; then |
| 1084 | if [ $1 -lt 0 ] || [ $1 -gt $DFC_MAX_IDX ]; then |
| 1085 | __print_err "arg should be 0.."$DFC_MAX_IDX |
| 1086 | exit 1 |
| 1087 | fi |
| 1088 | appname=$DFC_APP_BASE$1 |
| 1089 | localport=$(($DFC_PORT + $1)) |
| 1090 | echo -e "---- DFC test criteria: $appname \033[1m ${2} \033[0m contains: ${3} ----" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1091 | ((RES_TEST++)) |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1092 | result="$(__do_curl http://127.0.0.1:$localport/${2})" |
| 1093 | if [[ $result =~ $3 ]]; then |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1094 | ((RES_PASS++)) |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1095 | echo -e "---- \033[32m\033[1mPASS\033[0m - Test criteria met" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1096 | else |
| 1097 | ((RES_FAIL++)) |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1098 | echo -e "---- \033[31m\033[1mFAIL\033[0m - Target '${3}' not reached, result = ${result} ----" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1099 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1100 | else |
| 1101 | echo "Wrong args to dfc_contain_str, needs three arg: <dfc-index> <dfc-variable> <str>" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1102 | exit 1 |
| 1103 | fi |
| 1104 | } |
| 1105 | |
| 1106 | # Store all dfc app and simulators log to the test case log dir. All logs gets a prefix to |
| 1107 | # separate logs stored at different steps in the test script. Arg: <tc-id> <log-prefix> |
| 1108 | store_logs() { |
| 1109 | if [ $# != 1 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1110 | __print_err "need one arg, <file-prefix>" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1111 | exit 1 |
| 1112 | fi |
| 1113 | echo "Storing all container logs and dfc app log using prefix: "$1 |
| 1114 | if ! [ $START_ARG == "manual-app" ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1115 | for (( i=0; i<=$DFC_MAX_IDX; i++ )); do |
| 1116 | appname=$DFC_APP_BASE$i |
| 1117 | tmp=$(docker ps | grep $appname) |
| 1118 | if ! [ -z "$tmp" ]; then #Only stored logs from running DFC apps |
| 1119 | docker cp $appname:/var/log/ONAP/application.log $TESTLOGS/$ATC/${1}_${appname}_application.log |
| 1120 | docker logs $appname > $TESTLOGS/$ATC/$1_$appname-docker.log 2>&1 |
| 1121 | fi |
| 1122 | done |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1123 | fi |
| 1124 | docker logs dfc_mr-sim > $TESTLOGS/$ATC/$1_dfc_mr-sim-docker.log 2>&1 |
| 1125 | docker logs dfc_dr-sim > $TESTLOGS/$ATC/$1_dfc_dr-sim-docker.log 2>&1 |
| 1126 | docker logs dfc_dr-redir-sim > $TESTLOGS/$ATC/$1_dfc_dr-redir-sim-docker.log 2>&1 |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1127 | |
| 1128 | for (( i=0; i<=$FTP_MAX_IDX; i++ )); do |
| 1129 | appname=$SFTP_BASE$i |
| 1130 | docker logs $appname > $TESTLOGS/$ATC/${1}_${appname}.log 2>&1 |
| 1131 | appname=$FTPS_BASE$i |
| 1132 | docker logs $appname > $TESTLOGS/$ATC/${1}_${appname}.log 2>&1 |
| 1133 | done |
| 1134 | |
| 1135 | docker logs dfc_consul > $TESTLOGS/$ATC/$1_consul.log 2>&1 |
| 1136 | docker logs dfc_cbs > $TESTLOGS/$ATC/$1_cbs.log 2>&1 |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1137 | } |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1138 | # Check the dfc application log, for all dfc instances, for WARN and ERR messages and print the count. |
| 1139 | check_dfc_logs() { |
| 1140 | for (( i=0; i<=$DFC_MAX_IDX; i++ )); do |
| 1141 | appname=$DFC_APP_BASE$i |
| 1142 | tmp=$(docker ps | grep $appname) |
| 1143 | if ! [ -z "$tmp" ]; then #Only check logs for running dfc_apps |
| 1144 | _check_dfc_log $appname |
| 1145 | fi |
| 1146 | done |
| 1147 | } |
| 1148 | |
| 1149 | # Check dfc app log for one dfc instance, arg <dfc-app-name> |
| 1150 | _check_dfc_log() { |
| 1151 | echo "Checking $1 log $DFC_LOGPATH for WARNINGs and ERRORs" |
| 1152 | foundentries=$(docker exec -it $1 grep WARN /var/log/ONAP/application.log | wc -l) |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1153 | if [ $? -ne 0 ];then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1154 | echo " Problem to search $1 log $DFC_LOGPATH" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1155 | else |
| 1156 | if [ $foundentries -eq 0 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1157 | echo " No WARN entries found in $1 log $DFC_LOGPATH" |
| 1158 | else |
| 1159 | echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $1 log $DFC_LOGPATH" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1160 | fi |
| 1161 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1162 | foundentries=$(docker exec -it $1 grep ERR $DFC_LOGPATH | wc -l) |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1163 | if [ $? -ne 0 ];then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1164 | echo " Problem to search $1 log $DFC_LOGPATH" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1165 | else |
| 1166 | if [ $foundentries -eq 0 ]; then |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1167 | echo " No ERR entries found in $1 log $DFC_LOGPATH" |
| 1168 | else |
| 1169 | echo -e " Found \033[1m"$foundentries"\033[0m ERR entries in $1 log $DFC_LOGPATH" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1170 | fi |
| 1171 | fi |
| 1172 | } |
| 1173 | |
| 1174 | print_all() { |
| 1175 | |
| 1176 | echo "---- DFC and all sim variables" |
| 1177 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1178 | for (( i=0; i<=$DFC_MAX_IDX; i++ )); do |
| 1179 | appname=$DFC_APP_BASE$i |
| 1180 | tmp=$(docker ps | grep $appname) |
| 1181 | if ! [ -z "$tmp" ]; then #Only check running dfc_apps |
| 1182 | dfc_print $i status |
| 1183 | fi |
| 1184 | done |
| 1185 | |
| 1186 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1187 | mr_print tc_info |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1188 | mr_print status |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1189 | mr_print execution_time |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1190 | mr_print groups |
| 1191 | mr_print changeids |
| 1192 | mr_print fileprefixes |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1193 | mr_print exe_time_first_poll |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1194 | mr_print groups/exe_time_first_poll |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1195 | mr_print ctr_requests |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1196 | mr_print groups/ctr_requests |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1197 | mr_print ctr_responses |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1198 | mr_print groups/ctr_responses |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1199 | mr_print ctr_files |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1200 | mr_print groups/ctr_files |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1201 | mr_print ctr_unique_files |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1202 | mr_print groups/ctr_unique_files |
| 1203 | mr_print groups/ctr_events |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1204 | mr_print ctr_events |
| 1205 | mr_print ctr_unique_PNFs |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1206 | mr_print groups/ctr_unique_PNFs |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1207 | |
| 1208 | dr_print tc_info |
| 1209 | dr_print execution_time |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1210 | dr_print feeds |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1211 | dr_print ctr_publish_query |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1212 | dr_print feeds/ctr_publish_query |
| 1213 | dr_print ctr_publish_query_bad_file_prefix |
| 1214 | dr_print feeds/ctr_publish_query_bad_file_prefix |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1215 | dr_print ctr_publish_query_published |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1216 | dr_print feeds/ctr_publish_query_published |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1217 | dr_print ctr_publish_query_not_published |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1218 | dr_print feeds/ctr_publish_query_not_published |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1219 | dr_print ctr_publish_req |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1220 | dr_print feeds/ctr_publish_req |
| 1221 | dr_print ctr_publish_req_bad_file_prefix |
| 1222 | dr_print feeds/ctr_publish_req_bad_file_prefix |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1223 | dr_print ctr_publish_req_redirect |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1224 | dr_print feeds/ctr_publish_req_redirect |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1225 | dr_print ctr_publish_req_published |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1226 | dr_print feeds/ctr_publish_req_published |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1227 | dr_print ctr_published_files |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1228 | dr_print feeds/ctr_published_files |
| 1229 | dr_print ctr_double_publish |
| 1230 | dr_print feeds/ctr_double_publish |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1231 | |
| 1232 | drr_print tc_info |
| 1233 | drr_print execution_time |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1234 | drr_print feeds |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1235 | drr_print ctr_publish_requests |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1236 | drr_print feeds/ctr_publish_requests |
| 1237 | drr_print ctr_publish_requests_bad_file_prefix |
| 1238 | drr_print feeds/ctr_publish_requests_bad_file_prefix |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1239 | drr_print ctr_publish_responses |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1240 | drr_print feeds/ctr_publish_responses |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1241 | drr_print dwl_volume |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1242 | drr_print feeds/dwl_volume |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1243 | drr_print time_lastpublish |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1244 | drr_print feeds/time_lastpublish |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1247 | # Print the test result |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1248 | print_result() { |
| 1249 | |
| 1250 | TCTEST_END=$SECONDS |
| 1251 | duration=$((TCTEST_END-TCTEST_START)) |
| 1252 | |
| 1253 | echo "-------------------------------------------------------------------------------------------------" |
| 1254 | echo "------------------------------------- Test case: "$ATC |
| 1255 | echo "------------------------------------- Ended: "$(date) |
| 1256 | echo "-------------------------------------------------------------------------------------------------" |
| 1257 | echo "-- Description: "$TC_ONELINE_DESCR |
| 1258 | echo "-- Execution time: " $duration " seconds" |
| 1259 | echo "-------------------------------------------------------------------------------------------------" |
| 1260 | echo "------------------------------------- RESULTS" |
| 1261 | echo "" |
| 1262 | |
| 1263 | |
| 1264 | total=$((RES_PASS+RES_FAIL)) |
| 1265 | if [ $RES_TEST -eq 0 ]; then |
| 1266 | echo -e "\033[1mNo tests seem to have executed. Check the script....\033[0m" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1267 | echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m" |
| 1268 | echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m" |
| 1269 | echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m" |
| 1270 | echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1271 | elif [ $total != $RES_TEST ]; then |
| 1272 | echo -e "\033[1mTotal number of tests does not match the sum of passed and failed tests. Check the script....\033[0m" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1273 | echo -e "\033[31m\033[1m ___ ___ ___ ___ ___ _____ ___ _ ___ _ _ _ ___ ___ \033[0m" |
| 1274 | echo -e "\033[31m\033[1m/ __|/ __| _ \_ _| _ \_ _| | __/_\ |_ _| | | | | | _ \ __|\033[0m" |
| 1275 | echo -e "\033[31m\033[1m\__ \ (__| /| || _/ | | | _/ _ \ | || |_| |_| | / _| \033[0m" |
| 1276 | echo -e "\033[31m\033[1m|___/\___|_|_\___|_| |_| |_/_/ \_\___|____\___/|_|_\___|\033[0m" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1277 | elif [ $RES_PASS = $RES_TEST ]; then |
| 1278 | echo -e "All tests \033[32m\033[1mPASS\033[0m" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1279 | echo -e "\033[32m\033[1m ___ _ ___ ___ \033[0m" |
| 1280 | echo -e "\033[32m\033[1m | _ \/_\ / __/ __| \033[0m" |
| 1281 | echo -e "\033[32m\033[1m | _/ _ \\__ \__ \\ \033[0m" |
| 1282 | echo -e "\033[32m\033[1m |_|/_/ \_\___/___/ \033[0m" |
| 1283 | echo "" |
| 1284 | |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1285 | # Update test suite counter |
| 1286 | if [ -f .tmp_tcsuite_pass_ctr ]; then |
| 1287 | tmpval=$(< .tmp_tcsuite_pass_ctr) |
| 1288 | ((tmpval++)) |
| 1289 | echo $tmpval > .tmp_tcsuite_pass_ctr |
| 1290 | fi |
| 1291 | if [ -f .tmp_tcsuite_pass ]; then |
| 1292 | echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_pass |
| 1293 | fi |
| 1294 | else |
| 1295 | echo -e "One or more tests with status \033[31m\033[1mFAIL\033[0m " |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 1296 | echo -e "\033[31m\033[1m ___ _ ___ _ \033[0m" |
| 1297 | echo -e "\033[31m\033[1m | __/_\ |_ _| | \033[0m" |
| 1298 | echo -e "\033[31m\033[1m | _/ _ \ | || |__ \033[0m" |
| 1299 | echo -e "\033[31m\033[1m |_/_/ \_\___|____|\033[0m" |
| 1300 | echo "" |
BjornMagnussonXA | 42dcb26 | 2019-04-26 19:29:54 +0000 | [diff] [blame] | 1301 | # Update test suite counter |
| 1302 | if [ -f .tmp_tcsuite_fail_ctr ]; then |
| 1303 | tmpval=$(< .tmp_tcsuite_fail_ctr) |
| 1304 | ((tmpval++)) |
| 1305 | echo $tmpval > .tmp_tcsuite_fail_ctr |
| 1306 | fi |
| 1307 | if [ -f .tmp_tcsuite_fail ]; then |
| 1308 | echo " - "$ATC " -- "$TC_ONELINE_DESCR" Execution time: "$duration" seconds" >> .tmp_tcsuite_fail |
| 1309 | fi |
| 1310 | fi |
| 1311 | |
| 1312 | echo "++++ Number of tests: "$RES_TEST |
| 1313 | echo "++++ Number of passed tests: "$RES_PASS |
| 1314 | echo "++++ Number of failed tests: "$RES_FAIL |
| 1315 | echo "------------------------------------- Test case complete ---------------------------------" |
| 1316 | echo "-------------------------------------------------------------------------------------------------" |
| 1317 | echo "" |
| 1318 | } |