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() {
81 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
82 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4/policies"
84 elif [ $# -gt 2 ] && [ $2 == "STD" ]; then
85 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_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}
98 if [ $retcode -ne 0 ]; then
99 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
103 if [ $status -ne $1 ]; then
104 __log_test_fail_status_code $1 $status
107 body=${res:0:${#res}-3}
111 if [ $2 == "OSC" ]; then
114 for pid in ${@:$start} ; do
115 if [ "$targetJson" != "[" ]; then
116 targetJson=$targetJson","
118 targetJson=$targetJson"\"$UUID$pid\""
120 targetJson=$targetJson"]"
122 echo " TARGET JSON: $targetJson" >> $HTTPLOG
124 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
126 if [ $res -ne 0 ]; then
136 # Controller API Test function: getA1PolicyType
137 # arg: <response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]
138 # (Function for test scripts)
139 controller_api_get_A1_policy_type() {
143 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
144 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4"
148 if [ $paramError -ne 0 ]; then
149 __print_err "<response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]" $@
153 res=$(__do_curl_to_controller getA1PolicyType "$url")
155 status=${res:${#res}-3}
157 if [ $retcode -ne 0 ]; then
158 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
162 if [ $status -ne $1 ]; then
163 __log_test_fail_status_code $1 $status
166 body=${res:0:${#res}-3}
168 if [ $# -eq 5 ]; then
170 body=${res:0:${#res}-3}
173 echo " TARGET JSON: $targetJson" >> $HTTPLOG
174 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
176 if [ $res -ne 0 ]; then
186 # Controller API Test function: deleteA1Policy
187 # arg: <response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)
188 # (Function for test scripts)
189 controller_api_delete_A1_policy() {
193 if [ $# -eq 5 ] && [ $2 == "OSC" ]; then
194 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
196 elif [ $# -eq 4 ] && [ $2 == "STD" ]; then
197 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
201 if [ $paramError -ne 0 ]; then
202 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
206 res=$(__do_curl_to_controller deleteA1Policy "$url")
208 status=${res:${#res}-3}
210 if [ $retcode -ne 0 ]; then
211 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
215 if [ $status -ne $1 ]; then
216 __log_test_fail_status_code $1 $status
224 # Controller API Test function: putA1Policy
225 # arg: <response-code> (STD <ric-id> <policy-id> <template-file> ) | (OSC <ric-id> <policy-type-id> <policy-id> <template-file>)
226 # (Function for test scripts)
227 controller_api_put_A1_policy() {
231 if [ $# -eq 6 ] && [ $2 == "OSC" ]; then
232 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
233 body=$(sed 's/XXX/'${5}'/g' $6)
236 elif [ $# -eq 5 ] && [ $2 == "STD" ]; then
237 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
238 body=$(sed 's/XXX/'${4}'/g' $5)
242 if [ $paramError -ne 0 ]; then
243 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
247 res=$(__do_curl_to_controller putA1Policy "$url" "$body")
249 status=${res:${#res}-3}
251 if [ $retcode -ne 0 ]; then
252 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
256 if [ $status -ne $1 ]; then
257 __log_test_fail_status_code $1 $status
266 # Controller API Test function: getA1PolicyStatus
267 # arg: <response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>)
268 # (Function for test scripts)
269 controller_api_get_A1_policy_status() {
274 if [ $# -ge 5 ] && [ $2 == "OSC" ]; then
275 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5/status"
276 if [ $# -gt 5 ]; then
277 targetJson="{\"instance_status\":\"$6\""
278 targetJson=$targetJson",\"has_been_deleted\":\"$7\""
279 targetJson=$targetJson",\"created_at\":\"????\"}"
282 elif [ $# -ge 4 ] && [ $2 == "STD" ]; then
283 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4/status"
284 if [ $# -gt 4 ]; then
285 targetJson="{\"enforceStatus\":\"$5\""
286 if [ $# -eq 6 ]; then
287 targetJson=$targetJson",\"reason\":\"$6\""
289 targetJson=$targetJson"}"
294 if [ $paramError -ne 0 ]; then
295 __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>)" $@
299 res=$(__do_curl_to_controller getA1PolicyStatus "$url")
301 status=${res:${#res}-3}
303 if [ $retcode -ne 0 ]; then
304 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
308 if [ $status -ne $1 ]; then
309 __log_test_fail_status_code $1 $status
313 if [ ! -z "$targetJson" ]; then
315 body=${res:0:${#res}-3}
316 echo " TARGET JSON: $targetJson" >> $HTTPLOG
317 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
319 if [ $res -ne 0 ]; then