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 echo "$json" > .sndc.payload.json
45 echo " FILE: $json" >> $HTTPLOG
46 curlString="curl -sw %{http_code} -X POST http://$SDNC_USER:$SDNC_PWD@localhost:$SDNC_EXTERNAL_PORT$SDNC_API_URL$1 -H accept:application/json -H Content-Type:application/json --data-binary @.sndc.payload.json"
47 echo " CMD: "$curlString >> $HTTPLOG
50 echo " RESP: "$res >> $HTTPLOG
51 if [ $retcode -ne 0 ]; then
52 echo " RETCODE: "$retcode >> $HTTPLOG
57 status=${res:${#res}-3}
59 if [ $status -ne 200 ]; then
63 body=${res:0:${#res}-3}
64 echo "$body" > .sdnc-reply.json
65 res=$(python ../common/extract_sdnc_reply.py .sdnc-reply.json)
66 echo " EXTRACED BODY+CODE: "$res >> $HTTPLOG
71 # Controller API Test function: getA1Policy (return ids only)
72 # arg: <response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )
73 # (Function for test scripts)
74 controller_api_get_A1_policy_ids() {
75 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
76 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
80 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
81 url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies"
83 elif [ $# -gt 2 ] && [ $2 == "STD" ]; then
84 url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies"
88 if [ $paramError -ne 0 ]; then
89 __print_err "<response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )" $@
93 res=$(__do_curl_to_controller getA1Policy "$url")
95 status=${res:${#res}-3}
98 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
103 if [ $status -ne $1 ]; then
104 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
108 body=${res:0:${#res}-3}
112 if [ $2 == "OSC" ]; then
115 for pid in ${@:$start} ; do
116 if [ "$targetJson" != "[" ]; then
117 targetJson=$targetJson","
119 targetJson=$targetJson"\"$pid\""
121 targetJson=$targetJson"]"
123 echo " TARGET JSON: $targetJson" >> $HTTPLOG
125 res=$(python ../common/compare_json.py "$targetJson" "$body")
127 if [ $res -ne 0 ]; then
128 echo -e $RED" FAIL, returned body not correct"$ERED
134 echo -e $GREEN" PASS"$EGREEN
139 # Controller API Test function: getA1PolicyType
140 # arg: <response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]
141 # (Function for test scripts)
142 controller_api_get_A1_policy_type() {
143 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
144 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
148 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
149 url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4"
153 if [ $paramError -ne 0 ]; then
154 __print_err "<response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]" $@
158 res=$(__do_curl_to_controller getA1PolicyType "$url")
160 status=${res:${#res}-3}
162 if [ $? -ne 0 ]; then
163 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
168 if [ $status -ne $1 ]; then
169 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
173 body=${res:0:${#res}-3}
175 if [ $# -eq 5 ]; then
177 body=${res:0:${#res}-3}
180 echo " TARGET JSON: $targetJson" >> $HTTPLOG
181 res=$(python ../common/compare_json.py "$targetJson" "$body")
183 if [ $res -ne 0 ]; then
184 echo -e $RED" FAIL, returned body not correct"$ERED
191 echo -e $GREEN" PASS"$EGREEN
195 # Controller API Test function: deleteA1Policy
196 # arg: <response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)
197 # (Function for test scripts)
198 controller_api_delete_A1_policy() {
199 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
200 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
204 if [ $# -eq 5 ] && [ $2 == "OSC" ]; then
205 url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies/$5"
207 elif [ $# -eq 4 ] && [ $2 == "STD" ]; then
208 url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies/$4"
212 if [ $paramError -ne 0 ]; then
213 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
217 res=$(__do_curl_to_controller deleteA1Policy "$url")
219 status=${res:${#res}-3}
221 if [ $? -ne 0 ]; then
222 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
227 if [ $status -ne $1 ]; then
228 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
234 echo -e $GREEN" PASS"$EGREEN
238 # Controller API Test function: putA1Policy
239 # arg: <response-code> (STD <ric-id> <policy-id> <template-file> ) | (OSC <ric-id> <policy-type-id> <policy-id> <template-file>)
240 # (Function for test scripts)
241 controller_api_put_A1_policy() {
242 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
243 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
247 if [ $# -eq 6 ] && [ $2 == "OSC" ]; then
248 url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies/$5"
249 body=$(sed 's/XXX/'${5}'/g' $6)
252 elif [ $# -eq 5 ] && [ $2 == "STD" ]; then
253 url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies/$4"
254 body=$(sed 's/XXX/'${4}'/g' $5)
258 if [ $paramError -ne 0 ]; then
259 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
263 res=$(__do_curl_to_controller putA1Policy "$url" "$body")
265 status=${res:${#res}-3}
267 if [ $? -ne 0 ]; then
268 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
273 if [ $status -ne $1 ]; then
274 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
280 echo -e $GREEN" PASS"$EGREEN
285 # Controller API Test function: getA1PolicyStatus
286 # arg: <response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>)
287 # (Function for test scripts)
288 controller_api_get_A1_policy_status() {
289 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
290 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
295 if [ $# -ge 5 ] && [ $2 == "OSC" ]; then
296 url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies/$5/status"
297 if [ $# -gt 5 ]; then
298 targetJson="{\"instance_status\":\"$6\""
299 targetJson=$targetJson",\"has_been_deleted\":\"$7\""
300 targetJson=$targetJson",\"created_at\":\"????\"}"
303 elif [ $# -ge 4 ] && [ $2 == "STD" ]; then
304 url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies/$4/status"
305 if [ $# -gt 4 ]; then
306 targetJson="{\"enforceStatus\":\"$5\""
307 if [ $# -eq 6 ]; then
308 targetJson=$targetJson",\"reason\":\"$6\""
310 targetJson=$targetJson"}"
315 if [ $paramError -ne 0 ]; then
316 __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>)" $@
320 res=$(__do_curl_to_controller getA1PolicyStatus "$url")
322 status=${res:${#res}-3}
324 if [ $? -ne 0 ]; then
325 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
330 if [ $status -ne $1 ]; then
331 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
336 if [ ! -z "$targetJson" ]; then
338 body=${res:0:${#res}-3}
339 echo " TARGET JSON: $targetJson" >> $HTTPLOG
340 res=$(python ../common/compare_json.py "$targetJson" "$body")
342 if [ $res -ne 0 ]; then
343 echo -e $RED" FAIL, returned body not correct"$ERED
350 echo -e $GREEN" PASS"$EGREEN