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> [<timeout>]]
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 [ $# -lt 2 ] && [ $# -gt 4 ]; then
510 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
514 query="/A1-EI/v1/eijobs/$2/status"
518 res="$(__do_curl_to_api ECS GET $query)"
519 status=${res:${#res}-3}
521 if [ $# -eq 4 ]; then
522 duration=$((SECONDS-start))
523 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
524 if [ $duration -gt $4 ]; then
526 duration=-1 #Last iteration
529 duration=-1 #single test, no wait
532 if [ $status -ne $1 ]; then
533 if [ $duration -eq -1 ]; then
534 __log_test_fail_status_code $1 $status
538 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
539 body=${res:0:${#res}-3}
540 targetJson="{\"eiJobStatus\": \"$3\"}"
541 echo " TARGET JSON: $targetJson" >> $HTTPLOG
542 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
544 if [ $res -ne 0 ]; then
545 if [ $duration -eq -1 ]; then
550 duration=-1 #Goto pass
553 if [ $duration -eq -1 ]; then
554 if [ $# -eq 4 ]; then
569 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
570 # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
571 # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
572 # (Function for test scripts)
573 ecs_api_a1_get_job() {
576 if [ -z "$FLAT_A1_EI" ]; then
577 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
578 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
581 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
583 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
584 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
585 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
588 query="/A1-EI/v1/eijobs/$2"
590 res="$(__do_curl_to_api ECS GET $query)"
591 status=${res:${#res}-3}
593 if [ $status -ne $1 ]; then
594 __log_test_fail_status_code $1 $status
598 if [ -z "$FLAT_A1_EI" ]; then
599 if [ $# -eq 6 ]; then
600 body=${res:0:${#res}-3}
604 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
606 _log_test_fail_general "Job template file "$6", does not exist"
609 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
610 echo " TARGET JSON: $targetJson" >> $HTTPLOG
611 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
613 if [ $res -ne 0 ]; then
619 if [ $# -eq 7 ]; then
620 body=${res:0:${#res}-3}
624 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
626 _log_test_fail_general "Job template file "$6", does not exist"
629 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
630 echo " TARGET JSON: $targetJson" >> $HTTPLOG
631 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
633 if [ $res -ne 0 ]; then
644 # API Test function: DELETE /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
645 # args: <response-code> <type-id> <job-id>
646 # args (flat uri structure): <response-code> <job-id>
647 # (Function for test scripts)
648 ecs_api_a1_delete_job() {
651 if [ -z "$FLAT_A1_EI" ]; then
652 if [ $# -ne 3 ]; then
653 __print_err "<response-code> <type-id> <job-id>" $@
657 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
659 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
660 if [ $# -ne 2 ]; then
661 __print_err "<response-code> <job-id>" $@
664 query="/A1-EI/v1/eijobs/$2"
666 res="$(__do_curl_to_api ECS DELETE $query)"
667 status=${res:${#res}-3}
669 if [ $status -ne $1 ]; then
670 __log_test_fail_status_code $1 $status
678 # API Test function: PUT /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
679 # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
680 # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
681 # (Function for test scripts)
682 ecs_api_a1_put_job() {
685 if [ -z "$FLAT_A1_EI" ]; then
686 if [ $# -lt 6 ]; then
687 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
692 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
694 _log_test_fail_general "Job template file "$6", does not exist"
698 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
700 echo "$inputJson" > $file
702 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
704 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
705 if [ $# -lt 7 ]; then
706 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
711 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
713 _log_test_fail_general "Job template file "$7", does not exist"
717 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
719 echo "$inputJson" > $file
721 query="/A1-EI/v1/eijobs/$2"
724 res="$(__do_curl_to_api ECS PUT $query $file)"
725 status=${res:${#res}-3}
727 if [ $status -ne $1 ]; then
728 __log_test_fail_status_code $1 $status
737 ##########################################
738 #### Enrichment Data Producer API ####
739 ##########################################
740 # Function prefix: ecs_api_edp
742 # API Test function: GET /ei-producer/v1/eitypes
743 # args: <response-code> [ EMPTY | <type-id>+]
744 # (Function for test scripts)
745 ecs_api_edp_get_type_ids() {
748 if [ $# -lt 1 ]; then
749 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
753 query="/ei-producer/v1/eitypes"
754 res="$(__do_curl_to_api ECS GET $query)"
755 status=${res:${#res}-3}
757 if [ $status -ne $1 ]; then
758 __log_test_fail_status_code $1 $status
762 if [ $# -gt 1 ]; then
763 body=${res:0:${#res}-3}
765 if [ $2 != "EMPTY" ]; then
766 for pid in ${@:2} ; do
767 if [ "$targetJson" != "[" ]; then
768 targetJson=$targetJson","
770 targetJson=$targetJson"\"$pid\""
773 targetJson=$targetJson"]"
774 echo " TARGET JSON: $targetJson" >> $HTTPLOG
775 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
777 if [ $res -ne 0 ]; then
787 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
788 # args: <response-code> <producer-id> [<status> [<timeout>]]
789 # (Function for test scripts)
790 ecs_api_edp_get_producer_status() {
793 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
794 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
798 query="/ei-producer/v1/eiproducers/$2/status"
801 res="$(__do_curl_to_api ECS GET $query)"
802 status=${res:${#res}-3}
804 if [ $# -eq 4 ]; then
805 duration=$((SECONDS-start))
806 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
807 if [ $duration -gt $4 ]; then
809 duration=-1 #Last iteration
812 duration=-1 #single test, no wait
815 if [ $status -ne $1 ]; then
816 if [ $duration -eq -1 ]; then
817 __log_test_fail_status_code $1 $status
821 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
822 body=${res:0:${#res}-3}
823 targetJson="{\"operational_state\": \"$3\"}"
824 echo " TARGET JSON: $targetJson" >> $HTTPLOG
825 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
827 if [ $res -ne 0 ]; then
828 if [ $duration -eq -1 ]; then
833 duration=-1 #Goto pass
836 if [ $duration -eq -1 ]; then
837 if [ $# -eq 4 ]; then
849 # API Test function: GET /ei-producer/v1/eiproducers
850 # args (v1_1): <response-code> [ EMPTY | <producer-id>+]
851 # (Function for test scripts)
852 ecs_api_edp_get_producer_ids() {
855 if [ $# -lt 1 ]; then
856 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
860 query="/ei-producer/v1/eiproducers"
861 res="$(__do_curl_to_api ECS GET $query)"
862 status=${res:${#res}-3}
864 if [ $status -ne $1 ]; then
865 __log_test_fail_status_code $1 $status
869 if [ $# -gt 1 ]; then
870 body=${res:0:${#res}-3}
873 for pid in ${@:2} ; do
874 if [ "$targetJson" != "[" ]; then
875 targetJson=$targetJson","
877 if [ $pid != "EMPTY" ]; then
878 targetJson=$targetJson"\"$pid\""
882 targetJson=$targetJson"]"
883 echo " TARGET JSON: $targetJson" >> $HTTPLOG
884 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
886 if [ $res -ne 0 ]; then
896 # API Test function: GET /ei-producer/v1/eiproducers
897 # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
898 # (Function for test scripts)
899 ecs_api_edp_get_producer_ids_2() {
902 if [ $# -lt 1 ]; then
903 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
907 query="/ei-producer/v1/eiproducers"
908 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
909 query=$query"?ei_type_id=$2"
911 res="$(__do_curl_to_api ECS GET $query)"
912 status=${res:${#res}-3}
914 if [ $status -ne $1 ]; then
915 __log_test_fail_status_code $1 $status
919 if [ $# -gt 2 ]; then
920 body=${res:0:${#res}-3}
923 for pid in ${@:3} ; do
924 if [ "$targetJson" != "[" ]; then
925 targetJson=$targetJson","
927 if [ $pid != "EMPTY" ]; then
928 targetJson=$targetJson"\"$pid\""
932 targetJson=$targetJson"]"
933 echo " TARGET JSON: $targetJson" >> $HTTPLOG
934 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
936 if [ $res -ne 0 ]; then
946 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
947 # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
948 # (Function for test scripts)
949 ecs_api_edp_get_type() {
953 if [ $# -eq 2 ]; then
956 if [ $# -gt 3 ]; then
959 if [ $paramError -ne 0 ]; then
960 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
964 query="/ei-producer/v1/eitypes/$2"
965 res="$(__do_curl_to_api ECS GET $query)"
966 status=${res:${#res}-3}
968 if [ $status -ne $1 ]; then
969 __log_test_fail_status_code $1 $status
972 if [ $# -gt 3 ]; then
973 body=${res:0:${#res}-3}
978 __log_test_fail_general "Job template file "$3", does not exist"
983 if [ $4 != "EMPTY" ]; then
984 for pid in ${@:4} ; do
985 if [ "$targetJson" != "" ]; then
986 targetJson=$targetJson","
988 targetJson=$targetJson"\"$pid\""
991 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
993 echo " TARGET JSON: $targetJson" >> $HTTPLOG
994 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
996 if [ $res -ne 0 ]; then
1005 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1006 # args: (v1_2) <response-code> <type-id> [<job-schema-file> ]
1007 # (Function for test scripts)
1008 ecs_api_edp_get_type_2() {
1012 if [ $# -eq 2 ]; then
1015 if [ $# -eq 3 ]; then
1018 if [ $paramError -ne 0 ]; then
1019 __print_err "<response-code> <type-id> [<job-schema-file> ]" $@
1023 query="/ei-producer/v1/eitypes/$2"
1024 res="$(__do_curl_to_api ECS GET $query)"
1025 status=${res:${#res}-3}
1027 if [ $status -ne $1 ]; then
1028 __log_test_fail_status_code $1 $status
1031 if [ $# -eq 3 ]; then
1032 body=${res:0:${#res}-3}
1037 __log_test_fail_general "Job template file "$3", does not exist"
1041 targetJson="{\"ei_job_data_schema\":$schema}"
1043 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1044 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1046 if [ $res -ne 0 ]; then
1047 __log_test_fail_body
1055 # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1056 # args: (v1_2) <response-code> <type-id> <job-schema-file>
1057 # (Function for test scripts)
1058 ecs_api_edp_put_type_2() {
1061 if [ $# -ne 3 ]; then
1062 __print_err "<response-code> <type-id> <job-schema-file>" $@
1066 if [ ! -f $3 ]; then
1067 __log_test_fail_general "Job schema file "$3", does not exist"
1071 input_json="{\"ei_job_data_schema\":$schema}"
1072 file="./tmp/put_type.json"
1073 echo $input_json > $file
1075 query="/ei-producer/v1/eitypes/$2"
1076 res="$(__do_curl_to_api ECS PUT $query $file)"
1077 status=${res:${#res}-3}
1079 if [ $status -ne $1 ]; then
1080 __log_test_fail_status_code $1 $status
1088 # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1089 # args: (v1_2) <response-code> <type-id>
1090 # (Function for test scripts)
1091 ecs_api_edp_delete_type_2() {
1094 if [ $# -ne 2 ]; then
1095 __print_err "<response-code> <type-id>" $@
1099 query="/ei-producer/v1/eitypes/$2"
1100 res="$(__do_curl_to_api ECS DELETE $query)"
1101 status=${res:${#res}-3}
1103 if [ $status -ne $1 ]; then
1104 __log_test_fail_status_code $1 $status
1112 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1113 # args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
1114 # (Function for test scripts)
1115 ecs_api_edp_get_producer() {
1118 #Possible arg count: 2, 5 6, 8, 10 etc
1120 if [ $# -eq 2 ]; then
1123 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1126 variablecount=$(($#-4))
1127 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1131 if [ $paramError -ne 0 ]; then
1132 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
1136 query="/ei-producer/v1/eiproducers/$2"
1137 res="$(__do_curl_to_api ECS GET $query)"
1138 status=${res:${#res}-3}
1140 if [ $status -ne $1 ]; then
1141 __log_test_fail_status_code $1 $status
1145 if [ $# -gt 2 ]; then
1146 body=${res:0:${#res}-3}
1148 if [ $# -gt 5 ]; then
1150 for ((i=0; i<$(($#-5)); i=i+2)); do
1151 if [ "$targetJson" != "[" ]; then
1152 targetJson=$targetJson","
1154 if [ -f ${arr[$i+1]} ]; then
1155 schema=$(cat ${arr[$i+1]})
1157 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1161 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1164 targetJson=$targetJson"]"
1165 if [ $# -gt 4 ]; then
1166 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1168 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1169 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1171 if [ $res -ne 0 ]; then
1172 __log_test_fail_body
1181 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1182 # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1183 # (Function for test scripts)
1184 ecs_api_edp_get_producer_2() {
1187 #Possible arg count: 2, 5, 6, 7, 8 etc
1189 if [ $# -eq 2 ]; then
1192 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1195 if [ $# -ge 5 ]; then
1199 if [ $paramError -ne 0 ]; then
1200 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1204 query="/ei-producer/v1/eiproducers/$2"
1205 res="$(__do_curl_to_api ECS GET $query)"
1206 status=${res:${#res}-3}
1208 if [ $status -ne $1 ]; then
1209 __log_test_fail_status_code $1 $status
1213 if [ $# -gt 2 ]; then
1214 body=${res:0:${#res}-3}
1216 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1218 for ((i=0; i<$(($#-4)); i=i+1)); do
1219 if [ "$targetJson" != "[" ]; then
1220 targetJson=$targetJson","
1222 targetJson=$targetJson"\"${arr[$i]}\""
1225 targetJson=$targetJson"]"
1226 if [ $# -gt 4 ]; then
1227 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1229 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1230 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1232 if [ $res -ne 0 ]; then
1233 __log_test_fail_body
1242 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
1243 # args: <response-code> <producer-id>
1244 # (Function for test scripts)
1245 ecs_api_edp_delete_producer() {
1248 if [ $# -lt 2 ]; then
1249 __print_err "<response-code> <producer-id>" $@
1253 query="/ei-producer/v1/eiproducers/$2"
1254 res="$(__do_curl_to_api ECS DELETE $query)"
1255 status=${res:${#res}-3}
1257 if [ $status -ne $1 ]; then
1258 __log_test_fail_status_code $1 $status
1266 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1267 # args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
1268 # (Function for test scripts)
1269 ecs_api_edp_put_producer() {
1272 #Valid number of parametrer 5,6,8,10,
1274 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1276 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
1279 if [ $paramError -ne 0 ]; then
1280 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
1285 if [ $# -gt 5 ]; then
1287 for ((i=0; i<$(($#-5)); i=i+2)); do
1288 if [ "$inputJson" != "[" ]; then
1289 inputJson=$inputJson","
1291 if [ -f ${arr[$i+1]} ]; then
1292 schema=$(cat ${arr[$i+1]})
1294 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1297 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1300 inputJson="\"supported_ei_types\":"$inputJson"]"
1302 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1304 inputJson="{"$inputJson"}"
1306 file="./tmp/.p.json"
1307 echo "$inputJson" > $file
1308 query="/ei-producer/v1/eiproducers/$2"
1309 res="$(__do_curl_to_api ECS PUT $query $file)"
1310 status=${res:${#res}-3}
1312 if [ $status -ne $1 ]; then
1313 __log_test_fail_status_code $1 $status
1321 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1322 # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1323 # (Function for test scripts)
1324 ecs_api_edp_put_producer_2() {
1327 #Valid number of parametrer 5,6,8,10,
1329 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1331 elif [ $# -ge 5 ]; then
1334 if [ $paramError -ne 0 ]; then
1335 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1340 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1342 for ((i=0; i<$(($#-4)); i=i+1)); do
1343 if [ "$inputJson" != "[" ]; then
1344 inputJson=$inputJson","
1346 inputJson=$inputJson"\""${arr[$i]}"\""
1349 inputJson="\"supported_ei_types\":"$inputJson"]"
1351 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1353 inputJson="{"$inputJson"}"
1355 file="./tmp/.p.json"
1356 echo "$inputJson" > $file
1357 query="/ei-producer/v1/eiproducers/$2"
1358 res="$(__do_curl_to_api ECS PUT $query $file)"
1359 status=${res:${#res}-3}
1361 if [ $status -ne $1 ]; then
1362 __log_test_fail_status_code $1 $status
1370 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1371 # args: <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1372 # (Function for test scripts)
1373 ecs_api_edp_get_producer_jobs() {
1376 #Valid number of parameter 2,3,7,11
1378 if [ $# -eq 2 ]; then
1381 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1384 variablecount=$(($#-2))
1385 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1388 if [ $paramError -eq 1 ]; then
1389 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1393 query="/ei-producer/v1/eiproducers/$2/eijobs"
1394 res="$(__do_curl_to_api ECS GET $query)"
1395 status=${res:${#res}-3}
1396 if [ $status -ne $1 ]; then
1397 __log_test_fail_status_code $1 $status
1400 if [ $# -gt 2 ]; then
1401 body=${res:0:${#res}-3}
1403 if [ $# -gt 3 ]; then
1405 for ((i=0; i<$(($#-3)); i=i+5)); do
1406 if [ "$targetJson" != "[" ]; then
1407 targetJson=$targetJson","
1409 if [ -f ${arr[$i+4]} ]; then
1410 jobfile=$(cat ${arr[$i+4]})
1411 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1413 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1416 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}"
1419 targetJson=$targetJson"]"
1421 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1422 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1424 if [ $res -ne 0 ]; then
1425 __log_test_fail_body
1435 ##########################################
1436 #### Service status ####
1437 ##########################################
1438 # Function prefix: ecs_api_service
1440 # API Test function: GET /status
1441 # args: <response-code>
1442 # (Function for test scripts)
1443 ecs_api_service_status() {
1446 if [ $# -lt 1 ]; then
1447 __print_err "<response-code> [<producer-id>]*|NOID" $@
1450 res="$(__do_curl_to_api ECS GET /status)"
1451 status=${res:${#res}-3}
1452 if [ $status -ne $1 ]; then
1453 __log_test_fail_status_code $1 $status
1461 ##########################################
1462 #### Reset jobs ####
1463 ##########################################
1464 # Function prefix: ecs_api_admin
1466 # Admin to remove all jobs
1468 # (Function for test scripts)
1470 ecs_api_admin_reset() {
1473 if [ -z "$FLAT_A1_EI" ]; then
1474 query="/A1-EI/v1/eitypes/$2/eijobs"
1476 query="/A1-EI/v1/eijobs"
1478 res="$(__do_curl_to_api ECS GET $query)"
1479 status=${res:${#res}-3}
1481 if [ $status -ne 200 ]; then
1482 __log_test_fail_status_code $1 $status
1486 #Remove brackets and response code
1487 body=${res:1:${#res}-4}
1488 list=$(echo ${body//,/ })
1489 list=$(echo ${list//[/})
1490 list=$(echo ${list//]/})
1491 list=$(echo ${list//\"/})
1493 for job in $list; do
1494 if [ -z "$FLAT_A1_EI" ]; then
1495 echo "Not supported for non-flat EI api"
1497 query="/A1-EI/v1/eijobs/$job"
1498 res="$(__do_curl_to_api ECS DELETE $query)"
1499 status=${res:${#res}-3}
1500 if [ $status -ne 204 ]; then
1501 __log_test_fail_status_code $1 $status
1504 echo " Deleted job: "$job