Added JWT handling to a1pms
[nonrtric.git] / test / common / ics_api_functions.sh
1 #!/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
20 # This is a script that contains container/service management functions and test functions for ICS
21
22 ################ 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 __ICS_imagesetup() {
28         __check_and_create_image_var ICS "ICS_IMAGE" "ICS_IMAGE_BASE" "ICS_IMAGE_TAG" $1 "$ICS_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 __ICS_imagepull() {
37         __check_and_pull_image $1 "$ICS_DISPLAY_NAME" $ICS_APP_NAME ICS_IMAGE
38 }
39
40 # Build image (only for simulator or interfaces stubs owned by the test environment)
41 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
42 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
43 __ICS_imagebuild() {
44         echo -e $RED" Image for app ICS shall never be built"$ERED
45 }
46
47 # Generate a string for each included image using the app display name and a docker images format string
48 # If a custom image repo is used then also the source image from the local repo is listed
49 # arg: <docker-images-format-string> <file-to-append>
50 __ICS_image_data() {
51         echo -e "$ICS_DISPLAY_NAME\t$(docker images --format $1 $ICS_IMAGE)" >>   $2
52         if [ ! -z "$ICS_IMAGE_SOURCE" ]; then
53                 echo -e "-- source image --\t$(docker images --format $1 $ICS_IMAGE_SOURCE)" >>   $2
54         fi
55 }
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 __ICS_kube_scale_zero() {
61         __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS
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 __ICS_kube_scale_zero_and_wait() {
67         __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-informationservice
68 }
69
70 # Delete all kube resouces for the app
71 # This function is called for apps managed by the test script.
72 __ICS_kube_delete_all() {
73         __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS
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 __ICS_store_docker_logs() {
80         if [ $RUNMODE == "KUBE" ]; then
81                 kubectl $KUBECONF  logs -l "autotest=ICS" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_ics.log 2>&1
82         else
83                 docker logs $ICS_APP_NAME > $1$2_ics.log 2>&1
84         fi
85 }
86
87 # Initial setup of protocol, host and ports
88 # This function is called for apps managed by the test script.
89 # args: -
90 __ICS_initial_setup() {
91         use_ics_rest_http
92         export ICS_SIDECAR_JWT_FILE=""
93 }
94
95 # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
96 # For docker, the namespace shall be excluded
97 # This function is called for apps managed by the test script as well as for prestarted apps.
98 # args: -
99 __ICS_statisics_setup() {
100         if [ $RUNMODE == "KUBE" ]; then
101                 echo "ICS $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
102         else
103                 echo "ICS $ICS_APP_NAME"
104         fi
105 }
106
107 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
108 # args: -
109 __ICS_test_requirements() {
110         :
111 }
112
113 #######################################################
114
115
116 # Make curl retries towards ICS for http response codes set in this env var, space separated list of codes
117 ICS_RETRY_CODES=""
118
119 #Save first worker node the pod is started on
120 __ICS_WORKER_NODE=""
121
122 ###########################
123 ### ICS functions
124 ###########################
125
126 # All calls to ICS will be directed to the ICS REST interface from now on
127 # args: -
128 # (Function for test scripts)
129 use_ics_rest_http() {
130         __ics_set_protocoll "http" $ICS_INTERNAL_PORT $ICS_EXTERNAL_PORT
131 }
132
133 # All calls to ICS will be directed to the ICS REST interface from now on
134 # args: -
135 # (Function for test scripts)
136 use_ics_rest_https() {
137         __ics_set_protocoll "https" $ICS_INTERNAL_SECURE_PORT $ICS_EXTERNAL_SECURE_PORT
138 }
139
140 # All calls to ICS will be directed to the ICS dmaap interface over http from now on
141 # args: -
142 # (Function for test scripts)
143 use_ics_dmaap_http() {
144         echo -e $BOLD"ICS dmaap protocol setting"$EBOLD
145         echo -e $RED" - NOT SUPPORTED - "$ERED
146         echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ICS"
147         ICS_ADAPTER_TYPE="MR-HTTP"
148         echo ""
149 }
150
151 # Setup paths to svc/container for internal and external access
152 # args: <protocol> <internal-port> <external-port>
153 __ics_set_protocoll() {
154         echo -e $BOLD"$ICS_DISPLAY_NAME protocol setting"$EBOLD
155         echo -e " Using $BOLD $1 $EBOLD towards $ICS_DISPLAY_NAME"
156
157         ## Access to ICS
158
159         ICS_SERVICE_PATH=$1"://"$ICS_APP_NAME":"$2  # docker access, container->container and script->container via proxy
160         if [ $RUNMODE == "KUBE" ]; then
161                 ICS_SERVICE_PATH=$1"://"$ICS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
162         fi
163
164         # ICS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
165         ICS_ADAPTER_TYPE="REST"
166         ICS_ADAPTER=$ICS_SERVICE_PATH
167
168         echo ""
169 }
170
171 # Export env vars for config files, docker compose and kube resources
172 # args: PROXY|NOPROXY
173 __ics_export_vars() {
174                 export ICS_APP_NAME
175                 export ICS_APP_NAME_ALIAS
176                 export KUBE_NONRTRIC_NAMESPACE
177                 export ICS_IMAGE
178                 export ICS_INTERNAL_PORT
179                 export ICS_INTERNAL_SECURE_PORT
180                 export ICS_EXTERNAL_PORT
181                 export ICS_EXTERNAL_SECURE_PORT
182                 export ICS_CONFIG_MOUNT_PATH
183                 export ICS_CONFIG_CONFIGMAP_NAME=$ICS_APP_NAME"-config"
184                 export ICS_DATA_CONFIGMAP_NAME=$ICS_APP_NAME"-data"
185                 export ICS_CONTAINER_MNT_DIR
186                 export ICS_HOST_MNT_DIR
187                 export ICS_CONFIG_FILE
188                 export DOCKER_SIM_NWNAME
189                 export ICS_DISPLAY_NAME
190                 export ICS_LOGPATH
191
192                 export ICS_DATA_PV_NAME=$ICS_APP_NAME"-pv"
193                 export ICS_DATA_PVC_NAME=$ICS_APP_NAME"-pvc"
194                 #Create a unique path for the pv each time to prevent a previous volume to be reused
195                 export ICS_PV_PATH="icsdata-"$(date +%s)
196                 export HOST_PATH_BASE_DIR
197
198                 if [ $1 == "PROXY" ]; then
199                         export ICS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT  #Set if proxy is started
200                         export ICS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
201                         if [ $ICS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ICS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
202                                 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
203                         else
204                                 echo " Configured with http proxy"
205                         fi
206                 else
207                         export ICS_HTTP_PROXY_CONFIG_PORT=0
208                         export ICS_HTTP_PROXY_CONFIG_HOST_NAME=""
209                         echo " Configured without http proxy"
210                 fi
211 }
212
213
214 # Start the ICS
215 # args: PROXY|NOPROXY <config-file>
216 # (Function for test scripts)
217 start_ics() {
218
219         echo -e $BOLD"Starting $ICS_DISPLAY_NAME"$EBOLD
220
221         if [ $RUNMODE == "KUBE" ]; then
222
223                 # Check if app shall be fully managed by the test script
224                 __check_included_image "ICS"
225                 retcode_i=$?
226
227                 # Check if app shall only be used by the testscipt
228                 __check_prestarted_image "ICS"
229                 retcode_p=$?
230
231                 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
232                         echo -e $RED"The $ICS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
233                         echo -e $RED"The $ICS_APP_NAME will not be started"$ERED
234                         exit
235                 fi
236                 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
237                         echo -e $RED"The $ICS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
238                         echo -e $RED"The $ICS_APP_NAME will not be started"$ERED
239                         exit
240                 fi
241
242                 if [ $retcode_p -eq 0 ]; then
243                         echo -e " Using existing $ICS_APP_NAME deployment and service"
244                         echo " Setting ICS replicas=1"
245                         res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
246                         __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
247                 fi
248
249                 # Check if app shall be fully managed by the test script
250                 if [ $retcode_i -eq 0 ]; then
251                         echo -e " Creating $ICS_APP_NAME app and expose service"
252
253                         #Check if nonrtric namespace exists, if not create it
254                         __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
255
256                         __ics_export_vars $1
257
258                         # Create config map for config
259                         datafile=$PWD/tmp/$ICS_CONFIG_FILE
260                         cp $2 $datafile
261                         output_yaml=$PWD/tmp/ics_cfc.yaml
262                         __kube_create_configmap $ICS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ICS $datafile $output_yaml
263
264                         # Create pv
265                         input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"pv.yaml
266                         output_yaml=$PWD/tmp/ics_pv.yaml
267                         __kube_create_instance pv $ICS_APP_NAME $input_yaml $output_yaml
268
269                         # Create pvc
270                         input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"pvc.yaml
271                         output_yaml=$PWD/tmp/ics_pvc.yaml
272                         __kube_create_instance pvc $ICS_APP_NAME $input_yaml $output_yaml
273
274                         # Create service
275                         input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"svc.yaml
276                         output_yaml=$PWD/tmp/ics_svc.yaml
277                         __kube_create_instance service $ICS_APP_NAME $input_yaml $output_yaml
278
279                         # Create app
280                         input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"app.yaml
281                         output_yaml=$PWD/tmp/ics_app.yaml
282                         if [ -z "$ICS_SIDECAR_JWT_FILE" ]; then
283                                 cat $input_yaml | sed  '/#ICS_JWT_START/,/#ICS_JWT_STOP/d' > $PWD/tmp/ics_app_tmp.yaml
284                                 input_yaml=$PWD/tmp/ics_app_tmp.yaml
285                         fi
286                         __kube_create_instance app $ICS_APP_NAME $input_yaml $output_yaml
287                 fi
288
289                 # Tie the ICS to a worker node so that ICS will always be scheduled to the same worker node if the ICS pod is restarted
290                 # A PVC of type hostPath is mounted to ICS, for persistent storage, so the ICS must always be on the node which mounted the volume
291
292                 # 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
293                 if [ $retcode_i -eq 0 ]; then
294                         __ICS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=ICS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
295                         if [ -z "$__ICS_WORKER_NODE" ]; then
296                                 echo -e $YELLOW" Cannot find worker node for pod for $ICS_APP_NAME, persistency may not work"$EYELLOW
297                         fi
298                 else
299                         echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
300                 fi
301
302
303                 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
304
305         else
306                 __check_included_image 'ICS'
307                 if [ $? -eq 1 ]; then
308                         echo -e $RED"The ICS app is not included in this test script"$ERED
309                         echo -e $RED"ICS will not be started"$ERED
310                         exit 1
311                 fi
312
313                 curdir=$PWD
314                 cd $SIM_GROUP
315                 cd ics
316                 cd $ICS_HOST_MNT_DIR
317                 #cd ..
318                 if [ -d db ]; then
319                         if [ "$(ls -A $DIR)" ]; then
320                                 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
321                                 rm -rf db/*  &> /dev/null
322                                 if [ $? -ne 0 ]; then
323                                         echo -e $RED" Cannot remove database files in: $PWD"$ERED
324                                         exit 1
325                                 fi
326                         fi
327                 else
328                         echo " No files in mounted dir or dir does not exists"
329                         mkdir db
330                 fi
331
332                 cd $curdir
333
334                 __ics_export_vars $1
335
336                 dest_file=$SIM_GROUP/$ICS_COMPOSE_DIR/$ICS_HOST_MNT_DIR/$ICS_CONFIG_FILE
337
338                 envsubst < $2 > $dest_file
339
340                 __start_container $ICS_COMPOSE_DIR "" NODOCKERARGS 1 $ICS_APP_NAME
341
342                 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
343         fi
344         echo ""
345         return 0
346 }
347
348 # Stop the ics
349 # args: -
350 # args: -
351 # (Function for test scripts)
352 stop_ics() {
353         echo -e $BOLD"Stopping $ICS_DISPLAY_NAME"$EBOLD
354
355         if [ $RUNMODE == "KUBE" ]; then
356
357                 __check_prestarted_image "ICS"
358                 if [ $? -eq 0 ]; then
359                         echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
360                         res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
361                         __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
362                         return 0
363                 fi
364
365                 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS
366                 echo "  Deleting the replica set - a new will be started when the app is started"
367                 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ICS")
368                 if [ $? -ne 0 ]; then
369                         echo -e $RED" Could not delete replica set "$RED
370                         ((RES_CONF_FAIL++))
371                         return 1
372                 fi
373         else
374                 docker stop $ICS_APP_NAME &> ./tmp/.dockererr
375                 if [ $? -ne 0 ]; then
376                         __print_err "Could not stop $ICS_APP_NAME" $@
377                         cat ./tmp/.dockererr
378                         ((RES_CONF_FAIL++))
379                         return 1
380                 fi
381         fi
382         echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
383         echo ""
384         return 0
385 }
386
387 # Start a previously stopped ics
388 # args: -
389 # (Function for test scripts)
390 start_stopped_ics() {
391         echo -e $BOLD"Starting (the previously stopped) $ICS_DISPLAY_NAME"$EBOLD
392
393         if [ $RUNMODE == "KUBE" ]; then
394
395                 __check_prestarted_image "ICS"
396                 if [ $? -eq 0 ]; then
397                         echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
398                         res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
399                         __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
400                         __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
401                         return 0
402                 fi
403
404                 # Tie the ICS to the same worker node it was initially started on
405                 # A PVC of type hostPath is mounted to A1PMS, for persistent storage, so the A1PMS must always be on the node which mounted the volume
406                 if [ -z "$__ICS_WORKER_NODE" ]; then
407                         echo -e $RED" No initial worker node found for pod "$RED
408                         ((RES_CONF_FAIL++))
409                         return 1
410                 else
411                         echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ICS_WORKER_NODE to deployment for $ICS_APP_NAME. Pod will always run on this worker node: $__ICS_WORKER_NODE"$BOLD
412                         echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
413                         tmp=$(kubectl $KUBECONF patch deployment $ICS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ICS_WORKER_NODE'"}}}}}')
414                         if [ $? -ne 0 ]; then
415                                 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ICS_APP_NAME, persistency may not work"$EYELLOW
416                         fi
417                         __kube_scale deployment $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
418                 fi
419         else
420                 docker start $ICS_APP_NAME &> ./tmp/.dockererr
421                 if [ $? -ne 0 ]; then
422                         __print_err "Could not start (the stopped) $ICS_APP_NAME" $@
423                         cat ./tmp/.dockererr
424                         ((RES_CONF_FAIL++))
425                         return 1
426                 fi
427         fi
428         __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
429         if [ $? -ne 0 ]; then
430                 return 1
431         fi
432         echo ""
433         return 0
434 }
435
436 # Turn on debug level tracing in ICS
437 # args: -
438 # (Function for test scripts)
439 set_ics_debug() {
440         echo -e $BOLD"Setting ics debug logging"$EBOLD
441         curlString="$ICS_SERVICE_PATH$ICS_ACTUATOR -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
442         result=$(__do_curl "$curlString")
443         if [ $? -ne 0 ]; then
444                 __print_err "Could not set debug mode" $@
445                 ((RES_CONF_FAIL++))
446                 return 1
447         fi
448         echo ""
449         return 0
450 }
451
452 # Turn on trace level tracing in ICS
453 # args: -
454 # (Function for test scripts)
455 set_ics_trace() {
456         echo -e $BOLD"Setting ics trace logging"$EBOLD
457         curlString="$ICS_SERVICE_PATH$ICS_ACTUATOR -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
458         result=$(__do_curl "$curlString")
459         if [ $? -ne 0 ]; then
460                 __print_err "Could not set trace mode" $@
461                 ((RES_CONF_FAIL++))
462                 return 1
463         fi
464         echo ""
465         return 0
466 }
467
468 # Perform curl retries when making direct call to ICS for the specified http response codes
469 # Speace separated list of http response codes
470 # args: [<response-code>]*
471 use_ics_retries() {
472         echo -e $BOLD"Do curl retries to the ICS REST inteface for these response codes:$@"$EBOLD
473         ICS_RETRY_CODES=$@
474         echo ""
475         return 0
476 }
477
478 # Check the ics logs for WARNINGs and ERRORs
479 # args: -
480 # (Function for test scripts)
481 check_ics_logs() {
482         __check_container_logs "ICS" $ICS_APP_NAME $ICS_LOGPATH WARN ERR
483 }
484
485
486 # Tests if a variable value in the ICS is equal to a target value and and optional timeout.
487 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
488 # equal to the target or not.
489 # Arg: <variable-name> <target-value> <timeout-in-sec>  - This test waits up to the timeout seconds
490 # before setting pass or fail depending on if the variable value becomes equal to the target
491 # value or not.
492 # (Function for test scripts)
493 ics_equal() {
494         if [ $# -eq 2 ] || [ $# -eq 3 ]; then
495                 __var_test ICS "$ICS_SERVICE_PATH/" $1 "=" $2 $3
496         else
497                 __print_err "Wrong args to ics_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
498         fi
499 }
500
501
502 ##########################################
503 ######### A1-E information  API ##########
504 ##########################################
505 #Function prefix: ics_api_a1
506
507 # API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
508 # args: <response-code> <type-id>  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
509 # args (flat uri structure): <response-code> <type-id>|NOTYPE  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
510 # (Function for test scripts)
511 ics_api_a1_get_job_ids() {
512         __log_test_start $@
513
514         if [ -z "$FLAT_A1_EI" ]; then
515                 # Valid number of parameters 4,5,6 etc
516         if [ $# -lt 3 ]; then
517                         __print_err "<response-code> <type-id>  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
518                         return 1
519                 fi
520         else
521                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
522                 # Valid number of parameters 4,5,6 etc
523         if [ $# -lt 3 ]; then
524                         __print_err "<response-code> <type-id>|NOTYPE  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
525                         return 1
526                 fi
527         fi
528         search=""
529         if [ $3 != "NOWNER" ]; then
530                 search="?owner="$3
531         fi
532
533         if [  -z "$FLAT_A1_EI" ]; then
534                 query="/A1-EI/v1/eitypes/$2/eijobs$search"
535         else
536                 if [ $2 != "NOTYPE" ]; then
537                         if [ -z "$search" ]; then
538                                 search="?eiTypeId="$2
539                         else
540                                 search=$search"&eiTypeId="$2
541                         fi
542                 fi
543                 query="/A1-EI/v1/eijobs$search"
544         fi
545     res="$(__do_curl_to_api ICS GET $query)"
546     status=${res:${#res}-3}
547
548         if [ $status -ne $1 ]; then
549                 __log_test_fail_status_code $1 $status
550                 return 1
551         fi
552
553         if [ $# -gt 3 ]; then
554                 body=${res:0:${#res}-3}
555                 targetJson="["
556
557                 for pid in ${@:4} ; do
558                         if [ "$targetJson" != "[" ]; then
559                                 targetJson=$targetJson","
560                         fi
561                         if [ $pid != "EMPTY" ]; then
562                                 targetJson=$targetJson"\"$pid\""
563                         fi
564                 done
565
566                 targetJson=$targetJson"]"
567                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
568                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
569
570                 if [ $res -ne 0 ]; then
571                         __log_test_fail_body
572                         return 1
573                 fi
574         fi
575
576         __log_test_pass
577         return 0
578 }
579
580 # API Test function: GET â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}
581 # args: <response-code> <type-id> [<schema-file>]
582 # (Function for test scripts)
583 ics_api_a1_get_type() {
584         __log_test_start $@
585
586     if [ $# -lt 2 ] || [ $# -gt 3 ]; then
587                 __print_err "<response-code> <type-id> [<schema-file>]" $@
588                 return 1
589         fi
590
591         query="/A1-EI/v1/eitypes/$2"
592     res="$(__do_curl_to_api ICS GET $query)"
593     status=${res:${#res}-3}
594
595         if [ $status -ne $1 ]; then
596                 __log_test_fail_status_code $1 $status
597                 return 1
598         fi
599
600         if [ $# -eq 3 ]; then
601                 body=${res:0:${#res}-3}
602                 if [ -f $3 ]; then
603                         schema=$(cat $3)
604                 else
605                         __log_test_fail_general "Schema file "$3", does not exist"
606                         return 1
607                 fi
608                 if [ -z "$FLAT_A1_EI" ]; then
609                         targetJson="{\"eiJobParametersSchema\":$schema}"
610                 else
611                         targetJson=$schema
612                 fi
613                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
614                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
615
616                 if [ $res -ne 0 ]; then
617                         __log_test_fail_body
618                         return 1
619                 fi
620         fi
621
622         __log_test_pass
623         return 0
624 }
625
626 # API Test function: GET /A1-EI/v1/eitypes
627 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
628 # (Function for test scripts)
629 ics_api_a1_get_type_ids() {
630         __log_test_start $@
631
632     if [ $# -lt 1 ]; then
633                 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
634                 return 1
635         fi
636
637         query="/A1-EI/v1/eitypes"
638     res="$(__do_curl_to_api ICS GET $query)"
639     status=${res:${#res}-3}
640
641         if [ $status -ne $1 ]; then
642                 __log_test_fail_status_code $1 $status
643                 return 1
644         fi
645         if [ $# -gt 1 ]; then
646                 body=${res:0:${#res}-3}
647                 targetJson="["
648                 if [ $2 != "EMPTY" ]; then
649                         for pid in ${@:2} ; do
650                                 if [ "$targetJson" != "[" ]; then
651                                         targetJson=$targetJson","
652                                 fi
653                                 targetJson=$targetJson"\"$pid\""
654                         done
655                 fi
656                 targetJson=$targetJson"]"
657                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
658                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
659
660                 if [ $res -ne 0 ]; then
661                         __log_test_fail_body
662                         return 1
663                 fi
664         fi
665
666         __log_test_pass
667         return 0
668 }
669
670 # API Test function: GET â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
671 # args: <response-code> <type-id> <job-id> [<status>]
672 # args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
673 # (Function for test scripts)
674 ics_api_a1_get_job_status() {
675         __log_test_start $@
676
677         if [ -z "$FLAT_A1_EI" ]; then
678                 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
679                         __print_err "<response-code> <type-id> <job-id> [<status>]" $@
680                         return 1
681                 fi
682
683                 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
684
685                 res="$(__do_curl_to_api ICS GET $query)"
686                 status=${res:${#res}-3}
687
688                 if [ $status -ne $1 ]; then
689                         __log_test_fail_status_code $1 $status
690                         return 1
691                 fi
692                 if [ $# -eq 4 ]; then
693                         body=${res:0:${#res}-3}
694                         targetJson="{\"operationalState\": \"$4\"}"
695                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
696                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
697
698                         if [ $res -ne 0 ]; then
699                                 __log_test_fail_body
700                                 return 1
701                         fi
702                 fi
703         else
704                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
705                 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
706                         __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
707                         return 1
708                 fi
709
710                 query="/A1-EI/v1/eijobs/$2/status"
711
712                 start=$SECONDS
713                 for (( ; ; )); do
714                         res="$(__do_curl_to_api ICS GET $query)"
715                         status=${res:${#res}-3}
716
717                         if [ $# -eq 4 ]; then
718                                 duration=$((SECONDS-start))
719                                 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
720                                 if [ $duration -gt $4 ]; then
721                                         echo ""
722                                         duration=-1  #Last iteration
723                                 fi
724                         else
725                                 duration=-1 #single test, no wait
726                         fi
727
728                         if [ $status -ne $1 ]; then
729                                 if [ $duration -eq -1 ]; then
730                                         __log_test_fail_status_code $1 $status
731                                         return 1
732                                 fi
733                         fi
734                         if [ $# -ge 3 ] && [ $status -eq $1 ]; then
735                                 body=${res:0:${#res}-3}
736                                 targetJson="{\"eiJobStatus\": \"$3\"}"
737                                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
738                                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
739
740                                 if [ $res -ne 0 ]; then
741                                         if [ $duration -eq -1 ]; then
742                                                 __log_test_fail_body
743                                                 return 1
744                                         fi
745                                 else
746                                         duration=-1  #Goto pass
747                                 fi
748                         fi
749                         if [ $duration -eq -1 ]; then
750                                 if [ $# -eq 4 ]; then
751                                         echo ""
752                                 fi
753                                 __log_test_pass
754                                 return 0
755                         else
756                                 sleep 1
757                         fi
758                 done
759         fi
760
761         __log_test_pass
762         return 0
763 }
764
765 # API Test function: GET â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
766 # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
767 # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
768 # (Function for test scripts)
769 ics_api_a1_get_job() {
770         __log_test_start $@
771
772         if [  -z "$FLAT_A1_EI" ]; then
773                 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
774                         __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
775                         return 1
776                 fi
777                 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
778         else
779                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
780                 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
781                         __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
782                         return 1
783                 fi
784                 query="/A1-EI/v1/eijobs/$2"
785         fi
786     res="$(__do_curl_to_api ICS GET $query)"
787     status=${res:${#res}-3}
788
789         if [ $status -ne $1 ]; then
790                 __log_test_fail_status_code $1 $status
791                 return 1
792         fi
793
794         if [  -z "$FLAT_A1_EI" ]; then
795                 if [ $# -eq 6 ]; then
796                         body=${res:0:${#res}-3}
797
798                         if [ -f $6 ]; then
799                                 jobfile=$(cat $6)
800                                 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
801                         else
802                                 __log_test_fail_general "Job template file "$6", does not exist"
803                                 return 1
804                         fi
805                         targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
806                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
807                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
808
809                         if [ $res -ne 0 ]; then
810                                 __log_test_fail_body
811                                 return 1
812                         fi
813                 fi
814         else
815                 if [ $# -eq 7 ]; then
816                         body=${res:0:${#res}-3}
817
818                         if [ -f $7 ]; then
819                                 jobfile=$(cat $7)
820                                 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
821                         else
822                                 __log_test_fail_general "Job template file "$6", does not exist"
823                                 return 1
824                         fi
825                         targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
826                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
827                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
828
829                         if [ $res -ne 0 ]; then
830                                 __log_test_fail_body
831                                 return 1
832                         fi
833                 fi
834         fi
835
836         __log_test_pass
837         return 0
838 }
839
840 # API Test function: DELETE â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
841 # args: <response-code> <type-id> <job-id>
842 # args (flat uri structure): <response-code> <job-id>
843 # (Function for test scripts)
844 ics_api_a1_delete_job() {
845         __log_test_start $@
846
847         if [  -z "$FLAT_A1_EI" ]; then
848                 if [ $# -ne 3 ]; then
849                         __print_err "<response-code> <type-id> <job-id>" $@
850                         return 1
851                 fi
852
853                 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
854         else
855                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
856                 if [ $# -ne 2 ]; then
857                         __print_err "<response-code> <job-id>" $@
858                         return 1
859                 fi
860                 query="/A1-EI/v1/eijobs/$2"
861         fi
862     res="$(__do_curl_to_api ICS DELETE $query)"
863     status=${res:${#res}-3}
864
865         if [ $status -ne $1 ]; then
866                 __log_test_fail_status_code $1 $status
867                 return 1
868         fi
869
870         __log_test_pass
871         return 0
872 }
873
874 # API Test function: PUT â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
875 # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
876 # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
877 # (Function for test scripts)
878 ics_api_a1_put_job() {
879         __log_test_start $@
880
881         if [  -z "$FLAT_A1_EI" ]; then
882                 if [ $# -lt 6 ]; then
883                         __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
884                         return 1
885                 fi
886                 if [ -f $6 ]; then
887                         jobfile=$(cat $6)
888                         jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
889                 else
890                         __log_test_fail_general "Job template file "$6", does not exist"
891                         return 1
892                 fi
893
894                 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
895                 file="./tmp/.p.json"
896                 echo "$inputJson" > $file
897
898                 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
899         else
900                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
901                 if [ $# -lt 7 ]; then
902                         __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
903                         return 1
904                 fi
905                 if [ -f $7 ]; then
906                         jobfile=$(cat $7)
907                         jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
908                 else
909                         __log_test_fail_general "Job template file "$7", does not exist"
910                         return 1
911                 fi
912
913                 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
914                 file="./tmp/.p.json"
915                 echo "$inputJson" > $file
916
917                 query="/A1-EI/v1/eijobs/$2"
918         fi
919
920     res="$(__do_curl_to_api ICS PUT $query $file)"
921     status=${res:${#res}-3}
922
923         if [ $status -ne $1 ]; then
924                 __log_test_fail_status_code $1 $status
925                 return 1
926         fi
927
928         __log_test_pass
929         return 0
930 }
931
932
933 ##########################################
934 ####   information Data Producer API   ####
935 ##########################################
936 # Function prefix: ics_api_edp
937
938 # API Test function: GET /ei-producer/v1/eitypes
939 # API Test function: GET /data-producer/v1/info-types
940 # args: <response-code> [ EMPTY | <type-id>+]
941 # (Function for test scripts)
942 ics_api_edp_get_type_ids() {
943         __log_test_start $@
944
945     if [ $# -lt 1 ]; then
946                 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
947                 return 1
948         fi
949         if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
950                 query="/data-producer/v1/info-types"
951         else
952                 query="/ei-producer/v1/eitypes"
953         fi
954     res="$(__do_curl_to_api ICS GET $query)"
955     status=${res:${#res}-3}
956
957         if [ $status -ne $1 ]; then
958                 __log_test_fail_status_code $1 $status
959                 return 1
960         fi
961
962         if [ $# -gt 1 ]; then
963                 body=${res:0:${#res}-3}
964                 targetJson="["
965                 if [ $2 != "EMPTY" ]; then
966                         for pid in ${@:2} ; do
967                                 if [ "$targetJson" != "[" ]; then
968                                         targetJson=$targetJson","
969                                 fi
970                                 targetJson=$targetJson"\"$pid\""
971                         done
972                 fi
973                 targetJson=$targetJson"]"
974                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
975                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
976
977                 if [ $res -ne 0 ]; then
978                         __log_test_fail_body
979                         return 1
980                 fi
981         fi
982
983         __log_test_pass
984         return 0
985 }
986
987 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
988 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status
989 # args: <response-code> <producer-id> [<status> [<timeout>]]
990 # (Function for test scripts)
991 ics_api_edp_get_producer_status() {
992         __log_test_start $@
993
994     if [ $# -lt 2 ] || [ $# -gt 4 ]; then
995                 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
996                 return 1
997         fi
998         if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
999                 query="/data-producer/v1/info-producers/$2/status"
1000         else
1001                 query="/ei-producer/v1/eiproducers/$2/status"
1002         fi
1003         start=$SECONDS
1004         for (( ; ; )); do
1005                 res="$(__do_curl_to_api ICS GET $query)"
1006                 status=${res:${#res}-3}
1007
1008                 if [ $# -eq 4 ]; then
1009                         duration=$((SECONDS-start))
1010                         echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
1011                         if [ $duration -gt $4 ]; then
1012                                 echo ""
1013                                 duration=-1  #Last iteration
1014                         fi
1015                 else
1016                         duration=-1 #single test, no wait
1017                 fi
1018
1019                 if [ $status -ne $1 ]; then
1020                         if [ $duration -eq -1 ]; then
1021                                 __log_test_fail_status_code $1 $status
1022                                 return 1
1023                         fi
1024                 fi
1025                 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1026                         body=${res:0:${#res}-3}
1027                         targetJson="{\"operational_state\": \"$3\"}"
1028                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
1029                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1030
1031                         if [ $res -ne 0 ]; then
1032                                 if [ $duration -eq -1 ]; then
1033                                         __log_test_fail_body
1034                                         return 1
1035                                 fi
1036                         else
1037                                 duration=-1  #Goto pass
1038                         fi
1039                 fi
1040                 if [ $duration -eq -1 ]; then
1041                         if [ $# -eq 4 ]; then
1042                                 echo ""
1043                         fi
1044                         __log_test_pass
1045                         return 0
1046                 else
1047                         sleep 1
1048                 fi
1049         done
1050 }
1051
1052
1053 # API Test function: GET /ei-producer/v1/eiproducers
1054 # args (v1_1): <response-code> [ EMPTY | <producer-id>+]
1055 # (Function for test scripts)
1056 ics_api_edp_get_producer_ids() {
1057         __log_test_start $@
1058
1059     if [ $# -lt 1 ]; then
1060                 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
1061                 return 1
1062         fi
1063
1064         query="/ei-producer/v1/eiproducers"
1065     res="$(__do_curl_to_api ICS GET $query)"
1066     status=${res:${#res}-3}
1067
1068         if [ $status -ne $1 ]; then
1069                 __log_test_fail_status_code $1 $status
1070                 return 1
1071         fi
1072
1073         if [ $# -gt 1 ]; then
1074                 body=${res:0:${#res}-3}
1075                 targetJson="["
1076
1077                 for pid in ${@:2} ; do
1078                         if [ "$targetJson" != "[" ]; then
1079                                 targetJson=$targetJson","
1080                         fi
1081                         if [ $pid != "EMPTY" ]; then
1082                                 targetJson=$targetJson"\"$pid\""
1083                         fi
1084                 done
1085
1086                 targetJson=$targetJson"]"
1087                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1088                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1089
1090                 if [ $res -ne 0 ]; then
1091                         __log_test_fail_body
1092                         return 1
1093                 fi
1094         fi
1095
1096         __log_test_pass
1097         return 0
1098 }
1099
1100 # API Test function: GET /ei-producer/v1/eiproducers
1101 # API Test function: GET /data-producer/v1/info-producers
1102 # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1103 # (Function for test scripts)
1104 ics_api_edp_get_producer_ids_2() {
1105         __log_test_start $@
1106
1107     if [ $# -lt 1 ]; then
1108                 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1109                 return 1
1110         fi
1111     if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1112                 query="/data-producer/v1/info-producers"
1113                 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1114                         query=$query"?info_type_id=$2&infoTypeId=$2"  #info_type_id changed to infoTypeId in F-release.
1115                                                                       #Remove info_type_id when F-release is no longer supported
1116                 fi
1117         else
1118                 query="/ei-producer/v1/eiproducers"
1119                 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1120                         query=$query"?ei_type_id=$2"
1121                 fi
1122         fi
1123     res="$(__do_curl_to_api ICS GET $query)"
1124     status=${res:${#res}-3}
1125
1126         if [ $status -ne $1 ]; then
1127                 __log_test_fail_status_code $1 $status
1128                 return 1
1129         fi
1130
1131         if [ $# -gt 2 ]; then
1132                 body=${res:0:${#res}-3}
1133                 targetJson="["
1134
1135                 for pid in ${@:3} ; do
1136                         if [ "$targetJson" != "[" ]; then
1137                                 targetJson=$targetJson","
1138                         fi
1139                         if [ $pid != "EMPTY" ]; then
1140                                 targetJson=$targetJson"\"$pid\""
1141                         fi
1142                 done
1143
1144                 targetJson=$targetJson"]"
1145                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1146                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1147
1148                 if [ $res -ne 0 ]; then
1149                         __log_test_fail_body
1150                         return 1
1151                 fi
1152         fi
1153
1154         __log_test_pass
1155         return 0
1156 }
1157
1158 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1159 # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
1160 # (Function for test scripts)
1161 ics_api_edp_get_type() {
1162         __log_test_start $@
1163
1164         paramError=1
1165         if [ $# -eq 2 ]; then
1166                 paramError=0
1167         fi
1168         if [ $# -gt 3 ]; then
1169                 paramError=0
1170         fi
1171     if [ $paramError -ne 0 ]; then
1172                 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
1173                 return 1
1174         fi
1175
1176         query="/ei-producer/v1/eitypes/$2"
1177     res="$(__do_curl_to_api ICS GET $query)"
1178     status=${res:${#res}-3}
1179
1180         if [ $status -ne $1 ]; then
1181                 __log_test_fail_status_code $1 $status
1182                 return 1
1183         fi
1184         if [ $# -gt 3 ]; then
1185                 body=${res:0:${#res}-3}
1186
1187                 if [ -f $3 ]; then
1188                         schema=$(cat $3)
1189                 else
1190                         __log_test_fail_general "Job template file "$3", does not exist"
1191                         return 1
1192                 fi
1193
1194                 targetJson=""
1195                 if [ $4 != "EMPTY" ]; then
1196                         for pid in ${@:4} ; do
1197                                 if [ "$targetJson" != "" ]; then
1198                                         targetJson=$targetJson","
1199                                 fi
1200                                 targetJson=$targetJson"\"$pid\""
1201                         done
1202                 fi
1203                 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1204
1205                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1206                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1207
1208                 if [ $res -ne 0 ]; then
1209                         __log_test_fail_body
1210                         return 1
1211                 fi
1212         fi
1213         __log_test_pass
1214         return 0
1215 }
1216
1217 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1218 # API Test function: GET /data-producer/v1/info-types/{infoTypeId}
1219 # args: (v1_2) <response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]
1220 # (Function for test scripts)
1221 ics_api_edp_get_type_2() {
1222         __log_test_start $@
1223
1224         paramError=1
1225         if [ $# -eq 2 ]; then
1226                 paramError=0
1227         fi
1228         if [ $# -eq 3 ]; then
1229                 paramError=0
1230         fi
1231         if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
1232                 if [ $# -eq 4 ]; then
1233                         paramError=0
1234                 fi
1235         fi
1236     if [ $paramError -ne 0 ]; then
1237                 __print_err "<response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]" $@
1238                 return 1
1239         fi
1240         if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1241                 query="/data-producer/v1/info-types/$2"
1242         else
1243                 query="/ei-producer/v1/eitypes/$2"
1244         fi
1245
1246     res="$(__do_curl_to_api ICS GET $query)"
1247     status=${res:${#res}-3}
1248
1249         if [ $status -ne $1 ]; then
1250                 __log_test_fail_status_code $1 $status
1251                 return 1
1252         fi
1253         if [ $# -ge 3 ]; then
1254                 body=${res:0:${#res}-3}
1255
1256                 if [ -f $3 ]; then
1257                         schema=$(cat $3)
1258                 else
1259                         __log_test_fail_general "Job template file "$3", does not exist"
1260                         return 1
1261                 fi
1262                 info_data=""
1263                 if [ $# -gt 3 ]; then
1264                         if [ -f $4 ]; then
1265                                 info_data=$(cat $4)
1266                         else
1267                                 __log_test_fail_general "Info-data file "$4", does not exist"
1268                                 return 1
1269                         fi
1270                         info_data=",\"info_type_information\":$info_data"
1271                 fi
1272                 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1273                         targetJson="{\"info_job_data_schema\":$schema $info_data}"
1274                 else
1275                         targetJson="{\"ei_job_data_schema\":$schema}"
1276                 fi
1277
1278                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1279                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1280
1281                 if [ $res -ne 0 ]; then
1282                         __log_test_fail_body
1283                         return 1
1284                 fi
1285         fi
1286         __log_test_pass
1287         return 0
1288 }
1289
1290 # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1291 # API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
1292 # args: (v1_2) <response-code> <type-id> <job-schema-file> [ <info-type-info> ]
1293 # (Function for test scripts)
1294 ics_api_edp_put_type_2() {
1295         __log_test_start $@
1296
1297         if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
1298                 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1299                         __print_err "<response-code> <type-id> <job-schema-file> [ <info-type-info> ]" $@
1300                         return 1
1301                 fi
1302         else
1303                 if [ $# -ne 3 ]; then
1304                         __print_err "<response-code> <type-id> <job-schema-file>" $@
1305                         return 1
1306                 fi
1307         fi
1308
1309         if [ ! -f $3 ]; then
1310                 __log_test_fail_general "Job schema file "$3", does not exist"
1311                 return 1
1312         fi
1313
1314         info_data=""
1315         if [ $# -gt 3 ]; then
1316                 if [ -f $4 ]; then
1317                         info_data=$(cat $4)
1318                 else
1319                         __log_test_fail_general "Info-data file "$4", does not exist"
1320                         return 1
1321                 fi
1322                 info_data=",\"info_type_information\":$info_data"
1323         fi
1324
1325         if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1326                 schema=$(cat $3)
1327                 input_json="{\"info_job_data_schema\":$schema $info_data}"
1328                 file="./tmp/put_type.json"
1329                 echo $input_json > $file
1330
1331                 query="/data-producer/v1/info-types/$2"
1332         else
1333                 schema=$(cat $3)
1334                 input_json="{\"ei_job_data_schema\":$schema}"
1335                 file="./tmp/put_type.json"
1336                 echo $input_json > $file
1337
1338                 query="/ei-producer/v1/eitypes/$2"
1339         fi
1340     res="$(__do_curl_to_api ICS PUT $query $file)"
1341     status=${res:${#res}-3}
1342
1343         if [ $status -ne $1 ]; then
1344                 __log_test_fail_status_code $1 $status
1345                 return 1
1346         fi
1347
1348         __log_test_pass
1349         return 0
1350 }
1351
1352 # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1353 # API Test function: DELETE /data-producer/v1/info-types/{infoTypeId}
1354 # args: (v1_2) <response-code> <type-id>
1355 # (Function for test scripts)
1356 ics_api_edp_delete_type_2() {
1357         __log_test_start $@
1358
1359     if [ $# -ne 2 ]; then
1360                 __print_err "<response-code> <type-id>" $@
1361                 return 1
1362         fi
1363
1364         if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1365                 query="/data-producer/v1/info-types/$2"
1366         else
1367                 query="/ei-producer/v1/eitypes/$2"
1368         fi
1369     res="$(__do_curl_to_api ICS DELETE $query)"
1370     status=${res:${#res}-3}
1371
1372         if [ $status -ne $1 ]; then
1373                 __log_test_fail_status_code $1 $status
1374                 return 1
1375         fi
1376
1377         __log_test_pass
1378         return 0
1379 }
1380
1381 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1382 # args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
1383 # (Function for test scripts)
1384 ics_api_edp_get_producer() {
1385         __log_test_start $@
1386
1387         #Possible arg count: 2, 5 6, 8, 10 etc
1388         paramError=1
1389         if [ $# -eq 2 ]; then
1390                 paramError=0
1391         fi
1392         if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1393                 paramError=0
1394         fi
1395         variablecount=$(($#-4))
1396         if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1397                 paramError=0
1398         fi
1399
1400     if [ $paramError -ne 0 ]; then
1401                 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
1402                 return 1
1403         fi
1404
1405         query="/ei-producer/v1/eiproducers/$2"
1406     res="$(__do_curl_to_api ICS GET $query)"
1407     status=${res:${#res}-3}
1408
1409         if [ $status -ne $1 ]; then
1410                 __log_test_fail_status_code $1 $status
1411                 return 1
1412         fi
1413
1414         if [ $# -gt 2 ]; then
1415                 body=${res:0:${#res}-3}
1416                 targetJson="["
1417                 if [ $# -gt 5 ]; then
1418                         arr=(${@:5})
1419                         for ((i=0; i<$(($#-5)); i=i+2)); do
1420                                 if [ "$targetJson" != "[" ]; then
1421                                         targetJson=$targetJson","
1422                                 fi
1423                                 if [ -f ${arr[$i+1]} ]; then
1424                                         schema=$(cat ${arr[$i+1]})
1425                                 else
1426                                         __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1427                                         return 1
1428                                 fi
1429
1430                                 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1431                         done
1432                 fi
1433                 targetJson=$targetJson"]"
1434                 if [ $# -gt 4 ]; then
1435                         targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1436                 fi
1437                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1438                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1439
1440                 if [ $res -ne 0 ]; then
1441                         __log_test_fail_body
1442                         return 1
1443                 fi
1444         fi
1445
1446         __log_test_pass
1447         return 0
1448 }
1449
1450 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1451 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}
1452 # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1453 # (Function for test scripts)
1454 ics_api_edp_get_producer_2() {
1455         __log_test_start $@
1456
1457         #Possible arg count: 2, 5, 6, 7, 8 etc
1458         paramError=1
1459         if [ $# -eq 2 ]; then
1460                 paramError=0
1461         fi
1462         if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1463                 paramError=0
1464         fi
1465         if [ $# -ge 5 ]; then
1466                 paramError=0
1467         fi
1468
1469     if [ $paramError -ne 0 ]; then
1470                 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1471                 return 1
1472         fi
1473         if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1474                 query="/data-producer/v1/info-producers/$2"
1475         else
1476                 query="/ei-producer/v1/eiproducers/$2"
1477         fi
1478     res="$(__do_curl_to_api ICS GET $query)"
1479     status=${res:${#res}-3}
1480
1481         if [ $status -ne $1 ]; then
1482                 __log_test_fail_status_code $1 $status
1483                 return 1
1484         fi
1485
1486         if [ $# -gt 2 ]; then
1487                 body=${res:0:${#res}-3}
1488                 targetJson="["
1489                 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1490                         arr=(${@:5})
1491                         for ((i=0; i<$(($#-4)); i=i+1)); do
1492                                 if [ "$targetJson" != "[" ]; then
1493                                         targetJson=$targetJson","
1494                                 fi
1495                                 targetJson=$targetJson"\"${arr[$i]}\""
1496                         done
1497                 fi
1498                 targetJson=$targetJson"]"
1499                 if [ $# -gt 4 ]; then
1500                         if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1501                                 targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}"
1502                         else
1503                                 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1504                         fi
1505                 fi
1506                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1507                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1508
1509                 if [ $res -ne 0 ]; then
1510                         __log_test_fail_body
1511                         return 1
1512                 fi
1513         fi
1514
1515         __log_test_pass
1516         return 0
1517 }
1518
1519 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
1520 # API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId}
1521 # args: <response-code> <producer-id>
1522 # (Function for test scripts)
1523 ics_api_edp_delete_producer() {
1524         __log_test_start $@
1525
1526     if [ $# -lt 2 ]; then
1527                 __print_err "<response-code> <producer-id>" $@
1528                 return 1
1529         fi
1530         if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1531                 query="/data-producer/v1/info-producers/$2"
1532         else
1533                 query="/ei-producer/v1/eiproducers/$2"
1534         fi
1535     res="$(__do_curl_to_api ICS DELETE $query)"
1536     status=${res:${#res}-3}
1537
1538         if [ $status -ne $1 ]; then
1539                 __log_test_fail_status_code $1 $status
1540                 return 1
1541         fi
1542
1543         __log_test_pass
1544         return 0
1545 }
1546
1547 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1548 # args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
1549 # (Function for test scripts)
1550 ics_api_edp_put_producer() {
1551         __log_test_start $@
1552
1553         #Valid number of parametrer 5,6,8,10,
1554         paramError=1
1555         if  [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1556                 paramError=0
1557         elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
1558                 paramError=0
1559         fi
1560         if [ $paramError -ne 0 ]; then
1561                 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
1562                 return 1
1563         fi
1564
1565         inputJson="["
1566         if [ $# -gt 5 ]; then
1567                 arr=(${@:5})
1568                 for ((i=0; i<$(($#-5)); i=i+2)); do
1569                         if [ "$inputJson" != "[" ]; then
1570                                 inputJson=$inputJson","
1571                         fi
1572                         if [ -f ${arr[$i+1]} ]; then
1573                                 schema=$(cat ${arr[$i+1]})
1574                         else
1575                                 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1576                                 return 1
1577                         fi
1578                         inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1579                 done
1580         fi
1581         inputJson="\"supported_ei_types\":"$inputJson"]"
1582
1583         inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1584
1585         inputJson="{"$inputJson"}"
1586
1587         file="./tmp/.p.json"
1588         echo "$inputJson" > $file
1589         query="/ei-producer/v1/eiproducers/$2"
1590     res="$(__do_curl_to_api ICS PUT $query $file)"
1591     status=${res:${#res}-3}
1592
1593         if [ $status -ne $1 ]; then
1594                 __log_test_fail_status_code $1 $status
1595                 return 1
1596         fi
1597
1598         __log_test_pass
1599         return 0
1600 }
1601
1602 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1603 # API Test function: PUT /data-producer/v1/info-producers/{infoProducerId}
1604 # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1605 # (Function for test scripts)
1606 ics_api_edp_put_producer_2() {
1607         __log_test_start $@
1608
1609         #Valid number of parametrer 5,6,8,10,
1610         paramError=1
1611         if  [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1612                 paramError=0
1613         elif [ $# -ge 5 ]; then
1614                 paramError=0
1615         fi
1616         if [ $paramError -ne 0 ]; then
1617                 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1618                 return 1
1619         fi
1620
1621         inputJson="["
1622         if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1623                 arr=(${@:5})
1624                 for ((i=0; i<$(($#-4)); i=i+1)); do
1625                         if [ "$inputJson" != "[" ]; then
1626                                 inputJson=$inputJson","
1627                         fi
1628                         inputJson=$inputJson"\""${arr[$i]}"\""
1629                 done
1630         fi
1631         if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1632                 inputJson="\"supported_info_types\":"$inputJson"]"
1633
1634                 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
1635
1636                 inputJson="{"$inputJson"}"
1637
1638                 file="./tmp/.p.json"
1639                 echo "$inputJson" > $file
1640                 query="/data-producer/v1/info-producers/$2"
1641         else
1642                 inputJson="\"supported_ei_types\":"$inputJson"]"
1643
1644                 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1645
1646                 inputJson="{"$inputJson"}"
1647
1648                 file="./tmp/.p.json"
1649                 echo "$inputJson" > $file
1650                 query="/ei-producer/v1/eiproducers/$2"
1651         fi
1652     res="$(__do_curl_to_api ICS PUT $query $file)"
1653     status=${res:${#res}-3}
1654
1655         if [ $status -ne $1 ]; then
1656                 __log_test_fail_status_code $1 $status
1657                 return 1
1658         fi
1659
1660         __log_test_pass
1661         return 0
1662 }
1663
1664 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1665 # args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1666 # (Function for test scripts)
1667 ics_api_edp_get_producer_jobs() {
1668         __log_test_start $@
1669
1670         #Valid number of parameter 2,3,7,11
1671         paramError=1
1672         if [ $# -eq 2 ]; then
1673                 paramError=0
1674         fi
1675         if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1676                 paramError=0
1677         fi
1678         variablecount=$(($#-2))
1679         if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1680                 paramError=0
1681         fi
1682         if [ $paramError -eq 1 ]; then
1683                 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1684                 return 1
1685         fi
1686
1687         query="/ei-producer/v1/eiproducers/$2/eijobs"
1688     res="$(__do_curl_to_api ICS GET $query)"
1689     status=${res:${#res}-3}
1690         if [ $status -ne $1 ]; then
1691                 __log_test_fail_status_code $1 $status
1692                 return 1
1693         fi
1694         if [ $# -gt 2 ]; then
1695                 body=${res:0:${#res}-3}
1696                 targetJson="["
1697                 if [ $# -gt 3 ]; then
1698                         arr=(${@:3})
1699                         for ((i=0; i<$(($#-3)); i=i+5)); do
1700                                 if [ "$targetJson" != "[" ]; then
1701                                         targetJson=$targetJson","
1702                                 fi
1703                                 if [ -f ${arr[$i+4]} ]; then
1704                                         jobfile=$(cat ${arr[$i+4]})
1705                                         jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1706                                 else
1707                                         __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1708                                         return 1
1709                                 fi
1710                                 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}"
1711                         done
1712                 fi
1713                 targetJson=$targetJson"]"
1714
1715                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1716                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1717
1718                 if [ $res -ne 0 ]; then
1719                         __log_test_fail_body
1720                         return 1
1721                 fi
1722         fi
1723
1724         __log_test_pass
1725         return 0
1726 }
1727
1728 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1729 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs
1730 # args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1731 # (Function for test scripts)
1732 ics_api_edp_get_producer_jobs_2() {
1733         __log_test_start $@
1734
1735         #Valid number of parameter 2,3,7,11
1736         paramError=1
1737         if [ $# -eq 2 ]; then
1738                 paramError=0
1739         fi
1740         if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1741                 paramError=0
1742         fi
1743         variablecount=$(($#-2))
1744         if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1745                 paramError=0
1746         fi
1747         if [ $paramError -eq 1 ]; then
1748                 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1749                 return 1
1750         fi
1751         if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1752                 query="/data-producer/v1/info-producers/$2/info-jobs"
1753         else
1754                 query="/ei-producer/v1/eiproducers/$2/eijobs"
1755         fi
1756     res="$(__do_curl_to_api ICS GET $query)"
1757     status=${res:${#res}-3}
1758         if [ $status -ne $1 ]; then
1759                 __log_test_fail_status_code $1 $status
1760                 return 1
1761         fi
1762         if [ $# -gt 2 ]; then
1763                 body=${res:0:${#res}-3}
1764                 targetJson="["
1765                 if [ $# -gt 3 ]; then
1766                         arr=(${@:3})
1767                         for ((i=0; i<$(($#-3)); i=i+5)); do
1768                                 if [ "$targetJson" != "[" ]; then
1769                                         targetJson=$targetJson","
1770                                 fi
1771                                 if [ -f ${arr[$i+4]} ]; then
1772                                         jobfile=$(cat ${arr[$i+4]})
1773                                         jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1774                                 else
1775                                         __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1776                                         return 1
1777                                 fi
1778                                 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1779                                         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\":\"????\"}"
1780                                 else
1781                                         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\":\"????\"}"
1782                                 fi
1783                         done
1784                 fi
1785                 targetJson=$targetJson"]"
1786
1787                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1788                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1789
1790                 if [ $res -ne 0 ]; then
1791                         __log_test_fail_body
1792                         return 1
1793                 fi
1794         fi
1795
1796         __log_test_pass
1797         return 0
1798 }
1799
1800 ##########################################
1801 ####          Service status          ####
1802 ##########################################
1803 # Function prefix: ics_api_service
1804
1805 # API Test function: GET â€‹/status
1806 # args: <response-code>
1807 # (Function for test scripts)
1808 ics_api_service_status() {
1809         __log_test_start $@
1810
1811     if [ $# -lt 1 ]; then
1812                 __print_err "<response-code>" $@
1813                 return 1
1814         fi
1815         res="$(__do_curl_to_api ICS GET /status)"
1816     status=${res:${#res}-3}
1817         if [ $status -ne $1 ]; then
1818                 __log_test_fail_status_code $1 $status
1819                 return 1
1820         fi
1821         __log_test_pass
1822         return 0
1823 }
1824
1825 ###########################################
1826 ######### Info data consumer API ##########
1827 ###########################################
1828 #Function prefix: ics_api_idc
1829
1830
1831 # API Test function: GET /data-consumer/v1/info-types
1832 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
1833 # (Function for test scripts)
1834 ics_api_idc_get_type_ids() {
1835         __log_test_start $@
1836
1837     if [ $# -lt 1 ]; then
1838                 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1839                 return 1
1840         fi
1841
1842         query="/data-consumer/v1/info-types"
1843     res="$(__do_curl_to_api ICS GET $query)"
1844     status=${res:${#res}-3}
1845
1846         if [ $status -ne $1 ]; then
1847                 __log_test_fail_status_code $1 $status
1848                 return 1
1849         fi
1850         if [ $# -gt 1 ]; then
1851                 body=${res:0:${#res}-3}
1852                 targetJson="["
1853                 if [ $2 != "EMPTY" ]; then
1854                         for pid in ${@:2} ; do
1855                                 if [ "$targetJson" != "[" ]; then
1856                                         targetJson=$targetJson","
1857                                 fi
1858                                 targetJson=$targetJson"\"$pid\""
1859                         done
1860                 fi
1861                 targetJson=$targetJson"]"
1862                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1863                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1864
1865                 if [ $res -ne 0 ]; then
1866                         __log_test_fail_body
1867                         return 1
1868                 fi
1869         fi
1870
1871         __log_test_pass
1872         return 0
1873 }
1874
1875 # API Test function: GET /data-consumer/v1/info-jobs
1876 # args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
1877 # (Function for test scripts)
1878 ics_api_idc_get_job_ids() {
1879         __log_test_start $@
1880
1881         # Valid number of parameters 4,5,6 etc
1882         if [ $# -lt 3 ]; then
1883                 __print_err "<response-code> <type-id>|NOTYPE  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
1884                 return 1
1885         fi
1886         search=""
1887         if [ $3 != "NOWNER" ]; then
1888                 search="?owner="$3
1889         fi
1890
1891         if [ $2 != "NOTYPE" ]; then
1892                 if [ -z "$search" ]; then
1893                         search="?infoTypeId="$2
1894                 else
1895                         search=$search"&infoTypeId="$2
1896                 fi
1897         fi
1898         query="/data-consumer/v1/info-jobs$search"
1899
1900     res="$(__do_curl_to_api ICS GET $query)"
1901     status=${res:${#res}-3}
1902
1903         if [ $status -ne $1 ]; then
1904                 __log_test_fail_status_code $1 $status
1905                 return 1
1906         fi
1907
1908         if [ $# -gt 3 ]; then
1909                 body=${res:0:${#res}-3}
1910                 targetJson="["
1911
1912                 for pid in ${@:4} ; do
1913                         if [ "$targetJson" != "[" ]; then
1914                                 targetJson=$targetJson","
1915                         fi
1916                         if [ $pid != "EMPTY" ]; then
1917                                 targetJson=$targetJson"\"$pid\""
1918                         fi
1919                 done
1920
1921                 targetJson=$targetJson"]"
1922                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1923                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1924
1925                 if [ $res -ne 0 ]; then
1926                         __log_test_fail_body
1927                         return 1
1928                 fi
1929         fi
1930
1931         __log_test_pass
1932         return 0
1933 }
1934
1935 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
1936 # args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
1937 # (Function for test scripts)
1938 ics_api_idc_get_job() {
1939         __log_test_start $@
1940
1941         if [ $# -ne 2 ] && [ $# -ne 7 ]; then
1942                 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
1943                 return 1
1944         fi
1945         query="/data-consumer/v1/info-jobs/$2"
1946     res="$(__do_curl_to_api ICS GET $query)"
1947     status=${res:${#res}-3}
1948
1949         if [ $status -ne $1 ]; then
1950                 __log_test_fail_status_code $1 $status
1951                 return 1
1952         fi
1953
1954         if [ $# -eq 7 ]; then
1955                 body=${res:0:${#res}-3}
1956
1957                 if [ -f $7 ]; then
1958                         jobfile=$(cat $7)
1959                         jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1960                 else
1961                         __log_test_fail_general "Job template file "$6", does not exist"
1962                         return 1
1963                 fi
1964                 targetJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
1965                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1966                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1967
1968                 if [ $res -ne 0 ]; then
1969                         __log_test_fail_body
1970                         return 1
1971                 fi
1972         fi
1973
1974         __log_test_pass
1975         return 0
1976 }
1977
1978
1979 # API Test function: PUT â€‹/data-consumer/v1/info-jobs/{infoJobId}
1980 # args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
1981 # (Function for test scripts)
1982 ics_api_idc_put_job() {
1983         __log_test_start $@
1984
1985         if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1986                 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
1987                 return 1
1988         fi
1989         if [ -f $7 ]; then
1990                 jobfile=$(cat $7)
1991                 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1992         else
1993                 __log_test_fail_general "Job template file "$7", does not exist"
1994                 return 1
1995         fi
1996
1997         inputJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
1998         file="./tmp/.p.json"
1999         echo "$inputJson" > $file
2000
2001         query="/data-consumer/v1/info-jobs/$2"
2002
2003         if [ $# -eq 8 ]; then
2004                 if [ $8 == "VALIDATE" ]; then
2005                         query=$query"?typeCheck=true"
2006                 fi
2007         fi
2008
2009     res="$(__do_curl_to_api ICS PUT $query $file)"
2010     status=${res:${#res}-3}
2011
2012         if [ $status -ne $1 ]; then
2013                 __log_test_fail_status_code $1 $status
2014                 return 1
2015         fi
2016
2017         __log_test_pass
2018         return 0
2019 }
2020
2021 # API Test function: DELETE â€‹/data-consumer/v1/info-jobs/{infoJobId}
2022 # args: <response-code> <job-id>
2023 # (Function for test scripts)
2024 ics_api_idc_delete_job() {
2025         __log_test_start $@
2026
2027         if [ $# -ne 2 ]; then
2028                 __print_err "<response-code> <job-id>" $@
2029                 return 1
2030         fi
2031         query="/data-consumer/v1/info-jobs/$2"
2032     res="$(__do_curl_to_api ICS DELETE $query)"
2033     status=${res:${#res}-3}
2034
2035         if [ $status -ne $1 ]; then
2036                 __log_test_fail_status_code $1 $status
2037                 return 1
2038         fi
2039
2040         __log_test_pass
2041         return 0
2042 }
2043
2044 # API Test function: GET â€‹/data-consumer/v1/info-types/{infoTypeId}
2045 # args: <response-code> <type-id> [<schema-file> [<type-status> <producers-count]]
2046 # (Function for test scripts)
2047 ics_api_idc_get_type() {
2048         __log_test_start $@
2049
2050     if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2051                 __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@
2052                 return 1
2053         fi
2054
2055         query="/data-consumer/v1/info-types/$2"
2056     res="$(__do_curl_to_api ICS GET $query)"
2057     status=${res:${#res}-3}
2058
2059         if [ $status -ne $1 ]; then
2060                 __log_test_fail_status_code $1 $status
2061                 return 1
2062         fi
2063
2064         if [ $# -gt 2 ]; then
2065                 body=${res:0:${#res}-3}
2066                 if [ -f $3 ]; then
2067                         schema=$(cat $3)
2068                 else
2069                         __log_test_fail_general "Schema file "$3", does not exist"
2070                         return 1
2071                 fi
2072                 if [ $# -eq 5 ]; then
2073                         targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}"
2074                 else
2075                         targetJson="{\"job_data_schema\":$schema}"
2076                 fi
2077                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2078                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2079
2080                 if [ $res -ne 0 ]; then
2081                         __log_test_fail_body
2082                         return 1
2083                 fi
2084         fi
2085
2086         __log_test_pass
2087         return 0
2088 }
2089
2090 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2091 # This test only status during an optional timeout. No test of the list of producers
2092 # args: <response-code> <job-id> [<status> [<timeout>]]
2093 # (Function for test scripts)
2094 ics_api_idc_get_job_status() {
2095         __log_test_start $@
2096
2097         if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2098                 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2099                 return 1
2100         fi
2101
2102         query="/data-consumer/v1/info-jobs/$2/status"
2103
2104         start=$SECONDS
2105         for (( ; ; )); do
2106                 res="$(__do_curl_to_api ICS GET $query)"
2107                 status=${res:${#res}-3}
2108
2109                 if [ $# -eq 4 ]; then
2110                         duration=$((SECONDS-start))
2111                         echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2112                         if [ $duration -gt $4 ]; then
2113                                 echo ""
2114                                 duration=-1  #Last iteration
2115                         fi
2116                 else
2117                         duration=-1 #single test, no wait
2118                 fi
2119
2120                 if [ $status -ne $1 ]; then
2121                         if [ $duration -eq -1 ]; then
2122                                 __log_test_fail_status_code $1 $status
2123                                 return 1
2124                         fi
2125                 fi
2126                 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
2127                         body=${res:0:${#res}-3}
2128                         targetJson="{\"info_job_status\": \"$3\"}"
2129                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
2130                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2131
2132                         if [ $res -ne 0 ]; then
2133                                 if [ $duration -eq -1 ]; then
2134                                         __log_test_fail_body
2135                                         return 1
2136                                 fi
2137                         else
2138                                 duration=-1  #Goto pass
2139                         fi
2140                 fi
2141                 if [ $duration -eq -1 ]; then
2142                         if [ $# -eq 4 ]; then
2143                                 echo ""
2144                         fi
2145                         __log_test_pass
2146                         return 0
2147                 else
2148                         sleep 1
2149                 fi
2150         done
2151
2152         __log_test_pass
2153         return 0
2154 }
2155
2156 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2157 # This function test status and the list of producers with and optional timeout
2158 # args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
2159 # (Function for test scripts)
2160 ics_api_idc_get_job_status2() {
2161
2162         __log_test_start $@
2163         param_error=0
2164         if [ $# -lt 2 ]; then
2165                 param_error=1
2166         fi
2167         args=("$@")
2168         timeout=0
2169         if [ $# -gt 2 ]; then
2170                 if [ $# -lt 4 ]; then
2171                         param_error=1
2172                 fi
2173                 targetJson="{\"info_job_status\": \"$3\""
2174                 if [ "$4" == "EMPTYPROD" ]; then
2175                         targetJson=$targetJson",\"producers\": []}"
2176                         if [ $# -gt 4 ]; then
2177                                 timeout=$5
2178                         fi
2179                 else
2180                         targetJson=$targetJson",\"producers\": ["
2181                         if [ $# -eq $(($4+5)) ]; then
2182                                 idx=$(($4+4))
2183                                 timeout=${args[$idx]}
2184                         fi
2185                         for ((ics_i = 0 ; ics_i < $4 ; ics_i++)); do
2186                                 idx=$(($ics_i+4))
2187                                 if [ $ics_i -gt 0 ]; then
2188                                         targetJson=$targetJson","
2189                                 fi
2190                                 targetJson=$targetJson"\""${args[$idx]}"\""
2191                         done
2192                         targetJson=$targetJson"]}"
2193                 fi
2194         fi
2195
2196         if [ $param_error -ne 0 ]; then
2197                 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2198                 return 1
2199         fi
2200
2201         query="/data-consumer/v1/info-jobs/$2/status"
2202
2203         start=$SECONDS
2204         for (( ; ; )); do
2205                 res="$(__do_curl_to_api ICS GET $query)"
2206                 status=${res:${#res}-3}
2207
2208                 if [ $# -gt 2 ]; then
2209                         duration=$((SECONDS-start))
2210                         echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2211                         if [ $duration -gt $timeout ]; then
2212                                 echo ""
2213                                 duration=-1  #Last iteration
2214                         fi
2215                 else
2216                         duration=-1 #single test, no wait
2217                 fi
2218
2219                 if [ $status -ne $1 ]; then
2220                         if [ $duration -eq -1 ]; then
2221                                 __log_test_fail_status_code $1 $status
2222                                 return 1
2223                         fi
2224                 fi
2225                 if [ $# -gt 2 ] && [ $status -eq $1 ]; then
2226                         body=${res:0:${#res}-3}
2227                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
2228                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2229
2230                         if [ $res -ne 0 ]; then
2231                                 if [ $duration -eq -1 ]; then
2232                                         __log_test_fail_body
2233                                         return 1
2234                                 fi
2235                         else
2236                                 duration=-1  #Goto pass
2237                         fi
2238                 fi
2239                 if [ $duration -eq -1 ]; then
2240                         if [ $# -eq 4 ]; then
2241                                 echo ""
2242                         fi
2243                         __log_test_pass
2244                         return 0
2245                 else
2246                         sleep 1
2247                 fi
2248         done
2249
2250         __log_test_pass
2251         return 0
2252 }
2253
2254 ##########################################
2255 ####     Type subscriptions           ####
2256 ##########################################
2257
2258 # API Test function: GET /data-consumer/v1/info-type-subscription
2259 # args: <response-code>  <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]
2260 # (Function for test scripts)
2261 ics_api_idc_get_subscription_ids() {
2262         __log_test_start $@
2263
2264     if [ $# -lt 3 ]; then
2265                 __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@
2266                 return 1
2267         fi
2268
2269         query="/data-consumer/v1/info-type-subscription"
2270         search=""
2271         if [ $2 != "NOOWNER" ]; then
2272                 search="?owner="$2
2273         fi
2274
2275     res="$(__do_curl_to_api ICS GET $query$search)"
2276     status=${res:${#res}-3}
2277
2278         if [ $status -ne $1 ]; then
2279                 __log_test_fail_status_code $1 $status
2280                 return 1
2281         fi
2282
2283         if [ $# -gt 2 ]; then
2284                 body=${res:0:${#res}-3}
2285                 targetJson="["
2286                 if [ $3 != "EMPTY" ]; then
2287                         for pid in ${@:3} ; do
2288                                 if [ "$targetJson" != "[" ]; then
2289                                         targetJson=$targetJson","
2290                                 fi
2291                                 targetJson=$targetJson"\"$pid\""
2292                         done
2293                 fi
2294                 targetJson=$targetJson"]"
2295                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2296                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2297
2298                 if [ $res -ne 0 ]; then
2299                         __log_test_fail_body
2300                         return 1
2301                 fi
2302         fi
2303
2304         __log_test_pass
2305         return 0
2306 }
2307
2308 # API Test function: GET /data-consumer/v1/info-type-subscription/{subscriptionId}
2309 # args: <response-code>  <subscription-id> [ <owner-id> <status-uri> ]
2310 # (Function for test scripts)
2311 ics_api_idc_get_subscription() {
2312         __log_test_start $@
2313
2314     if [ $# -ne 2 ] && [ $# -ne 4 ]; then
2315                 __print_err "<response-code>  <subscription-id> [ <owner-id> <status-uri> ]" $@
2316                 return 1
2317         fi
2318
2319         query="/data-consumer/v1/info-type-subscription/$2"
2320     res="$(__do_curl_to_api ICS GET $query)"
2321     status=${res:${#res}-3}
2322
2323         if [ $status -ne $1 ]; then
2324                 __log_test_fail_status_code $1 $status
2325                 return 1
2326         fi
2327
2328         if [ $# -gt 2 ]; then
2329                 body=${res:0:${#res}-3}
2330                 targetJson="{\"owner\":\"$3\",\"status_result_uri\":\"$4\"}"
2331                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2332                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2333
2334                 if [ $res -ne 0 ]; then
2335                         __log_test_fail_body
2336                         return 1
2337                 fi
2338         fi
2339
2340         __log_test_pass
2341         return 0
2342 }
2343
2344 # API Test function: PUT /data-consumer/v1/info-type-subscription/{subscriptionId}
2345 # args: <response-code>  <subscription-id> <owner-id> <status-uri>
2346 # (Function for test scripts)
2347 ics_api_idc_put_subscription() {
2348         __log_test_start $@
2349
2350     if [ $# -ne 4 ]; then
2351                 __print_err "<response-code>  <subscription-id> <owner-id> <status-uri>" $@
2352                 return 1
2353         fi
2354
2355         inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}"
2356         file="./tmp/.p.json"
2357         echo "$inputJson" > $file
2358
2359         query="/data-consumer/v1/info-type-subscription/$2"
2360     res="$(__do_curl_to_api ICS PUT $query $file)"
2361     status=${res:${#res}-3}
2362
2363         if [ $status -ne $1 ]; then
2364                 __log_test_fail_status_code $1 $status
2365                 return 1
2366         fi
2367
2368         __log_test_pass
2369         return 0
2370 }
2371
2372 # API Test function: DELETE /data-consumer/v1/info-type-subscription/{subscriptionId}
2373 # args: <response-code>  <subscription-id>
2374 # (Function for test scripts)
2375 ics_api_idc_delete_subscription() {
2376         __log_test_start $@
2377
2378         if [ $# -ne 2 ]; then
2379                 __print_err "<response-code>  <subscription-id> " $@
2380                 return 1
2381         fi
2382
2383         query="/data-consumer/v1/info-type-subscription/$2"
2384     res="$(__do_curl_to_api ICS DELETE $query)"
2385     status=${res:${#res}-3}
2386
2387         if [ $status -ne $1 ]; then
2388                 __log_test_fail_status_code $1 $status
2389                 return 1
2390         fi
2391
2392         __log_test_pass
2393         return 0
2394 }
2395
2396 ##########################################
2397 ####          Reset jobs              ####
2398 ##########################################
2399 # Function prefix: ics_api_admin
2400
2401 # Admin to remove all jobs
2402 # args: <response-code> [ <type> ]
2403 # (Function for test scripts)
2404
2405 ics_api_admin_reset() {
2406         __log_test_start $@
2407
2408         if [  -z "$FLAT_A1_EI" ]; then
2409                 query="/A1-EI/v1/eitypes/$2/eijobs"
2410         else
2411                 query="/A1-EI/v1/eijobs"
2412         fi
2413     res="$(__do_curl_to_api ICS GET $query)"
2414     status=${res:${#res}-3}
2415
2416         if [ $status -ne 200 ]; then
2417                 __log_test_fail_status_code $1 $status
2418                 return 1
2419         fi
2420
2421         #Remove brackets and response code
2422         body=${res:1:${#res}-4}
2423         list=$(echo ${body//,/ })
2424         list=$(echo ${list//[/})
2425         list=$(echo ${list//]/})
2426         list=$(echo ${list//\"/})
2427         list=$list" "
2428         for job in $list; do
2429                 if [  -z "$FLAT_A1_EI" ]; then
2430                         echo "Not supported for non-flat EI api"
2431                 else
2432                         query="/A1-EI/v1/eijobs/$job"
2433                         res="$(__do_curl_to_api ICS DELETE $query)"
2434                         status=${res:${#res}-3}
2435                         if [ $status -ne 204 ]; then
2436                                 __log_test_fail_status_code $1 $status
2437                                 return 1
2438                         fi
2439                         echo " Deleted job: "$job
2440                 fi
2441         done
2442
2443         __log_test_pass
2444         return 0
2445 }
2446
2447 ##########################################
2448 ####     Reset jobs and producers     ####
2449 ##########################################
2450
2451
2452 # Admin reset to remove all data in ics; jobs, producers etc
2453 # NOTE - only works in kubernetes and the pod should not be running
2454 # args: -
2455 # (Function for test scripts)
2456
2457 ics_kube_pvc_reset() {
2458         __log_test_start $@
2459
2460         pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE  --no-headers -o custom-columns=":metadata.name" | grep information)
2461         if [ -z "$pvc_name" ]; then
2462                 pvc_name=informationservice-pvc
2463         fi
2464         echo " Trying to reset pvc: "$pvc_name
2465
2466         __kube_clean_pvc $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $ICS_CONTAINER_MNT_DIR
2467
2468         __log_test_pass
2469         return 0
2470 }
2471
2472 # args: <realm> <client-name> <client-secret>
2473 ics_configure_sec() {
2474         export ICS_CREDS_GRANT_TYPE="client_credentials"
2475         export ICS_CREDS_CLIENT_SECRET=$3
2476         export ICS_CREDS_CLIENT_ID=$2
2477         export ICS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
2478         export ICS_SIDECAR_MOUNT="/token-cache"
2479         export ICS_SIDECAR_JWT_FILE=$ICS_SIDECAR_MOUNT"/jwt.txt"
2480
2481         export AUTHSIDECAR_APP_NAME
2482         export AUTHSIDECAR_DISPLAY_NAME
2483 }