2701957fb6757ed0f0ea25a85b3fdb07f36f475d
[nonrtric.git] / test / common / sdnc_api_functions.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2020-2023 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 $KUBECONF  logs -l "autotest=SDNC" -n $KUBE_SDNC_NAMESPACE --tail=-1 > $1$2_SDNC.log 2>&1
97                 podname=$(kubectl $KUBECONF get pods -n $KUBE_SDNC_NAMESPACE -l "autotest=SDNC" -o custom-columns=":metadata.name")
98                 kubectl $KUBECONF 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 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
124 # args: -
125 __SDNC_test_requirements() {
126         :
127 }
128
129 #######################################################
130
131 # Set http as the protocol to use for all communication to SDNC
132 # args: -
133 # (Function for test scripts)
134 use_sdnc_http() {
135         __sdnc_set_protocoll "http" $SDNC_INTERNAL_PORT $SDNC_EXTERNAL_PORT
136 }
137
138 # Set https as the protocol to use for all communication to SDNC
139 # args: -
140 # (Function for test scripts)
141 use_sdnc_https() {
142         __sdnc_set_protocoll "https" $SDNC_INTERNAL_SECURE_PORT $SDNC_EXTERNAL_SECURE_PORT
143 }
144
145 # Setup paths to svc/container for internal and external access
146 # args: <protocol> <internal-port> <external-port>
147 __sdnc_set_protocoll() {
148         echo -e $BOLD"$SDNC_DISPLAY_NAME protocol setting"$EBOLD
149         echo -e " Using $BOLD $1 $EBOLD towards $SDNC_DISPLAY_NAME"
150
151         ## Access to SDNC
152
153         SDNC_SERVICE_PATH=$1"://"$SDNC_APP_NAME":"$2  # docker access, container->container and script->container via proxy
154         SDNC_SERVICE_API_PATH=$1"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_APP_NAME":"$2$SDNC_API_URL
155         if [ $RUNMODE == "KUBE" ]; then
156                 SDNC_SERVICE_PATH=$1"://"$SDNC_APP_NAME.$KUBE_SDNC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
157                 SDNC_SERVICE_API_PATH=$1"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_APP_NAME.$KUBE_SDNC_NAMESPACE":"$3$SDNC_API_URL
158         fi
159         echo ""
160
161 }
162
163 # Export env vars for config files, docker compose and kube resources
164 # args:
165 __sdnc_export_vars() {
166         export KUBE_SDNC_NAMESPACE
167         export DOCKER_SIM_NWNAME
168
169         export SDNC_APP_NAME
170         export SDNC_DISPLAY_NAME
171
172         export SDNC_A1_CONTROLLER_IMAGE
173         export SDNC_INTERNAL_PORT
174         export SDNC_EXTERNAL_PORT
175         export SDNC_INTERNAL_SECURE_PORT
176         export SDNC_EXTERNAL_SECURE_PORT
177         export SDNC_A1_TRUSTSTORE_PASSWORD
178         export SDNC_DB_APP_NAME
179         export SDNC_DB_IMAGE
180         export SDNC_USER
181         export SDNC_PWD
182 }
183
184 ##################
185 ### SDNC functions
186 ##################
187
188 # Start the SDNC A1 Controller
189 # args: -
190 # (Function for test scripts)
191 start_sdnc() {
192
193         echo -e $BOLD"Starting $SDNC_DISPLAY_NAME"$EBOLD
194
195         if [ $RUNMODE == "KUBE" ]; then
196
197                 # Check if app shall be fully managed by the test script
198                 __check_included_image "SDNC"
199                 retcode_i=$?
200
201                 # Check if app shall only be used by the testscipt
202                 __check_prestarted_image "SDNC"
203                 retcode_p=$?
204
205                 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
206                         echo -e $RED"The $SDNC_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
207                         echo -e $RED"The $SDNC_APP_NAME will not be started"$ERED
208                         exit
209                 fi
210                 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
211                         echo -e $RED"The $SDNC_APP_NAME app is included both as managed and prestarted in this test script"$ERED
212                         echo -e $RED"The $SDNC_APP_NAME will not be started"$ERED
213                         exit
214                 fi
215
216
217                 if [ $retcode_p -eq 0 ]; then
218                         echo -e " Using existing $SDNC_APP_NAME deployment and service"
219                         echo " Setting SDNC replicas=1"
220                         __kube_scale deployment $SDNC_APP_NAME $KUBE_SDNC_NAMESPACE 1
221                 fi
222
223                                 # Check if app shall be fully managed by the test script
224                 if [ $retcode_i -eq 0 ]; then
225
226                         echo -e " Creating $SDNC_APP_NAME app and expose service"
227
228                         #Check if namespace exists, if not create it
229                         __kube_create_namespace $KUBE_SDNC_NAMESPACE
230
231                         __sdnc_export_vars
232
233                         # Create service
234                         input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"svc.yaml
235                         output_yaml=$PWD/tmp/sdnc_svc.yaml
236                         __kube_create_instance service $SDNC_APP_NAME $input_yaml $output_yaml
237
238                         # Create app
239                         input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"$SDNC_KUBE_APP_FILE
240                         output_yaml=$PWD/tmp/sdnc_app.yaml
241                         __kube_create_instance app $SDNC_APP_NAME $input_yaml $output_yaml
242
243                 fi
244
245                 __check_service_start $SDNC_APP_NAME $SDNC_SERVICE_PATH$SDNC_ALIVE_URL
246         else
247
248                 __check_included_image 'SDNC'
249                 if [ $? -eq 1 ]; then
250                         echo -e $RED"The SDNC A1 Controller app is not included in this test script"$ERED
251                         echo -e $RED"The A1PMS will not be started"$ERED
252                         exit
253                 fi
254
255                 __sdnc_export_vars
256
257                 __start_container $SDNC_COMPOSE_DIR $SDNC_COMPOSE_FILE NODOCKERARGS 1 $SDNC_APP_NAME
258
259                 __check_service_start $SDNC_APP_NAME $SDNC_SERVICE_PATH$SDNC_ALIVE_URL
260         fi
261     echo ""
262     return 0
263 }
264
265
266 # Stop the sndc
267 # args: -
268 # args: -
269 # (Function for test scripts)
270 stop_sdnc() {
271         echo -e $BOLD"Stopping $SDNC_DISPLAY_NAME"$EBOLD
272
273         if [ $RUNMODE == "KUBE" ]; then
274                 __log_conf_fail_not_supported " Cannot stop sndc in KUBE mode"
275                 return 1
276         else
277                 docker stop $SDNC_APP_NAME &> ./tmp/.dockererr
278                 if [ $? -ne 0 ]; then
279                         __print_err "Could not stop $SDNC_APP_NAME" $@
280                         cat ./tmp/.dockererr
281                         ((RES_CONF_FAIL++))
282                         return 1
283                 fi
284         fi
285         echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
286         echo ""
287         return 0
288 }
289
290 # Start a previously stopped sdnc
291 # args: -
292 # (Function for test scripts)
293 start_stopped_sdnc() {
294         echo -e $BOLD"Starting (the previously stopped) $SDNC_DISPLAY_NAME"$EBOLD
295
296         if [ $RUNMODE == "KUBE" ]; then
297                 __log_conf_fail_not_supported " Cannot restart sndc in KUBE mode"
298                 return 1
299         else
300                 docker start $SDNC_APP_NAME &> ./tmp/.dockererr
301                 if [ $? -ne 0 ]; then
302                         __print_err "Could not start (the stopped) $SDNC_APP_NAME" $@
303                         cat ./tmp/.dockererr
304                         ((RES_CONF_FAIL++))
305                         return 1
306                 fi
307         fi
308         __check_service_start $SDNC_APP_NAME $SDNC_SERVICE_PATH$SDNC_ALIVE_URL
309         if [ $? -ne 0 ]; then
310                 return 1
311         fi
312         echo ""
313         return 0
314 }
315
316 # Check the sdnc logs for WARNINGs and ERRORs
317 # args: -
318 # (Function for test scripts)
319 check_sdnc_logs() {
320         __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
321 }
322
323 # Generic function to query the RICs via the A1-controller API.
324 # args: <operation> <url> [<body>]
325 # <operation>: getA1Policy,putA1Policy,getA1PolicyType,deleteA1Policy,getA1PolicyStatus
326 # response: <json-body><3-digit-response-code>
327 # (Not for test scripts)
328 __do_curl_to_controller() {
329     echo " (${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
330     if [ $# -ne 2 ] && [ $# -ne 3 ]; then
331                 ((RES_CONF_FAIL++))
332         echo "-Incorrect number of parameters to __do_curl_to_controller " $@ >> $HTTPLOG
333         echo "-Expected: <operation> <url> [<body>]" >> $HTTPLOG
334         echo "-Returning response 000" >> $HTTPLOG
335         echo "000"
336         return 1
337     fi
338     if [ $# -eq 2 ]; then
339         json='{"input":{"near-rt-ric-url":"'$2'"}}'
340     else
341         # Escape quotes in the body
342         body=$(echo "$3" | sed 's/"/\\"/g')
343         json='{"input":{"near-rt-ric-url":"'$2'","body":"'"$body"'"}}'
344     fi
345         payload="./tmp/.sdnc.payload.json"
346     echo "$json" > $payload
347     echo "  FILE ($payload) : $json"  >> $HTTPLOG
348         proxyflag=""
349         if [ ! -z "$KUBE_PROXY_PATH" ]; then
350                 if [ $KUBE_PROXY_HTTPX == "http" ]; then
351                         proxyflag=" --proxy $KUBE_PROXY_PATH"
352                 else
353                         proxyflag=" --proxy-insecure --proxy $KUBE_PROXY_PATH"
354                 fi
355         fi
356     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"
357     echo "  CMD: "$curlString >> $HTTPLOG
358     res=$($curlString)
359     retcode=$?
360     echo "  RESP: "$res >> $HTTPLOG
361     if [ $retcode -ne 0 ]; then
362         echo "  RETCODE: "$retcode >> $HTTPLOG
363         echo "000"
364         return 1
365     fi
366
367         status=${res:${#res}-3}
368
369     if [ $status -ne 200 ]; then
370         echo "000"
371         return 1
372     fi
373     body=${res:0:${#res}-3}
374         echo "  JSON: "$body >> $HTTPLOG
375         reply="./tmp/.sdnc-reply.json"
376     echo "$body" > $reply
377     res=$(python3 ../common/extract_sdnc_reply.py $SDNC_RESPONSE_JSON_KEY $reply)
378     echo "  EXTRACED BODY+CODE: "$res >> $HTTPLOG
379     echo "$res"
380     return 0
381 }
382
383 # Controller API Test function: getA1Policy (return ids only)
384 # arg: <response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )
385 # (Function for test scripts)
386 controller_api_get_A1_policy_ids() {
387         __log_test_start $@
388
389         ric_id=$(__find_sim_host $3)
390     paramError=1
391     if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
392         url="$ric_id/a1-p/policytypes/$4/policies"
393                 paramError=0
394     elif [ $# -gt 2 ] && [ $2 == "STD" ]; then
395         url="$ric_id/A1-P/v1/policies"
396         paramError=0
397         fi
398
399     if [ $paramError -ne 0 ]; then
400                 __print_err "<response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )" $@
401                 return 1
402         fi
403
404     res=$(__do_curl_to_controller getA1Policy "$url")
405     retcode=$?
406     status=${res:${#res}-3}
407
408     if [ $retcode -ne 0 ]; then
409                 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
410                 return 1
411         fi
412
413         if [ $status -ne $1 ]; then
414                 __log_test_fail_status_code $1 $status
415                 return 1
416         fi
417     body=${res:0:${#res}-3}
418
419         targetJson="["
420     start=4
421     if [ $2 == "OSC" ]; then
422         start=5
423     fi
424     for pid in ${@:$start} ; do
425         if [ "$targetJson" != "[" ]; then
426             targetJson=$targetJson","
427         fi
428         targetJson=$targetJson"\"$UUID$pid\""
429     done
430     targetJson=$targetJson"]"
431
432         echo " TARGET JSON: $targetJson" >> $HTTPLOG
433
434         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
435
436         if [ $res -ne 0 ]; then
437                 __log_test_fail_body
438                 return 1
439         fi
440
441         __log_test_pass
442         return 0
443 }
444
445
446 # Controller API Test function: getA1PolicyType
447 # arg: <response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]
448 # (Function for test scripts)
449 controller_api_get_A1_policy_type() {
450         __log_test_start $@
451
452         ric_id=$(__find_sim_host $3)
453     paramError=1
454     if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
455         url="$ric_id/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=$(__find_sim_host $3)
504     paramError=1
505     if [ $# -eq 5 ] && [ $2 == "OSC" ]; then
506         url="$ric_id/a1-p/policytypes/$4/policies/$UUID$5"
507                 paramError=0
508     elif [ $# -eq 4 ] && [ $2 == "STD" ]; then
509         url="$ric_id/A1-P/v1/policies/$UUID$4"
510         paramError=0
511         fi
512
513     if [ $paramError -ne 0 ]; then
514                 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
515                 return 1
516         fi
517
518     res=$(__do_curl_to_controller deleteA1Policy "$url")
519     retcode=$?
520     status=${res:${#res}-3}
521
522     if [ $retcode -ne 0 ]; then
523                 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
524                 return 1
525         fi
526
527         if [ $status -ne $1 ]; then
528                 __log_test_fail_status_code $1 $status
529                 return 1
530         fi
531
532         __log_test_pass
533         return 0
534 }
535
536 # Controller API Test function: putA1Policy
537 # arg: <response-code> (STD <ric-id> <policy-id> <template-file> ) | (OSC <ric-id> <policy-type-id> <policy-id> <template-file>)
538 # (Function for test scripts)
539 controller_api_put_A1_policy() {
540         __log_test_start $@
541
542         ric_id=$(__find_sim_host $3)
543     paramError=1
544     if [ $# -eq 6 ] && [ $2 == "OSC" ]; then
545         url="$ric_id/a1-p/policytypes/$4/policies/$UUID$5"
546         body=$(sed 's/XXX/'${5}'/g' $6)
547
548                 paramError=0
549     elif [ $# -eq 5 ] && [ $2 == "STD" ]; then
550         url="$ric_id/A1-P/v1/policies/$UUID$4"
551         body=$(sed 's/XXX/'${4}'/g' $5)
552         paramError=0
553         fi
554
555     if [ $paramError -ne 0 ]; then
556                 __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@
557                 return 1
558         fi
559
560     res=$(__do_curl_to_controller putA1Policy "$url" "$body")
561     retcode=$?
562     status=${res:${#res}-3}
563
564     if [ $retcode -ne 0 ]; then
565                 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
566                 return 1
567         fi
568
569         if [ $status -ne $1 ]; then
570                 __log_test_fail_status_code $1 $status
571                 return 1
572         fi
573
574         __log_test_pass
575         return 0
576 }
577
578
579 # Controller API Test function: getA1PolicyStatus
580 # arg: <response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>)
581 # (Function for test scripts)
582 controller_api_get_A1_policy_status() {
583         __log_test_start $@
584
585         ric_id=$(__find_sim_host $3)
586     targetJson=""
587     paramError=1
588     if [ $# -ge 5 ] && [ $2 == "OSC" ]; then
589         url="$ric_id/a1-p/policytypes/$4/policies/$UUID$5/status"
590         if [ $# -gt 5 ]; then
591             targetJson="{\"instance_status\":\"$6\""
592             targetJson=$targetJson",\"has_been_deleted\":\"$7\""
593             targetJson=$targetJson",\"created_at\":\"????\"}"
594         fi
595                 paramError=0
596     elif [ $# -ge 4 ] && [ $2 == "STD" ]; then
597         url="$ric_id/A1-P/v1/policies/$UUID$4/status"
598         if [ $# -gt 4 ]; then
599             targetJson="{\"enforceStatus\":\"$5\""
600             if [ $# -eq 6 ]; then
601                 targetJson=$targetJson",\"reason\":\"$6\""
602             fi
603             targetJson=$targetJson"}"
604         fi
605         paramError=0
606         fi
607
608     if [ $paramError -ne 0 ]; then
609                 __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>)" $@
610                 return 1
611         fi
612
613     res=$(__do_curl_to_controller getA1PolicyStatus "$url")
614     retcode=$?
615     status=${res:${#res}-3}
616
617     if [ $retcode -ne 0 ]; then
618                 __log_test_fail_status_code $1 $retcode "(likely remote server error)"
619                 return 1
620         fi
621
622         if [ $status -ne $1 ]; then
623                 __log_test_fail_status_code $1 $status
624                 return 1
625         fi
626
627         if [ ! -z "$targetJson" ]; then
628
629                 body=${res:0:${#res}-3}
630                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
631                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
632
633                 if [ $res -ne 0 ]; then
634                         __log_test_fail_body
635                         return 1
636                 fi
637         fi
638
639         __log_test_pass
640         return 0
641 }
642
643 # Wait for http status on url
644 # args: <response-code> <ric-id>
645 # (Function for test scripts)
646 controller_api_wait_for_status_ok() {
647         __log_conf_start $@
648
649     if [ $# -ne 2 ]; then
650                 __print_err "<response-code> <ric-id> " $@
651                 return 1
652         fi
653         ric_id=$(__find_sim_host $2)
654     url="$ric_id/"
655
656         TS_START=$SECONDS
657         while [ $(($TS_START+500)) -gt $SECONDS ]; do
658                 echo -ne " Waiting for http status $1 on $url via sdnc, waited: $(($SECONDS-$TS_START))"$SAMELINE
659                 res=$(__do_curl_to_controller getA1Policy "$url")
660                 retcode=$?
661                 status=${res:${#res}-3}
662                 if [ $retcode -eq 0 ]; then
663                         if [ $status -eq $1 ]; then
664                                 echo ""
665                                 __log_conf_ok
666                                 return 0
667                         fi
668                 fi
669                 sleep 5
670         done
671         echo ""
672         __log_conf_fail_general
673         return 1
674 }