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 ECS
23 # Host name may be changed if app started by kube
26 ECS_HOST_NAME=$LOCALHOST_NAME
27 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
29 # ECS_ADAPTER used for switch between REST and DMAAP (only REST supported currently)
30 ECS_ADAPTER_TYPE="REST"
33 # Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
36 ###########################
38 ###########################
40 # All calls to ECS will be directed to the ECS REST interface from now on
42 # (Function for test scripts)
44 echo -e $BOLD"ECS protocol setting"$EBOLD
45 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
47 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
49 ECS_ADAPTER_TYPE="REST"
54 # All calls to ECS will be directed to the ECS REST interface from now on
56 # (Function for test scripts)
57 use_ecs_rest_https() {
58 echo -e $BOLD"ECS protocol setting"$EBOLD
59 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
61 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
63 ECS_ADAPTER_TYPE="REST"
68 # All calls to ECS will be directed to the ECS dmaap interface over http from now on
70 # (Function for test scripts)
71 use_ecs_dmaap_http() {
72 echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
73 echo -e $RED" - NOT SUPPORTED - "$ERED
74 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
75 ECS_ADAPTER_TYPE="MR-HTTP"
79 # All calls to ECS will be directed to the ECS dmaap interface over https from now on
81 # (Function for test scripts)
82 use_ecs_dmaap_https() {
83 echo -e $BOLD"RICSIM protocol setting"$EBOLD
84 echo -e $RED" - NOT SUPPORTED - "$ERED
85 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
86 ECS_ADAPTER_TYPE="MR-HTTPS"
92 # (Function for test scripts)
95 echo -e $BOLD"Starting $ECS_DISPLAY_NAME"$EBOLD
97 if [ $RUNMODE == "KUBE" ]; then
99 # Check if app shall be fully managed by the test script
100 __check_included_image "ECS"
103 # Check if app shall only be used by the testscipt
104 __check_prestarted_image "ECS"
107 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
108 echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
109 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
112 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
113 echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
114 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
119 if [ $retcode_p -eq 0 ]; then
120 echo -e " Using existing $ECS_APP_NAME deployment and service"
121 echo " Setting ECS replicas=1"
122 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
125 # Check if app shall be fully managed by the test script
126 if [ $retcode_i -eq 0 ]; then
127 echo -e " Creating $ECS_APP_NAME app and expose service"
129 #Check if nonrtric namespace exists, if not create it
130 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
133 export KUBE_NONRTRIC_NAMESPACE
135 export ECS_INTERNAL_PORT
136 export ECS_INTERNAL_SECURE_PORT
137 export ECS_EXTERNAL_PORT
138 export ECS_EXTERNAL_SECURE_PORT
139 export ECS_CONFIG_MOUNT_PATH
140 export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config"
141 export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data"
142 export ECS_CONTAINER_MNT_DIR
144 # Create config map for config
145 datafile=$PWD/tmp/$ECS_CONFIG_FILE
147 output_yaml=$PWD/tmp/ecs_cfc.yaml
148 __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml
151 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml
152 output_yaml=$PWD/tmp/ecs_pvc.yaml
153 __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml
156 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml
157 output_yaml=$PWD/tmp/ecs_svc.yaml
158 __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml
161 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml
162 output_yaml=$PWD/tmp/ecs_app.yaml
163 __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml
166 echo " Retrieving host and ports for service..."
167 ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
168 ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
169 ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
171 echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT"
173 if [ $ECS_HTTPX == "http" ]; then
174 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
176 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
179 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
181 if [ $ECS_ADAPTER_TYPE == "REST" ]; then
182 ECS_ADAPTER=$ECS_PATH
185 __check_included_image 'ECS'
186 if [ $? -eq 1 ]; then
187 echo -e $RED"The ECS app is not included in this test script"$ERED
188 echo -e $RED"ECS will not be started"$ERED
198 if [ "$(ls -A $DIR)" ]; then
199 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
200 rm -rf db/* &> /dev/null
201 if [ $? -ne 0 ]; then
202 echo -e $RED" Cannot remove database files in: $PWD"$ERED
207 echo " No files in mounted dir or dir does not exists"
212 export ECS_APP_NAME_ALIAS
213 export ECS_HOST_MNT_DIR
214 export ECS_CONTAINER_MNT_DIR
215 export ECS_INTERNAL_PORT
216 export ECS_EXTERNAL_PORT
217 export ECS_INTERNAL_SECURE_PORT
218 export ECS_EXTERNAL_SECURE_PORT
219 export DOCKER_SIM_NWNAME
221 __start_container $ECS_COMPOSE_DIR NODOCKERARGS 1 $ECS_APP_NAME
223 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
231 # (Function for test scripts)
233 echo -e $BOLD"Re-starting ECS"$EBOLD
234 docker restart $ECS_APP_NAME &> ./tmp/.dockererr
235 if [ $? -ne 0 ]; then
236 __print_err "Could not restart $ECS_APP_NAME" $@
242 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
247 # Turn on debug level tracing in ECS
249 # (Function for test scripts)
251 echo -e $BOLD"Setting ecs debug logging"$EBOLD
252 curlString="$ECS_PATH$ECS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
253 result=$(__do_curl "$curlString")
254 if [ $? -ne 0 ]; then
255 __print_err "Could not set debug mode" $@
263 # Turn on trace level tracing in ECS
265 # (Function for test scripts)
267 echo -e $BOLD"Setting ecs trace logging"$EBOLD
268 curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
269 result=$(__do_curl "$curlString")
270 if [ $? -ne 0 ]; then
271 __print_err "Could not set trace mode" $@
279 # Perform curl retries when making direct call to ECS for the specified http response codes
280 # Speace separated list of http response codes
281 # args: [<response-code>]*
282 use_agent_retries() {
283 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
284 ECS_AGENT_RETRY_CODES=$@
290 # Tests if a variable value in the ECS is equal to a target value and and optional timeout.
291 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
292 # equal to the target or not.
293 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
294 # before setting pass or fail depending on if the variable value becomes equal to the target
296 # (Function for test scripts)
298 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
299 __var_test ECS "$ECS_PATH/" $1 "=" $2 $3
301 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
306 ##########################################
307 ######### A1-E Enrichment API ##########
308 ##########################################
309 #Function prefix: ecs_api_a1
311 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs
312 # args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
313 # args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
314 # (Function for test scripts)
315 ecs_api_a1_get_job_ids() {
318 if [ -z "$FLAT_A1_EI" ]; then
319 # Valid number of parameters 4,5,6 etc
320 if [ $# -lt 3 ]; then
321 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
325 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
326 # Valid number of parameters 4,5,6 etc
327 if [ $# -lt 3 ]; then
328 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
333 if [ $3 != "NOWNER" ]; then
337 if [ -z "$FLAT_A1_EI" ]; then
338 query="/A1-EI/v1/eitypes/$2/eijobs$search"
340 if [ $2 != "NOTYPE" ]; then
341 if [ -z "$search" ]; then
342 search="?eiTypeId="$2
344 search=$search"&eiTypeId="$2
347 query="/A1-EI/v1/eijobs$search"
349 res="$(__do_curl_to_api ECS GET $query)"
350 status=${res:${#res}-3}
352 if [ $status -ne $1 ]; then
353 __log_test_fail_status_code $1 $status
357 if [ $# -gt 3 ]; then
358 body=${res:0:${#res}-3}
361 for pid in ${@:4} ; do
362 if [ "$targetJson" != "[" ]; then
363 targetJson=$targetJson","
365 if [ $pid != "EMPTY" ]; then
366 targetJson=$targetJson"\"$pid\""
370 targetJson=$targetJson"]"
371 echo " TARGET JSON: $targetJson" >> $HTTPLOG
372 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
374 if [ $res -ne 0 ]; then
384 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}
385 # args: <response-code> <type-id> [<schema-file>]
386 # (Function for test scripts)
387 ecs_api_a1_get_type() {
390 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
391 __print_err "<response-code> <type-id> [<schema-file>]" $@
395 query="/A1-EI/v1/eitypes/$2"
396 res="$(__do_curl_to_api ECS GET $query)"
397 status=${res:${#res}-3}
399 if [ $status -ne $1 ]; then
400 __log_test_fail_status_code $1 $status
404 if [ $# -eq 3 ]; then
405 body=${res:0:${#res}-3}
409 __log_test_fail_general "Schema file "$3", does not exist"
412 if [ -z "$FLAT_A1_EI" ]; then
413 targetJson="{\"eiJobParametersSchema\":$schema}"
417 echo " TARGET JSON: $targetJson" >> $HTTPLOG
418 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
420 if [ $res -ne 0 ]; then
430 # API Test function: GET /A1-EI/v1/eitypes
431 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
432 # (Function for test scripts)
433 ecs_api_a1_get_type_ids() {
436 if [ $# -lt 1 ]; then
437 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
441 query="/A1-EI/v1/eitypes"
442 res="$(__do_curl_to_api ECS GET $query)"
443 status=${res:${#res}-3}
445 if [ $status -ne $1 ]; then
446 __log_test_fail_status_code $1 $status
449 if [ $# -gt 1 ]; then
450 body=${res:0:${#res}-3}
452 if [ $2 != "EMPTY" ]; then
453 for pid in ${@:2} ; do
454 if [ "$targetJson" != "[" ]; then
455 targetJson=$targetJson","
457 targetJson=$targetJson"\"$pid\""
460 targetJson=$targetJson"]"
461 echo " TARGET JSON: $targetJson" >> $HTTPLOG
462 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
464 if [ $res -ne 0 ]; then
474 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}/status
475 # args: <response-code> <type-id> <job-id> [<status>]
476 # args (flat uri structure): <response-code> <job-id> [<status>]
477 # (Function for test scripts)
478 ecs_api_a1_get_job_status() {
481 if [ -z "$FLAT_A1_EI" ]; then
482 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
483 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
487 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
489 res="$(__do_curl_to_api ECS GET $query)"
490 status=${res:${#res}-3}
492 if [ $status -ne $1 ]; then
493 __log_test_fail_status_code $1 $status
496 if [ $# -eq 4 ]; then
497 body=${res:0:${#res}-3}
498 targetJson="{\"operationalState\": \"$4\"}"
499 echo " TARGET JSON: $targetJson" >> $HTTPLOG
500 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
502 if [ $res -ne 0 ]; then
508 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
509 if [ $# -ne 2 ] && [ $# -ne 3 ]; then
510 __print_err "<response-code> <job-id> [<status>]" $@
514 query="/A1-EI/v1/eijobs/$2/status"
516 res="$(__do_curl_to_api ECS GET $query)"
517 status=${res:${#res}-3}
519 if [ $status -ne $1 ]; then
520 __log_test_fail_status_code $1 $status
523 if [ $# -eq 3 ]; then
524 body=${res:0:${#res}-3}
525 targetJson="{\"eiJobStatus\": \"$3\"}"
526 echo " TARGET JSON: $targetJson" >> $HTTPLOG
527 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
529 if [ $res -ne 0 ]; then
540 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
541 # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
542 # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
543 # (Function for test scripts)
544 ecs_api_a1_get_job() {
547 if [ -z "$FLAT_A1_EI" ]; then
548 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
549 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
552 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
554 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
555 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
556 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
559 query="/A1-EI/v1/eijobs/$2"
561 res="$(__do_curl_to_api ECS GET $query)"
562 status=${res:${#res}-3}
564 if [ $status -ne $1 ]; then
565 __log_test_fail_status_code $1 $status
569 if [ -z "$FLAT_A1_EI" ]; then
570 if [ $# -eq 6 ]; then
571 body=${res:0:${#res}-3}
575 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
577 _log_test_fail_general "Job template file "$6", does not exist"
580 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
581 echo " TARGET JSON: $targetJson" >> $HTTPLOG
582 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
584 if [ $res -ne 0 ]; then
590 if [ $# -eq 7 ]; then
591 body=${res:0:${#res}-3}
595 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
597 _log_test_fail_general "Job template file "$6", does not exist"
600 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
601 echo " TARGET JSON: $targetJson" >> $HTTPLOG
602 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
604 if [ $res -ne 0 ]; then
615 # API Test function: DELETE /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
616 # args: <response-code> <type-id> <job-id>
617 # args (flat uri structure): <response-code> <job-id>
618 # (Function for test scripts)
619 ecs_api_a1_delete_job() {
622 if [ -z "$FLAT_A1_EI" ]; then
623 if [ $# -ne 3 ]; then
624 __print_err "<response-code> <type-id> <job-id>" $@
628 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
630 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
631 if [ $# -ne 2 ]; then
632 __print_err "<response-code> <job-id>" $@
635 query="/A1-EI/v1/eijobs/$2"
637 res="$(__do_curl_to_api ECS DELETE $query)"
638 status=${res:${#res}-3}
640 if [ $status -ne $1 ]; then
641 __log_test_fail_status_code $1 $status
649 # API Test function: PUT /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
650 # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
651 # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
652 # (Function for test scripts)
653 ecs_api_a1_put_job() {
656 if [ -z "$FLAT_A1_EI" ]; then
657 if [ $# -lt 6 ]; then
658 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
663 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
665 _log_test_fail_general "Job template file "$6", does not exist"
669 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
671 echo "$inputJson" > $file
673 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
675 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
676 if [ $# -lt 7 ]; then
677 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
682 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
684 _log_test_fail_general "Job template file "$7", does not exist"
688 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
690 echo "$inputJson" > $file
692 query="/A1-EI/v1/eijobs/$2"
695 res="$(__do_curl_to_api ECS PUT $query $file)"
696 status=${res:${#res}-3}
698 if [ $status -ne $1 ]; then
699 __log_test_fail_status_code $1 $status
708 ##########################################
709 #### Enrichment Data Producer API ####
710 ##########################################
711 # Function prefix: ecs_api_edp
713 # API Test function: GET /ei-producer/v1/eitypes
714 # args: <response-code> [ EMPTY | <type-id>+]
715 # (Function for test scripts)
716 ecs_api_edp_get_type_ids() {
719 if [ $# -lt 1 ]; then
720 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
724 query="/ei-producer/v1/eitypes"
725 res="$(__do_curl_to_api ECS GET $query)"
726 status=${res:${#res}-3}
728 if [ $status -ne $1 ]; then
729 __log_test_fail_status_code $1 $status
733 if [ $# -gt 1 ]; then
734 body=${res:0:${#res}-3}
736 if [ $2 != "EMPTY" ]; then
737 for pid in ${@:2} ; do
738 if [ "$targetJson" != "[" ]; then
739 targetJson=$targetJson","
741 targetJson=$targetJson"\"$pid\""
744 targetJson=$targetJson"]"
745 echo " TARGET JSON: $targetJson" >> $HTTPLOG
746 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
748 if [ $res -ne 0 ]; then
758 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
759 # args: <response-code> <producer-id> [<status> [<timeout>]]
760 # (Function for test scripts)
761 ecs_api_edp_get_producer_status() {
764 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
765 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
769 query="/ei-producer/v1/eiproducers/$2/status"
772 res="$(__do_curl_to_api ECS GET $query)"
773 status=${res:${#res}-3}
775 if [ $# -eq 4 ]; then
776 duration=$((SECONDS-start))
777 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
778 if [ $duration -gt $4 ]; then
780 duration=-1 #Last iteration
783 duration=-1 #single test, no wait
786 if [ $status -ne $1 ]; then
787 if [ $duration -eq -1 ]; then
788 __log_test_fail_status_code $1 $status
792 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
793 body=${res:0:${#res}-3}
794 targetJson="{\"operational_state\": \"$3\"}"
795 echo " TARGET JSON: $targetJson" >> $HTTPLOG
796 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
798 if [ $res -ne 0 ]; then
799 if [ $duration -eq -1 ]; then
804 duration=-1 #Goto pass
807 if [ $duration -eq -1 ]; then
808 if [ $# -eq 4 ]; then
820 # API Test function: GET /ei-producer/v1/eiproducers
821 # args: <response-code> [ EMPTY | <producer-id>+]
822 # (Function for test scripts)
823 ecs_api_edp_get_producer_ids() {
826 if [ $# -lt 1 ]; then
827 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
831 query="/ei-producer/v1/eiproducers"
832 res="$(__do_curl_to_api ECS GET $query)"
833 status=${res:${#res}-3}
835 if [ $status -ne $1 ]; then
836 __log_test_fail_status_code $1 $status
840 if [ $# -gt 1 ]; then
841 body=${res:0:${#res}-3}
844 for pid in ${@:2} ; do
845 if [ "$targetJson" != "[" ]; then
846 targetJson=$targetJson","
848 if [ $pid != "EMPTY" ]; then
849 targetJson=$targetJson"\"$pid\""
853 targetJson=$targetJson"]"
854 echo " TARGET JSON: $targetJson" >> $HTTPLOG
855 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
857 if [ $res -ne 0 ]; then
867 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
868 # args: <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
869 # (Function for test scripts)
870 ecs_api_edp_get_type() {
874 if [ $# -eq 2 ]; then
877 if [ $# -gt 3 ]; then
880 if [ $paramError -ne 0 ]; then
881 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
885 query="/ei-producer/v1/eitypes/$2"
886 res="$(__do_curl_to_api ECS GET $query)"
887 status=${res:${#res}-3}
889 if [ $status -ne $1 ]; then
890 __log_test_fail_status_code $1 $status
893 if [ $# -gt 3 ]; then
894 body=${res:0:${#res}-3}
899 __log_test_fail_general "Job template file "$3", does not exist"
904 if [ $4 != "EMPTY" ]; then
905 for pid in ${@:4} ; do
906 if [ "$targetJson" != "" ]; then
907 targetJson=$targetJson","
909 targetJson=$targetJson"\"$pid\""
912 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
914 echo " TARGET JSON: $targetJson" >> $HTTPLOG
915 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
917 if [ $res -ne 0 ]; then
926 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
927 # args: <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
928 # (Function for test scripts)
929 ecs_api_edp_get_producer() {
932 #Possible arg count: 2, 5 6, 8, 10 etc
934 if [ $# -eq 2 ]; then
937 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
940 variablecount=$(($#-4))
941 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
945 if [ $paramError -ne 0 ]; then
946 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
950 query="/ei-producer/v1/eiproducers/$2"
951 res="$(__do_curl_to_api ECS GET $query)"
952 status=${res:${#res}-3}
954 if [ $status -ne $1 ]; then
955 __log_test_fail_status_code $1 $status
959 if [ $# -gt 2 ]; then
960 body=${res:0:${#res}-3}
962 if [ $# -gt 5 ]; then
964 for ((i=0; i<$(($#-5)); i=i+2)); do
965 if [ "$targetJson" != "[" ]; then
966 targetJson=$targetJson","
968 if [ -f ${arr[$i+1]} ]; then
969 schema=$(cat ${arr[$i+1]})
971 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
975 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
978 targetJson=$targetJson"]"
979 if [ $# -gt 4 ]; then
980 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
982 echo " TARGET JSON: $targetJson" >> $HTTPLOG
983 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
985 if [ $res -ne 0 ]; then
995 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
996 # args: <response-code> <producer-id>
997 # (Function for test scripts)
998 ecs_api_edp_delete_producer() {
1001 if [ $# -lt 2 ]; then
1002 __print_err "<response-code> <producer-id>" $@
1006 query="/ei-producer/v1/eiproducers/$2"
1007 res="$(__do_curl_to_api ECS DELETE $query)"
1008 status=${res:${#res}-3}
1010 if [ $status -ne $1 ]; then
1011 __log_test_fail_status_code $1 $status
1019 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1020 # args: <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
1021 # (Function for test scripts)
1022 ecs_api_edp_put_producer() {
1025 #Valid number of parametrer 5,6,8,10,
1027 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1029 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
1032 if [ $paramError -ne 0 ]; then
1033 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
1038 if [ $# -gt 5 ]; then
1040 for ((i=0; i<$(($#-5)); i=i+2)); do
1041 if [ "$inputJson" != "[" ]; then
1042 inputJson=$inputJson","
1044 if [ -f ${arr[$i+1]} ]; then
1045 schema=$(cat ${arr[$i+1]})
1047 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1050 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1053 inputJson="\"supported_ei_types\":"$inputJson"]"
1055 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1057 inputJson="{"$inputJson"}"
1059 file="./tmp/.p.json"
1060 echo "$inputJson" > $file
1061 query="/ei-producer/v1/eiproducers/$2"
1062 res="$(__do_curl_to_api ECS PUT $query $file)"
1063 status=${res:${#res}-3}
1065 if [ $status -ne $1 ]; then
1066 __log_test_fail_status_code $1 $status
1074 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1075 # args: <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1076 # (Function for test scripts)
1077 ecs_api_edp_get_producer_jobs() {
1080 #Valid number of parameter 2,3,7,11
1082 if [ $# -eq 2 ]; then
1085 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1088 variablecount=$(($#-2))
1089 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1092 if [ $paramError -eq 1 ]; then
1093 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1097 query="/ei-producer/v1/eiproducers/$2/eijobs"
1098 res="$(__do_curl_to_api ECS GET $query)"
1099 status=${res:${#res}-3}
1100 if [ $status -ne $1 ]; then
1101 __log_test_fail_status_code $1 $status
1104 if [ $# -gt 2 ]; then
1105 body=${res:0:${#res}-3}
1107 if [ $# -gt 3 ]; then
1109 for ((i=0; i<$(($#-3)); i=i+5)); do
1110 if [ "$targetJson" != "[" ]; then
1111 targetJson=$targetJson","
1113 if [ -f ${arr[$i+4]} ]; then
1114 jobfile=$(cat ${arr[$i+4]})
1115 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1117 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1120 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}"
1123 targetJson=$targetJson"]"
1125 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1126 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1128 if [ $res -ne 0 ]; then
1129 __log_test_fail_body
1139 ##########################################
1140 #### Service status ####
1141 ##########################################
1142 # Function prefix: ecs_api_service
1144 # API Test function: GET /status
1145 # args: <response-code>
1146 # (Function for test scripts)
1147 ecs_api_service_status() {
1150 if [ $# -lt 1 ]; then
1151 __print_err "<response-code> [<producer-id>]*|NOID" $@
1154 res="$(__do_curl_to_api ECS GET /status)"
1155 status=${res:${#res}-3}
1156 if [ $status -ne $1 ]; then
1157 __log_test_fail_status_code $1 $status
1165 ##########################################
1166 #### Reset jobs ####
1167 ##########################################
1168 # Function prefix: ecs_api_admin
1170 # Admin to remove all jobs
1172 # (Function for test scripts)
1174 ecs_api_admin_reset() {
1177 if [ -z "$FLAT_A1_EI" ]; then
1178 query="/A1-EI/v1/eitypes/$2/eijobs"
1180 query="/A1-EI/v1/eijobs"
1182 res="$(__do_curl_to_api ECS GET $query)"
1183 status=${res:${#res}-3}
1185 if [ $status -ne 200 ]; then
1186 __log_test_fail_status_code $1 $status
1190 #Remove brackets and response code
1191 body=${res:1:${#res}-4}
1192 list=$(echo ${body//,/ })
1193 list=$(echo ${list//[/})
1194 list=$(echo ${list//]/})
1195 list=$(echo ${list//\"/})
1197 for job in $list; do
1198 if [ -z "$FLAT_A1_EI" ]; then
1199 echo "Not supported for non-flat EI api"
1201 query="/A1-EI/v1/eijobs/$job"
1202 res="$(__do_curl_to_api ECS DELETE $query)"
1203 status=${res:${#res}-3}
1204 if [ $status -ne 204 ]; then
1205 __log_test_fail_status_code $1 $status
1208 echo " Deleted job: "$job