blob: f80e827ba6eb57dc39527a1074b3eb3887b30514 [file] [log] [blame]
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001#!/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
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010020# This is a script that contains container/service management functions and test functions for Producer stub
21
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010022
23################ Test engine functions ################
24
25# Create the image var used during the test
26# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
27# <image-tag-suffix> is present only for images with staging, snapshot,release tags
28__PRODSTUB_imagesetup() {
29 __check_and_create_image_var PRODSTUB "PROD_STUB_IMAGE" "PROD_STUB_IMAGE_BASE" "PROD_STUB_IMAGE_TAG" LOCAL "$PROD_STUB_DISPLAY_NAME"
30}
31
32# Pull image from remote repo or use locally built image
33# arg: <pull-policy-override> <pull-policy-original>
34# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
35# <pull-policy-original> Shall be used for images that does not allow overriding
36# Both var may contain: 'remote', 'remote-remove' or 'local'
37__PRODSTUB_imagepull() {
BjornMagnussonXAa69cd902021-04-22 23:46:10 +020038 echo -e $RED"Image for app PRODSTUB shall never be pulled from remote repo"$ERED
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010039}
40
41# Build image (only for simulator or interfaces stubs owned by the test environment)
42# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
43# <image-tag-suffix> is present only for images with staging, snapshot,release tags
44__PRODSTUB_imagebuild() {
45 cd ../prodstub
46 echo " Building PRODSTUB - $PROD_STUB_DISPLAY_NAME - image: $PROD_STUB_IMAGE"
47 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $PROD_STUB_IMAGE . &> .dockererr
48 if [ $? -eq 0 ]; then
BjornMagnussonXA483ee332021-04-08 01:35:24 +020049 echo -e $GREEN" Build Ok"$EGREEN
50 __retag_and_push_image PROD_STUB_IMAGE
51 if [ $? -ne 0 ]; then
52 exit 1
53 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010054 else
BjornMagnussonXA483ee332021-04-08 01:35:24 +020055 echo -e $RED" Build Failed"$ERED
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010056 ((RES_CONF_FAIL++))
57 cat .dockererr
58 echo -e $RED"Exiting...."$ERED
59 exit 1
60 fi
61}
62
63# Generate a string for each included image using the app display name and a docker images format string
BjornMagnussonXA483ee332021-04-08 01:35:24 +020064# If a custom image repo is used then also the source image from the local repo is listed
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010065# arg: <docker-images-format-string> <file-to-append>
66__PRODSTUB_image_data() {
67 echo -e "$PROD_STUB_DISPLAY_NAME\t$(docker images --format $1 $PROD_STUB_IMAGE)" >> $2
BjornMagnussonXA483ee332021-04-08 01:35:24 +020068 if [ ! -z "$PROD_STUB_IMAGE_SOURCE" ]; then
69 echo -e "-- source image --\t$(docker images --format $1 $PROD_STUB_IMAGE_SOURCE)" >> $2
70 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010071}
72
73# Scale kubernetes resources to zero
74# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
75# This function is called for apps fully managed by the test script
76__PRODSTUB_kube_scale_zero() {
77 __kube_scale_all_resources $KUBE_SIM_NAMESPACE autotest PRODSTUB
78}
79
80# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
81# This function is called for prestarted apps not managed by the test script.
82__PRODSTUB_kube_scale_zero_and_wait() {
83 echo -e $RED" PRODSTUB app is not scaled in this state"$ERED
84}
85
86# Delete all kube resouces for the app
87# This function is called for apps managed by the test script.
88__PRODSTUB_kube_delete_all() {
89 __kube_delete_all_resources $KUBE_SIM_NAMESPACE autotest PRODSTUB
90}
91
92# Store docker logs
93# This function is called for apps managed by the test script.
94# args: <log-dir> <file-prexix>
95__PRODSTUB_store_docker_logs() {
96 docker logs $PROD_STUB_APP_NAME > $1$2_prodstub.log 2>&1
97}
98#######################################################
99
100
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100101## Access to Prod stub sim
102# Direct access
103PROD_STUB_HTTPX="http"
104PROD_STUB_HOST_NAME=$LOCALHOST_NAME
105PROD_STUB_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_HOST_NAME":"$PROD_STUB_EXTERNAL_PORT
106
107#Docker/Kube internal path
108if [ $RUNMODE == "KUBE" ]; then
109 PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME"."$KUBE_SIM_NAMESPACE":"$PROD_STUB_EXTERNAL_PORT
110else
111 PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME":"$PROD_STUB_INTERNAL_PORT
112fi
113
114# Set http as the protocol to use for all communication to the Producer stub
115# args: -
116# (Function for test scripts)
117use_prod_stub_http() {
118 echo -e $BOLD"Producer stub protocol setting"$EBOLD
119 echo -e " Using $BOLD http $EBOLD towards Producer stub"
120
121 PROD_STUB_HTTPX="http"
122 PROD_STUB_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_HOST_NAME":"$PROD_STUB_EXTERNAL_PORT
123
124 if [ $RUNMODE == "KUBE" ]; then
125 PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME"."$KUBE_SIM_NAMESPACE":"$PROD_STUB_EXTERNAL_PORT
126 else
127 PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME":"$PROD_STUB_INTERNAL_PORT
128 fi
129
130 echo ""
131}
132
133# Set https as the protocol to use for all communication to the Producer stub
134# args: -
135# (Function for test scripts)
136use_prod_stub_https() {
137 echo -e $BOLD"Producer stub protocol setting"$EBOLD
138 echo -e " Using $BOLD https $EBOLD towards Producer stub"
139
140 PROD_STUB_HTTPX="https"
141 PROD_STUB_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_HOST_NAME":"$PROD_STUB_EXTERNAL_SECURE_PORT
142
143 if [ $RUNMODE == "KUBE" ]; then
144 PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME"."$KUBE_SIM_NAMESPACE":"$PROD_STUB_EXTERNAL_SECURE_PORT
145 else
146 PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME":"$PROD_STUB_INTERNAL_SECURE_PORT
147 fi
148 echo ""
149}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200150
151### Admin API functions producer stub
152
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100153###########################
154### Producer stub functions
155###########################
156
157# Start the Producer stub in the simulator group
158# args: -
159# (Function for test scripts)
160start_prod_stub() {
161
162 echo -e $BOLD"Starting $PROD_STUB_DISPLAY_NAME"$EBOLD
163
164 if [ $RUNMODE == "KUBE" ]; then
165
166 # Check if app shall be fully managed by the test script
167 __check_included_image "PRODSTUB"
168 retcode_i=$?
169
170 # Check if app shall only be used by the testscipt
171 __check_prestarted_image "PRODSTUB"
172 retcode_p=$?
173
174 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
175 echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
176 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
177 exit
178 fi
179 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
180 echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
181 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
182 exit
183 fi
184
185 if [ $retcode_p -eq 0 ]; then
186 echo -e " Using existing $PROD_STUB_APP_NAME deployment and service"
187 echo " Setting RC replicas=1"
188 __kube_scale deployment $PROD_STUB_APP_NAME $KUBE_SIM_NAMESPACE 1
189 fi
190
191 if [ $retcode_i -eq 0 ]; then
192 echo -e " Creating $PROD_STUB_APP_NAME deployment and service"
193 export PROD_STUB_APP_NAME
194 export KUBE_SIM_NAMESPACE
195 export PROD_STUB_IMAGE
196 export PROD_STUB_INTERNAL_PORT
197 export PROD_STUB_INTERNAL_SECURE_PORT
198 export PROD_STUB_EXTERNAL_PORT
199 export PROD_STUB_EXTERNAL_SECURE_PORT
200
201 __kube_create_namespace $KUBE_SIM_NAMESPACE
202
203 # Create service
204 input_yaml=$SIM_GROUP"/"$PROD_STUB_COMPOSE_DIR"/"svc.yaml
205 output_yaml=$PWD/tmp/prodstub_svc.yaml
206 __kube_create_instance service $PROD_STUB_APP_NAME $input_yaml $output_yaml
207
208 # Create app
209 input_yaml=$SIM_GROUP"/"$PROD_STUB_COMPOSE_DIR"/"app.yaml
210 output_yaml=$PWD/tmp/prodstub_app.yaml
211 __kube_create_instance app $PROD_STUB_APP_NAME $input_yaml $output_yaml
212 fi
213
214 PROD_STUB_HOST_NAME=$(__kube_get_service_host $PROD_STUB_APP_NAME $KUBE_SIM_NAMESPACE)
215
216 PROD_STUB_EXTERNAL_PORT=$(__kube_get_service_port $PROD_STUB_APP_NAME $KUBE_SIM_NAMESPACE "http")
217 PROD_STUB_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $PROD_STUB_APP_NAME $KUBE_SIM_NAMESPACE "https")
218
219 echo " Host IP, http port, https port: $PROD_STUB_HOST_NAME $PROD_STUB_EXTERNAL_PORT $PROD_STUB_EXTERNAL_SECURE_PORT"
220 if [ $PROD_STUB_HTTPX == "http" ]; then
221 PROD_STUB_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_HOST_NAME":"$PROD_STUB_EXTERNAL_PORT
222 PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME"."$KUBE_SIM_NAMESPACE":"$PROD_STUB_EXTERNAL_PORT
223 else
224 PROD_STUB_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_HOST_NAME":"$PROD_STUB_EXTERNAL_SECURE_PORT
225 PROD_STUB_SERVICE_PATH=$PROD_STUB_HTTPX"://"$PROD_STUB_APP_NAME"."$KUBE_SIM_NAMESPACE":"$PROD_STUB_EXTERNAL_SECURE_PORT
226 fi
227
228 __check_service_start $PROD_STUB_APP_NAME $PROD_STUB_PATH$PROD_STUB_ALIVE_URL
229
230 echo -ne " Service $PROD_STUB_APP_NAME - reset "$SAMELINE
231 result=$(__do_curl $PROD_STUB_PATH/reset)
232 if [ $? -ne 0 ]; then
233 echo -e " Service $PROD_STUB_APP_NAME - reset $RED Failed $ERED - will continue"
234 else
235 echo -e " Service $PROD_STUB_APP_NAME - reset $GREEN OK $EGREEN"
236 fi
237 else
238
239 # Check if docker app shall be fully managed by the test script
240 __check_included_image 'PRODSTUB'
241 if [ $? -eq 1 ]; then
242 echo -e $RED"The Producer stub app is not included as managed in this test script"$ERED
243 echo -e $RED"The Producer stub will not be started"$ERED
244 exit
245 fi
246
247 export PROD_STUB_APP_NAME
248 export PROD_STUB_APP_NAME_ALIAS
249 export PROD_STUB_INTERNAL_PORT
250 export PROD_STUB_EXTERNAL_PORT
251 export PROD_STUB_INTERNAL_SECURE_PORT
252 export PROD_STUB_EXTERNAL_SECURE_PORT
253 export DOCKER_SIM_NWNAME
254
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100255 export PROD_STUB_DISPLAY_NAME
256
257 __start_container $PROD_STUB_COMPOSE_DIR "" NODOCKERARGS 1 $PROD_STUB_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100258
259 __check_service_start $PROD_STUB_APP_NAME $PROD_STUB_PATH$PROD_STUB_ALIVE_URL
260 fi
261 echo ""
262 return 0
263}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200264
265# Excute a curl cmd towards the prodstub simulator and check the response code.
266# args: TEST|CONF <expected-response-code> <curl-cmd-string> [<json-file-to-compare-output>]
267__execute_curl_to_prodstub() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100268 TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
269 echo "(${BASH_LINENO[0]}) - ${TIMESTAMP}: ${FUNCNAME[0]}" $@ >> $HTTPLOG
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100270 proxyflag=""
271 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA483ee332021-04-08 01:35:24 +0200272 if [ ! -z "$KUBE_PROXY_PATH" ]; then
BjornMagnussonXA674793d2021-05-06 19:49:17 +0200273 if [ $KUBE_PROXY_HTTPX == "http" ]; then
274 proxyflag=" --proxy $KUBE_PROXY_PATH"
275 else
276 proxyflag=" --proxy-insecure --proxy $KUBE_PROXY_PATH"
277 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100278 fi
279 fi
280 echo " CMD: $3 $proxyflag" >> $HTTPLOG
281 res="$($3 $proxyflag)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200282 echo " RESP: $res" >> $HTTPLOG
283 retcode=$?
284 if [ $retcode -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100285 __log_conf_fail_general " Fatal error when executing curl, response: "$retcode
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200286 return 1
287 fi
288 status=${res:${#res}-3}
289 if [ $status -eq $2 ]; then
290 if [ $# -eq 4 ]; then
291 body=${res:0:${#res}-3}
292 jobfile=$(cat $4)
293 echo " TARGET JSON: $jobfile" >> $HTTPLOG
294 res=$(python3 ../common/compare_json.py "$jobfile" "$body")
295 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100296 if [ $1 == "TEST" ]; then
297 __log_test_fail_body
298 else
299 __log_conf_fail_body
300 fi
301 return 1
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200302 fi
303 fi
304 if [ $1 == "TEST" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100305 __log_test_pass
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200306 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100307 __log_conf_ok
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200308 fi
309 return 0
310 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100311 if [ $1 == "TEST" ]; then
312 __log_test_fail_status_code $2 $status
313 else
314 __log_conf_fail_status_code $2 $status
315 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200316 return 1
317}
318
319# Prodstub API: Set (or reset) response code for producer supervision
320# <response-code> <producer-id> [<forced_response_code>]
321# (Function for test scripts)
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200322prodstub_arm_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100323 __log_conf_start $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200324 if [ $# -ne 2 ] && [ $# -ne 3 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200325 __print_err "<response-code> <producer-id> [<forced_response_code>]" $@
326 return 1
327 fi
328
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100329 curlString="curl -X PUT -skw %{http_code} $PROD_STUB_PATH/arm/supervision/"$2
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200330 if [ $# -eq 3 ]; then
331 curlString=$curlString"?response="$3
332 fi
333
334 __execute_curl_to_prodstub CONF $1 "$curlString"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100335 return $?
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200336}
337
338# Prodstub API: Set (or reset) response code job create
339# <response-code> <producer-id> <job-id> [<forced_response_code>]
340# (Function for test scripts)
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200341prodstub_arm_job_create() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100342 __log_conf_start $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200343 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200344 __print_err "<response-code> <producer-id> <job-id> [<forced_response_code>]" $@
345 return 1
346 fi
347
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100348 curlString="curl -X PUT -skw %{http_code} $PROD_STUB_PATH/arm/create/$2/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200349 if [ $# -eq 4 ]; then
350 curlString=$curlString"?response="$4
351 fi
352
353 __execute_curl_to_prodstub CONF $1 "$curlString"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100354 return $?
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200355}
356
357# Prodstub API: Set (or reset) response code job delete
358# <response-code> <producer-id> <job-id> [<forced_response_code>]
359# (Function for test scripts)
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200360prodstub_arm_job_delete() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100361 __log_conf_start $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200362 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200363 __print_err "<response-code> <producer-id> <job-id> [<forced_response_code>]" $@
364 return 1
365 fi
366
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100367 curlString="curl -X PUT -skw %{http_code} $PROD_STUB_PATH/arm/delete/$2/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200368 if [ $# -eq 4 ]; then
369 curlString=$curlString"?response="$4
370 fi
371
372 __execute_curl_to_prodstub CONF $1 "$curlString"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100373 return $?
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200374}
375
376# Prodstub API: Arm a type of a producer
377# <response-code> <producer-id> <type-id>
378# (Function for test scripts)
379prodstub_arm_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100380 __log_conf_start $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200381 if [ $# -ne 3 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200382 __print_err "<response-code> <producer-id> <type-id>" $@
383 return 1
384 fi
385
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100386 curlString="curl -X PUT -skw %{http_code} $PROD_STUB_PATH/arm/type/$2/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200387
388 __execute_curl_to_prodstub CONF $1 "$curlString"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100389 return $?
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200390}
391
392# Prodstub API: Disarm a type in a producer
393# <response-code> <producer-id> <type-id>
394# (Function for test scripts)
395prodstub_disarm_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100396 __log_conf_start $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200397 if [ $# -ne 3 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200398 __print_err "<response-code> <producer-id> <type-id>" $@
399 return 1
400 fi
401
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100402 curlString="curl -X DELETE -skw %{http_code} $PROD_STUB_PATH/arm/type/$2/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200403
404 __execute_curl_to_prodstub CONF $1 "$curlString"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100405 return $?
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200406}
407
408# Prodstub API: Get job data for a job and compare with a target job json
BjornMagnussonXA2138b632020-11-30 21:17:32 +0100409# <response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file>
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200410# (Function for test scripts)
411prodstub_check_jobdata() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100412 __log_test_start $@
BjornMagnussonXA2138b632020-11-30 21:17:32 +0100413 if [ $# -ne 7 ]; then
414 __print_err "<response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file>" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200415 return 1
416 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +0100417 if [ -f $7 ]; then
418 jobfile=$(cat $7)
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200419 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
420 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200421 __log_test_fail_general "Template file "$7" for jobdata, does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200422 return 1
423 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +0100424 targetJson="{\"ei_job_identity\":\"$3\",\"ei_type_identity\":\"$4\",\"target_uri\":\"$5\",\"owner\":\"$6\", \"ei_job_data\":$jobfile}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200425 file="./tmp/.p.json"
426 echo "$targetJson" > $file
427
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100428 curlString="curl -X GET -skw %{http_code} $PROD_STUB_PATH/jobdata/$2/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200429
430 __execute_curl_to_prodstub TEST $1 "$curlString" $file
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100431 return $?
432}
433
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100434# Prodstub API: Get job data for a job and compare with a target job json
435# <response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file>
436# (Function for test scripts)
437prodstub_check_jobdata_2() {
438 __log_test_start $@
439 if [ $# -ne 7 ]; then
440 __print_err "<response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file>" $@
441 return 1
442 fi
443 if [ -f $7 ]; then
444 jobfile=$(cat $7)
445 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
446 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200447 __log_test_fail_general "Template file "$7" for jobdata, does not exist"
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100448 return 1
449 fi
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200450 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
451 targetJson="{\"info_job_identity\":\"$3\",\"info_type_identity\":\"$4\",\"target_uri\":\"$5\",\"owner\":\"$6\", \"info_job_data\":$jobfile,\"last_updated\":\"????\"}"
452 else
453 targetJson="{\"ei_job_identity\":\"$3\",\"ei_type_identity\":\"$4\",\"target_uri\":\"$5\",\"owner\":\"$6\", \"ei_job_data\":$jobfile,\"last_updated\":\"????\"}"
454 fi
455 file="./tmp/.p.json"
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100456 echo "$targetJson" > $file
457
458 curlString="curl -X GET -skw %{http_code} $PROD_STUB_PATH/jobdata/$2/$3"
459
460 __execute_curl_to_prodstub TEST $1 "$curlString" $file
461 return $?
462}
463
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200464# Prodstub API: Get job data for a job and compare with a target job json (info-jobs)
465# <response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file>
466# (Function for test scripts)
467prodstub_check_jobdata_3() {
468 __log_test_start $@
469 if [ $# -ne 7 ]; then
470 __print_err "<response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file>" $@
471 return 1
472 fi
473 if [ -f $7 ]; then
474 jobfile=$(cat $7)
475 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
476 else
477 __log_test_fail_general "Template file "$7" for jobdata, does not exist"
478 return 1
479 fi
480 targetJson="{\"info_job_identity\":\"$3\",\"info_type_identity\":\"$4\",\"target_uri\":\"$5\",\"owner\":\"$6\", \"info_job_data\":$jobfile,\"last_updated\":\"????\"}"
481 file="./tmp/.p.json"
482 echo "$targetJson" > $file
483
484 curlString="curl -X GET -skw %{http_code} $PROD_STUB_PATH/jobdata/$2/$3"
485
486 __execute_curl_to_prodstub TEST $1 "$curlString" $file
487 return $?
488}
489
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100490# Prodstub API: Delete the job data
491# <response-code> <producer-id> <job-id>
492# (Function for test scripts)
493prodstub_delete_jobdata() {
494 __log_conf_start
495 if [ $# -ne 3 ]; then
496 __print_err "<response-code> <producer-id> <job-id> " $@
497 return 1
498 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100499 curlString="curl -X DELETE -skw %{http_code} $PROD_STUB_PATH/jobdata/$2/$3"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100500
501 __execute_curl_to_prodstub CONF $1 "$curlString"
502 return $?
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200503}
504
505# Tests if a variable value in the prod stub is equal to a target value and and optional timeout.
506# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
507# equal to the target or not.
508# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
509# before setting pass or fail depending on if the variable value becomes equal to the target
510# value or not.
511# (Function for test scripts)
512prodstub_equal() {
513 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100514 __var_test "PRODSTUB" "$PROD_STUB_PATH/counter/" $1 "=" $2 $3
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200515 else
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200516 __print_err "Wrong args to prodstub_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
517 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200518}