blob: 9bde835e8c5ed0515138210d84f2b4f15e3d680e [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
BjornMagnussonXAa69cd902021-04-22 23:46:10 +020099#Save first worker node the pod is started on
100__ECS_WORKER_NODE=""
101
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100102###########################
103### ECS functions
104###########################
105
106# All calls to ECS will be directed to the ECS REST interface from now on
107# args: -
108# (Function for test scripts)
109use_ecs_rest_http() {
110 echo -e $BOLD"ECS protocol setting"$EBOLD
111 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
112 ECS_HTTPX="http"
113 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
114
115 ECS_ADAPTER_TYPE="REST"
116 ECS_ADAPTER=$ECS_PATH
117 echo ""
118}
119
120# All calls to ECS will be directed to the ECS REST interface from now on
121# args: -
122# (Function for test scripts)
123use_ecs_rest_https() {
124 echo -e $BOLD"ECS protocol setting"$EBOLD
125 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
126 ECS_HTTPX="https"
127 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
128
129 ECS_ADAPTER_TYPE="REST"
130 ECS_ADAPTER=$ECS_PATH
131 echo ""
132}
133
134# All calls to ECS will be directed to the ECS dmaap interface over http from now on
135# args: -
136# (Function for test scripts)
137use_ecs_dmaap_http() {
138 echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
139 echo -e $RED" - NOT SUPPORTED - "$ERED
140 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
141 ECS_ADAPTER_TYPE="MR-HTTP"
142 echo ""
143}
144
145# All calls to ECS will be directed to the ECS dmaap interface over https from now on
146# args: -
147# (Function for test scripts)
148use_ecs_dmaap_https() {
149 echo -e $BOLD"RICSIM protocol setting"$EBOLD
150 echo -e $RED" - NOT SUPPORTED - "$ERED
151 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
152 ECS_ADAPTER_TYPE="MR-HTTPS"
153 echo ""
154}
155
156# Start the ECS
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100157# args: PROXY|NOPROXY <config-file>
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100158# (Function for test scripts)
159start_ecs() {
160
161 echo -e $BOLD"Starting $ECS_DISPLAY_NAME"$EBOLD
162
163 if [ $RUNMODE == "KUBE" ]; then
164
165 # Check if app shall be fully managed by the test script
166 __check_included_image "ECS"
167 retcode_i=$?
168
169 # Check if app shall only be used by the testscipt
170 __check_prestarted_image "ECS"
171 retcode_p=$?
172
173 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
174 echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
175 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
176 exit
177 fi
178 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
179 echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
180 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
181 exit
182 fi
183
184
185 if [ $retcode_p -eq 0 ]; then
186 echo -e " Using existing $ECS_APP_NAME deployment and service"
187 echo " Setting ECS replicas=1"
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200188 res_type=$(__kube_get_resource_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
189 __kube_scale $res_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100190 fi
191
192 # Check if app shall be fully managed by the test script
193 if [ $retcode_i -eq 0 ]; then
194 echo -e " Creating $ECS_APP_NAME app and expose service"
195
196 #Check if nonrtric namespace exists, if not create it
197 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
198
199 export ECS_APP_NAME
200 export KUBE_NONRTRIC_NAMESPACE
201 export ECS_IMAGE
202 export ECS_INTERNAL_PORT
203 export ECS_INTERNAL_SECURE_PORT
204 export ECS_EXTERNAL_PORT
205 export ECS_EXTERNAL_SECURE_PORT
206 export ECS_CONFIG_MOUNT_PATH
207 export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config"
208 export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data"
209 export ECS_CONTAINER_MNT_DIR
210
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100211 export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv"
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200212 export ECS_DATA_PVC_NAME=$ECS_APP_NAME"-pvc"
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100213 #Create a unique path for the pv each time to prevent a previous volume to be reused
214 export ECS_PV_PATH="ecsdata-"$(date +%s)
215
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100216 if [ $1 == "PROXY" ]; then
217 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
218 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
219 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
220 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
221 else
222 echo " Configured with http proxy"
223 fi
224 else
225 ECS_HTTP_PROXY_CONFIG_PORT=0
226 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
227 echo " Configured without http proxy"
228 fi
229 export ECS_HTTP_PROXY_CONFIG_PORT
230 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
231
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100232 # Create config map for config
233 datafile=$PWD/tmp/$ECS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100234 cp $2 $datafile
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100235 output_yaml=$PWD/tmp/ecs_cfc.yaml
236 __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml
237
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100238 # Create pv
239 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pv.yaml
240 output_yaml=$PWD/tmp/ecs_pv.yaml
241 __kube_create_instance pv $ECS_APP_NAME $input_yaml $output_yaml
242
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100243 # Create pvc
244 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml
245 output_yaml=$PWD/tmp/ecs_pvc.yaml
246 __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml
247
248 # Create service
249 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml
250 output_yaml=$PWD/tmp/ecs_svc.yaml
251 __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml
252
253 # Create app
254 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml
255 output_yaml=$PWD/tmp/ecs_app.yaml
256 __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml
257 fi
258
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200259 # Tie the ECS to a worker node so that ECS will always be scheduled to the same worker node if the ECS pod is restarted
260 # A PVC of type hostPath is mounted to ECS, for persistent storage, so the ECS must always be on the node which mounted the volume
261
262 # Keep the initial worker node in case the pod need to be "restarted" - must be made to the same node due to a volume mounted on the host
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200263 if [ $retcode_i -eq 0 ]; then
264 __ECS_WORKER_NODE=$(kubectl get pod -l "autotest=ECS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
265 if [ -z "$__ECS_WORKER_NODE" ]; then
266 echo -e $YELLOW" Cannot find worker node for pod for $ECS_APP_NAME, persistency may not work"$EYELLOW
267 fi
268 else
269 echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200270 fi
271
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100272 echo " Retrieving host and ports for service..."
273 ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
274 ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
275 ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
276
277 echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT"
278
279 if [ $ECS_HTTPX == "http" ]; then
280 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
281 else
282 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
283 fi
284
285 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
286
287 if [ $ECS_ADAPTER_TYPE == "REST" ]; then
288 ECS_ADAPTER=$ECS_PATH
289 fi
290 else
291 __check_included_image 'ECS'
292 if [ $? -eq 1 ]; then
293 echo -e $RED"The ECS app is not included in this test script"$ERED
294 echo -e $RED"ECS will not be started"$ERED
295 exit 1
296 fi
297
298 curdir=$PWD
299 cd $SIM_GROUP
300 cd ecs
301 cd $ECS_HOST_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100302 #cd ..
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100303 if [ -d db ]; then
304 if [ "$(ls -A $DIR)" ]; then
305 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
306 rm -rf db/* &> /dev/null
307 if [ $? -ne 0 ]; then
308 echo -e $RED" Cannot remove database files in: $PWD"$ERED
309 exit 1
310 fi
311 fi
312 else
313 echo " No files in mounted dir or dir does not exists"
314 fi
315 cd $curdir
316
317 export ECS_APP_NAME
318 export ECS_APP_NAME_ALIAS
319 export ECS_HOST_MNT_DIR
320 export ECS_CONTAINER_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100321 export ECS_CONFIG_MOUNT_PATH
322 export ECS_CONFIG_FILE
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100323 export ECS_INTERNAL_PORT
324 export ECS_EXTERNAL_PORT
325 export ECS_INTERNAL_SECURE_PORT
326 export ECS_EXTERNAL_SECURE_PORT
327 export DOCKER_SIM_NWNAME
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100328 export ECS_DISPLAY_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100329
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100330 if [ $1 == "PROXY" ]; then
331 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
332 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
333 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
334 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
335 else
336 echo " Configured with http proxy"
337 fi
338 else
339 ECS_HTTP_PROXY_CONFIG_PORT=0
340 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
341 echo " Configured without http proxy"
342 fi
343 export ECS_HTTP_PROXY_CONFIG_PORT
344 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
345
346 dest_file=$SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_HOST_MNT_DIR/$ECS_CONFIG_FILE
347
348 envsubst < $2 > $dest_file
349
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100350 __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100351
352 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
353 fi
354 echo ""
355 return 0
356}
357
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200358# Stop the ecs
359# args: -
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100360# args: -
361# (Function for test scripts)
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200362stop_ecs() {
363 echo -e $BOLD"Stopping $ECS_DISPLAY_NAME"$EBOLD
364
365 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200366
367 __check_prestarted_image "ECS"
368 if [ $? -eq 0 ]; then
369 echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200370 res_type=$(__kube_get_resource_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
371 __kube_scale $res_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200372 return 0
373 fi
374
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200375 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
376 echo " Deleting the replica set - a new will be started when the app is started"
377 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ECS")
378 if [ $? -ne 0 ]; then
379 echo -e $RED" Could not delete replica set "$RED
380 ((RES_CONF_FAIL++))
381 return 1
382 fi
383 else
384 docker stop $ECS_APP_NAME &> ./tmp/.dockererr
385 if [ $? -ne 0 ]; then
386 __print_err "Could not stop $ECS_APP_NAME" $@
387 cat ./tmp/.dockererr
388 ((RES_CONF_FAIL++))
389 return 1
390 fi
391 fi
392 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
393 echo ""
394 return 0
395}
396
397# Start a previously stopped ecs
398# args: -
399# (Function for test scripts)
400start_stopped_ecs() {
401 echo -e $BOLD"Starting (the previously stopped) $ECS_DISPLAY_NAME"$EBOLD
402
403 if [ $RUNMODE == "KUBE" ]; then
404
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200405 __check_prestarted_image "ECS"
406 if [ $? -eq 0 ]; then
407 echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200408 res_type=$(__kube_get_resource_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
409 __kube_scale $res_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200410 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
411 return 0
412 fi
413
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200414 # Tie the PMS to the same worker node it was initially started on
415 # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume
416 if [ -z "$__ECS_WORKER_NODE" ]; then
417 echo -e $RED" No initial worker node found for pod "$RED
418 ((RES_CONF_FAIL++))
419 return 1
420 else
421 echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ECS_WORKER_NODE to deployment for $ECS_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD
422 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
423 tmp=$(kubectl patch deployment $ECS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ECS_WORKER_NODE'"}}}}}')
424 if [ $? -ne 0 ]; then
425 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ECS_APP_NAME, persistency may not work"$EYELLOW
426 fi
427 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
428 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200429 else
430 docker start $ECS_APP_NAME &> ./tmp/.dockererr
431 if [ $? -ne 0 ]; then
432 __print_err "Could not start (the stopped) $ECS_APP_NAME" $@
433 cat ./tmp/.dockererr
434 ((RES_CONF_FAIL++))
435 return 1
436 fi
437 fi
438 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100439 if [ $? -ne 0 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100440 return 1
441 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100442 echo ""
443 return 0
444}
445
446# Turn on debug level tracing in ECS
447# args: -
448# (Function for test scripts)
449set_ecs_debug() {
450 echo -e $BOLD"Setting ecs debug logging"$EBOLD
451 curlString="$ECS_PATH$ECS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
452 result=$(__do_curl "$curlString")
453 if [ $? -ne 0 ]; then
454 __print_err "Could not set debug mode" $@
455 ((RES_CONF_FAIL++))
456 return 1
457 fi
458 echo ""
459 return 0
460}
461
462# Turn on trace level tracing in ECS
463# args: -
464# (Function for test scripts)
465set_ecs_trace() {
466 echo -e $BOLD"Setting ecs trace logging"$EBOLD
467 curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
468 result=$(__do_curl "$curlString")
469 if [ $? -ne 0 ]; then
470 __print_err "Could not set trace mode" $@
471 ((RES_CONF_FAIL++))
472 return 1
473 fi
474 echo ""
475 return 0
476}
477
478# Perform curl retries when making direct call to ECS for the specified http response codes
479# Speace separated list of http response codes
480# args: [<response-code>]*
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100481use_ecs_retries() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100482 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100483 ECS_RETRY_CODES=$@
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100484 echo ""
485 return 0
486}
487
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100488# Check the ecs logs for WARNINGs and ERRORs
489# args: -
490# (Function for test scripts)
491check_ecs_logs() {
492 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
493}
494
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200495
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100496# Tests if a variable value in the ECS is equal to a target value and and optional timeout.
497# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
498# equal to the target or not.
499# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
500# before setting pass or fail depending on if the variable value becomes equal to the target
501# value or not.
502# (Function for test scripts)
503ecs_equal() {
504 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100505 __var_test ECS "$ECS_PATH/" $1 "=" $2 $3
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100506 else
507 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
508 fi
509}
510
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200511
512##########################################
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100513######### A1-E Enrichment API ##########
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200514##########################################
515#Function prefix: ecs_api_a1
516
517# API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200518# args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100519# args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200520# (Function for test scripts)
521ecs_api_a1_get_job_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100522 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200523
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100524 if [ -z "$FLAT_A1_EI" ]; then
525 # Valid number of parameters 4,5,6 etc
526 if [ $# -lt 3 ]; then
527 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
528 return 1
529 fi
530 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100531 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100532 # Valid number of parameters 4,5,6 etc
533 if [ $# -lt 3 ]; then
534 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
535 return 1
536 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200537 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100538 search=""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200539 if [ $3 != "NOWNER" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100540 search="?owner="$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200541 fi
542
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100543 if [ -z "$FLAT_A1_EI" ]; then
544 query="/A1-EI/v1/eitypes/$2/eijobs$search"
545 else
546 if [ $2 != "NOTYPE" ]; then
547 if [ -z "$search" ]; then
548 search="?eiTypeId="$2
549 else
550 search=$search"&eiTypeId="$2
551 fi
552 fi
553 query="/A1-EI/v1/eijobs$search"
554 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200555 res="$(__do_curl_to_api ECS GET $query)"
556 status=${res:${#res}-3}
557
558 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100559 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200560 return 1
561 fi
562
563 if [ $# -gt 3 ]; then
564 body=${res:0:${#res}-3}
565 targetJson="["
566
567 for pid in ${@:4} ; do
568 if [ "$targetJson" != "[" ]; then
569 targetJson=$targetJson","
570 fi
571 if [ $pid != "EMPTY" ]; then
572 targetJson=$targetJson"\"$pid\""
573 fi
574 done
575
576 targetJson=$targetJson"]"
577 echo " TARGET JSON: $targetJson" >> $HTTPLOG
578 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
579
580 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100581 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200582 return 1
583 fi
584 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200585
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100586 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200587 return 0
588}
589
590# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200591# args: <response-code> <type-id> [<schema-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200592# (Function for test scripts)
593ecs_api_a1_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100594 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200595
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200596 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
597 __print_err "<response-code> <type-id> [<schema-file>]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200598 return 1
599 fi
600
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200601 query="/A1-EI/v1/eitypes/$2"
602 res="$(__do_curl_to_api ECS GET $query)"
603 status=${res:${#res}-3}
604
605 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100606 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200607 return 1
608 fi
609
610 if [ $# -eq 3 ]; then
611 body=${res:0:${#res}-3}
612 if [ -f $3 ]; then
613 schema=$(cat $3)
614 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100615 __log_test_fail_general "Schema file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200616 return 1
617 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100618 if [ -z "$FLAT_A1_EI" ]; then
619 targetJson="{\"eiJobParametersSchema\":$schema}"
620 else
621 targetJson=$schema
622 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200623 echo " TARGET JSON: $targetJson" >> $HTTPLOG
624 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
625
626 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100627 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200628 return 1
629 fi
630 fi
631
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100632 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200633 return 0
634}
635
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200636# API Test function: GET /A1-EI/v1/eitypes
637# args: <response-code> [ (EMPTY | [<type-id>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200638# (Function for test scripts)
639ecs_api_a1_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100640 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200641
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200642 if [ $# -lt 1 ]; then
643 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200644 return 1
645 fi
646
647 query="/A1-EI/v1/eitypes"
648 res="$(__do_curl_to_api ECS GET $query)"
649 status=${res:${#res}-3}
650
651 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100652 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200653 return 1
654 fi
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200655 if [ $# -gt 1 ]; then
656 body=${res:0:${#res}-3}
657 targetJson="["
658 if [ $2 != "EMPTY" ]; then
659 for pid in ${@:2} ; do
660 if [ "$targetJson" != "[" ]; then
661 targetJson=$targetJson","
662 fi
663 targetJson=$targetJson"\"$pid\""
664 done
665 fi
666 targetJson=$targetJson"]"
667 echo " TARGET JSON: $targetJson" >> $HTTPLOG
668 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200669
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200670 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100671 __log_test_fail_body
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200672 return 1
673 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200674 fi
675
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100676 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200677 return 0
678}
679
680# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200681# args: <response-code> <type-id> <job-id> [<status>]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100682# args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200683# (Function for test scripts)
684ecs_api_a1_get_job_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100685 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200686
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100687 if [ -z "$FLAT_A1_EI" ]; then
688 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
689 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
690 return 1
691 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200692
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100693 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200694
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100695 res="$(__do_curl_to_api ECS GET $query)"
696 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200697
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100698 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100699 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200700 return 1
701 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100702 if [ $# -eq 4 ]; then
703 body=${res:0:${#res}-3}
704 targetJson="{\"operationalState\": \"$4\"}"
705 echo " TARGET JSON: $targetJson" >> $HTTPLOG
706 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
707
708 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100709 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100710 return 1
711 fi
712 fi
713 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100714 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100715 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
716 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100717 return 1
718 fi
719
720 query="/A1-EI/v1/eijobs/$2/status"
721
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100722 start=$SECONDS
723 for (( ; ; )); do
724 res="$(__do_curl_to_api ECS GET $query)"
725 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100726
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100727 if [ $# -eq 4 ]; then
728 duration=$((SECONDS-start))
729 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
730 if [ $duration -gt $4 ]; then
731 echo ""
732 duration=-1 #Last iteration
733 fi
734 else
735 duration=-1 #single test, no wait
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100736 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100737
738 if [ $status -ne $1 ]; then
739 if [ $duration -eq -1 ]; then
740 __log_test_fail_status_code $1 $status
741 return 1
742 fi
743 fi
744 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
745 body=${res:0:${#res}-3}
746 targetJson="{\"eiJobStatus\": \"$3\"}"
747 echo " TARGET JSON: $targetJson" >> $HTTPLOG
748 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
749
750 if [ $res -ne 0 ]; then
751 if [ $duration -eq -1 ]; then
752 __log_test_fail_body
753 return 1
754 fi
755 else
756 duration=-1 #Goto pass
757 fi
758 fi
759 if [ $duration -eq -1 ]; then
760 if [ $# -eq 4 ]; then
761 echo ""
762 fi
763 __log_test_pass
764 return 0
765 else
766 sleep 1
767 fi
768 done
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200769 fi
770
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100771 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200772 return 0
773}
774
775# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200776# args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100777# args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200778# (Function for test scripts)
779ecs_api_a1_get_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100780 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200781
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100782 if [ -z "$FLAT_A1_EI" ]; then
783 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
784 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
785 return 1
786 fi
787 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
788 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100789 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100790 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
791 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
792 return 1
793 fi
794 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200795 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200796 res="$(__do_curl_to_api ECS GET $query)"
797 status=${res:${#res}-3}
798
799 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100800 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200801 return 1
802 fi
803
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100804 if [ -z "$FLAT_A1_EI" ]; then
805 if [ $# -eq 6 ]; then
806 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200807
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100808 if [ -f $6 ]; then
809 jobfile=$(cat $6)
810 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
811 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200812 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100813 return 1
814 fi
815 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
816 echo " TARGET JSON: $targetJson" >> $HTTPLOG
817 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
818
819 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100820 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100821 return 1
822 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200823 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100824 else
825 if [ $# -eq 7 ]; then
826 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200827
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100828 if [ -f $7 ]; then
829 jobfile=$(cat $7)
830 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
831 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200832 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100833 return 1
834 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100835 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100836 echo " TARGET JSON: $targetJson" >> $HTTPLOG
837 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
838
839 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100840 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100841 return 1
842 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200843 fi
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# API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200851# args: <response-code> <type-id> <job-id>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100852# args (flat uri structure): <response-code> <job-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200853# (Function for test scripts)
854ecs_api_a1_delete_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100855 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200856
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100857 if [ -z "$FLAT_A1_EI" ]; then
858 if [ $# -ne 3 ]; then
859 __print_err "<response-code> <type-id> <job-id>" $@
860 return 1
861 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200862
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100863 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
864 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100865 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100866 if [ $# -ne 2 ]; then
867 __print_err "<response-code> <job-id>" $@
868 return 1
869 fi
870 query="/A1-EI/v1/eijobs/$2"
871 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200872 res="$(__do_curl_to_api ECS DELETE $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
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200877 return 1
878 fi
879
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100880 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200881 return 0
882}
883
884# API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200885# args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100886# 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 +0200887# (Function for test scripts)
888ecs_api_a1_put_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100889 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200890
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100891 if [ -z "$FLAT_A1_EI" ]; then
892 if [ $# -lt 6 ]; then
893 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
894 return 1
895 fi
896 if [ -f $6 ]; then
897 jobfile=$(cat $6)
898 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
899 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200900 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100901 return 1
902 fi
903
904 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
905 file="./tmp/.p.json"
906 echo "$inputJson" > $file
907
908 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200909 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100910 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100911 if [ $# -lt 7 ]; then
912 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
913 return 1
914 fi
915 if [ -f $7 ]; then
916 jobfile=$(cat $7)
917 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
918 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200919 __log_test_fail_general "Job template file "$7", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100920 return 1
921 fi
922
923 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
924 file="./tmp/.p.json"
925 echo "$inputJson" > $file
926
927 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200928 fi
929
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200930 res="$(__do_curl_to_api ECS PUT $query $file)"
931 status=${res:${#res}-3}
932
933 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100934 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200935 return 1
936 fi
937
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100938 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200939 return 0
940}
941
942
943##########################################
944#### Enrichment Data Producer API ####
945##########################################
946# Function prefix: ecs_api_edp
947
948# API Test function: GET /ei-producer/v1/eitypes
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200949# API Test function: GET /data-producer/v1/info-types
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200950# args: <response-code> [ EMPTY | <type-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200951# (Function for test scripts)
952ecs_api_edp_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100953 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200954
955 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200956 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200957 return 1
958 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200959 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
960 query="/data-producer/v1/info-types"
961 else
962 query="/ei-producer/v1/eitypes"
963 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200964 res="$(__do_curl_to_api ECS GET $query)"
965 status=${res:${#res}-3}
966
967 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100968 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200969 return 1
970 fi
971
972 if [ $# -gt 1 ]; then
973 body=${res:0:${#res}-3}
974 targetJson="["
975 if [ $2 != "EMPTY" ]; then
976 for pid in ${@:2} ; do
977 if [ "$targetJson" != "[" ]; then
978 targetJson=$targetJson","
979 fi
980 targetJson=$targetJson"\"$pid\""
981 done
982 fi
983 targetJson=$targetJson"]"
984 echo " TARGET JSON: $targetJson" >> $HTTPLOG
985 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
986
987 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100988 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200989 return 1
990 fi
991 fi
992
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100993 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200994 return 0
995}
996
997# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200998# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100999# args: <response-code> <producer-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001000# (Function for test scripts)
1001ecs_api_edp_get_producer_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001002 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001003
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001004 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
1005 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001006 return 1
1007 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001008 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1009 query="/data-producer/v1/info-producers/$2/status"
1010 else
1011 query="/ei-producer/v1/eiproducers/$2/status"
1012 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001013 start=$SECONDS
1014 for (( ; ; )); do
1015 res="$(__do_curl_to_api ECS GET $query)"
1016 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001017
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001018 if [ $# -eq 4 ]; then
1019 duration=$((SECONDS-start))
1020 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
1021 if [ $duration -gt $4 ]; then
1022 echo ""
1023 duration=-1 #Last iteration
1024 fi
1025 else
1026 duration=-1 #single test, no wait
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001027 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001028
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001029 if [ $status -ne $1 ]; then
1030 if [ $duration -eq -1 ]; then
1031 __log_test_fail_status_code $1 $status
1032 return 1
1033 fi
1034 fi
1035 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1036 body=${res:0:${#res}-3}
1037 targetJson="{\"operational_state\": \"$3\"}"
1038 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1039 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1040
1041 if [ $res -ne 0 ]; then
1042 if [ $duration -eq -1 ]; then
1043 __log_test_fail_body
1044 return 1
1045 fi
1046 else
1047 duration=-1 #Goto pass
1048 fi
1049 fi
1050 if [ $duration -eq -1 ]; then
1051 if [ $# -eq 4 ]; then
1052 echo ""
1053 fi
1054 __log_test_pass
1055 return 0
1056 else
1057 sleep 1
1058 fi
1059 done
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001060}
1061
1062
1063# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001064# args (v1_1): <response-code> [ EMPTY | <producer-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001065# (Function for test scripts)
1066ecs_api_edp_get_producer_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001067 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001068
1069 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001070 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001071 return 1
1072 fi
1073
1074 query="/ei-producer/v1/eiproducers"
1075 res="$(__do_curl_to_api ECS GET $query)"
1076 status=${res:${#res}-3}
1077
1078 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001079 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001080 return 1
1081 fi
1082
1083 if [ $# -gt 1 ]; then
1084 body=${res:0:${#res}-3}
1085 targetJson="["
1086
1087 for pid in ${@:2} ; do
1088 if [ "$targetJson" != "[" ]; then
1089 targetJson=$targetJson","
1090 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001091 if [ $pid != "EMPTY" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001092 targetJson=$targetJson"\"$pid\""
1093 fi
1094 done
1095
1096 targetJson=$targetJson"]"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001097 echo " TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001098 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1099
1100 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001101 __log_test_fail_body
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001102 return 1
1103 fi
1104 fi
1105
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001106 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001107 return 0
1108}
1109
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001110# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001111# API Test function: GET /data-producer/v1/info-producers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001112# args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1113# (Function for test scripts)
1114ecs_api_edp_get_producer_ids_2() {
1115 __log_test_start $@
1116
1117 if [ $# -lt 1 ]; then
1118 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1119 return 1
1120 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001121 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1122 query="/data-producer/v1/info-producers"
1123 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1124 query=$query"?info_type_id=$2"
1125 fi
1126 else
1127 query="/ei-producer/v1/eiproducers"
1128 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1129 query=$query"?ei_type_id=$2"
1130 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001131 fi
1132 res="$(__do_curl_to_api ECS GET $query)"
1133 status=${res:${#res}-3}
1134
1135 if [ $status -ne $1 ]; then
1136 __log_test_fail_status_code $1 $status
1137 return 1
1138 fi
1139
1140 if [ $# -gt 2 ]; then
1141 body=${res:0:${#res}-3}
1142 targetJson="["
1143
1144 for pid in ${@:3} ; do
1145 if [ "$targetJson" != "[" ]; then
1146 targetJson=$targetJson","
1147 fi
1148 if [ $pid != "EMPTY" ]; then
1149 targetJson=$targetJson"\"$pid\""
1150 fi
1151 done
1152
1153 targetJson=$targetJson"]"
1154 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1155 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1156
1157 if [ $res -ne 0 ]; then
1158 __log_test_fail_body
1159 return 1
1160 fi
1161 fi
1162
1163 __log_test_pass
1164 return 0
1165}
1166
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001167# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001168# args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001169# (Function for test scripts)
1170ecs_api_edp_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001171 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001172
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001173 paramError=1
1174 if [ $# -eq 2 ]; then
1175 paramError=0
1176 fi
1177 if [ $# -gt 3 ]; then
1178 paramError=0
1179 fi
1180 if [ $paramError -ne 0 ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02001181 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001182 return 1
1183 fi
1184
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001185 query="/ei-producer/v1/eitypes/$2"
1186 res="$(__do_curl_to_api ECS GET $query)"
1187 status=${res:${#res}-3}
1188
1189 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001190 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001191 return 1
1192 fi
1193 if [ $# -gt 3 ]; then
1194 body=${res:0:${#res}-3}
1195
1196 if [ -f $3 ]; then
1197 schema=$(cat $3)
1198 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001199 __log_test_fail_general "Job template file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001200 return 1
1201 fi
1202
1203 targetJson=""
1204 if [ $4 != "EMPTY" ]; then
1205 for pid in ${@:4} ; do
1206 if [ "$targetJson" != "" ]; then
1207 targetJson=$targetJson","
1208 fi
1209 targetJson=$targetJson"\"$pid\""
1210 done
1211 fi
1212 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1213
1214 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1215 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1216
1217 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001218 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001219 return 1
1220 fi
1221 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001222 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001223 return 0
1224}
1225
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001226# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001227# API Test function: GET /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001228# args: (v1_2) <response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001229# (Function for test scripts)
1230ecs_api_edp_get_type_2() {
1231 __log_test_start $@
1232
1233 paramError=1
1234 if [ $# -eq 2 ]; then
1235 paramError=0
1236 fi
1237 if [ $# -eq 3 ]; then
1238 paramError=0
1239 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001240 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
1241 if [ $# -eq 4 ]; then
1242 paramError=0
1243 fi
1244 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001245 if [ $paramError -ne 0 ]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001246 __print_err "<response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]" $@
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001247 return 1
1248 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001249 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1250 query="/data-producer/v1/info-types/$2"
1251 else
1252 query="/ei-producer/v1/eitypes/$2"
1253 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001254
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001255 res="$(__do_curl_to_api ECS GET $query)"
1256 status=${res:${#res}-3}
1257
1258 if [ $status -ne $1 ]; then
1259 __log_test_fail_status_code $1 $status
1260 return 1
1261 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001262 if [ $# -ge 3 ]; then
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001263 body=${res:0:${#res}-3}
1264
1265 if [ -f $3 ]; then
1266 schema=$(cat $3)
1267 else
1268 __log_test_fail_general "Job template file "$3", does not exist"
1269 return 1
1270 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001271 info_data=""
1272 if [ $# -gt 3 ]; then
1273 if [ -f $4 ]; then
1274 info_data=$(cat $4)
1275 else
1276 __log_test_fail_general "Info-data file "$4", does not exist"
1277 return 1
1278 fi
1279 info_data=",\"info_type_information\":$info_data"
1280 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001281 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001282 targetJson="{\"info_job_data_schema\":$schema $info_data}"
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001283 else
1284 targetJson="{\"ei_job_data_schema\":$schema}"
1285 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001286
1287 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1288 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1289
1290 if [ $res -ne 0 ]; then
1291 __log_test_fail_body
1292 return 1
1293 fi
1294 fi
1295 __log_test_pass
1296 return 0
1297}
1298
1299# API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001300# API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001301# args: (v1_2) <response-code> <type-id> <job-schema-file> [ <info-type-info> ]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001302# (Function for test scripts)
1303ecs_api_edp_put_type_2() {
1304 __log_test_start $@
1305
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001306 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
1307 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1308 __print_err "<response-code> <type-id> <job-schema-file> [ <info-type-info> ]" $@
1309 return 1
1310 fi
1311 else
1312 if [ $# -ne 3 ]; then
1313 __print_err "<response-code> <type-id> <job-schema-file>" $@
1314 return 1
1315 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001316 fi
1317
1318 if [ ! -f $3 ]; then
1319 __log_test_fail_general "Job schema file "$3", does not exist"
1320 return 1
1321 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001322
1323 info_data=""
1324 if [ $# -gt 3 ]; then
1325 if [ -f $4 ]; then
1326 info_data=$(cat $4)
1327 else
1328 __log_test_fail_general "Info-data file "$4", does not exist"
1329 return 1
1330 fi
1331 info_data=",\"info_type_information\":$info_data"
1332 fi
1333
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001334 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1335 schema=$(cat $3)
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001336 input_json="{\"info_job_data_schema\":$schema $info_data}"
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001337 file="./tmp/put_type.json"
1338 echo $input_json > $file
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001339
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001340 query="/data-producer/v1/info-types/$2"
1341 else
1342 schema=$(cat $3)
1343 input_json="{\"ei_job_data_schema\":$schema}"
1344 file="./tmp/put_type.json"
1345 echo $input_json > $file
1346
1347 query="/ei-producer/v1/eitypes/$2"
1348 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001349 res="$(__do_curl_to_api ECS PUT $query $file)"
1350 status=${res:${#res}-3}
1351
1352 if [ $status -ne $1 ]; then
1353 __log_test_fail_status_code $1 $status
1354 return 1
1355 fi
1356
1357 __log_test_pass
1358 return 0
1359}
1360
1361# API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001362# API Test function: DELETE /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001363# args: (v1_2) <response-code> <type-id>
1364# (Function for test scripts)
1365ecs_api_edp_delete_type_2() {
1366 __log_test_start $@
1367
1368 if [ $# -ne 2 ]; then
1369 __print_err "<response-code> <type-id>" $@
1370 return 1
1371 fi
1372
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001373 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1374 query="/data-producer/v1/info-types/$2"
1375 else
1376 query="/ei-producer/v1/eitypes/$2"
1377 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001378 res="$(__do_curl_to_api ECS DELETE $query)"
1379 status=${res:${#res}-3}
1380
1381 if [ $status -ne $1 ]; then
1382 __log_test_fail_status_code $1 $status
1383 return 1
1384 fi
1385
1386 __log_test_pass
1387 return 0
1388}
1389
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001390# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001391# args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001392# (Function for test scripts)
1393ecs_api_edp_get_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001394 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001395
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001396 #Possible arg count: 2, 5 6, 8, 10 etc
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001397 paramError=1
1398 if [ $# -eq 2 ]; then
1399 paramError=0
1400 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001401 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001402 paramError=0
1403 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001404 variablecount=$(($#-4))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001405 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1406 paramError=0
1407 fi
1408
1409 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001410 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001411 return 1
1412 fi
1413
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001414 query="/ei-producer/v1/eiproducers/$2"
1415 res="$(__do_curl_to_api ECS GET $query)"
1416 status=${res:${#res}-3}
1417
1418 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001419 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001420 return 1
1421 fi
1422
1423 if [ $# -gt 2 ]; then
1424 body=${res:0:${#res}-3}
1425 targetJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001426 if [ $# -gt 5 ]; then
1427 arr=(${@:5})
1428 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001429 if [ "$targetJson" != "[" ]; then
1430 targetJson=$targetJson","
1431 fi
1432 if [ -f ${arr[$i+1]} ]; then
1433 schema=$(cat ${arr[$i+1]})
1434 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001435 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001436 return 1
1437 fi
1438
1439 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1440 done
1441 fi
1442 targetJson=$targetJson"]"
1443 if [ $# -gt 4 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001444 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001445 fi
1446 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1447 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1448
1449 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001450 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001451 return 1
1452 fi
1453 fi
1454
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001455 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001456 return 0
1457}
1458
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001459# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001460# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001461# args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1462# (Function for test scripts)
1463ecs_api_edp_get_producer_2() {
1464 __log_test_start $@
1465
1466 #Possible arg count: 2, 5, 6, 7, 8 etc
1467 paramError=1
1468 if [ $# -eq 2 ]; then
1469 paramError=0
1470 fi
1471 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1472 paramError=0
1473 fi
1474 if [ $# -ge 5 ]; then
1475 paramError=0
1476 fi
1477
1478 if [ $paramError -ne 0 ]; then
1479 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1480 return 1
1481 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001482 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1483 query="/data-producer/v1/info-producers/$2"
1484 else
1485 query="/ei-producer/v1/eiproducers/$2"
1486 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001487 res="$(__do_curl_to_api ECS GET $query)"
1488 status=${res:${#res}-3}
1489
1490 if [ $status -ne $1 ]; then
1491 __log_test_fail_status_code $1 $status
1492 return 1
1493 fi
1494
1495 if [ $# -gt 2 ]; then
1496 body=${res:0:${#res}-3}
1497 targetJson="["
1498 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1499 arr=(${@:5})
1500 for ((i=0; i<$(($#-4)); i=i+1)); do
1501 if [ "$targetJson" != "[" ]; then
1502 targetJson=$targetJson","
1503 fi
1504 targetJson=$targetJson"\"${arr[$i]}\""
1505 done
1506 fi
1507 targetJson=$targetJson"]"
1508 if [ $# -gt 4 ]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001509 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1510 targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}"
1511 else
1512 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1513 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001514 fi
1515 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1516 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1517
1518 if [ $res -ne 0 ]; then
1519 __log_test_fail_body
1520 return 1
1521 fi
1522 fi
1523
1524 __log_test_pass
1525 return 0
1526}
1527
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001528# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001529# API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001530# args: <response-code> <producer-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001531# (Function for test scripts)
1532ecs_api_edp_delete_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001533 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001534
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001535 if [ $# -lt 2 ]; then
1536 __print_err "<response-code> <producer-id>" $@
1537 return 1
1538 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001539 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1540 query="/data-producer/v1/info-producers/$2"
1541 else
1542 query="/ei-producer/v1/eiproducers/$2"
1543 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001544 res="$(__do_curl_to_api ECS DELETE $query)"
1545 status=${res:${#res}-3}
1546
1547 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001548 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001549 return 1
1550 fi
1551
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001552 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001553 return 0
1554}
1555
1556# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001557# args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001558# (Function for test scripts)
1559ecs_api_edp_put_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001560 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001561
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001562 #Valid number of parametrer 5,6,8,10,
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001563 paramError=1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001564 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001565 paramError=0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001566 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001567 paramError=0
1568 fi
1569 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001570 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001571 return 1
1572 fi
1573
1574 inputJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001575 if [ $# -gt 5 ]; then
1576 arr=(${@:5})
1577 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001578 if [ "$inputJson" != "[" ]; then
1579 inputJson=$inputJson","
1580 fi
1581 if [ -f ${arr[$i+1]} ]; then
1582 schema=$(cat ${arr[$i+1]})
1583 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001584 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001585 return 1
1586 fi
1587 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1588 done
1589 fi
1590 inputJson="\"supported_ei_types\":"$inputJson"]"
1591
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001592 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001593
1594 inputJson="{"$inputJson"}"
1595
1596 file="./tmp/.p.json"
1597 echo "$inputJson" > $file
1598 query="/ei-producer/v1/eiproducers/$2"
1599 res="$(__do_curl_to_api ECS PUT $query $file)"
1600 status=${res:${#res}-3}
1601
1602 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001603 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001604 return 1
1605 fi
1606
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001607 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001608 return 0
1609}
1610
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001611# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001612# API Test function: PUT /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001613# args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1614# (Function for test scripts)
1615ecs_api_edp_put_producer_2() {
1616 __log_test_start $@
1617
1618 #Valid number of parametrer 5,6,8,10,
1619 paramError=1
1620 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1621 paramError=0
1622 elif [ $# -ge 5 ]; then
1623 paramError=0
1624 fi
1625 if [ $paramError -ne 0 ]; then
1626 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1627 return 1
1628 fi
1629
1630 inputJson="["
1631 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1632 arr=(${@:5})
1633 for ((i=0; i<$(($#-4)); i=i+1)); do
1634 if [ "$inputJson" != "[" ]; then
1635 inputJson=$inputJson","
1636 fi
1637 inputJson=$inputJson"\""${arr[$i]}"\""
1638 done
1639 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001640 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1641 inputJson="\"supported_info_types\":"$inputJson"]"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001642
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001643 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001644
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001645 inputJson="{"$inputJson"}"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001646
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001647 file="./tmp/.p.json"
1648 echo "$inputJson" > $file
1649 query="/data-producer/v1/info-producers/$2"
1650 else
1651 inputJson="\"supported_ei_types\":"$inputJson"]"
1652
1653 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1654
1655 inputJson="{"$inputJson"}"
1656
1657 file="./tmp/.p.json"
1658 echo "$inputJson" > $file
1659 query="/ei-producer/v1/eiproducers/$2"
1660 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001661 res="$(__do_curl_to_api ECS PUT $query $file)"
1662 status=${res:${#res}-3}
1663
1664 if [ $status -ne $1 ]; then
1665 __log_test_fail_status_code $1 $status
1666 return 1
1667 fi
1668
1669 __log_test_pass
1670 return 0
1671}
1672
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001673# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001674# 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 +02001675# (Function for test scripts)
1676ecs_api_edp_get_producer_jobs() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001677 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001678
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001679 #Valid number of parameter 2,3,7,11
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001680 paramError=1
1681 if [ $# -eq 2 ]; then
1682 paramError=0
1683 fi
1684 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1685 paramError=0
1686 fi
1687 variablecount=$(($#-2))
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001688 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001689 paramError=0
1690 fi
1691 if [ $paramError -eq 1 ]; then
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001692 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001693 return 1
1694 fi
1695
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001696 query="/ei-producer/v1/eiproducers/$2/eijobs"
1697 res="$(__do_curl_to_api ECS GET $query)"
1698 status=${res:${#res}-3}
1699 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001700 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001701 return 1
1702 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001703 if [ $# -gt 2 ]; then
1704 body=${res:0:${#res}-3}
1705 targetJson="["
1706 if [ $# -gt 3 ]; then
1707 arr=(${@:3})
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001708 for ((i=0; i<$(($#-3)); i=i+5)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001709 if [ "$targetJson" != "[" ]; then
1710 targetJson=$targetJson","
1711 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001712 if [ -f ${arr[$i+4]} ]; then
1713 jobfile=$(cat ${arr[$i+4]})
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001714 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1715 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001716 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001717 return 1
1718 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001719 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 +02001720 done
1721 fi
1722 targetJson=$targetJson"]"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001723
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001724 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1725 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001726
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001727 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001728 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001729 return 1
1730 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001731 fi
1732
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001733 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001734 return 0
1735}
1736
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001737# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001738# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001739# args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1740# (Function for test scripts)
1741ecs_api_edp_get_producer_jobs_2() {
1742 __log_test_start $@
1743
1744 #Valid number of parameter 2,3,7,11
1745 paramError=1
1746 if [ $# -eq 2 ]; then
1747 paramError=0
1748 fi
1749 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1750 paramError=0
1751 fi
1752 variablecount=$(($#-2))
1753 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1754 paramError=0
1755 fi
1756 if [ $paramError -eq 1 ]; then
1757 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1758 return 1
1759 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001760 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1761 query="/data-producer/v1/info-producers/$2/info-jobs"
1762 else
1763 query="/ei-producer/v1/eiproducers/$2/eijobs"
1764 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001765 res="$(__do_curl_to_api ECS GET $query)"
1766 status=${res:${#res}-3}
1767 if [ $status -ne $1 ]; then
1768 __log_test_fail_status_code $1 $status
1769 return 1
1770 fi
1771 if [ $# -gt 2 ]; then
1772 body=${res:0:${#res}-3}
1773 targetJson="["
1774 if [ $# -gt 3 ]; then
1775 arr=(${@:3})
1776 for ((i=0; i<$(($#-3)); i=i+5)); do
1777 if [ "$targetJson" != "[" ]; then
1778 targetJson=$targetJson","
1779 fi
1780 if [ -f ${arr[$i+4]} ]; then
1781 jobfile=$(cat ${arr[$i+4]})
1782 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1783 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001784 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001785 return 1
1786 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001787 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1788 targetJson=$targetJson"{\"info_job_identity\":\"${arr[$i]}\",\"info_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"info_job_data\":$jobfile, \"last_updated\":\"????\"}"
1789 else
1790 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\":\"????\"}"
1791 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001792 done
1793 fi
1794 targetJson=$targetJson"]"
1795
1796 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1797 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1798
1799 if [ $res -ne 0 ]; then
1800 __log_test_fail_body
1801 return 1
1802 fi
1803 fi
1804
1805 __log_test_pass
1806 return 0
1807}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001808
1809##########################################
1810#### Service status ####
1811##########################################
1812# Function prefix: ecs_api_service
1813
1814# API Test function: GET ​/status
1815# args: <response-code>
1816# (Function for test scripts)
1817ecs_api_service_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001818 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001819
1820 if [ $# -lt 1 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001821 __print_err "<response-code>" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001822 return 1
1823 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001824 res="$(__do_curl_to_api ECS GET /status)"
1825 status=${res:${#res}-3}
1826 if [ $status -ne $1 ]; then
1827 __log_test_fail_status_code $1 $status
1828 return 1
1829 fi
1830 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001831 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001832}
1833
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001834###########################################
1835######### Info data consumer API ##########
1836###########################################
1837#Function prefix: ecs_api_idc
1838
1839
1840# API Test function: GET /data-consumer/v1/info-types
1841# args: <response-code> [ (EMPTY | [<type-id>]+) ]
1842# (Function for test scripts)
1843ecs_api_idc_get_type_ids() {
1844 __log_test_start $@
1845
1846 if [ $# -lt 1 ]; then
1847 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1848 return 1
1849 fi
1850
1851 query="/data-consumer/v1/info-types"
1852 res="$(__do_curl_to_api ECS GET $query)"
1853 status=${res:${#res}-3}
1854
1855 if [ $status -ne $1 ]; then
1856 __log_test_fail_status_code $1 $status
1857 return 1
1858 fi
1859 if [ $# -gt 1 ]; then
1860 body=${res:0:${#res}-3}
1861 targetJson="["
1862 if [ $2 != "EMPTY" ]; then
1863 for pid in ${@:2} ; do
1864 if [ "$targetJson" != "[" ]; then
1865 targetJson=$targetJson","
1866 fi
1867 targetJson=$targetJson"\"$pid\""
1868 done
1869 fi
1870 targetJson=$targetJson"]"
1871 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1872 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1873
1874 if [ $res -ne 0 ]; then
1875 __log_test_fail_body
1876 return 1
1877 fi
1878 fi
1879
1880 __log_test_pass
1881 return 0
1882}
1883
1884# API Test function: GET /data-consumer/v1/info-jobs
1885# args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
1886# (Function for test scripts)
1887ecs_api_idc_get_job_ids() {
1888 __log_test_start $@
1889
1890 # Valid number of parameters 4,5,6 etc
1891 if [ $# -lt 3 ]; then
1892 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
1893 return 1
1894 fi
1895 search=""
1896 if [ $3 != "NOWNER" ]; then
1897 search="?owner="$3
1898 fi
1899
1900 if [ $2 != "NOTYPE" ]; then
1901 if [ -z "$search" ]; then
1902 search="?infoTypeId="$2
1903 else
1904 search=$search"&infoTypeId="$2
1905 fi
1906 fi
1907 query="/data-consumer/v1/info-jobs$search"
1908
1909 res="$(__do_curl_to_api ECS GET $query)"
1910 status=${res:${#res}-3}
1911
1912 if [ $status -ne $1 ]; then
1913 __log_test_fail_status_code $1 $status
1914 return 1
1915 fi
1916
1917 if [ $# -gt 3 ]; then
1918 body=${res:0:${#res}-3}
1919 targetJson="["
1920
1921 for pid in ${@:4} ; do
1922 if [ "$targetJson" != "[" ]; then
1923 targetJson=$targetJson","
1924 fi
1925 if [ $pid != "EMPTY" ]; then
1926 targetJson=$targetJson"\"$pid\""
1927 fi
1928 done
1929
1930 targetJson=$targetJson"]"
1931 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1932 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1933
1934 if [ $res -ne 0 ]; then
1935 __log_test_fail_body
1936 return 1
1937 fi
1938 fi
1939
1940 __log_test_pass
1941 return 0
1942}
1943
1944# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
1945# args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
1946# (Function for test scripts)
1947ecs_api_idc_get_job() {
1948 __log_test_start $@
1949
1950 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
1951 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
1952 return 1
1953 fi
1954 query="/data-consumer/v1/info-jobs/$2"
1955 res="$(__do_curl_to_api ECS GET $query)"
1956 status=${res:${#res}-3}
1957
1958 if [ $status -ne $1 ]; then
1959 __log_test_fail_status_code $1 $status
1960 return 1
1961 fi
1962
1963 if [ $# -eq 7 ]; then
1964 body=${res:0:${#res}-3}
1965
1966 if [ -f $7 ]; then
1967 jobfile=$(cat $7)
1968 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1969 else
1970 __log_test_fail_general "Job template file "$6", does not exist"
1971 return 1
1972 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001973 targetJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001974 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1975 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1976
1977 if [ $res -ne 0 ]; then
1978 __log_test_fail_body
1979 return 1
1980 fi
1981 fi
1982
1983 __log_test_pass
1984 return 0
1985}
1986
1987
1988# API Test function: PUT ​/data-consumer/v1/info-jobs/{infoJobId}
1989# args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
1990# (Function for test scripts)
1991ecs_api_idc_put_job() {
1992 __log_test_start $@
1993
1994 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1995 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
1996 return 1
1997 fi
1998 if [ -f $7 ]; then
1999 jobfile=$(cat $7)
2000 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
2001 else
2002 __log_test_fail_general "Job template file "$7", does not exist"
2003 return 1
2004 fi
2005
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02002006 inputJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002007 file="./tmp/.p.json"
2008 echo "$inputJson" > $file
2009
2010 query="/data-consumer/v1/info-jobs/$2"
2011
2012 if [ $# -eq 8 ]; then
2013 if [ $8 == "VALIDATE" ]; then
2014 query=$query"?typeCheck=true"
2015 fi
2016 fi
2017
2018 res="$(__do_curl_to_api ECS PUT $query $file)"
2019 status=${res:${#res}-3}
2020
2021 if [ $status -ne $1 ]; then
2022 __log_test_fail_status_code $1 $status
2023 return 1
2024 fi
2025
2026 __log_test_pass
2027 return 0
2028}
2029
2030# API Test function: DELETE ​/data-consumer/v1/info-jobs/{infoJobId}
2031# args: <response-code> <job-id>
2032# (Function for test scripts)
2033ecs_api_idc_delete_job() {
2034 __log_test_start $@
2035
2036 if [ $# -ne 2 ]; then
2037 __print_err "<response-code> <job-id>" $@
2038 return 1
2039 fi
2040 query="/data-consumer/v1/info-jobs/$2"
2041 res="$(__do_curl_to_api ECS DELETE $query)"
2042 status=${res:${#res}-3}
2043
2044 if [ $status -ne $1 ]; then
2045 __log_test_fail_status_code $1 $status
2046 return 1
2047 fi
2048
2049 __log_test_pass
2050 return 0
2051}
2052
2053# API Test function: GET ​/data-consumer/v1/info-types/{infoTypeId}
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002054# args: <response-code> <type-id> [<schema-file> [<type-status> <producers-count]]
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002055# (Function for test scripts)
2056ecs_api_idc_get_type() {
2057 __log_test_start $@
2058
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002059 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2060 __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002061 return 1
2062 fi
2063
2064 query="/data-consumer/v1/info-types/$2"
2065 res="$(__do_curl_to_api ECS GET $query)"
2066 status=${res:${#res}-3}
2067
2068 if [ $status -ne $1 ]; then
2069 __log_test_fail_status_code $1 $status
2070 return 1
2071 fi
2072
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002073 if [ $# -gt 2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002074 body=${res:0:${#res}-3}
2075 if [ -f $3 ]; then
2076 schema=$(cat $3)
2077 else
2078 __log_test_fail_general "Schema file "$3", does not exist"
2079 return 1
2080 fi
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002081 if [ $# -eq 5 ]; then
2082 targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}"
2083 else
2084 targetJson="{\"job_data_schema\":$schema}"
2085 fi
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002086 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2087 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2088
2089 if [ $res -ne 0 ]; then
2090 __log_test_fail_body
2091 return 1
2092 fi
2093 fi
2094
2095 __log_test_pass
2096 return 0
2097}
2098
2099# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002100# This test only status during an optional timeout. No test of the list of producers
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002101# args: <response-code> <job-id> [<status> [<timeout>]]
2102# (Function for test scripts)
2103ecs_api_idc_get_job_status() {
2104 __log_test_start $@
2105
2106 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2107 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2108 return 1
2109 fi
2110
2111 query="/data-consumer/v1/info-jobs/$2/status"
2112
2113 start=$SECONDS
2114 for (( ; ; )); do
2115 res="$(__do_curl_to_api ECS GET $query)"
2116 status=${res:${#res}-3}
2117
2118 if [ $# -eq 4 ]; then
2119 duration=$((SECONDS-start))
2120 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2121 if [ $duration -gt $4 ]; then
2122 echo ""
2123 duration=-1 #Last iteration
2124 fi
2125 else
2126 duration=-1 #single test, no wait
2127 fi
2128
2129 if [ $status -ne $1 ]; then
2130 if [ $duration -eq -1 ]; then
2131 __log_test_fail_status_code $1 $status
2132 return 1
2133 fi
2134 fi
2135 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
2136 body=${res:0:${#res}-3}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02002137 targetJson="{\"info_job_status\": \"$3\"}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002138 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2139 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2140
2141 if [ $res -ne 0 ]; then
2142 if [ $duration -eq -1 ]; then
2143 __log_test_fail_body
2144 return 1
2145 fi
2146 else
2147 duration=-1 #Goto pass
2148 fi
2149 fi
2150 if [ $duration -eq -1 ]; then
2151 if [ $# -eq 4 ]; then
2152 echo ""
2153 fi
2154 __log_test_pass
2155 return 0
2156 else
2157 sleep 1
2158 fi
2159 done
2160
2161 __log_test_pass
2162 return 0
2163}
2164
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002165# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2166# This function test status and the list of producers with and optional timeout
2167# args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
2168# (Function for test scripts)
2169ecs_api_idc_get_job_status2() {
2170
2171 __log_test_start $@
2172 param_error=0
2173 if [ $# -lt 2 ]; then
2174 param_error=1
2175 fi
2176 args=("$@")
2177 timeout=0
2178 if [ $# -gt 2 ]; then
2179 if [ $# -lt 4 ]; then
2180 param_error=1
2181 fi
2182 targetJson="{\"info_job_status\": \"$3\""
2183 if [ "$4" == "EMPTYPROD" ]; then
2184 targetJson=$targetJson",\"producers\": []}"
2185 if [ $# -gt 4 ]; then
2186 timeout=$5
2187 fi
2188 else
2189 targetJson=$targetJson",\"producers\": ["
2190 if [ $# -eq $(($4+5)) ]; then
2191 idx=$(($4+4))
2192 timeout=${args[$idx]}
2193 fi
2194 for ((ecs_i = 0 ; ecs_i < $4 ; ecs_i++)); do
2195 idx=$(($ecs_i+4))
2196 if [ $ecs_i -gt 0 ]; then
2197 targetJson=$targetJson","
2198 fi
2199 targetJson=$targetJson"\""${args[$idx]}"\""
2200 done
2201 targetJson=$targetJson"]}"
2202 fi
2203 fi
2204
2205 if [ $param_error -ne 0 ]; then
2206 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2207 return 1
2208 fi
2209
2210 query="/data-consumer/v1/info-jobs/$2/status"
2211
2212 start=$SECONDS
2213 for (( ; ; )); do
2214 res="$(__do_curl_to_api ECS GET $query)"
2215 status=${res:${#res}-3}
2216
2217 if [ $# -gt 2 ]; then
2218 duration=$((SECONDS-start))
2219 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2220 if [ $duration -gt $timeout ]; then
2221 echo ""
2222 duration=-1 #Last iteration
2223 fi
2224 else
2225 duration=-1 #single test, no wait
2226 fi
2227
2228 if [ $status -ne $1 ]; then
2229 if [ $duration -eq -1 ]; then
2230 __log_test_fail_status_code $1 $status
2231 return 1
2232 fi
2233 fi
2234 if [ $# -gt 2 ] && [ $status -eq $1 ]; then
2235 body=${res:0:${#res}-3}
2236 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2237 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2238
2239 if [ $res -ne 0 ]; then
2240 if [ $duration -eq -1 ]; then
2241 __log_test_fail_body
2242 return 1
2243 fi
2244 else
2245 duration=-1 #Goto pass
2246 fi
2247 fi
2248 if [ $duration -eq -1 ]; then
2249 if [ $# -eq 4 ]; then
2250 echo ""
2251 fi
2252 __log_test_pass
2253 return 0
2254 else
2255 sleep 1
2256 fi
2257 done
2258
2259 __log_test_pass
2260 return 0
2261}
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002262
2263##########################################
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002264#### Type subscriptions ####
2265##########################################
2266
2267# API Test function: GET /data-consumer/v1/info-type-subscription
2268# args: <response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]
2269# (Function for test scripts)
2270ecs_api_idc_get_subscription_ids() {
2271 __log_test_start $@
2272
2273 if [ $# -lt 3 ]; then
2274 __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@
2275 return 1
2276 fi
2277
2278 query="/data-consumer/v1/info-type-subscription"
2279 search=""
2280 if [ $2 != "NOOWNER" ]; then
2281 search="?owner="$2
2282 fi
2283
2284 res="$(__do_curl_to_api ECS GET $query$search)"
2285 status=${res:${#res}-3}
2286
2287 if [ $status -ne $1 ]; then
2288 __log_test_fail_status_code $1 $status
2289 return 1
2290 fi
2291
2292 if [ $# -gt 2 ]; then
2293 body=${res:0:${#res}-3}
2294 targetJson="["
2295 if [ $3 != "EMPTY" ]; then
2296 for pid in ${@:3} ; do
2297 if [ "$targetJson" != "[" ]; then
2298 targetJson=$targetJson","
2299 fi
2300 targetJson=$targetJson"\"$pid\""
2301 done
2302 fi
2303 targetJson=$targetJson"]"
2304 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2305 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2306
2307 if [ $res -ne 0 ]; then
2308 __log_test_fail_body
2309 return 1
2310 fi
2311 fi
2312
2313 __log_test_pass
2314 return 0
2315}
2316
2317# API Test function: GET /data-consumer/v1/info-type-subscription/{subscriptionId}
2318# args: <response-code> <subscription-id> [ <owner-id> <status-uri> ]
2319# (Function for test scripts)
2320ecs_api_idc_get_subscription() {
2321 __log_test_start $@
2322
2323 if [ $# -ne 2 ] && [ $# -ne 4 ]; then
2324 __print_err "<response-code> <subscription-id> [ <owner-id> <status-uri> ]" $@
2325 return 1
2326 fi
2327
2328 query="/data-consumer/v1/info-type-subscription/$2"
2329 res="$(__do_curl_to_api ECS GET $query)"
2330 status=${res:${#res}-3}
2331
2332 if [ $status -ne $1 ]; then
2333 __log_test_fail_status_code $1 $status
2334 return 1
2335 fi
2336
2337 if [ $# -gt 2 ]; then
2338 body=${res:0:${#res}-3}
2339 targetJson="{\"owner\":\"$3\",\"status_result_uri\":\"$4\"}"
2340 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2341 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2342
2343 if [ $res -ne 0 ]; then
2344 __log_test_fail_body
2345 return 1
2346 fi
2347 fi
2348
2349 __log_test_pass
2350 return 0
2351}
2352
2353# API Test function: PUT /data-consumer/v1/info-type-subscription/{subscriptionId}
2354# args: <response-code> <subscription-id> <owner-id> <status-uri>
2355# (Function for test scripts)
2356ecs_api_idc_put_subscription() {
2357 __log_test_start $@
2358
2359 if [ $# -ne 4 ]; then
2360 __print_err "<response-code> <subscription-id> <owner-id> <status-uri>" $@
2361 return 1
2362 fi
2363
2364 inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}"
2365 file="./tmp/.p.json"
2366 echo "$inputJson" > $file
2367
2368 query="/data-consumer/v1/info-type-subscription/$2"
2369 res="$(__do_curl_to_api ECS PUT $query $file)"
2370 status=${res:${#res}-3}
2371
2372 if [ $status -ne $1 ]; then
2373 __log_test_fail_status_code $1 $status
2374 return 1
2375 fi
2376
2377 __log_test_pass
2378 return 0
2379}
2380
2381# API Test function: DELETE /data-consumer/v1/info-type-subscription/{subscriptionId}
2382# args: <response-code> <subscription-id>
2383# (Function for test scripts)
2384ecs_api_idc_delete_subscription() {
2385 __log_test_start $@
2386
2387 if [ $# -ne 2 ]; then
2388 __print_err "<response-code> <subscription-id> " $@
2389 return 1
2390 fi
2391
2392 query="/data-consumer/v1/info-type-subscription/$2"
2393 res="$(__do_curl_to_api ECS DELETE $query)"
2394 status=${res:${#res}-3}
2395
2396 if [ $status -ne $1 ]; then
2397 __log_test_fail_status_code $1 $status
2398 return 1
2399 fi
2400
2401 __log_test_pass
2402 return 0
2403}
2404
2405##########################################
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002406#### Reset jobs ####
2407##########################################
2408# Function prefix: ecs_api_admin
2409
2410# Admin to remove all jobs
BjornMagnussonXA366e36a2021-01-27 11:48:56 +01002411# args: <response-code> [ <type> ]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002412# (Function for test scripts)
2413
2414ecs_api_admin_reset() {
2415 __log_test_start $@
2416
2417 if [ -z "$FLAT_A1_EI" ]; then
2418 query="/A1-EI/v1/eitypes/$2/eijobs"
2419 else
2420 query="/A1-EI/v1/eijobs"
2421 fi
2422 res="$(__do_curl_to_api ECS GET $query)"
2423 status=${res:${#res}-3}
2424
2425 if [ $status -ne 200 ]; then
2426 __log_test_fail_status_code $1 $status
2427 return 1
2428 fi
2429
2430 #Remove brackets and response code
2431 body=${res:1:${#res}-4}
2432 list=$(echo ${body//,/ })
2433 list=$(echo ${list//[/})
2434 list=$(echo ${list//]/})
2435 list=$(echo ${list//\"/})
2436 list=$list" "
2437 for job in $list; do
2438 if [ -z "$FLAT_A1_EI" ]; then
2439 echo "Not supported for non-flat EI api"
2440 else
2441 query="/A1-EI/v1/eijobs/$job"
2442 res="$(__do_curl_to_api ECS DELETE $query)"
2443 status=${res:${#res}-3}
2444 if [ $status -ne 204 ]; then
2445 __log_test_fail_status_code $1 $status
2446 return 1
2447 fi
2448 echo " Deleted job: "$job
2449 fi
2450 done
2451
2452 __log_test_pass
2453 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002454}
2455
2456##########################################
2457#### Reset jobs and producers ####
2458##########################################
2459
2460
2461# Admin reset to remove all data in ecs; jobs, producers etc
2462# NOTE - only works in kubernetes and the pod should not be running
2463# args: -
2464# (Function for test scripts)
2465
2466ecs_kube_pvc_reset() {
2467 __log_test_start $@
2468
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002469 pvc_name=$(kubectl get pvc -n nonrtric --no-headers -o custom-columns=":metadata.name" | grep enrichment)
2470 if [ -z "$pvc_name" ]; then
2471 pvc_name=enrichmentservice-pvc
2472 fi
2473 echo " Trying to reset pvc: "$pvc_name
2474
2475 __kube_clean_pvc $ECS_APP_NAME nonrtric $pvc_name /var/enrichment-coordinator-service/database
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002476
2477 __log_test_pass
2478 return 0
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002479}