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"
335 dest_file=$SIM_GROUP/$ICS_COMPOSE_DIR/$ICS_HOST_MNT_DIR/$ICS_CONFIG_FILE
337 envsubst < $2 > $dest_file
339 __start_container $ICS_COMPOSE_DIR "" NODOCKERARGS 1 $ICS_APP_NAME
341 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
350 # (Function for test scripts)
352 echo -e $BOLD"Stopping $ICS_DISPLAY_NAME"$EBOLD
354 if [ $RUNMODE == "KUBE" ]; then
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
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
373 docker stop $ICS_APP_NAME &> ./tmp/.dockererr
374 if [ $? -ne 0 ]; then
375 __print_err "Could not stop $ICS_APP_NAME" $@
381 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
386 # Start a previously stopped ics
388 # (Function for test scripts)
389 start_stopped_ics() {
390 echo -e $BOLD"Starting (the previously stopped) $ICS_DISPLAY_NAME"$EBOLD
392 if [ $RUNMODE == "KUBE" ]; then
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
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
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
416 __kube_scale deployment $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
419 docker start $ICS_APP_NAME &> ./tmp/.dockererr
420 if [ $? -ne 0 ]; then
421 __print_err "Could not start (the stopped) $ICS_APP_NAME" $@
427 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
428 if [ $? -ne 0 ]; then
435 # Turn on debug level tracing in ICS
437 # (Function for test scripts)
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" $@
451 # Turn on trace level tracing in ICS
453 # (Function for test scripts)
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" $@
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>]*
471 echo -e $BOLD"Do curl retries to the ICS REST inteface for these response codes:$@"$EBOLD
477 # Check the ics logs for WARNINGs and ERRORs
479 # (Function for test scripts)
481 __check_container_logs "ICS" $ICS_APP_NAME $ICS_LOGPATH WARN ERR
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
491 # (Function for test scripts)
493 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
494 __var_test ICS "$ICS_SERVICE_PATH/" $1 "=" $2 $3
496 __print_err "Wrong args to ics_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
501 ##########################################
502 ######### A1-E information API ##########
503 ##########################################
504 #Function prefix: ics_api_a1
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() {
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>+ ]" $@
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>+ ]" $@
528 if [ $3 != "NOWNER" ]; then
532 if [ -z "$FLAT_A1_EI" ]; then
533 query="/A1-EI/v1/eitypes/$2/eijobs$search"
535 if [ $2 != "NOTYPE" ]; then
536 if [ -z "$search" ]; then
537 search="?eiTypeId="$2
539 search=$search"&eiTypeId="$2
542 query="/A1-EI/v1/eijobs$search"
544 res="$(__do_curl_to_api ICS GET $query)"
545 status=${res:${#res}-3}
547 if [ $status -ne $1 ]; then
548 __log_test_fail_status_code $1 $status
552 if [ $# -gt 3 ]; then
553 body=${res:0:${#res}-3}
556 for pid in ${@:4} ; do
557 if [ "$targetJson" != "[" ]; then
558 targetJson=$targetJson","
560 if [ $pid != "EMPTY" ]; then
561 targetJson=$targetJson"\"$pid\""
565 targetJson=$targetJson"]"
566 echo " TARGET JSON: $targetJson" >> $HTTPLOG
567 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
569 if [ $res -ne 0 ]; then
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() {
585 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
586 __print_err "<response-code> <type-id> [<schema-file>]" $@
590 query="/A1-EI/v1/eitypes/$2"
591 res="$(__do_curl_to_api ICS GET $query)"
592 status=${res:${#res}-3}
594 if [ $status -ne $1 ]; then
595 __log_test_fail_status_code $1 $status
599 if [ $# -eq 3 ]; then
600 body=${res:0:${#res}-3}
604 __log_test_fail_general "Schema file "$3", does not exist"
607 if [ -z "$FLAT_A1_EI" ]; then
608 targetJson="{\"eiJobParametersSchema\":$schema}"
612 echo " TARGET JSON: $targetJson" >> $HTTPLOG
613 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
615 if [ $res -ne 0 ]; then
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() {
631 if [ $# -lt 1 ]; then
632 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
636 query="/A1-EI/v1/eitypes"
637 res="$(__do_curl_to_api ICS GET $query)"
638 status=${res:${#res}-3}
640 if [ $status -ne $1 ]; then
641 __log_test_fail_status_code $1 $status
644 if [ $# -gt 1 ]; then
645 body=${res:0:${#res}-3}
647 if [ $2 != "EMPTY" ]; then
648 for pid in ${@:2} ; do
649 if [ "$targetJson" != "[" ]; then
650 targetJson=$targetJson","
652 targetJson=$targetJson"\"$pid\""
655 targetJson=$targetJson"]"
656 echo " TARGET JSON: $targetJson" >> $HTTPLOG
657 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
659 if [ $res -ne 0 ]; then
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() {
676 if [ -z "$FLAT_A1_EI" ]; then
677 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
678 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
682 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
684 res="$(__do_curl_to_api ICS GET $query)"
685 status=${res:${#res}-3}
687 if [ $status -ne $1 ]; then
688 __log_test_fail_status_code $1 $status
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")
697 if [ $res -ne 0 ]; then
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>]]" $@
709 query="/A1-EI/v1/eijobs/$2/status"
713 res="$(__do_curl_to_api ICS GET $query)"
714 status=${res:${#res}-3}
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
721 duration=-1 #Last iteration
724 duration=-1 #single test, no wait
727 if [ $status -ne $1 ]; then
728 if [ $duration -eq -1 ]; then
729 __log_test_fail_status_code $1 $status
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")
739 if [ $res -ne 0 ]; then
740 if [ $duration -eq -1 ]; then
745 duration=-1 #Goto pass
748 if [ $duration -eq -1 ]; then
749 if [ $# -eq 4 ]; then
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() {
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>]" $@
776 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
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>]" $@
783 query="/A1-EI/v1/eijobs/$2"
785 res="$(__do_curl_to_api ICS GET $query)"
786 status=${res:${#res}-3}
788 if [ $status -ne $1 ]; then
789 __log_test_fail_status_code $1 $status
793 if [ -z "$FLAT_A1_EI" ]; then
794 if [ $# -eq 6 ]; then
795 body=${res:0:${#res}-3}
799 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
801 __log_test_fail_general "Job template file "$6", does not exist"
804 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
805 echo " TARGET JSON: $targetJson" >> $HTTPLOG
806 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
808 if [ $res -ne 0 ]; then
814 if [ $# -eq 7 ]; then
815 body=${res:0:${#res}-3}
819 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
821 __log_test_fail_general "Job template file "$6", does not exist"
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")
828 if [ $res -ne 0 ]; then
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() {
846 if [ -z "$FLAT_A1_EI" ]; then
847 if [ $# -ne 3 ]; then
848 __print_err "<response-code> <type-id> <job-id>" $@
852 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
854 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
855 if [ $# -ne 2 ]; then
856 __print_err "<response-code> <job-id>" $@
859 query="/A1-EI/v1/eijobs/$2"
861 res="$(__do_curl_to_api ICS DELETE $query)"
862 status=${res:${#res}-3}
864 if [ $status -ne $1 ]; then
865 __log_test_fail_status_code $1 $status
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() {
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>" $@
887 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
889 __log_test_fail_general "Job template file "$6", does not exist"
893 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
895 echo "$inputJson" > $file
897 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
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>" $@
906 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
908 __log_test_fail_general "Job template file "$7", does not exist"
912 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
914 echo "$inputJson" > $file
916 query="/A1-EI/v1/eijobs/$2"
919 res="$(__do_curl_to_api ICS PUT $query $file)"
920 status=${res:${#res}-3}
922 if [ $status -ne $1 ]; then
923 __log_test_fail_status_code $1 $status
932 ##########################################
933 #### information Data Producer API ####
934 ##########################################
935 # Function prefix: ics_api_edp
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() {
944 if [ $# -lt 1 ]; then
945 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
948 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
949 query="/data-producer/v1/info-types"
951 query="/ei-producer/v1/eitypes"
953 res="$(__do_curl_to_api ICS GET $query)"
954 status=${res:${#res}-3}
956 if [ $status -ne $1 ]; then
957 __log_test_fail_status_code $1 $status
961 if [ $# -gt 1 ]; then
962 body=${res:0:${#res}-3}
964 if [ $2 != "EMPTY" ]; then
965 for pid in ${@:2} ; do
966 if [ "$targetJson" != "[" ]; then
967 targetJson=$targetJson","
969 targetJson=$targetJson"\"$pid\""
972 targetJson=$targetJson"]"
973 echo " TARGET JSON: $targetJson" >> $HTTPLOG
974 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
976 if [ $res -ne 0 ]; then
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() {
993 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
994 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
997 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
998 query="/data-producer/v1/info-producers/$2/status"
1000 query="/ei-producer/v1/eiproducers/$2/status"
1004 res="$(__do_curl_to_api ICS GET $query)"
1005 status=${res:${#res}-3}
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
1012 duration=-1 #Last iteration
1015 duration=-1 #single test, no wait
1018 if [ $status -ne $1 ]; then
1019 if [ $duration -eq -1 ]; then
1020 __log_test_fail_status_code $1 $status
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")
1030 if [ $res -ne 0 ]; then
1031 if [ $duration -eq -1 ]; then
1032 __log_test_fail_body
1036 duration=-1 #Goto pass
1039 if [ $duration -eq -1 ]; then
1040 if [ $# -eq 4 ]; then
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() {
1058 if [ $# -lt 1 ]; then
1059 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
1063 query="/ei-producer/v1/eiproducers"
1064 res="$(__do_curl_to_api ICS GET $query)"
1065 status=${res:${#res}-3}
1067 if [ $status -ne $1 ]; then
1068 __log_test_fail_status_code $1 $status
1072 if [ $# -gt 1 ]; then
1073 body=${res:0:${#res}-3}
1076 for pid in ${@:2} ; do
1077 if [ "$targetJson" != "[" ]; then
1078 targetJson=$targetJson","
1080 if [ $pid != "EMPTY" ]; then
1081 targetJson=$targetJson"\"$pid\""
1085 targetJson=$targetJson"]"
1086 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1087 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1089 if [ $res -ne 0 ]; then
1090 __log_test_fail_body
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() {
1106 if [ $# -lt 1 ]; then
1107 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
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
1117 query="/ei-producer/v1/eiproducers"
1118 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1119 query=$query"?ei_type_id=$2"
1122 res="$(__do_curl_to_api ICS GET $query)"
1123 status=${res:${#res}-3}
1125 if [ $status -ne $1 ]; then
1126 __log_test_fail_status_code $1 $status
1130 if [ $# -gt 2 ]; then
1131 body=${res:0:${#res}-3}
1134 for pid in ${@:3} ; do
1135 if [ "$targetJson" != "[" ]; then
1136 targetJson=$targetJson","
1138 if [ $pid != "EMPTY" ]; then
1139 targetJson=$targetJson"\"$pid\""
1143 targetJson=$targetJson"]"
1144 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1145 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1147 if [ $res -ne 0 ]; then
1148 __log_test_fail_body
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() {
1164 if [ $# -eq 2 ]; then
1167 if [ $# -gt 3 ]; then
1170 if [ $paramError -ne 0 ]; then
1171 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
1175 query="/ei-producer/v1/eitypes/$2"
1176 res="$(__do_curl_to_api ICS GET $query)"
1177 status=${res:${#res}-3}
1179 if [ $status -ne $1 ]; then
1180 __log_test_fail_status_code $1 $status
1183 if [ $# -gt 3 ]; then
1184 body=${res:0:${#res}-3}
1189 __log_test_fail_general "Job template file "$3", does not exist"
1194 if [ $4 != "EMPTY" ]; then
1195 for pid in ${@:4} ; do
1196 if [ "$targetJson" != "" ]; then
1197 targetJson=$targetJson","
1199 targetJson=$targetJson"\"$pid\""
1202 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1204 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1205 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1207 if [ $res -ne 0 ]; then
1208 __log_test_fail_body
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() {
1224 if [ $# -eq 2 ]; then
1227 if [ $# -eq 3 ]; then
1230 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
1231 if [ $# -eq 4 ]; then
1235 if [ $paramError -ne 0 ]; then
1236 __print_err "<response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]" $@
1239 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1240 query="/data-producer/v1/info-types/$2"
1242 query="/ei-producer/v1/eitypes/$2"
1245 res="$(__do_curl_to_api ICS GET $query)"
1246 status=${res:${#res}-3}
1248 if [ $status -ne $1 ]; then
1249 __log_test_fail_status_code $1 $status
1252 if [ $# -ge 3 ]; then
1253 body=${res:0:${#res}-3}
1258 __log_test_fail_general "Job template file "$3", does not exist"
1262 if [ $# -gt 3 ]; then
1266 __log_test_fail_general "Info-data file "$4", does not exist"
1269 info_data=",\"info_type_information\":$info_data"
1271 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1272 targetJson="{\"info_job_data_schema\":$schema $info_data}"
1274 targetJson="{\"ei_job_data_schema\":$schema}"
1277 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1278 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1280 if [ $res -ne 0 ]; then
1281 __log_test_fail_body
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() {
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> ]" $@
1302 if [ $# -ne 3 ]; then
1303 __print_err "<response-code> <type-id> <job-schema-file>" $@
1308 if [ ! -f $3 ]; then
1309 __log_test_fail_general "Job schema file "$3", does not exist"
1314 if [ $# -gt 3 ]; then
1318 __log_test_fail_general "Info-data file "$4", does not exist"
1321 info_data=",\"info_type_information\":$info_data"
1324 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1326 input_json="{\"info_job_data_schema\":$schema $info_data}"
1327 file="./tmp/put_type.json"
1328 echo $input_json > $file
1330 query="/data-producer/v1/info-types/$2"
1333 input_json="{\"ei_job_data_schema\":$schema}"
1334 file="./tmp/put_type.json"
1335 echo $input_json > $file
1337 query="/ei-producer/v1/eitypes/$2"
1339 res="$(__do_curl_to_api ICS PUT $query $file)"
1340 status=${res:${#res}-3}
1342 if [ $status -ne $1 ]; then
1343 __log_test_fail_status_code $1 $status
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() {
1358 if [ $# -ne 2 ]; then
1359 __print_err "<response-code> <type-id>" $@
1363 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1364 query="/data-producer/v1/info-types/$2"
1366 query="/ei-producer/v1/eitypes/$2"
1368 res="$(__do_curl_to_api ICS DELETE $query)"
1369 status=${res:${#res}-3}
1371 if [ $status -ne $1 ]; then
1372 __log_test_fail_status_code $1 $status
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() {
1386 #Possible arg count: 2, 5 6, 8, 10 etc
1388 if [ $# -eq 2 ]; then
1391 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1394 variablecount=$(($#-4))
1395 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1399 if [ $paramError -ne 0 ]; then
1400 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
1404 query="/ei-producer/v1/eiproducers/$2"
1405 res="$(__do_curl_to_api ICS GET $query)"
1406 status=${res:${#res}-3}
1408 if [ $status -ne $1 ]; then
1409 __log_test_fail_status_code $1 $status
1413 if [ $# -gt 2 ]; then
1414 body=${res:0:${#res}-3}
1416 if [ $# -gt 5 ]; then
1418 for ((i=0; i<$(($#-5)); i=i+2)); do
1419 if [ "$targetJson" != "[" ]; then
1420 targetJson=$targetJson","
1422 if [ -f ${arr[$i+1]} ]; then
1423 schema=$(cat ${arr[$i+1]})
1425 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1429 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
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\"}"
1436 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1437 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1439 if [ $res -ne 0 ]; then
1440 __log_test_fail_body
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() {
1456 #Possible arg count: 2, 5, 6, 7, 8 etc
1458 if [ $# -eq 2 ]; then
1461 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1464 if [ $# -ge 5 ]; then
1468 if [ $paramError -ne 0 ]; then
1469 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1472 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1473 query="/data-producer/v1/info-producers/$2"
1475 query="/ei-producer/v1/eiproducers/$2"
1477 res="$(__do_curl_to_api ICS GET $query)"
1478 status=${res:${#res}-3}
1480 if [ $status -ne $1 ]; then
1481 __log_test_fail_status_code $1 $status
1485 if [ $# -gt 2 ]; then
1486 body=${res:0:${#res}-3}
1488 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1490 for ((i=0; i<$(($#-4)); i=i+1)); do
1491 if [ "$targetJson" != "[" ]; then
1492 targetJson=$targetJson","
1494 targetJson=$targetJson"\"${arr[$i]}\""
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\"}"
1502 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1505 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1506 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1508 if [ $res -ne 0 ]; then
1509 __log_test_fail_body
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() {
1525 if [ $# -lt 2 ]; then
1526 __print_err "<response-code> <producer-id>" $@
1529 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1530 query="/data-producer/v1/info-producers/$2"
1532 query="/ei-producer/v1/eiproducers/$2"
1534 res="$(__do_curl_to_api ICS DELETE $query)"
1535 status=${res:${#res}-3}
1537 if [ $status -ne $1 ]; then
1538 __log_test_fail_status_code $1 $status
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() {
1552 #Valid number of parametrer 5,6,8,10,
1554 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1556 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
1559 if [ $paramError -ne 0 ]; then
1560 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
1565 if [ $# -gt 5 ]; then
1567 for ((i=0; i<$(($#-5)); i=i+2)); do
1568 if [ "$inputJson" != "[" ]; then
1569 inputJson=$inputJson","
1571 if [ -f ${arr[$i+1]} ]; then
1572 schema=$(cat ${arr[$i+1]})
1574 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1577 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1580 inputJson="\"supported_ei_types\":"$inputJson"]"
1582 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1584 inputJson="{"$inputJson"}"
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}
1592 if [ $status -ne $1 ]; then
1593 __log_test_fail_status_code $1 $status
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() {
1608 #Valid number of parametrer 5,6,8,10,
1610 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1612 elif [ $# -ge 5 ]; then
1615 if [ $paramError -ne 0 ]; then
1616 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1621 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1623 for ((i=0; i<$(($#-4)); i=i+1)); do
1624 if [ "$inputJson" != "[" ]; then
1625 inputJson=$inputJson","
1627 inputJson=$inputJson"\""${arr[$i]}"\""
1630 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1631 inputJson="\"supported_info_types\":"$inputJson"]"
1633 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
1635 inputJson="{"$inputJson"}"
1637 file="./tmp/.p.json"
1638 echo "$inputJson" > $file
1639 query="/data-producer/v1/info-producers/$2"
1641 inputJson="\"supported_ei_types\":"$inputJson"]"
1643 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1645 inputJson="{"$inputJson"}"
1647 file="./tmp/.p.json"
1648 echo "$inputJson" > $file
1649 query="/ei-producer/v1/eiproducers/$2"
1651 res="$(__do_curl_to_api ICS PUT $query $file)"
1652 status=${res:${#res}-3}
1654 if [ $status -ne $1 ]; then
1655 __log_test_fail_status_code $1 $status
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() {
1669 #Valid number of parameter 2,3,7,11
1671 if [ $# -eq 2 ]; then
1674 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1677 variablecount=$(($#-2))
1678 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
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>]+)" $@
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
1693 if [ $# -gt 2 ]; then
1694 body=${res:0:${#res}-3}
1696 if [ $# -gt 3 ]; then
1698 for ((i=0; i<$(($#-3)); i=i+5)); do
1699 if [ "$targetJson" != "[" ]; then
1700 targetJson=$targetJson","
1702 if [ -f ${arr[$i+4]} ]; then
1703 jobfile=$(cat ${arr[$i+4]})
1704 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1706 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
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}"
1712 targetJson=$targetJson"]"
1714 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1715 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1717 if [ $res -ne 0 ]; then
1718 __log_test_fail_body
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() {
1734 #Valid number of parameter 2,3,7,11
1736 if [ $# -eq 2 ]; then
1739 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1742 variablecount=$(($#-2))
1743 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
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>]+)" $@
1750 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1751 query="/data-producer/v1/info-producers/$2/info-jobs"
1753 query="/ei-producer/v1/eiproducers/$2/eijobs"
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
1761 if [ $# -gt 2 ]; then
1762 body=${res:0:${#res}-3}
1764 if [ $# -gt 3 ]; then
1766 for ((i=0; i<$(($#-3)); i=i+5)); do
1767 if [ "$targetJson" != "[" ]; then
1768 targetJson=$targetJson","
1770 if [ -f ${arr[$i+4]} ]; then
1771 jobfile=$(cat ${arr[$i+4]})
1772 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1774 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
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\":\"????\"}"
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\":\"????\"}"
1784 targetJson=$targetJson"]"
1786 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1787 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1789 if [ $res -ne 0 ]; then
1790 __log_test_fail_body
1799 ##########################################
1800 #### Service status ####
1801 ##########################################
1802 # Function prefix: ics_api_service
1804 # API Test function: GET ​/status
1805 # args: <response-code>
1806 # (Function for test scripts)
1807 ics_api_service_status() {
1810 if [ $# -lt 1 ]; then
1811 __print_err "<response-code>" $@
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
1824 ###########################################
1825 ######### Info data consumer API ##########
1826 ###########################################
1827 #Function prefix: ics_api_idc
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() {
1836 if [ $# -lt 1 ]; then
1837 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1841 query="/data-consumer/v1/info-types"
1842 res="$(__do_curl_to_api ICS GET $query)"
1843 status=${res:${#res}-3}
1845 if [ $status -ne $1 ]; then
1846 __log_test_fail_status_code $1 $status
1849 if [ $# -gt 1 ]; then
1850 body=${res:0:${#res}-3}
1852 if [ $2 != "EMPTY" ]; then
1853 for pid in ${@:2} ; do
1854 if [ "$targetJson" != "[" ]; then
1855 targetJson=$targetJson","
1857 targetJson=$targetJson"\"$pid\""
1860 targetJson=$targetJson"]"
1861 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1862 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1864 if [ $res -ne 0 ]; then
1865 __log_test_fail_body
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() {
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>+ ]" $@
1886 if [ $3 != "NOWNER" ]; then
1890 if [ $2 != "NOTYPE" ]; then
1891 if [ -z "$search" ]; then
1892 search="?infoTypeId="$2
1894 search=$search"&infoTypeId="$2
1897 query="/data-consumer/v1/info-jobs$search"
1899 res="$(__do_curl_to_api ICS GET $query)"
1900 status=${res:${#res}-3}
1902 if [ $status -ne $1 ]; then
1903 __log_test_fail_status_code $1 $status
1907 if [ $# -gt 3 ]; then
1908 body=${res:0:${#res}-3}
1911 for pid in ${@:4} ; do
1912 if [ "$targetJson" != "[" ]; then
1913 targetJson=$targetJson","
1915 if [ $pid != "EMPTY" ]; then
1916 targetJson=$targetJson"\"$pid\""
1920 targetJson=$targetJson"]"
1921 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1922 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1924 if [ $res -ne 0 ]; then
1925 __log_test_fail_body
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() {
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>]" $@
1944 query="/data-consumer/v1/info-jobs/$2"
1945 res="$(__do_curl_to_api ICS GET $query)"
1946 status=${res:${#res}-3}
1948 if [ $status -ne $1 ]; then
1949 __log_test_fail_status_code $1 $status
1953 if [ $# -eq 7 ]; then
1954 body=${res:0:${#res}-3}
1958 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1960 __log_test_fail_general "Job template file "$6", does not exist"
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")
1967 if [ $res -ne 0 ]; then
1968 __log_test_fail_body
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() {
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 ]" $@
1990 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1992 __log_test_fail_general "Job template file "$7", does not exist"
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
2000 query="/data-consumer/v1/info-jobs/$2"
2002 if [ $# -eq 8 ]; then
2003 if [ $8 == "VALIDATE" ]; then
2004 query=$query"?typeCheck=true"
2008 res="$(__do_curl_to_api ICS PUT $query $file)"
2009 status=${res:${#res}-3}
2011 if [ $status -ne $1 ]; then
2012 __log_test_fail_status_code $1 $status
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() {
2026 if [ $# -ne 2 ]; then
2027 __print_err "<response-code> <job-id>" $@
2030 query="/data-consumer/v1/info-jobs/$2"
2031 res="$(__do_curl_to_api ICS DELETE $query)"
2032 status=${res:${#res}-3}
2034 if [ $status -ne $1 ]; then
2035 __log_test_fail_status_code $1 $status
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() {
2049 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2050 __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@
2054 query="/data-consumer/v1/info-types/$2"
2055 res="$(__do_curl_to_api ICS GET $query)"
2056 status=${res:${#res}-3}
2058 if [ $status -ne $1 ]; then
2059 __log_test_fail_status_code $1 $status
2063 if [ $# -gt 2 ]; then
2064 body=${res:0:${#res}-3}
2068 __log_test_fail_general "Schema file "$3", does not exist"
2071 if [ $# -eq 5 ]; then
2072 targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}"
2074 targetJson="{\"job_data_schema\":$schema}"
2076 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2077 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2079 if [ $res -ne 0 ]; then
2080 __log_test_fail_body
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() {
2096 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2097 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2101 query="/data-consumer/v1/info-jobs/$2/status"
2105 res="$(__do_curl_to_api ICS GET $query)"
2106 status=${res:${#res}-3}
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
2113 duration=-1 #Last iteration
2116 duration=-1 #single test, no wait
2119 if [ $status -ne $1 ]; then
2120 if [ $duration -eq -1 ]; then
2121 __log_test_fail_status_code $1 $status
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")
2131 if [ $res -ne 0 ]; then
2132 if [ $duration -eq -1 ]; then
2133 __log_test_fail_body
2137 duration=-1 #Goto pass
2140 if [ $duration -eq -1 ]; then
2141 if [ $# -eq 4 ]; then
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() {
2163 if [ $# -lt 2 ]; then
2168 if [ $# -gt 2 ]; then
2169 if [ $# -lt 4 ]; then
2172 targetJson="{\"info_job_status\": \"$3\""
2173 if [ "$4" == "EMPTYPROD" ]; then
2174 targetJson=$targetJson",\"producers\": []}"
2175 if [ $# -gt 4 ]; then
2179 targetJson=$targetJson",\"producers\": ["
2180 if [ $# -eq $(($4+5)) ]; then
2182 timeout=${args[$idx]}
2184 for ((ics_i = 0 ; ics_i < $4 ; ics_i++)); do
2186 if [ $ics_i -gt 0 ]; then
2187 targetJson=$targetJson","
2189 targetJson=$targetJson"\""${args[$idx]}"\""
2191 targetJson=$targetJson"]}"
2195 if [ $param_error -ne 0 ]; then
2196 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2200 query="/data-consumer/v1/info-jobs/$2/status"
2204 res="$(__do_curl_to_api ICS GET $query)"
2205 status=${res:${#res}-3}
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
2212 duration=-1 #Last iteration
2215 duration=-1 #single test, no wait
2218 if [ $status -ne $1 ]; then
2219 if [ $duration -eq -1 ]; then
2220 __log_test_fail_status_code $1 $status
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")
2229 if [ $res -ne 0 ]; then
2230 if [ $duration -eq -1 ]; then
2231 __log_test_fail_body
2235 duration=-1 #Goto pass
2238 if [ $duration -eq -1 ]; then
2239 if [ $# -eq 4 ]; then
2253 ##########################################
2254 #### Type subscriptions ####
2255 ##########################################
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() {
2263 if [ $# -lt 3 ]; then
2264 __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@
2268 query="/data-consumer/v1/info-type-subscription"
2270 if [ $2 != "NOOWNER" ]; then
2274 res="$(__do_curl_to_api ICS GET $query$search)"
2275 status=${res:${#res}-3}
2277 if [ $status -ne $1 ]; then
2278 __log_test_fail_status_code $1 $status
2282 if [ $# -gt 2 ]; then
2283 body=${res:0:${#res}-3}
2285 if [ $3 != "EMPTY" ]; then
2286 for pid in ${@:3} ; do
2287 if [ "$targetJson" != "[" ]; then
2288 targetJson=$targetJson","
2290 targetJson=$targetJson"\"$pid\""
2293 targetJson=$targetJson"]"
2294 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2295 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2297 if [ $res -ne 0 ]; then
2298 __log_test_fail_body
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() {
2313 if [ $# -ne 2 ] && [ $# -ne 4 ]; then
2314 __print_err "<response-code> <subscription-id> [ <owner-id> <status-uri> ]" $@
2318 query="/data-consumer/v1/info-type-subscription/$2"
2319 res="$(__do_curl_to_api ICS GET $query)"
2320 status=${res:${#res}-3}
2322 if [ $status -ne $1 ]; then
2323 __log_test_fail_status_code $1 $status
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")
2333 if [ $res -ne 0 ]; then
2334 __log_test_fail_body
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() {
2349 if [ $# -ne 4 ]; then
2350 __print_err "<response-code> <subscription-id> <owner-id> <status-uri>" $@
2354 inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}"
2355 file="./tmp/.p.json"
2356 echo "$inputJson" > $file
2358 query="/data-consumer/v1/info-type-subscription/$2"
2359 res="$(__do_curl_to_api ICS PUT $query $file)"
2360 status=${res:${#res}-3}
2362 if [ $status -ne $1 ]; then
2363 __log_test_fail_status_code $1 $status
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() {
2377 if [ $# -ne 2 ]; then
2378 __print_err "<response-code> <subscription-id> " $@
2382 query="/data-consumer/v1/info-type-subscription/$2"
2383 res="$(__do_curl_to_api ICS DELETE $query)"
2384 status=${res:${#res}-3}
2386 if [ $status -ne $1 ]; then
2387 __log_test_fail_status_code $1 $status
2395 ##########################################
2396 #### Reset jobs ####
2397 ##########################################
2398 # Function prefix: ics_api_admin
2400 # Admin to remove all jobs
2401 # args: <response-code> [ <type> ]
2402 # (Function for test scripts)
2404 ics_api_admin_reset() {
2407 if [ -z "$FLAT_A1_EI" ]; then
2408 query="/A1-EI/v1/eitypes/$2/eijobs"
2410 query="/A1-EI/v1/eijobs"
2412 res="$(__do_curl_to_api ICS GET $query)"
2413 status=${res:${#res}-3}
2415 if [ $status -ne 200 ]; then
2416 __log_test_fail_status_code $1 $status
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//\"/})
2427 for job in $list; do
2428 if [ -z "$FLAT_A1_EI" ]; then
2429 echo "Not supported for non-flat EI api"
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
2438 echo " Deleted job: "$job
2446 ##########################################
2447 #### Reset jobs and producers ####
2448 ##########################################
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
2454 # (Function for test scripts)
2456 ics_kube_pvc_reset() {
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
2463 echo " Trying to reset pvc: "$pvc_name
2465 __kube_clean_pvc $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $ICS_CONTAINER_MNT_DIR
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"
2480 export AUTHSIDECAR_APP_NAME
2481 export AUTHSIDECAR_DISPLAY_NAME