X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Fecs_api_functions.sh;h=3edb88d2f98bc65b2f11e98a02385fdd66ee06dc;hb=e29568dbbfe4bb333c936dfe7b54ba639fdef492;hp=e9ff1f9a0f331f091959da5d78292c9d67bcf435;hpb=c963b73942867f631f9e5708e28025140afcb893;p=nonrtric.git diff --git a/test/common/ecs_api_functions.sh b/test/common/ecs_api_functions.sh index e9ff1f9a..3edb88d2 100644 --- a/test/common/ecs_api_functions.sh +++ b/test/common/ecs_api_functions.sh @@ -19,6 +19,69 @@ # This is a script that contains container/service management functions and test functions for ECS +################ Test engine functions ################ + +# Create the image var used during the test +# arg: (selects staging, snapshot, release etc) +# is present only for images with staging, snapshot,release tags +__ECS_imagesetup() { + __check_and_create_image_var ECS "ECS_IMAGE" "ECS_IMAGE_BASE" "ECS_IMAGE_TAG" $1 "$ECS_DISPLAY_NAME" +} + +# Pull image from remote repo or use locally built image +# arg: +# Shall be used for images allowing overriding. For example use a local image when test is started to use released images +# Shall be used for images that does not allow overriding +# Both var may contain: 'remote', 'remote-remove' or 'local' +__ECS_imagepull() { + __check_and_pull_image $1 "$ECS_DISPLAY_NAME" $ECS_APP_NAME ECS_IMAGE +} + +# Build image (only for simulator or interfaces stubs owned by the test environment) +# arg: (selects staging, snapshot, release etc) +# is present only for images with staging, snapshot,release tags +__ECS_imagebuild() { + echo -e $RED" Image for app ECS shall never be built"$ERED +} + +# Generate a string for each included image using the app display name and a docker images format string +# If a custom image repo is used then also the source image from the local repo is listed +# arg: +__ECS_image_data() { + echo -e "$ECS_DISPLAY_NAME\t$(docker images --format $1 $ECS_IMAGE)" >> $2 + if [ ! -z "$ECS_IMAGE_SOURCE" ]; then + echo -e "-- source image --\t$(docker images --format $1 $ECS_IMAGE_SOURCE)" >> $2 + fi +} + +# Scale kubernetes resources to zero +# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action. +# This function is called for apps fully managed by the test script +__ECS_kube_scale_zero() { + __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS +} + +# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action. +# This function is called for prestarted apps not managed by the test script. +__ECS_kube_scale_zero_and_wait() { + __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-enrichmentservice +} + +# Delete all kube resouces for the app +# This function is called for apps managed by the test script. +__ECS_kube_delete_all() { + __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS +} + +# Store docker logs +# This function is called for apps managed by the test script. +# args: +__ECS_store_docker_logs() { + docker logs $ECS_APP_NAME > $1$2_ecs.log 2>&1 +} +####################################################### + + ## Access to ECS # Host name may be changed if app started by kube # Direct access @@ -33,6 +96,9 @@ ECS_ADAPTER=$ECS_PATH # Make curl retries towards ECS for http response codes set in this env var, space separated list of codes ECS_RETRY_CODES="" +#Save first worker node the pod is started on +__ECS_WORKER_NODE="" + ########################### ### ECS functions ########################### @@ -141,6 +207,11 @@ start_ecs() { export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data" export ECS_CONTAINER_MNT_DIR + export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv" + export ECS_DATA_PVC_NAME=$ECS_APP_NAME"-pvc" + #Create a unique path for the pv each time to prevent a previous volume to be reused + export ECS_PV_PATH="ecsdata-"$(date +%s) + if [ $1 == "PROXY" ]; then ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started @@ -163,6 +234,11 @@ start_ecs() { output_yaml=$PWD/tmp/ecs_cfc.yaml __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml + # Create pv + input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pv.yaml + output_yaml=$PWD/tmp/ecs_pv.yaml + __kube_create_instance pv $ECS_APP_NAME $input_yaml $output_yaml + # Create pvc input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml output_yaml=$PWD/tmp/ecs_pvc.yaml @@ -179,6 +255,19 @@ start_ecs() { __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml fi + # Tie the ECS to a worker node so that ECS will always be scheduled to the same worker node if the ECS pod is restarted + # A PVC of type hostPath is mounted to ECS, for persistent storage, so the ECS must always be on the node which mounted the volume + + # 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 + if [ $retcode_i -eq 0 ]; then + __ECS_WORKER_NODE=$(kubectl get pod -l "autotest=ECS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}') + if [ -z "$__ECS_WORKER_NODE" ]; then + echo -e $YELLOW" Cannot find worker node for pod for $ECS_APP_NAME, persistency may not work"$EYELLOW + fi + else + echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW + fi + echo " Retrieving host and ports for service..." ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE) ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http") @@ -235,6 +324,7 @@ start_ecs() { export ECS_INTERNAL_SECURE_PORT export ECS_EXTERNAL_SECURE_PORT export DOCKER_SIM_NWNAME + export ECS_DISPLAY_NAME if [ $1 == "PROXY" ]; then ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started @@ -256,7 +346,7 @@ start_ecs() { envsubst < $2 > $dest_file - __start_container $ECS_COMPOSE_DIR NODOCKERARGS 1 $ECS_APP_NAME + __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL fi @@ -264,20 +354,88 @@ start_ecs() { return 0 } -# Restart ECS +# Stop the ecs +# args: - # args: - # (Function for test scripts) -restart_ecs() { - echo -e $BOLD"Re-starting ECS"$EBOLD - docker restart $ECS_APP_NAME &> ./tmp/.dockererr - if [ $? -ne 0 ]; then - __print_err "Could not restart $ECS_APP_NAME" $@ - cat ./tmp/.dockererr - ((RES_CONF_FAIL++)) - return 1 +stop_ecs() { + echo -e $BOLD"Stopping $ECS_DISPLAY_NAME"$EBOLD + + if [ $RUNMODE == "KUBE" ]; then + + __check_prestarted_image "ECS" + if [ $? -eq 0 ]; then + echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW + __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0 + return 0 + fi + + __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS + echo " Deleting the replica set - a new will be started when the app is started" + tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ECS") + if [ $? -ne 0 ]; then + echo -e $RED" Could not delete replica set "$RED + ((RES_CONF_FAIL++)) + return 1 + fi + else + docker stop $ECS_APP_NAME &> ./tmp/.dockererr + if [ $? -ne 0 ]; then + __print_err "Could not stop $ECS_APP_NAME" $@ + cat ./tmp/.dockererr + ((RES_CONF_FAIL++)) + return 1 + fi fi + echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD + echo "" + return 0 +} + +# Start a previously stopped ecs +# args: - +# (Function for test scripts) +start_stopped_ecs() { + echo -e $BOLD"Starting (the previously stopped) $ECS_DISPLAY_NAME"$EBOLD + + if [ $RUNMODE == "KUBE" ]; then + __check_prestarted_image "ECS" + if [ $? -eq 0 ]; then + echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW + __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 + __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL + return 0 + fi + + # Tie the PMS to the same worker node it was initially started on + # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume + if [ -z "$__ECS_WORKER_NODE" ]; then + echo -e $RED" No initial worker node found for pod "$RED + ((RES_CONF_FAIL++)) + return 1 + else + echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ECS_WORKER_NODE to deployment for $ECS_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD + echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD + tmp=$(kubectl patch deployment $ECS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ECS_WORKER_NODE'"}}}}}') + if [ $? -ne 0 ]; then + echo -e $YELLOW" Cannot set nodeSelector to deployment for $ECS_APP_NAME, persistency may not work"$EYELLOW + fi + __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 + fi + else + docker start $ECS_APP_NAME &> ./tmp/.dockererr + if [ $? -ne 0 ]; then + __print_err "Could not start (the stopped) $ECS_APP_NAME" $@ + cat ./tmp/.dockererr + ((RES_CONF_FAIL++)) + return 1 + fi + fi __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL + if [ $? -ne 0 ]; then + return 1 + fi echo "" return 0 } @@ -324,6 +482,13 @@ use_ecs_retries() { return 0 } +# Check the ecs logs for WARNINGs and ERRORs +# args: - +# (Function for test scripts) +check_ecs_logs() { + __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR +} + # Tests if a variable value in the ECS is equal to a target value and and optional timeout. # Arg: - This test set pass or fail depending on if the variable is @@ -360,7 +525,7 @@ ecs_api_a1_get_job_ids() { return 1 fi else - echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW + echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW # Valid number of parameters 4,5,6 etc if [ $# -lt 3 ]; then __print_err " |NOTYPE |NOOWNER [ EMPTY | + ]" $@ @@ -543,7 +708,7 @@ ecs_api_a1_get_job_status() { fi fi else - echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW + echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW if [ $# -lt 2 ] && [ $# -gt 4 ]; then __print_err " [ []]" $@ return 1 @@ -618,7 +783,7 @@ ecs_api_a1_get_job() { fi query="/A1-EI/v1/eitypes/$2/eijobs/$3" else - echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW + echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW if [ $# -ne 2 ] && [ $# -ne 7 ]; then __print_err " [ ]" $@ return 1 @@ -641,7 +806,7 @@ ecs_api_a1_get_job() { jobfile=$(cat $6) jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") else - _log_test_fail_general "Job template file "$6", does not exist" + __log_test_fail_general "Job template file "$6", does not exist" return 1 fi targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" @@ -661,7 +826,7 @@ ecs_api_a1_get_job() { jobfile=$(cat $7) jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") else - _log_test_fail_general "Job template file "$6", does not exist" + __log_test_fail_general "Job template file "$6", does not exist" return 1 fi targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" @@ -694,7 +859,7 @@ ecs_api_a1_delete_job() { query="/A1-EI/v1/eitypes/$2/eijobs/$3" else - echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW + echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW if [ $# -ne 2 ]; then __print_err " " $@ return 1 @@ -729,7 +894,7 @@ ecs_api_a1_put_job() { jobfile=$(cat $6) jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") else - _log_test_fail_general "Job template file "$6", does not exist" + __log_test_fail_general "Job template file "$6", does not exist" return 1 fi @@ -739,7 +904,7 @@ ecs_api_a1_put_job() { query="/A1-EI/v1/eitypes/$2/eijobs/$3" else - echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW + echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW if [ $# -lt 7 ]; then __print_err " " $@ return 1 @@ -748,7 +913,7 @@ ecs_api_a1_put_job() { jobfile=$(cat $7) jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") else - _log_test_fail_general "Job template file "$7", does not exist" + __log_test_fail_general "Job template file "$7", does not exist" return 1 fi @@ -778,6 +943,7 @@ ecs_api_a1_put_job() { # Function prefix: ecs_api_edp # API Test function: GET /ei-producer/v1/eitypes +# API Test function: GET /data-producer/v1/info-types # args: [ EMPTY | +] # (Function for test scripts) ecs_api_edp_get_type_ids() { @@ -787,8 +953,11 @@ ecs_api_edp_get_type_ids() { __print_err " [ EMPTY | +]" $@ return 1 fi - - query="/ei-producer/v1/eitypes" + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + query="/data-producer/v1/info-types" + else + query="/ei-producer/v1/eitypes" + fi res="$(__do_curl_to_api ECS GET $query)" status=${res:${#res}-3} @@ -823,6 +992,7 @@ ecs_api_edp_get_type_ids() { } # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status +# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status # args: [ []] # (Function for test scripts) ecs_api_edp_get_producer_status() { @@ -832,8 +1002,11 @@ ecs_api_edp_get_producer_status() { __print_err " [ []]" $@ return 1 fi - - query="/ei-producer/v1/eiproducers/$2/status" + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + query="/data-producer/v1/info-producers/$2/status" + else + query="/ei-producer/v1/eiproducers/$2/status" + fi start=$SECONDS for (( ; ; )); do res="$(__do_curl_to_api ECS GET $query)" @@ -932,6 +1105,7 @@ ecs_api_edp_get_producer_ids() { } # API Test function: GET /ei-producer/v1/eiproducers +# API Test function: GET /data-producer/v1/info-producers # args (v1_2): [ ( NOTYPE | ) [ EMPTY | +] ] # (Function for test scripts) ecs_api_edp_get_producer_ids_2() { @@ -941,10 +1115,16 @@ ecs_api_edp_get_producer_ids_2() { __print_err " [ ( NOTYPE | ) [ EMPTY | +] ]" $@ return 1 fi - - query="/ei-producer/v1/eiproducers" - if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then - query=$query"?ei_type_id=$2" + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + query="/data-producer/v1/info-producers" + if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then + query=$query"?info_type_id=$2" + fi + else + query="/ei-producer/v1/eiproducers" + if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then + query=$query"?ei_type_id=$2" + fi fi res="$(__do_curl_to_api ECS GET $query)" status=${res:${#res}-3} @@ -1041,6 +1221,7 @@ ecs_api_edp_get_type() { } # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId} +# API Test function: GET /data-producer/v1/info-types/{infoTypeId} # args: (v1_2) [ ] # (Function for test scripts) ecs_api_edp_get_type_2() { @@ -1057,8 +1238,12 @@ ecs_api_edp_get_type_2() { __print_err " [ ]" $@ return 1 fi + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + query="/data-producer/v1/info-types/$2" + else + query="/ei-producer/v1/eitypes/$2" + fi - query="/ei-producer/v1/eitypes/$2" res="$(__do_curl_to_api ECS GET $query)" status=${res:${#res}-3} @@ -1075,8 +1260,11 @@ ecs_api_edp_get_type_2() { __log_test_fail_general "Job template file "$3", does not exist" return 1 fi - - targetJson="{\"ei_job_data_schema\":$schema}" + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + targetJson="{\"info_job_data_schema\":$schema}" + else + targetJson="{\"ei_job_data_schema\":$schema}" + fi echo " TARGET JSON: $targetJson" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$targetJson" "$body") @@ -1091,6 +1279,7 @@ ecs_api_edp_get_type_2() { } # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId} +# API Test function: PUT /data-producer/v1/info-types/{infoTypeId} # args: (v1_2) # (Function for test scripts) ecs_api_edp_put_type_2() { @@ -1105,12 +1294,21 @@ ecs_api_edp_put_type_2() { __log_test_fail_general "Job schema file "$3", does not exist" return 1 fi - schema=$(cat $3) - input_json="{\"ei_job_data_schema\":$schema}" - file="./tmp/put_type.json" - echo $input_json > $file + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + schema=$(cat $3) + input_json="{\"info_job_data_schema\":$schema}" + file="./tmp/put_type.json" + echo $input_json > $file - query="/ei-producer/v1/eitypes/$2" + query="/data-producer/v1/info-types/$2" + else + schema=$(cat $3) + input_json="{\"ei_job_data_schema\":$schema}" + file="./tmp/put_type.json" + echo $input_json > $file + + query="/ei-producer/v1/eitypes/$2" + fi res="$(__do_curl_to_api ECS PUT $query $file)" status=${res:${#res}-3} @@ -1124,6 +1322,7 @@ ecs_api_edp_put_type_2() { } # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId} +# API Test function: DELETE /data-producer/v1/info-types/{infoTypeId} # args: (v1_2) # (Function for test scripts) ecs_api_edp_delete_type_2() { @@ -1134,7 +1333,11 @@ ecs_api_edp_delete_type_2() { return 1 fi - query="/ei-producer/v1/eitypes/$2" + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + query="/data-producer/v1/info-types/$2" + else + query="/ei-producer/v1/eitypes/$2" + fi res="$(__do_curl_to_api ECS DELETE $query)" status=${res:${#res}-3} @@ -1192,7 +1395,7 @@ ecs_api_edp_get_producer() { if [ -f ${arr[$i+1]} ]; then schema=$(cat ${arr[$i+1]}) else - _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" + __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" return 1 fi @@ -1217,6 +1420,7 @@ ecs_api_edp_get_producer() { } # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} +# API Test function: GET /data-producer/v1/info-producers/{infoProducerId} # args (v1_2): [ (EMPTY | +) ] # (Function for test scripts) ecs_api_edp_get_producer_2() { @@ -1238,8 +1442,11 @@ ecs_api_edp_get_producer_2() { __print_err " [ (EMPTY | +) ]" $@ return 1 fi - - query="/ei-producer/v1/eiproducers/$2" + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + query="/data-producer/v1/info-producers/$2" + else + query="/ei-producer/v1/eiproducers/$2" + fi res="$(__do_curl_to_api ECS GET $query)" status=${res:${#res}-3} @@ -1262,7 +1469,11 @@ ecs_api_edp_get_producer_2() { fi targetJson=$targetJson"]" if [ $# -gt 4 ]; then - targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}" + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}" + else + targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}" + fi fi echo " TARGET JSON: $targetJson" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$targetJson" "$body") @@ -1278,6 +1489,7 @@ ecs_api_edp_get_producer_2() { } # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId} +# API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId} # args: # (Function for test scripts) ecs_api_edp_delete_producer() { @@ -1287,8 +1499,11 @@ ecs_api_edp_delete_producer() { __print_err " " $@ return 1 fi - - query="/ei-producer/v1/eiproducers/$2" + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + query="/data-producer/v1/info-producers/$2" + else + query="/ei-producer/v1/eiproducers/$2" + fi res="$(__do_curl_to_api ECS DELETE $query)" status=${res:${#res}-3} @@ -1329,7 +1544,7 @@ ecs_api_edp_put_producer() { if [ -f ${arr[$i+1]} ]; then schema=$(cat ${arr[$i+1]}) else - _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" + __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" return 1 fi inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" @@ -1357,6 +1572,7 @@ ecs_api_edp_put_producer() { } # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} +# API Test function: PUT /data-producer/v1/info-producers/{infoProducerId} # args: (v1_2) NOTYPE|[+] # (Function for test scripts) ecs_api_edp_put_producer_2() { @@ -1384,15 +1600,27 @@ ecs_api_edp_put_producer_2() { inputJson=$inputJson"\""${arr[$i]}"\"" done fi - inputJson="\"supported_ei_types\":"$inputJson"]" + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + inputJson="\"supported_info_types\":"$inputJson"]" - inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"" + inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"" - inputJson="{"$inputJson"}" + inputJson="{"$inputJson"}" - file="./tmp/.p.json" - echo "$inputJson" > $file - query="/ei-producer/v1/eiproducers/$2" + file="./tmp/.p.json" + echo "$inputJson" > $file + query="/data-producer/v1/info-producers/$2" + else + inputJson="\"supported_ei_types\":"$inputJson"]" + + inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"" + + inputJson="{"$inputJson"}" + + file="./tmp/.p.json" + echo "$inputJson" > $file + query="/ei-producer/v1/eiproducers/$2" + fi res="$(__do_curl_to_api ECS PUT $query $file)" status=${res:${#res}-3} @@ -1448,7 +1676,7 @@ ecs_api_edp_get_producer_jobs() { jobfile=$(cat ${arr[$i+4]}) jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g") else - _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist" + __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist" return 1 fi 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}" @@ -1470,6 +1698,7 @@ ecs_api_edp_get_producer_jobs() { } # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs +# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs # args: (V1-2) (EMPTY | [ ]+) # (Function for test scripts) ecs_api_edp_get_producer_jobs_2() { @@ -1491,8 +1720,11 @@ ecs_api_edp_get_producer_jobs_2() { __print_err " (EMPTY | [ ]+)" $@ return 1 fi - - query="/ei-producer/v1/eiproducers/$2/eijobs" + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + query="/data-producer/v1/info-producers/$2/info-jobs" + else + query="/ei-producer/v1/eiproducers/$2/eijobs" + fi res="$(__do_curl_to_api ECS GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -1512,10 +1744,14 @@ ecs_api_edp_get_producer_jobs_2() { jobfile=$(cat ${arr[$i+4]}) jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g") else - _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist" + __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist" return 1 fi - targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile, \"last_updated\":\"????\"}" + if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then + 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\":\"????\"}" + else + targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile, \"last_updated\":\"????\"}" + fi done fi targetJson=$targetJson"]" @@ -1545,7 +1781,7 @@ ecs_api_service_status() { __log_test_start $@ if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + __print_err "" $@ return 1 fi res="$(__do_curl_to_api ECS GET /status)" @@ -1558,6 +1794,332 @@ ecs_api_service_status() { return 0 } +########################################### +######### Info data consumer API ########## +########################################### +#Function prefix: ecs_api_idc + + +# API Test function: GET /data-consumer/v1/info-types +# args: [ (EMPTY | []+) ] +# (Function for test scripts) +ecs_api_idc_get_type_ids() { + __log_test_start $@ + + if [ $# -lt 1 ]; then + __print_err " [ (EMPTY | []+) ]" $@ + return 1 + fi + + query="/data-consumer/v1/info-types" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + if [ $# -gt 1 ]; then + body=${res:0:${#res}-3} + targetJson="[" + if [ $2 != "EMPTY" ]; then + for pid in ${@:2} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"\"$pid\"" + done + fi + targetJson=$targetJson"]" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + __log_test_fail_body + return 1 + fi + fi + + __log_test_pass + return 0 +} + +# API Test function: GET /data-consumer/v1/info-jobs +# args: |NOTYPE |NOOWNER [ EMPTY | + ] +# (Function for test scripts) +ecs_api_idc_get_job_ids() { + __log_test_start $@ + + # Valid number of parameters 4,5,6 etc + if [ $# -lt 3 ]; then + __print_err " |NOTYPE |NOOWNER [ EMPTY | + ]" $@ + return 1 + fi + search="" + if [ $3 != "NOWNER" ]; then + search="?owner="$3 + fi + + if [ $2 != "NOTYPE" ]; then + if [ -z "$search" ]; then + search="?infoTypeId="$2 + else + search=$search"&infoTypeId="$2 + fi + fi + query="/data-consumer/v1/info-jobs$search" + + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + + if [ $# -gt 3 ]; then + body=${res:0:${#res}-3} + targetJson="[" + + for pid in ${@:4} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + if [ $pid != "EMPTY" ]; then + targetJson=$targetJson"\"$pid\"" + fi + done + + targetJson=$targetJson"]" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + __log_test_fail_body + return 1 + fi + fi + + __log_test_pass + return 0 +} + +# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId} +# args: [ ] +# (Function for test scripts) +ecs_api_idc_get_job() { + __log_test_start $@ + + if [ $# -ne 2 ] && [ $# -ne 7 ]; then + __print_err " [ ]" $@ + return 1 + fi + query="/data-consumer/v1/info-jobs/$2" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + + if [ $# -eq 7 ]; then + body=${res:0:${#res}-3} + + if [ -f $7 ]; then + jobfile=$(cat $7) + jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") + else + __log_test_fail_general "Job template file "$6", does not exist" + return 1 + fi + targetJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + __log_test_fail_body + return 1 + fi + fi + + __log_test_pass + return 0 +} + + +# API Test function: PUT ​/data-consumer/v1/info-jobs/{infoJobId} +# args: [ VALIDATE ] +# (Function for test scripts) +ecs_api_idc_put_job() { + __log_test_start $@ + + if [ $# -lt 7 ] || [ $# -gt 8 ]; then + __print_err " [ VALIDATE ]" $@ + return 1 + fi + if [ -f $7 ]; then + jobfile=$(cat $7) + jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") + else + __log_test_fail_general "Job template file "$7", does not exist" + return 1 + fi + + inputJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}" + file="./tmp/.p.json" + echo "$inputJson" > $file + + query="/data-consumer/v1/info-jobs/$2" + + if [ $# -eq 8 ]; then + if [ $8 == "VALIDATE" ]; then + query=$query"?typeCheck=true" + fi + fi + + res="$(__do_curl_to_api ECS PUT $query $file)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + + __log_test_pass + return 0 +} + +# API Test function: DELETE ​/data-consumer/v1/info-jobs/{infoJobId} +# args: +# (Function for test scripts) +ecs_api_idc_delete_job() { + __log_test_start $@ + + if [ $# -ne 2 ]; then + __print_err " " $@ + return 1 + fi + query="/data-consumer/v1/info-jobs/$2" + res="$(__do_curl_to_api ECS DELETE $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + + __log_test_pass + return 0 +} + +# API Test function: GET ​/data-consumer/v1/info-types/{infoTypeId} +# args: [] +# (Function for test scripts) +ecs_api_idc_get_type() { + __log_test_start $@ + + if [ $# -lt 2 ] || [ $# -gt 3 ]; then + __print_err " []" $@ + return 1 + fi + + query="/data-consumer/v1/info-types/$2" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + + if [ $# -eq 3 ]; then + body=${res:0:${#res}-3} + if [ -f $3 ]; then + schema=$(cat $3) + else + __log_test_fail_general "Schema file "$3", does not exist" + return 1 + fi + targetJson="{\"job_data_schema\":$schema}" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + __log_test_fail_body + return 1 + fi + fi + + __log_test_pass + return 0 +} + +# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status +# args: [ []] +# (Function for test scripts) +ecs_api_idc_get_job_status() { + __log_test_start $@ + + if [ $# -lt 2 ] && [ $# -gt 4 ]; then + __print_err " [ []]" $@ + return 1 + fi + + query="/data-consumer/v1/info-jobs/$2/status" + + start=$SECONDS + for (( ; ; )); do + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $# -eq 4 ]; then + duration=$((SECONDS-start)) + echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}" + if [ $duration -gt $4 ]; then + echo "" + duration=-1 #Last iteration + fi + else + duration=-1 #single test, no wait + fi + + if [ $status -ne $1 ]; then + if [ $duration -eq -1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + fi + if [ $# -ge 3 ] && [ $status -eq $1 ]; then + body=${res:0:${#res}-3} + targetJson="{\"info_job_status\": \"$3\"}" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + if [ $duration -eq -1 ]; then + __log_test_fail_body + return 1 + fi + else + duration=-1 #Goto pass + fi + fi + if [ $duration -eq -1 ]; then + if [ $# -eq 4 ]; then + echo "" + fi + __log_test_pass + return 0 + else + sleep 1 + fi + done + + __log_test_pass + return 0 +} + ########################################## #### Reset jobs #### @@ -1565,7 +2127,7 @@ ecs_api_service_status() { # Function prefix: ecs_api_admin # Admin to remove all jobs -# args: +# args: [ ] # (Function for test scripts) ecs_api_admin_reset() { @@ -1606,6 +2168,25 @@ ecs_api_admin_reset() { fi done + __log_test_pass + return 0 +} + +########################################## +#### Reset jobs and producers #### +########################################## + + +# Admin reset to remove all data in ecs; jobs, producers etc +# NOTE - only works in kubernetes and the pod should not be running +# args: - +# (Function for test scripts) + +ecs_kube_pvc_reset() { + __log_test_start $@ + + __kube_clean_pvc $ECS_APP_NAME nonrtric enrichmentservice-pvc /var/enrichment-coordinator-service/database + __log_test_pass return 0 } \ No newline at end of file