BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # ============LICENSE_START=============================================== |
| 4 | # Copyright (C) 2020 Nordix Foundation. All rights reserved. |
| 5 | # ======================================================================== |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # ============LICENSE_END================================================= |
| 18 | # |
| 19 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 20 | # This is a script that contains container/service management functions and test functions for Producer stub |
| 21 | |
| 22 | ## Access to Prod stub sim |
| 23 | # Direct access |
| 24 | PROD_STUB_HTTPX="http" |
| 25 | PROD_STUB_HOST_NAME=$LOCALHOST_NAME |
| 26 | PROD_STUB_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_HOST_NAME":"$PROD_STUB_EXTERNAL_PORT |
| 27 | |
| 28 | #Docker/Kube internal path |
| 29 | if [ $RUNMODE == "KUBE" ]; then |
| 30 | PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME"."$KUBE_SIM_NAMESPACE":"$PROD_STUB_EXTERNAL_PORT |
| 31 | else |
| 32 | PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME":"$PROD_STUB_INTERNAL_PORT |
| 33 | fi |
| 34 | |
| 35 | # Set http as the protocol to use for all communication to the Producer stub |
| 36 | # args: - |
| 37 | # (Function for test scripts) |
| 38 | use_prod_stub_http() { |
| 39 | echo -e $BOLD"Producer stub protocol setting"$EBOLD |
| 40 | echo -e " Using $BOLD http $EBOLD towards Producer stub" |
| 41 | |
| 42 | PROD_STUB_HTTPX="http" |
| 43 | PROD_STUB_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_HOST_NAME":"$PROD_STUB_EXTERNAL_PORT |
| 44 | |
| 45 | if [ $RUNMODE == "KUBE" ]; then |
| 46 | PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME"."$KUBE_SIM_NAMESPACE":"$PROD_STUB_EXTERNAL_PORT |
| 47 | else |
| 48 | PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME":"$PROD_STUB_INTERNAL_PORT |
| 49 | fi |
| 50 | |
| 51 | echo "" |
| 52 | } |
| 53 | |
| 54 | # Set https as the protocol to use for all communication to the Producer stub |
| 55 | # args: - |
| 56 | # (Function for test scripts) |
| 57 | use_prod_stub_https() { |
| 58 | echo -e $BOLD"Producer stub protocol setting"$EBOLD |
| 59 | echo -e " Using $BOLD https $EBOLD towards Producer stub" |
| 60 | |
| 61 | PROD_STUB_HTTPX="https" |
| 62 | PROD_STUB_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_HOST_NAME":"$PROD_STUB_EXTERNAL_SECURE_PORT |
| 63 | |
| 64 | if [ $RUNMODE == "KUBE" ]; then |
| 65 | PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME"."$KUBE_SIM_NAMESPACE":"$PROD_STUB_EXTERNAL_SECURE_PORT |
| 66 | else |
| 67 | PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME":"$PROD_STUB_INTERNAL_SECURE_PORT |
| 68 | fi |
| 69 | echo "" |
| 70 | } |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 71 | |
| 72 | ### Admin API functions producer stub |
| 73 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 74 | ########################### |
| 75 | ### Producer stub functions |
| 76 | ########################### |
| 77 | |
| 78 | # Start the Producer stub in the simulator group |
| 79 | # args: - |
| 80 | # (Function for test scripts) |
| 81 | start_prod_stub() { |
| 82 | |
| 83 | echo -e $BOLD"Starting $PROD_STUB_DISPLAY_NAME"$EBOLD |
| 84 | |
| 85 | if [ $RUNMODE == "KUBE" ]; then |
| 86 | |
| 87 | # Check if app shall be fully managed by the test script |
| 88 | __check_included_image "PRODSTUB" |
| 89 | retcode_i=$? |
| 90 | |
| 91 | # Check if app shall only be used by the testscipt |
| 92 | __check_prestarted_image "PRODSTUB" |
| 93 | retcode_p=$? |
| 94 | |
| 95 | if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then |
| 96 | echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED |
| 97 | echo -e $RED"The $ECS_APP_NAME will not be started"$ERED |
| 98 | exit |
| 99 | fi |
| 100 | if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then |
| 101 | echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED |
| 102 | echo -e $RED"The $ECS_APP_NAME will not be started"$ERED |
| 103 | exit |
| 104 | fi |
| 105 | |
| 106 | if [ $retcode_p -eq 0 ]; then |
| 107 | echo -e " Using existing $PROD_STUB_APP_NAME deployment and service" |
| 108 | echo " Setting RC replicas=1" |
| 109 | __kube_scale deployment $PROD_STUB_APP_NAME $KUBE_SIM_NAMESPACE 1 |
| 110 | fi |
| 111 | |
| 112 | if [ $retcode_i -eq 0 ]; then |
| 113 | echo -e " Creating $PROD_STUB_APP_NAME deployment and service" |
| 114 | export PROD_STUB_APP_NAME |
| 115 | export KUBE_SIM_NAMESPACE |
| 116 | export PROD_STUB_IMAGE |
| 117 | export PROD_STUB_INTERNAL_PORT |
| 118 | export PROD_STUB_INTERNAL_SECURE_PORT |
| 119 | export PROD_STUB_EXTERNAL_PORT |
| 120 | export PROD_STUB_EXTERNAL_SECURE_PORT |
| 121 | |
| 122 | __kube_create_namespace $KUBE_SIM_NAMESPACE |
| 123 | |
| 124 | # Create service |
| 125 | input_yaml=$SIM_GROUP"/"$PROD_STUB_COMPOSE_DIR"/"svc.yaml |
| 126 | output_yaml=$PWD/tmp/prodstub_svc.yaml |
| 127 | __kube_create_instance service $PROD_STUB_APP_NAME $input_yaml $output_yaml |
| 128 | |
| 129 | # Create app |
| 130 | input_yaml=$SIM_GROUP"/"$PROD_STUB_COMPOSE_DIR"/"app.yaml |
| 131 | output_yaml=$PWD/tmp/prodstub_app.yaml |
| 132 | __kube_create_instance app $PROD_STUB_APP_NAME $input_yaml $output_yaml |
| 133 | fi |
| 134 | |
| 135 | PROD_STUB_HOST_NAME=$(__kube_get_service_host $PROD_STUB_APP_NAME $KUBE_SIM_NAMESPACE) |
| 136 | |
| 137 | PROD_STUB_EXTERNAL_PORT=$(__kube_get_service_port $PROD_STUB_APP_NAME $KUBE_SIM_NAMESPACE "http") |
| 138 | PROD_STUB_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $PROD_STUB_APP_NAME $KUBE_SIM_NAMESPACE "https") |
| 139 | |
| 140 | echo " Host IP, http port, https port: $PROD_STUB_HOST_NAME $PROD_STUB_EXTERNAL_PORT $PROD_STUB_EXTERNAL_SECURE_PORT" |
| 141 | if [ $PROD_STUB_HTTPX == "http" ]; then |
| 142 | PROD_STUB_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_HOST_NAME":"$PROD_STUB_EXTERNAL_PORT |
| 143 | PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME"."$KUBE_SIM_NAMESPACE":"$PROD_STUB_EXTERNAL_PORT |
| 144 | else |
| 145 | PROD_STUB_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_HOST_NAME":"$PROD_STUB_EXTERNAL_SECURE_PORT |
| 146 | PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME"."$KUBE_SIM_NAMESPACE":"$PROD_STUB_EXTERNAL_SECURE_PORT |
| 147 | fi |
| 148 | |
| 149 | __check_service_start $PROD_STUB_APP_NAME $PROD_STUB_PATH$PROD_STUB_ALIVE_URL |
| 150 | |
| 151 | echo -ne " Service $PROD_STUB_APP_NAME - reset "$SAMELINE |
| 152 | result=$(__do_curl $PROD_STUB_PATH/reset) |
| 153 | if [ $? -ne 0 ]; then |
| 154 | echo -e " Service $PROD_STUB_APP_NAME - reset $RED Failed $ERED - will continue" |
| 155 | else |
| 156 | echo -e " Service $PROD_STUB_APP_NAME - reset $GREEN OK $EGREEN" |
| 157 | fi |
| 158 | else |
| 159 | |
| 160 | # Check if docker app shall be fully managed by the test script |
| 161 | __check_included_image 'PRODSTUB' |
| 162 | if [ $? -eq 1 ]; then |
| 163 | echo -e $RED"The Producer stub app is not included as managed in this test script"$ERED |
| 164 | echo -e $RED"The Producer stub will not be started"$ERED |
| 165 | exit |
| 166 | fi |
| 167 | |
| 168 | export PROD_STUB_APP_NAME |
| 169 | export PROD_STUB_APP_NAME_ALIAS |
| 170 | export PROD_STUB_INTERNAL_PORT |
| 171 | export PROD_STUB_EXTERNAL_PORT |
| 172 | export PROD_STUB_INTERNAL_SECURE_PORT |
| 173 | export PROD_STUB_EXTERNAL_SECURE_PORT |
| 174 | export DOCKER_SIM_NWNAME |
| 175 | |
| 176 | __start_container $PROD_STUB_COMPOSE_DIR NODOCKERARGS 1 $PROD_STUB_APP_NAME |
| 177 | |
| 178 | __check_service_start $PROD_STUB_APP_NAME $PROD_STUB_PATH$PROD_STUB_ALIVE_URL |
| 179 | fi |
| 180 | echo "" |
| 181 | return 0 |
| 182 | } |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 183 | |
| 184 | # Excute a curl cmd towards the prodstub simulator and check the response code. |
| 185 | # args: TEST|CONF <expected-response-code> <curl-cmd-string> [<json-file-to-compare-output>] |
| 186 | __execute_curl_to_prodstub() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 187 | TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") |
| 188 | echo "(${BASH_LINENO[0]}) - ${TIMESTAMP}: ${FUNCNAME[0]}" $@ >> $HTTPLOG |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 189 | echo " CMD: $3" >> $HTTPLOG |
| 190 | res="$($3)" |
| 191 | echo " RESP: $res" >> $HTTPLOG |
| 192 | retcode=$? |
| 193 | if [ $retcode -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 194 | __log_conf_fail_general " Fatal error when executing curl, response: "$retcode |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 195 | return 1 |
| 196 | fi |
| 197 | status=${res:${#res}-3} |
| 198 | if [ $status -eq $2 ]; then |
| 199 | if [ $# -eq 4 ]; then |
| 200 | body=${res:0:${#res}-3} |
| 201 | jobfile=$(cat $4) |
| 202 | echo " TARGET JSON: $jobfile" >> $HTTPLOG |
| 203 | res=$(python3 ../common/compare_json.py "$jobfile" "$body") |
| 204 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 205 | if [ $1 == "TEST" ]; then |
| 206 | __log_test_fail_body |
| 207 | else |
| 208 | __log_conf_fail_body |
| 209 | fi |
| 210 | return 1 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 211 | fi |
| 212 | fi |
| 213 | if [ $1 == "TEST" ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 214 | __log_test_pass |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 215 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 216 | __log_conf_ok |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 217 | fi |
| 218 | return 0 |
| 219 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 220 | if [ $1 == "TEST" ]; then |
| 221 | __log_test_fail_status_code $2 $status |
| 222 | else |
| 223 | __log_conf_fail_status_code $2 $status |
| 224 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 225 | return 1 |
| 226 | } |
| 227 | |
| 228 | # Prodstub API: Set (or reset) response code for producer supervision |
| 229 | # <response-code> <producer-id> [<forced_response_code>] |
| 230 | # (Function for test scripts) |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 231 | prodstub_arm_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 232 | __log_conf_start $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 233 | if [ $# -ne 2 ] && [ $# -ne 3 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 234 | __print_err "<response-code> <producer-id> [<forced_response_code>]" $@ |
| 235 | return 1 |
| 236 | fi |
| 237 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 238 | curlString="curl -X PUT -skw %{http_code} $PROD_STUB_PATH/arm/supervision/"$2 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 239 | if [ $# -eq 3 ]; then |
| 240 | curlString=$curlString"?response="$3 |
| 241 | fi |
| 242 | |
| 243 | __execute_curl_to_prodstub CONF $1 "$curlString" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 244 | return $? |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | # Prodstub API: Set (or reset) response code job create |
| 248 | # <response-code> <producer-id> <job-id> [<forced_response_code>] |
| 249 | # (Function for test scripts) |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 250 | prodstub_arm_job_create() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 251 | __log_conf_start $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 252 | if [ $# -ne 3 ] && [ $# -ne 4 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 253 | __print_err "<response-code> <producer-id> <job-id> [<forced_response_code>]" $@ |
| 254 | return 1 |
| 255 | fi |
| 256 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 257 | curlString="curl -X PUT -skw %{http_code} $PROD_STUB_PATH/arm/create/$2/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 258 | if [ $# -eq 4 ]; then |
| 259 | curlString=$curlString"?response="$4 |
| 260 | fi |
| 261 | |
| 262 | __execute_curl_to_prodstub CONF $1 "$curlString" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 263 | return $? |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | # Prodstub API: Set (or reset) response code job delete |
| 267 | # <response-code> <producer-id> <job-id> [<forced_response_code>] |
| 268 | # (Function for test scripts) |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 269 | prodstub_arm_job_delete() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 270 | __log_conf_start $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 271 | if [ $# -ne 3 ] && [ $# -ne 4 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 272 | __print_err "<response-code> <producer-id> <job-id> [<forced_response_code>]" $@ |
| 273 | return 1 |
| 274 | fi |
| 275 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 276 | curlString="curl -X PUT -skw %{http_code} $PROD_STUB_PATH/arm/delete/$2/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 277 | if [ $# -eq 4 ]; then |
| 278 | curlString=$curlString"?response="$4 |
| 279 | fi |
| 280 | |
| 281 | __execute_curl_to_prodstub CONF $1 "$curlString" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 282 | return $? |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | # Prodstub API: Arm a type of a producer |
| 286 | # <response-code> <producer-id> <type-id> |
| 287 | # (Function for test scripts) |
| 288 | prodstub_arm_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 289 | __log_conf_start $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 290 | if [ $# -ne 3 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 291 | __print_err "<response-code> <producer-id> <type-id>" $@ |
| 292 | return 1 |
| 293 | fi |
| 294 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 295 | curlString="curl -X PUT -skw %{http_code} $PROD_STUB_PATH/arm/type/$2/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 296 | |
| 297 | __execute_curl_to_prodstub CONF $1 "$curlString" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 298 | return $? |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | # Prodstub API: Disarm a type in a producer |
| 302 | # <response-code> <producer-id> <type-id> |
| 303 | # (Function for test scripts) |
| 304 | prodstub_disarm_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 305 | __log_conf_start $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 306 | if [ $# -ne 3 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 307 | __print_err "<response-code> <producer-id> <type-id>" $@ |
| 308 | return 1 |
| 309 | fi |
| 310 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 311 | curlString="curl -X DELETE -skw %{http_code} $PROD_STUB_PATH/arm/type/$2/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 312 | |
| 313 | __execute_curl_to_prodstub CONF $1 "$curlString" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 314 | return $? |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | # Prodstub API: Get job data for a job and compare with a target job json |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 318 | # <response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file> |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 319 | # (Function for test scripts) |
| 320 | prodstub_check_jobdata() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 321 | __log_test_start $@ |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 322 | if [ $# -ne 7 ]; then |
| 323 | __print_err "<response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file>" $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 324 | return 1 |
| 325 | fi |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 326 | if [ -f $7 ]; then |
| 327 | jobfile=$(cat $7) |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 328 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 329 | else |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 330 | _log_test_fail_general "Template file "$7" for jobdata, does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 331 | return 1 |
| 332 | fi |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 333 | targetJson="{\"ei_job_identity\":\"$3\",\"ei_type_identity\":\"$4\",\"target_uri\":\"$5\",\"owner\":\"$6\", \"ei_job_data\":$jobfile}" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 334 | file="./tmp/.p.json" |
| 335 | echo "$targetJson" > $file |
| 336 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 337 | curlString="curl -X GET -skw %{http_code} $PROD_STUB_PATH/jobdata/$2/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 338 | |
| 339 | __execute_curl_to_prodstub TEST $1 "$curlString" $file |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 340 | return $? |
| 341 | } |
| 342 | |
| 343 | # Prodstub API: Delete the job data |
| 344 | # <response-code> <producer-id> <job-id> |
| 345 | # (Function for test scripts) |
| 346 | prodstub_delete_jobdata() { |
| 347 | __log_conf_start |
| 348 | if [ $# -ne 3 ]; then |
| 349 | __print_err "<response-code> <producer-id> <job-id> " $@ |
| 350 | return 1 |
| 351 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 352 | curlString="curl -X DELETE -skw %{http_code} $PROD_STUB_PATH/jobdata/$2/$3" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 353 | |
| 354 | __execute_curl_to_prodstub CONF $1 "$curlString" |
| 355 | return $? |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | # Tests if a variable value in the prod stub is equal to a target value and and optional timeout. |
| 359 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 360 | # equal to the target or not. |
| 361 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 362 | # before setting pass or fail depending on if the variable value becomes equal to the target |
| 363 | # value or not. |
| 364 | # (Function for test scripts) |
| 365 | prodstub_equal() { |
| 366 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 367 | __var_test "PRODSTUB" "$PROD_STUB_PATH/counter/" $1 "=" $2 $3 |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 368 | else |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 369 | __print_err "Wrong args to prodstub_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@ |
| 370 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 371 | } |