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 -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 @.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 " JSON: "$body >> $HTTPLOG
65 echo "$body" > .sdnc-reply.json
66 res=$(python3 ../common/extract_sdnc_reply.py .sdnc-reply.json)
67 echo " EXTRACED BODY+CODE: "$res >> $HTTPLOG
72 # Controller API Test function: getA1Policy (return ids only)
73 # arg: <response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )
74 # (Function for test scripts)
75 controller_api_get_A1_policy_ids() {
76 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
77 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
81 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
82 url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies"
84 elif [ $# -gt 2 ] && [ $2 == "STD" ]; then
85 url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies"
89 if [ $paramError -ne 0 ]; then
90 __print_err "<response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )" $@
94 res=$(__do_curl_to_controller getA1Policy "$url")
96 status=${res:${#res}-3}
99 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
104 if [ $status -ne $1 ]; then
105 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
109 body=${res:0:${#res}-3}
113 if [ $2 == "OSC" ]; then
116 for pid in ${@:$start} ; do
117 if [ "$targetJson" != "[" ]; then
118 targetJson=$targetJson","
120 targetJson=$targetJson"\"$pid\""
122 targetJson=$targetJson"]"
124 echo " TARGET JSON: $targetJson" >> $HTTPLOG
126 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
128 if [ $res -ne 0 ]; then
129 echo -e $RED" FAIL, returned body not correct"$ERED
135 echo -e $GREEN" PASS"$EGREEN
140 # Controller API Test function: getA1PolicyType
141 # arg: <response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]
142 # (Function for test scripts)
143 controller_api_get_A1_policy_type() {
144 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
145 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
149 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
150 url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4"
154 if [ $paramError -ne 0 ]; then
155 __print_err "<response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]" $@
159 res=$(__do_curl_to_controller getA1PolicyType "$url")
161 status=${res:${#res}-3}
163 if [ $? -ne 0 ]; then
164 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
169 if [ $status -ne $1 ]; then
170 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
174 body=${res:0:${#res}-3}
176 if [ $# -eq 5 ]; then
178 body=${res:0:${#res}-3}
181 echo " TARGET JSON: $targetJson" >> $HTTPLOG
182 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
184 if [ $res -ne 0 ]; then
185 echo -e $RED" FAIL, returned body not correct"$ERED
192 echo -e $GREEN" PASS"$EGREEN
196 # Controller API Test function: deleteA1Policy
197 # arg: <response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)
198 # (Function for test scripts)
199 controller_api_delete_A1_policy() {
200 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
201 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
205 if [ $# -eq 5 ] && [ $2 == "OSC" ]; then
206 url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies/$5"
208 elif [ $# -eq 4 ] && [ $2 == "STD" ]; then
209 url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies/$4"
213 if [ $paramError -ne 0 ]; then
214 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
218 res=$(__do_curl_to_controller deleteA1Policy "$url")
220 status=${res:${#res}-3}
222 if [ $? -ne 0 ]; then
223 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
228 if [ $status -ne $1 ]; then
229 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
235 echo -e $GREEN" PASS"$EGREEN
239 # Controller API Test function: putA1Policy
240 # arg: <response-code> (STD <ric-id> <policy-id> <template-file> ) | (OSC <ric-id> <policy-type-id> <policy-id> <template-file>)
241 # (Function for test scripts)
242 controller_api_put_A1_policy() {
243 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
244 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
248 if [ $# -eq 6 ] && [ $2 == "OSC" ]; then
249 url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies/$5"
250 body=$(sed 's/XXX/'${5}'/g' $6)
253 elif [ $# -eq 5 ] && [ $2 == "STD" ]; then
254 url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies/$4"
255 body=$(sed 's/XXX/'${4}'/g' $5)
259 if [ $paramError -ne 0 ]; then
260 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
264 res=$(__do_curl_to_controller putA1Policy "$url" "$body")
266 status=${res:${#res}-3}
268 if [ $? -ne 0 ]; then
269 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
274 if [ $status -ne $1 ]; then
275 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
281 echo -e $GREEN" PASS"$EGREEN
286 # Controller API Test function: getA1PolicyStatus
287 # arg: <response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>)
288 # (Function for test scripts)
289 controller_api_get_A1_policy_status() {
290 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
291 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
296 if [ $# -ge 5 ] && [ $2 == "OSC" ]; then
297 url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies/$5/status"
298 if [ $# -gt 5 ]; then
299 targetJson="{\"instance_status\":\"$6\""
300 targetJson=$targetJson",\"has_been_deleted\":\"$7\""
301 targetJson=$targetJson",\"created_at\":\"????\"}"
304 elif [ $# -ge 4 ] && [ $2 == "STD" ]; then
305 url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies/$4/status"
306 if [ $# -gt 4 ]; then
307 targetJson="{\"enforceStatus\":\"$5\""
308 if [ $# -eq 6 ]; then
309 targetJson=$targetJson",\"reason\":\"$6\""
311 targetJson=$targetJson"}"
316 if [ $paramError -ne 0 ]; then
317 __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>)" $@
321 res=$(__do_curl_to_controller getA1PolicyStatus "$url")
323 status=${res:${#res}-3}
325 if [ $? -ne 0 ]; then
326 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
331 if [ $status -ne $1 ]; then
332 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
337 if [ ! -z "$targetJson" ]; then
339 body=${res:0:${#res}-3}
340 echo " TARGET JSON: $targetJson" >> $HTTPLOG
341 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
343 if [ $res -ne 0 ]; then
344 echo -e $RED" FAIL, returned body not correct"$ERED
351 echo -e $GREEN" PASS"$EGREEN