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 . ../common/api_curl.sh
22 ### Admin API functions for the Callback Reciver
25 # Excute a curl cmd towards a Callback Reciver admin interface and check the response code.
26 # args: <expected-response-code> <curl-cmd-string>
27 __execute_curl_to_cr() {
28 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
29 echo " CMD: $2" >> $HTTPLOG
31 echo " RESP: $res" >> $HTTPLOG
33 if [ $retcode -ne 0 ]; then
35 echo " RETCODE: "$retcode
36 echo -e $RED" FAIL - fatal error when executing curl."$ERED
39 status=${res:${#res}-3}
40 if [ $status -eq $1 ]; then
41 echo -e $GREEN" OK"$EGREEN
44 echo -e $RED" FAIL - expected http response: "$1" but got http response: "$status $ERED
49 # Tests if a variable value in the CR is equal to a target value and and optional timeout.
50 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
51 # equal to the target or not.
52 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
53 # before setting pass or fail depending on if the variable value becomes equal to the target
55 # (Function for test scripts)
57 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
58 __var_test "CR" "$LOCALHOST$CR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
60 __print_err "Wrong args to cr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
64 # CR API: Check the contents of all current ric sync events for one id from PMS
65 # <response-code> <id> [ EMPTY | ( <ric-id> )+ ]
66 # (Function for test scripts)
67 cr_api_check_all_sync_events() {
70 if [ "$PMS_VERSION" != "V2" ]; then
71 __log_test_fail_not_supported
76 __print_err "<response-code> <id> [ EMPTY | ( <ric-id> )+ ]" $@
80 query="/get-all-events/"$2
81 res="$(__do_curl_to_api CR GET $query)"
82 status=${res:${#res}-3}
84 if [ $status -ne $1 ]; then
85 __log_test_fail_status_code $1 $status
90 body=${res:0:${#res}-3}
91 if [ $# -eq 3 ] && [ $3 == "EMPTY" ]; then
97 for ((i=0; i<$(($#-2)); i=i+1)); do
99 if [ "$targetJson" != "[" ]; then
100 targetJson=$targetJson","
102 targetJson=$targetJson"{\"ric_id\":\"${arr[$i]}\",\"event_type\":\"AVAILABLE\"}"
106 targetJson=$targetJson"]"
107 echo "TARGET JSON: $targetJson" >> $HTTPLOG
108 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
110 if [ $res -ne 0 ]; then
119 # CR API: Check the contents of all current status events for one id from ECS
120 # <response-code> <id> [ EMPTY | ( <status> )+ ]
121 # (Function for test scripts)
122 cr_api_check_all_ecs_events() {
125 if [ $# -lt 2 ]; then
126 __print_err "<response-code> <id> [ EMPTY | ( <status> )+ ]" $@
130 query="/get-all-events/"$2
131 res="$(__do_curl_to_api CR GET $query)"
132 status=${res:${#res}-3}
134 if [ $status -ne $1 ]; then
135 __log_test_fail_status_code $1 $status
139 if [ $# -gt 2 ]; then
140 body=${res:0:${#res}-3}
141 if [ $# -eq 3 ] && [ $3 == "EMPTY" ]; then
147 for ((i=0; i<$(($#-2)); i=i+1)); do
149 if [ "$targetJson" != "[" ]; then
150 targetJson=$targetJson","
152 targetJson=$targetJson"{\"eiJobStatus\":\"${arr[$i]}\"}"
156 targetJson=$targetJson"]"
157 echo "TARGET JSON: $targetJson" >> $HTTPLOG
158 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
160 if [ $res -ne 0 ]; then