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 #######################################################
140 #Var to hold the current number of CR instances
144 # Set http as the protocol to use for all communication to the Dmaap adapter
146 # (Function for test scripts)
148 __cr_set_protocoll "http" $CR_INTERNAL_PORT $CR_EXTERNAL_PORT
151 # Set https as the protocol to use for all communication to the Dmaap adapter
153 # (Function for test scripts)
155 __cr_set_protocoll "https" $CR_INTERNAL_SECURE_PORT $CR_EXTERNAL_SECURE_PORT
158 # Setup paths to svc/container for internal and external access
159 # args: <protocol> <internal-port> <external-port>
160 __cr_set_protocoll() {
162 echo -e $BOLD"$CR_DISPLAY_NAME protocol setting"$EBOLD
163 echo -e " Using $BOLD http $EBOLD towards $CR_DISPLAY_NAME"
164 ## Access to Dmaap adapter
165 for ((CR_INSTANCE=0; CR_INSTANCE<$MAX_CR_APP_COUNT; CR_INSTANCE++ )); do
166 CR_DOCKER_INSTANCE=$(($CR_INSTANCE+1))
167 # CR_SERVICE_PATH is the base path to cr
168 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
169 __CR_SERVICE_PATH=$1"://"$CR_APP_NAME"_cr_"${CR_DOCKER_INSTANCE}":"$2 # docker access, container->container and script->container via proxy
171 __CR_SERVICE_PATH=$1"://"$CR_APP_NAME"-cr-"${CR_DOCKER_INSTANCE}":"$2 # docker access, container->container and script->container via proxy
173 if [ $RUNMODE == "KUBE" ]; then
174 __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
176 export CR_SERVICE_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH
177 # Service paths are used in test script to provide callbacck urls to app
178 export CR_SERVICE_MR_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH$CR_APP_CALLBACK_MR #Only for messages from dmaap adapter/mediator
179 export CR_SERVICE_TEXT_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH$CR_APP_CALLBACK_TEXT #Callbacks for text payload
180 export CR_SERVICE_APP_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH$CR_APP_CALLBACK #For general callbacks from apps
182 if [ $CR_INSTANCE -eq 0 ]; then
183 # CR_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
184 # CR_ADDAPTER need to be set before each call to CR....only set for instance 0 here
185 CR_ADAPTER_TYPE="REST"
186 CR_ADAPTER=$__CR_SERVICE_PATH
192 # Export env vars for config files, docker compose and kube resources
196 export CR_DISPLAY_NAME
198 export KUBE_SIM_NAMESPACE
199 export DOCKER_SIM_NWNAME
203 export CR_INTERNAL_PORT
204 export CR_INTERNAL_SECURE_PORT
205 export CR_EXTERNAL_PORT
206 export CR_EXTERNAL_SECURE_PORT
211 # Start the Callback reciver in the simulator group
213 # (Function for test scripts)
216 echo -e $BOLD"Starting $CR_DISPLAY_NAME"$EBOLD
218 if [ $# -ne 1 ]; then
219 echo -e $RED" Number of CR instances missing, usage: start_cr <app-count>"$ERED
222 if [ $1 -lt 1 ] || [ $1 -gt 10 ]; then
223 echo -e $RED" Number of CR shall be 1...10, usage: start_cr <app-count>"$ERED
226 export CR_APP_COUNT=$1
228 if [ $RUNMODE == "KUBE" ]; then
230 # Check if app shall be fully managed by the test script
231 __check_included_image "CR"
234 # Check if app shall only be used by the testscipt
235 __check_prestarted_image "CR"
238 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
239 echo -e $RED"The $CR_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
240 echo -e $RED"The $CR_APP_NAME will not be started"$ERED
243 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
244 echo -e $RED"The $CR_APP_NAME app is included both as managed and prestarted in this test script"$ERED
245 echo -e $RED"The $CR_APP_NAME will not be started"$ERED
249 # Check if app shall be used - not managed - by the test script
250 if [ $retcode_p -eq 0 ]; then
251 echo -e " Using existing $CR_APP_NAME deployment and service"
252 echo " Setting CR replicas=1"
253 __kube_scale deployment $CR_APP_NAME $KUBE_SIM_NAMESPACE 1
256 if [ $retcode_i -eq 0 ]; then
257 echo -e " Creating $CR_APP_NAME deployment and service"
261 __kube_create_namespace $KUBE_SIM_NAMESPACE
264 input_yaml=$SIM_GROUP"/"$CR_COMPOSE_DIR"/"svc.yaml
265 output_yaml=$PWD/tmp/cr_svc.yaml
266 __kube_create_instance service $CR_APP_NAME $input_yaml $output_yaml
269 input_yaml=$SIM_GROUP"/"$CR_COMPOSE_DIR"/"app.yaml
270 output_yaml=$PWD/tmp/cr_app.yaml
271 __kube_create_instance app $CR_APP_NAME $input_yaml $output_yaml
275 for ((CR_INSTANCE=0; CR_INSTANCE<$CR_APP_COUNT; CR_INSTANCE++ )); do
276 __dynvar="CR_SERVICE_PATH_"$CR_INSTANCE
277 __cr_app_name=$CR_APP_NAME"-"$CR_INSTANCE
278 __check_service_start $__cr_app_name ${!__dynvar}$CR_ALIVE_URL
279 result=$(__do_curl ${!__dynvar}/reset)
283 # Check if docker app shall be fully managed by the test script
284 __check_included_image 'CR'
285 if [ $? -eq 1 ]; then
286 echo -e $RED"The Callback Receiver app is not included in this test script"$ERED
287 echo -e $RED"The Callback Receiver will not be started"$ERED
295 while [ $cntr -le $CR_APP_COUNT ]; do
296 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
297 app=$CR_APP_NAME"_cr_"$cntr
299 app=$CR_APP_NAME"-cr-"$cntr
301 app_data="$app_data $app"
305 echo "COMPOSE_PROJECT_NAME="$CR_APP_NAME > $SIM_GROUP/$CR_COMPOSE_DIR/.env
307 __start_container $CR_COMPOSE_DIR "" NODOCKERARGS $CR_APP_COUNT $app_data
309 cntr=1 #Counter for docker instance, starts on 1
310 cntr2=0 #Couter for env var name, starts with 0 to be compablible with kube
311 while [ $cntr -le $CR_APP_COUNT ]; do
312 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
313 app=$CR_APP_NAME"_cr_"$cntr
315 app=$CR_APP_NAME"-cr-"$cntr
317 __dynvar="CR_SERVICE_PATH_"$cntr2
318 __check_service_start $app ${!__dynvar}$CR_ALIVE_URL
326 #Convert a cr path id to the value of the environment var holding the url
328 # returns: <base-url-to-the-app>
329 __cr_get_service_path(){
330 if [ $# -ne 1 ]; then
334 if [ $1 -lt 0 ] || [ $1 -ge $MAX_CR_APP_COUNT ]; then
338 __dynvar="CR_SERVICE_PATH_"$1
343 # Tests if a variable value in the CR is equal to a target value and and optional timeout.
344 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
345 # equal to the target or not.
346 # Arg: <cr-path-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
347 # before setting pass or fail depending on if the variable value becomes equal to the target
349 # (Function for test scripts)
351 if [ $# -eq 3 ] || [ $# -eq 4 ]; then
352 CR_SERVICE_PATH=$(__cr_get_service_path $1)
353 CR_ADAPTER=$CR_SERVICE_PATH
354 if [ $? -ne 0 ]; then
355 __print_err "<cr-path-id> missing or incorrect" $@
358 __var_test "CR" "$CR_SERVICE_PATH/counter/" $2 "=" $3 $4
360 __print_err "Wrong args to cr_equal, needs three or four args: <cr-path-id> <variable-name> <target-value> [ timeout ]" $@
364 # Tests if a variable value in the CR contains the target string and and optional timeout
365 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable contains
367 # Arg: <cr-path-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
368 # before setting pass or fail depending on if the variable value contains the target
370 # (Function for test scripts)
373 if [ $# -eq 3 ] || [ $# -eq 4 ]; then
374 CR_SERVICE_PATH=$(__cr_get_service_path $1)
375 CR_ADAPTER=$CR_SERVICE_PATH
376 if [ $? -ne 0 ]; then
377 __print_err "<cr-path-id> missing or incorrect" $@
380 __var_test "CR" "$CR_SERVICE_PATH/counter/" $2 "contain_str" $3 $4
383 __print_err "needs two or three args: <cr-path-id> <variable-name> <target-value> [ timeout ]"
388 # Read a variable value from CR sim and send to stdout. Arg: <variable-name>
390 CR_SERVICE_PATH=$(__cr_get_service_path $1)
391 CR_ADAPTER=$CR_SERVICE_PATH
392 if [ $? -ne 0 ]; then
393 __print_err "<cr-path-id> missing or incorrect" $@
396 echo "$(__do_curl $CR_SERVICE_PATH/counter/$1)"
399 # Function to configure write delay on callbacks
400 # Delay given in seconds.
401 # arg <response-code> <cr-path-id> <delay-in-sec>
402 # (Function for test scripts)
403 cr_delay_callback() {
406 if [ $# -ne 3 ]; then
407 __print_err "<response-code> <cr-path-id> <delay-in-sec>]" $@
411 CR_SERVICE_PATH=$(__cr_get_service_path $2)
412 CR_ADAPTER=$CR_SERVICE_PATH
413 if [ $? -ne 0 ]; then
414 __print_err "<cr-path-id> missing or incorrect" $@
418 res="$(__do_curl_to_api CR POST /forcedelay?delay=$3)"
419 status=${res:${#res}-3}
421 if [ $status -ne 200 ]; then
422 __log_conf_fail_status_code $1 $status
430 # CR API: Check the contents of all current ric sync events for one id from PMS
431 # <response-code> <cr-path-id> <id> [ EMPTY | ( <ric-id> )+ ]
432 # (Function for test scripts)
433 cr_api_check_all_sync_events() {
436 if [ "$PMS_VERSION" != "V2" ]; then
437 __log_test_fail_not_supported
441 if [ $# -lt 3 ]; then
442 __print_err "<response-code> <cr-path-id> <id> [ EMPTY | ( <ric-id> )+ ]" $@
446 CR_SERVICE_PATH=$(__cr_get_service_path $2)
447 CR_ADAPTER=$CR_SERVICE_PATH
448 if [ $? -ne 0 ]; then
449 __print_err "<cr-path-id> missing or incorrect" $@
453 query="/get-all-events/"$3
454 res="$(__do_curl_to_api CR GET $query)"
455 status=${res:${#res}-3}
457 if [ $status -ne $1 ]; then
458 __log_test_fail_status_code $1 $status
462 if [ $# -gt 3 ]; then
463 body=${res:0:${#res}-3}
464 if [ $# -eq 4 ] && [ $4 == "EMPTY" ]; then
470 for ((i=0; i<$(($#-3)); i=i+1)); do
472 if [ "$targetJson" != "[" ]; then
473 targetJson=$targetJson","
475 targetJson=$targetJson"{\"ric_id\":\"${arr[$i]}\",\"event_type\":\"AVAILABLE\"}"
479 targetJson=$targetJson"]"
480 echo "TARGET JSON: $targetJson" >> $HTTPLOG
481 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
483 if [ $res -ne 0 ]; then
492 # CR API: Check the contents of all current status events for one id from ECS
493 # <response-code> <cr-path-id> <id> [ EMPTY | ( <status> )+ ]
494 # (Function for test scripts)
495 cr_api_check_all_ecs_events() {
498 if [ $# -lt 3 ]; then
499 __print_err "<response-code> <cr-path-id> <id> [ EMPTY | ( <status> )+ ]" $@
503 CR_SERVICE_PATH=$(__cr_get_service_path $2)
504 CR_ADAPTER=$CR_SERVICE_PATH
505 if [ $? -ne 0 ]; then
506 __print_err "<cr-path-id> missing or incorrect" $@
510 query="/get-all-events/"$3
511 res="$(__do_curl_to_api CR GET $query)"
512 status=${res:${#res}-3}
514 if [ $status -ne $1 ]; then
515 __log_test_fail_status_code $1 $status
519 if [ $# -gt 3 ]; then
520 body=${res:0:${#res}-3}
521 if [ $# -eq 4 ] && [ $4 == "EMPTY" ]; then
527 for ((i=0; i<$(($#-3)); i=i+1)); do
529 if [ "$targetJson" != "[" ]; then
530 targetJson=$targetJson","
532 targetJson=$targetJson"{\"eiJobStatus\":\"${arr[$i]}\"}"
536 targetJson=$targetJson"]"
537 echo "TARGET JSON: $targetJson" >> $HTTPLOG
538 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
540 if [ $res -ne 0 ]; then
549 # CR API: Check the contents of all current type subscription events for one id from ECS
550 # <response-code> <cr-path-id> <id> [ EMPTY | ( <type-id> <schema> <registration-status> )+ ]
551 # (Function for test scripts)
552 cr_api_check_all_ecs_subscription_events() {
555 #Valid number of parameter 3,4,8,12
557 if [ $# -eq 3 ]; then
560 if [ $# -eq 4 ] && [ "$4" == "EMPTY" ]; then
563 variablecount=$(($#-3))
564 if [ $# -gt 4 ] && [ $(($variablecount%3)) -eq 0 ]; then
567 if [ $paramError -eq 1 ]; then
568 __print_err "<response-code> <cr-path-id> <id> [ EMPTY | ( <type-id> <schema> <registration-status> )+ ]" $@
572 CR_SERVICE_PATH=$(__cr_get_service_path $2)
573 CR_ADAPTER=$CR_SERVICE_PATH
574 if [ $? -ne 0 ]; then
575 __print_err "<cr-path-id> missing or incorrect" $@
579 query="/get-all-events/"$3
580 res="$(__do_curl_to_api CR GET $query)"
581 status=${res:${#res}-3}
583 if [ $status -ne $1 ]; then
584 __log_test_fail_status_code $1 $status
588 if [ $# -gt 3 ]; then
589 body=${res:0:${#res}-3}
591 if [ $# -gt 4 ]; then
593 for ((i=0; i<$(($#-4)); i=i+3)); do
594 if [ "$targetJson" != "[" ]; then
595 targetJson=$targetJson","
597 if [ -f ${arr[$i+1]} ]; then
598 jobfile=$(cat ${arr[$i+1]})
600 __log_test_fail_general "Job schema file "${arr[$i+1]}", does not exist"
603 targetJson=$targetJson"{\"info_type_id\":\"${arr[$i]}\",\"job_data_schema\":$jobfile,\"status\":\"${arr[$i+2]}\"}"
606 targetJson=$targetJson"]"
608 echo " TARGET JSON: $targetJson" >> $HTTPLOG
609 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
611 if [ $res -ne 0 ]; then
622 # CR API: Reset all events and counters
624 # (Function for test scripts)
628 if [ $# -ne 0 ]; then
629 __print_err "<cr-path-id>" $@
633 CR_SERVICE_PATH=$(__cr_get_service_path $1)
634 CR_ADAPTER=$CR_SERVICE_PATH
635 if [ $? -ne 0 ]; then
636 __print_err "<cr-path-id> missing or incorrect" $@
640 res="$(__do_curl_to_api CR GET /reset)"
641 status=${res:${#res}-3}
643 if [ $status -ne 200 ]; then
644 __log_conf_fail_status_code $1 $status
653 # CR API: Check the contents of all json events for path
654 # <response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg>+ )
655 # (Function for test scripts)
656 cr_api_check_all_genric_json_events() {
659 if [ $# -lt 4 ]; then
660 __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg>+ )" $@
664 CR_SERVICE_PATH=$(__cr_get_service_path $2)
665 CR_ADAPTER=$CR_SERVICE_PATH
666 if [ $? -ne 0 ]; then
667 __print_err "<cr-path-id> missing or incorrect" $@
671 query="/get-all-events/"$3
672 res="$(__do_curl_to_api CR GET $query)"
673 status=${res:${#res}-3}
675 if [ $status -ne $1 ]; then
676 __log_test_fail_status_code $1 $status
679 body=${res:0:${#res}-3}
682 if [ $4 != "EMPTY" ]; then
686 while [ $# -gt 0 ]; do
687 if [ "$targetJson" != "[" ]; then
688 targetJson=$targetJson","
690 targetJson=$targetJson$1
694 targetJson=$targetJson"]"
696 echo " TARGET JSON: $targetJson" >> $HTTPLOG
697 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
699 if [ $res -ne 0 ]; then
709 # CR API: Check a single (oldest) json event (or none if empty) for path
710 # <response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg> )
711 # (Function for test scripts)
712 cr_api_check_single_genric_json_event() {
715 if [ $# -ne 4 ]; then
716 __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg> )" $@
720 CR_SERVICE_PATH=$(__cr_get_service_path $2)
721 CR_ADAPTER=$CR_SERVICE_PATH
722 if [ $? -ne 0 ]; then
723 __print_err "<cr-path-id> missing or incorrect" $@
727 query="/get-event/"$3
728 res="$(__do_curl_to_api CR GET $query)"
729 status=${res:${#res}-3}
731 if [ $status -ne $1 ]; then
732 __log_test_fail_status_code $1 $status
735 body=${res:0:${#res}-3}
738 if [ $targetJson == "EMPTY" ] && [ ${#body} -ne 0 ]; then
742 echo " TARGET JSON: $targetJson" >> $HTTPLOG
743 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
745 if [ $res -ne 0 ]; then
754 # CR API: Check a single (oldest) json in md5 format (or none if empty) for path.
755 # Note that if a json message is given, it shall be compact, no ws except inside string.
756 # The MD5 will generate different hash if ws is present or not in otherwise equivalent json
757 # arg: <response-code> <cr-path-id> <topic-url> (EMPTY | <data-msg> )
758 # (Function for test scripts)
759 cr_api_check_single_genric_event_md5() {
762 if [ $# -ne 4 ]; then
763 __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <data-msg> )" $@
767 CR_SERVICE_PATH=$(__cr_get_service_path $2)
768 CR_ADAPTER=$CR_SERVICE_PATH
769 if [ $? -ne 0 ]; then
770 __print_err "<cr-path-id> missing or incorrect" $@
774 query="/get-event/"$3
775 res="$(__do_curl_to_api CR GET $query)"
776 status=${res:${#res}-3}
778 if [ $status -ne $1 ]; then
779 __log_test_fail_status_code $1 $status
782 body=${res:0:${#res}-3}
783 if [ $4 == "EMPTY" ]; then
784 if [ ${#body} -ne 0 ]; then
792 command -v md5 > /dev/null # Mac
793 if [ $? -eq 0 ]; then
794 targetMd5=$(echo -n "$4" | md5)
796 command -v md5sum > /dev/null # Linux
797 if [ $? -eq 0 ]; then
798 targetMd5=$(echo -n "$4" | md5sum | cut -d' ' -f 1) # Need to cut additional info printed by cmd
800 __log_test_fail_general "Command md5 nor md5sum is available"
804 targetMd5="\""$targetMd5"\"" #Quotes needed
806 echo " TARGET MD5 hash: $targetMd5" >> $HTTPLOG
808 if [ "$body" != "$targetMd5" ]; then
817 # CR API: Check a single (oldest) event in md5 format (or none if empty) for path.
818 # Note that if a file with json message is given, the json shall be compact, no ws except inside string and not newlines.
819 # The MD5 will generate different hash if ws/newlines is present or not in otherwise equivalent json
820 # arg: <response-code> <cr-path-id> <topic-url> (EMPTY | <data-file> )
821 # (Function for test scripts)
822 cr_api_check_single_genric_event_md5_file() {
825 if [ $# -ne 4 ]; then
826 __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <data-file> )" $@
830 CR_SERVICE_PATH=$(__cr_get_service_path $2)
831 CR_ADAPTER=$CR_SERVICE_PATH
832 if [ $? -ne 0 ]; then
833 __print_err "<cr-path-id> missing or incorrect" $@
837 query="/get-event/"$3
838 res="$(__do_curl_to_api CR GET $query)"
839 status=${res:${#res}-3}
841 if [ $status -ne $1 ]; then
842 __log_test_fail_status_code $1 $status
845 body=${res:0:${#res}-3}
846 if [ $4 == "EMPTY" ]; then
847 if [ ${#body} -ne 0 ]; then
857 __log_test_fail_general "File $3 does not exist"
863 command -v md5 > /dev/null # Mac
864 if [ $? -eq 0 ]; then
865 targetMd5=$(echo -n "$filedata" | md5)
867 command -v md5sum > /dev/null # Linux
868 if [ $? -eq 0 ]; then
869 targetMd5=$(echo -n "$filedata" | md5sum | cut -d' ' -f 1) # Need to cut additional info printed by cmd
871 __log_test_fail_general "Command md5 nor md5sum is available"
875 targetMd5="\""$targetMd5"\"" #Quotes needed
877 echo " TARGET MD5 hash: $targetMd5" >> $HTTPLOG
879 if [ "$body" != "$targetMd5" ]; then