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=================================================
21 ### Admin API functions for the RIC simulator
24 # Excute a curl cmd towards a ricsimulator and check the response code.
25 # args: <expected-response-code> <curl-cmd-string> [<file>]
26 __execute_curl_to_sim() {
27 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
28 echo " CMD: $2" >> $HTTPLOG
30 echo " FILE: $(<$3)" >> $HTTPLOG
33 echo " RESP: $res" >> $HTTPLOG
35 if [ $retcode -ne 0 ]; then
36 echo " RETCODE: "$retcode
37 echo -e $RED" FAIL - fatal error when executing curl."$ERED
40 status=${res:${#res}-3}
41 if [ $status -eq $1 ]; then
42 echo -e $GREEN" OK"$EGREEN
45 echo -e $RED" FAIL - expected http response: "$1" but got http response: "$status $ERED
49 # Tests if a variable value in the ricsimulator is equal to a target value and and optional timeout.
50 # Arg: <ric-id> <variable-name> <target-value> - This test set pass or fail depending on if the variable is
51 # equal to the target or not.
52 # Arg: <ric-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
53 # before setting pass or fail depending on if the variable value becomes equal to the target
55 # (Function for test scripts)
58 if [ $# -eq 3 ] || [ $# -eq 4 ]; then
60 port=$(__find_sim_port $app)
61 __var_test $app "$RIC_SIM_LOCALHOST$port/counter/" $2 "=" $3 $4
65 __print_err "needs three or four args: <ric-id> <sim-param> <target-value> [ timeout ]"
70 # Print a variable value from the RIC sim.
71 # args: <ric-id> <variable-name>
72 # (Function for test scripts)
77 __print_err "need two args, <ric-id> <sim-param>" $@
81 port=$(__find_sim_port $app)
82 echo -e $BOLD"INFO(${BASH_LINENO[0]}): $app, $2 = $(__do_curl $RIC_SIM_LOCALHOST$port/counter/$2)"$EBOLD
85 # Tests if a variable value in the RIC simulator contains the target string and and optional timeout
86 # Arg: <ric-id> <variable-name> <target-value> - This test set pass or fail depending on if the variable contains
88 # Arg: <ric-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
89 # before setting pass or fail depending on if the variable value contains the target
91 # (Function for test scripts)
94 if [ $# -eq 3 ] || [ $# -eq 4 ]; then
96 port=$(__find_sim_port $app)
97 __var_test $app "$RIC_SIM_LOCALHOST$port/counter/" $2 "contain_str" $3 $4
101 __print_err "needs three or four args: <ric-id> <sim-param> <target-value> [ timeout ]"
106 # Simulator API: Put a policy type in a ric
107 # args: <response-code> <ric-id> <policy-type-id> <policy-type-file>
108 # (Function for test scripts)
109 sim_put_policy_type() {
110 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
111 if [ $# -ne 4 ]; then
113 __print_err "<response-code> <ric-id> <policy-type-id> <policy-type-file>" $@
117 res=$(__find_sim_port $app)
119 curlString="curl -X PUT -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/policytype?id="$3" -H Content-Type:application/json --data-binary @"$4
121 __execute_curl_to_sim $1 "$curlString" $4
125 # DSimulator API: Delete a policy type in a ric
126 # <response-code> <ric-id> <policy-type-id>
127 # (Function for test scripts)
128 sim_delete_policy_type() {
129 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
130 if [ $# -ne 3 ]; then
132 __print_err "<response-code> <ric-id> <policy_type_id>" $@
136 res=$(__find_sim_port $app)
138 curlString="curl -X DELETE -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/policytype?id="$3
140 __execute_curl_to_sim $1 "$curlString"
144 # Simulator API: Delete instances (and status), for one ric
145 # <response-code> <ric-id>
146 # (Function for test scripts)
147 sim_post_delete_instances() {
148 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
149 if [ $# -ne 2 ]; then
151 __print_err "<response-code> <ric-id>" $@
155 res=$(__find_sim_port $app)
157 curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/deleteinstances"
159 __execute_curl_to_sim $1 "$curlString"
163 # Simulator API: Delete all (instances/types/statuses/settings), for one ric
164 # <response-code> <ric-id>
165 # (Function for test scripts)
166 sim_post_delete_all() {
167 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
168 if [ $# -ne 3 ]; then
170 __print_err "<response-code> <numericic-id>" $@
174 res=$(__find_sim_port $app)
176 curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/deleteall"
178 __execute_curl_to_sim $1 "$curlString"
182 # Simulator API: Set (or reset) response code for next A1 message, for one ric
183 # <response-code> <ric-id> [<forced_response_code>]
184 # (Function for test scripts)
185 sim_post_forcedresponse() {
186 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
187 if [ $# -ne 3 ]; then
189 __print_err "<response-code> <ric-id> <forced_response_code>" $@
193 res=$(__find_sim_port $app)
195 curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/forceresponse"
196 if [ $# -eq 3 ]; then
197 curlString=$curlString"?code="$3
200 __execute_curl_to_sim $1 "$curlString"
204 # Simulator API: Set (or reset) A1 response delay, for one ric
205 # <response-code> <ric-id> [<delay-in-seconds>]
206 # (Function for test scripts)
207 sim_post_forcedelay() {
208 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
209 if [ $# -ne 3 ]; then
211 __print_err "<response-code> <ric-id> [<delay-in-seconds>]" $@
215 res=$(__find_sim_port $app)
217 curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST$res/delay"
218 if [ $# -eq 3 ]; then
219 curlString=$curlString"?delay="$3
222 __execute_curl_to_sim $1 "$curlString"