Merge "Kafka now works in kube for calls outside its namespace"
[nonrtric.git] / test / common / sdnc_api_functions.sh
1 #!/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
20 # This is a script that contains container/service management functions and test functions for A1 Controller API
21
22 ################ 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 # If a custom image repo is used then also the source image from the local repo is listed
60 # arg: <docker-images-format-string> <file-to-append>
61 __SDNC_image_data() {
62         echo -e "$SDNC_DISPLAY_NAME\t$(docker images --format $1 $SDNC_A1_CONTROLLER_IMAGE)" >>   $2
63         if [ ! -z "$SDNC_A1_CONTROLLER_IMAGE_SOURCE" ]; then
64                 echo -e "-- source image --\t$(docker images --format $1 $SDNC_A1_CONTROLLER_IMAGE_SOURCE)" >>   $2
65         fi
66         echo -e "SDNC DB\t$(docker images --format $1 $SDNC_DB_IMAGE)" >>   $2
67         if [ ! -z "$SDNC_DB_IMAGE_SOURCE" ]; then
68                 echo -e "-- source image --\t$(docker images --format $1 $SDNC_DB_IMAGE_SOURCE)" >>   $2
69         fi
70 }
71
72 # Scale kubernetes resources to zero
73 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
74 # This function is called for apps fully managed by the test script
75 __SDNC_kube_scale_zero() {
76         __kube_scale_all_resources $KUBE_SDNC_NAMESPACE autotest SDNC
77 }
78
79 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
80 # This function is called for prestarted apps not managed by the test script.
81 __SDNC_kube_scale_zero_and_wait() {
82         echo -e " SDNC replicas kept as is"
83 }
84
85 # Delete all kube resouces for the app
86 # This function is called for apps managed by the test script.
87 __SDNC_kube_delete_all() {
88         __kube_delete_all_resources $KUBE_SDNC_NAMESPACE autotest SDNC
89 }
90
91 # Store docker logs
92 # This function is called for apps managed by the test script.
93 # args: <log-dir> <file-prexix>
94 __SDNC_store_docker_logs() {
95         if [ $RUNMODE == "KUBE" ]; then
96                 kubectl  logs -l "autotest=SDNC" -n $KUBE_SDNC_NAMESPACE --tail=-1 > $1$2_SDNC.log 2>&1
97                 podname=$(kubectl get pods -n $KUBE_SDNC_NAMESPACE -l "autotest=SDNC" -o custom-columns=":metadata.name")
98                 kubectl exec -t -n $KUBE_SDNC_NAMESPACE $podname -- cat $SDNC_KARAF_LOG> $1$2_SDNC_karaf.log 2>&1
99         else
100                 docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $1$2_SDNC_karaf.log 2>&1
101         fi
102 }
103
104 # Initial setup of protocol, host and ports
105 # This function is called for apps managed by the test script.
106 # args: -
107 __SDNC_initial_setup() {
108         use_sdnc_http
109 }
110
111 # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
112 # For docker, the namespace shall be excluded
113 # This function is called for apps managed by the test script as well as for prestarted apps.
114 # args: -
115 __SDNC_statisics_setup() {
116         if [ $RUNMODE == "KUBE" ]; then
117                 echo "SDNC $SDNC_APP_NAME $KUBE_SDNC_NAMESPACE"
118         else
119                 echo "SDNC $SDNC_APP_NAME"
120         fi
121 }
122
123 #######################################################
124
125 # Set http as the protocol to use for all communication to SDNC
126 # args: -
127 # (Function for test scripts)
128 use_sdnc_http() {
129         __sdnc_set_protocoll "http" $SDNC_INTERNAL_PORT $SDNC_EXTERNAL_PORT
130 }
131
132 # Set https as the protocol to use for all communication to SDNC
133 # args: -
134 # (Function for test scripts)
135 use_sdnc_https() {
136         __sdnc_set_protocoll "https" $SDNC_INTERNAL_SECURE_PORT $SDNC_EXTERNAL_SECURE_PORT
137 }
138
139 # Setup paths to svc/container for internal and external access
140 # args: <protocol> <internal-port> <external-port>
141 __sdnc_set_protocoll() {
142         echo -e $BOLD"$SDNC_DISPLAY_NAME protocol setting"$EBOLD
143         echo -e " Using $BOLD http $EBOLD towards $SDNC_DISPLAY_NAME"
144
145         ## Access to SDNC
146
147         SDNC_SERVICE_PATH=$1"://"$SDNC_APP_NAME":"$2  # docker access, container->container and script->container via proxy
148         SDNC_SERVICE_API_PATH=$1"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_APP_NAME":"$1$SDNC_API_URL
149         if [ $RUNMODE == "KUBE" ]; then
150                 SDNC_SERVICE_PATH=$1"://"$SDNC_APP_NAME.$KUBE_SDNC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
151                 SDNC_SERVICE_API_PATH=$1"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_APP_NAME.KUBE_SDNC_NAMESPACE":"$1$SDNC_API_URL
152         fi
153         echo ""
154
155 }
156
157 # Export env vars for config files, docker compose and kube resources
158 # args:
159 __sdnc_export_vars() {
160         export KUBE_SDNC_NAMESPACE
161         export DOCKER_SIM_NWNAME
162
163         export SDNC_APP_NAME
164         export SDNC_DISPLAY_NAME
165
166         export SDNC_A1_CONTROLLER_IMAGE
167         export SDNC_INTERNAL_PORT
168         export SDNC_EXTERNAL_PORT
169         export SDNC_INTERNAL_SECURE_PORT
170         export SDNC_EXTERNAL_SECURE_PORT
171         export SDNC_A1_TRUSTSTORE_PASSWORD
172         export SDNC_DB_APP_NAME
173         export SDNC_DB_IMAGE
174         export SDNC_USER
175         export SDNC_PWD
176 }
177
178 ##################
179 ### SDNC functions
180 ##################
181
182 # Start the SDNC A1 Controller
183 # args: -
184 # (Function for test scripts)
185 start_sdnc() {
186
187         echo -e $BOLD"Starting $SDNC_DISPLAY_NAME"$EBOLD
188
189         if [ $RUNMODE == "KUBE" ]; then
190
191                 # Check if app shall be fully managed by the test script
192                 __check_included_image "SDNC"
193                 retcode_i=$?
194
195                 # Check if app shall only be used by the testscipt
196                 __check_prestarted_image "SDNC"
197                 retcode_p=$?
198
199                 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
200                         echo -e $RED"The $SDNC_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
201                         echo -e $RED"The $SDNC_APP_NAME will not be started"$ERED
202                         exit
203                 fi
204                 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
205                         echo -e $RED"The $SDNC_APP_NAME app is included both as managed and prestarted in this test script"$ERED
206                         echo -e $RED"The $SDNC_APP_NAME will not be started"$ERED
207                         exit
208                 fi
209
210
211                 if [ $retcode_p -eq 0 ]; then
212                         echo -e " Using existing $SDNC_APP_NAME deployment and service"
213                         echo " Setting SDNC replicas=1"
214                         __kube_scale deployment $SDNC_APP_NAME $KUBE_SDNC_NAMESPACE 1
215                 fi
216
217                                 # Check if app shall be fully managed by the test script
218                 if [ $retcode_i -eq 0 ]; then
219
220                         echo -e " Creating $SDNC_APP_NAME app and expose service"
221
222                         #Check if namespace exists, if not create it
223                         __kube_create_namespace $KUBE_SDNC_NAMESPACE
224
225                         __sdnc_export_vars
226
227                         # Create service
228                         input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"svc.yaml
229                         output_yaml=$PWD/tmp/sdnc_svc.yaml
230                         __kube_create_instance service $SDNC_APP_NAME $input_yaml $output_yaml
231
232                         # Create app
233                         input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"$SDNC_KUBE_APP_FILE
234                         output_yaml=$PWD/tmp/sdnc_app.yaml
235                         __kube_create_instance app $SDNC_APP_NAME $input_yaml $output_yaml
236
237                 fi
238
239                 __check_service_start $SDNC_APP_NAME $SDNC_SERVICE_PATH$SDNC_ALIVE_URL
240         else
241
242                 __check_included_image 'SDNC'
243                 if [ $? -eq 1 ]; then
244                         echo -e $RED"The SDNC A1 Controller app is not included in this test script"$ERED
245                         echo -e $RED"The Policy Agent will not be started"$ERED
246                         exit
247                 fi
248
249                 __sdnc_export_vars
250
251                 __start_container $SDNC_COMPOSE_DIR $SDNC_COMPOSE_FILE NODOCKERARGS 1 $SDNC_APP_NAME
252
253                 __check_service_start $SDNC_APP_NAME $SDNC_SERVICE_PATH$SDNC_ALIVE_URL
254         fi
255     echo ""
256     return 0
257 }
258
259
260 # Stop the sndc
261 # args: -
262 # args: -
263 # (Function for test scripts)
264 stop_sdnc() {
265         echo -e $BOLD"Stopping $SDNC_DISPLAY_NAME"$EBOLD
266
267         if [ $RUNMODE == "KUBE" ]; then
268                 __log_conf_fail_not_supported " Cannot stop sndc in KUBE mode"
269                 return 1
270         else
271                 docker stop $SDNC_APP_NAME &> ./tmp/.dockererr
272                 if [ $? -ne 0 ]; then
273                         __print_err "Could not stop $SDNC_APP_NAME" $@
274                         cat ./tmp/.dockererr
275                         ((RES_CONF_FAIL++))
276                         return 1
277                 fi
278         fi
279         echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
280         echo ""
281         return 0
282 }
283
284 # Start a previously stopped sdnc
285 # args: -
286 # (Function for test scripts)
287 start_stopped_sdnc() {
288         echo -e $BOLD"Starting (the previously stopped) $SDNC_DISPLAY_NAME"$EBOLD
289
290         if [ $RUNMODE == "KUBE" ]; then
291                 __log_conf_fail_not_supported " Cannot restart sndc in KUBE mode"
292                 return 1
293         else
294                 docker start $SDNC_APP_NAME &> ./tmp/.dockererr
295                 if [ $? -ne 0 ]; then
296                         __print_err "Could not start (the stopped) $SDNC_APP_NAME" $@
297                         cat ./tmp/.dockererr
298                         ((RES_CONF_FAIL++))
299                         return 1
300                 fi
301         fi
302         __check_service_start $SDNC_APP_NAME $SDNC_SERVICE_PATH$SDNC_ALIVE_URL
303         if [ $? -ne 0 ]; then
304                 return 1
305         fi
306         echo ""
307         return 0
308 }
309
310 # Check the agent logs for WARNINGs and ERRORs
311 # args: -
312 # (Function for test scripts)
313 check_sdnc_logs() {
314         __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
315 }
316
317 # Generic function to query the RICs via the A1-controller API.
318 # args: <operation> <url> [<body>]
319 # <operation>: getA1Policy,putA1Policy,getA1PolicyType,deleteA1Policy,getA1PolicyStatus
320 # response: <json-body><3-digit-response-code>
321 # (Not for test scripts)
322 __do_curl_to_controller() {
323     echo " (${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
324     if [ $# -ne 2 ] && [ $# -ne 3 ]; then
325                 ((RES_CONF_FAIL++))
326         echo "-Incorrect number of parameters to __do_curl_to_controller " $@ >> $HTTPLOG
327         echo "-Expected: <operation> <url> [<body>]" >> $HTTPLOG
328         echo "-Returning response 000" >> $HTTPLOG
329         echo "000"
330         return 1
331     fi
332     if [ $# -eq 2 ]; then
333         json='{"input":{"near-rt-ric-url":"'$2'"}}'
334     else
335         # Escape quotes in the body
336         body=$(echo "$3" | sed 's/"/\\"/g')
337         json='{"input":{"near-rt-ric-url":"'$2'","body":"'"$body"'"}}'
338     fi
339         payload="./tmp/.sdnc.payload.json"
340     echo "$json" > $payload
341     echo "  FILE ($payload) : $json"  >> $HTTPLOG
342         proxyflag=""
343         if [ ! -z "$KUBE_PROXY_PATH" ]; then
344                 if [ $KUBE_PROXY_HTTPX == "http" ]; then
345                         proxyflag=" --proxy $KUBE_PROXY_PATH"
346                 else
347                         proxyflag=" --proxy-insecure --proxy $KUBE_PROXY_PATH"
348                 fi
349         fi
350     curlString="curl -skw %{http_code} $proxyflag -X POST $SDNC_SERVICE_API_PATH$1 -H accept:application/json -H Content-Type:application/json --data-binary @$payload"
351     echo "  CMD: "$curlString >> $HTTPLOG
352     res=$($curlString)
353     retcode=$?
354     echo "  RESP: "$res >> $HTTPLOG
355     if [ $retcode -ne 0 ]; then
356         echo "  RETCODE: "$retcode >> $HTTPLOG
357         echo "000"
358         return 1
359     fi
360
361         status=${res:${#res}-3}
362
363     if [ $status -ne 200 ]; then
364         echo "000"
365         return 1
366     fi
367     body=${res:0:${#res}-3}
368         echo "  JSON: "$body >> $HTTPLOG
369         reply="./tmp/.sdnc-reply.json"
370     echo "$body" > $reply
371     res=$(python3 ../common/extract_sdnc_reply.py $SDNC_RESPONSE_JSON_KEY $reply)
372     echo "  EXTRACED BODY+CODE: "$res >> $HTTPLOG
373     echo "$res"
374     return 0
375 }
376
377 # Controller API Test function: getA1Policy (return ids only)
378 # arg: <response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )
379 # (Function for test scripts)
380 controller_api_get_A1_policy_ids() {
381         __log_test_start $@
382
383         ric_id=$3
384         if [ $RUNMODE == "KUBE" ]; then
385                 ric_id=$(get_kube_sim_host $3)
386         fi
387     paramError=1
388     if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
389         url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies"
390                 paramError=0
391     elif [ $# -gt 2 ] && [ $2 == "STD" ]; then
392         url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies"
393         paramError=0
394         fi
395
396     if [ $paramError -ne 0 ]; then
397                 __print_err "<response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )" $@
398                 return 1
399         fi
400
401     res=$(__do_curl_to_controller getA1Policy "$url")
402     retcode=$?
403     status=${res:${#res}-3}
404
405     if [ $retcode -ne 0 ]; then
406                 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
407                 return 1
408         fi
409
410         if [ $status -ne $1 ]; then
411                 __log_test_fail_status_code $1 $status
412                 return 1
413         fi
414     body=${res:0:${#res}-3}
415
416         targetJson="["
417     start=4
418     if [ $2 == "OSC" ]; then
419         start=5
420     fi
421     for pid in ${@:$start} ; do
422         if [ "$targetJson" != "[" ]; then
423             targetJson=$targetJson","
424         fi
425         targetJson=$targetJson"\"$UUID$pid\""
426     done
427     targetJson=$targetJson"]"
428
429         echo " TARGET JSON: $targetJson" >> $HTTPLOG
430
431         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
432
433         if [ $res -ne 0 ]; then
434                 __log_test_fail_body
435                 return 1
436         fi
437
438         __log_test_pass
439         return 0
440 }
441
442
443 # Controller API Test function: getA1PolicyType
444 # arg: <response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]
445 # (Function for test scripts)
446 controller_api_get_A1_policy_type() {
447         __log_test_start $@
448
449         ric_id=$3
450         if [ $RUNMODE == "KUBE" ]; then
451                 ric_id=$(get_kube_sim_host $3)
452         fi
453     paramError=1
454     if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
455         url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4"
456                 paramError=0
457         fi
458
459     if [ $paramError -ne 0 ]; then
460                 __print_err "<response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]" $@
461                 return 1
462         fi
463
464     res=$(__do_curl_to_controller getA1PolicyType "$url")
465     retcode=$?
466     status=${res:${#res}-3}
467
468     if [ $retcode -ne 0 ]; then
469                 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
470                 return 1
471         fi
472
473         if [ $status -ne $1 ]; then
474                 __log_test_fail_status_code $1 $status
475                 return 1
476         fi
477     body=${res:0:${#res}-3}
478
479         if [ $# -eq 5 ]; then
480
481                 body=${res:0:${#res}-3}
482
483                 targetJson=$(< $5)
484                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
485                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
486
487                 if [ $res -ne 0 ]; then
488                         __log_test_fail_body
489                         return 1
490                 fi
491         fi
492
493         __log_test_pass
494         return 0
495 }
496
497 # Controller API Test function: deleteA1Policy
498 # arg: <response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)
499 # (Function for test scripts)
500 controller_api_delete_A1_policy() {
501         __log_test_start $@
502
503         ric_id=$3
504         if [ $RUNMODE == "KUBE" ]; then
505                 ric_id=$(get_kube_sim_host $3)
506         fi
507     paramError=1
508     if [ $# -eq 5 ] && [ $2 == "OSC" ]; then
509         url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
510                 paramError=0
511     elif [ $# -eq 4 ] && [ $2 == "STD" ]; then
512         url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
513         paramError=0
514         fi
515
516     if [ $paramError -ne 0 ]; then
517                 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
518                 return 1
519         fi
520
521     res=$(__do_curl_to_controller deleteA1Policy "$url")
522     retcode=$?
523     status=${res:${#res}-3}
524
525     if [ $retcode -ne 0 ]; then
526                 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
527                 return 1
528         fi
529
530         if [ $status -ne $1 ]; then
531                 __log_test_fail_status_code $1 $status
532                 return 1
533         fi
534
535         __log_test_pass
536         return 0
537 }
538
539 # Controller API Test function: putA1Policy
540 # arg: <response-code> (STD <ric-id> <policy-id> <template-file> ) | (OSC <ric-id> <policy-type-id> <policy-id> <template-file>)
541 # (Function for test scripts)
542 controller_api_put_A1_policy() {
543         __log_test_start $@
544
545         ric_id=$3
546         if [ $RUNMODE == "KUBE" ]; then
547                 ric_id=$(get_kube_sim_host $3)
548         fi
549     paramError=1
550     if [ $# -eq 6 ] && [ $2 == "OSC" ]; then
551         url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
552         body=$(sed 's/XXX/'${5}'/g' $6)
553
554                 paramError=0
555     elif [ $# -eq 5 ] && [ $2 == "STD" ]; then
556         url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
557         body=$(sed 's/XXX/'${4}'/g' $5)
558         paramError=0
559         fi
560
561     if [ $paramError -ne 0 ]; then
562                 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
563                 return 1
564         fi
565
566     res=$(__do_curl_to_controller putA1Policy "$url" "$body")
567     retcode=$?
568     status=${res:${#res}-3}
569
570     if [ $retcode -ne 0 ]; then
571                 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
572                 return 1
573         fi
574
575         if [ $status -ne $1 ]; then
576                 __log_test_fail_status_code $1 $status
577                 return 1
578         fi
579
580         __log_test_pass
581         return 0
582 }
583
584
585 # Controller API Test function: getA1PolicyStatus
586 # arg: <response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>)
587 # (Function for test scripts)
588 controller_api_get_A1_policy_status() {
589         __log_test_start $@
590
591         ric_id=$3
592         if [ $RUNMODE == "KUBE" ]; then
593                 ric_id=$(get_kube_sim_host $3)
594         fi
595     targetJson=""
596     paramError=1
597     if [ $# -ge 5 ] && [ $2 == "OSC" ]; then
598         url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5/status"
599         if [ $# -gt 5 ]; then
600             targetJson="{\"instance_status\":\"$6\""
601             targetJson=$targetJson",\"has_been_deleted\":\"$7\""
602             targetJson=$targetJson",\"created_at\":\"????\"}"
603         fi
604                 paramError=0
605     elif [ $# -ge 4 ] && [ $2 == "STD" ]; then
606         url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4/status"
607         if [ $# -gt 4 ]; then
608             targetJson="{\"enforceStatus\":\"$5\""
609             if [ $# -eq 6 ]; then
610                 targetJson=$targetJson",\"reason\":\"$6\""
611             fi
612             targetJson=$targetJson"}"
613         fi
614         paramError=0
615         fi
616
617     if [ $paramError -ne 0 ]; then
618                 __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>)" $@
619                 return 1
620         fi
621
622     res=$(__do_curl_to_controller getA1PolicyStatus "$url")
623     retcode=$?
624     status=${res:${#res}-3}
625
626     if [ $retcode -ne 0 ]; then
627                 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
628                 return 1
629         fi
630
631         if [ $status -ne $1 ]; then
632                 __log_test_fail_status_code $1 $status
633                 return 1
634         fi
635
636         if [ ! -z "$targetJson" ]; then
637
638                 body=${res:0:${#res}-3}
639                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
640                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
641
642                 if [ $res -ne 0 ]; then
643                         __log_test_fail_body
644                         return 1
645                 fi
646         fi
647
648         __log_test_pass
649         return 0
650 }