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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
20 # This is a script that contains container/service management functions and test functions for ICS
22 ################ Test engine functions ################
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
28 __check_and_create_image_var ICS "ICS_IMAGE" "ICS_IMAGE_BASE" "ICS_IMAGE_TAG" $1 "$ICS_DISPLAY_NAME"
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'
37 __check_and_pull_image $1 "$ICS_DISPLAY_NAME" $ICS_APP_NAME ICS_IMAGE
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
44 echo -e $RED" Image for app ICS shall never be built"$ERED
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>
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
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
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
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
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
83 docker logs $ICS_APP_NAME > $1$2_ics.log 2>&1
87 # Initial setup of protocol, host and ports
88 # This function is called for apps managed by the test script.
90 __ICS_initial_setup() {
92 export ICS_SIDECAR_JWT_FILE=""
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.
99 __ICS_statisics_setup() {
100 if [ $RUNMODE == "KUBE" ]; then
101 echo "ICS $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
103 echo "ICS $ICS_APP_NAME"
107 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
109 __ICS_test_requirements() {
113 #######################################################
116 # Make curl retries towards ICS for http response codes set in this env var, space separated list of codes
119 #Save first worker node the pod is started on
122 ###########################
124 ###########################
126 # All calls to ICS will be directed to the ICS REST interface from now on
128 # (Function for test scripts)
129 use_ics_rest_http() {
130 __ics_set_protocoll "http" $ICS_INTERNAL_PORT $ICS_EXTERNAL_PORT
133 # All calls to ICS will be directed to the ICS REST interface from now on
135 # (Function for test scripts)
136 use_ics_rest_https() {
137 __ics_set_protocoll "https" $ICS_INTERNAL_SECURE_PORT $ICS_EXTERNAL_SECURE_PORT
140 # All calls to ICS will be directed to the ICS dmaap interface over http from now on
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"
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"
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
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
171 # Export env vars for config files, docker compose and kube resources
172 # args: PROXY|NOPROXY
173 __ics_export_vars() {
175 export ICS_APP_NAME_ALIAS
176 export KUBE_NONRTRIC_NAMESPACE
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
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
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
204 echo " Configured with http proxy"
207 export ICS_HTTP_PROXY_CONFIG_PORT=0
208 export ICS_HTTP_PROXY_CONFIG_HOST_NAME=""
209 echo " Configured without http proxy"
215 # args: PROXY|NOPROXY <config-file>
216 # (Function for test scripts)
219 echo -e $BOLD"Starting $ICS_DISPLAY_NAME"$EBOLD
221 if [ $RUNMODE == "KUBE" ]; then
223 # Check if app shall be fully managed by the test script
224 __check_included_image "ICS"
227 # Check if app shall only be used by the testscipt
228 __check_prestarted_image "ICS"
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
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
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
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"
253 #Check if nonrtric namespace exists, if not create it
254 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
258 # Create config map for config
259 datafile=$PWD/tmp/$ICS_CONFIG_FILE
261 output_yaml=$PWD/tmp/ics_cfc.yaml
262 __kube_create_configmap $ICS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ICS $datafile $output_yaml
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
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
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
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
286 __kube_create_instance app $ICS_APP_NAME $input_yaml $output_yaml
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
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
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
303 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
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
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
328 echo " No files in mounted dir or dir does not exists"
336 dest_file=$SIM_GROUP/$ICS_COMPOSE_DIR/$ICS_HOST_MNT_DIR/$ICS_CONFIG_FILE
338 envsubst < $2 > $dest_file
340 __start_container $ICS_COMPOSE_DIR "" NODOCKERARGS 1 $ICS_APP_NAME
342 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
351 # (Function for test scripts)
353 echo -e $BOLD"Stopping $ICS_DISPLAY_NAME"$EBOLD
355 if [ $RUNMODE == "KUBE" ]; then
357 __check_prestarted_image "ICS"
358 if [ $? -eq 0 ]; then
359 echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
360 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
361 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
365 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS
366 echo " Deleting the replica set - a new will be started when the app is started"
367 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ICS")
368 if [ $? -ne 0 ]; then
369 echo -e $RED" Could not delete replica set "$RED
374 docker stop $ICS_APP_NAME &> ./tmp/.dockererr
375 if [ $? -ne 0 ]; then
376 __print_err "Could not stop $ICS_APP_NAME" $@
382 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
387 # Start a previously stopped ics
389 # (Function for test scripts)
390 start_stopped_ics() {
391 echo -e $BOLD"Starting (the previously stopped) $ICS_DISPLAY_NAME"$EBOLD
393 if [ $RUNMODE == "KUBE" ]; then
395 __check_prestarted_image "ICS"
396 if [ $? -eq 0 ]; then
397 echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
398 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
399 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
400 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
404 # Tie the ICS to the same worker node it was initially started on
405 # A PVC of type hostPath is mounted to A1PMS, for persistent storage, so the A1PMS must always be on the node which mounted the volume
406 if [ -z "$__ICS_WORKER_NODE" ]; then
407 echo -e $RED" No initial worker node found for pod "$RED
411 echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ICS_WORKER_NODE to deployment for $ICS_APP_NAME. Pod will always run on this worker node: $__ICS_WORKER_NODE"$BOLD
412 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
413 tmp=$(kubectl $KUBECONF patch deployment $ICS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ICS_WORKER_NODE'"}}}}}')
414 if [ $? -ne 0 ]; then
415 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ICS_APP_NAME, persistency may not work"$EYELLOW
417 __kube_scale deployment $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
420 docker start $ICS_APP_NAME &> ./tmp/.dockererr
421 if [ $? -ne 0 ]; then
422 __print_err "Could not start (the stopped) $ICS_APP_NAME" $@
428 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
429 if [ $? -ne 0 ]; then
436 # Turn on debug level tracing in ICS
438 # (Function for test scripts)
440 echo -e $BOLD"Setting ics debug logging"$EBOLD
441 curlString="$ICS_SERVICE_PATH$ICS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
442 result=$(__do_curl "$curlString")
443 if [ $? -ne 0 ]; then
444 __print_err "Could not set debug mode" $@
452 # Turn on trace level tracing in ICS
454 # (Function for test scripts)
456 echo -e $BOLD"Setting ics trace logging"$EBOLD
457 curlString="$ICS_SERVICE_PATH$ICS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
458 result=$(__do_curl "$curlString")
459 if [ $? -ne 0 ]; then
460 __print_err "Could not set trace mode" $@
468 # Perform curl retries when making direct call to ICS for the specified http response codes
469 # Speace separated list of http response codes
470 # args: [<response-code>]*
472 echo -e $BOLD"Do curl retries to the ICS REST inteface for these response codes:$@"$EBOLD
478 # Check the ics logs for WARNINGs and ERRORs
480 # (Function for test scripts)
482 __check_container_logs "ICS" $ICS_APP_NAME $ICS_LOGPATH WARN ERR
486 # Tests if a variable value in the ICS is equal to a target value and and optional timeout.
487 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
488 # equal to the target or not.
489 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
490 # before setting pass or fail depending on if the variable value becomes equal to the target
492 # (Function for test scripts)
494 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
495 __var_test ICS "$ICS_SERVICE_PATH/" $1 "=" $2 $3
497 __print_err "Wrong args to ics_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
502 ##########################################
503 ######### A1-E information API ##########
504 ##########################################
505 #Function prefix: ics_api_a1
507 # API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
508 # args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
509 # args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
510 # (Function for test scripts)
511 ics_api_a1_get_job_ids() {
514 if [ -z "$FLAT_A1_EI" ]; then
515 # Valid number of parameters 4,5,6 etc
516 if [ $# -lt 3 ]; then
517 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
521 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
522 # Valid number of parameters 4,5,6 etc
523 if [ $# -lt 3 ]; then
524 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
529 if [ $3 != "NOWNER" ]; then
533 if [ -z "$FLAT_A1_EI" ]; then
534 query="/A1-EI/v1/eitypes/$2/eijobs$search"
536 if [ $2 != "NOTYPE" ]; then
537 if [ -z "$search" ]; then
538 search="?eiTypeId="$2
540 search=$search"&eiTypeId="$2
543 query="/A1-EI/v1/eijobs$search"
545 res="$(__do_curl_to_api ICS GET $query)"
546 status=${res:${#res}-3}
548 if [ $status -ne $1 ]; then
549 __log_test_fail_status_code $1 $status
553 if [ $# -gt 3 ]; then
554 body=${res:0:${#res}-3}
557 for pid in ${@:4} ; do
558 if [ "$targetJson" != "[" ]; then
559 targetJson=$targetJson","
561 if [ $pid != "EMPTY" ]; then
562 targetJson=$targetJson"\"$pid\""
566 targetJson=$targetJson"]"
567 echo " TARGET JSON: $targetJson" >> $HTTPLOG
568 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
570 if [ $res -ne 0 ]; then
580 # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
581 # args: <response-code> <type-id> [<schema-file>]
582 # (Function for test scripts)
583 ics_api_a1_get_type() {
586 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
587 __print_err "<response-code> <type-id> [<schema-file>]" $@
591 query="/A1-EI/v1/eitypes/$2"
592 res="$(__do_curl_to_api ICS GET $query)"
593 status=${res:${#res}-3}
595 if [ $status -ne $1 ]; then
596 __log_test_fail_status_code $1 $status
600 if [ $# -eq 3 ]; then
601 body=${res:0:${#res}-3}
605 __log_test_fail_general "Schema file "$3", does not exist"
608 if [ -z "$FLAT_A1_EI" ]; then
609 targetJson="{\"eiJobParametersSchema\":$schema}"
613 echo " TARGET JSON: $targetJson" >> $HTTPLOG
614 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
616 if [ $res -ne 0 ]; then
626 # API Test function: GET /A1-EI/v1/eitypes
627 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
628 # (Function for test scripts)
629 ics_api_a1_get_type_ids() {
632 if [ $# -lt 1 ]; then
633 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
637 query="/A1-EI/v1/eitypes"
638 res="$(__do_curl_to_api ICS GET $query)"
639 status=${res:${#res}-3}
641 if [ $status -ne $1 ]; then
642 __log_test_fail_status_code $1 $status
645 if [ $# -gt 1 ]; then
646 body=${res:0:${#res}-3}
648 if [ $2 != "EMPTY" ]; then
649 for pid in ${@:2} ; do
650 if [ "$targetJson" != "[" ]; then
651 targetJson=$targetJson","
653 targetJson=$targetJson"\"$pid\""
656 targetJson=$targetJson"]"
657 echo " TARGET JSON: $targetJson" >> $HTTPLOG
658 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
660 if [ $res -ne 0 ]; then
670 # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
671 # args: <response-code> <type-id> <job-id> [<status>]
672 # args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
673 # (Function for test scripts)
674 ics_api_a1_get_job_status() {
677 if [ -z "$FLAT_A1_EI" ]; then
678 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
679 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
683 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
685 res="$(__do_curl_to_api ICS GET $query)"
686 status=${res:${#res}-3}
688 if [ $status -ne $1 ]; then
689 __log_test_fail_status_code $1 $status
692 if [ $# -eq 4 ]; then
693 body=${res:0:${#res}-3}
694 targetJson="{\"operationalState\": \"$4\"}"
695 echo " TARGET JSON: $targetJson" >> $HTTPLOG
696 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
698 if [ $res -ne 0 ]; then
704 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
705 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
706 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
710 query="/A1-EI/v1/eijobs/$2/status"
714 res="$(__do_curl_to_api ICS GET $query)"
715 status=${res:${#res}-3}
717 if [ $# -eq 4 ]; then
718 duration=$((SECONDS-start))
719 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
720 if [ $duration -gt $4 ]; then
722 duration=-1 #Last iteration
725 duration=-1 #single test, no wait
728 if [ $status -ne $1 ]; then
729 if [ $duration -eq -1 ]; then
730 __log_test_fail_status_code $1 $status
734 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
735 body=${res:0:${#res}-3}
736 targetJson="{\"eiJobStatus\": \"$3\"}"
737 echo " TARGET JSON: $targetJson" >> $HTTPLOG
738 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
740 if [ $res -ne 0 ]; then
741 if [ $duration -eq -1 ]; then
746 duration=-1 #Goto pass
749 if [ $duration -eq -1 ]; then
750 if [ $# -eq 4 ]; then
765 # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
766 # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
767 # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
768 # (Function for test scripts)
769 ics_api_a1_get_job() {
772 if [ -z "$FLAT_A1_EI" ]; then
773 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
774 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
777 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
779 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
780 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
781 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
784 query="/A1-EI/v1/eijobs/$2"
786 res="$(__do_curl_to_api ICS GET $query)"
787 status=${res:${#res}-3}
789 if [ $status -ne $1 ]; then
790 __log_test_fail_status_code $1 $status
794 if [ -z "$FLAT_A1_EI" ]; then
795 if [ $# -eq 6 ]; then
796 body=${res:0:${#res}-3}
800 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
802 __log_test_fail_general "Job template file "$6", does not exist"
805 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
806 echo " TARGET JSON: $targetJson" >> $HTTPLOG
807 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
809 if [ $res -ne 0 ]; then
815 if [ $# -eq 7 ]; then
816 body=${res:0:${#res}-3}
820 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
822 __log_test_fail_general "Job template file "$6", does not exist"
825 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
826 echo " TARGET JSON: $targetJson" >> $HTTPLOG
827 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
829 if [ $res -ne 0 ]; then
840 # API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
841 # args: <response-code> <type-id> <job-id>
842 # args (flat uri structure): <response-code> <job-id>
843 # (Function for test scripts)
844 ics_api_a1_delete_job() {
847 if [ -z "$FLAT_A1_EI" ]; then
848 if [ $# -ne 3 ]; then
849 __print_err "<response-code> <type-id> <job-id>" $@
853 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
855 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
856 if [ $# -ne 2 ]; then
857 __print_err "<response-code> <job-id>" $@
860 query="/A1-EI/v1/eijobs/$2"
862 res="$(__do_curl_to_api ICS DELETE $query)"
863 status=${res:${#res}-3}
865 if [ $status -ne $1 ]; then
866 __log_test_fail_status_code $1 $status
874 # API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
875 # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
876 # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
877 # (Function for test scripts)
878 ics_api_a1_put_job() {
881 if [ -z "$FLAT_A1_EI" ]; then
882 if [ $# -lt 6 ]; then
883 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
888 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
890 __log_test_fail_general "Job template file "$6", does not exist"
894 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
896 echo "$inputJson" > $file
898 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
900 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
901 if [ $# -lt 7 ]; then
902 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
907 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
909 __log_test_fail_general "Job template file "$7", does not exist"
913 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
915 echo "$inputJson" > $file
917 query="/A1-EI/v1/eijobs/$2"
920 res="$(__do_curl_to_api ICS PUT $query $file)"
921 status=${res:${#res}-3}
923 if [ $status -ne $1 ]; then
924 __log_test_fail_status_code $1 $status
933 ##########################################
934 #### information Data Producer API ####
935 ##########################################
936 # Function prefix: ics_api_edp
938 # API Test function: GET /ei-producer/v1/eitypes
939 # API Test function: GET /data-producer/v1/info-types
940 # args: <response-code> [ EMPTY | <type-id>+]
941 # (Function for test scripts)
942 ics_api_edp_get_type_ids() {
945 if [ $# -lt 1 ]; then
946 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
949 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
950 query="/data-producer/v1/info-types"
952 query="/ei-producer/v1/eitypes"
954 res="$(__do_curl_to_api ICS GET $query)"
955 status=${res:${#res}-3}
957 if [ $status -ne $1 ]; then
958 __log_test_fail_status_code $1 $status
962 if [ $# -gt 1 ]; then
963 body=${res:0:${#res}-3}
965 if [ $2 != "EMPTY" ]; then
966 for pid in ${@:2} ; do
967 if [ "$targetJson" != "[" ]; then
968 targetJson=$targetJson","
970 targetJson=$targetJson"\"$pid\""
973 targetJson=$targetJson"]"
974 echo " TARGET JSON: $targetJson" >> $HTTPLOG
975 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
977 if [ $res -ne 0 ]; then
987 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
988 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status
989 # args: <response-code> <producer-id> [<status> [<timeout>]]
990 # (Function for test scripts)
991 ics_api_edp_get_producer_status() {
994 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
995 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
998 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
999 query="/data-producer/v1/info-producers/$2/status"
1001 query="/ei-producer/v1/eiproducers/$2/status"
1005 res="$(__do_curl_to_api ICS GET $query)"
1006 status=${res:${#res}-3}
1008 if [ $# -eq 4 ]; then
1009 duration=$((SECONDS-start))
1010 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
1011 if [ $duration -gt $4 ]; then
1013 duration=-1 #Last iteration
1016 duration=-1 #single test, no wait
1019 if [ $status -ne $1 ]; then
1020 if [ $duration -eq -1 ]; then
1021 __log_test_fail_status_code $1 $status
1025 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1026 body=${res:0:${#res}-3}
1027 targetJson="{\"operational_state\": \"$3\"}"
1028 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1029 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1031 if [ $res -ne 0 ]; then
1032 if [ $duration -eq -1 ]; then
1033 __log_test_fail_body
1037 duration=-1 #Goto pass
1040 if [ $duration -eq -1 ]; then
1041 if [ $# -eq 4 ]; then
1053 # API Test function: GET /ei-producer/v1/eiproducers
1054 # args (v1_1): <response-code> [ EMPTY | <producer-id>+]
1055 # (Function for test scripts)
1056 ics_api_edp_get_producer_ids() {
1059 if [ $# -lt 1 ]; then
1060 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
1064 query="/ei-producer/v1/eiproducers"
1065 res="$(__do_curl_to_api ICS GET $query)"
1066 status=${res:${#res}-3}
1068 if [ $status -ne $1 ]; then
1069 __log_test_fail_status_code $1 $status
1073 if [ $# -gt 1 ]; then
1074 body=${res:0:${#res}-3}
1077 for pid in ${@:2} ; do
1078 if [ "$targetJson" != "[" ]; then
1079 targetJson=$targetJson","
1081 if [ $pid != "EMPTY" ]; then
1082 targetJson=$targetJson"\"$pid\""
1086 targetJson=$targetJson"]"
1087 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1088 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1090 if [ $res -ne 0 ]; then
1091 __log_test_fail_body
1100 # API Test function: GET /ei-producer/v1/eiproducers
1101 # API Test function: GET /data-producer/v1/info-producers
1102 # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1103 # (Function for test scripts)
1104 ics_api_edp_get_producer_ids_2() {
1107 if [ $# -lt 1 ]; then
1108 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1111 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1112 query="/data-producer/v1/info-producers"
1113 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1114 query=$query"?info_type_id=$2&infoTypeId=$2" #info_type_id changed to infoTypeId in F-release.
1115 #Remove info_type_id when F-release is no longer supported
1118 query="/ei-producer/v1/eiproducers"
1119 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1120 query=$query"?ei_type_id=$2"
1123 res="$(__do_curl_to_api ICS GET $query)"
1124 status=${res:${#res}-3}
1126 if [ $status -ne $1 ]; then
1127 __log_test_fail_status_code $1 $status
1131 if [ $# -gt 2 ]; then
1132 body=${res:0:${#res}-3}
1135 for pid in ${@:3} ; do
1136 if [ "$targetJson" != "[" ]; then
1137 targetJson=$targetJson","
1139 if [ $pid != "EMPTY" ]; then
1140 targetJson=$targetJson"\"$pid\""
1144 targetJson=$targetJson"]"
1145 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1146 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1148 if [ $res -ne 0 ]; then
1149 __log_test_fail_body
1158 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1159 # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
1160 # (Function for test scripts)
1161 ics_api_edp_get_type() {
1165 if [ $# -eq 2 ]; then
1168 if [ $# -gt 3 ]; then
1171 if [ $paramError -ne 0 ]; then
1172 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
1176 query="/ei-producer/v1/eitypes/$2"
1177 res="$(__do_curl_to_api ICS GET $query)"
1178 status=${res:${#res}-3}
1180 if [ $status -ne $1 ]; then
1181 __log_test_fail_status_code $1 $status
1184 if [ $# -gt 3 ]; then
1185 body=${res:0:${#res}-3}
1190 __log_test_fail_general "Job template file "$3", does not exist"
1195 if [ $4 != "EMPTY" ]; then
1196 for pid in ${@:4} ; do
1197 if [ "$targetJson" != "" ]; then
1198 targetJson=$targetJson","
1200 targetJson=$targetJson"\"$pid\""
1203 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1205 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1206 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1208 if [ $res -ne 0 ]; then
1209 __log_test_fail_body
1217 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1218 # API Test function: GET /data-producer/v1/info-types/{infoTypeId}
1219 # args: (v1_2) <response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]
1220 # (Function for test scripts)
1221 ics_api_edp_get_type_2() {
1225 if [ $# -eq 2 ]; then
1228 if [ $# -eq 3 ]; then
1231 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
1232 if [ $# -eq 4 ]; then
1236 if [ $paramError -ne 0 ]; then
1237 __print_err "<response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]" $@
1240 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1241 query="/data-producer/v1/info-types/$2"
1243 query="/ei-producer/v1/eitypes/$2"
1246 res="$(__do_curl_to_api ICS GET $query)"
1247 status=${res:${#res}-3}
1249 if [ $status -ne $1 ]; then
1250 __log_test_fail_status_code $1 $status
1253 if [ $# -ge 3 ]; then
1254 body=${res:0:${#res}-3}
1259 __log_test_fail_general "Job template file "$3", does not exist"
1263 if [ $# -gt 3 ]; then
1267 __log_test_fail_general "Info-data file "$4", does not exist"
1270 info_data=",\"info_type_information\":$info_data"
1272 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1273 targetJson="{\"info_job_data_schema\":$schema $info_data}"
1275 targetJson="{\"ei_job_data_schema\":$schema}"
1278 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1279 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1281 if [ $res -ne 0 ]; then
1282 __log_test_fail_body
1290 # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1291 # API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
1292 # args: (v1_2) <response-code> <type-id> <job-schema-file> [ <info-type-info> ]
1293 # (Function for test scripts)
1294 ics_api_edp_put_type_2() {
1297 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
1298 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1299 __print_err "<response-code> <type-id> <job-schema-file> [ <info-type-info> ]" $@
1303 if [ $# -ne 3 ]; then
1304 __print_err "<response-code> <type-id> <job-schema-file>" $@
1309 if [ ! -f $3 ]; then
1310 __log_test_fail_general "Job schema file "$3", does not exist"
1315 if [ $# -gt 3 ]; then
1319 __log_test_fail_general "Info-data file "$4", does not exist"
1322 info_data=",\"info_type_information\":$info_data"
1325 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1327 input_json="{\"info_job_data_schema\":$schema $info_data}"
1328 file="./tmp/put_type.json"
1329 echo $input_json > $file
1331 query="/data-producer/v1/info-types/$2"
1334 input_json="{\"ei_job_data_schema\":$schema}"
1335 file="./tmp/put_type.json"
1336 echo $input_json > $file
1338 query="/ei-producer/v1/eitypes/$2"
1340 res="$(__do_curl_to_api ICS PUT $query $file)"
1341 status=${res:${#res}-3}
1343 if [ $status -ne $1 ]; then
1344 __log_test_fail_status_code $1 $status
1352 # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1353 # API Test function: DELETE /data-producer/v1/info-types/{infoTypeId}
1354 # args: (v1_2) <response-code> <type-id>
1355 # (Function for test scripts)
1356 ics_api_edp_delete_type_2() {
1359 if [ $# -ne 2 ]; then
1360 __print_err "<response-code> <type-id>" $@
1364 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1365 query="/data-producer/v1/info-types/$2"
1367 query="/ei-producer/v1/eitypes/$2"
1369 res="$(__do_curl_to_api ICS DELETE $query)"
1370 status=${res:${#res}-3}
1372 if [ $status -ne $1 ]; then
1373 __log_test_fail_status_code $1 $status
1381 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1382 # args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
1383 # (Function for test scripts)
1384 ics_api_edp_get_producer() {
1387 #Possible arg count: 2, 5 6, 8, 10 etc
1389 if [ $# -eq 2 ]; then
1392 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1395 variablecount=$(($#-4))
1396 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1400 if [ $paramError -ne 0 ]; then
1401 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
1405 query="/ei-producer/v1/eiproducers/$2"
1406 res="$(__do_curl_to_api ICS GET $query)"
1407 status=${res:${#res}-3}
1409 if [ $status -ne $1 ]; then
1410 __log_test_fail_status_code $1 $status
1414 if [ $# -gt 2 ]; then
1415 body=${res:0:${#res}-3}
1417 if [ $# -gt 5 ]; then
1419 for ((i=0; i<$(($#-5)); i=i+2)); do
1420 if [ "$targetJson" != "[" ]; then
1421 targetJson=$targetJson","
1423 if [ -f ${arr[$i+1]} ]; then
1424 schema=$(cat ${arr[$i+1]})
1426 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1430 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1433 targetJson=$targetJson"]"
1434 if [ $# -gt 4 ]; then
1435 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1437 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1438 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1440 if [ $res -ne 0 ]; then
1441 __log_test_fail_body
1450 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1451 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}
1452 # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1453 # (Function for test scripts)
1454 ics_api_edp_get_producer_2() {
1457 #Possible arg count: 2, 5, 6, 7, 8 etc
1459 if [ $# -eq 2 ]; then
1462 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1465 if [ $# -ge 5 ]; then
1469 if [ $paramError -ne 0 ]; then
1470 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1473 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1474 query="/data-producer/v1/info-producers/$2"
1476 query="/ei-producer/v1/eiproducers/$2"
1478 res="$(__do_curl_to_api ICS GET $query)"
1479 status=${res:${#res}-3}
1481 if [ $status -ne $1 ]; then
1482 __log_test_fail_status_code $1 $status
1486 if [ $# -gt 2 ]; then
1487 body=${res:0:${#res}-3}
1489 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1491 for ((i=0; i<$(($#-4)); i=i+1)); do
1492 if [ "$targetJson" != "[" ]; then
1493 targetJson=$targetJson","
1495 targetJson=$targetJson"\"${arr[$i]}\""
1498 targetJson=$targetJson"]"
1499 if [ $# -gt 4 ]; then
1500 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1501 targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}"
1503 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1506 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1507 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1509 if [ $res -ne 0 ]; then
1510 __log_test_fail_body
1519 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
1520 # API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId}
1521 # args: <response-code> <producer-id>
1522 # (Function for test scripts)
1523 ics_api_edp_delete_producer() {
1526 if [ $# -lt 2 ]; then
1527 __print_err "<response-code> <producer-id>" $@
1530 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1531 query="/data-producer/v1/info-producers/$2"
1533 query="/ei-producer/v1/eiproducers/$2"
1535 res="$(__do_curl_to_api ICS DELETE $query)"
1536 status=${res:${#res}-3}
1538 if [ $status -ne $1 ]; then
1539 __log_test_fail_status_code $1 $status
1547 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1548 # args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
1549 # (Function for test scripts)
1550 ics_api_edp_put_producer() {
1553 #Valid number of parametrer 5,6,8,10,
1555 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1557 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
1560 if [ $paramError -ne 0 ]; then
1561 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
1566 if [ $# -gt 5 ]; then
1568 for ((i=0; i<$(($#-5)); i=i+2)); do
1569 if [ "$inputJson" != "[" ]; then
1570 inputJson=$inputJson","
1572 if [ -f ${arr[$i+1]} ]; then
1573 schema=$(cat ${arr[$i+1]})
1575 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1578 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1581 inputJson="\"supported_ei_types\":"$inputJson"]"
1583 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1585 inputJson="{"$inputJson"}"
1587 file="./tmp/.p.json"
1588 echo "$inputJson" > $file
1589 query="/ei-producer/v1/eiproducers/$2"
1590 res="$(__do_curl_to_api ICS PUT $query $file)"
1591 status=${res:${#res}-3}
1593 if [ $status -ne $1 ]; then
1594 __log_test_fail_status_code $1 $status
1602 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1603 # API Test function: PUT /data-producer/v1/info-producers/{infoProducerId}
1604 # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1605 # (Function for test scripts)
1606 ics_api_edp_put_producer_2() {
1609 #Valid number of parametrer 5,6,8,10,
1611 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1613 elif [ $# -ge 5 ]; then
1616 if [ $paramError -ne 0 ]; then
1617 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1622 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1624 for ((i=0; i<$(($#-4)); i=i+1)); do
1625 if [ "$inputJson" != "[" ]; then
1626 inputJson=$inputJson","
1628 inputJson=$inputJson"\""${arr[$i]}"\""
1631 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1632 inputJson="\"supported_info_types\":"$inputJson"]"
1634 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
1636 inputJson="{"$inputJson"}"
1638 file="./tmp/.p.json"
1639 echo "$inputJson" > $file
1640 query="/data-producer/v1/info-producers/$2"
1642 inputJson="\"supported_ei_types\":"$inputJson"]"
1644 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1646 inputJson="{"$inputJson"}"
1648 file="./tmp/.p.json"
1649 echo "$inputJson" > $file
1650 query="/ei-producer/v1/eiproducers/$2"
1652 res="$(__do_curl_to_api ICS PUT $query $file)"
1653 status=${res:${#res}-3}
1655 if [ $status -ne $1 ]; then
1656 __log_test_fail_status_code $1 $status
1664 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1665 # args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1666 # (Function for test scripts)
1667 ics_api_edp_get_producer_jobs() {
1670 #Valid number of parameter 2,3,7,11
1672 if [ $# -eq 2 ]; then
1675 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1678 variablecount=$(($#-2))
1679 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1682 if [ $paramError -eq 1 ]; then
1683 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1687 query="/ei-producer/v1/eiproducers/$2/eijobs"
1688 res="$(__do_curl_to_api ICS GET $query)"
1689 status=${res:${#res}-3}
1690 if [ $status -ne $1 ]; then
1691 __log_test_fail_status_code $1 $status
1694 if [ $# -gt 2 ]; then
1695 body=${res:0:${#res}-3}
1697 if [ $# -gt 3 ]; then
1699 for ((i=0; i<$(($#-3)); i=i+5)); do
1700 if [ "$targetJson" != "[" ]; then
1701 targetJson=$targetJson","
1703 if [ -f ${arr[$i+4]} ]; then
1704 jobfile=$(cat ${arr[$i+4]})
1705 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1707 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1710 targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile}"
1713 targetJson=$targetJson"]"
1715 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1716 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1718 if [ $res -ne 0 ]; then
1719 __log_test_fail_body
1728 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1729 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs
1730 # args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1731 # (Function for test scripts)
1732 ics_api_edp_get_producer_jobs_2() {
1735 #Valid number of parameter 2,3,7,11
1737 if [ $# -eq 2 ]; then
1740 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1743 variablecount=$(($#-2))
1744 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1747 if [ $paramError -eq 1 ]; then
1748 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1751 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1752 query="/data-producer/v1/info-producers/$2/info-jobs"
1754 query="/ei-producer/v1/eiproducers/$2/eijobs"
1756 res="$(__do_curl_to_api ICS GET $query)"
1757 status=${res:${#res}-3}
1758 if [ $status -ne $1 ]; then
1759 __log_test_fail_status_code $1 $status
1762 if [ $# -gt 2 ]; then
1763 body=${res:0:${#res}-3}
1765 if [ $# -gt 3 ]; then
1767 for ((i=0; i<$(($#-3)); i=i+5)); do
1768 if [ "$targetJson" != "[" ]; then
1769 targetJson=$targetJson","
1771 if [ -f ${arr[$i+4]} ]; then
1772 jobfile=$(cat ${arr[$i+4]})
1773 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1775 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1778 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1779 targetJson=$targetJson"{\"info_job_identity\":\"${arr[$i]}\",\"info_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"info_job_data\":$jobfile, \"last_updated\":\"????\"}"
1781 targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile, \"last_updated\":\"????\"}"
1785 targetJson=$targetJson"]"
1787 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1788 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1790 if [ $res -ne 0 ]; then
1791 __log_test_fail_body
1800 ##########################################
1801 #### Service status ####
1802 ##########################################
1803 # Function prefix: ics_api_service
1805 # API Test function: GET ​/status
1806 # args: <response-code>
1807 # (Function for test scripts)
1808 ics_api_service_status() {
1811 if [ $# -lt 1 ]; then
1812 __print_err "<response-code>" $@
1815 res="$(__do_curl_to_api ICS GET /status)"
1816 status=${res:${#res}-3}
1817 if [ $status -ne $1 ]; then
1818 __log_test_fail_status_code $1 $status
1825 ###########################################
1826 ######### Info data consumer API ##########
1827 ###########################################
1828 #Function prefix: ics_api_idc
1831 # API Test function: GET /data-consumer/v1/info-types
1832 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
1833 # (Function for test scripts)
1834 ics_api_idc_get_type_ids() {
1837 if [ $# -lt 1 ]; then
1838 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1842 query="/data-consumer/v1/info-types"
1843 res="$(__do_curl_to_api ICS GET $query)"
1844 status=${res:${#res}-3}
1846 if [ $status -ne $1 ]; then
1847 __log_test_fail_status_code $1 $status
1850 if [ $# -gt 1 ]; then
1851 body=${res:0:${#res}-3}
1853 if [ $2 != "EMPTY" ]; then
1854 for pid in ${@:2} ; do
1855 if [ "$targetJson" != "[" ]; then
1856 targetJson=$targetJson","
1858 targetJson=$targetJson"\"$pid\""
1861 targetJson=$targetJson"]"
1862 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1863 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1865 if [ $res -ne 0 ]; then
1866 __log_test_fail_body
1875 # API Test function: GET /data-consumer/v1/info-jobs
1876 # args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
1877 # (Function for test scripts)
1878 ics_api_idc_get_job_ids() {
1881 # Valid number of parameters 4,5,6 etc
1882 if [ $# -lt 3 ]; then
1883 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
1887 if [ $3 != "NOWNER" ]; then
1891 if [ $2 != "NOTYPE" ]; then
1892 if [ -z "$search" ]; then
1893 search="?infoTypeId="$2
1895 search=$search"&infoTypeId="$2
1898 query="/data-consumer/v1/info-jobs$search"
1900 res="$(__do_curl_to_api ICS GET $query)"
1901 status=${res:${#res}-3}
1903 if [ $status -ne $1 ]; then
1904 __log_test_fail_status_code $1 $status
1908 if [ $# -gt 3 ]; then
1909 body=${res:0:${#res}-3}
1912 for pid in ${@:4} ; do
1913 if [ "$targetJson" != "[" ]; then
1914 targetJson=$targetJson","
1916 if [ $pid != "EMPTY" ]; then
1917 targetJson=$targetJson"\"$pid\""
1921 targetJson=$targetJson"]"
1922 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1923 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1925 if [ $res -ne 0 ]; then
1926 __log_test_fail_body
1935 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
1936 # args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
1937 # (Function for test scripts)
1938 ics_api_idc_get_job() {
1941 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
1942 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
1945 query="/data-consumer/v1/info-jobs/$2"
1946 res="$(__do_curl_to_api ICS GET $query)"
1947 status=${res:${#res}-3}
1949 if [ $status -ne $1 ]; then
1950 __log_test_fail_status_code $1 $status
1954 if [ $# -eq 7 ]; then
1955 body=${res:0:${#res}-3}
1959 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1961 __log_test_fail_general "Job template file "$6", does not exist"
1964 targetJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
1965 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1966 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1968 if [ $res -ne 0 ]; then
1969 __log_test_fail_body
1979 # API Test function: PUT ​/data-consumer/v1/info-jobs/{infoJobId}
1980 # args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
1981 # (Function for test scripts)
1982 ics_api_idc_put_job() {
1985 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1986 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
1991 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1993 __log_test_fail_general "Job template file "$7", does not exist"
1997 inputJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
1998 file="./tmp/.p.json"
1999 echo "$inputJson" > $file
2001 query="/data-consumer/v1/info-jobs/$2"
2003 if [ $# -eq 8 ]; then
2004 if [ $8 == "VALIDATE" ]; then
2005 query=$query"?typeCheck=true"
2009 res="$(__do_curl_to_api ICS PUT $query $file)"
2010 status=${res:${#res}-3}
2012 if [ $status -ne $1 ]; then
2013 __log_test_fail_status_code $1 $status
2021 # API Test function: DELETE ​/data-consumer/v1/info-jobs/{infoJobId}
2022 # args: <response-code> <job-id>
2023 # (Function for test scripts)
2024 ics_api_idc_delete_job() {
2027 if [ $# -ne 2 ]; then
2028 __print_err "<response-code> <job-id>" $@
2031 query="/data-consumer/v1/info-jobs/$2"
2032 res="$(__do_curl_to_api ICS DELETE $query)"
2033 status=${res:${#res}-3}
2035 if [ $status -ne $1 ]; then
2036 __log_test_fail_status_code $1 $status
2044 # API Test function: GET ​/data-consumer/v1/info-types/{infoTypeId}
2045 # args: <response-code> <type-id> [<schema-file> [<type-status> <producers-count]]
2046 # (Function for test scripts)
2047 ics_api_idc_get_type() {
2050 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2051 __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@
2055 query="/data-consumer/v1/info-types/$2"
2056 res="$(__do_curl_to_api ICS GET $query)"
2057 status=${res:${#res}-3}
2059 if [ $status -ne $1 ]; then
2060 __log_test_fail_status_code $1 $status
2064 if [ $# -gt 2 ]; then
2065 body=${res:0:${#res}-3}
2069 __log_test_fail_general "Schema file "$3", does not exist"
2072 if [ $# -eq 5 ]; then
2073 targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}"
2075 targetJson="{\"job_data_schema\":$schema}"
2077 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2078 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2080 if [ $res -ne 0 ]; then
2081 __log_test_fail_body
2090 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2091 # This test only status during an optional timeout. No test of the list of producers
2092 # args: <response-code> <job-id> [<status> [<timeout>]]
2093 # (Function for test scripts)
2094 ics_api_idc_get_job_status() {
2097 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2098 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2102 query="/data-consumer/v1/info-jobs/$2/status"
2106 res="$(__do_curl_to_api ICS GET $query)"
2107 status=${res:${#res}-3}
2109 if [ $# -eq 4 ]; then
2110 duration=$((SECONDS-start))
2111 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2112 if [ $duration -gt $4 ]; then
2114 duration=-1 #Last iteration
2117 duration=-1 #single test, no wait
2120 if [ $status -ne $1 ]; then
2121 if [ $duration -eq -1 ]; then
2122 __log_test_fail_status_code $1 $status
2126 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
2127 body=${res:0:${#res}-3}
2128 targetJson="{\"info_job_status\": \"$3\"}"
2129 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2130 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2132 if [ $res -ne 0 ]; then
2133 if [ $duration -eq -1 ]; then
2134 __log_test_fail_body
2138 duration=-1 #Goto pass
2141 if [ $duration -eq -1 ]; then
2142 if [ $# -eq 4 ]; then
2156 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2157 # This function test status and the list of producers with and optional timeout
2158 # args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
2159 # (Function for test scripts)
2160 ics_api_idc_get_job_status2() {
2164 if [ $# -lt 2 ]; then
2169 if [ $# -gt 2 ]; then
2170 if [ $# -lt 4 ]; then
2173 targetJson="{\"info_job_status\": \"$3\""
2174 if [ "$4" == "EMPTYPROD" ]; then
2175 targetJson=$targetJson",\"producers\": []}"
2176 if [ $# -gt 4 ]; then
2180 targetJson=$targetJson",\"producers\": ["
2181 if [ $# -eq $(($4+5)) ]; then
2183 timeout=${args[$idx]}
2185 for ((ics_i = 0 ; ics_i < $4 ; ics_i++)); do
2187 if [ $ics_i -gt 0 ]; then
2188 targetJson=$targetJson","
2190 targetJson=$targetJson"\""${args[$idx]}"\""
2192 targetJson=$targetJson"]}"
2196 if [ $param_error -ne 0 ]; then
2197 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2201 query="/data-consumer/v1/info-jobs/$2/status"
2205 res="$(__do_curl_to_api ICS GET $query)"
2206 status=${res:${#res}-3}
2208 if [ $# -gt 2 ]; then
2209 duration=$((SECONDS-start))
2210 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2211 if [ $duration -gt $timeout ]; then
2213 duration=-1 #Last iteration
2216 duration=-1 #single test, no wait
2219 if [ $status -ne $1 ]; then
2220 if [ $duration -eq -1 ]; then
2221 __log_test_fail_status_code $1 $status
2225 if [ $# -gt 2 ] && [ $status -eq $1 ]; then
2226 body=${res:0:${#res}-3}
2227 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2228 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2230 if [ $res -ne 0 ]; then
2231 if [ $duration -eq -1 ]; then
2232 __log_test_fail_body
2236 duration=-1 #Goto pass
2239 if [ $duration -eq -1 ]; then
2240 if [ $# -eq 4 ]; then
2254 ##########################################
2255 #### Type subscriptions ####
2256 ##########################################
2258 # API Test function: GET /data-consumer/v1/info-type-subscription
2259 # args: <response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]
2260 # (Function for test scripts)
2261 ics_api_idc_get_subscription_ids() {
2264 if [ $# -lt 3 ]; then
2265 __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@
2269 query="/data-consumer/v1/info-type-subscription"
2271 if [ $2 != "NOOWNER" ]; then
2275 res="$(__do_curl_to_api ICS GET $query$search)"
2276 status=${res:${#res}-3}
2278 if [ $status -ne $1 ]; then
2279 __log_test_fail_status_code $1 $status
2283 if [ $# -gt 2 ]; then
2284 body=${res:0:${#res}-3}
2286 if [ $3 != "EMPTY" ]; then
2287 for pid in ${@:3} ; do
2288 if [ "$targetJson" != "[" ]; then
2289 targetJson=$targetJson","
2291 targetJson=$targetJson"\"$pid\""
2294 targetJson=$targetJson"]"
2295 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2296 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2298 if [ $res -ne 0 ]; then
2299 __log_test_fail_body
2308 # API Test function: GET /data-consumer/v1/info-type-subscription/{subscriptionId}
2309 # args: <response-code> <subscription-id> [ <owner-id> <status-uri> ]
2310 # (Function for test scripts)
2311 ics_api_idc_get_subscription() {
2314 if [ $# -ne 2 ] && [ $# -ne 4 ]; then
2315 __print_err "<response-code> <subscription-id> [ <owner-id> <status-uri> ]" $@
2319 query="/data-consumer/v1/info-type-subscription/$2"
2320 res="$(__do_curl_to_api ICS GET $query)"
2321 status=${res:${#res}-3}
2323 if [ $status -ne $1 ]; then
2324 __log_test_fail_status_code $1 $status
2328 if [ $# -gt 2 ]; then
2329 body=${res:0:${#res}-3}
2330 targetJson="{\"owner\":\"$3\",\"status_result_uri\":\"$4\"}"
2331 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2332 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2334 if [ $res -ne 0 ]; then
2335 __log_test_fail_body
2344 # API Test function: PUT /data-consumer/v1/info-type-subscription/{subscriptionId}
2345 # args: <response-code> <subscription-id> <owner-id> <status-uri>
2346 # (Function for test scripts)
2347 ics_api_idc_put_subscription() {
2350 if [ $# -ne 4 ]; then
2351 __print_err "<response-code> <subscription-id> <owner-id> <status-uri>" $@
2355 inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}"
2356 file="./tmp/.p.json"
2357 echo "$inputJson" > $file
2359 query="/data-consumer/v1/info-type-subscription/$2"
2360 res="$(__do_curl_to_api ICS PUT $query $file)"
2361 status=${res:${#res}-3}
2363 if [ $status -ne $1 ]; then
2364 __log_test_fail_status_code $1 $status
2372 # API Test function: DELETE /data-consumer/v1/info-type-subscription/{subscriptionId}
2373 # args: <response-code> <subscription-id>
2374 # (Function for test scripts)
2375 ics_api_idc_delete_subscription() {
2378 if [ $# -ne 2 ]; then
2379 __print_err "<response-code> <subscription-id> " $@
2383 query="/data-consumer/v1/info-type-subscription/$2"
2384 res="$(__do_curl_to_api ICS DELETE $query)"
2385 status=${res:${#res}-3}
2387 if [ $status -ne $1 ]; then
2388 __log_test_fail_status_code $1 $status
2396 ##########################################
2397 #### Reset jobs ####
2398 ##########################################
2399 # Function prefix: ics_api_admin
2401 # Admin to remove all jobs
2402 # args: <response-code> [ <type> ]
2403 # (Function for test scripts)
2405 ics_api_admin_reset() {
2408 if [ -z "$FLAT_A1_EI" ]; then
2409 query="/A1-EI/v1/eitypes/$2/eijobs"
2411 query="/A1-EI/v1/eijobs"
2413 res="$(__do_curl_to_api ICS GET $query)"
2414 status=${res:${#res}-3}
2416 if [ $status -ne 200 ]; then
2417 __log_test_fail_status_code $1 $status
2421 #Remove brackets and response code
2422 body=${res:1:${#res}-4}
2423 list=$(echo ${body//,/ })
2424 list=$(echo ${list//[/})
2425 list=$(echo ${list//]/})
2426 list=$(echo ${list//\"/})
2428 for job in $list; do
2429 if [ -z "$FLAT_A1_EI" ]; then
2430 echo "Not supported for non-flat EI api"
2432 query="/A1-EI/v1/eijobs/$job"
2433 res="$(__do_curl_to_api ICS DELETE $query)"
2434 status=${res:${#res}-3}
2435 if [ $status -ne 204 ]; then
2436 __log_test_fail_status_code $1 $status
2439 echo " Deleted job: "$job
2447 ##########################################
2448 #### Reset jobs and producers ####
2449 ##########################################
2452 # Admin reset to remove all data in ics; jobs, producers etc
2453 # NOTE - only works in kubernetes and the pod should not be running
2455 # (Function for test scripts)
2457 ics_kube_pvc_reset() {
2460 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep information)
2461 if [ -z "$pvc_name" ]; then
2462 pvc_name=informationservice-pvc
2464 echo " Trying to reset pvc: "$pvc_name
2466 __kube_clean_pvc $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $ICS_CONTAINER_MNT_DIR
2472 # args: <realm> <client-name> <client-secret>
2473 ics_configure_sec() {
2474 export ICS_CREDS_GRANT_TYPE="client_credentials"
2475 export ICS_CREDS_CLIENT_SECRET=$3
2476 export ICS_CREDS_CLIENT_ID=$2
2477 export ICS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
2478 export ICS_SIDECAR_MOUNT="/token-cache"
2479 export ICS_SIDECAR_JWT_FILE=$ICS_SIDECAR_MOUNT"/jwt.txt"
2481 export AUTHSIDECAR_APP_NAME
2482 export AUTHSIDECAR_DISPLAY_NAME