blob: d4055018220a380d3a198c513a126afb5a736495 [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/bin/bash
2
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
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
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=================================================
18#
19
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010020# This is a script that contains container/service management functions and test functions for A1 Controller API
21
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010022################ Test engine functions ################
23
24# Create the image var used during the test
25# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
26# <image-tag-suffix> is present only for images with staging, snapshot,release tags
27__SDNC_imagesetup() {
28
29 sdnc_suffix_tag=$1
30
31 for oia_name in $ONAP_IMAGES_APP_NAMES; do
32 if [ "$oia_name" == "SDNC" ]; then
33 sdnc_suffix_tag="REMOTE_RELEASE_ONAP"
34 fi
35 done
36 __check_and_create_image_var SDNC "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_IMAGE_BASE" "SDNC_A1_CONTROLLER_IMAGE_TAG" $sdnc_suffix_tag "$SDNC_DISPLAY_NAME"
37 __check_and_create_image_var SDNC "SDNC_DB_IMAGE" "SDNC_DB_IMAGE_BASE" "SDNC_DB_IMAGE_TAG" REMOTE_PROXY "SDNC DB"
38
39}
40
41# Pull image from remote repo or use locally built image
42# arg: <pull-policy-override> <pull-policy-original>
43# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
44# <pull-policy-original> Shall be used for images that does not allow overriding
45# Both var may contain: 'remote', 'remote-remove' or 'local'
46__SDNC_imagepull() {
47 __check_and_pull_image $1 "$SDNC_DISPLAY_NAME" $SDNC_APP_NAME $SDNC_A1_CONTROLLER_IMAGE
48 __check_and_pull_image $2 "SDNC DB" $SDNC_APP_NAME $SDNC_DB_IMAGE
49}
50
51# Build image (only for simulator or interfaces stubs owned by the test environment)
52# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
53# <image-tag-suffix> is present only for images with staging, snapshot,release tags
54__SDNC_imagebuild() {
55 echo -e $RED" Image for app SDNC shall never be built"$ERED
56}
57
58# Generate a string for each included image using the app display name and a docker images format string
59# arg: <docker-images-format-string> <file-to-append>
60__SDNC_image_data() {
61 echo -e "$SDNC_DISPLAY_NAME\t$(docker images --format $1 $SDNC_A1_CONTROLLER_IMAGE)" >> $2
62 echo -e "SDNC DB\t$(docker images --format $1 $SDNC_DB_IMAGE)" >> $2
63}
64
65# Scale kubernetes resources to zero
66# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
67# This function is called for apps fully managed by the test script
68__SDNC_kube_scale_zero() {
69 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest SDNC
70}
71
72# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
73# This function is called for prestarted apps not managed by the test script.
74__SDNC_kube_scale_zero_and_wait() {
75 echo -e " SDNC replicas kept as is"
76}
77
78# Delete all kube resouces for the app
79# This function is called for apps managed by the test script.
80__SDNC_kube_delete_all() {
81 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest SDNC
82}
83
84# Store docker logs
85# This function is called for apps managed by the test script.
86# args: <log-dir> <file-prexix>
87__SDNC_store_docker_logs() {
88 docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $1$2_SDNC_karaf.log 2>&1
89}
90
91#######################################################
92
93
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010094SDNC_HTTPX="http"
95SDNC_HOST_NAME=$LOCALHOST_NAME
96SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT
97SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT$SDNC_API_URL
98#Docker/Kube internal path
99if [ $RUNMODE == "KUBE" ]; then
100 SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_PORT
101 #presume correct
102 SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_PORT
103 #test
104 #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_PORT
105else
106 SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_INTERNAL_PORT
107fi
108
109use_sdnc_http() {
110 echo -e $BOLD"SDNC NB protocol setting"$EBOLD
111 echo -e " Using $BOLD http $EBOLD towards SDNC"
112 SDNC_HTTPX="http"
113 SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT
114 SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT$SDNC_API_URL
115 if [ $RUNMODE == "KUBE" ]; then
116 #presume correct
117 SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_PORT
118 #test
119 #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_PORT
120 else
121 SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_INTERNAL_PORT
122 fi
123 echo ""
124}
125
126use_sdnc_https() {
127 echo -e $BOLD"SDNC NB protocol setting"$EBOLD
128 echo -e " Using $BOLD https $EBOLD towards SDNC"
129 SDNC_HTTPX="https"
130 SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_SECURE_PORT
131 SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_SECURE_PORT$SDNC_API_URL
132 if [ $RUNMODE == "KUBE" ]; then
133 #presume correct
134 SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_SECURE_PORT
135 #test
136 #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_SECURE_PORT
137 else
138 SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_INTERNAL_SECURE_PORT
139 fi
140 echo ""
141}
142
143##################
144### SDNC functions
145##################
146
147# Start the SDNC A1 Controller
148# args: -
149# (Function for test scripts)
150start_sdnc() {
151
152 echo -e $BOLD"Starting $SDNC_DISPLAY_NAME"$EBOLD
153
154 if [ $RUNMODE == "KUBE" ]; then
155
156 # Check if app shall be fully managed by the test script
157 __check_included_image "SDNC"
158 retcode_i=$?
159
160 # Check if app shall only be used by the testscipt
161 __check_prestarted_image "SDNC"
162 retcode_p=$?
163
164 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
165 echo -e $RED"The $SDNC_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
166 echo -e $RED"The $SDNC_APP_NAME will not be started"$ERED
167 exit
168 fi
169 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
170 echo -e $RED"The $SDNC_APP_NAME app is included both as managed and prestarted in this test script"$ERED
171 echo -e $RED"The $SDNC_APP_NAME will not be started"$ERED
172 exit
173 fi
174
175
176 if [ $retcode_p -eq 0 ]; then
177 echo -e " Using existing $SDNC_APP_NAME deployment and service"
178 echo " Setting SDNC replicas=1"
179 __kube_scale deployment $SDNC_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
180 fi
181
182 # Check if app shall be fully managed by the test script
183 if [ $retcode_i -eq 0 ]; then
184
185 echo -e " Creating $SDNC_APP_NAME app and expose service"
186
187 #Check if nonrtric namespace exists, if not create it
188 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
189
190 export KUBE_NONRTRIC_NAMESPACE
191 export SDNC_APP_NAME
192 export SDNC_A1_CONTROLLER_IMAGE
193 export SDNC_INTERNAL_PORT
194 export SDNC_EXTERNAL_PORT
195 export SDNC_INTERNAL_SECURE_PORT
196 export SDNC_EXTERNAL_SECURE_PORT
197 export SDNC_A1_TRUSTSTORE_PASSWORD
198 export SDNC_DB_APP_NAME
199 export SDNC_DB_IMAGE
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100200 export SDNC_USER
201 export SDNC_PWD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100202
203 # Create service
204 input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"svc.yaml
205 output_yaml=$PWD/tmp/sdnc_svc.yaml
206 __kube_create_instance service $SDNC_APP_NAME $input_yaml $output_yaml
207
208 # Create app
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100209 input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"$SDNC_KUBE_APP_FILE
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100210 output_yaml=$PWD/tmp/sdnc_app.yaml
211 __kube_create_instance app $SDNC_APP_NAME $input_yaml $output_yaml
212
213 fi
214
215 echo " Retrieving host and ports for service..."
216 SDNC_HOST_NAME=$(__kube_get_service_host $SDNC_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
217 SDNC_EXTERNAL_PORT=$(__kube_get_service_port $SDNC_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
218 SDNC_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $SDNC_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
219
220 echo " Host IP, http port, https port: $SDNC_HOST_NAME $SDNC_EXTERNAL_PORT $SDNC_EXTERNAL_SECURE_PORT"
221
222 if [ $SDNC_HTTPX == "http" ]; then
223 SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT
224 SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT$SDNC_API_URL
225 #presume correct
226 SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_PORT
227 #test
228 #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_PORT
229 else
230 SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_SECURE_PORT
231 SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_SECURE_PORT$SDNC_API_URL
232 #presume correct
233 SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_SECURE_PORT
234 #test
235 #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_SECURE_PORT
236 fi
237
238 __check_service_start $SDNC_APP_NAME $SDNC_PATH$SDNC_ALIVE_URL
239 else
240
241 __check_included_image 'SDNC'
242 if [ $? -eq 1 ]; then
243 echo -e $RED"The SDNC A1 Controller app is not included in this test script"$ERED
244 echo -e $RED"The Policy Agent will not be started"$ERED
245 exit
246 fi
247
248 export SDNC_DB_APP_NAME
249 export SDNC_APP_NAME
250 export SDNC_INTERNAL_PORT
251 export SDNC_EXTERNAL_PORT
252 export SDNC_INTERNAL_SECURE_PORT
253 export SDNC_EXTERNAL_SECURE_PORT
254 export SDNC_A1_TRUSTSTORE_PASSWORD
255 export DOCKER_SIM_NWNAME
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100256 export SDNC_DISPLAY_NAME
257 export SDNC_USER
258 export SDNC_PWD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100259
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100260 __start_container $SDNC_COMPOSE_DIR $SDNC_COMPOSE_FILE NODOCKERARGS 1 $SDNC_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100261
262 __check_service_start $SDNC_APP_NAME $SDNC_PATH$SDNC_ALIVE_URL
263 fi
264 echo ""
265 return 0
266}
267
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100268# Check the agent logs for WARNINGs and ERRORs
269# args: -
270# (Function for test scripts)
271check_sdnc_logs() {
272 __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
273}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100274
275# Generic function to query the RICs via the A1-controller API.
276# args: <operation> <url> [<body>]
277# <operation>: getA1Policy,putA1Policy,getA1PolicyType,deleteA1Policy,getA1PolicyStatus
278# response: <json-body><3-digit-response-code>
279# (Not for test scripts)
280__do_curl_to_controller() {
281 echo " (${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
282 if [ $# -ne 2 ] && [ $# -ne 3 ]; then
283 ((RES_CONF_FAIL++))
284 echo "-Incorrect number of parameters to __do_curl_to_controller " $@ >> $HTTPLOG
285 echo "-Expected: <operation> <url> [<body>]" >> $HTTPLOG
286 echo "-Returning response 000" >> $HTTPLOG
287 echo "000"
288 return 1
289 fi
290 if [ $# -eq 2 ]; then
291 json='{"input":{"near-rt-ric-url":"'$2'"}}'
292 else
293 # Escape quotes in the body
294 body=$(echo "$3" | sed 's/"/\\"/g')
295 json='{"input":{"near-rt-ric-url":"'$2'","body":"'"$body"'"}}'
296 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200297 payload="./tmp/.sdnc.payload.json"
298 echo "$json" > $payload
299 echo " FILE ($payload) : $json" >> $HTTPLOG
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100300 proxyflag=""
301 if [ $RUNMODE == "KUBE" ]; then
302 if [ ! -z "$CLUSTER_KUBE_PROXY_NODEPORT" ]; then
303 proxyflag=" --proxy http://localhost:$CLUSTER_KUBE_PROXY_NODEPORT"
304 fi
305 fi
306 curlString="curl -skw %{http_code} $proxyflag -X POST $SDNC_API_PATH$1 -H accept:application/json -H Content-Type:application/json --data-binary @$payload"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100307 echo " CMD: "$curlString >> $HTTPLOG
308 res=$($curlString)
309 retcode=$?
310 echo " RESP: "$res >> $HTTPLOG
311 if [ $retcode -ne 0 ]; then
312 echo " RETCODE: "$retcode >> $HTTPLOG
313 echo "000"
314 return 1
315 fi
316
317 status=${res:${#res}-3}
318
319 if [ $status -ne 200 ]; then
320 echo "000"
321 return 1
322 fi
323 body=${res:0:${#res}-3}
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200324 echo " JSON: "$body >> $HTTPLOG
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200325 reply="./tmp/.sdnc-reply.json"
326 echo "$body" > $reply
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100327 res=$(python3 ../common/extract_sdnc_reply.py $SDNC_RESPONSE_JSON_KEY $reply)
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100328 echo " EXTRACED BODY+CODE: "$res >> $HTTPLOG
329 echo "$res"
330 return 0
331}
332
333# Controller API Test function: getA1Policy (return ids only)
334# arg: <response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )
335# (Function for test scripts)
336controller_api_get_A1_policy_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100337 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100338
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100339 ric_id=$3
340 if [ $RUNMODE == "KUBE" ]; then
341 ric_id=$(get_kube_sim_host $3)
342 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100343 paramError=1
344 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100345 url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100346 paramError=0
347 elif [ $# -gt 2 ] && [ $2 == "STD" ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100348 url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100349 paramError=0
350 fi
351
352 if [ $paramError -ne 0 ]; then
353 __print_err "<response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )" $@
354 return 1
355 fi
356
357 res=$(__do_curl_to_controller getA1Policy "$url")
358 retcode=$?
359 status=${res:${#res}-3}
360
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100361 if [ $retcode -ne 0 ]; then
362 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100363 return 1
364 fi
365
366 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100367 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100368 return 1
369 fi
370 body=${res:0:${#res}-3}
371
372 targetJson="["
373 start=4
374 if [ $2 == "OSC" ]; then
375 start=5
376 fi
377 for pid in ${@:$start} ; do
378 if [ "$targetJson" != "[" ]; then
379 targetJson=$targetJson","
380 fi
BjornMagnussonXAad047782020-06-08 15:54:11 +0200381 targetJson=$targetJson"\"$UUID$pid\""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100382 done
383 targetJson=$targetJson"]"
384
385 echo " TARGET JSON: $targetJson" >> $HTTPLOG
386
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200387 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100388
389 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100390 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100391 return 1
392 fi
393
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100394 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100395 return 0
396}
397
398
399# Controller API Test function: getA1PolicyType
400# arg: <response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]
401# (Function for test scripts)
402controller_api_get_A1_policy_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100403 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100404
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100405 ric_id=$3
406 if [ $RUNMODE == "KUBE" ]; then
407 ric_id=$(get_kube_sim_host $3)
408 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100409 paramError=1
410 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100411 url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100412 paramError=0
413 fi
414
415 if [ $paramError -ne 0 ]; then
416 __print_err "<response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]" $@
417 return 1
418 fi
419
420 res=$(__do_curl_to_controller getA1PolicyType "$url")
421 retcode=$?
422 status=${res:${#res}-3}
423
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100424 if [ $retcode -ne 0 ]; then
425 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100426 return 1
427 fi
428
429 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100430 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100431 return 1
432 fi
433 body=${res:0:${#res}-3}
434
435 if [ $# -eq 5 ]; then
436
437 body=${res:0:${#res}-3}
438
439 targetJson=$(< $5)
440 echo " TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200441 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100442
443 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100444 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100445 return 1
446 fi
447 fi
448
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100449 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100450 return 0
451}
452
453# Controller API Test function: deleteA1Policy
454# arg: <response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)
455# (Function for test scripts)
456controller_api_delete_A1_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100457 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100458
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100459 ric_id=$3
460 if [ $RUNMODE == "KUBE" ]; then
461 ric_id=$(get_kube_sim_host $3)
462 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100463 paramError=1
464 if [ $# -eq 5 ] && [ $2 == "OSC" ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100465 url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100466 paramError=0
467 elif [ $# -eq 4 ] && [ $2 == "STD" ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100468 url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100469 paramError=0
470 fi
471
472 if [ $paramError -ne 0 ]; then
473 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
474 return 1
475 fi
476
477 res=$(__do_curl_to_controller deleteA1Policy "$url")
478 retcode=$?
479 status=${res:${#res}-3}
480
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100481 if [ $retcode -ne 0 ]; then
482 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100483 return 1
484 fi
485
486 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100487 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100488 return 1
489 fi
490
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100491 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100492 return 0
493}
494
495# Controller API Test function: putA1Policy
496# arg: <response-code> (STD <ric-id> <policy-id> <template-file> ) | (OSC <ric-id> <policy-type-id> <policy-id> <template-file>)
497# (Function for test scripts)
498controller_api_put_A1_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100499 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100500
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100501 ric_id=$3
502 if [ $RUNMODE == "KUBE" ]; then
503 ric_id=$(get_kube_sim_host $3)
504 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100505 paramError=1
506 if [ $# -eq 6 ] && [ $2 == "OSC" ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100507 url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100508 body=$(sed 's/XXX/'${5}'/g' $6)
509
510 paramError=0
511 elif [ $# -eq 5 ] && [ $2 == "STD" ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100512 url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100513 body=$(sed 's/XXX/'${4}'/g' $5)
514 paramError=0
515 fi
516
517 if [ $paramError -ne 0 ]; then
518 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
519 return 1
520 fi
521
522 res=$(__do_curl_to_controller putA1Policy "$url" "$body")
523 retcode=$?
524 status=${res:${#res}-3}
525
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100526 if [ $retcode -ne 0 ]; then
527 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100528 return 1
529 fi
530
531 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100532 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100533 return 1
534 fi
535
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100536 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100537 return 0
538}
539
540
541# Controller API Test function: getA1PolicyStatus
542# arg: <response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>)
543# (Function for test scripts)
544controller_api_get_A1_policy_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100545 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100546
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100547 ric_id=$3
548 if [ $RUNMODE == "KUBE" ]; then
549 ric_id=$(get_kube_sim_host $3)
550 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100551 targetJson=""
552 paramError=1
553 if [ $# -ge 5 ] && [ $2 == "OSC" ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100554 url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5/status"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100555 if [ $# -gt 5 ]; then
556 targetJson="{\"instance_status\":\"$6\""
557 targetJson=$targetJson",\"has_been_deleted\":\"$7\""
558 targetJson=$targetJson",\"created_at\":\"????\"}"
559 fi
560 paramError=0
561 elif [ $# -ge 4 ] && [ $2 == "STD" ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100562 url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4/status"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100563 if [ $# -gt 4 ]; then
564 targetJson="{\"enforceStatus\":\"$5\""
565 if [ $# -eq 6 ]; then
566 targetJson=$targetJson",\"reason\":\"$6\""
567 fi
568 targetJson=$targetJson"}"
569 fi
570 paramError=0
571 fi
572
573 if [ $paramError -ne 0 ]; then
574 __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>)" $@
575 return 1
576 fi
577
578 res=$(__do_curl_to_controller getA1PolicyStatus "$url")
579 retcode=$?
580 status=${res:${#res}-3}
581
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100582 if [ $retcode -ne 0 ]; then
583 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100584 return 1
585 fi
586
587 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100588 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100589 return 1
590 fi
591
592 if [ ! -z "$targetJson" ]; then
593
594 body=${res:0:${#res}-3}
595 echo " TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200596 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100597
598 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100599 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100600 return 1
601 fi
602 fi
603
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100604 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100605 return 0
606}