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 specific test functions for A1 Controller API
22 # Generic function to query the RICs via the A1-controller API.
23 # args: <operation> <url> [<body>]
24 # <operation>: getA1Policy,putA1Policy,getA1PolicyType,deleteA1Policy,getA1PolicyStatus
25 # response: <json-body><3-digit-response-code>
26 # (Not for test scripts)
27 __do_curl_to_controller() {
28 echo " (${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
29 if [ $# -ne 2 ] && [ $# -ne 3 ]; then
31 echo "-Incorrect number of parameters to __do_curl_to_controller " $@ >> $HTTPLOG
32 echo "-Expected: <operation> <url> [<body>]" >> $HTTPLOG
33 echo "-Returning response 000" >> $HTTPLOG
38 json='{"input":{"near-rt-ric-url":"'$2'"}}'
40 # Escape quotes in the body
41 body=$(echo "$3" | sed 's/"/\\"/g')
42 json='{"input":{"near-rt-ric-url":"'$2'","body":"'"$body"'"}}'
44 payload="./tmp/.sdnc.payload.json"
45 echo "$json" > $payload
46 echo " FILE ($payload) : $json" >> $HTTPLOG
47 curlString="curl -skw %{http_code} -X POST $SDNC_HTTPX://$SDNC_USER:$SDNC_PWD@localhost:$SDNC_LOCAL_PORT$SDNC_API_URL$1 -H accept:application/json -H Content-Type:application/json --data-binary @$payload"
48 echo " CMD: "$curlString >> $HTTPLOG
51 echo " RESP: "$res >> $HTTPLOG
52 if [ $retcode -ne 0 ]; then
53 echo " RETCODE: "$retcode >> $HTTPLOG
58 status=${res:${#res}-3}
60 if [ $status -ne 200 ]; then
64 body=${res:0:${#res}-3}
65 echo " JSON: "$body >> $HTTPLOG
66 reply="./tmp/.sdnc-reply.json"
68 res=$(python3 ../common/extract_sdnc_reply.py $reply)
69 echo " EXTRACED BODY+CODE: "$res >> $HTTPLOG
74 # Controller API Test function: getA1Policy (return ids only)
75 # arg: <response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )
76 # (Function for test scripts)
77 controller_api_get_A1_policy_ids() {
78 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
79 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
83 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
84 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4/policies"
86 elif [ $# -gt 2 ] && [ $2 == "STD" ]; then
87 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/A1-P/v1/policies"
91 if [ $paramError -ne 0 ]; then
92 __print_err "<response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )" $@
96 res=$(__do_curl_to_controller getA1Policy "$url")
98 status=${res:${#res}-3}
100 if [ $? -ne 0 ]; then
101 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
103 __check_stop_at_error
107 if [ $status -ne $1 ]; then
108 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
110 __check_stop_at_error
113 body=${res:0:${#res}-3}
117 if [ $2 == "OSC" ]; then
120 for pid in ${@:$start} ; do
121 if [ "$targetJson" != "[" ]; then
122 targetJson=$targetJson","
124 targetJson=$targetJson"\"$UUID$pid\""
126 targetJson=$targetJson"]"
128 echo " TARGET JSON: $targetJson" >> $HTTPLOG
130 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
132 if [ $res -ne 0 ]; then
133 echo -e $RED" FAIL, returned body not correct"$ERED
135 __check_stop_at_error
140 echo -e $GREEN" PASS"$EGREEN
145 # Controller API Test function: getA1PolicyType
146 # arg: <response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]
147 # (Function for test scripts)
148 controller_api_get_A1_policy_type() {
149 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
150 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
154 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
155 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4"
159 if [ $paramError -ne 0 ]; then
160 __print_err "<response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]" $@
164 res=$(__do_curl_to_controller getA1PolicyType "$url")
166 status=${res:${#res}-3}
168 if [ $? -ne 0 ]; then
169 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
171 __check_stop_at_error
175 if [ $status -ne $1 ]; then
176 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
178 __check_stop_at_error
181 body=${res:0:${#res}-3}
183 if [ $# -eq 5 ]; then
185 body=${res:0:${#res}-3}
188 echo " TARGET JSON: $targetJson" >> $HTTPLOG
189 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
191 if [ $res -ne 0 ]; then
192 echo -e $RED" FAIL, returned body not correct"$ERED
194 __check_stop_at_error
200 echo -e $GREEN" PASS"$EGREEN
204 # Controller API Test function: deleteA1Policy
205 # arg: <response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)
206 # (Function for test scripts)
207 controller_api_delete_A1_policy() {
208 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
209 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
213 if [ $# -eq 5 ] && [ $2 == "OSC" ]; then
214 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
216 elif [ $# -eq 4 ] && [ $2 == "STD" ]; then
217 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
221 if [ $paramError -ne 0 ]; then
222 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
226 res=$(__do_curl_to_controller deleteA1Policy "$url")
228 status=${res:${#res}-3}
230 if [ $? -ne 0 ]; then
231 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
233 __check_stop_at_error
237 if [ $status -ne $1 ]; then
238 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
240 __check_stop_at_error
245 echo -e $GREEN" PASS"$EGREEN
249 # Controller API Test function: putA1Policy
250 # arg: <response-code> (STD <ric-id> <policy-id> <template-file> ) | (OSC <ric-id> <policy-type-id> <policy-id> <template-file>)
251 # (Function for test scripts)
252 controller_api_put_A1_policy() {
253 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
254 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
258 if [ $# -eq 6 ] && [ $2 == "OSC" ]; then
259 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
260 body=$(sed 's/XXX/'${5}'/g' $6)
263 elif [ $# -eq 5 ] && [ $2 == "STD" ]; then
264 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
265 body=$(sed 's/XXX/'${4}'/g' $5)
269 if [ $paramError -ne 0 ]; then
270 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
274 res=$(__do_curl_to_controller putA1Policy "$url" "$body")
276 status=${res:${#res}-3}
278 if [ $? -ne 0 ]; then
279 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
281 __check_stop_at_error
285 if [ $status -ne $1 ]; then
286 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
288 __check_stop_at_error
293 echo -e $GREEN" PASS"$EGREEN
298 # Controller API Test function: getA1PolicyStatus
299 # arg: <response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>)
300 # (Function for test scripts)
301 controller_api_get_A1_policy_status() {
302 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
303 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
308 if [ $# -ge 5 ] && [ $2 == "OSC" ]; then
309 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5/status"
310 if [ $# -gt 5 ]; then
311 targetJson="{\"instance_status\":\"$6\""
312 targetJson=$targetJson",\"has_been_deleted\":\"$7\""
313 targetJson=$targetJson",\"created_at\":\"????\"}"
316 elif [ $# -ge 4 ] && [ $2 == "STD" ]; then
317 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4/status"
318 if [ $# -gt 4 ]; then
319 targetJson="{\"enforceStatus\":\"$5\""
320 if [ $# -eq 6 ]; then
321 targetJson=$targetJson",\"reason\":\"$6\""
323 targetJson=$targetJson"}"
328 if [ $paramError -ne 0 ]; then
329 __print_err "<response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>)" $@
333 res=$(__do_curl_to_controller getA1PolicyStatus "$url")
335 status=${res:${#res}-3}
337 if [ $? -ne 0 ]; then
338 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
340 __check_stop_at_error
344 if [ $status -ne $1 ]; then
345 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
347 __check_stop_at_error
351 if [ ! -z "$targetJson" ]; then
353 body=${res:0:${#res}-3}
354 echo " TARGET JSON: $targetJson" >> $HTTPLOG
355 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
357 if [ $res -ne 0 ]; then
358 echo -e $RED" FAIL, returned body not correct"$ERED
360 __check_stop_at_error
366 echo -e $GREEN" PASS"$EGREEN