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
61 __print_err "Wrong args to cr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
65 # CR API: Check the contents of all current ric sync events from PMS
66 # <response-code> <id> [ EMPTY | ( <ric-id> )+ ]
67 # (Function for test scripts)
68 cr_api_check_all_sync_events() {
69 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
70 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
73 if [ "$PMS_VERSION" != "V2" ]; then
74 echo -e $RED" FAIL, function not supported"$ERED
81 __print_err "<response-code> <id> [ EMPTY | ( <ric-id> )+ ]" $@
85 query="/get-all-events/"$2
86 res="$(__do_curl_to_api CR GET $query)"
87 status=${res:${#res}-3}
89 if [ $status -ne $1 ]; then
90 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
97 body=${res:0:${#res}-3}
98 if [ $# -eq 3 ] && [ $3 == "EMPTY" ]; then
104 for ((i=0; i<$(($#-2)); i=i+1)); do
106 if [ "$targetJson" != "[" ]; then
107 targetJson=$targetJson","
109 targetJson=$targetJson"{\"ric_id\":\"${arr[$i]}\",\"event_type\":\"AVAILABLE\"}"
113 targetJson=$targetJson"]"
114 echo "TARGET JSON: $targetJson" >> $HTTPLOG
115 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
117 if [ $res -ne 0 ]; then
118 echo -e $RED" FAIL, returned body not correct"$ERED
120 __check_stop_at_error
125 echo -e $GREEN" PASS"$EGREEN