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 managemnt functions test functions for the Callback Reciver
23 ################ Test engine functions ################
25 # Create the image var used during the test
26 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
27 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
29 __check_and_create_image_var CR "CR_IMAGE" "CR_IMAGE_BASE" "CR_IMAGE_TAG" LOCAL "$CR_DISPLAY_NAME"
32 # Pull image from remote repo or use locally built image
33 # arg: <pull-policy-override> <pull-policy-original>
34 # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
35 # <pull-policy-original> Shall be used for images that does not allow overriding
36 # Both var may contain: 'remote', 'remote-remove' or 'local'
38 echo -e $RED" Image for app CR shall never be pulled from remote repo"$ERED
41 # Build image (only for simulator or interfaces stubs owned by the test environment)
42 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
43 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
46 echo " Building CR - $CR_DISPLAY_NAME - image: $CR_IMAGE"
47 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $CR_IMAGE . &> .dockererr
49 echo -e $GREEN" Build Ok"$EGREEN
50 __retag_and_push_image CR_IMAGE
55 echo -e $RED" Build Failed"$ERED
58 echo -e $RED"Exiting...."$ERED
63 # Generate a string for each included image using the app display name and a docker images format string
64 # If a custom image repo is used then also the source image from the local repo is listed
65 # arg: <docker-images-format-string> <file-to-append>
67 echo -e "$CR_DISPLAY_NAME\t$(docker images --format $1 $CR_IMAGE)" >> $2
68 if [ ! -z "$CR_IMAGE_SOURCE" ]; then
69 echo -e "-- source image --\t$(docker images --format $1 $CR_IMAGE_SOURCE)" >> $2
73 # Scale kubernetes resources to zero
74 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
75 # This function is called for apps fully managed by the test script
76 __CR_kube_scale_zero() {
77 __kube_scale_all_resources $KUBE_SIM_NAMESPACE autotest CR
80 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
81 # This function is called for prestarted apps not managed by the test script.
82 __CR_kube_scale_zero_and_wait() {
83 echo -e $RED" CR app is not scaled in this state"$ERED
86 # Delete all kube resouces for the app
87 # This function is called for apps managed by the test script.
88 __CR_kube_delete_all() {
89 __kube_delete_all_resources $KUBE_SIM_NAMESPACE autotest CR
93 # This function is called for apps managed by the test script.
94 # args: <log-dir> <file-prexix>
95 __CR_store_docker_logs() {
96 if [ $RUNMODE == "KUBE" ]; then
97 for podname in $(kubectl get pods -n $KUBE_SIM_NAMESPACE -l "autotest=CR" -o custom-columns=":metadata.name"); do
98 kubectl logs -n $KUBE_SIM_NAMESPACE $podname --tail=-1 > $1$2_$podname.log 2>&1
101 crs=$(docker ps --filter "name=$CR_APP_NAME" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
103 docker logs $crid > $1$2_$crid.log 2>&1
108 # Initial setup of protocol, host and ports
109 # This function is called for apps managed by the test script.
111 __CR_initial_setup() {
115 # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
116 # For docker, the namespace shall be excluded
117 # This function is called for apps managed by the test script as well as for prestarted apps.
119 __CR_statisics_setup() {
120 for ((CR_INSTANCE=MAX_CR_APP_COUNT; CR_INSTANCE>0; CR_INSTANCE-- )); do
121 if [ $RUNMODE == "KUBE" ]; then
122 CR_INSTANCE_KUBE=$(($CR_INSTANCE-1))
123 echo -n " CR-$CR_INSTANCE_KUBE $CR_APP_NAME-$CR_INSTANCE_KUBE $KUBE_SIM_NAMESPACE "
125 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
126 echo -n " CR_$CR_INSTANCE ${CR_APP_NAME}_cr_$CR_INSTANCE "
128 echo -n " CR_$CR_INSTANCE ${CR_APP_NAME}-cr-$CR_INSTANCE "
134 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
136 __CR_test_requirements() {
140 #######################################################
146 #Var to hold the current number of CR instances
150 # Set http as the protocol to use for all communication to the Dmaap adapter
152 # (Function for test scripts)
154 __cr_set_protocoll "http" $CR_INTERNAL_PORT $CR_EXTERNAL_PORT
157 # Set https as the protocol to use for all communication to the Dmaap adapter
159 # (Function for test scripts)
161 __cr_set_protocoll "https" $CR_INTERNAL_SECURE_PORT $CR_EXTERNAL_SECURE_PORT
164 # Setup paths to svc/container for internal and external access
165 # args: <protocol> <internal-port> <external-port>
166 __cr_set_protocoll() {
168 echo -e $BOLD"$CR_DISPLAY_NAME protocol setting"$EBOLD
169 echo -e " Using $BOLD $1 $EBOLD towards $CR_DISPLAY_NAME"
170 ## Access to Dmaap adapter
171 for ((CR_INSTANCE=0; CR_INSTANCE<$MAX_CR_APP_COUNT; CR_INSTANCE++ )); do
172 CR_DOCKER_INSTANCE=$(($CR_INSTANCE+1))
173 # CR_SERVICE_PATH is the base path to cr
174 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
175 __CR_SERVICE_PATH=$1"://"$CR_APP_NAME"_cr_"${CR_DOCKER_INSTANCE}":"$2 # docker access, container->container and script->container via proxy
177 __CR_SERVICE_PATH=$1"://"$CR_APP_NAME"-cr-"${CR_DOCKER_INSTANCE}":"$2 # docker access, container->container and script->container via proxy
179 if [ $RUNMODE == "KUBE" ]; then
180 __CR_SERVICE_PATH=$1"://"$CR_APP_NAME"-"$CR_INSTANCE.$CR_APP_NAME"."$KUBE_SIM_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
182 export CR_SERVICE_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH
183 # Service paths are used in test script to provide callbacck urls to app
184 export CR_SERVICE_MR_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH$CR_APP_CALLBACK_MR #Only for messages from dmaap adapter/mediator
185 export CR_SERVICE_TEXT_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH$CR_APP_CALLBACK_TEXT #Callbacks for text payload
186 export CR_SERVICE_APP_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH$CR_APP_CALLBACK #For general callbacks from apps
188 if [ $CR_INSTANCE -eq 0 ]; then
189 # CR_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
190 # CR_ADDAPTER need to be set before each call to CR....only set for instance 0 here
191 CR_ADAPTER_TYPE="REST"
192 CR_ADAPTER=$__CR_SERVICE_PATH
198 # Export env vars for config files, docker compose and kube resources
202 export CR_DISPLAY_NAME
204 export KUBE_SIM_NAMESPACE
205 export DOCKER_SIM_NWNAME
209 export CR_INTERNAL_PORT
210 export CR_INTERNAL_SECURE_PORT
211 export CR_EXTERNAL_PORT
212 export CR_EXTERNAL_SECURE_PORT
217 # Start the Callback reciver in the simulator group
219 # (Function for test scripts)
222 echo -e $BOLD"Starting $CR_DISPLAY_NAME"$EBOLD
224 if [ $# -ne 1 ]; then
225 echo -e $RED" Number of CR instances missing, usage: start_cr <app-count>"$ERED
228 if [ $1 -lt 1 ] || [ $1 -gt 10 ]; then
229 echo -e $RED" Number of CR shall be 1...10, usage: start_cr <app-count>"$ERED
232 export CR_APP_COUNT=$1
234 if [ $RUNMODE == "KUBE" ]; then
236 # Check if app shall be fully managed by the test script
237 __check_included_image "CR"
240 # Check if app shall only be used by the testscipt
241 __check_prestarted_image "CR"
244 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
245 echo -e $RED"The $CR_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
246 echo -e $RED"The $CR_APP_NAME will not be started"$ERED
249 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
250 echo -e $RED"The $CR_APP_NAME app is included both as managed and prestarted in this test script"$ERED
251 echo -e $RED"The $CR_APP_NAME will not be started"$ERED
255 # Check if app shall be used - not managed - by the test script
256 if [ $retcode_p -eq 0 ]; then
257 echo -e " Using existing $CR_APP_NAME deployment and service"
258 echo " Setting CR replicas=1"
259 __kube_scale deployment $CR_APP_NAME $KUBE_SIM_NAMESPACE 1
262 if [ $retcode_i -eq 0 ]; then
263 echo -e " Creating $CR_APP_NAME deployment and service"
267 __kube_create_namespace $KUBE_SIM_NAMESPACE
270 input_yaml=$SIM_GROUP"/"$CR_COMPOSE_DIR"/"svc.yaml
271 output_yaml=$PWD/tmp/cr_svc.yaml
272 __kube_create_instance service $CR_APP_NAME $input_yaml $output_yaml
275 input_yaml=$SIM_GROUP"/"$CR_COMPOSE_DIR"/"app.yaml
276 output_yaml=$PWD/tmp/cr_app.yaml
277 __kube_create_instance app $CR_APP_NAME $input_yaml $output_yaml
281 for ((CR_INSTANCE=0; CR_INSTANCE<$CR_APP_COUNT; CR_INSTANCE++ )); do
282 __dynvar="CR_SERVICE_PATH_"$CR_INSTANCE
283 __cr_app_name=$CR_APP_NAME"-"$CR_INSTANCE
284 __check_service_start $__cr_app_name ${!__dynvar}$CR_ALIVE_URL
285 result=$(__do_curl ${!__dynvar}/reset)
289 # Check if docker app shall be fully managed by the test script
290 __check_included_image 'CR'
291 if [ $? -eq 1 ]; then
292 echo -e $RED"The Callback Receiver app is not included in this test script"$ERED
293 echo -e $RED"The Callback Receiver will not be started"$ERED
301 while [ $cntr -le $CR_APP_COUNT ]; do
302 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
303 app=$CR_APP_NAME"_cr_"$cntr
305 app=$CR_APP_NAME"-cr-"$cntr
307 app_data="$app_data $app"
311 echo "COMPOSE_PROJECT_NAME="$CR_APP_NAME > $SIM_GROUP/$CR_COMPOSE_DIR/.env
313 __start_container $CR_COMPOSE_DIR "" NODOCKERARGS $CR_APP_COUNT $app_data
315 cntr=1 #Counter for docker instance, starts on 1
316 cntr2=0 #Couter for env var name, starts with 0 to be compablible with kube
317 while [ $cntr -le $CR_APP_COUNT ]; do
318 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
319 app=$CR_APP_NAME"_cr_"$cntr
321 app=$CR_APP_NAME"-cr-"$cntr
323 __dynvar="CR_SERVICE_PATH_"$cntr2
324 __check_service_start $app ${!__dynvar}$CR_ALIVE_URL
332 #Convert a cr path id to the value of the environment var holding the url
334 # returns: <base-url-to-the-app>
335 __cr_get_service_path(){
336 if [ $# -ne 1 ]; then
340 if [ $1 -lt 0 ] || [ $1 -ge $MAX_CR_APP_COUNT ]; then
344 __dynvar="CR_SERVICE_PATH_"$1
349 # Tests if a variable value in the CR is equal to a target value and and optional timeout.
350 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
351 # equal to the target or not.
352 # Arg: <cr-path-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
353 # before setting pass or fail depending on if the variable value becomes equal to the target
355 # (Function for test scripts)
357 if [ $# -eq 3 ] || [ $# -eq 4 ]; then
358 CR_SERVICE_PATH=$(__cr_get_service_path $1)
359 CR_ADAPTER=$CR_SERVICE_PATH
360 if [ $? -ne 0 ]; then
361 __print_err "<cr-path-id> missing or incorrect" $@
364 __var_test "CR" "$CR_SERVICE_PATH/counter/" $2 "=" $3 $4
366 __print_err "Wrong args to cr_equal, needs three or four args: <cr-path-id> <variable-name> <target-value> [ timeout ]" $@
370 # Tests if a variable value in the CR contains the target string and and optional timeout
371 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable contains
373 # Arg: <cr-path-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
374 # before setting pass or fail depending on if the variable value contains the target
376 # (Function for test scripts)
379 if [ $# -eq 3 ] || [ $# -eq 4 ]; then
380 CR_SERVICE_PATH=$(__cr_get_service_path $1)
381 CR_ADAPTER=$CR_SERVICE_PATH
382 if [ $? -ne 0 ]; then
383 __print_err "<cr-path-id> missing or incorrect" $@
386 __var_test "CR" "$CR_SERVICE_PATH/counter/" $2 "contain_str" $3 $4
389 __print_err "needs two or three args: <cr-path-id> <variable-name> <target-value> [ timeout ]"
394 # Read a variable value from CR sim and send to stdout. Arg: <variable-name>
396 CR_SERVICE_PATH=$(__cr_get_service_path $1)
397 CR_ADAPTER=$CR_SERVICE_PATH
398 if [ $? -ne 0 ]; then
399 __print_err "<cr-path-id> missing or incorrect" $@
402 echo "$(__do_curl $CR_SERVICE_PATH/counter/$1)"
405 # Function to configure write delay on callbacks
406 # Delay given in seconds.
407 # arg <response-code> <cr-path-id> <delay-in-sec>
408 # (Function for test scripts)
409 cr_delay_callback() {
412 if [ $# -ne 3 ]; then
413 __print_err "<response-code> <cr-path-id> <delay-in-sec>]" $@
417 CR_SERVICE_PATH=$(__cr_get_service_path $2)
418 CR_ADAPTER=$CR_SERVICE_PATH
419 if [ $? -ne 0 ]; then
420 __print_err "<cr-path-id> missing or incorrect" $@
424 res="$(__do_curl_to_api CR POST /forcedelay?delay=$3)"
425 status=${res:${#res}-3}
427 if [ $status -ne 200 ]; then
428 __log_conf_fail_status_code $1 $status
436 # CR API: Check the contents of all current ric sync events for one id from PMS
437 # <response-code> <cr-path-id> <id> [ EMPTY | ( <ric-id> )+ ]
438 # (Function for test scripts)
439 cr_api_check_all_sync_events() {
442 if [ "$PMS_VERSION" != "V2" ]; then
443 __log_test_fail_not_supported
447 if [ $# -lt 3 ]; then
448 __print_err "<response-code> <cr-path-id> <id> [ EMPTY | ( <ric-id> )+ ]" $@
452 CR_SERVICE_PATH=$(__cr_get_service_path $2)
453 CR_ADAPTER=$CR_SERVICE_PATH
454 if [ $? -ne 0 ]; then
455 __print_err "<cr-path-id> missing or incorrect" $@
459 query="/get-all-events/"$3
460 res="$(__do_curl_to_api CR GET $query)"
461 status=${res:${#res}-3}
463 if [ $status -ne $1 ]; then
464 __log_test_fail_status_code $1 $status
468 if [ $# -gt 3 ]; then
469 body=${res:0:${#res}-3}
470 if [ $# -eq 4 ] && [ $4 == "EMPTY" ]; then
476 for ((i=0; i<$(($#-3)); i=i+1)); do
478 if [ "$targetJson" != "[" ]; then
479 targetJson=$targetJson","
481 targetJson=$targetJson"{\"ric_id\":\"${arr[$i]}\",\"event_type\":\"AVAILABLE\"}"
485 targetJson=$targetJson"]"
486 echo "TARGET JSON: $targetJson" >> $HTTPLOG
487 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
489 if [ $res -ne 0 ]; then
498 # CR API: Check the contents of all current status events for one id from ICS
499 # <response-code> <cr-path-id> <id> [ EMPTY | ( <status> )+ ]
500 # (Function for test scripts)
501 cr_api_check_all_ics_events() {
504 if [ $# -lt 3 ]; then
505 __print_err "<response-code> <cr-path-id> <id> [ EMPTY | ( <status> )+ ]" $@
509 CR_SERVICE_PATH=$(__cr_get_service_path $2)
510 CR_ADAPTER=$CR_SERVICE_PATH
511 if [ $? -ne 0 ]; then
512 __print_err "<cr-path-id> missing or incorrect" $@
516 query="/get-all-events/"$3
517 res="$(__do_curl_to_api CR GET $query)"
518 status=${res:${#res}-3}
520 if [ $status -ne $1 ]; then
521 __log_test_fail_status_code $1 $status
525 if [ $# -gt 3 ]; then
526 body=${res:0:${#res}-3}
527 if [ $# -eq 4 ] && [ $4 == "EMPTY" ]; then
533 for ((i=0; i<$(($#-3)); i=i+1)); do
535 if [ "$targetJson" != "[" ]; then
536 targetJson=$targetJson","
538 targetJson=$targetJson"{\"eiJobStatus\":\"${arr[$i]}\"}"
542 targetJson=$targetJson"]"
543 echo "TARGET JSON: $targetJson" >> $HTTPLOG
544 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
546 if [ $res -ne 0 ]; then
555 # CR API: Check the contents of all current type subscription events for one id from ICS
556 # <response-code> <cr-path-id> <id> [ EMPTY | ( <type-id> <schema> <registration-status> )+ ]
557 # (Function for test scripts)
558 cr_api_check_all_ics_subscription_events() {
561 #Valid number of parameter 3,4,8,12
563 if [ $# -eq 3 ]; then
566 if [ $# -eq 4 ] && [ "$4" == "EMPTY" ]; then
569 variablecount=$(($#-3))
570 if [ $# -gt 4 ] && [ $(($variablecount%3)) -eq 0 ]; then
573 if [ $paramError -eq 1 ]; then
574 __print_err "<response-code> <cr-path-id> <id> [ EMPTY | ( <type-id> <schema> <registration-status> )+ ]" $@
578 CR_SERVICE_PATH=$(__cr_get_service_path $2)
579 CR_ADAPTER=$CR_SERVICE_PATH
580 if [ $? -ne 0 ]; then
581 __print_err "<cr-path-id> missing or incorrect" $@
585 query="/get-all-events/"$3
586 res="$(__do_curl_to_api CR GET $query)"
587 status=${res:${#res}-3}
589 if [ $status -ne $1 ]; then
590 __log_test_fail_status_code $1 $status
594 if [ $# -gt 3 ]; then
595 body=${res:0:${#res}-3}
597 if [ $# -gt 4 ]; then
599 for ((i=0; i<$(($#-4)); i=i+3)); do
600 if [ "$targetJson" != "[" ]; then
601 targetJson=$targetJson","
603 if [ -f ${arr[$i+1]} ]; then
604 jobfile=$(cat ${arr[$i+1]})
606 __log_test_fail_general "Job schema file "${arr[$i+1]}", does not exist"
609 targetJson=$targetJson"{\"info_type_id\":\"${arr[$i]}\",\"job_data_schema\":$jobfile,\"status\":\"${arr[$i+2]}\"}"
612 targetJson=$targetJson"]"
614 echo " TARGET JSON: $targetJson" >> $HTTPLOG
615 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
617 if [ $res -ne 0 ]; then
628 # CR API: Reset all events and counters
630 # (Function for test scripts)
634 if [ $# -ne 1 ]; then
635 __print_err "<cr-path-id>" $@
639 CR_SERVICE_PATH=$(__cr_get_service_path $1)
640 CR_ADAPTER=$CR_SERVICE_PATH
641 if [ $? -ne 0 ]; then
642 __print_err "<cr-path-id> missing or incorrect" $@
646 res="$(__do_curl_to_api CR GET /reset)"
647 status=${res:${#res}-3}
649 if [ $status -ne 200 ]; then
650 __log_conf_fail_status_code $1 $status
659 # CR API: Check the contents of all json events for path
660 # <response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg>+ )
661 # (Function for test scripts)
662 cr_api_check_all_genric_json_events() {
665 if [ $# -lt 4 ]; then
666 __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg>+ )" $@
670 CR_SERVICE_PATH=$(__cr_get_service_path $2)
671 CR_ADAPTER=$CR_SERVICE_PATH
672 if [ $? -ne 0 ]; then
673 __print_err "<cr-path-id> missing or incorrect" $@
677 query="/get-all-events/"$3
678 res="$(__do_curl_to_api CR GET $query)"
679 status=${res:${#res}-3}
681 if [ $status -ne $1 ]; then
682 __log_test_fail_status_code $1 $status
685 body=${res:0:${#res}-3}
688 if [ $4 != "EMPTY" ]; then
692 while [ $# -gt 0 ]; do
693 if [ "$targetJson" != "[" ]; then
694 targetJson=$targetJson","
696 targetJson=$targetJson$1
700 targetJson=$targetJson"]"
702 echo " TARGET JSON: $targetJson" >> $HTTPLOG
703 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
705 if [ $res -ne 0 ]; then
715 # CR API: Check a single (oldest) json event (or none if empty) for path
716 # <response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg> )
717 # (Function for test scripts)
718 cr_api_check_single_genric_json_event() {
721 if [ $# -ne 4 ]; then
722 __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg> )" $@
726 CR_SERVICE_PATH=$(__cr_get_service_path $2)
727 CR_ADAPTER=$CR_SERVICE_PATH
728 if [ $? -ne 0 ]; then
729 __print_err "<cr-path-id> missing or incorrect" $@
733 query="/get-event/"$3
734 res="$(__do_curl_to_api CR GET $query)"
735 status=${res:${#res}-3}
737 if [ $status -ne $1 ]; then
738 __log_test_fail_status_code $1 $status
741 body=${res:0:${#res}-3}
744 if [ $targetJson == "EMPTY" ] && [ ${#body} -ne 0 ]; then
748 echo " TARGET JSON: $targetJson" >> $HTTPLOG
749 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
751 if [ $res -ne 0 ]; then
760 # CR API: Check a single (oldest) json in md5 format (or none if empty) for path.
761 # Note that if a json message is given, it shall be compact, no ws except inside string.
762 # The MD5 will generate different hash if ws is present or not in otherwise equivalent json
763 # arg: <response-code> <cr-path-id> <topic-url> (EMPTY | <data-msg> )
764 # (Function for test scripts)
765 cr_api_check_single_genric_event_md5() {
768 if [ $# -ne 4 ]; then
769 __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <data-msg> )" $@
773 CR_SERVICE_PATH=$(__cr_get_service_path $2)
774 CR_ADAPTER=$CR_SERVICE_PATH
775 if [ $? -ne 0 ]; then
776 __print_err "<cr-path-id> missing or incorrect" $@
780 query="/get-event/"$3
781 res="$(__do_curl_to_api CR GET $query)"
782 status=${res:${#res}-3}
784 if [ $status -ne $1 ]; then
785 __log_test_fail_status_code $1 $status
788 body=${res:0:${#res}-3}
789 if [ $4 == "EMPTY" ]; then
790 if [ ${#body} -ne 0 ]; then
798 command -v md5 > /dev/null # Mac
799 if [ $? -eq 0 ]; then
800 targetMd5=$(echo -n "$4" | md5)
802 command -v md5sum > /dev/null # Linux
803 if [ $? -eq 0 ]; then
804 targetMd5=$(echo -n "$4" | md5sum | cut -d' ' -f 1) # Need to cut additional info printed by cmd
806 __log_test_fail_general "Command md5 nor md5sum is available"
810 targetMd5="\""$targetMd5"\"" #Quotes needed
812 echo " TARGET MD5 hash: $targetMd5" >> $HTTPLOG
814 if [ "$body" != "$targetMd5" ]; then
823 # CR API: Check a single (oldest) event in md5 format (or none if empty) for path.
824 # Note that if a file with json message is given, the json shall be compact, no ws except inside string and not newlines.
825 # The MD5 will generate different hash if ws/newlines is present or not in otherwise equivalent json
826 # arg: <response-code> <cr-path-id> <topic-url> (EMPTY | <data-file> )
827 # (Function for test scripts)
828 cr_api_check_single_genric_event_md5_file() {
831 if [ $# -ne 4 ]; then
832 __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <data-file> )" $@
836 CR_SERVICE_PATH=$(__cr_get_service_path $2)
837 CR_ADAPTER=$CR_SERVICE_PATH
838 if [ $? -ne 0 ]; then
839 __print_err "<cr-path-id> missing or incorrect" $@
843 query="/get-event/"$3
844 res="$(__do_curl_to_api CR GET $query)"
845 status=${res:${#res}-3}
847 if [ $status -ne $1 ]; then
848 __log_test_fail_status_code $1 $status
851 body=${res:0:${#res}-3}
852 if [ $4 == "EMPTY" ]; then
853 if [ ${#body} -ne 0 ]; then
863 __log_test_fail_general "File $3 does not exist"
869 command -v md5 > /dev/null # Mac
870 if [ $? -eq 0 ]; then
871 targetMd5=$(echo -n "$filedata" | md5)
873 command -v md5sum > /dev/null # Linux
874 if [ $? -eq 0 ]; then
875 targetMd5=$(echo -n "$filedata" | md5sum | cut -d' ' -f 1) # Need to cut additional info printed by cmd
877 __log_test_fail_general "Command md5 nor md5sum is available"
881 targetMd5="\""$targetMd5"\"" #Quotes needed
883 echo " TARGET MD5 hash: $targetMd5" >> $HTTPLOG
885 if [ "$body" != "$targetMd5" ]; then