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>
26 __execute_curl_to_sim() {
27 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
28 echo " CMD: $2" >> $HTTPLOG
30 echo " RESP: $res" >> $HTTPLOG
32 if [ $retcode -ne 0 ]; then
33 echo " RETCODE: "$retcode
34 echo -e $RED" FAIL - fatal error when executing curl."$ERED
37 status=${res:${#res}-3}
38 if [ $status -eq $1 ]; then
39 echo -e $GREEN" OK"$EGREEN
42 echo -e $RED" FAIL - expected http response: "$1" but got http response: "$status $ERED
46 # Tests if a variable value in the ricsimulator is equal to a target value and and optional timeout.
47 # Arg: <ric-id> <variable-name> <target-value> - This test set pass or fail depending on if the variable is
48 # equal to the target or not.
49 # Arg: <ric-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
50 # before setting pass or fail depending on if the variable value becomes equal to the target
52 # (Function for test scripts)
55 if [ $# -eq 3 ] || [ $# -eq 4 ]; then
57 port=$(__find_sim_port $app)
58 __var_test $app "$RIC_SIM_LOCALHOST$port/counter/" $2 "=" $3 $4
62 __print_err "needs three or four args: <ric-id> <sim-param> <target-value> [ timeout ]"
67 # Print a variable value from the RIC sim.
68 # args: <ric-id> <variable-name>
69 # (Function for test scripts)
74 __print_err "need two args, <ric-id> <sim-param>" $@
78 port=$(__find_sim_port $app)
79 echo -e $BOLD"INFO(${BASH_LINENO[0]}): $app, $2 = $(__do_curl $RIC_SIM_LOCALHOST$port/counter/$2)"$EBOLD
82 # Tests if a variable value in the RIC simulator contains the target string and and optional timeout
83 # Arg: <ric-id> <variable-name> <target-value> - This test set pass or fail depending on if the variable contains
85 # Arg: <ric-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
86 # before setting pass or fail depending on if the variable value contains the target
88 # (Function for test scripts)
91 if [ $# -eq 3 ] || [ $# -eq 4 ]; then
93 port=$(__find_sim_port $app)
94 __var_test $app "$RIC_SIM_LOCALHOST$port/counter/" $2 "contain_str" $3 $4
98 __print_err "needs three or four args: <ric-id> <sim-param> <target-value> [ timeout ]"
103 # Simulator API: Put a policy type in a ric
104 # args: <response-code> <ric-id> <policy-type-id> <policy-type-file>
105 # (Function for test scripts)
106 sim_put_policy_type() {
107 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
108 if [ $# -ne 4 ]; then
110 __print_err "<response-code> <ric-id> <policy-type-id> <policy-type-file>" $@
114 res=$(__find_sim_port $app)
116 curlString="curl -X PUT -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/policytype?id="$3" -H Content-Type:application/json --data-binary @"$4
118 __execute_curl_to_sim $1 "$curlString"
122 # DSimulator API: Delete a policy type in a ric
123 # <response-code> <ric-id> <policy-type-id>
124 # (Function for test scripts)
125 sim_delete_policy_type() {
126 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
127 if [ $# -ne 3 ]; then
129 __print_err "<response-code> <ric-id> <policy_type_id>" $@
133 res=$(__find_sim_port $app)
135 curlString="curl -X DELETE -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/policytype?id="$3
137 __execute_curl_to_sim $1 "$curlString"
141 # Simulator API: Delete instances (and status), for one ric
142 # <response-code> <ric-id>
143 # (Function for test scripts)
144 sim_post_delete_instances() {
145 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
146 if [ $# -ne 2 ]; then
148 __print_err "<response-code> <ric-id>" $@
152 res=$(__find_sim_port $app)
154 curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/deleteinstances"
156 __execute_curl_to_sim $1 "$curlString"
160 # Simulator API: Delete all (instances/types/statuses/settings), for one ric
161 # <response-code> <ric-id>
162 # (Function for test scripts)
163 sim_post_delete_all() {
164 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
165 if [ $# -ne 3 ]; then
167 __print_err "<response-code> <numericic-id>" $@
171 res=$(__find_sim_port $app)
173 curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/deleteall"
175 __execute_curl_to_sim $1 "$curlString"
179 # Simulator API: Set (or reset) response code for next A1 message, for one ric
180 # <response-code> <ric-id> [<forced_response_code>]
181 # (Function for test scripts)
182 sim_post_forcedresponse() {
183 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
184 if [ $# -ne 3 ]; then
186 __print_err "<response-code> <ric-id> <forced_response_code>" $@
190 res=$(__find_sim_port $app)
192 curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/forceresponse"
193 if [ $# -eq 3 ]; then
194 curlString=$curlString"?code="$3
197 __execute_curl_to_sim $1 "$curlString"
201 # Simulator API: Set (or reset) A1 response delay, for one ric
202 # <response-code> <ric-id> [<delay-in-seconds>]
203 # (Function for test scripts)
204 sim_post_forcedelay() {
205 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
206 if [ $# -ne 3 ]; then
208 __print_err "<response-code> <ric-id> [<delay-in-seconds>]" $@
212 res=$(__find_sim_port $app)
214 curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST$res/forcedelay"
215 if [ $# -eq 3 ]; then
216 curlString=$curlString"?delay="$3
219 __execute_curl_to_sim $1 "$curlString"