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