blob: 525ac8b501c8d60eee8ad4b17adeb83d29843532 [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() {
BjornMagnussonXA483ee332021-04-08 01:35:24 +020037 __check_and_pull_image $1 "$ECS_DISPLAY_NAME" $ECS_APP_NAME ECS_IMAGE
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010038}
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
BjornMagnussonXA483ee332021-04-08 01:35:24 +020048# If a custom image repo is used then also the source image from the local repo is listed
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010049# arg: <docker-images-format-string> <file-to-append>
50__ECS_image_data() {
51 echo -e "$ECS_DISPLAY_NAME\t$(docker images --format $1 $ECS_IMAGE)" >> $2
BjornMagnussonXA483ee332021-04-08 01:35:24 +020052 if [ ! -z "$ECS_IMAGE_SOURCE" ]; then
53 echo -e "-- source image --\t$(docker images --format $1 $ECS_IMAGE_SOURCE)" >> $2
54 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010055}
56
57# Scale kubernetes resources to zero
58# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
59# This function is called for apps fully managed by the test script
60__ECS_kube_scale_zero() {
61 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
62}
63
64# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
65# This function is called for prestarted apps not managed by the test script.
66__ECS_kube_scale_zero_and_wait() {
67 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-enrichmentservice
68}
69
70# Delete all kube resouces for the app
71# This function is called for apps managed by the test script.
72__ECS_kube_delete_all() {
73 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
74}
75
76# Store docker logs
77# This function is called for apps managed by the test script.
78# args: <log-dir> <file-prexix>
79__ECS_store_docker_logs() {
80 docker logs $ECS_APP_NAME > $1$2_ecs.log 2>&1
81}
82#######################################################
83
84
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010085## Access to ECS
86# Host name may be changed if app started by kube
87# Direct access
88ECS_HTTPX="http"
89ECS_HOST_NAME=$LOCALHOST_NAME
90ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
91
92# ECS_ADAPTER used for switch between REST and DMAAP (only REST supported currently)
93ECS_ADAPTER_TYPE="REST"
94ECS_ADAPTER=$ECS_PATH
95
96# Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
97ECS_RETRY_CODES=""
98
99###########################
100### ECS functions
101###########################
102
103# All calls to ECS will be directed to the ECS REST interface from now on
104# args: -
105# (Function for test scripts)
106use_ecs_rest_http() {
107 echo -e $BOLD"ECS protocol setting"$EBOLD
108 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
109 ECS_HTTPX="http"
110 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
111
112 ECS_ADAPTER_TYPE="REST"
113 ECS_ADAPTER=$ECS_PATH
114 echo ""
115}
116
117# All calls to ECS will be directed to the ECS REST interface from now on
118# args: -
119# (Function for test scripts)
120use_ecs_rest_https() {
121 echo -e $BOLD"ECS protocol setting"$EBOLD
122 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
123 ECS_HTTPX="https"
124 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
125
126 ECS_ADAPTER_TYPE="REST"
127 ECS_ADAPTER=$ECS_PATH
128 echo ""
129}
130
131# All calls to ECS will be directed to the ECS dmaap interface over http from now on
132# args: -
133# (Function for test scripts)
134use_ecs_dmaap_http() {
135 echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
136 echo -e $RED" - NOT SUPPORTED - "$ERED
137 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
138 ECS_ADAPTER_TYPE="MR-HTTP"
139 echo ""
140}
141
142# All calls to ECS will be directed to the ECS dmaap interface over https from now on
143# args: -
144# (Function for test scripts)
145use_ecs_dmaap_https() {
146 echo -e $BOLD"RICSIM protocol setting"$EBOLD
147 echo -e $RED" - NOT SUPPORTED - "$ERED
148 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
149 ECS_ADAPTER_TYPE="MR-HTTPS"
150 echo ""
151}
152
153# Start the ECS
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100154# args: PROXY|NOPROXY <config-file>
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100155# (Function for test scripts)
156start_ecs() {
157
158 echo -e $BOLD"Starting $ECS_DISPLAY_NAME"$EBOLD
159
160 if [ $RUNMODE == "KUBE" ]; then
161
162 # Check if app shall be fully managed by the test script
163 __check_included_image "ECS"
164 retcode_i=$?
165
166 # Check if app shall only be used by the testscipt
167 __check_prestarted_image "ECS"
168 retcode_p=$?
169
170 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
171 echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
172 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
173 exit
174 fi
175 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
176 echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
177 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
178 exit
179 fi
180
181
182 if [ $retcode_p -eq 0 ]; then
183 echo -e " Using existing $ECS_APP_NAME deployment and service"
184 echo " Setting ECS replicas=1"
185 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
186 fi
187
188 # Check if app shall be fully managed by the test script
189 if [ $retcode_i -eq 0 ]; then
190 echo -e " Creating $ECS_APP_NAME app and expose service"
191
192 #Check if nonrtric namespace exists, if not create it
193 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
194
195 export ECS_APP_NAME
196 export KUBE_NONRTRIC_NAMESPACE
197 export ECS_IMAGE
198 export ECS_INTERNAL_PORT
199 export ECS_INTERNAL_SECURE_PORT
200 export ECS_EXTERNAL_PORT
201 export ECS_EXTERNAL_SECURE_PORT
202 export ECS_CONFIG_MOUNT_PATH
203 export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config"
204 export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data"
205 export ECS_CONTAINER_MNT_DIR
206
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100207 export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv"
208 #Create a unique path for the pv each time to prevent a previous volume to be reused
209 export ECS_PV_PATH="ecsdata-"$(date +%s)
210
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100211 if [ $1 == "PROXY" ]; then
212 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
213 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
214 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
215 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
216 else
217 echo " Configured with http proxy"
218 fi
219 else
220 ECS_HTTP_PROXY_CONFIG_PORT=0
221 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
222 echo " Configured without http proxy"
223 fi
224 export ECS_HTTP_PROXY_CONFIG_PORT
225 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
226
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100227 # Create config map for config
228 datafile=$PWD/tmp/$ECS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100229 cp $2 $datafile
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100230 output_yaml=$PWD/tmp/ecs_cfc.yaml
231 __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml
232
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100233 # Create pv
234 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pv.yaml
235 output_yaml=$PWD/tmp/ecs_pv.yaml
236 __kube_create_instance pv $ECS_APP_NAME $input_yaml $output_yaml
237
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100238 # Create pvc
239 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml
240 output_yaml=$PWD/tmp/ecs_pvc.yaml
241 __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml
242
243 # Create service
244 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml
245 output_yaml=$PWD/tmp/ecs_svc.yaml
246 __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml
247
248 # Create app
249 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml
250 output_yaml=$PWD/tmp/ecs_app.yaml
251 __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml
252 fi
253
254 echo " Retrieving host and ports for service..."
255 ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
256 ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
257 ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
258
259 echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT"
260
261 if [ $ECS_HTTPX == "http" ]; then
262 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
263 else
264 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
265 fi
266
267 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
268
269 if [ $ECS_ADAPTER_TYPE == "REST" ]; then
270 ECS_ADAPTER=$ECS_PATH
271 fi
272 else
273 __check_included_image 'ECS'
274 if [ $? -eq 1 ]; then
275 echo -e $RED"The ECS app is not included in this test script"$ERED
276 echo -e $RED"ECS will not be started"$ERED
277 exit 1
278 fi
279
280 curdir=$PWD
281 cd $SIM_GROUP
282 cd ecs
283 cd $ECS_HOST_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100284 #cd ..
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100285 if [ -d db ]; then
286 if [ "$(ls -A $DIR)" ]; then
287 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
288 rm -rf db/* &> /dev/null
289 if [ $? -ne 0 ]; then
290 echo -e $RED" Cannot remove database files in: $PWD"$ERED
291 exit 1
292 fi
293 fi
294 else
295 echo " No files in mounted dir or dir does not exists"
296 fi
297 cd $curdir
298
299 export ECS_APP_NAME
300 export ECS_APP_NAME_ALIAS
301 export ECS_HOST_MNT_DIR
302 export ECS_CONTAINER_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100303 export ECS_CONFIG_MOUNT_PATH
304 export ECS_CONFIG_FILE
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100305 export ECS_INTERNAL_PORT
306 export ECS_EXTERNAL_PORT
307 export ECS_INTERNAL_SECURE_PORT
308 export ECS_EXTERNAL_SECURE_PORT
309 export DOCKER_SIM_NWNAME
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100310 export ECS_DISPLAY_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100311
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100312 if [ $1 == "PROXY" ]; then
313 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
314 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
315 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
316 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
317 else
318 echo " Configured with http proxy"
319 fi
320 else
321 ECS_HTTP_PROXY_CONFIG_PORT=0
322 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
323 echo " Configured without http proxy"
324 fi
325 export ECS_HTTP_PROXY_CONFIG_PORT
326 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
327
328 dest_file=$SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_HOST_MNT_DIR/$ECS_CONFIG_FILE
329
330 envsubst < $2 > $dest_file
331
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100332 __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100333
334 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
335 fi
336 echo ""
337 return 0
338}
339
340# Restart ECS
341# args: -
342# (Function for test scripts)
343restart_ecs() {
344 echo -e $BOLD"Re-starting ECS"$EBOLD
345 docker restart $ECS_APP_NAME &> ./tmp/.dockererr
346 if [ $? -ne 0 ]; then
347 __print_err "Could not restart $ECS_APP_NAME" $@
348 cat ./tmp/.dockererr
349 ((RES_CONF_FAIL++))
350 return 1
351 fi
352
353 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
354 echo ""
355 return 0
356}
357
358# Turn on debug level tracing in ECS
359# args: -
360# (Function for test scripts)
361set_ecs_debug() {
362 echo -e $BOLD"Setting ecs debug logging"$EBOLD
363 curlString="$ECS_PATH$ECS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
364 result=$(__do_curl "$curlString")
365 if [ $? -ne 0 ]; then
366 __print_err "Could not set debug mode" $@
367 ((RES_CONF_FAIL++))
368 return 1
369 fi
370 echo ""
371 return 0
372}
373
374# Turn on trace level tracing in ECS
375# args: -
376# (Function for test scripts)
377set_ecs_trace() {
378 echo -e $BOLD"Setting ecs trace logging"$EBOLD
379 curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
380 result=$(__do_curl "$curlString")
381 if [ $? -ne 0 ]; then
382 __print_err "Could not set trace mode" $@
383 ((RES_CONF_FAIL++))
384 return 1
385 fi
386 echo ""
387 return 0
388}
389
390# Perform curl retries when making direct call to ECS for the specified http response codes
391# Speace separated list of http response codes
392# args: [<response-code>]*
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100393use_ecs_retries() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100394 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100395 ECS_RETRY_CODES=$@
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100396 echo ""
397 return 0
398}
399
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100400# Check the ecs logs for WARNINGs and ERRORs
401# args: -
402# (Function for test scripts)
403check_ecs_logs() {
404 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
405}
406
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200407
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100408# Tests if a variable value in the ECS is equal to a target value and and optional timeout.
409# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
410# equal to the target or not.
411# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
412# before setting pass or fail depending on if the variable value becomes equal to the target
413# value or not.
414# (Function for test scripts)
415ecs_equal() {
416 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100417 __var_test ECS "$ECS_PATH/" $1 "=" $2 $3
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100418 else
419 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
420 fi
421}
422
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200423
424##########################################
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100425######### A1-E Enrichment API ##########
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200426##########################################
427#Function prefix: ecs_api_a1
428
429# API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200430# args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100431# args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200432# (Function for test scripts)
433ecs_api_a1_get_job_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100434 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200435
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100436 if [ -z "$FLAT_A1_EI" ]; then
437 # Valid number of parameters 4,5,6 etc
438 if [ $# -lt 3 ]; then
439 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
440 return 1
441 fi
442 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100443 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100444 # Valid number of parameters 4,5,6 etc
445 if [ $# -lt 3 ]; then
446 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
447 return 1
448 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200449 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100450 search=""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200451 if [ $3 != "NOWNER" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100452 search="?owner="$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200453 fi
454
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100455 if [ -z "$FLAT_A1_EI" ]; then
456 query="/A1-EI/v1/eitypes/$2/eijobs$search"
457 else
458 if [ $2 != "NOTYPE" ]; then
459 if [ -z "$search" ]; then
460 search="?eiTypeId="$2
461 else
462 search=$search"&eiTypeId="$2
463 fi
464 fi
465 query="/A1-EI/v1/eijobs$search"
466 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200467 res="$(__do_curl_to_api ECS GET $query)"
468 status=${res:${#res}-3}
469
470 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100471 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200472 return 1
473 fi
474
475 if [ $# -gt 3 ]; then
476 body=${res:0:${#res}-3}
477 targetJson="["
478
479 for pid in ${@:4} ; do
480 if [ "$targetJson" != "[" ]; then
481 targetJson=$targetJson","
482 fi
483 if [ $pid != "EMPTY" ]; then
484 targetJson=$targetJson"\"$pid\""
485 fi
486 done
487
488 targetJson=$targetJson"]"
489 echo " TARGET JSON: $targetJson" >> $HTTPLOG
490 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
491
492 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100493 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200494 return 1
495 fi
496 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200497
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100498 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200499 return 0
500}
501
502# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200503# args: <response-code> <type-id> [<schema-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200504# (Function for test scripts)
505ecs_api_a1_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100506 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200507
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200508 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
509 __print_err "<response-code> <type-id> [<schema-file>]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200510 return 1
511 fi
512
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200513 query="/A1-EI/v1/eitypes/$2"
514 res="$(__do_curl_to_api ECS GET $query)"
515 status=${res:${#res}-3}
516
517 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100518 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200519 return 1
520 fi
521
522 if [ $# -eq 3 ]; then
523 body=${res:0:${#res}-3}
524 if [ -f $3 ]; then
525 schema=$(cat $3)
526 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100527 __log_test_fail_general "Schema file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200528 return 1
529 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100530 if [ -z "$FLAT_A1_EI" ]; then
531 targetJson="{\"eiJobParametersSchema\":$schema}"
532 else
533 targetJson=$schema
534 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200535 echo " TARGET JSON: $targetJson" >> $HTTPLOG
536 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
537
538 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100539 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200540 return 1
541 fi
542 fi
543
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100544 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200545 return 0
546}
547
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200548# API Test function: GET /A1-EI/v1/eitypes
549# args: <response-code> [ (EMPTY | [<type-id>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200550# (Function for test scripts)
551ecs_api_a1_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100552 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200553
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200554 if [ $# -lt 1 ]; then
555 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200556 return 1
557 fi
558
559 query="/A1-EI/v1/eitypes"
560 res="$(__do_curl_to_api ECS GET $query)"
561 status=${res:${#res}-3}
562
563 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100564 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200565 return 1
566 fi
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200567 if [ $# -gt 1 ]; then
568 body=${res:0:${#res}-3}
569 targetJson="["
570 if [ $2 != "EMPTY" ]; then
571 for pid in ${@:2} ; do
572 if [ "$targetJson" != "[" ]; then
573 targetJson=$targetJson","
574 fi
575 targetJson=$targetJson"\"$pid\""
576 done
577 fi
578 targetJson=$targetJson"]"
579 echo " TARGET JSON: $targetJson" >> $HTTPLOG
580 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200581
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200582 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100583 __log_test_fail_body
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200584 return 1
585 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200586 fi
587
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100588 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200589 return 0
590}
591
592# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200593# args: <response-code> <type-id> <job-id> [<status>]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100594# args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200595# (Function for test scripts)
596ecs_api_a1_get_job_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100597 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200598
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100599 if [ -z "$FLAT_A1_EI" ]; then
600 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
601 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
602 return 1
603 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200604
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100605 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200606
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100607 res="$(__do_curl_to_api ECS GET $query)"
608 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200609
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100610 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100611 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200612 return 1
613 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100614 if [ $# -eq 4 ]; then
615 body=${res:0:${#res}-3}
616 targetJson="{\"operationalState\": \"$4\"}"
617 echo " TARGET JSON: $targetJson" >> $HTTPLOG
618 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
619
620 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100621 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100622 return 1
623 fi
624 fi
625 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100626 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100627 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
628 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100629 return 1
630 fi
631
632 query="/A1-EI/v1/eijobs/$2/status"
633
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100634 start=$SECONDS
635 for (( ; ; )); do
636 res="$(__do_curl_to_api ECS GET $query)"
637 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100638
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100639 if [ $# -eq 4 ]; then
640 duration=$((SECONDS-start))
641 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
642 if [ $duration -gt $4 ]; then
643 echo ""
644 duration=-1 #Last iteration
645 fi
646 else
647 duration=-1 #single test, no wait
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100648 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100649
650 if [ $status -ne $1 ]; then
651 if [ $duration -eq -1 ]; then
652 __log_test_fail_status_code $1 $status
653 return 1
654 fi
655 fi
656 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
657 body=${res:0:${#res}-3}
658 targetJson="{\"eiJobStatus\": \"$3\"}"
659 echo " TARGET JSON: $targetJson" >> $HTTPLOG
660 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
661
662 if [ $res -ne 0 ]; then
663 if [ $duration -eq -1 ]; then
664 __log_test_fail_body
665 return 1
666 fi
667 else
668 duration=-1 #Goto pass
669 fi
670 fi
671 if [ $duration -eq -1 ]; then
672 if [ $# -eq 4 ]; then
673 echo ""
674 fi
675 __log_test_pass
676 return 0
677 else
678 sleep 1
679 fi
680 done
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200681 fi
682
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100683 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200684 return 0
685}
686
687# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200688# args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100689# args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200690# (Function for test scripts)
691ecs_api_a1_get_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100692 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200693
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100694 if [ -z "$FLAT_A1_EI" ]; then
695 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
696 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
697 return 1
698 fi
699 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
700 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100701 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100702 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
703 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
704 return 1
705 fi
706 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200707 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200708 res="$(__do_curl_to_api ECS GET $query)"
709 status=${res:${#res}-3}
710
711 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100712 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200713 return 1
714 fi
715
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100716 if [ -z "$FLAT_A1_EI" ]; then
717 if [ $# -eq 6 ]; then
718 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200719
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100720 if [ -f $6 ]; then
721 jobfile=$(cat $6)
722 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
723 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100724 _log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100725 return 1
726 fi
727 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
728 echo " TARGET JSON: $targetJson" >> $HTTPLOG
729 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
730
731 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100732 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100733 return 1
734 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200735 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100736 else
737 if [ $# -eq 7 ]; then
738 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200739
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100740 if [ -f $7 ]; then
741 jobfile=$(cat $7)
742 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
743 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100744 _log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100745 return 1
746 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100747 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100748 echo " TARGET JSON: $targetJson" >> $HTTPLOG
749 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
750
751 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100752 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100753 return 1
754 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200755 fi
756 fi
757
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100758 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200759 return 0
760}
761
762# API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200763# args: <response-code> <type-id> <job-id>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100764# args (flat uri structure): <response-code> <job-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200765# (Function for test scripts)
766ecs_api_a1_delete_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100767 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200768
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100769 if [ -z "$FLAT_A1_EI" ]; then
770 if [ $# -ne 3 ]; then
771 __print_err "<response-code> <type-id> <job-id>" $@
772 return 1
773 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200774
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100775 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
776 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100777 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100778 if [ $# -ne 2 ]; then
779 __print_err "<response-code> <job-id>" $@
780 return 1
781 fi
782 query="/A1-EI/v1/eijobs/$2"
783 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200784 res="$(__do_curl_to_api ECS DELETE $query)"
785 status=${res:${#res}-3}
786
787 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100788 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200789 return 1
790 fi
791
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100792 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200793 return 0
794}
795
796# API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200797# args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100798# 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 +0200799# (Function for test scripts)
800ecs_api_a1_put_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100801 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200802
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100803 if [ -z "$FLAT_A1_EI" ]; then
804 if [ $# -lt 6 ]; then
805 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
806 return 1
807 fi
808 if [ -f $6 ]; then
809 jobfile=$(cat $6)
810 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
811 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100812 _log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100813 return 1
814 fi
815
816 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
817 file="./tmp/.p.json"
818 echo "$inputJson" > $file
819
820 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200821 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100822 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100823 if [ $# -lt 7 ]; then
824 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
825 return 1
826 fi
827 if [ -f $7 ]; then
828 jobfile=$(cat $7)
829 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
830 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100831 _log_test_fail_general "Job template file "$7", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100832 return 1
833 fi
834
835 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
836 file="./tmp/.p.json"
837 echo "$inputJson" > $file
838
839 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200840 fi
841
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200842 res="$(__do_curl_to_api ECS PUT $query $file)"
843 status=${res:${#res}-3}
844
845 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100846 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200847 return 1
848 fi
849
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100850 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200851 return 0
852}
853
854
855##########################################
856#### Enrichment Data Producer API ####
857##########################################
858# Function prefix: ecs_api_edp
859
860# API Test function: GET /ei-producer/v1/eitypes
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200861# args: <response-code> [ EMPTY | <type-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200862# (Function for test scripts)
863ecs_api_edp_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100864 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200865
866 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200867 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200868 return 1
869 fi
870
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200871 query="/ei-producer/v1/eitypes"
872 res="$(__do_curl_to_api ECS GET $query)"
873 status=${res:${#res}-3}
874
875 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100876 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200877 return 1
878 fi
879
880 if [ $# -gt 1 ]; then
881 body=${res:0:${#res}-3}
882 targetJson="["
883 if [ $2 != "EMPTY" ]; then
884 for pid in ${@:2} ; do
885 if [ "$targetJson" != "[" ]; then
886 targetJson=$targetJson","
887 fi
888 targetJson=$targetJson"\"$pid\""
889 done
890 fi
891 targetJson=$targetJson"]"
892 echo " TARGET JSON: $targetJson" >> $HTTPLOG
893 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
894
895 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100896 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200897 return 1
898 fi
899 fi
900
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100901 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200902 return 0
903}
904
905# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100906# args: <response-code> <producer-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200907# (Function for test scripts)
908ecs_api_edp_get_producer_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100909 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200910
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100911 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
912 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200913 return 1
914 fi
915
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200916 query="/ei-producer/v1/eiproducers/$2/status"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100917 start=$SECONDS
918 for (( ; ; )); do
919 res="$(__do_curl_to_api ECS GET $query)"
920 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200921
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100922 if [ $# -eq 4 ]; then
923 duration=$((SECONDS-start))
924 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
925 if [ $duration -gt $4 ]; then
926 echo ""
927 duration=-1 #Last iteration
928 fi
929 else
930 duration=-1 #single test, no wait
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200931 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200932
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100933 if [ $status -ne $1 ]; then
934 if [ $duration -eq -1 ]; then
935 __log_test_fail_status_code $1 $status
936 return 1
937 fi
938 fi
939 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
940 body=${res:0:${#res}-3}
941 targetJson="{\"operational_state\": \"$3\"}"
942 echo " TARGET JSON: $targetJson" >> $HTTPLOG
943 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
944
945 if [ $res -ne 0 ]; then
946 if [ $duration -eq -1 ]; then
947 __log_test_fail_body
948 return 1
949 fi
950 else
951 duration=-1 #Goto pass
952 fi
953 fi
954 if [ $duration -eq -1 ]; then
955 if [ $# -eq 4 ]; then
956 echo ""
957 fi
958 __log_test_pass
959 return 0
960 else
961 sleep 1
962 fi
963 done
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200964}
965
966
967# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100968# args (v1_1): <response-code> [ EMPTY | <producer-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200969# (Function for test scripts)
970ecs_api_edp_get_producer_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100971 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200972
973 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200974 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200975 return 1
976 fi
977
978 query="/ei-producer/v1/eiproducers"
979 res="$(__do_curl_to_api ECS GET $query)"
980 status=${res:${#res}-3}
981
982 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100983 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200984 return 1
985 fi
986
987 if [ $# -gt 1 ]; then
988 body=${res:0:${#res}-3}
989 targetJson="["
990
991 for pid in ${@:2} ; do
992 if [ "$targetJson" != "[" ]; then
993 targetJson=$targetJson","
994 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200995 if [ $pid != "EMPTY" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200996 targetJson=$targetJson"\"$pid\""
997 fi
998 done
999
1000 targetJson=$targetJson"]"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001001 echo " TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001002 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1003
1004 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001005 __log_test_fail_body
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001006 return 1
1007 fi
1008 fi
1009
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001010 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001011 return 0
1012}
1013
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001014# API Test function: GET /ei-producer/v1/eiproducers
1015# args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1016# (Function for test scripts)
1017ecs_api_edp_get_producer_ids_2() {
1018 __log_test_start $@
1019
1020 if [ $# -lt 1 ]; then
1021 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1022 return 1
1023 fi
1024
1025 query="/ei-producer/v1/eiproducers"
1026 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1027 query=$query"?ei_type_id=$2"
1028 fi
1029 res="$(__do_curl_to_api ECS GET $query)"
1030 status=${res:${#res}-3}
1031
1032 if [ $status -ne $1 ]; then
1033 __log_test_fail_status_code $1 $status
1034 return 1
1035 fi
1036
1037 if [ $# -gt 2 ]; then
1038 body=${res:0:${#res}-3}
1039 targetJson="["
1040
1041 for pid in ${@:3} ; do
1042 if [ "$targetJson" != "[" ]; then
1043 targetJson=$targetJson","
1044 fi
1045 if [ $pid != "EMPTY" ]; then
1046 targetJson=$targetJson"\"$pid\""
1047 fi
1048 done
1049
1050 targetJson=$targetJson"]"
1051 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1052 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1053
1054 if [ $res -ne 0 ]; then
1055 __log_test_fail_body
1056 return 1
1057 fi
1058 fi
1059
1060 __log_test_pass
1061 return 0
1062}
1063
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001064# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001065# args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001066# (Function for test scripts)
1067ecs_api_edp_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001068 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001069
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001070 paramError=1
1071 if [ $# -eq 2 ]; then
1072 paramError=0
1073 fi
1074 if [ $# -gt 3 ]; then
1075 paramError=0
1076 fi
1077 if [ $paramError -ne 0 ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02001078 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001079 return 1
1080 fi
1081
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001082 query="/ei-producer/v1/eitypes/$2"
1083 res="$(__do_curl_to_api ECS GET $query)"
1084 status=${res:${#res}-3}
1085
1086 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001087 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001088 return 1
1089 fi
1090 if [ $# -gt 3 ]; then
1091 body=${res:0:${#res}-3}
1092
1093 if [ -f $3 ]; then
1094 schema=$(cat $3)
1095 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001096 __log_test_fail_general "Job template file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001097 return 1
1098 fi
1099
1100 targetJson=""
1101 if [ $4 != "EMPTY" ]; then
1102 for pid in ${@:4} ; do
1103 if [ "$targetJson" != "" ]; then
1104 targetJson=$targetJson","
1105 fi
1106 targetJson=$targetJson"\"$pid\""
1107 done
1108 fi
1109 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1110
1111 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1112 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1113
1114 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001115 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001116 return 1
1117 fi
1118 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001119 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001120 return 0
1121}
1122
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001123# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1124# args: (v1_2) <response-code> <type-id> [<job-schema-file> ]
1125# (Function for test scripts)
1126ecs_api_edp_get_type_2() {
1127 __log_test_start $@
1128
1129 paramError=1
1130 if [ $# -eq 2 ]; then
1131 paramError=0
1132 fi
1133 if [ $# -eq 3 ]; then
1134 paramError=0
1135 fi
1136 if [ $paramError -ne 0 ]; then
1137 __print_err "<response-code> <type-id> [<job-schema-file> ]" $@
1138 return 1
1139 fi
1140
1141 query="/ei-producer/v1/eitypes/$2"
1142 res="$(__do_curl_to_api ECS GET $query)"
1143 status=${res:${#res}-3}
1144
1145 if [ $status -ne $1 ]; then
1146 __log_test_fail_status_code $1 $status
1147 return 1
1148 fi
1149 if [ $# -eq 3 ]; then
1150 body=${res:0:${#res}-3}
1151
1152 if [ -f $3 ]; then
1153 schema=$(cat $3)
1154 else
1155 __log_test_fail_general "Job template file "$3", does not exist"
1156 return 1
1157 fi
1158
1159 targetJson="{\"ei_job_data_schema\":$schema}"
1160
1161 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1162 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1163
1164 if [ $res -ne 0 ]; then
1165 __log_test_fail_body
1166 return 1
1167 fi
1168 fi
1169 __log_test_pass
1170 return 0
1171}
1172
1173# API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1174# args: (v1_2) <response-code> <type-id> <job-schema-file>
1175# (Function for test scripts)
1176ecs_api_edp_put_type_2() {
1177 __log_test_start $@
1178
1179 if [ $# -ne 3 ]; then
1180 __print_err "<response-code> <type-id> <job-schema-file>" $@
1181 return 1
1182 fi
1183
1184 if [ ! -f $3 ]; then
1185 __log_test_fail_general "Job schema file "$3", does not exist"
1186 return 1
1187 fi
1188 schema=$(cat $3)
1189 input_json="{\"ei_job_data_schema\":$schema}"
1190 file="./tmp/put_type.json"
1191 echo $input_json > $file
1192
1193 query="/ei-producer/v1/eitypes/$2"
1194 res="$(__do_curl_to_api ECS PUT $query $file)"
1195 status=${res:${#res}-3}
1196
1197 if [ $status -ne $1 ]; then
1198 __log_test_fail_status_code $1 $status
1199 return 1
1200 fi
1201
1202 __log_test_pass
1203 return 0
1204}
1205
1206# API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1207# args: (v1_2) <response-code> <type-id>
1208# (Function for test scripts)
1209ecs_api_edp_delete_type_2() {
1210 __log_test_start $@
1211
1212 if [ $# -ne 2 ]; then
1213 __print_err "<response-code> <type-id>" $@
1214 return 1
1215 fi
1216
1217 query="/ei-producer/v1/eitypes/$2"
1218 res="$(__do_curl_to_api ECS DELETE $query)"
1219 status=${res:${#res}-3}
1220
1221 if [ $status -ne $1 ]; then
1222 __log_test_fail_status_code $1 $status
1223 return 1
1224 fi
1225
1226 __log_test_pass
1227 return 0
1228}
1229
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001230# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001231# args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001232# (Function for test scripts)
1233ecs_api_edp_get_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001234 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001235
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001236 #Possible arg count: 2, 5 6, 8, 10 etc
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001237 paramError=1
1238 if [ $# -eq 2 ]; then
1239 paramError=0
1240 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001241 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001242 paramError=0
1243 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001244 variablecount=$(($#-4))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001245 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1246 paramError=0
1247 fi
1248
1249 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001250 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001251 return 1
1252 fi
1253
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001254 query="/ei-producer/v1/eiproducers/$2"
1255 res="$(__do_curl_to_api ECS GET $query)"
1256 status=${res:${#res}-3}
1257
1258 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001259 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001260 return 1
1261 fi
1262
1263 if [ $# -gt 2 ]; then
1264 body=${res:0:${#res}-3}
1265 targetJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001266 if [ $# -gt 5 ]; then
1267 arr=(${@:5})
1268 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001269 if [ "$targetJson" != "[" ]; then
1270 targetJson=$targetJson","
1271 fi
1272 if [ -f ${arr[$i+1]} ]; then
1273 schema=$(cat ${arr[$i+1]})
1274 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001275 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001276 return 1
1277 fi
1278
1279 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1280 done
1281 fi
1282 targetJson=$targetJson"]"
1283 if [ $# -gt 4 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001284 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001285 fi
1286 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1287 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1288
1289 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001290 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001291 return 1
1292 fi
1293 fi
1294
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001295 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001296 return 0
1297}
1298
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001299# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1300# args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1301# (Function for test scripts)
1302ecs_api_edp_get_producer_2() {
1303 __log_test_start $@
1304
1305 #Possible arg count: 2, 5, 6, 7, 8 etc
1306 paramError=1
1307 if [ $# -eq 2 ]; then
1308 paramError=0
1309 fi
1310 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1311 paramError=0
1312 fi
1313 if [ $# -ge 5 ]; then
1314 paramError=0
1315 fi
1316
1317 if [ $paramError -ne 0 ]; then
1318 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1319 return 1
1320 fi
1321
1322 query="/ei-producer/v1/eiproducers/$2"
1323 res="$(__do_curl_to_api ECS GET $query)"
1324 status=${res:${#res}-3}
1325
1326 if [ $status -ne $1 ]; then
1327 __log_test_fail_status_code $1 $status
1328 return 1
1329 fi
1330
1331 if [ $# -gt 2 ]; then
1332 body=${res:0:${#res}-3}
1333 targetJson="["
1334 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1335 arr=(${@:5})
1336 for ((i=0; i<$(($#-4)); i=i+1)); do
1337 if [ "$targetJson" != "[" ]; then
1338 targetJson=$targetJson","
1339 fi
1340 targetJson=$targetJson"\"${arr[$i]}\""
1341 done
1342 fi
1343 targetJson=$targetJson"]"
1344 if [ $# -gt 4 ]; then
1345 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1346 fi
1347 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1348 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1349
1350 if [ $res -ne 0 ]; then
1351 __log_test_fail_body
1352 return 1
1353 fi
1354 fi
1355
1356 __log_test_pass
1357 return 0
1358}
1359
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001360# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001361# args: <response-code> <producer-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001362# (Function for test scripts)
1363ecs_api_edp_delete_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001364 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001365
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001366 if [ $# -lt 2 ]; then
1367 __print_err "<response-code> <producer-id>" $@
1368 return 1
1369 fi
1370
1371 query="/ei-producer/v1/eiproducers/$2"
1372 res="$(__do_curl_to_api ECS DELETE $query)"
1373 status=${res:${#res}-3}
1374
1375 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001376 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001377 return 1
1378 fi
1379
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001380 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001381 return 0
1382}
1383
1384# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001385# args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001386# (Function for test scripts)
1387ecs_api_edp_put_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001388 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001389
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001390 #Valid number of parametrer 5,6,8,10,
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001391 paramError=1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001392 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001393 paramError=0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001394 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001395 paramError=0
1396 fi
1397 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001398 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001399 return 1
1400 fi
1401
1402 inputJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001403 if [ $# -gt 5 ]; then
1404 arr=(${@:5})
1405 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001406 if [ "$inputJson" != "[" ]; then
1407 inputJson=$inputJson","
1408 fi
1409 if [ -f ${arr[$i+1]} ]; then
1410 schema=$(cat ${arr[$i+1]})
1411 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001412 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001413 return 1
1414 fi
1415 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1416 done
1417 fi
1418 inputJson="\"supported_ei_types\":"$inputJson"]"
1419
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001420 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001421
1422 inputJson="{"$inputJson"}"
1423
1424 file="./tmp/.p.json"
1425 echo "$inputJson" > $file
1426 query="/ei-producer/v1/eiproducers/$2"
1427 res="$(__do_curl_to_api ECS PUT $query $file)"
1428 status=${res:${#res}-3}
1429
1430 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001431 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001432 return 1
1433 fi
1434
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001435 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001436 return 0
1437}
1438
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001439# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1440# args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1441# (Function for test scripts)
1442ecs_api_edp_put_producer_2() {
1443 __log_test_start $@
1444
1445 #Valid number of parametrer 5,6,8,10,
1446 paramError=1
1447 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1448 paramError=0
1449 elif [ $# -ge 5 ]; then
1450 paramError=0
1451 fi
1452 if [ $paramError -ne 0 ]; then
1453 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1454 return 1
1455 fi
1456
1457 inputJson="["
1458 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1459 arr=(${@:5})
1460 for ((i=0; i<$(($#-4)); i=i+1)); do
1461 if [ "$inputJson" != "[" ]; then
1462 inputJson=$inputJson","
1463 fi
1464 inputJson=$inputJson"\""${arr[$i]}"\""
1465 done
1466 fi
1467 inputJson="\"supported_ei_types\":"$inputJson"]"
1468
1469 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1470
1471 inputJson="{"$inputJson"}"
1472
1473 file="./tmp/.p.json"
1474 echo "$inputJson" > $file
1475 query="/ei-producer/v1/eiproducers/$2"
1476 res="$(__do_curl_to_api ECS PUT $query $file)"
1477 status=${res:${#res}-3}
1478
1479 if [ $status -ne $1 ]; then
1480 __log_test_fail_status_code $1 $status
1481 return 1
1482 fi
1483
1484 __log_test_pass
1485 return 0
1486}
1487
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001488# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001489# 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 +02001490# (Function for test scripts)
1491ecs_api_edp_get_producer_jobs() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001492 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001493
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001494 #Valid number of parameter 2,3,7,11
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001495 paramError=1
1496 if [ $# -eq 2 ]; then
1497 paramError=0
1498 fi
1499 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1500 paramError=0
1501 fi
1502 variablecount=$(($#-2))
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001503 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001504 paramError=0
1505 fi
1506 if [ $paramError -eq 1 ]; then
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001507 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001508 return 1
1509 fi
1510
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001511 query="/ei-producer/v1/eiproducers/$2/eijobs"
1512 res="$(__do_curl_to_api ECS GET $query)"
1513 status=${res:${#res}-3}
1514 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001515 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001516 return 1
1517 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001518 if [ $# -gt 2 ]; then
1519 body=${res:0:${#res}-3}
1520 targetJson="["
1521 if [ $# -gt 3 ]; then
1522 arr=(${@:3})
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001523 for ((i=0; i<$(($#-3)); i=i+5)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001524 if [ "$targetJson" != "[" ]; then
1525 targetJson=$targetJson","
1526 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001527 if [ -f ${arr[$i+4]} ]; then
1528 jobfile=$(cat ${arr[$i+4]})
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001529 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1530 else
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001531 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001532 return 1
1533 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001534 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 +02001535 done
1536 fi
1537 targetJson=$targetJson"]"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001538
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001539 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1540 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001541
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001542 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001543 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001544 return 1
1545 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001546 fi
1547
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001548 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001549 return 0
1550}
1551
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001552# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1553# args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1554# (Function for test scripts)
1555ecs_api_edp_get_producer_jobs_2() {
1556 __log_test_start $@
1557
1558 #Valid number of parameter 2,3,7,11
1559 paramError=1
1560 if [ $# -eq 2 ]; then
1561 paramError=0
1562 fi
1563 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1564 paramError=0
1565 fi
1566 variablecount=$(($#-2))
1567 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1568 paramError=0
1569 fi
1570 if [ $paramError -eq 1 ]; then
1571 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1572 return 1
1573 fi
1574
1575 query="/ei-producer/v1/eiproducers/$2/eijobs"
1576 res="$(__do_curl_to_api ECS GET $query)"
1577 status=${res:${#res}-3}
1578 if [ $status -ne $1 ]; then
1579 __log_test_fail_status_code $1 $status
1580 return 1
1581 fi
1582 if [ $# -gt 2 ]; then
1583 body=${res:0:${#res}-3}
1584 targetJson="["
1585 if [ $# -gt 3 ]; then
1586 arr=(${@:3})
1587 for ((i=0; i<$(($#-3)); i=i+5)); do
1588 if [ "$targetJson" != "[" ]; then
1589 targetJson=$targetJson","
1590 fi
1591 if [ -f ${arr[$i+4]} ]; then
1592 jobfile=$(cat ${arr[$i+4]})
1593 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1594 else
1595 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1596 return 1
1597 fi
1598 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\":\"????\"}"
1599 done
1600 fi
1601 targetJson=$targetJson"]"
1602
1603 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1604 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1605
1606 if [ $res -ne 0 ]; then
1607 __log_test_fail_body
1608 return 1
1609 fi
1610 fi
1611
1612 __log_test_pass
1613 return 0
1614}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001615
1616##########################################
1617#### Service status ####
1618##########################################
1619# Function prefix: ecs_api_service
1620
1621# API Test function: GET ​/status
1622# args: <response-code>
1623# (Function for test scripts)
1624ecs_api_service_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001625 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001626
1627 if [ $# -lt 1 ]; then
1628 __print_err "<response-code> [<producer-id>]*|NOID" $@
1629 return 1
1630 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001631 res="$(__do_curl_to_api ECS GET /status)"
1632 status=${res:${#res}-3}
1633 if [ $status -ne $1 ]; then
1634 __log_test_fail_status_code $1 $status
1635 return 1
1636 fi
1637 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001638 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001639}
1640
1641
1642##########################################
1643#### Reset jobs ####
1644##########################################
1645# Function prefix: ecs_api_admin
1646
1647# Admin to remove all jobs
BjornMagnussonXA366e36a2021-01-27 11:48:56 +01001648# args: <response-code> [ <type> ]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001649# (Function for test scripts)
1650
1651ecs_api_admin_reset() {
1652 __log_test_start $@
1653
1654 if [ -z "$FLAT_A1_EI" ]; then
1655 query="/A1-EI/v1/eitypes/$2/eijobs"
1656 else
1657 query="/A1-EI/v1/eijobs"
1658 fi
1659 res="$(__do_curl_to_api ECS GET $query)"
1660 status=${res:${#res}-3}
1661
1662 if [ $status -ne 200 ]; then
1663 __log_test_fail_status_code $1 $status
1664 return 1
1665 fi
1666
1667 #Remove brackets and response code
1668 body=${res:1:${#res}-4}
1669 list=$(echo ${body//,/ })
1670 list=$(echo ${list//[/})
1671 list=$(echo ${list//]/})
1672 list=$(echo ${list//\"/})
1673 list=$list" "
1674 for job in $list; do
1675 if [ -z "$FLAT_A1_EI" ]; then
1676 echo "Not supported for non-flat EI api"
1677 else
1678 query="/A1-EI/v1/eijobs/$job"
1679 res="$(__do_curl_to_api ECS DELETE $query)"
1680 status=${res:${#res}-3}
1681 if [ $status -ne 204 ]; then
1682 __log_test_fail_status_code $1 $status
1683 return 1
1684 fi
1685 echo " Deleted job: "$job
1686 fi
1687 done
1688
1689 __log_test_pass
1690 return 0
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001691}