3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020-2023 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 pre-started 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 resources 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-prefix>
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 kubernetes 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 pre-started apps.
99 __ICS_statistics_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 test script
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>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
509 # (Function for test scripts)
510 ics_api_a1_get_job_ids() {
513 # Valid number of parameters 4,5,6 etc
514 if [ $# -lt 3 ]; then
515 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
519 if [ $3 != "NOWNER" ]; then
523 if [ $2 != "NOTYPE" ]; then
524 if [ -z "$search" ]; then
525 search="?eiTypeId="$2
527 search=$search"&eiTypeId="$2
530 query="/A1-EI/v1/eijobs$search"
531 res="$(__do_curl_to_api ICS GET $query)"
532 status=${res:${#res}-3}
534 if [ $status -ne $1 ]; then
535 __log_test_fail_status_code $1 $status
539 if [ $# -gt 3 ]; then
540 body=${res:0:${#res}-3}
543 for pid in ${@:4} ; do
544 if [ "$targetJson" != "[" ]; then
545 targetJson=$targetJson","
547 if [ $pid != "EMPTY" ]; then
548 targetJson=$targetJson"\"$pid\""
552 targetJson=$targetJson"]"
553 echo " TARGET JSON: $targetJson" >> $HTTPLOG
554 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
556 if [ $res -ne 0 ]; then
566 # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
567 # args: <response-code> <type-id> [<schema-file>]
568 # (Function for test scripts)
569 ics_api_a1_get_type() {
572 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
573 __print_err "<response-code> <type-id> [<schema-file>]" $@
577 query="/A1-EI/v1/eitypes/$2"
578 res="$(__do_curl_to_api ICS GET $query)"
579 status=${res:${#res}-3}
581 if [ $status -ne $1 ]; then
582 __log_test_fail_status_code $1 $status
586 if [ $# -eq 3 ]; then
587 body=${res:0:${#res}-3}
591 __log_test_fail_general "Schema file "$3", does not exist"
595 echo " TARGET JSON: $targetJson" >> $HTTPLOG
596 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
598 if [ $res -ne 0 ]; then
608 # API Test function: GET /A1-EI/v1/eitypes
609 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
610 # (Function for test scripts)
611 ics_api_a1_get_type_ids() {
614 if [ $# -lt 1 ]; then
615 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
619 query="/A1-EI/v1/eitypes"
620 res="$(__do_curl_to_api ICS GET $query)"
621 status=${res:${#res}-3}
623 if [ $status -ne $1 ]; then
624 __log_test_fail_status_code $1 $status
627 if [ $# -gt 1 ]; then
628 body=${res:0:${#res}-3}
630 if [ $2 != "EMPTY" ]; then
631 for pid in ${@:2} ; do
632 if [ "$targetJson" != "[" ]; then
633 targetJson=$targetJson","
635 targetJson=$targetJson"\"$pid\""
638 targetJson=$targetJson"]"
639 echo " TARGET JSON: $targetJson" >> $HTTPLOG
640 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
642 if [ $res -ne 0 ]; then
652 # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
653 # args: <response-code> <job-id> [<status> [<timeout>]]
654 # (Function for test scripts)
655 ics_api_a1_get_job_status() {
658 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
659 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
663 query="/A1-EI/v1/eijobs/$2/status"
667 res="$(__do_curl_to_api ICS GET $query)"
668 status=${res:${#res}-3}
670 if [ $# -eq 4 ]; then
671 duration=$((SECONDS-start))
672 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
673 if [ $duration -gt $4 ]; then
675 duration=-1 #Last iteration
678 duration=-1 #single test, no wait
681 if [ $status -ne $1 ]; then
682 if [ $duration -eq -1 ]; then
683 __log_test_fail_status_code $1 $status
687 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
688 body=${res:0:${#res}-3}
689 targetJson="{\"eiJobStatus\": \"$3\"}"
690 echo " TARGET JSON: $targetJson" >> $HTTPLOG
691 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
693 if [ $res -ne 0 ]; then
694 if [ $duration -eq -1 ]; then
699 duration=-1 #Goto pass
702 if [ $duration -eq -1 ]; then
703 if [ $# -eq 4 ]; then
717 # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
718 # args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
719 # (Function for test scripts)
720 ics_api_a1_get_job() {
723 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
724 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
727 query="/A1-EI/v1/eijobs/$2"
728 res="$(__do_curl_to_api ICS GET $query)"
729 status=${res:${#res}-3}
731 if [ $status -ne $1 ]; then
732 __log_test_fail_status_code $1 $status
736 if [ $# -eq 7 ]; then
737 body=${res:0:${#res}-3}
741 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
743 __log_test_fail_general "Job template file "$6", does not exist"
746 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
747 echo " TARGET JSON: $targetJson" >> $HTTPLOG
748 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
750 if [ $res -ne 0 ]; then
760 # API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
761 # args: <response-code> <job-id>
762 # (Function for test scripts)
763 ics_api_a1_delete_job() {
766 if [ $# -ne 2 ]; then
767 __print_err "<response-code> <job-id>" $@
770 query="/A1-EI/v1/eijobs/$2"
771 res="$(__do_curl_to_api ICS DELETE $query)"
772 status=${res:${#res}-3}
774 if [ $status -ne $1 ]; then
775 __log_test_fail_status_code $1 $status
783 # API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
784 # args <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
785 # (Function for test scripts)
786 ics_api_a1_put_job() {
789 if [ $# -lt 7 ]; then
790 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
795 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
797 __log_test_fail_general "Job template file "$7", does not exist"
801 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
803 echo "$inputJson" > $file
805 query="/A1-EI/v1/eijobs/$2"
807 res="$(__do_curl_to_api ICS PUT $query $file)"
808 status=${res:${#res}-3}
810 if [ $status -ne $1 ]; then
811 __log_test_fail_status_code $1 $status
820 ##########################################
821 #### information Data Producer API ####
822 ##########################################
823 # Function prefix: ics_api_edp
825 # API Test function: GET /ei-producer/v1/eitypes
826 # API Test function: GET /data-producer/v1/info-types
827 # args: <response-code> [ EMPTY | <type-id>+]
828 # (Function for test scripts)
829 ics_api_edp_get_type_ids() {
832 if [ $# -lt 1 ]; then
833 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
836 query="/data-producer/v1/info-types"
837 res="$(__do_curl_to_api ICS GET $query)"
838 status=${res:${#res}-3}
840 if [ $status -ne $1 ]; then
841 __log_test_fail_status_code $1 $status
845 if [ $# -gt 1 ]; then
846 body=${res:0:${#res}-3}
848 if [ $2 != "EMPTY" ]; then
849 for pid in ${@:2} ; do
850 if [ "$targetJson" != "[" ]; then
851 targetJson=$targetJson","
853 targetJson=$targetJson"\"$pid\""
856 targetJson=$targetJson"]"
857 echo " TARGET JSON: $targetJson" >> $HTTPLOG
858 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
860 if [ $res -ne 0 ]; then
870 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
871 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status
872 # args: <response-code> <producer-id> [<status> [<timeout>]]
873 # (Function for test scripts)
874 ics_api_edp_get_producer_status() {
877 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
878 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
881 query="/data-producer/v1/info-producers/$2/status"
884 res="$(__do_curl_to_api ICS GET $query)"
885 status=${res:${#res}-3}
887 if [ $# -eq 4 ]; then
888 duration=$((SECONDS-start))
889 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
890 if [ $duration -gt $4 ]; then
892 duration=-1 #Last iteration
895 duration=-1 #single test, no wait
898 if [ $status -ne $1 ]; then
899 if [ $duration -eq -1 ]; then
900 __log_test_fail_status_code $1 $status
904 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
905 body=${res:0:${#res}-3}
906 targetJson="{\"operational_state\": \"$3\"}"
907 echo " TARGET JSON: $targetJson" >> $HTTPLOG
908 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
910 if [ $res -ne 0 ]; then
911 if [ $duration -eq -1 ]; then
916 duration=-1 #Goto pass
919 if [ $duration -eq -1 ]; then
920 if [ $# -eq 4 ]; then
932 # API Test function: GET /ei-producer/v1/eiproducers
933 # args (v1_1): <response-code> [ EMPTY | <producer-id>+]
934 # (Function for test scripts)
935 ics_api_edp_get_producer_ids() {
938 if [ $# -lt 1 ]; then
939 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
943 query="/ei-producer/v1/eiproducers"
944 res="$(__do_curl_to_api ICS GET $query)"
945 status=${res:${#res}-3}
947 if [ $status -ne $1 ]; then
948 __log_test_fail_status_code $1 $status
952 if [ $# -gt 1 ]; then
953 body=${res:0:${#res}-3}
956 for pid in ${@:2} ; do
957 if [ "$targetJson" != "[" ]; then
958 targetJson=$targetJson","
960 if [ $pid != "EMPTY" ]; then
961 targetJson=$targetJson"\"$pid\""
965 targetJson=$targetJson"]"
966 echo " TARGET JSON: $targetJson" >> $HTTPLOG
967 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
969 if [ $res -ne 0 ]; then
979 # API Test function: GET /ei-producer/v1/eiproducers
980 # API Test function: GET /data-producer/v1/info-producers
981 # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
982 # (Function for test scripts)
983 ics_api_edp_get_producer_ids_2() {
986 if [ $# -lt 1 ]; then
987 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
990 query="/data-producer/v1/info-producers"
991 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
992 query=$query"?info_type_id=$2&infoTypeId=$2" #info_type_id changed to infoTypeId in F-release.
993 #Remove info_type_id when F-release is no longer supported
995 res="$(__do_curl_to_api ICS GET $query)"
996 status=${res:${#res}-3}
998 if [ $status -ne $1 ]; then
999 __log_test_fail_status_code $1 $status
1003 if [ $# -gt 2 ]; then
1004 body=${res:0:${#res}-3}
1007 for pid in ${@:3} ; do
1008 if [ "$targetJson" != "[" ]; then
1009 targetJson=$targetJson","
1011 if [ $pid != "EMPTY" ]; then
1012 targetJson=$targetJson"\"$pid\""
1016 targetJson=$targetJson"]"
1017 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1018 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1020 if [ $res -ne 0 ]; then
1021 __log_test_fail_body
1030 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1031 # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
1032 # (Function for test scripts)
1033 ics_api_edp_get_type() {
1037 if [ $# -eq 2 ]; then
1040 if [ $# -gt 3 ]; then
1043 if [ $paramError -ne 0 ]; then
1044 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
1048 query="/ei-producer/v1/eitypes/$2"
1049 res="$(__do_curl_to_api ICS GET $query)"
1050 status=${res:${#res}-3}
1052 if [ $status -ne $1 ]; then
1053 __log_test_fail_status_code $1 $status
1056 if [ $# -gt 3 ]; then
1057 body=${res:0:${#res}-3}
1062 __log_test_fail_general "Job template file "$3", does not exist"
1067 if [ $4 != "EMPTY" ]; then
1068 for pid in ${@:4} ; do
1069 if [ "$targetJson" != "" ]; then
1070 targetJson=$targetJson","
1072 targetJson=$targetJson"\"$pid\""
1075 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1077 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1078 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1080 if [ $res -ne 0 ]; then
1081 __log_test_fail_body
1089 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1090 # API Test function: GET /data-producer/v1/info-types/{infoTypeId}
1091 # args: (v1_2) <response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]
1092 # (Function for test scripts)
1093 ics_api_edp_get_type_2() {
1097 if [ $# -eq 2 ]; then
1100 if [ $# -eq 3 ]; then
1103 if [ $# -eq 4 ]; then
1106 if [ $paramError -ne 0 ]; then
1107 __print_err "<response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]" $@
1110 query="/data-producer/v1/info-types/$2"
1112 res="$(__do_curl_to_api ICS GET $query)"
1113 status=${res:${#res}-3}
1115 if [ $status -ne $1 ]; then
1116 __log_test_fail_status_code $1 $status
1119 if [ $# -ge 3 ]; then
1120 body=${res:0:${#res}-3}
1125 __log_test_fail_general "Job template file "$3", does not exist"
1129 if [ $# -gt 3 ]; then
1133 __log_test_fail_general "Info-data file "$4", does not exist"
1136 info_data=",\"info_type_information\":$info_data"
1138 targetJson="{\"info_job_data_schema\":$schema $info_data}"
1140 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1141 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1143 if [ $res -ne 0 ]; then
1144 __log_test_fail_body
1152 # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1153 # API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
1154 # args: (v1_2) <response-code> <type-id> <job-schema-file> [ <info-type-info> ]
1155 # (Function for test scripts)
1156 ics_api_edp_put_type_2() {
1159 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1160 __print_err "<response-code> <type-id> <job-schema-file> [ <info-type-info> ]" $@
1164 if [ ! -f $3 ]; then
1165 __log_test_fail_general "Job schema file "$3", does not exist"
1170 if [ $# -gt 3 ]; then
1174 __log_test_fail_general "Info-data file "$4", does not exist"
1177 info_data=",\"info_type_information\":$info_data"
1181 input_json="{\"info_job_data_schema\":$schema $info_data}"
1182 file="./tmp/put_type.json"
1183 echo $input_json > $file
1185 query="/data-producer/v1/info-types/$2"
1186 res="$(__do_curl_to_api ICS PUT $query $file)"
1187 status=${res:${#res}-3}
1189 if [ $status -ne $1 ]; then
1190 __log_test_fail_status_code $1 $status
1198 # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1199 # API Test function: DELETE /data-producer/v1/info-types/{infoTypeId}
1200 # args: (v1_2) <response-code> <type-id>
1201 # (Function for test scripts)
1202 ics_api_edp_delete_type_2() {
1205 if [ $# -ne 2 ]; then
1206 __print_err "<response-code> <type-id>" $@
1210 query="/data-producer/v1/info-types/$2"
1211 res="$(__do_curl_to_api ICS DELETE $query)"
1212 status=${res:${#res}-3}
1214 if [ $status -ne $1 ]; then
1215 __log_test_fail_status_code $1 $status
1223 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1224 # args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
1225 # (Function for test scripts)
1226 ics_api_edp_get_producer() {
1229 #Possible arg count: 2, 5 6, 8, 10 etc
1231 if [ $# -eq 2 ]; then
1234 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1237 variablecount=$(($#-4))
1238 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1242 if [ $paramError -ne 0 ]; then
1243 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
1247 query="/ei-producer/v1/eiproducers/$2"
1248 res="$(__do_curl_to_api ICS GET $query)"
1249 status=${res:${#res}-3}
1251 if [ $status -ne $1 ]; then
1252 __log_test_fail_status_code $1 $status
1256 if [ $# -gt 2 ]; then
1257 body=${res:0:${#res}-3}
1259 if [ $# -gt 5 ]; then
1261 for ((i=0; i<$(($#-5)); i=i+2)); do
1262 if [ "$targetJson" != "[" ]; then
1263 targetJson=$targetJson","
1265 if [ -f ${arr[$i+1]} ]; then
1266 schema=$(cat ${arr[$i+1]})
1268 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1272 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1275 targetJson=$targetJson"]"
1276 if [ $# -gt 4 ]; then
1277 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1279 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1280 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1282 if [ $res -ne 0 ]; then
1283 __log_test_fail_body
1292 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1293 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}
1294 # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1295 # (Function for test scripts)
1296 ics_api_edp_get_producer_2() {
1299 #Possible arg count: 2, 5, 6, 7, 8 etc
1301 if [ $# -eq 2 ]; then
1304 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1307 if [ $# -ge 5 ]; then
1311 if [ $paramError -ne 0 ]; then
1312 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1315 query="/data-producer/v1/info-producers/$2"
1316 res="$(__do_curl_to_api ICS GET $query)"
1317 status=${res:${#res}-3}
1319 if [ $status -ne $1 ]; then
1320 __log_test_fail_status_code $1 $status
1324 if [ $# -gt 2 ]; then
1325 body=${res:0:${#res}-3}
1327 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1329 for ((i=0; i<$(($#-4)); i=i+1)); do
1330 if [ "$targetJson" != "[" ]; then
1331 targetJson=$targetJson","
1333 targetJson=$targetJson"\"${arr[$i]}\""
1336 targetJson=$targetJson"]"
1337 if [ $# -gt 4 ]; then
1338 targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}"
1340 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1341 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1343 if [ $res -ne 0 ]; then
1344 __log_test_fail_body
1353 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
1354 # API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId}
1355 # args: <response-code> <producer-id>
1356 # (Function for test scripts)
1357 ics_api_edp_delete_producer() {
1360 if [ $# -lt 2 ]; then
1361 __print_err "<response-code> <producer-id>" $@
1364 query="/data-producer/v1/info-producers/$2"
1365 res="$(__do_curl_to_api ICS DELETE $query)"
1366 status=${res:${#res}-3}
1368 if [ $status -ne $1 ]; then
1369 __log_test_fail_status_code $1 $status
1377 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1378 # args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
1379 # (Function for test scripts)
1380 ics_api_edp_put_producer() {
1383 #Valid number of parametrer 5,6,8,10,
1385 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1387 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
1390 if [ $paramError -ne 0 ]; then
1391 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
1396 if [ $# -gt 5 ]; then
1398 for ((i=0; i<$(($#-5)); i=i+2)); do
1399 if [ "$inputJson" != "[" ]; then
1400 inputJson=$inputJson","
1402 if [ -f ${arr[$i+1]} ]; then
1403 schema=$(cat ${arr[$i+1]})
1405 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1408 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1411 inputJson="\"supported_ei_types\":"$inputJson"]"
1413 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1415 inputJson="{"$inputJson"}"
1417 file="./tmp/.p.json"
1418 echo "$inputJson" > $file
1419 query="/ei-producer/v1/eiproducers/$2"
1420 res="$(__do_curl_to_api ICS PUT $query $file)"
1421 status=${res:${#res}-3}
1423 if [ $status -ne $1 ]; then
1424 __log_test_fail_status_code $1 $status
1432 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1433 # API Test function: PUT /data-producer/v1/info-producers/{infoProducerId}
1434 # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1435 # (Function for test scripts)
1436 ics_api_edp_put_producer_2() {
1439 #Valid number of parametrer 5,6,8,10,
1441 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1443 elif [ $# -ge 5 ]; then
1446 if [ $paramError -ne 0 ]; then
1447 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1452 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1454 for ((i=0; i<$(($#-4)); i=i+1)); do
1455 if [ "$inputJson" != "[" ]; then
1456 inputJson=$inputJson","
1458 inputJson=$inputJson"\""${arr[$i]}"\""
1461 inputJson="\"supported_info_types\":"$inputJson"]"
1463 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
1465 inputJson="{"$inputJson"}"
1467 file="./tmp/.p.json"
1468 echo "$inputJson" > $file
1469 query="/data-producer/v1/info-producers/$2"
1470 res="$(__do_curl_to_api ICS PUT $query $file)"
1471 status=${res:${#res}-3}
1473 if [ $status -ne $1 ]; then
1474 __log_test_fail_status_code $1 $status
1482 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1483 # args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1484 # (Function for test scripts)
1485 ics_api_edp_get_producer_jobs() {
1488 #Valid number of parameter 2,3,7,11
1490 if [ $# -eq 2 ]; then
1493 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1496 variablecount=$(($#-2))
1497 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1500 if [ $paramError -eq 1 ]; then
1501 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1505 query="/ei-producer/v1/eiproducers/$2/eijobs"
1506 res="$(__do_curl_to_api ICS GET $query)"
1507 status=${res:${#res}-3}
1508 if [ $status -ne $1 ]; then
1509 __log_test_fail_status_code $1 $status
1512 if [ $# -gt 2 ]; then
1513 body=${res:0:${#res}-3}
1515 if [ $# -gt 3 ]; then
1517 for ((i=0; i<$(($#-3)); i=i+5)); do
1518 if [ "$targetJson" != "[" ]; then
1519 targetJson=$targetJson","
1521 if [ -f ${arr[$i+4]} ]; then
1522 jobfile=$(cat ${arr[$i+4]})
1523 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1525 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1528 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}"
1531 targetJson=$targetJson"]"
1533 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1534 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1536 if [ $res -ne 0 ]; then
1537 __log_test_fail_body
1546 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1547 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs
1548 # args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1549 # (Function for test scripts)
1550 ics_api_edp_get_producer_jobs_2() {
1553 #Valid number of parameter 2,3,7,11
1555 if [ $# -eq 2 ]; then
1558 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1561 variablecount=$(($#-2))
1562 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1565 if [ $paramError -eq 1 ]; then
1566 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1569 query="/data-producer/v1/info-producers/$2/info-jobs"
1570 res="$(__do_curl_to_api ICS GET $query)"
1571 status=${res:${#res}-3}
1572 if [ $status -ne $1 ]; then
1573 __log_test_fail_status_code $1 $status
1576 if [ $# -gt 2 ]; then
1577 body=${res:0:${#res}-3}
1579 if [ $# -gt 3 ]; then
1581 for ((i=0; i<$(($#-3)); i=i+5)); do
1582 if [ "$targetJson" != "[" ]; then
1583 targetJson=$targetJson","
1585 if [ -f ${arr[$i+4]} ]; then
1586 jobfile=$(cat ${arr[$i+4]})
1587 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1589 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1592 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\":\"????\"}"
1596 targetJson=$targetJson"]"
1598 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1599 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1601 if [ $res -ne 0 ]; then
1602 __log_test_fail_body
1611 ##########################################
1612 #### Service status ####
1613 ##########################################
1614 # Function prefix: ics_api_service
1616 # API Test function: GET ​/status
1617 # args: <response-code>
1618 # (Function for test scripts)
1619 ics_api_service_status() {
1622 if [ $# -lt 1 ]; then
1623 __print_err "<response-code>" $@
1626 res="$(__do_curl_to_api ICS GET /status)"
1627 status=${res:${#res}-3}
1628 if [ $status -ne $1 ]; then
1629 __log_test_fail_status_code $1 $status
1636 ###########################################
1637 ######### Info data consumer API ##########
1638 ###########################################
1639 #Function prefix: ics_api_idc
1642 # API Test function: GET /data-consumer/v1/info-types
1643 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
1644 # (Function for test scripts)
1645 ics_api_idc_get_type_ids() {
1648 if [ $# -lt 1 ]; then
1649 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1653 query="/data-consumer/v1/info-types"
1654 res="$(__do_curl_to_api ICS GET $query)"
1655 status=${res:${#res}-3}
1657 if [ $status -ne $1 ]; then
1658 __log_test_fail_status_code $1 $status
1661 if [ $# -gt 1 ]; then
1662 body=${res:0:${#res}-3}
1664 if [ $2 != "EMPTY" ]; then
1665 for pid in ${@:2} ; do
1666 if [ "$targetJson" != "[" ]; then
1667 targetJson=$targetJson","
1669 targetJson=$targetJson"\"$pid\""
1672 targetJson=$targetJson"]"
1673 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1674 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1676 if [ $res -ne 0 ]; then
1677 __log_test_fail_body
1686 # API Test function: GET /data-consumer/v1/info-jobs
1687 # args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
1688 # (Function for test scripts)
1689 ics_api_idc_get_job_ids() {
1692 # Valid number of parameters 4,5,6 etc
1693 if [ $# -lt 3 ]; then
1694 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
1698 if [ $3 != "NOWNER" ]; then
1702 if [ $2 != "NOTYPE" ]; then
1703 if [ -z "$search" ]; then
1704 search="?infoTypeId="$2
1706 search=$search"&infoTypeId="$2
1709 query="/data-consumer/v1/info-jobs$search"
1711 res="$(__do_curl_to_api ICS GET $query)"
1712 status=${res:${#res}-3}
1714 if [ $status -ne $1 ]; then
1715 __log_test_fail_status_code $1 $status
1719 if [ $# -gt 3 ]; then
1720 body=${res:0:${#res}-3}
1723 for pid in ${@:4} ; do
1724 if [ "$targetJson" != "[" ]; then
1725 targetJson=$targetJson","
1727 if [ $pid != "EMPTY" ]; then
1728 targetJson=$targetJson"\"$pid\""
1732 targetJson=$targetJson"]"
1733 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1734 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1736 if [ $res -ne 0 ]; then
1737 __log_test_fail_body
1746 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
1747 # args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
1748 # (Function for test scripts)
1749 ics_api_idc_get_job() {
1752 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
1753 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
1756 query="/data-consumer/v1/info-jobs/$2"
1757 res="$(__do_curl_to_api ICS GET $query)"
1758 status=${res:${#res}-3}
1760 if [ $status -ne $1 ]; then
1761 __log_test_fail_status_code $1 $status
1765 if [ $# -eq 7 ]; then
1766 body=${res:0:${#res}-3}
1770 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1772 __log_test_fail_general "Job template file "$6", does not exist"
1775 targetJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
1776 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1777 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1779 if [ $res -ne 0 ]; then
1780 __log_test_fail_body
1790 # API Test function: PUT ​/data-consumer/v1/info-jobs/{infoJobId}
1791 # args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
1792 # (Function for test scripts)
1793 ics_api_idc_put_job() {
1796 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1797 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
1802 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1804 __log_test_fail_general "Job template file "$7", does not exist"
1808 inputJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
1809 file="./tmp/.p.json"
1810 echo "$inputJson" > $file
1812 query="/data-consumer/v1/info-jobs/$2"
1814 if [ $# -eq 8 ]; then
1815 if [ $8 == "VALIDATE" ]; then
1816 query=$query"?typeCheck=true"
1820 res="$(__do_curl_to_api ICS PUT $query $file)"
1821 status=${res:${#res}-3}
1823 if [ $status -ne $1 ]; then
1824 __log_test_fail_status_code $1 $status
1832 # API Test function: DELETE ​/data-consumer/v1/info-jobs/{infoJobId}
1833 # args: <response-code> <job-id>
1834 # (Function for test scripts)
1835 ics_api_idc_delete_job() {
1838 if [ $# -ne 2 ]; then
1839 __print_err "<response-code> <job-id>" $@
1842 query="/data-consumer/v1/info-jobs/$2"
1843 res="$(__do_curl_to_api ICS DELETE $query)"
1844 status=${res:${#res}-3}
1846 if [ $status -ne $1 ]; then
1847 __log_test_fail_status_code $1 $status
1855 # API Test function: GET ​/data-consumer/v1/info-types/{infoTypeId}
1856 # args: <response-code> <type-id> [<schema-file> [<type-status> <producers-count]]
1857 # (Function for test scripts)
1858 ics_api_idc_get_type() {
1861 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
1862 __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@
1866 query="/data-consumer/v1/info-types/$2"
1867 res="$(__do_curl_to_api ICS GET $query)"
1868 status=${res:${#res}-3}
1870 if [ $status -ne $1 ]; then
1871 __log_test_fail_status_code $1 $status
1875 if [ $# -gt 2 ]; then
1876 body=${res:0:${#res}-3}
1880 __log_test_fail_general "Schema file "$3", does not exist"
1883 if [ $# -eq 5 ]; then
1884 targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}"
1886 targetJson="{\"job_data_schema\":$schema}"
1888 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1889 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1891 if [ $res -ne 0 ]; then
1892 __log_test_fail_body
1901 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
1902 # This test only status during an optional timeout. No test of the list of producers
1903 # args: <response-code> <job-id> [<status> [<timeout>]]
1904 # (Function for test scripts)
1905 ics_api_idc_get_job_status() {
1908 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
1909 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
1913 query="/data-consumer/v1/info-jobs/$2/status"
1917 res="$(__do_curl_to_api ICS GET $query)"
1918 status=${res:${#res}-3}
1920 if [ $# -eq 4 ]; then
1921 duration=$((SECONDS-start))
1922 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
1923 if [ $duration -gt $4 ]; then
1925 duration=-1 #Last iteration
1928 duration=-1 #single test, no wait
1931 if [ $status -ne $1 ]; then
1932 if [ $duration -eq -1 ]; then
1933 __log_test_fail_status_code $1 $status
1937 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1938 body=${res:0:${#res}-3}
1939 targetJson="{\"info_job_status\": \"$3\"}"
1940 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1941 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1943 if [ $res -ne 0 ]; then
1944 if [ $duration -eq -1 ]; then
1945 __log_test_fail_body
1949 duration=-1 #Goto pass
1952 if [ $duration -eq -1 ]; then
1953 if [ $# -eq 4 ]; then
1967 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
1968 # This function test status and the list of producers with and optional timeout
1969 # args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
1970 # (Function for test scripts)
1971 ics_api_idc_get_job_status2() {
1975 if [ $# -lt 2 ]; then
1980 if [ $# -gt 2 ]; then
1981 if [ $# -lt 4 ]; then
1984 targetJson="{\"info_job_status\": \"$3\""
1985 if [ "$4" == "EMPTYPROD" ]; then
1986 targetJson=$targetJson",\"producers\": []}"
1987 if [ $# -gt 4 ]; then
1991 targetJson=$targetJson",\"producers\": ["
1992 if [ $# -eq $(($4+5)) ]; then
1994 timeout=${args[$idx]}
1996 for ((ics_i = 0 ; ics_i < $4 ; ics_i++)); do
1998 if [ $ics_i -gt 0 ]; then
1999 targetJson=$targetJson","
2001 targetJson=$targetJson"\""${args[$idx]}"\""
2003 targetJson=$targetJson"]}"
2007 if [ $param_error -ne 0 ]; then
2008 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2012 query="/data-consumer/v1/info-jobs/$2/status"
2016 res="$(__do_curl_to_api ICS GET $query)"
2017 status=${res:${#res}-3}
2019 if [ $# -gt 2 ]; then
2020 duration=$((SECONDS-start))
2021 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2022 if [ $duration -gt $timeout ]; then
2024 duration=-1 #Last iteration
2027 duration=-1 #single test, no wait
2030 if [ $status -ne $1 ]; then
2031 if [ $duration -eq -1 ]; then
2032 __log_test_fail_status_code $1 $status
2036 if [ $# -gt 2 ] && [ $status -eq $1 ]; then
2037 body=${res:0:${#res}-3}
2038 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2039 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2041 if [ $res -ne 0 ]; then
2042 if [ $duration -eq -1 ]; then
2043 __log_test_fail_body
2047 duration=-1 #Goto pass
2050 if [ $duration -eq -1 ]; then
2051 if [ $# -eq 4 ]; then
2065 ##########################################
2066 #### Type subscriptions ####
2067 ##########################################
2069 # API Test function: GET /data-consumer/v1/info-type-subscription
2070 # args: <response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]
2071 # (Function for test scripts)
2072 ics_api_idc_get_subscription_ids() {
2075 if [ $# -lt 3 ]; then
2076 __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@
2080 query="/data-consumer/v1/info-type-subscription"
2082 if [ $2 != "NOOWNER" ]; then
2086 res="$(__do_curl_to_api ICS GET $query$search)"
2087 status=${res:${#res}-3}
2089 if [ $status -ne $1 ]; then
2090 __log_test_fail_status_code $1 $status
2094 if [ $# -gt 2 ]; then
2095 body=${res:0:${#res}-3}
2097 if [ $3 != "EMPTY" ]; then
2098 for pid in ${@:3} ; do
2099 if [ "$targetJson" != "[" ]; then
2100 targetJson=$targetJson","
2102 targetJson=$targetJson"\"$pid\""
2105 targetJson=$targetJson"]"
2106 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2107 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2109 if [ $res -ne 0 ]; then
2110 __log_test_fail_body
2119 # API Test function: GET /data-consumer/v1/info-type-subscription/{subscriptionId}
2120 # args: <response-code> <subscription-id> [ <owner-id> <status-uri> ]
2121 # (Function for test scripts)
2122 ics_api_idc_get_subscription() {
2125 if [ $# -ne 2 ] && [ $# -ne 4 ]; then
2126 __print_err "<response-code> <subscription-id> [ <owner-id> <status-uri> ]" $@
2130 query="/data-consumer/v1/info-type-subscription/$2"
2131 res="$(__do_curl_to_api ICS GET $query)"
2132 status=${res:${#res}-3}
2134 if [ $status -ne $1 ]; then
2135 __log_test_fail_status_code $1 $status
2139 if [ $# -gt 2 ]; then
2140 body=${res:0:${#res}-3}
2141 targetJson="{\"owner\":\"$3\",\"status_result_uri\":\"$4\"}"
2142 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2143 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2145 if [ $res -ne 0 ]; then
2146 __log_test_fail_body
2155 # API Test function: PUT /data-consumer/v1/info-type-subscription/{subscriptionId}
2156 # args: <response-code> <subscription-id> <owner-id> <status-uri>
2157 # (Function for test scripts)
2158 ics_api_idc_put_subscription() {
2161 if [ $# -ne 4 ]; then
2162 __print_err "<response-code> <subscription-id> <owner-id> <status-uri>" $@
2166 inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}"
2167 file="./tmp/.p.json"
2168 echo "$inputJson" > $file
2170 query="/data-consumer/v1/info-type-subscription/$2"
2171 res="$(__do_curl_to_api ICS PUT $query $file)"
2172 status=${res:${#res}-3}
2174 if [ $status -ne $1 ]; then
2175 __log_test_fail_status_code $1 $status
2183 # API Test function: DELETE /data-consumer/v1/info-type-subscription/{subscriptionId}
2184 # args: <response-code> <subscription-id>
2185 # (Function for test scripts)
2186 ics_api_idc_delete_subscription() {
2189 if [ $# -ne 2 ]; then
2190 __print_err "<response-code> <subscription-id> " $@
2194 query="/data-consumer/v1/info-type-subscription/$2"
2195 res="$(__do_curl_to_api ICS DELETE $query)"
2196 status=${res:${#res}-3}
2198 if [ $status -ne $1 ]; then
2199 __log_test_fail_status_code $1 $status
2207 ##########################################
2208 #### Reset jobs ####
2209 ##########################################
2210 # Function prefix: ics_api_admin
2212 # Admin to remove all jobs
2213 # args: <response-code> [ <type> ]
2214 # (Function for test scripts)
2216 ics_api_admin_reset() {
2219 query="/A1-EI/v1/eijobs"
2220 res="$(__do_curl_to_api ICS GET $query)"
2221 status=${res:${#res}-3}
2223 if [ $status -ne 200 ]; then
2224 __log_test_fail_status_code $1 $status
2228 #Remove brackets and response code
2229 body=${res:1:${#res}-4}
2230 list=$(echo ${body//,/ })
2231 list=$(echo ${list//[/})
2232 list=$(echo ${list//]/})
2233 list=$(echo ${list//\"/})
2235 for job in $list; do
2236 query="/A1-EI/v1/eijobs/$job"
2237 res="$(__do_curl_to_api ICS DELETE $query)"
2238 status=${res:${#res}-3}
2239 if [ $status -ne 204 ]; then
2240 __log_test_fail_status_code $1 $status
2243 echo " Deleted job: "$job
2250 ##########################################
2251 #### Reset jobs and producers ####
2252 ##########################################
2255 # Admin reset to remove all data in ics; jobs, producers etc
2256 # NOTE - only works in kubernetes and the pod should not be running
2258 # (Function for test scripts)
2260 ics_kube_pvc_reset() {
2263 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep information)
2264 if [ -z "$pvc_name" ]; then
2265 pvc_name=informationservice-pvc
2267 echo " Trying to reset pvc: "$pvc_name
2269 __kube_clean_pvc $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $ICS_CONTAINER_MNT_DIR
2275 # args: <realm> <client-name> <client-secret>
2276 ics_configure_sec() {
2277 export ICS_CREDS_GRANT_TYPE="client_credentials"
2278 export ICS_CREDS_CLIENT_SECRET=$3
2279 export ICS_CREDS_CLIENT_ID=$2
2280 export ICS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
2281 export ICS_SIDECAR_MOUNT="/token-cache"
2282 export ICS_SIDECAR_JWT_FILE=$ICS_SIDECAR_MOUNT"/jwt.txt"
2284 export AUTHSIDECAR_APP_NAME
2285 export AUTHSIDECAR_DISPLAY_NAME