blob: d55f4399a98a1c8f5eb68aefaefcada85c205475 [file] [log] [blame]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +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 ECS
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020021
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010022################ Test engine functions ################
23
24# Create the image var used during the test
25# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
26# <image-tag-suffix> is present only for images with staging, snapshot,release tags
27__ECS_imagesetup() {
28 __check_and_create_image_var ECS "ECS_IMAGE" "ECS_IMAGE_BASE" "ECS_IMAGE_TAG" $1 "$ECS_DISPLAY_NAME"
29}
30
31# Pull image from remote repo or use locally built image
32# arg: <pull-policy-override> <pull-policy-original>
33# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
34# <pull-policy-original> Shall be used for images that does not allow overriding
35# Both var may contain: 'remote', 'remote-remove' or 'local'
36__ECS_imagepull() {
37 __check_and_pull_image $1 "$ECS_DISPLAY_NAME" $ECS_APP_NAME $ECS_IMAGE
38}
39
40# Build image (only for simulator or interfaces stubs owned by the test environment)
41# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
42# <image-tag-suffix> is present only for images with staging, snapshot,release tags
43__ECS_imagebuild() {
44 echo -e $RED" Image for app ECS shall never be built"$ERED
45}
46
47# Generate a string for each included image using the app display name and a docker images format string
48# arg: <docker-images-format-string> <file-to-append>
49__ECS_image_data() {
50 echo -e "$ECS_DISPLAY_NAME\t$(docker images --format $1 $ECS_IMAGE)" >> $2
51}
52
53# Scale kubernetes resources to zero
54# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
55# This function is called for apps fully managed by the test script
56__ECS_kube_scale_zero() {
57 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
58}
59
60# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
61# This function is called for prestarted apps not managed by the test script.
62__ECS_kube_scale_zero_and_wait() {
63 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-enrichmentservice
64}
65
66# Delete all kube resouces for the app
67# This function is called for apps managed by the test script.
68__ECS_kube_delete_all() {
69 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
70}
71
72# Store docker logs
73# This function is called for apps managed by the test script.
74# args: <log-dir> <file-prexix>
75__ECS_store_docker_logs() {
76 docker logs $ECS_APP_NAME > $1$2_ecs.log 2>&1
77}
78#######################################################
79
80
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010081## Access to ECS
82# Host name may be changed if app started by kube
83# Direct access
84ECS_HTTPX="http"
85ECS_HOST_NAME=$LOCALHOST_NAME
86ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
87
88# ECS_ADAPTER used for switch between REST and DMAAP (only REST supported currently)
89ECS_ADAPTER_TYPE="REST"
90ECS_ADAPTER=$ECS_PATH
91
92# Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
93ECS_RETRY_CODES=""
94
95###########################
96### ECS functions
97###########################
98
99# All calls to ECS will be directed to the ECS REST interface from now on
100# args: -
101# (Function for test scripts)
102use_ecs_rest_http() {
103 echo -e $BOLD"ECS protocol setting"$EBOLD
104 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
105 ECS_HTTPX="http"
106 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
107
108 ECS_ADAPTER_TYPE="REST"
109 ECS_ADAPTER=$ECS_PATH
110 echo ""
111}
112
113# All calls to ECS will be directed to the ECS REST interface from now on
114# args: -
115# (Function for test scripts)
116use_ecs_rest_https() {
117 echo -e $BOLD"ECS protocol setting"$EBOLD
118 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
119 ECS_HTTPX="https"
120 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
121
122 ECS_ADAPTER_TYPE="REST"
123 ECS_ADAPTER=$ECS_PATH
124 echo ""
125}
126
127# All calls to ECS will be directed to the ECS dmaap interface over http from now on
128# args: -
129# (Function for test scripts)
130use_ecs_dmaap_http() {
131 echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
132 echo -e $RED" - NOT SUPPORTED - "$ERED
133 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
134 ECS_ADAPTER_TYPE="MR-HTTP"
135 echo ""
136}
137
138# All calls to ECS will be directed to the ECS dmaap interface over https from now on
139# args: -
140# (Function for test scripts)
141use_ecs_dmaap_https() {
142 echo -e $BOLD"RICSIM protocol setting"$EBOLD
143 echo -e $RED" - NOT SUPPORTED - "$ERED
144 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
145 ECS_ADAPTER_TYPE="MR-HTTPS"
146 echo ""
147}
148
149# Start the ECS
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100150# args: PROXY|NOPROXY <config-file>
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100151# (Function for test scripts)
152start_ecs() {
153
154 echo -e $BOLD"Starting $ECS_DISPLAY_NAME"$EBOLD
155
156 if [ $RUNMODE == "KUBE" ]; then
157
158 # Check if app shall be fully managed by the test script
159 __check_included_image "ECS"
160 retcode_i=$?
161
162 # Check if app shall only be used by the testscipt
163 __check_prestarted_image "ECS"
164 retcode_p=$?
165
166 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
167 echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
168 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
169 exit
170 fi
171 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
172 echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
173 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
174 exit
175 fi
176
177
178 if [ $retcode_p -eq 0 ]; then
179 echo -e " Using existing $ECS_APP_NAME deployment and service"
180 echo " Setting ECS replicas=1"
181 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
182 fi
183
184 # Check if app shall be fully managed by the test script
185 if [ $retcode_i -eq 0 ]; then
186 echo -e " Creating $ECS_APP_NAME app and expose service"
187
188 #Check if nonrtric namespace exists, if not create it
189 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
190
191 export ECS_APP_NAME
192 export KUBE_NONRTRIC_NAMESPACE
193 export ECS_IMAGE
194 export ECS_INTERNAL_PORT
195 export ECS_INTERNAL_SECURE_PORT
196 export ECS_EXTERNAL_PORT
197 export ECS_EXTERNAL_SECURE_PORT
198 export ECS_CONFIG_MOUNT_PATH
199 export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config"
200 export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data"
201 export ECS_CONTAINER_MNT_DIR
202
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100203 export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv"
204 #Create a unique path for the pv each time to prevent a previous volume to be reused
205 export ECS_PV_PATH="ecsdata-"$(date +%s)
206
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100207 if [ $1 == "PROXY" ]; then
208 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
209 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
210 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
211 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
212 else
213 echo " Configured with http proxy"
214 fi
215 else
216 ECS_HTTP_PROXY_CONFIG_PORT=0
217 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
218 echo " Configured without http proxy"
219 fi
220 export ECS_HTTP_PROXY_CONFIG_PORT
221 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
222
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100223 # Create config map for config
224 datafile=$PWD/tmp/$ECS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100225 cp $2 $datafile
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100226 output_yaml=$PWD/tmp/ecs_cfc.yaml
227 __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml
228
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100229 # Create pv
230 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pv.yaml
231 output_yaml=$PWD/tmp/ecs_pv.yaml
232 __kube_create_instance pv $ECS_APP_NAME $input_yaml $output_yaml
233
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100234 # Create pvc
235 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml
236 output_yaml=$PWD/tmp/ecs_pvc.yaml
237 __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml
238
239 # Create service
240 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml
241 output_yaml=$PWD/tmp/ecs_svc.yaml
242 __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml
243
244 # Create app
245 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml
246 output_yaml=$PWD/tmp/ecs_app.yaml
247 __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml
248 fi
249
250 echo " Retrieving host and ports for service..."
251 ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
252 ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
253 ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
254
255 echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT"
256
257 if [ $ECS_HTTPX == "http" ]; then
258 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
259 else
260 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
261 fi
262
263 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
264
265 if [ $ECS_ADAPTER_TYPE == "REST" ]; then
266 ECS_ADAPTER=$ECS_PATH
267 fi
268 else
269 __check_included_image 'ECS'
270 if [ $? -eq 1 ]; then
271 echo -e $RED"The ECS app is not included in this test script"$ERED
272 echo -e $RED"ECS will not be started"$ERED
273 exit 1
274 fi
275
276 curdir=$PWD
277 cd $SIM_GROUP
278 cd ecs
279 cd $ECS_HOST_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100280 #cd ..
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100281 if [ -d db ]; then
282 if [ "$(ls -A $DIR)" ]; then
283 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
284 rm -rf db/* &> /dev/null
285 if [ $? -ne 0 ]; then
286 echo -e $RED" Cannot remove database files in: $PWD"$ERED
287 exit 1
288 fi
289 fi
290 else
291 echo " No files in mounted dir or dir does not exists"
292 fi
293 cd $curdir
294
295 export ECS_APP_NAME
296 export ECS_APP_NAME_ALIAS
297 export ECS_HOST_MNT_DIR
298 export ECS_CONTAINER_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100299 export ECS_CONFIG_MOUNT_PATH
300 export ECS_CONFIG_FILE
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100301 export ECS_INTERNAL_PORT
302 export ECS_EXTERNAL_PORT
303 export ECS_INTERNAL_SECURE_PORT
304 export ECS_EXTERNAL_SECURE_PORT
305 export DOCKER_SIM_NWNAME
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100306 export ECS_DISPLAY_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100307
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100308 if [ $1 == "PROXY" ]; then
309 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
310 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
311 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
312 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
313 else
314 echo " Configured with http proxy"
315 fi
316 else
317 ECS_HTTP_PROXY_CONFIG_PORT=0
318 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
319 echo " Configured without http proxy"
320 fi
321 export ECS_HTTP_PROXY_CONFIG_PORT
322 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
323
324 dest_file=$SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_HOST_MNT_DIR/$ECS_CONFIG_FILE
325
326 envsubst < $2 > $dest_file
327
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100328 __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100329
330 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
331 fi
332 echo ""
333 return 0
334}
335
336# Restart ECS
337# args: -
338# (Function for test scripts)
339restart_ecs() {
340 echo -e $BOLD"Re-starting ECS"$EBOLD
341 docker restart $ECS_APP_NAME &> ./tmp/.dockererr
342 if [ $? -ne 0 ]; then
343 __print_err "Could not restart $ECS_APP_NAME" $@
344 cat ./tmp/.dockererr
345 ((RES_CONF_FAIL++))
346 return 1
347 fi
348
349 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
350 echo ""
351 return 0
352}
353
354# Turn on debug level tracing in ECS
355# args: -
356# (Function for test scripts)
357set_ecs_debug() {
358 echo -e $BOLD"Setting ecs debug logging"$EBOLD
359 curlString="$ECS_PATH$ECS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
360 result=$(__do_curl "$curlString")
361 if [ $? -ne 0 ]; then
362 __print_err "Could not set debug mode" $@
363 ((RES_CONF_FAIL++))
364 return 1
365 fi
366 echo ""
367 return 0
368}
369
370# Turn on trace level tracing in ECS
371# args: -
372# (Function for test scripts)
373set_ecs_trace() {
374 echo -e $BOLD"Setting ecs trace logging"$EBOLD
375 curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
376 result=$(__do_curl "$curlString")
377 if [ $? -ne 0 ]; then
378 __print_err "Could not set trace mode" $@
379 ((RES_CONF_FAIL++))
380 return 1
381 fi
382 echo ""
383 return 0
384}
385
386# Perform curl retries when making direct call to ECS for the specified http response codes
387# Speace separated list of http response codes
388# args: [<response-code>]*
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100389use_ecs_retries() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100390 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100391 ECS_RETRY_CODES=$@
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100392 echo ""
393 return 0
394}
395
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100396# Check the ecs logs for WARNINGs and ERRORs
397# args: -
398# (Function for test scripts)
399check_ecs_logs() {
400 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
401}
402
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200403
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100404# Tests if a variable value in the ECS is equal to a target value and and optional timeout.
405# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
406# equal to the target or not.
407# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
408# before setting pass or fail depending on if the variable value becomes equal to the target
409# value or not.
410# (Function for test scripts)
411ecs_equal() {
412 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100413 __var_test ECS "$ECS_PATH/" $1 "=" $2 $3
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100414 else
415 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
416 fi
417}
418
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200419
420##########################################
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100421######### A1-E Enrichment API ##########
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200422##########################################
423#Function prefix: ecs_api_a1
424
425# API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200426# args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100427# args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200428# (Function for test scripts)
429ecs_api_a1_get_job_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100430 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200431
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100432 if [ -z "$FLAT_A1_EI" ]; then
433 # Valid number of parameters 4,5,6 etc
434 if [ $# -lt 3 ]; then
435 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
436 return 1
437 fi
438 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100439 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100440 # Valid number of parameters 4,5,6 etc
441 if [ $# -lt 3 ]; then
442 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
443 return 1
444 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200445 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100446 search=""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200447 if [ $3 != "NOWNER" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100448 search="?owner="$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200449 fi
450
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100451 if [ -z "$FLAT_A1_EI" ]; then
452 query="/A1-EI/v1/eitypes/$2/eijobs$search"
453 else
454 if [ $2 != "NOTYPE" ]; then
455 if [ -z "$search" ]; then
456 search="?eiTypeId="$2
457 else
458 search=$search"&eiTypeId="$2
459 fi
460 fi
461 query="/A1-EI/v1/eijobs$search"
462 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200463 res="$(__do_curl_to_api ECS GET $query)"
464 status=${res:${#res}-3}
465
466 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100467 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200468 return 1
469 fi
470
471 if [ $# -gt 3 ]; then
472 body=${res:0:${#res}-3}
473 targetJson="["
474
475 for pid in ${@:4} ; do
476 if [ "$targetJson" != "[" ]; then
477 targetJson=$targetJson","
478 fi
479 if [ $pid != "EMPTY" ]; then
480 targetJson=$targetJson"\"$pid\""
481 fi
482 done
483
484 targetJson=$targetJson"]"
485 echo " TARGET JSON: $targetJson" >> $HTTPLOG
486 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
487
488 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100489 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200490 return 1
491 fi
492 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200493
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100494 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200495 return 0
496}
497
498# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200499# args: <response-code> <type-id> [<schema-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200500# (Function for test scripts)
501ecs_api_a1_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100502 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200503
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200504 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
505 __print_err "<response-code> <type-id> [<schema-file>]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200506 return 1
507 fi
508
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200509 query="/A1-EI/v1/eitypes/$2"
510 res="$(__do_curl_to_api ECS GET $query)"
511 status=${res:${#res}-3}
512
513 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100514 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200515 return 1
516 fi
517
518 if [ $# -eq 3 ]; then
519 body=${res:0:${#res}-3}
520 if [ -f $3 ]; then
521 schema=$(cat $3)
522 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100523 __log_test_fail_general "Schema file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200524 return 1
525 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100526 if [ -z "$FLAT_A1_EI" ]; then
527 targetJson="{\"eiJobParametersSchema\":$schema}"
528 else
529 targetJson=$schema
530 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200531 echo " TARGET JSON: $targetJson" >> $HTTPLOG
532 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
533
534 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100535 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200536 return 1
537 fi
538 fi
539
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100540 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200541 return 0
542}
543
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200544# API Test function: GET /A1-EI/v1/eitypes
545# args: <response-code> [ (EMPTY | [<type-id>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200546# (Function for test scripts)
547ecs_api_a1_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100548 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200549
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200550 if [ $# -lt 1 ]; then
551 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200552 return 1
553 fi
554
555 query="/A1-EI/v1/eitypes"
556 res="$(__do_curl_to_api ECS GET $query)"
557 status=${res:${#res}-3}
558
559 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100560 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200561 return 1
562 fi
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200563 if [ $# -gt 1 ]; then
564 body=${res:0:${#res}-3}
565 targetJson="["
566 if [ $2 != "EMPTY" ]; then
567 for pid in ${@:2} ; do
568 if [ "$targetJson" != "[" ]; then
569 targetJson=$targetJson","
570 fi
571 targetJson=$targetJson"\"$pid\""
572 done
573 fi
574 targetJson=$targetJson"]"
575 echo " TARGET JSON: $targetJson" >> $HTTPLOG
576 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200577
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200578 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100579 __log_test_fail_body
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200580 return 1
581 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200582 fi
583
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100584 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200585 return 0
586}
587
588# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200589# args: <response-code> <type-id> <job-id> [<status>]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100590# args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200591# (Function for test scripts)
592ecs_api_a1_get_job_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100593 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200594
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100595 if [ -z "$FLAT_A1_EI" ]; then
596 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
597 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
598 return 1
599 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200600
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100601 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200602
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100603 res="$(__do_curl_to_api ECS GET $query)"
604 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200605
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100606 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100607 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200608 return 1
609 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100610 if [ $# -eq 4 ]; then
611 body=${res:0:${#res}-3}
612 targetJson="{\"operationalState\": \"$4\"}"
613 echo " TARGET JSON: $targetJson" >> $HTTPLOG
614 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
615
616 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100617 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100618 return 1
619 fi
620 fi
621 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100622 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100623 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
624 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100625 return 1
626 fi
627
628 query="/A1-EI/v1/eijobs/$2/status"
629
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100630 start=$SECONDS
631 for (( ; ; )); do
632 res="$(__do_curl_to_api ECS GET $query)"
633 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100634
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100635 if [ $# -eq 4 ]; then
636 duration=$((SECONDS-start))
637 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
638 if [ $duration -gt $4 ]; then
639 echo ""
640 duration=-1 #Last iteration
641 fi
642 else
643 duration=-1 #single test, no wait
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100644 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100645
646 if [ $status -ne $1 ]; then
647 if [ $duration -eq -1 ]; then
648 __log_test_fail_status_code $1 $status
649 return 1
650 fi
651 fi
652 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
653 body=${res:0:${#res}-3}
654 targetJson="{\"eiJobStatus\": \"$3\"}"
655 echo " TARGET JSON: $targetJson" >> $HTTPLOG
656 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
657
658 if [ $res -ne 0 ]; then
659 if [ $duration -eq -1 ]; then
660 __log_test_fail_body
661 return 1
662 fi
663 else
664 duration=-1 #Goto pass
665 fi
666 fi
667 if [ $duration -eq -1 ]; then
668 if [ $# -eq 4 ]; then
669 echo ""
670 fi
671 __log_test_pass
672 return 0
673 else
674 sleep 1
675 fi
676 done
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200677 fi
678
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100679 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200680 return 0
681}
682
683# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200684# args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100685# args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200686# (Function for test scripts)
687ecs_api_a1_get_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100688 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200689
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100690 if [ -z "$FLAT_A1_EI" ]; then
691 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
692 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
693 return 1
694 fi
695 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
696 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100697 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100698 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
699 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
700 return 1
701 fi
702 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200703 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200704 res="$(__do_curl_to_api ECS GET $query)"
705 status=${res:${#res}-3}
706
707 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100708 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200709 return 1
710 fi
711
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100712 if [ -z "$FLAT_A1_EI" ]; then
713 if [ $# -eq 6 ]; then
714 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200715
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100716 if [ -f $6 ]; then
717 jobfile=$(cat $6)
718 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
719 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100720 _log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100721 return 1
722 fi
723 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
724 echo " TARGET JSON: $targetJson" >> $HTTPLOG
725 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
726
727 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100728 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100729 return 1
730 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200731 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100732 else
733 if [ $# -eq 7 ]; then
734 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200735
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100736 if [ -f $7 ]; then
737 jobfile=$(cat $7)
738 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
739 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100740 _log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100741 return 1
742 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100743 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100744 echo " TARGET JSON: $targetJson" >> $HTTPLOG
745 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
746
747 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100748 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100749 return 1
750 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200751 fi
752 fi
753
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100754 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200755 return 0
756}
757
758# API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200759# args: <response-code> <type-id> <job-id>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100760# args (flat uri structure): <response-code> <job-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200761# (Function for test scripts)
762ecs_api_a1_delete_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100763 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200764
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100765 if [ -z "$FLAT_A1_EI" ]; then
766 if [ $# -ne 3 ]; then
767 __print_err "<response-code> <type-id> <job-id>" $@
768 return 1
769 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200770
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100771 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
772 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100773 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100774 if [ $# -ne 2 ]; then
775 __print_err "<response-code> <job-id>" $@
776 return 1
777 fi
778 query="/A1-EI/v1/eijobs/$2"
779 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200780 res="$(__do_curl_to_api ECS DELETE $query)"
781 status=${res:${#res}-3}
782
783 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100784 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200785 return 1
786 fi
787
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100788 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200789 return 0
790}
791
792# API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200793# args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100794# args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200795# (Function for test scripts)
796ecs_api_a1_put_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100797 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200798
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100799 if [ -z "$FLAT_A1_EI" ]; then
800 if [ $# -lt 6 ]; then
801 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
802 return 1
803 fi
804 if [ -f $6 ]; then
805 jobfile=$(cat $6)
806 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
807 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100808 _log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100809 return 1
810 fi
811
812 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
813 file="./tmp/.p.json"
814 echo "$inputJson" > $file
815
816 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200817 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100818 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100819 if [ $# -lt 7 ]; then
820 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
821 return 1
822 fi
823 if [ -f $7 ]; then
824 jobfile=$(cat $7)
825 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
826 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100827 _log_test_fail_general "Job template file "$7", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100828 return 1
829 fi
830
831 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
832 file="./tmp/.p.json"
833 echo "$inputJson" > $file
834
835 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200836 fi
837
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200838 res="$(__do_curl_to_api ECS PUT $query $file)"
839 status=${res:${#res}-3}
840
841 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100842 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200843 return 1
844 fi
845
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100846 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200847 return 0
848}
849
850
851##########################################
852#### Enrichment Data Producer API ####
853##########################################
854# Function prefix: ecs_api_edp
855
856# API Test function: GET /ei-producer/v1/eitypes
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200857# args: <response-code> [ EMPTY | <type-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200858# (Function for test scripts)
859ecs_api_edp_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100860 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200861
862 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200863 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200864 return 1
865 fi
866
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200867 query="/ei-producer/v1/eitypes"
868 res="$(__do_curl_to_api ECS GET $query)"
869 status=${res:${#res}-3}
870
871 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100872 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200873 return 1
874 fi
875
876 if [ $# -gt 1 ]; then
877 body=${res:0:${#res}-3}
878 targetJson="["
879 if [ $2 != "EMPTY" ]; then
880 for pid in ${@:2} ; do
881 if [ "$targetJson" != "[" ]; then
882 targetJson=$targetJson","
883 fi
884 targetJson=$targetJson"\"$pid\""
885 done
886 fi
887 targetJson=$targetJson"]"
888 echo " TARGET JSON: $targetJson" >> $HTTPLOG
889 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
890
891 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100892 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200893 return 1
894 fi
895 fi
896
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100897 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200898 return 0
899}
900
901# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100902# args: <response-code> <producer-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200903# (Function for test scripts)
904ecs_api_edp_get_producer_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100905 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200906
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100907 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
908 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200909 return 1
910 fi
911
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200912 query="/ei-producer/v1/eiproducers/$2/status"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100913 start=$SECONDS
914 for (( ; ; )); do
915 res="$(__do_curl_to_api ECS GET $query)"
916 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200917
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100918 if [ $# -eq 4 ]; then
919 duration=$((SECONDS-start))
920 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
921 if [ $duration -gt $4 ]; then
922 echo ""
923 duration=-1 #Last iteration
924 fi
925 else
926 duration=-1 #single test, no wait
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200927 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200928
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100929 if [ $status -ne $1 ]; then
930 if [ $duration -eq -1 ]; then
931 __log_test_fail_status_code $1 $status
932 return 1
933 fi
934 fi
935 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
936 body=${res:0:${#res}-3}
937 targetJson="{\"operational_state\": \"$3\"}"
938 echo " TARGET JSON: $targetJson" >> $HTTPLOG
939 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
940
941 if [ $res -ne 0 ]; then
942 if [ $duration -eq -1 ]; then
943 __log_test_fail_body
944 return 1
945 fi
946 else
947 duration=-1 #Goto pass
948 fi
949 fi
950 if [ $duration -eq -1 ]; then
951 if [ $# -eq 4 ]; then
952 echo ""
953 fi
954 __log_test_pass
955 return 0
956 else
957 sleep 1
958 fi
959 done
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200960}
961
962
963# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100964# args (v1_1): <response-code> [ EMPTY | <producer-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200965# (Function for test scripts)
966ecs_api_edp_get_producer_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100967 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200968
969 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200970 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200971 return 1
972 fi
973
974 query="/ei-producer/v1/eiproducers"
975 res="$(__do_curl_to_api ECS GET $query)"
976 status=${res:${#res}-3}
977
978 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100979 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200980 return 1
981 fi
982
983 if [ $# -gt 1 ]; then
984 body=${res:0:${#res}-3}
985 targetJson="["
986
987 for pid in ${@:2} ; do
988 if [ "$targetJson" != "[" ]; then
989 targetJson=$targetJson","
990 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200991 if [ $pid != "EMPTY" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200992 targetJson=$targetJson"\"$pid\""
993 fi
994 done
995
996 targetJson=$targetJson"]"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200997 echo " TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200998 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
999
1000 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001001 __log_test_fail_body
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001002 return 1
1003 fi
1004 fi
1005
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001006 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001007 return 0
1008}
1009
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001010# API Test function: GET /ei-producer/v1/eiproducers
1011# args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1012# (Function for test scripts)
1013ecs_api_edp_get_producer_ids_2() {
1014 __log_test_start $@
1015
1016 if [ $# -lt 1 ]; then
1017 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1018 return 1
1019 fi
1020
1021 query="/ei-producer/v1/eiproducers"
1022 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1023 query=$query"?ei_type_id=$2"
1024 fi
1025 res="$(__do_curl_to_api ECS GET $query)"
1026 status=${res:${#res}-3}
1027
1028 if [ $status -ne $1 ]; then
1029 __log_test_fail_status_code $1 $status
1030 return 1
1031 fi
1032
1033 if [ $# -gt 2 ]; then
1034 body=${res:0:${#res}-3}
1035 targetJson="["
1036
1037 for pid in ${@:3} ; do
1038 if [ "$targetJson" != "[" ]; then
1039 targetJson=$targetJson","
1040 fi
1041 if [ $pid != "EMPTY" ]; then
1042 targetJson=$targetJson"\"$pid\""
1043 fi
1044 done
1045
1046 targetJson=$targetJson"]"
1047 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1048 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1049
1050 if [ $res -ne 0 ]; then
1051 __log_test_fail_body
1052 return 1
1053 fi
1054 fi
1055
1056 __log_test_pass
1057 return 0
1058}
1059
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001060# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001061# args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001062# (Function for test scripts)
1063ecs_api_edp_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001064 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001065
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001066 paramError=1
1067 if [ $# -eq 2 ]; then
1068 paramError=0
1069 fi
1070 if [ $# -gt 3 ]; then
1071 paramError=0
1072 fi
1073 if [ $paramError -ne 0 ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02001074 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001075 return 1
1076 fi
1077
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001078 query="/ei-producer/v1/eitypes/$2"
1079 res="$(__do_curl_to_api ECS GET $query)"
1080 status=${res:${#res}-3}
1081
1082 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001083 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001084 return 1
1085 fi
1086 if [ $# -gt 3 ]; then
1087 body=${res:0:${#res}-3}
1088
1089 if [ -f $3 ]; then
1090 schema=$(cat $3)
1091 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001092 __log_test_fail_general "Job template file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001093 return 1
1094 fi
1095
1096 targetJson=""
1097 if [ $4 != "EMPTY" ]; then
1098 for pid in ${@:4} ; do
1099 if [ "$targetJson" != "" ]; then
1100 targetJson=$targetJson","
1101 fi
1102 targetJson=$targetJson"\"$pid\""
1103 done
1104 fi
1105 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1106
1107 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1108 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1109
1110 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001111 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001112 return 1
1113 fi
1114 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001115 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001116 return 0
1117}
1118
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001119# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1120# args: (v1_2) <response-code> <type-id> [<job-schema-file> ]
1121# (Function for test scripts)
1122ecs_api_edp_get_type_2() {
1123 __log_test_start $@
1124
1125 paramError=1
1126 if [ $# -eq 2 ]; then
1127 paramError=0
1128 fi
1129 if [ $# -eq 3 ]; then
1130 paramError=0
1131 fi
1132 if [ $paramError -ne 0 ]; then
1133 __print_err "<response-code> <type-id> [<job-schema-file> ]" $@
1134 return 1
1135 fi
1136
1137 query="/ei-producer/v1/eitypes/$2"
1138 res="$(__do_curl_to_api ECS GET $query)"
1139 status=${res:${#res}-3}
1140
1141 if [ $status -ne $1 ]; then
1142 __log_test_fail_status_code $1 $status
1143 return 1
1144 fi
1145 if [ $# -eq 3 ]; then
1146 body=${res:0:${#res}-3}
1147
1148 if [ -f $3 ]; then
1149 schema=$(cat $3)
1150 else
1151 __log_test_fail_general "Job template file "$3", does not exist"
1152 return 1
1153 fi
1154
1155 targetJson="{\"ei_job_data_schema\":$schema}"
1156
1157 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1158 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1159
1160 if [ $res -ne 0 ]; then
1161 __log_test_fail_body
1162 return 1
1163 fi
1164 fi
1165 __log_test_pass
1166 return 0
1167}
1168
1169# API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1170# args: (v1_2) <response-code> <type-id> <job-schema-file>
1171# (Function for test scripts)
1172ecs_api_edp_put_type_2() {
1173 __log_test_start $@
1174
1175 if [ $# -ne 3 ]; then
1176 __print_err "<response-code> <type-id> <job-schema-file>" $@
1177 return 1
1178 fi
1179
1180 if [ ! -f $3 ]; then
1181 __log_test_fail_general "Job schema file "$3", does not exist"
1182 return 1
1183 fi
1184 schema=$(cat $3)
1185 input_json="{\"ei_job_data_schema\":$schema}"
1186 file="./tmp/put_type.json"
1187 echo $input_json > $file
1188
1189 query="/ei-producer/v1/eitypes/$2"
1190 res="$(__do_curl_to_api ECS PUT $query $file)"
1191 status=${res:${#res}-3}
1192
1193 if [ $status -ne $1 ]; then
1194 __log_test_fail_status_code $1 $status
1195 return 1
1196 fi
1197
1198 __log_test_pass
1199 return 0
1200}
1201
1202# API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1203# args: (v1_2) <response-code> <type-id>
1204# (Function for test scripts)
1205ecs_api_edp_delete_type_2() {
1206 __log_test_start $@
1207
1208 if [ $# -ne 2 ]; then
1209 __print_err "<response-code> <type-id>" $@
1210 return 1
1211 fi
1212
1213 query="/ei-producer/v1/eitypes/$2"
1214 res="$(__do_curl_to_api ECS DELETE $query)"
1215 status=${res:${#res}-3}
1216
1217 if [ $status -ne $1 ]; then
1218 __log_test_fail_status_code $1 $status
1219 return 1
1220 fi
1221
1222 __log_test_pass
1223 return 0
1224}
1225
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001226# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001227# args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001228# (Function for test scripts)
1229ecs_api_edp_get_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001230 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001231
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001232 #Possible arg count: 2, 5 6, 8, 10 etc
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001233 paramError=1
1234 if [ $# -eq 2 ]; then
1235 paramError=0
1236 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001237 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001238 paramError=0
1239 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001240 variablecount=$(($#-4))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001241 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1242 paramError=0
1243 fi
1244
1245 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001246 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001247 return 1
1248 fi
1249
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001250 query="/ei-producer/v1/eiproducers/$2"
1251 res="$(__do_curl_to_api ECS GET $query)"
1252 status=${res:${#res}-3}
1253
1254 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001255 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001256 return 1
1257 fi
1258
1259 if [ $# -gt 2 ]; then
1260 body=${res:0:${#res}-3}
1261 targetJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001262 if [ $# -gt 5 ]; then
1263 arr=(${@:5})
1264 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001265 if [ "$targetJson" != "[" ]; then
1266 targetJson=$targetJson","
1267 fi
1268 if [ -f ${arr[$i+1]} ]; then
1269 schema=$(cat ${arr[$i+1]})
1270 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001271 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001272 return 1
1273 fi
1274
1275 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1276 done
1277 fi
1278 targetJson=$targetJson"]"
1279 if [ $# -gt 4 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001280 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001281 fi
1282 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1283 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1284
1285 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001286 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001287 return 1
1288 fi
1289 fi
1290
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001291 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001292 return 0
1293}
1294
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001295# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1296# args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1297# (Function for test scripts)
1298ecs_api_edp_get_producer_2() {
1299 __log_test_start $@
1300
1301 #Possible arg count: 2, 5, 6, 7, 8 etc
1302 paramError=1
1303 if [ $# -eq 2 ]; then
1304 paramError=0
1305 fi
1306 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1307 paramError=0
1308 fi
1309 if [ $# -ge 5 ]; then
1310 paramError=0
1311 fi
1312
1313 if [ $paramError -ne 0 ]; then
1314 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1315 return 1
1316 fi
1317
1318 query="/ei-producer/v1/eiproducers/$2"
1319 res="$(__do_curl_to_api ECS GET $query)"
1320 status=${res:${#res}-3}
1321
1322 if [ $status -ne $1 ]; then
1323 __log_test_fail_status_code $1 $status
1324 return 1
1325 fi
1326
1327 if [ $# -gt 2 ]; then
1328 body=${res:0:${#res}-3}
1329 targetJson="["
1330 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1331 arr=(${@:5})
1332 for ((i=0; i<$(($#-4)); i=i+1)); do
1333 if [ "$targetJson" != "[" ]; then
1334 targetJson=$targetJson","
1335 fi
1336 targetJson=$targetJson"\"${arr[$i]}\""
1337 done
1338 fi
1339 targetJson=$targetJson"]"
1340 if [ $# -gt 4 ]; then
1341 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1342 fi
1343 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1344 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1345
1346 if [ $res -ne 0 ]; then
1347 __log_test_fail_body
1348 return 1
1349 fi
1350 fi
1351
1352 __log_test_pass
1353 return 0
1354}
1355
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001356# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001357# args: <response-code> <producer-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001358# (Function for test scripts)
1359ecs_api_edp_delete_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001360 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001361
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001362 if [ $# -lt 2 ]; then
1363 __print_err "<response-code> <producer-id>" $@
1364 return 1
1365 fi
1366
1367 query="/ei-producer/v1/eiproducers/$2"
1368 res="$(__do_curl_to_api ECS DELETE $query)"
1369 status=${res:${#res}-3}
1370
1371 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001372 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001373 return 1
1374 fi
1375
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001376 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001377 return 0
1378}
1379
1380# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001381# args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001382# (Function for test scripts)
1383ecs_api_edp_put_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001384 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001385
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001386 #Valid number of parametrer 5,6,8,10,
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001387 paramError=1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001388 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001389 paramError=0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001390 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001391 paramError=0
1392 fi
1393 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001394 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001395 return 1
1396 fi
1397
1398 inputJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001399 if [ $# -gt 5 ]; then
1400 arr=(${@:5})
1401 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001402 if [ "$inputJson" != "[" ]; then
1403 inputJson=$inputJson","
1404 fi
1405 if [ -f ${arr[$i+1]} ]; then
1406 schema=$(cat ${arr[$i+1]})
1407 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001408 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001409 return 1
1410 fi
1411 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1412 done
1413 fi
1414 inputJson="\"supported_ei_types\":"$inputJson"]"
1415
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001416 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001417
1418 inputJson="{"$inputJson"}"
1419
1420 file="./tmp/.p.json"
1421 echo "$inputJson" > $file
1422 query="/ei-producer/v1/eiproducers/$2"
1423 res="$(__do_curl_to_api ECS PUT $query $file)"
1424 status=${res:${#res}-3}
1425
1426 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001427 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001428 return 1
1429 fi
1430
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001431 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001432 return 0
1433}
1434
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001435# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1436# args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1437# (Function for test scripts)
1438ecs_api_edp_put_producer_2() {
1439 __log_test_start $@
1440
1441 #Valid number of parametrer 5,6,8,10,
1442 paramError=1
1443 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1444 paramError=0
1445 elif [ $# -ge 5 ]; then
1446 paramError=0
1447 fi
1448 if [ $paramError -ne 0 ]; then
1449 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1450 return 1
1451 fi
1452
1453 inputJson="["
1454 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1455 arr=(${@:5})
1456 for ((i=0; i<$(($#-4)); i=i+1)); do
1457 if [ "$inputJson" != "[" ]; then
1458 inputJson=$inputJson","
1459 fi
1460 inputJson=$inputJson"\""${arr[$i]}"\""
1461 done
1462 fi
1463 inputJson="\"supported_ei_types\":"$inputJson"]"
1464
1465 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1466
1467 inputJson="{"$inputJson"}"
1468
1469 file="./tmp/.p.json"
1470 echo "$inputJson" > $file
1471 query="/ei-producer/v1/eiproducers/$2"
1472 res="$(__do_curl_to_api ECS PUT $query $file)"
1473 status=${res:${#res}-3}
1474
1475 if [ $status -ne $1 ]; then
1476 __log_test_fail_status_code $1 $status
1477 return 1
1478 fi
1479
1480 __log_test_pass
1481 return 0
1482}
1483
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001484# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001485# args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001486# (Function for test scripts)
1487ecs_api_edp_get_producer_jobs() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001488 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001489
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001490 #Valid number of parameter 2,3,7,11
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001491 paramError=1
1492 if [ $# -eq 2 ]; then
1493 paramError=0
1494 fi
1495 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1496 paramError=0
1497 fi
1498 variablecount=$(($#-2))
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001499 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001500 paramError=0
1501 fi
1502 if [ $paramError -eq 1 ]; then
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001503 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001504 return 1
1505 fi
1506
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001507 query="/ei-producer/v1/eiproducers/$2/eijobs"
1508 res="$(__do_curl_to_api ECS GET $query)"
1509 status=${res:${#res}-3}
1510 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001511 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001512 return 1
1513 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001514 if [ $# -gt 2 ]; then
1515 body=${res:0:${#res}-3}
1516 targetJson="["
1517 if [ $# -gt 3 ]; then
1518 arr=(${@:3})
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001519 for ((i=0; i<$(($#-3)); i=i+5)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001520 if [ "$targetJson" != "[" ]; then
1521 targetJson=$targetJson","
1522 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001523 if [ -f ${arr[$i+4]} ]; then
1524 jobfile=$(cat ${arr[$i+4]})
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001525 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1526 else
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001527 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001528 return 1
1529 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001530 targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001531 done
1532 fi
1533 targetJson=$targetJson"]"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001534
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001535 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1536 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001537
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001538 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001539 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001540 return 1
1541 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001542 fi
1543
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001544 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001545 return 0
1546}
1547
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001548# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1549# args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1550# (Function for test scripts)
1551ecs_api_edp_get_producer_jobs_2() {
1552 __log_test_start $@
1553
1554 #Valid number of parameter 2,3,7,11
1555 paramError=1
1556 if [ $# -eq 2 ]; then
1557 paramError=0
1558 fi
1559 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1560 paramError=0
1561 fi
1562 variablecount=$(($#-2))
1563 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1564 paramError=0
1565 fi
1566 if [ $paramError -eq 1 ]; then
1567 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1568 return 1
1569 fi
1570
1571 query="/ei-producer/v1/eiproducers/$2/eijobs"
1572 res="$(__do_curl_to_api ECS GET $query)"
1573 status=${res:${#res}-3}
1574 if [ $status -ne $1 ]; then
1575 __log_test_fail_status_code $1 $status
1576 return 1
1577 fi
1578 if [ $# -gt 2 ]; then
1579 body=${res:0:${#res}-3}
1580 targetJson="["
1581 if [ $# -gt 3 ]; then
1582 arr=(${@:3})
1583 for ((i=0; i<$(($#-3)); i=i+5)); do
1584 if [ "$targetJson" != "[" ]; then
1585 targetJson=$targetJson","
1586 fi
1587 if [ -f ${arr[$i+4]} ]; then
1588 jobfile=$(cat ${arr[$i+4]})
1589 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1590 else
1591 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1592 return 1
1593 fi
1594 targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile, \"last_updated\":\"????\"}"
1595 done
1596 fi
1597 targetJson=$targetJson"]"
1598
1599 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1600 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1601
1602 if [ $res -ne 0 ]; then
1603 __log_test_fail_body
1604 return 1
1605 fi
1606 fi
1607
1608 __log_test_pass
1609 return 0
1610}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001611
1612##########################################
1613#### Service status ####
1614##########################################
1615# Function prefix: ecs_api_service
1616
1617# API Test function: GET ​/status
1618# args: <response-code>
1619# (Function for test scripts)
1620ecs_api_service_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001621 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001622
1623 if [ $# -lt 1 ]; then
1624 __print_err "<response-code> [<producer-id>]*|NOID" $@
1625 return 1
1626 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001627 res="$(__do_curl_to_api ECS GET /status)"
1628 status=${res:${#res}-3}
1629 if [ $status -ne $1 ]; then
1630 __log_test_fail_status_code $1 $status
1631 return 1
1632 fi
1633 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001634 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001635}
1636
1637
1638##########################################
1639#### Reset jobs ####
1640##########################################
1641# Function prefix: ecs_api_admin
1642
1643# Admin to remove all jobs
BjornMagnussonXA366e36a2021-01-27 11:48:56 +01001644# args: <response-code> [ <type> ]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001645# (Function for test scripts)
1646
1647ecs_api_admin_reset() {
1648 __log_test_start $@
1649
1650 if [ -z "$FLAT_A1_EI" ]; then
1651 query="/A1-EI/v1/eitypes/$2/eijobs"
1652 else
1653 query="/A1-EI/v1/eijobs"
1654 fi
1655 res="$(__do_curl_to_api ECS GET $query)"
1656 status=${res:${#res}-3}
1657
1658 if [ $status -ne 200 ]; then
1659 __log_test_fail_status_code $1 $status
1660 return 1
1661 fi
1662
1663 #Remove brackets and response code
1664 body=${res:1:${#res}-4}
1665 list=$(echo ${body//,/ })
1666 list=$(echo ${list//[/})
1667 list=$(echo ${list//]/})
1668 list=$(echo ${list//\"/})
1669 list=$list" "
1670 for job in $list; do
1671 if [ -z "$FLAT_A1_EI" ]; then
1672 echo "Not supported for non-flat EI api"
1673 else
1674 query="/A1-EI/v1/eijobs/$job"
1675 res="$(__do_curl_to_api ECS DELETE $query)"
1676 status=${res:${#res}-3}
1677 if [ $status -ne 204 ]; then
1678 __log_test_fail_status_code $1 $status
1679 return 1
1680 fi
1681 echo " Deleted job: "$job
1682 fi
1683 done
1684
1685 __log_test_pass
1686 return 0
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001687}