blob: cf5f580f462e31b3606c09b6c1901ad2d64b3146 [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"
188 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
189 fi
190
191 # Check if app shall be fully managed by the test script
192 if [ $retcode_i -eq 0 ]; then
193 echo -e " Creating $ECS_APP_NAME app and expose service"
194
195 #Check if nonrtric namespace exists, if not create it
196 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
197
198 export ECS_APP_NAME
199 export KUBE_NONRTRIC_NAMESPACE
200 export ECS_IMAGE
201 export ECS_INTERNAL_PORT
202 export ECS_INTERNAL_SECURE_PORT
203 export ECS_EXTERNAL_PORT
204 export ECS_EXTERNAL_SECURE_PORT
205 export ECS_CONFIG_MOUNT_PATH
206 export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config"
207 export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data"
208 export ECS_CONTAINER_MNT_DIR
209
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100210 export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv"
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200211 export ECS_DATA_PVC_NAME=$ECS_APP_NAME"-pvc"
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100212 #Create a unique path for the pv each time to prevent a previous volume to be reused
213 export ECS_PV_PATH="ecsdata-"$(date +%s)
214
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100215 if [ $1 == "PROXY" ]; then
216 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
217 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
218 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
219 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
220 else
221 echo " Configured with http proxy"
222 fi
223 else
224 ECS_HTTP_PROXY_CONFIG_PORT=0
225 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
226 echo " Configured without http proxy"
227 fi
228 export ECS_HTTP_PROXY_CONFIG_PORT
229 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
230
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100231 # Create config map for config
232 datafile=$PWD/tmp/$ECS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100233 cp $2 $datafile
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100234 output_yaml=$PWD/tmp/ecs_cfc.yaml
235 __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml
236
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100237 # Create pv
238 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pv.yaml
239 output_yaml=$PWD/tmp/ecs_pv.yaml
240 __kube_create_instance pv $ECS_APP_NAME $input_yaml $output_yaml
241
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100242 # Create pvc
243 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml
244 output_yaml=$PWD/tmp/ecs_pvc.yaml
245 __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml
246
247 # Create service
248 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml
249 output_yaml=$PWD/tmp/ecs_svc.yaml
250 __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml
251
252 # Create app
253 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml
254 output_yaml=$PWD/tmp/ecs_app.yaml
255 __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml
256 fi
257
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200258 # 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
259 # 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
260
261 # 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 +0200262 if [ $retcode_i -eq 0 ]; then
263 __ECS_WORKER_NODE=$(kubectl get pod -l "autotest=ECS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
264 if [ -z "$__ECS_WORKER_NODE" ]; then
265 echo -e $YELLOW" Cannot find worker node for pod for $ECS_APP_NAME, persistency may not work"$EYELLOW
266 fi
267 else
268 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 +0200269 fi
270
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100271 echo " Retrieving host and ports for service..."
272 ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
273 ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
274 ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
275
276 echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT"
277
278 if [ $ECS_HTTPX == "http" ]; then
279 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
280 else
281 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
282 fi
283
284 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
285
286 if [ $ECS_ADAPTER_TYPE == "REST" ]; then
287 ECS_ADAPTER=$ECS_PATH
288 fi
289 else
290 __check_included_image 'ECS'
291 if [ $? -eq 1 ]; then
292 echo -e $RED"The ECS app is not included in this test script"$ERED
293 echo -e $RED"ECS will not be started"$ERED
294 exit 1
295 fi
296
297 curdir=$PWD
298 cd $SIM_GROUP
299 cd ecs
300 cd $ECS_HOST_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100301 #cd ..
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100302 if [ -d db ]; then
303 if [ "$(ls -A $DIR)" ]; then
304 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
305 rm -rf db/* &> /dev/null
306 if [ $? -ne 0 ]; then
307 echo -e $RED" Cannot remove database files in: $PWD"$ERED
308 exit 1
309 fi
310 fi
311 else
312 echo " No files in mounted dir or dir does not exists"
313 fi
314 cd $curdir
315
316 export ECS_APP_NAME
317 export ECS_APP_NAME_ALIAS
318 export ECS_HOST_MNT_DIR
319 export ECS_CONTAINER_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100320 export ECS_CONFIG_MOUNT_PATH
321 export ECS_CONFIG_FILE
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100322 export ECS_INTERNAL_PORT
323 export ECS_EXTERNAL_PORT
324 export ECS_INTERNAL_SECURE_PORT
325 export ECS_EXTERNAL_SECURE_PORT
326 export DOCKER_SIM_NWNAME
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100327 export ECS_DISPLAY_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100328
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100329 if [ $1 == "PROXY" ]; then
330 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
331 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
332 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
333 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
334 else
335 echo " Configured with http proxy"
336 fi
337 else
338 ECS_HTTP_PROXY_CONFIG_PORT=0
339 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
340 echo " Configured without http proxy"
341 fi
342 export ECS_HTTP_PROXY_CONFIG_PORT
343 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
344
345 dest_file=$SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_HOST_MNT_DIR/$ECS_CONFIG_FILE
346
347 envsubst < $2 > $dest_file
348
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100349 __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100350
351 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
352 fi
353 echo ""
354 return 0
355}
356
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200357# Stop the ecs
358# args: -
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100359# args: -
360# (Function for test scripts)
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200361stop_ecs() {
362 echo -e $BOLD"Stopping $ECS_DISPLAY_NAME"$EBOLD
363
364 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200365
366 __check_prestarted_image "ECS"
367 if [ $? -eq 0 ]; then
368 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
369 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
370 return 0
371 fi
372
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200373 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
374 echo " Deleting the replica set - a new will be started when the app is started"
375 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ECS")
376 if [ $? -ne 0 ]; then
377 echo -e $RED" Could not delete replica set "$RED
378 ((RES_CONF_FAIL++))
379 return 1
380 fi
381 else
382 docker stop $ECS_APP_NAME &> ./tmp/.dockererr
383 if [ $? -ne 0 ]; then
384 __print_err "Could not stop $ECS_APP_NAME" $@
385 cat ./tmp/.dockererr
386 ((RES_CONF_FAIL++))
387 return 1
388 fi
389 fi
390 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
391 echo ""
392 return 0
393}
394
395# Start a previously stopped ecs
396# args: -
397# (Function for test scripts)
398start_stopped_ecs() {
399 echo -e $BOLD"Starting (the previously stopped) $ECS_DISPLAY_NAME"$EBOLD
400
401 if [ $RUNMODE == "KUBE" ]; then
402
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200403 __check_prestarted_image "ECS"
404 if [ $? -eq 0 ]; then
405 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
406 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
407 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
408 return 0
409 fi
410
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200411 # Tie the PMS to the same worker node it was initially started on
412 # 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
413 if [ -z "$__ECS_WORKER_NODE" ]; then
414 echo -e $RED" No initial worker node found for pod "$RED
415 ((RES_CONF_FAIL++))
416 return 1
417 else
418 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
419 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
420 tmp=$(kubectl patch deployment $ECS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ECS_WORKER_NODE'"}}}}}')
421 if [ $? -ne 0 ]; then
422 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ECS_APP_NAME, persistency may not work"$EYELLOW
423 fi
424 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
425 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200426 else
427 docker start $ECS_APP_NAME &> ./tmp/.dockererr
428 if [ $? -ne 0 ]; then
429 __print_err "Could not start (the stopped) $ECS_APP_NAME" $@
430 cat ./tmp/.dockererr
431 ((RES_CONF_FAIL++))
432 return 1
433 fi
434 fi
435 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100436 if [ $? -ne 0 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100437 return 1
438 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100439 echo ""
440 return 0
441}
442
443# Turn on debug level tracing in ECS
444# args: -
445# (Function for test scripts)
446set_ecs_debug() {
447 echo -e $BOLD"Setting ecs debug logging"$EBOLD
448 curlString="$ECS_PATH$ECS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
449 result=$(__do_curl "$curlString")
450 if [ $? -ne 0 ]; then
451 __print_err "Could not set debug mode" $@
452 ((RES_CONF_FAIL++))
453 return 1
454 fi
455 echo ""
456 return 0
457}
458
459# Turn on trace level tracing in ECS
460# args: -
461# (Function for test scripts)
462set_ecs_trace() {
463 echo -e $BOLD"Setting ecs trace logging"$EBOLD
464 curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
465 result=$(__do_curl "$curlString")
466 if [ $? -ne 0 ]; then
467 __print_err "Could not set trace mode" $@
468 ((RES_CONF_FAIL++))
469 return 1
470 fi
471 echo ""
472 return 0
473}
474
475# Perform curl retries when making direct call to ECS for the specified http response codes
476# Speace separated list of http response codes
477# args: [<response-code>]*
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100478use_ecs_retries() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100479 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100480 ECS_RETRY_CODES=$@
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100481 echo ""
482 return 0
483}
484
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100485# Check the ecs logs for WARNINGs and ERRORs
486# args: -
487# (Function for test scripts)
488check_ecs_logs() {
489 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
490}
491
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200492
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100493# Tests if a variable value in the ECS is equal to a target value and and optional timeout.
494# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
495# equal to the target or not.
496# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
497# before setting pass or fail depending on if the variable value becomes equal to the target
498# value or not.
499# (Function for test scripts)
500ecs_equal() {
501 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100502 __var_test ECS "$ECS_PATH/" $1 "=" $2 $3
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100503 else
504 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
505 fi
506}
507
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200508
509##########################################
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100510######### A1-E Enrichment API ##########
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200511##########################################
512#Function prefix: ecs_api_a1
513
514# API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200515# args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100516# args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200517# (Function for test scripts)
518ecs_api_a1_get_job_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100519 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200520
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100521 if [ -z "$FLAT_A1_EI" ]; then
522 # Valid number of parameters 4,5,6 etc
523 if [ $# -lt 3 ]; then
524 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
525 return 1
526 fi
527 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100528 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100529 # Valid number of parameters 4,5,6 etc
530 if [ $# -lt 3 ]; then
531 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
532 return 1
533 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200534 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100535 search=""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200536 if [ $3 != "NOWNER" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100537 search="?owner="$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200538 fi
539
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100540 if [ -z "$FLAT_A1_EI" ]; then
541 query="/A1-EI/v1/eitypes/$2/eijobs$search"
542 else
543 if [ $2 != "NOTYPE" ]; then
544 if [ -z "$search" ]; then
545 search="?eiTypeId="$2
546 else
547 search=$search"&eiTypeId="$2
548 fi
549 fi
550 query="/A1-EI/v1/eijobs$search"
551 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200552 res="$(__do_curl_to_api ECS GET $query)"
553 status=${res:${#res}-3}
554
555 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100556 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200557 return 1
558 fi
559
560 if [ $# -gt 3 ]; then
561 body=${res:0:${#res}-3}
562 targetJson="["
563
564 for pid in ${@:4} ; do
565 if [ "$targetJson" != "[" ]; then
566 targetJson=$targetJson","
567 fi
568 if [ $pid != "EMPTY" ]; then
569 targetJson=$targetJson"\"$pid\""
570 fi
571 done
572
573 targetJson=$targetJson"]"
574 echo " TARGET JSON: $targetJson" >> $HTTPLOG
575 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
576
577 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100578 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200579 return 1
580 fi
581 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200582
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100583 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200584 return 0
585}
586
587# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200588# args: <response-code> <type-id> [<schema-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200589# (Function for test scripts)
590ecs_api_a1_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100591 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200592
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200593 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
594 __print_err "<response-code> <type-id> [<schema-file>]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200595 return 1
596 fi
597
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200598 query="/A1-EI/v1/eitypes/$2"
599 res="$(__do_curl_to_api ECS GET $query)"
600 status=${res:${#res}-3}
601
602 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100603 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200604 return 1
605 fi
606
607 if [ $# -eq 3 ]; then
608 body=${res:0:${#res}-3}
609 if [ -f $3 ]; then
610 schema=$(cat $3)
611 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100612 __log_test_fail_general "Schema file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200613 return 1
614 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100615 if [ -z "$FLAT_A1_EI" ]; then
616 targetJson="{\"eiJobParametersSchema\":$schema}"
617 else
618 targetJson=$schema
619 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200620 echo " TARGET JSON: $targetJson" >> $HTTPLOG
621 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
622
623 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100624 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200625 return 1
626 fi
627 fi
628
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100629 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200630 return 0
631}
632
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200633# API Test function: GET /A1-EI/v1/eitypes
634# args: <response-code> [ (EMPTY | [<type-id>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200635# (Function for test scripts)
636ecs_api_a1_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100637 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200638
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200639 if [ $# -lt 1 ]; then
640 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200641 return 1
642 fi
643
644 query="/A1-EI/v1/eitypes"
645 res="$(__do_curl_to_api ECS GET $query)"
646 status=${res:${#res}-3}
647
648 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100649 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200650 return 1
651 fi
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200652 if [ $# -gt 1 ]; then
653 body=${res:0:${#res}-3}
654 targetJson="["
655 if [ $2 != "EMPTY" ]; then
656 for pid in ${@:2} ; do
657 if [ "$targetJson" != "[" ]; then
658 targetJson=$targetJson","
659 fi
660 targetJson=$targetJson"\"$pid\""
661 done
662 fi
663 targetJson=$targetJson"]"
664 echo " TARGET JSON: $targetJson" >> $HTTPLOG
665 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200666
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200667 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100668 __log_test_fail_body
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200669 return 1
670 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200671 fi
672
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100673 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200674 return 0
675}
676
677# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200678# args: <response-code> <type-id> <job-id> [<status>]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100679# args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200680# (Function for test scripts)
681ecs_api_a1_get_job_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100682 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200683
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100684 if [ -z "$FLAT_A1_EI" ]; then
685 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
686 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
687 return 1
688 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200689
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100690 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200691
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100692 res="$(__do_curl_to_api ECS GET $query)"
693 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200694
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100695 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100696 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200697 return 1
698 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100699 if [ $# -eq 4 ]; then
700 body=${res:0:${#res}-3}
701 targetJson="{\"operationalState\": \"$4\"}"
702 echo " TARGET JSON: $targetJson" >> $HTTPLOG
703 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
704
705 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100706 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100707 return 1
708 fi
709 fi
710 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100711 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100712 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
713 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100714 return 1
715 fi
716
717 query="/A1-EI/v1/eijobs/$2/status"
718
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100719 start=$SECONDS
720 for (( ; ; )); do
721 res="$(__do_curl_to_api ECS GET $query)"
722 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100723
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100724 if [ $# -eq 4 ]; then
725 duration=$((SECONDS-start))
726 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
727 if [ $duration -gt $4 ]; then
728 echo ""
729 duration=-1 #Last iteration
730 fi
731 else
732 duration=-1 #single test, no wait
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100733 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100734
735 if [ $status -ne $1 ]; then
736 if [ $duration -eq -1 ]; then
737 __log_test_fail_status_code $1 $status
738 return 1
739 fi
740 fi
741 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
742 body=${res:0:${#res}-3}
743 targetJson="{\"eiJobStatus\": \"$3\"}"
744 echo " TARGET JSON: $targetJson" >> $HTTPLOG
745 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
746
747 if [ $res -ne 0 ]; then
748 if [ $duration -eq -1 ]; then
749 __log_test_fail_body
750 return 1
751 fi
752 else
753 duration=-1 #Goto pass
754 fi
755 fi
756 if [ $duration -eq -1 ]; then
757 if [ $# -eq 4 ]; then
758 echo ""
759 fi
760 __log_test_pass
761 return 0
762 else
763 sleep 1
764 fi
765 done
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200766 fi
767
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100768 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200769 return 0
770}
771
772# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200773# args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100774# args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200775# (Function for test scripts)
776ecs_api_a1_get_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100777 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200778
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100779 if [ -z "$FLAT_A1_EI" ]; then
780 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
781 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
782 return 1
783 fi
784 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
785 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100786 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100787 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
788 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
789 return 1
790 fi
791 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200792 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200793 res="$(__do_curl_to_api ECS GET $query)"
794 status=${res:${#res}-3}
795
796 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100797 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200798 return 1
799 fi
800
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100801 if [ -z "$FLAT_A1_EI" ]; then
802 if [ $# -eq 6 ]; then
803 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200804
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100805 if [ -f $6 ]; then
806 jobfile=$(cat $6)
807 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
808 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100809 _log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100810 return 1
811 fi
812 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
813 echo " TARGET JSON: $targetJson" >> $HTTPLOG
814 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
815
816 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100817 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100818 return 1
819 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200820 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100821 else
822 if [ $# -eq 7 ]; then
823 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200824
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100825 if [ -f $7 ]; then
826 jobfile=$(cat $7)
827 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
828 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100829 _log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100830 return 1
831 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100832 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100833 echo " TARGET JSON: $targetJson" >> $HTTPLOG
834 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
835
836 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100837 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100838 return 1
839 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200840 fi
841 fi
842
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100843 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200844 return 0
845}
846
847# API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200848# args: <response-code> <type-id> <job-id>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100849# args (flat uri structure): <response-code> <job-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200850# (Function for test scripts)
851ecs_api_a1_delete_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100852 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200853
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100854 if [ -z "$FLAT_A1_EI" ]; then
855 if [ $# -ne 3 ]; then
856 __print_err "<response-code> <type-id> <job-id>" $@
857 return 1
858 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200859
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100860 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
861 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100862 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100863 if [ $# -ne 2 ]; then
864 __print_err "<response-code> <job-id>" $@
865 return 1
866 fi
867 query="/A1-EI/v1/eijobs/$2"
868 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200869 res="$(__do_curl_to_api ECS DELETE $query)"
870 status=${res:${#res}-3}
871
872 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100873 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200874 return 1
875 fi
876
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100877 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200878 return 0
879}
880
881# API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200882# args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100883# 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 +0200884# (Function for test scripts)
885ecs_api_a1_put_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100886 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200887
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100888 if [ -z "$FLAT_A1_EI" ]; then
889 if [ $# -lt 6 ]; then
890 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
891 return 1
892 fi
893 if [ -f $6 ]; then
894 jobfile=$(cat $6)
895 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
896 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100897 _log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100898 return 1
899 fi
900
901 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
902 file="./tmp/.p.json"
903 echo "$inputJson" > $file
904
905 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200906 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100907 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100908 if [ $# -lt 7 ]; then
909 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
910 return 1
911 fi
912 if [ -f $7 ]; then
913 jobfile=$(cat $7)
914 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
915 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100916 _log_test_fail_general "Job template file "$7", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100917 return 1
918 fi
919
920 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
921 file="./tmp/.p.json"
922 echo "$inputJson" > $file
923
924 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200925 fi
926
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200927 res="$(__do_curl_to_api ECS PUT $query $file)"
928 status=${res:${#res}-3}
929
930 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100931 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200932 return 1
933 fi
934
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100935 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200936 return 0
937}
938
939
940##########################################
941#### Enrichment Data Producer API ####
942##########################################
943# Function prefix: ecs_api_edp
944
945# API Test function: GET /ei-producer/v1/eitypes
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200946# args: <response-code> [ EMPTY | <type-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200947# (Function for test scripts)
948ecs_api_edp_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100949 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200950
951 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200952 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200953 return 1
954 fi
955
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200956 query="/ei-producer/v1/eitypes"
957 res="$(__do_curl_to_api ECS GET $query)"
958 status=${res:${#res}-3}
959
960 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100961 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200962 return 1
963 fi
964
965 if [ $# -gt 1 ]; then
966 body=${res:0:${#res}-3}
967 targetJson="["
968 if [ $2 != "EMPTY" ]; then
969 for pid in ${@:2} ; do
970 if [ "$targetJson" != "[" ]; then
971 targetJson=$targetJson","
972 fi
973 targetJson=$targetJson"\"$pid\""
974 done
975 fi
976 targetJson=$targetJson"]"
977 echo " TARGET JSON: $targetJson" >> $HTTPLOG
978 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
979
980 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100981 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200982 return 1
983 fi
984 fi
985
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100986 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200987 return 0
988}
989
990# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100991# args: <response-code> <producer-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200992# (Function for test scripts)
993ecs_api_edp_get_producer_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100994 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200995
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100996 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
997 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200998 return 1
999 fi
1000
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001001 query="/ei-producer/v1/eiproducers/$2/status"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001002 start=$SECONDS
1003 for (( ; ; )); do
1004 res="$(__do_curl_to_api ECS GET $query)"
1005 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001006
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001007 if [ $# -eq 4 ]; then
1008 duration=$((SECONDS-start))
1009 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
1010 if [ $duration -gt $4 ]; then
1011 echo ""
1012 duration=-1 #Last iteration
1013 fi
1014 else
1015 duration=-1 #single test, no wait
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001016 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001017
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001018 if [ $status -ne $1 ]; then
1019 if [ $duration -eq -1 ]; then
1020 __log_test_fail_status_code $1 $status
1021 return 1
1022 fi
1023 fi
1024 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1025 body=${res:0:${#res}-3}
1026 targetJson="{\"operational_state\": \"$3\"}"
1027 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1028 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1029
1030 if [ $res -ne 0 ]; then
1031 if [ $duration -eq -1 ]; then
1032 __log_test_fail_body
1033 return 1
1034 fi
1035 else
1036 duration=-1 #Goto pass
1037 fi
1038 fi
1039 if [ $duration -eq -1 ]; then
1040 if [ $# -eq 4 ]; then
1041 echo ""
1042 fi
1043 __log_test_pass
1044 return 0
1045 else
1046 sleep 1
1047 fi
1048 done
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001049}
1050
1051
1052# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001053# args (v1_1): <response-code> [ EMPTY | <producer-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001054# (Function for test scripts)
1055ecs_api_edp_get_producer_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001056 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001057
1058 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001059 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001060 return 1
1061 fi
1062
1063 query="/ei-producer/v1/eiproducers"
1064 res="$(__do_curl_to_api ECS GET $query)"
1065 status=${res:${#res}-3}
1066
1067 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001068 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001069 return 1
1070 fi
1071
1072 if [ $# -gt 1 ]; then
1073 body=${res:0:${#res}-3}
1074 targetJson="["
1075
1076 for pid in ${@:2} ; do
1077 if [ "$targetJson" != "[" ]; then
1078 targetJson=$targetJson","
1079 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001080 if [ $pid != "EMPTY" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001081 targetJson=$targetJson"\"$pid\""
1082 fi
1083 done
1084
1085 targetJson=$targetJson"]"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001086 echo " TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001087 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1088
1089 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001090 __log_test_fail_body
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001091 return 1
1092 fi
1093 fi
1094
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001095 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001096 return 0
1097}
1098
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001099# API Test function: GET /ei-producer/v1/eiproducers
1100# args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1101# (Function for test scripts)
1102ecs_api_edp_get_producer_ids_2() {
1103 __log_test_start $@
1104
1105 if [ $# -lt 1 ]; then
1106 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1107 return 1
1108 fi
1109
1110 query="/ei-producer/v1/eiproducers"
1111 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1112 query=$query"?ei_type_id=$2"
1113 fi
1114 res="$(__do_curl_to_api ECS GET $query)"
1115 status=${res:${#res}-3}
1116
1117 if [ $status -ne $1 ]; then
1118 __log_test_fail_status_code $1 $status
1119 return 1
1120 fi
1121
1122 if [ $# -gt 2 ]; then
1123 body=${res:0:${#res}-3}
1124 targetJson="["
1125
1126 for pid in ${@:3} ; do
1127 if [ "$targetJson" != "[" ]; then
1128 targetJson=$targetJson","
1129 fi
1130 if [ $pid != "EMPTY" ]; then
1131 targetJson=$targetJson"\"$pid\""
1132 fi
1133 done
1134
1135 targetJson=$targetJson"]"
1136 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1137 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1138
1139 if [ $res -ne 0 ]; then
1140 __log_test_fail_body
1141 return 1
1142 fi
1143 fi
1144
1145 __log_test_pass
1146 return 0
1147}
1148
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001149# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001150# args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001151# (Function for test scripts)
1152ecs_api_edp_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001153 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001154
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001155 paramError=1
1156 if [ $# -eq 2 ]; then
1157 paramError=0
1158 fi
1159 if [ $# -gt 3 ]; then
1160 paramError=0
1161 fi
1162 if [ $paramError -ne 0 ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02001163 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001164 return 1
1165 fi
1166
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001167 query="/ei-producer/v1/eitypes/$2"
1168 res="$(__do_curl_to_api ECS GET $query)"
1169 status=${res:${#res}-3}
1170
1171 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001172 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001173 return 1
1174 fi
1175 if [ $# -gt 3 ]; then
1176 body=${res:0:${#res}-3}
1177
1178 if [ -f $3 ]; then
1179 schema=$(cat $3)
1180 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001181 __log_test_fail_general "Job template file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001182 return 1
1183 fi
1184
1185 targetJson=""
1186 if [ $4 != "EMPTY" ]; then
1187 for pid in ${@:4} ; do
1188 if [ "$targetJson" != "" ]; then
1189 targetJson=$targetJson","
1190 fi
1191 targetJson=$targetJson"\"$pid\""
1192 done
1193 fi
1194 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1195
1196 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1197 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1198
1199 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001200 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001201 return 1
1202 fi
1203 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001204 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001205 return 0
1206}
1207
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001208# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1209# args: (v1_2) <response-code> <type-id> [<job-schema-file> ]
1210# (Function for test scripts)
1211ecs_api_edp_get_type_2() {
1212 __log_test_start $@
1213
1214 paramError=1
1215 if [ $# -eq 2 ]; then
1216 paramError=0
1217 fi
1218 if [ $# -eq 3 ]; then
1219 paramError=0
1220 fi
1221 if [ $paramError -ne 0 ]; then
1222 __print_err "<response-code> <type-id> [<job-schema-file> ]" $@
1223 return 1
1224 fi
1225
1226 query="/ei-producer/v1/eitypes/$2"
1227 res="$(__do_curl_to_api ECS GET $query)"
1228 status=${res:${#res}-3}
1229
1230 if [ $status -ne $1 ]; then
1231 __log_test_fail_status_code $1 $status
1232 return 1
1233 fi
1234 if [ $# -eq 3 ]; then
1235 body=${res:0:${#res}-3}
1236
1237 if [ -f $3 ]; then
1238 schema=$(cat $3)
1239 else
1240 __log_test_fail_general "Job template file "$3", does not exist"
1241 return 1
1242 fi
1243
1244 targetJson="{\"ei_job_data_schema\":$schema}"
1245
1246 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1247 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1248
1249 if [ $res -ne 0 ]; then
1250 __log_test_fail_body
1251 return 1
1252 fi
1253 fi
1254 __log_test_pass
1255 return 0
1256}
1257
1258# API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1259# args: (v1_2) <response-code> <type-id> <job-schema-file>
1260# (Function for test scripts)
1261ecs_api_edp_put_type_2() {
1262 __log_test_start $@
1263
1264 if [ $# -ne 3 ]; then
1265 __print_err "<response-code> <type-id> <job-schema-file>" $@
1266 return 1
1267 fi
1268
1269 if [ ! -f $3 ]; then
1270 __log_test_fail_general "Job schema file "$3", does not exist"
1271 return 1
1272 fi
1273 schema=$(cat $3)
1274 input_json="{\"ei_job_data_schema\":$schema}"
1275 file="./tmp/put_type.json"
1276 echo $input_json > $file
1277
1278 query="/ei-producer/v1/eitypes/$2"
1279 res="$(__do_curl_to_api ECS PUT $query $file)"
1280 status=${res:${#res}-3}
1281
1282 if [ $status -ne $1 ]; then
1283 __log_test_fail_status_code $1 $status
1284 return 1
1285 fi
1286
1287 __log_test_pass
1288 return 0
1289}
1290
1291# API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1292# args: (v1_2) <response-code> <type-id>
1293# (Function for test scripts)
1294ecs_api_edp_delete_type_2() {
1295 __log_test_start $@
1296
1297 if [ $# -ne 2 ]; then
1298 __print_err "<response-code> <type-id>" $@
1299 return 1
1300 fi
1301
1302 query="/ei-producer/v1/eitypes/$2"
1303 res="$(__do_curl_to_api ECS DELETE $query)"
1304 status=${res:${#res}-3}
1305
1306 if [ $status -ne $1 ]; then
1307 __log_test_fail_status_code $1 $status
1308 return 1
1309 fi
1310
1311 __log_test_pass
1312 return 0
1313}
1314
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001315# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001316# args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001317# (Function for test scripts)
1318ecs_api_edp_get_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001319 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001320
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001321 #Possible arg count: 2, 5 6, 8, 10 etc
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001322 paramError=1
1323 if [ $# -eq 2 ]; then
1324 paramError=0
1325 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001326 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001327 paramError=0
1328 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001329 variablecount=$(($#-4))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001330 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1331 paramError=0
1332 fi
1333
1334 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001335 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001336 return 1
1337 fi
1338
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001339 query="/ei-producer/v1/eiproducers/$2"
1340 res="$(__do_curl_to_api ECS GET $query)"
1341 status=${res:${#res}-3}
1342
1343 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001344 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001345 return 1
1346 fi
1347
1348 if [ $# -gt 2 ]; then
1349 body=${res:0:${#res}-3}
1350 targetJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001351 if [ $# -gt 5 ]; then
1352 arr=(${@:5})
1353 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001354 if [ "$targetJson" != "[" ]; then
1355 targetJson=$targetJson","
1356 fi
1357 if [ -f ${arr[$i+1]} ]; then
1358 schema=$(cat ${arr[$i+1]})
1359 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001360 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001361 return 1
1362 fi
1363
1364 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1365 done
1366 fi
1367 targetJson=$targetJson"]"
1368 if [ $# -gt 4 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001369 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001370 fi
1371 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1372 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1373
1374 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001375 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001376 return 1
1377 fi
1378 fi
1379
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001380 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001381 return 0
1382}
1383
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001384# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1385# args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1386# (Function for test scripts)
1387ecs_api_edp_get_producer_2() {
1388 __log_test_start $@
1389
1390 #Possible arg count: 2, 5, 6, 7, 8 etc
1391 paramError=1
1392 if [ $# -eq 2 ]; then
1393 paramError=0
1394 fi
1395 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1396 paramError=0
1397 fi
1398 if [ $# -ge 5 ]; then
1399 paramError=0
1400 fi
1401
1402 if [ $paramError -ne 0 ]; then
1403 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1404 return 1
1405 fi
1406
1407 query="/ei-producer/v1/eiproducers/$2"
1408 res="$(__do_curl_to_api ECS GET $query)"
1409 status=${res:${#res}-3}
1410
1411 if [ $status -ne $1 ]; then
1412 __log_test_fail_status_code $1 $status
1413 return 1
1414 fi
1415
1416 if [ $# -gt 2 ]; then
1417 body=${res:0:${#res}-3}
1418 targetJson="["
1419 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1420 arr=(${@:5})
1421 for ((i=0; i<$(($#-4)); i=i+1)); do
1422 if [ "$targetJson" != "[" ]; then
1423 targetJson=$targetJson","
1424 fi
1425 targetJson=$targetJson"\"${arr[$i]}\""
1426 done
1427 fi
1428 targetJson=$targetJson"]"
1429 if [ $# -gt 4 ]; then
1430 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1431 fi
1432 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1433 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1434
1435 if [ $res -ne 0 ]; then
1436 __log_test_fail_body
1437 return 1
1438 fi
1439 fi
1440
1441 __log_test_pass
1442 return 0
1443}
1444
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001445# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001446# args: <response-code> <producer-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001447# (Function for test scripts)
1448ecs_api_edp_delete_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001449 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001450
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001451 if [ $# -lt 2 ]; then
1452 __print_err "<response-code> <producer-id>" $@
1453 return 1
1454 fi
1455
1456 query="/ei-producer/v1/eiproducers/$2"
1457 res="$(__do_curl_to_api ECS DELETE $query)"
1458 status=${res:${#res}-3}
1459
1460 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001461 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001462 return 1
1463 fi
1464
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001465 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001466 return 0
1467}
1468
1469# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001470# args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001471# (Function for test scripts)
1472ecs_api_edp_put_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001473 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001474
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001475 #Valid number of parametrer 5,6,8,10,
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001476 paramError=1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001477 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001478 paramError=0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001479 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001480 paramError=0
1481 fi
1482 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001483 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001484 return 1
1485 fi
1486
1487 inputJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001488 if [ $# -gt 5 ]; then
1489 arr=(${@:5})
1490 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001491 if [ "$inputJson" != "[" ]; then
1492 inputJson=$inputJson","
1493 fi
1494 if [ -f ${arr[$i+1]} ]; then
1495 schema=$(cat ${arr[$i+1]})
1496 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001497 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001498 return 1
1499 fi
1500 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1501 done
1502 fi
1503 inputJson="\"supported_ei_types\":"$inputJson"]"
1504
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001505 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001506
1507 inputJson="{"$inputJson"}"
1508
1509 file="./tmp/.p.json"
1510 echo "$inputJson" > $file
1511 query="/ei-producer/v1/eiproducers/$2"
1512 res="$(__do_curl_to_api ECS PUT $query $file)"
1513 status=${res:${#res}-3}
1514
1515 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001516 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001517 return 1
1518 fi
1519
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001520 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001521 return 0
1522}
1523
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001524# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1525# args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1526# (Function for test scripts)
1527ecs_api_edp_put_producer_2() {
1528 __log_test_start $@
1529
1530 #Valid number of parametrer 5,6,8,10,
1531 paramError=1
1532 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1533 paramError=0
1534 elif [ $# -ge 5 ]; then
1535 paramError=0
1536 fi
1537 if [ $paramError -ne 0 ]; then
1538 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1539 return 1
1540 fi
1541
1542 inputJson="["
1543 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1544 arr=(${@:5})
1545 for ((i=0; i<$(($#-4)); i=i+1)); do
1546 if [ "$inputJson" != "[" ]; then
1547 inputJson=$inputJson","
1548 fi
1549 inputJson=$inputJson"\""${arr[$i]}"\""
1550 done
1551 fi
1552 inputJson="\"supported_ei_types\":"$inputJson"]"
1553
1554 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1555
1556 inputJson="{"$inputJson"}"
1557
1558 file="./tmp/.p.json"
1559 echo "$inputJson" > $file
1560 query="/ei-producer/v1/eiproducers/$2"
1561 res="$(__do_curl_to_api ECS PUT $query $file)"
1562 status=${res:${#res}-3}
1563
1564 if [ $status -ne $1 ]; then
1565 __log_test_fail_status_code $1 $status
1566 return 1
1567 fi
1568
1569 __log_test_pass
1570 return 0
1571}
1572
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001573# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001574# 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 +02001575# (Function for test scripts)
1576ecs_api_edp_get_producer_jobs() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001577 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001578
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001579 #Valid number of parameter 2,3,7,11
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001580 paramError=1
1581 if [ $# -eq 2 ]; then
1582 paramError=0
1583 fi
1584 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1585 paramError=0
1586 fi
1587 variablecount=$(($#-2))
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001588 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001589 paramError=0
1590 fi
1591 if [ $paramError -eq 1 ]; then
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001592 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001593 return 1
1594 fi
1595
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001596 query="/ei-producer/v1/eiproducers/$2/eijobs"
1597 res="$(__do_curl_to_api ECS GET $query)"
1598 status=${res:${#res}-3}
1599 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001600 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001601 return 1
1602 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001603 if [ $# -gt 2 ]; then
1604 body=${res:0:${#res}-3}
1605 targetJson="["
1606 if [ $# -gt 3 ]; then
1607 arr=(${@:3})
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001608 for ((i=0; i<$(($#-3)); i=i+5)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001609 if [ "$targetJson" != "[" ]; then
1610 targetJson=$targetJson","
1611 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001612 if [ -f ${arr[$i+4]} ]; then
1613 jobfile=$(cat ${arr[$i+4]})
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001614 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1615 else
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001616 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001617 return 1
1618 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001619 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 +02001620 done
1621 fi
1622 targetJson=$targetJson"]"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001623
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001624 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1625 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001626
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001627 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001628 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001629 return 1
1630 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001631 fi
1632
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001633 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001634 return 0
1635}
1636
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001637# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1638# args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1639# (Function for test scripts)
1640ecs_api_edp_get_producer_jobs_2() {
1641 __log_test_start $@
1642
1643 #Valid number of parameter 2,3,7,11
1644 paramError=1
1645 if [ $# -eq 2 ]; then
1646 paramError=0
1647 fi
1648 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1649 paramError=0
1650 fi
1651 variablecount=$(($#-2))
1652 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1653 paramError=0
1654 fi
1655 if [ $paramError -eq 1 ]; then
1656 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1657 return 1
1658 fi
1659
1660 query="/ei-producer/v1/eiproducers/$2/eijobs"
1661 res="$(__do_curl_to_api ECS GET $query)"
1662 status=${res:${#res}-3}
1663 if [ $status -ne $1 ]; then
1664 __log_test_fail_status_code $1 $status
1665 return 1
1666 fi
1667 if [ $# -gt 2 ]; then
1668 body=${res:0:${#res}-3}
1669 targetJson="["
1670 if [ $# -gt 3 ]; then
1671 arr=(${@:3})
1672 for ((i=0; i<$(($#-3)); i=i+5)); do
1673 if [ "$targetJson" != "[" ]; then
1674 targetJson=$targetJson","
1675 fi
1676 if [ -f ${arr[$i+4]} ]; then
1677 jobfile=$(cat ${arr[$i+4]})
1678 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1679 else
1680 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1681 return 1
1682 fi
1683 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\":\"????\"}"
1684 done
1685 fi
1686 targetJson=$targetJson"]"
1687
1688 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1689 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1690
1691 if [ $res -ne 0 ]; then
1692 __log_test_fail_body
1693 return 1
1694 fi
1695 fi
1696
1697 __log_test_pass
1698 return 0
1699}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001700
1701##########################################
1702#### Service status ####
1703##########################################
1704# Function prefix: ecs_api_service
1705
1706# API Test function: GET ​/status
1707# args: <response-code>
1708# (Function for test scripts)
1709ecs_api_service_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001710 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001711
1712 if [ $# -lt 1 ]; then
1713 __print_err "<response-code> [<producer-id>]*|NOID" $@
1714 return 1
1715 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001716 res="$(__do_curl_to_api ECS GET /status)"
1717 status=${res:${#res}-3}
1718 if [ $status -ne $1 ]; then
1719 __log_test_fail_status_code $1 $status
1720 return 1
1721 fi
1722 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001723 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001724}
1725
1726
1727##########################################
1728#### Reset jobs ####
1729##########################################
1730# Function prefix: ecs_api_admin
1731
1732# Admin to remove all jobs
BjornMagnussonXA366e36a2021-01-27 11:48:56 +01001733# args: <response-code> [ <type> ]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001734# (Function for test scripts)
1735
1736ecs_api_admin_reset() {
1737 __log_test_start $@
1738
1739 if [ -z "$FLAT_A1_EI" ]; then
1740 query="/A1-EI/v1/eitypes/$2/eijobs"
1741 else
1742 query="/A1-EI/v1/eijobs"
1743 fi
1744 res="$(__do_curl_to_api ECS GET $query)"
1745 status=${res:${#res}-3}
1746
1747 if [ $status -ne 200 ]; then
1748 __log_test_fail_status_code $1 $status
1749 return 1
1750 fi
1751
1752 #Remove brackets and response code
1753 body=${res:1:${#res}-4}
1754 list=$(echo ${body//,/ })
1755 list=$(echo ${list//[/})
1756 list=$(echo ${list//]/})
1757 list=$(echo ${list//\"/})
1758 list=$list" "
1759 for job in $list; do
1760 if [ -z "$FLAT_A1_EI" ]; then
1761 echo "Not supported for non-flat EI api"
1762 else
1763 query="/A1-EI/v1/eijobs/$job"
1764 res="$(__do_curl_to_api ECS DELETE $query)"
1765 status=${res:${#res}-3}
1766 if [ $status -ne 204 ]; then
1767 __log_test_fail_status_code $1 $status
1768 return 1
1769 fi
1770 echo " Deleted job: "$job
1771 fi
1772 done
1773
1774 __log_test_pass
1775 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02001776}
1777
1778##########################################
1779#### Reset jobs and producers ####
1780##########################################
1781
1782
1783# Admin reset to remove all data in ecs; jobs, producers etc
1784# NOTE - only works in kubernetes and the pod should not be running
1785# args: -
1786# (Function for test scripts)
1787
1788ecs_kube_pvc_reset() {
1789 __log_test_start $@
1790
1791 __kube_clean_pvc $ECS_APP_NAME nonrtric enrichmentservice-pvc /var/enrichment-coordinator-service/database
1792
1793 __log_test_pass
1794 return 0
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001795}