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" > .sdnc.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 @.sdnc.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="$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}
99 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
101 __check_stop_at_error
105 if [ $status -ne $1 ]; then
106 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
108 __check_stop_at_error
111 body=${res:0:${#res}-3}
115 if [ $2 == "OSC" ]; then
118 for pid in ${@:$start} ; do
119 if [ "$targetJson" != "[" ]; then
120 targetJson=$targetJson","
122 targetJson=$targetJson"\"$UUID$pid\""
124 targetJson=$targetJson"]"
126 echo " TARGET JSON: $targetJson" >> $HTTPLOG
128 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
130 if [ $res -ne 0 ]; then
131 echo -e $RED" FAIL, returned body not correct"$ERED
133 __check_stop_at_error
138 echo -e $GREEN" PASS"$EGREEN
143 # Controller API Test function: getA1PolicyType
144 # arg: <response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]
145 # (Function for test scripts)
146 controller_api_get_A1_policy_type() {
147 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
148 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
152 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
153 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4"
157 if [ $paramError -ne 0 ]; then
158 __print_err "<response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]" $@
162 res=$(__do_curl_to_controller getA1PolicyType "$url")
164 status=${res:${#res}-3}
166 if [ $? -ne 0 ]; then
167 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
169 __check_stop_at_error
173 if [ $status -ne $1 ]; then
174 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
176 __check_stop_at_error
179 body=${res:0:${#res}-3}
181 if [ $# -eq 5 ]; then
183 body=${res:0:${#res}-3}
186 echo " TARGET JSON: $targetJson" >> $HTTPLOG
187 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
189 if [ $res -ne 0 ]; then
190 echo -e $RED" FAIL, returned body not correct"$ERED
192 __check_stop_at_error
198 echo -e $GREEN" PASS"$EGREEN
202 # Controller API Test function: deleteA1Policy
203 # arg: <response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)
204 # (Function for test scripts)
205 controller_api_delete_A1_policy() {
206 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
207 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
211 if [ $# -eq 5 ] && [ $2 == "OSC" ]; then
212 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
214 elif [ $# -eq 4 ] && [ $2 == "STD" ]; then
215 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
219 if [ $paramError -ne 0 ]; then
220 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
224 res=$(__do_curl_to_controller deleteA1Policy "$url")
226 status=${res:${#res}-3}
228 if [ $? -ne 0 ]; then
229 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
231 __check_stop_at_error
235 if [ $status -ne $1 ]; then
236 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
238 __check_stop_at_error
243 echo -e $GREEN" PASS"$EGREEN
247 # Controller API Test function: putA1Policy
248 # arg: <response-code> (STD <ric-id> <policy-id> <template-file> ) | (OSC <ric-id> <policy-type-id> <policy-id> <template-file>)
249 # (Function for test scripts)
250 controller_api_put_A1_policy() {
251 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
252 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
256 if [ $# -eq 6 ] && [ $2 == "OSC" ]; then
257 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
258 body=$(sed 's/XXX/'${5}'/g' $6)
261 elif [ $# -eq 5 ] && [ $2 == "STD" ]; then
262 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
263 body=$(sed 's/XXX/'${4}'/g' $5)
267 if [ $paramError -ne 0 ]; then
268 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
272 res=$(__do_curl_to_controller putA1Policy "$url" "$body")
274 status=${res:${#res}-3}
276 if [ $? -ne 0 ]; then
277 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
279 __check_stop_at_error
283 if [ $status -ne $1 ]; then
284 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
286 __check_stop_at_error
291 echo -e $GREEN" PASS"$EGREEN
296 # Controller API Test function: getA1PolicyStatus
297 # arg: <response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>)
298 # (Function for test scripts)
299 controller_api_get_A1_policy_status() {
300 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
301 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
306 if [ $# -ge 5 ] && [ $2 == "OSC" ]; then
307 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5/status"
308 if [ $# -gt 5 ]; then
309 targetJson="{\"instance_status\":\"$6\""
310 targetJson=$targetJson",\"has_been_deleted\":\"$7\""
311 targetJson=$targetJson",\"created_at\":\"????\"}"
314 elif [ $# -ge 4 ] && [ $2 == "STD" ]; then
315 url="$RIC_SIM_HTTPX://$3:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4/status"
316 if [ $# -gt 4 ]; then
317 targetJson="{\"enforceStatus\":\"$5\""
318 if [ $# -eq 6 ]; then
319 targetJson=$targetJson",\"reason\":\"$6\""
321 targetJson=$targetJson"}"
326 if [ $paramError -ne 0 ]; then
327 __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>)" $@
331 res=$(__do_curl_to_controller getA1PolicyStatus "$url")
333 status=${res:${#res}-3}
335 if [ $? -ne 0 ]; then
336 echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
338 __check_stop_at_error
342 if [ $status -ne $1 ]; then
343 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
345 __check_stop_at_error
349 if [ ! -z "$targetJson" ]; then
351 body=${res:0:${#res}-3}
352 echo " TARGET JSON: $targetJson" >> $HTTPLOG
353 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
355 if [ $res -ne 0 ]; then
356 echo -e $RED" FAIL, returned body not correct"$ERED
358 __check_stop_at_error
364 echo -e $GREEN" PASS"$EGREEN