Doc update with j-release links (master branch)
[nonrtric.git] / test / common / a1pms_api_functions.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2021-2023 Nordix Foundation. All rights reserved.
5 #  Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
6 #  ========================================================================
7 #  Licensed under the Apache License, Version 2.0 (the "License");
8 #  you may not use this file except in compliance with the License.
9 #  You may obtain a copy of the License at
10 #
11 #       http://www.apache.org/licenses/LICENSE-2.0
12 #
13 #  Unless required by applicable law or agreed to in writing, software
14 #  distributed under the License is distributed on an "AS IS" BASIS,
15 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 #  See the License for the specific language governing permissions and
17 #  limitations under the License.
18 #  ============LICENSE_END=================================================
19 #
20
21 # This is a script that contains management and test functions for A1PMS
22
23 ################ Test engine functions ################
24
25 # Create the image var used during the test
26 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
27 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
28 __A1PMS_imagesetup() {
29   __check_and_create_image_var A1PMS "A1PMS_IMAGE" "A1PMS_IMAGE_BASE" "A1PMS_IMAGE_TAG" $1 "$A1PMS_DISPLAY_NAME" ""
30 }
31
32 # Pull image from remote repo or use locally built image
33 # arg: <pull-policy-override> <pull-policy-original>
34 # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
35 # <pull-policy-original> Shall be used for images that does not allow overriding
36 # Both var may contain: 'remote', 'remote-remove' or 'local'
37 __A1PMS_imagepull() {
38   __check_and_pull_image $1 "$A1PMS_DISPLAY_NAME" $A1PMS_APP_NAME A1PMS_IMAGE
39 }
40
41 # Build image (only for simulator or interfaces stubs owned by the test environment)
42 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
43 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
44 __A1PMS_imagebuild() {
45   echo -e $RED" Image for app A1PMS shall never be built"$ERED
46 }
47
48 # Generate a string for each included image using the app display name and a docker images format string
49 # If a custom image repo is used then also the source image from the local repo is listed
50 # arg: <docker-images-format-string> <file-to-append>
51 __A1PMS_image_data() {
52   echo -e "$A1PMS_DISPLAY_NAME\t$(docker images --format $1 $A1PMS_IMAGE)" >>$2
53   if [ ! -z "$A1PMS_IMAGE_SOURCE" ]; then
54     echo -e "-- source image --\t$(docker images --format $1 $A1PMS_IMAGE_SOURCE)" >>$2
55   fi
56 }
57
58 # Scale kubernetes resources to zero
59 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
60 # This function is called for apps fully managed by the test script
61 __A1PMS_kube_scale_zero() {
62   __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
63 }
64
65 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
66 # This function is called for pre-started apps not managed by the test script.
67 __A1PMS_kube_scale_zero_and_wait() {
68   __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-policymanagementservice
69 }
70
71 # Delete all kube resources for the app
72 # This function is called for apps managed by the test script.
73 __A1PMS_kube_delete_all() {
74   __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
75 }
76
77 # Store docker logs
78 # This function is called for apps managed by the test script.
79 # args: <log-dir> <file-prefix>
80 __A1PMS_store_docker_logs() {
81   if [ $RUNMODE == "KUBE" ]; then
82     kubectl $KUBECONF logs -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 >$1$2_a1pms.log 2>&1
83   else
84     docker logs $A1PMS_APP_NAME >$1$2_a1pms.log 2>&1
85   fi
86 }
87
88 # Initial setup of protocol, host and ports
89 # This function is called for apps managed by the test script.
90 # args: -
91 __A1PMS_initial_setup() {
92   use_a1pms_rest_http
93   export A1PMS_SIDECAR_JWT_FILE=""
94 }
95
96 # Set app short-name, app name and namespace for logging runtime statistics of kubernetes pods or docker containers
97 # For docker, the namespace shall be excluded
98 # This function is called for apps managed by the test script as well as for pre-started apps.
99 # args: -
100 __A1PMS_statistics_setup() {
101   if [ $RUNMODE == "KUBE" ]; then
102     echo "A1PMS $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
103   else
104     echo "A1PMS $A1PMS_APP_NAME"
105   fi
106 }
107
108 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
109 # args: -
110 __A1PMS_test_requirements() {
111   :
112 }
113
114 #######################################################
115
116 ###########################
117 ### A1PMSs functions
118 ###########################
119
120 # Set http as the protocol to use for all communication to the A1PMS
121 # args: -
122 # (Function for test scripts)
123 use_a1pms_rest_http() {
124   __a1pms_set_protocoll "http" $A1PMS_INTERNAL_PORT $A1PMS_EXTERNAL_PORT
125 }
126
127 # Set https as the protocol to use for all communication to the A1PMS
128 # args: -
129 # (Function for test scripts)
130 use_a1pms_rest_https() {
131   __a1pms_set_protocoll "https" $A1PMS_INTERNAL_SECURE_PORT $A1PMS_EXTERNAL_SECURE_PORT
132 }
133
134 # All calls to the a1pms will be directed to the a1pms dmaap interface over http from now on
135 # args: -
136 # (Function for test scripts)
137 use_a1pms_dmaap_http() {
138   echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
139   echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
140   A1PMS_ADAPTER_TYPE="MR-HTTP"
141   echo ""
142 }
143
144 # All calls to the a1pms will be directed to the a1pms dmaap interface over https from now on
145 # args: -
146 # (Function for test scripts)
147 use_a1pms_dmaap_https() {
148   echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
149   echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
150   echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
151   A1PMS_ADAPTER_TYPE="MR-HTTPS"
152   echo ""
153 }
154
155 # Setup paths to svc/container for internal and external access
156 # args: <protocol> <internal-port> <external-port>
157 __a1pms_set_protocoll() {
158   echo -e $BOLD"$A1PMS_DISPLAY_NAME protocol setting"$EBOLD
159   echo -e " Using $BOLD $1 $EBOLD towards $A1PMS_DISPLAY_NAME"
160
161   ## Access to Dmaap adapter
162
163   A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME":"$2 # docker access, container->container and script->container via proxy
164   if [ $RUNMODE == "KUBE" ]; then
165     A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
166   fi
167
168   # A1PMS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
169   A1PMS_ADAPTER_TYPE="REST"
170   A1PMS_ADAPTER=$A1PMS_SERVICE_PATH
171
172   echo ""
173 }
174
175 # Make curl retries towards the a1pms for http response codes set in this env var, space separated list of codes
176 A1PMS_RETRY_CODES=""
177
178 #Save first worker node the pod is started on
179 __A1PMS_WORKER_NODE=""
180
181 # Export env vars for config files, docker compose and kube resources
182 # args: PROXY|NOPROXY
183 __export_a1pms_vars() {
184
185   export A1PMS_APP_NAME
186   export A1PMS_APP_NAME_ALIAS
187   export A1PMS_DISPLAY_NAME
188
189   export KUBE_NONRTRIC_NAMESPACE
190   export A1PMS_IMAGE
191   export A1PMS_INTERNAL_PORT
192   export A1PMS_INTERNAL_SECURE_PORT
193   export A1PMS_EXTERNAL_PORT
194   export A1PMS_EXTERNAL_SECURE_PORT
195   export A1PMS_CONFIG_MOUNT_PATH
196   export A1PMS_DATA_MOUNT_PATH
197   export A1PMS_CONFIG_CONFIGMAP_NAME=$A1PMS_APP_NAME"-config"
198   export A1PMS_DATA_CONFIGMAP_NAME=$A1PMS_APP_NAME"-data"
199   export A1PMS_PKG_NAME
200   export A1PMS_CONFIG_KEY
201   export DOCKER_SIM_NWNAME
202   export A1PMS_HOST_MNT_DIR
203   export A1PMS_CONFIG_FILE
204
205   export A1PMS_DATA_PV_NAME=$A1PMS_APP_NAME"-pv"
206   export A1PMS_DATA_PVC_NAME=$A1PMS_APP_NAME"-pvc"
207   ##Create a unique path for the pv each time to prevent a previous volume to be reused
208   export A1PMS_PV_PATH="a1pmsdata-"$(date +%s)
209   export A1PMS_CONTAINER_MNT_DIR
210   export HOST_PATH_BASE_DIR
211
212   if [ $1 == "PROXY" ]; then
213     export A1PMS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT           #Set if proxy is started
214     export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
215     if [ $A1PMS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$A1PMS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
216       echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
217     else
218       echo " Configured with http proxy"
219     fi
220   else
221     export A1PMS_HTTP_PROXY_CONFIG_PORT=0
222     export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=""
223     echo " Configured without http proxy"
224   fi
225 }
226
227 # Start the ms
228 # args: (docker) PROXY|NOPROXY <config-file>
229 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
230 # (Function for test scripts)
231 start_a1pms() {
232   echo -e $BOLD"Starting $A1PMS_DISPLAY_NAME"$EBOLD
233
234   if [ $RUNMODE == "KUBE" ]; then
235
236     # Check if app shall be fully managed by the test script
237     __check_included_image "A1PMS"
238     retcode_i=$?
239
240     # Check if app shall only be used by the test script
241     __check_prestarted_image "A1PMS"
242     retcode_p=$?
243
244     if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
245       echo -e $RED"The $A1PMS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
246       echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
247       exit
248     fi
249     if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
250       echo -e $RED"The $A1PMS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
251       echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
252       exit
253     fi
254
255     if [ $retcode_p -eq 0 ]; then
256       echo -e " Using existing $A1PMS_APP_NAME deployment and service"
257       echo " Setting $A1PMS_APP_NAME replicas=1"
258       res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
259       __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
260     fi
261
262     if [ $retcode_i -eq 0 ]; then
263
264       echo -e " Creating $A1PMS_APP_NAME app and expose service"
265
266       #Check if nonrtric namespace exists, if not create it
267       __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
268
269       __export_a1pms_vars $1
270
271       # Create config map for config
272       configfile=$PWD/tmp/$A1PMS_CONFIG_FILE
273       cp $2 $configfile
274       output_yaml=$PWD/tmp/a1pms-cfc.yaml
275       __kube_create_configmap $A1PMS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $configfile $output_yaml
276
277       # Create config map for data
278       data_json=$PWD/tmp/$A1PMS_DATA_FILE
279       if [ $# -lt 3 ]; then
280         #create empty dummy file
281         echo "{}" >$data_json
282       else
283         cp $3 $data_json
284       fi
285       output_yaml=$PWD/tmp/a1pms-cfd.yaml
286       __kube_create_configmap $A1PMS_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
287
288       ## Create pv
289       input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pv.yaml
290       output_yaml=$PWD/tmp/a1pms-pv.yaml
291       __kube_create_instance pv $A1PMS_APP_NAME $input_yaml $output_yaml
292
293       ## Create pvc
294       input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pvc.yaml
295       output_yaml=$PWD/tmp/a1pms-pvc.yaml
296       __kube_create_instance pvc $A1PMS_APP_NAME $input_yaml $output_yaml
297
298       # Create service
299       input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"svc.yaml
300       output_yaml=$PWD/tmp/a1pmssvc.yaml
301       __kube_create_instance service $A1PMS_APP_NAME $input_yaml $output_yaml
302
303       # Create app
304       input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"app.yaml
305       output_yaml=$PWD/tmp/a1pmsapp.yaml
306       if [ -z "$A1PMS_SIDECAR_JWT_FILE" ]; then
307         cat $input_yaml | sed '/#A1PMS_JWT_START/,/#A1PMS_JWT_STOP/d' >$PWD/tmp/a1pmsapp_tmp.yaml
308         input_yaml=$PWD/tmp/a1pmsapp_tmp.yaml
309       fi
310       __kube_create_instance app $A1PMS_APP_NAME $input_yaml $output_yaml
311
312     fi
313
314     # Keep the initial worker node in case the pod need to be "restarted" - must be made to the same node due to a volume mounted on the host
315     if [ $retcode_i -eq 0 ]; then
316       __A1PMS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
317       if [ -z "$__A1PMS_WORKER_NODE" ]; then
318         echo -e $YELLOW" Cannot find worker node for pod for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
319       fi
320     else
321       echo -e $YELLOW" Persistency may not work for app $A1PMS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
322     fi
323
324     __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
325
326   else
327     __check_included_image 'A1PMS'
328     if [ $? -eq 1 ]; then
329       echo -e $RED"The A1PMS app is not included in this test script"$ERED
330       echo -e $RED"The A1PMS will not be started"$ERED
331       exit
332     fi
333
334     curdir=$PWD
335     cd $SIM_GROUP
336     cd a1pms
337     cd $A1PMS_HOST_MNT_DIR
338     #cd ..
339     if [ -d db ]; then
340       if [ "$(ls -A $DIR)" ]; then
341         echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
342         rm -rf db/* &>/dev/null
343         if [ $? -ne 0 ]; then
344           echo -e $RED" Cannot remove database files in: $PWD"$ERED
345           exit 1
346         fi
347       fi
348     else
349       echo " No files in mounted dir or dir does not exists"
350       mkdir db
351     fi
352     cd $curdir
353
354     __export_a1pms_vars $1
355
356     dest_file=$SIM_GROUP/$A1PMS_COMPOSE_DIR/$A1PMS_HOST_MNT_DIR/application.yaml
357
358     envsubst <$2 >$dest_file
359
360     __start_container $A1PMS_COMPOSE_DIR "" NODOCKERARGS 1 $A1PMS_APP_NAME
361
362     __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
363   fi
364
365   __collect_endpoint_stats_image_info "A1PMS" $A1PMS_IMAGE
366   echo ""
367   return 0
368 }
369
370 # Stop the a1pms
371 # args: -
372 # args: -
373 # (Function for test scripts)
374 stop_a1pms() {
375   echo -e $BOLD"Stopping $A1PMS_DISPLAY_NAME"$EBOLD
376
377   if [ $RUNMODE == "KUBE" ]; then
378
379     __check_prestarted_image "A1PMS"
380     if [ $? -eq 0 ]; then
381       echo -e $YELLOW" Persistency may not work for app $A1PMS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
382       res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
383       __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
384       return 0
385     fi
386     __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
387     echo "  Deleting the replica set - a new will be started when the app is started"
388     tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
389     if [ $? -ne 0 ]; then
390       echo -e $RED" Could not delete replica set "$RED
391       ((RES_CONF_FAIL++))
392       return 1
393     fi
394   else
395     docker stop $A1PMS_APP_NAME &>./tmp/.dockererr
396     if [ $? -ne 0 ]; then
397       __print_err "Could not stop $A1PMS_APP_NAME" $@
398       cat ./tmp/.dockererr
399       ((RES_CONF_FAIL++))
400       return 1
401     fi
402   fi
403   echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
404   echo ""
405   return 0
406 }
407
408 # Start a previously stopped a1pms
409 # args: -
410 # (Function for test scripts)
411 start_stopped_a1pms() {
412   echo -e $BOLD"Starting (the previously stopped) $A1PMS_DISPLAY_NAME"$EBOLD
413
414   if [ $RUNMODE == "KUBE" ]; then
415
416     __check_prestarted_image "A1PMS"
417     if [ $? -eq 0 ]; then
418       echo -e $YELLOW" Persistency may not work for app $A1PMS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
419       res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
420       __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
421       __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
422       return 0
423     fi
424
425     # Tie the A1PMS to the same worker node it was initially started on
426     # A PVC of type hostPath is mounted to A1PMS, for persistent storage, so the A1PMS must always be on the node which mounted the volume
427     if [ -z "$__A1PMS_WORKER_NODE" ]; then
428       echo -e $RED" No initial worker node found for pod "$RED
429       ((RES_CONF_FAIL++))
430       return 1
431     else
432       echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__A1PMS_WORKER_NODE to deployment for $A1PMS_APP_NAME. Pod will always run on this worker node: $__A1PMS_WORKER_NODE"$BOLD
433       echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
434       tmp=$(kubectl $KUBECONF patch deployment $A1PMS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__A1PMS_WORKER_NODE'"}}}}}')
435       if [ $? -ne 0 ]; then
436         echo -e $YELLOW" Cannot set nodeSelector to deployment for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
437       fi
438       __kube_scale deployment $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
439     fi
440   else
441     docker start $A1PMS_APP_NAME &>./tmp/.dockererr
442     if [ $? -ne 0 ]; then
443       __print_err "Could not start (the stopped) $A1PMS_APP_NAME" $@
444       cat ./tmp/.dockererr
445       ((RES_CONF_FAIL++))
446       return 1
447     fi
448   fi
449   __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
450   if [ $? -ne 0 ]; then
451     return 1
452   fi
453   echo ""
454   return 0
455 }
456
457 # Function to prepare the a1pms configuration according to the current simulator configuration
458 # args: SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]
459 # (Function for test scripts)
460 prepare_a1pms_config() {
461   echo -e $BOLD"Prepare A1PMS config"$EBOLD
462
463   echo " Writing a1pms config for "$A1PMS_APP_NAME" to file: "$2
464
465   if [ $# != 2 ] && [ $# != 4 ]; then
466     ((RES_CONF_FAIL++))
467     __print_err "need two or four args,  SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]" $@
468     exit 1
469   fi
470
471   if [ $1 == "SDNC" ]; then
472     echo -e " Config$BOLD including SDNC$EBOLD configuration"
473   elif [ $1 == "NOSDNC" ]; then
474     echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
475   else
476     ((RES_CONF_FAIL++))
477     __print_err "need three args,  SDNC|NOSDNC <output-file> HEADER|NOHEADER" $@
478     exit 1
479   fi
480
481   config_json="\n            {"
482   if [ $1 == "SDNC" ]; then
483     config_json=$config_json"\n   \"controller\": ["
484     config_json=$config_json"\n                     {"
485     config_json=$config_json"\n                       \"name\": \"$SDNC_APP_NAME\","
486     config_json=$config_json"\n                       \"baseUrl\": \"$SDNC_SERVICE_PATH\","
487     config_json=$config_json"\n                       \"userName\": \"$SDNC_USER\","
488     config_json=$config_json"\n                       \"password\": \"$SDNC_PWD\""
489     config_json=$config_json"\n                     }"
490     config_json=$config_json"\n   ],"
491   fi
492   if [[ "$A1PMS_FEATURE_LEVEL" == *"NO-DMAAP"* ]]; then
493     :
494   else
495     config_json=$config_json"\n   \"streams_publishes\": {"
496     config_json=$config_json"\n                            \"dmaap_publisher\": {"
497     config_json=$config_json"\n                              \"type\": \"message-router\","
498     config_json=$config_json"\n                              \"dmaap_info\": {"
499     config_json=$config_json"\n                                \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
500     config_json=$config_json"\n                              }"
501     config_json=$config_json"\n                            }"
502     config_json=$config_json"\n   },"
503     config_json=$config_json"\n   \"streams_subscribes\": {"
504     config_json=$config_json"\n                             \"dmaap_subscriber\": {"
505     config_json=$config_json"\n                               \"type\": \"message-router\","
506     config_json=$config_json"\n                               \"dmaap_info\": {"
507     config_json=$config_json"\n                                   \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
508     config_json=$config_json"\n                                 }"
509     config_json=$config_json"\n                               }"
510     config_json=$config_json"\n   },"
511   fi
512
513   config_json=$config_json"\n   \"ric\": ["
514
515   if [ $RUNMODE == "KUBE" ]; then
516     result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
517     rics=""
518     ric_cntr=0
519     if [ $? -eq 0 ] && [ ! -z "$result" ]; then
520       for im in $result; do
521         if [[ $im != *"-0" ]]; then
522           ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
523           rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
524           let ric_cntr=ric_cntr+1
525         fi
526       done
527     fi
528     result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICMEDIATORSIM")].metadata.name}')
529     oranrics=""
530     if [ $? -eq 0 ] && [ ! -z "$result" ]; then
531       for im in $result; do
532         if [[ $im != *"-0" ]]; then
533           ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
534           rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
535           oranrics=$oranrics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
536           let ric_cntr=ric_cntr+1
537         fi
538       done
539     fi
540     if [ $ric_cntr -eq 0 ]; then
541       echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
542     fi
543   else
544     rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=a1sim" --filter "status=running" --format {{.Names}})
545     oranrics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=orana1sim" --filter "status=running" --format {{.Names}})
546
547     rics="$rics $oranrics"
548
549     if [ $? -ne 0 ] || [ -z "$rics" ]; then
550       echo -e $RED" FAIL - the names of the running RIC Simulator or ORAN RIC cannot be retrieved." $ERED
551       ((RES_CONF_FAIL++))
552       exit 1
553     fi
554   fi
555   cntr=0
556   for ric in $rics; do
557     if [ $cntr -gt 0 ]; then
558       config_json=$config_json"\n          ,"
559     fi
560     config_json=$config_json"\n          {"
561     if [ $RUNMODE == "KUBE" ]; then
562       ric_id=${ric%.*.*} #extract pod id from full hosthame
563       ric_id=$(echo "$ric_id" | tr '-' '_')
564     else
565       ric_id=$(echo "$ric" | tr '-' '_') #ric var still needs underscore as it is different from the container name
566     fi
567     echo " Found a1 sim: "$ric
568     config_json=$config_json"\n            \"name\": \"$ric_id\","
569
570     xricfound=0
571     for xric in $oranrics; do
572       if [ $xric == $ric ]; then
573         xricfound=1
574       fi
575     done
576     if [ $xricfound -eq 0 ]; then
577       config_json=$config_json"\n            \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
578     else
579       config_json=$config_json"\n            \"baseUrl\": \"$RICMEDIATOR_SIM_HTTPX://$ric:$RICMEDIATOR_SIM_PORT\","
580     fi
581     if [ ! -z "$3" ]; then
582       if [[ $ric == "$3"* ]]; then
583         config_json=$config_json"\n            \"customAdapterClass\": \"$4\","
584       fi
585     fi
586     if [ $1 == "SDNC" ]; then
587       config_json=$config_json"\n            \"controller\": \"$SDNC_APP_NAME\","
588     fi
589     config_json=$config_json"\n            \"managedElementIds\": ["
590     config_json=$config_json"\n              \"me1_$ric_id\","
591     config_json=$config_json"\n              \"me2_$ric_id\""
592     config_json=$config_json"\n            ]"
593     config_json=$config_json"\n          }"
594     let cntr=cntr+1
595   done
596
597   config_json=$config_json"\n           ]"
598   config_json=$config_json"\n}"
599
600   config_json="{\"config\":"$config_json"}"
601
602   printf "$config_json" >$2
603
604   echo ""
605 }
606
607 # Load the the appl config for the a1pms into a config map
608 a1pms_load_config() {
609   echo -e $BOLD"A1PMS - load config from "$EBOLD$1
610   data_json=$PWD/tmp/$A1PMS_DATA_FILE
611   cp $1 $data_json
612   output_yaml=$PWD/tmp/a1pms-cfd.yaml
613   __kube_create_configmap $A1PMS_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
614   echo ""
615 }
616
617 # Turn on debug level tracing in the a1pms
618 # args: -
619 # (Function for test scripts)
620 set_a1pms_debug() {
621   echo -e $BOLD"Setting a1pms debug logging"$EBOLD
622   curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
623   result=$(__do_curl "$curlString")
624   if [ $? -ne 0 ]; then
625     __print_err "could not set debug mode" $@
626     ((RES_CONF_FAIL++))
627     return 1
628   fi
629   echo ""
630   return 0
631 }
632
633 # Turn on trace level tracing in the a1pms
634 # args: -
635 # (Function for test scripts)
636 set_a1pms_trace() {
637   echo -e $BOLD"Setting a1pms trace logging"$EBOLD
638   curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
639   result=$(__do_curl "$curlString")
640   if [ $? -ne 0 ]; then
641     __print_err "could not set trace mode" $@
642     ((RES_CONF_FAIL++))
643     return 1
644   fi
645   echo ""
646   return 0
647 }
648
649 # Perform curl retries when making direct call to the a1pms for the specified http response codes
650 # Speace separated list of http response codes
651 # args: [<response-code>]*
652 use_a1pms_retries() {
653   echo -e $BOLD"Do curl retries to the a1pms REST inteface for these response codes:$@"$EBOLD
654   AGENT_RETRY_CODES=$@
655   echo ""
656   return
657 }
658
659 # Check the a1pms logs for WARNINGs and ERRORs
660 # args: -
661 # (Function for test scripts)
662 check_a1pms_logs() {
663   __check_container_logs "A1PMS" $A1PMS_APP_NAME $A1PMS_LOGPATH WARN ERR
664 }
665
666 #########################################################
667 #### Test case functions A1 Policy management service
668 #########################################################
669
670 # This function compare the size, towards a target value, of a json array returned from <url> of the A1PMS.
671 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
672 # args: json:<url> <target-value> [<timeout-in-seconds]
673 # (Function for test scripts)
674 a1pms_equal() {
675   echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >>$HTTPLOG
676   if [ $# -eq 2 ] || [ $# -eq 3 ]; then
677     if [[ $1 == "json:"* ]]; then
678       if [ "$A1PMS_VERSION" == "V2" ]; then
679         __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v2/" $1 "=" $2 $3
680       elif [ "$A1PMS_VERSION" == "V3" ]; then
681         echo "var test execution for V3"
682         __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v1/" $1 "=" $2 $3
683       else
684         __var_test "A1PMS" $A1PMS_SERVICE_PATH"/" $1 "=" $2 $3
685       fi
686       return 0
687     fi
688   fi
689   __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
690   return 1
691 }
692
693 # API Test function: GET /policies and V2 GET /v2/policy-instances
694 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*]
695 # args(V2): <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <transient> <notification-url> <template-file>]*]
696 # (Function for test scripts)
697 a1pms_api_get_policies() {
698   __log_test_start $@
699
700   if [ "$A1PMS_VERSION" == "V2" ]; then
701     paramError=0
702     variableParams=$(($# - 4))
703     if [ $# -lt 4 ]; then
704       paramError=1
705     elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
706       paramError=1
707     elif [ $# -gt 5 ] && [ $(($variableParams % 7)) -ne 0 ]; then
708       paramError=1
709     fi
710
711     if [ $paramError -ne 0 ]; then
712       __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <transient> <notification-url> <template-file>]*]" $@
713       return 1
714     fi
715   else
716     paramError=0
717     variableParams=$(($# - 4))
718     if [ $# -lt 4 ]; then
719       paramError=1
720     elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
721       paramError=1
722     elif [ $# -gt 5 ] && [ $(($variableParams % 5)) -ne 0 ]; then
723       paramError=1
724     fi
725
726     if [ $paramError -ne 0 ]; then
727       __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*]" $@
728       return 1
729     fi
730   fi
731
732   queryparams=""
733   if [ "$A1PMS_VERSION" == "V2" ]; then
734     if [ $2 != "NORIC" ]; then
735       queryparams="?ric_id="$2
736     fi
737     if [ $3 != "NOSERVICE" ]; then
738       if [ -z $queryparams ]; then
739         queryparams="?service_id="$3
740       else
741         queryparams=$queryparams"&service_id="$3
742       fi
743     fi
744     if [ $4 != "NOTYPE" ]; then
745       if [ -z $queryparams ]; then
746         queryparams="?policytype_id="$4
747       else
748         queryparams=$queryparams"&policytype_id="$4
749       fi
750     fi
751
752     query="/v2/policy-instances"$queryparams
753     res="$(__do_curl_to_api A1PMS GET $query)"
754     status=${res:${#res}-3}
755
756     if [ $status -ne $1 ]; then
757       __log_test_fail_status_code $1 $status
758       return 1
759     fi
760
761     if [ $# -gt 4 ]; then
762       body=${res:0:${#res}-3}
763       if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
764         targetJson="["
765       else
766         targetJson="["
767         arr=(${@:5})
768
769         for ((i = 0; i < $(($# - 4)); i = i + 7)); do
770
771           if [ "$targetJson" != "[" ]; then
772             targetJson=$targetJson","
773           fi
774           targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i + 1]}\",\"service_id\":\"${arr[$i + 2]}\",\"policytype_id\":"
775           if [ "${arr[$i + 3]}" == "EMPTY" ]; then
776             targetJson=$targetJson"\"\","
777           else
778             targetJson=$targetJson"\"${arr[$i + 3]}\","
779           fi
780           targetJson=$targetJson"\"transient\":${arr[$i + 4]},\"status_notification_uri\":\"${arr[$i + 5]}\","
781           file="./tmp/.p.json"
782           sed 's/XXX/'${arr[$i]}'/g' ${arr[$i + 6]} >$file
783           json=$(cat $file)
784           targetJson=$targetJson"\"policy_data\":"$json"}"
785         done
786       fi
787
788       targetJson=$targetJson"]"
789       targetJson="{\"policies\": $targetJson}"
790       echo "TARGET JSON: $targetJson" >>$HTTPLOG
791       res=$(python3 ../common/compare_json.py "$targetJson" "$body")
792
793       if [ $res -ne 0 ]; then
794         __log_test_fail_body
795         return 1
796       fi
797     fi
798   else
799     if [ $2 != "NORIC" ]; then
800       queryparams="?ric="$2
801     fi
802     if [ $3 != "NOSERVICE" ]; then
803       if [ -z $queryparams ]; then
804         queryparams="?service="$3
805       else
806         queryparams=$queryparams"&service="$3
807       fi
808     fi
809     if [ $4 != "NOTYPE" ]; then
810       if [ -z $queryparams ]; then
811         queryparams="?type="$4
812       else
813         queryparams=$queryparams"&type="$4
814       fi
815     fi
816
817     query="/policies"$queryparams
818     res="$(__do_curl_to_api A1PMS GET $query)"
819     status=${res:${#res}-3}
820
821     if [ $status -ne $1 ]; then
822       __log_test_fail_status_code $1 $status
823       return 1
824     fi
825
826     if [ $# -gt 4 ]; then
827       if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
828         targetJson="["
829       else
830         body=${res:0:${#res}-3}
831         targetJson="["
832         arr=(${@:5})
833
834         for ((i = 0; i < $(($# - 4)); i = i + 5)); do
835
836           if [ "$targetJson" != "[" ]; then
837             targetJson=$targetJson","
838           fi
839           targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i + 1]}\",\"service\":\"${arr[$i + 2]}\",\"type\":"
840           if [ "${arr[$i + 3]}" == "EMPTY" ]; then
841             targetJson=$targetJson"\"\","
842           else
843             targetJson=$targetJson"\"${arr[$i + 3]}\","
844           fi
845           file="./tmp/.p.json"
846           sed 's/XXX/'${arr[$i]}'/g' ${arr[$i + 4]} >$file
847           json=$(cat $file)
848           targetJson=$targetJson"\"json\":"$json"}"
849         done
850       fi
851
852       targetJson=$targetJson"]"
853       echo "TARGET JSON: $targetJson" >>$HTTPLOG
854       res=$(python3 ../common/compare_json.py "$targetJson" "$body")
855
856       if [ $res -ne 0 ]; then
857         __log_test_fail_body
858         return 1
859       fi
860     fi
861   fi
862   __collect_endpoint_stats "A1PMS" 00 "GET" $A1PMS_API_PREFIX"/v2/policy-instances" $status
863   __log_test_pass
864   return 0
865
866 }
867
868 # API Test function: GET /policy, V2 GET /v2/policies/{policy_id} and V3 GET a1policymanagement/v1/policies/{policy_id}
869 # args: <response-code>  <policy-id> [<template-file>]
870 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
871 # (Function for test scripts)
872 a1pms_api_get_policy() {
873   __log_test_start $@
874
875   if [ "$A1PMS_VERSION" == "V2" ]; then
876     if [ $# -ne 2 ] && [ $# -ne 8 ]; then
877       __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
878       return 1
879     fi
880     query="/v2/policies/$UUID$2"
881   elif [ "$A1PMS_VERSION" == "V3" ]; then
882     if [ $# -ne 2 ] && [ $# -ne 8 ]; then
883       __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
884       return 1
885     fi
886     query="/v1/policies/$UUID$2"
887   else
888     if [ $# -lt 2 ] || [ $# -gt 3 ]; then
889       __print_err "<response-code>  <policy-id> [<template-file>] " $@
890       return 1
891     fi
892     query="/policy?id=$UUID$2"
893   fi
894   res="$(__do_curl_to_api A1PMS GET $query)"
895   status=${res:${#res}-3}
896
897   if [ $status -ne $1 ]; then
898     __log_test_fail_status_code $1 $status
899     return 1
900   fi
901
902   if [ "$A1PMS_VERSION" == "V2" ]; then
903     if [ $# -eq 8 ]; then
904
905       #Create a policy json to compare with
906       body=${res:0:${#res}-3}
907
908       targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
909       if [ $7 != "NOTRANSIENT" ]; then
910         targetJson=$targetJson", \"transient\":$7"
911       fi
912       if [ $6 != "NOTYPE" ]; then
913         targetJson=$targetJson", \"policytype_id\":\"$6\""
914       else
915         targetJson=$targetJson", \"policytype_id\":\"\""
916       fi
917       if [ $8 != "NOURL" ]; then
918         targetJson=$targetJson", \"status_notification_uri\":\"$8\""
919       fi
920
921       data=$(sed 's/XXX/'${2}'/g' $3)
922       targetJson=$targetJson", \"policy_data\":$data"
923       targetJson="{$targetJson}"
924
925       echo "TARGET JSON: $targetJson" >>$HTTPLOG
926       res=$(python3 ../common/compare_json.py "$targetJson" "$body")
927       if [ $res -ne 0 ]; then
928         __log_test_fail_body
929         return 1
930       fi
931     fi
932   elif [ "$A1PMS_VERSION" == "V3" ]; then
933     if [ $# -eq 8 ]; then
934       #Create a policy json to compare with
935       body=${res:0:${#res}-3}
936       data=$(sed 's/XXX/'${2}'/g' $3)
937       targetJson=$data
938
939       echo "TARGET JSON: $targetJson" >>$HTTPLOG
940       res=$(python3 ../common/compare_json.py "$targetJson" "$body")
941       if [ $res -ne 0 ]; then
942         __log_test_fail_body
943         return 1
944       fi
945     fi
946   else
947     if [ $# -eq 3 ]; then
948       #Create a policy json to compare with
949       body=${res:0:${#res}-3}
950       file="./tmp/.p.json"
951       sed 's/XXX/'${2}'/g' $3 >$file
952       targetJson=$(<$file)
953       echo "TARGET JSON: $targetJson" >>$HTTPLOG
954       res=$(python3 ../common/compare_json.py "$targetJson" "$body")
955       if [ $res -ne 0 ]; then
956         __log_test_fail_body
957       fi
958     fi
959   fi
960
961   __collect_endpoint_stats "A1PMS" 01 "GET" ${A1PMS_API_PREFIX}${query} ${status}
962   __log_test_pass
963   return 0
964 }
965
966 # API Test function: PUT /policy and V2 PUT /policies
967 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
968 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
969 # (Function for test scripts)
970 a1pms_api_put_policy() {
971   __log_test_start $@
972
973   if [ "$A1PMS_VERSION" == "V2" ] || [ "$A1PMS_VERSION" == "V3" ]; then
974     if [ $# -lt 8 ] || [ $# -gt 9 ]; then
975       __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
976       return 1
977     fi
978   else
979     if [ $# -lt 7 ] || [ $# -gt 8 ]; then
980       __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
981       return 1
982     fi
983   fi
984
985   count=0
986   max=1
987   serv=$2
988   ric=$3
989   pt=$4
990   pid=$5
991   trans=$6
992
993   if [ "$A1PMS_VERSION" == "V2" ]; then
994     noti=$7
995     temp=$8
996     if [ $# -eq 9 ]; then
997       max=$9
998     fi
999   else
1000     temp=$7
1001     if [ $# -eq 8 ]; then
1002       max=$8
1003     fi
1004   fi
1005
1006   while [ $count -lt $max ]; do
1007     if [ "$A1PMS_VERSION" == "V2" ]; then
1008
1009       query="/v2/policies"
1010
1011       inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1012       if [ $trans != "NOTRANSIENT" ]; then
1013         inputJson=$inputJson", \"transient\":$trans"
1014       fi
1015       if [ $pt != "NOTYPE" ]; then
1016         inputJson=$inputJson", \"policytype_id\":\"$pt\""
1017       else
1018         inputJson=$inputJson", \"policytype_id\":\"\""
1019       fi
1020       if [ $noti != "NOURL" ]; then
1021         inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1022       fi
1023       file="./tmp/.p.json"
1024       data=$(sed 's/XXX/'${pid}'/g' $temp)
1025       inputJson=$inputJson", \"policy_data\":$data"
1026       inputJson="{$inputJson}"
1027       echo $inputJson >$file
1028     else
1029       query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1030
1031       if [ $pt != "NOTYPE" ]; then
1032         query=$query"&type=$pt"
1033       fi
1034
1035       if [ $trans != NOTRANSIENT ]; then
1036         query=$query"&transient=$trans"
1037       fi
1038
1039       file="./tmp/.p.json"
1040       sed 's/XXX/'${pid}'/g' $temp >$file
1041     fi
1042     res="$(__do_curl_to_api A1PMS PUT $query $file)"
1043     status=${res:${#res}-3}
1044     echo -ne " Executing "$count"("$max")${SAMELINE}"
1045     if [ $status -ne $1 ]; then
1046       echo " Executed "$count"?("$max")"
1047       __log_test_fail_status_code $1 $status
1048       return 1
1049     fi
1050     let pid=$pid+1
1051     let count=$count+1
1052     echo -ne " Executed  "$count"("$max")${SAMELINE}"
1053   done
1054   __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${query} ${status} ${max}
1055   echo ""
1056
1057   __log_test_pass
1058   return 0
1059 }
1060
1061 # API Test function: V3 PUT a1policymanagement/v1/policies
1062 # args: <response-code>  <policy-id>  <template-file> [<count>]
1063 # args(V2): <response-code> <policy-id> <template-file> [<count>]
1064 # (Function for test scripts)
1065 a1pms_api_put_policy_v3() {
1066   __log_test_start $@
1067
1068   if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1069     __print_err "<response-code> <policy-id> <template-file> [<count>]" $@
1070     return 1
1071   fi
1072
1073   count=0
1074   max=1
1075   pid=$2
1076   temp=$3
1077
1078   if [ $# -eq 4 ]; then
1079     max=$4
1080   fi
1081
1082   while [ $count -lt $max ]; do
1083     query="/v1/policies/$UUID$pid"
1084     file="./tmp/.p_v3.json"
1085     let update_value=$pid+300
1086     data=$(sed 's/XXX/'${update_value}'/g' $temp)
1087     inputJson="$data"
1088     echo $inputJson >$file
1089     res="$(__do_curl_to_api A1PMS PUT $query $file)"
1090     status=${res:${#res}-3}
1091     echo -ne " Executing "$count"("$max")${SAMELINE}"
1092     if [ $status -ne $1 ]; then
1093       echo " Executed "$count"?("$max")"
1094       __log_test_fail_status_code $1 $status
1095       return 1
1096     fi
1097     let pid=$pid+1
1098     let count=$count+1
1099     echo -ne " Executed  "$count"("$max")${SAMELINE}"
1100   done
1101   __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${query} ${status} ${max}
1102   echo ""
1103
1104   __log_test_pass
1105   return 0
1106 }
1107
1108 # API Test function: V£ POST a1policymanagement/v1/policies
1109 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
1110 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
1111 # (Function for test scripts)
1112 a1pms_api_post_policy_v3() {
1113   __log_test_start $@
1114
1115   if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1116     __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
1117     return 1
1118   fi
1119
1120   count=0
1121   max=1
1122   serv=$2
1123   ric=$3
1124   pt=$4
1125   pid=$5
1126   trans=$6
1127   noti=$7
1128   temp=$8
1129   if [ $# -eq 9 ]; then
1130     max=$9
1131   fi
1132
1133   while [ $count -lt $max ]; do
1134     query="/v1/policies"
1135
1136     inputJson="\"nearRtRicId\":\"$ric\""
1137     if [ $pt != "NOTYPE" ]; then
1138       inputJson=$inputJson", \"policyTypeId\":\"$pt\""
1139     else
1140       inputJson=$inputJson", \"policyTypeId\":\"\""
1141     fi
1142     if [ $serv != "NOSERVICE" ]; then
1143       inputJson=$inputJson", \"serviceId\":\"$serv\""
1144     fi
1145     if [ $noti != "NONOTIFYURL" ]; then
1146       inputJson=$inputJson", \"statusNotificationUri\":\"$noti\""
1147     fi
1148     if [ $trans != "NOTRANSIENT" ]; then
1149       inputJson=$inputJson", \"transient\":\"$trans\""
1150     fi
1151     file="./tmp/.p.json"
1152     data=$(sed 's/XXX/'${pid}'/g' $temp)
1153     inputJson=$inputJson", \"policyObject\":$data"
1154     inputJson=$inputJson", \"policyId\":\"$UUID$pid\""
1155     inputJson="{$inputJson}"
1156     echo $inputJson >$file
1157     res="$(__do_curl_to_api A1PMS POST $query $file)"
1158     status=${res:${#res}-3}
1159     echo -ne " Executing "$count"("$max")${SAMELINE}"
1160     if [ $status -ne $1 ]; then
1161       echo " Executed "$count"?("$max")"
1162       __log_test_fail_status_code $1 $status
1163       return 1
1164     fi
1165     let pid=$pid+1
1166     let count=$count+1
1167     echo -ne " Executed  "$count"("$max")${SAMELINE}"
1168   done
1169   __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${A1PMS_VERSION} ${status} ${max}
1170   echo ""
1171
1172   __log_test_pass
1173   return 0
1174 }
1175
1176 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
1177 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1178 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
1179 # (Function for test scripts)
1180
1181 a1pms_api_put_policy_batch() {
1182   __log_test_start $@
1183
1184   if [ "$A1PMS_VERSION" == "V2" ]; then
1185     if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1186       __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1187       return 1
1188     fi
1189   else
1190     if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1191       __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1192       return 1
1193     fi
1194   fi
1195
1196   count=0
1197   max=1
1198   serv=$2
1199   ric=$3
1200   pt=$4
1201   pid=$5
1202   trans=$6
1203   if [ "$A1PMS_VERSION" == "V2" ]; then
1204     noti=$7
1205     temp=$8
1206     if [ $# -eq 9 ]; then
1207       max=$9
1208     fi
1209   else
1210     temp=$7
1211     if [ $# -eq 8 ]; then
1212       max=$8
1213     fi
1214   fi
1215
1216   ARR=""
1217   while [ $count -lt $max ]; do
1218     if [ "$A1PMS_VERSION" == "V2" ]; then
1219       query="/v2/policies"
1220
1221       inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1222       if [ $trans != "NOTRANSIENT" ]; then
1223         inputJson=$inputJson", \"transient\":$trans"
1224       fi
1225       if [ $pt != "NOTYPE" ]; then
1226         inputJson=$inputJson", \"policytype_id\":\"$pt\""
1227       else
1228         inputJson=$inputJson", \"policytype_id\":\"\""
1229       fi
1230       if [ $noti != "NOURL" ]; then
1231         inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1232       fi
1233       file="./tmp/.p.json"
1234       data=$(sed 's/XXX/'${pid}'/g' $temp)
1235       inputJson=$inputJson", \"policy_data\":$data"
1236       inputJson="{$inputJson}"
1237       echo $inputJson >$file
1238     else
1239       query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1240
1241       if [ $pt != "NOTYPE" ]; then
1242         query=$query"&type=$pt"
1243       fi
1244
1245       if [ $trans != NOTRANSIENT ]; then
1246         query=$query"&transient=$trans"
1247       fi
1248       file="./tmp/.p.json"
1249       sed 's/XXX/'${pid}'/g' $temp >$file
1250     fi
1251     res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)"
1252     status=${res:${#res}-3}
1253     echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1254
1255     if [ $status -ne 200 ]; then
1256       echo " Requested(batch) "$count"?("$max")"
1257       __log_test_fail_status_code 200 $status
1258       return 1
1259     fi
1260     cid=${res:0:${#res}-3}
1261     ARR=$ARR" "$cid
1262     let pid=$pid+1
1263     let count=$count+1
1264     echo -ne " Requested(batch)  "$count"("$max")${SAMELINE}"
1265   done
1266
1267   echo ""
1268   count=0
1269   for cid in $ARR; do
1270
1271     res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1272     status=${res:${#res}-3}
1273     echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
1274
1275     if [ $status -ne $1 ]; then
1276       echo " Accepted(batch) "$count"?("$max")"
1277       __log_test_fail_status_code $1 $status
1278       return 1
1279     fi
1280
1281     let count=$count+1
1282     echo -ne " Accepted(batch)  "$count"("$max")${SAMELINE}"
1283   done
1284   __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max
1285
1286   echo ""
1287
1288   __log_test_pass
1289   return 0
1290 }
1291
1292 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1293 # args: <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <template-file> <count-per-ric> <number-of-threads>
1294 # args(V2): <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>
1295 # (Function for test scripts)
1296 a1pms_api_put_policy_parallel() {
1297   __log_test_start $@
1298
1299   if [ "$A1PMS_VERSION" == "V2" ]; then
1300     if [ $# -ne 11 ]; then
1301       __print_err "These all arguments needed <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>" $@
1302       return 1
1303     fi
1304   fi
1305
1306   resp_code=$1
1307   shift
1308   serv=$1
1309   shift
1310   ric_base=$1
1311   shift
1312   num_rics=$1
1313   shift
1314   type=$1
1315   shift
1316   start_id=$1
1317   shift
1318   transient=$1
1319   shift
1320   if [ "$A1PMS_VERSION" == "V2" ]; then
1321     noti=$1
1322     shift
1323   else
1324     noti=""
1325   fi
1326   template=$1
1327   shift
1328   count=$1
1329   shift
1330   pids=$1
1331   shift
1332
1333   #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1334   if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1335     echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1336     echo " Info - will execute over a1pms REST"
1337   fi
1338   if [ "$A1PMS_VERSION" == "V2" ]; then
1339     if [ $serv == "NOSERVICE" ]; then
1340       serv=""
1341     fi
1342     query="$A1PMS_API_PREFIX/v2/policies"
1343   else
1344     if [ $serv == "NOSERVICE" ]; then
1345       serv=""
1346     fi
1347     query="/policy?service=$serv"
1348
1349     if [ $type != "NOTYPE" ]; then
1350       query=$query"&type=$type"
1351     fi
1352
1353     if [ $transient != NOTRANSIENT ]; then
1354       query=$query"&transient=$transient"
1355     fi
1356   fi
1357
1358   urlbase=${A1PMS_ADAPTER}${query}
1359
1360   httpproxy="NOPROXY"
1361   if [ ! -z "$KUBE_PROXY_PATH" ]; then
1362     httpproxy=$KUBE_PROXY_PATH
1363   fi
1364
1365   for ((i = 1; i <= $pids; i++)); do
1366     uuid=$UUID
1367     if [ -z "$uuid" ]; then
1368       uuid="NOUUID"
1369     fi
1370     echo "" >"./tmp/.pid${i}.res.txt"
1371     if [ "$A1PMS_VERSION" == "V2" ]; then
1372       echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1373     else
1374       echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1375     fi
1376     echo $i
1377   done | xargs -n 1 -I{} -P $pids bash -c '{
1378                 arg=$(echo {})
1379                 echo " Parallel process $arg started"
1380                 tmp=$(< "./tmp/.pid${arg}.txt")
1381                 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1382         }'
1383   msg=""
1384   for ((i = 1; i <= $pids; i++)); do
1385     file="./tmp/.pid${i}.res.txt"
1386     tmp=$(<$file)
1387     if [ -z "$tmp" ]; then
1388       echo " Process $i : unknown result (result file empty"
1389       msg="failed"
1390     else
1391       res=${tmp:0:1}
1392       if [ $res == "0" ]; then
1393         echo " Process $i : OK - "${tmp:1}
1394       else
1395         echo " Process $i : failed - "${tmp:1}
1396         msg="failed"
1397       fi
1398     fi
1399   done
1400   if [ -z $msg ]; then
1401     __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count * $num_rics))
1402     __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1403     return 0
1404   fi
1405   __log_test_fail_general "One of more processes failed to execute"
1406   return 1
1407 }
1408
1409 # API Test function: V3 POST /policies, to run in i parallel for a number of rics
1410 # args: <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <template-file> <count-per-ric> <number-of-threads>
1411 # args(V3): <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>
1412 # (Function for test scripts)
1413 a1pms_api_post_policy_parallel() {
1414   __log_test_start $@
1415
1416   if [ $# -ne 11 ]; then
1417     __print_err "These all arguments needed <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>" $@
1418     return 1
1419   fi
1420
1421   resp_code=$1
1422   shift
1423   serv=$1
1424   shift
1425   ric_base=$1
1426   shift
1427   num_rics=$1
1428   shift
1429   type=$1
1430   shift
1431   start_id=$1
1432   shift
1433   transient=$1
1434   shift
1435   noti=$1
1436   shift
1437   template=$1
1438   shift
1439   count=$1
1440   shift
1441   pids=$1
1442   shift
1443
1444   #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1445   if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1446     echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1447     echo " Info - will execute over a1pms REST"
1448   fi
1449
1450   if [ $serv == "NOSERVICE" ]; then
1451     serv=""
1452   fi
1453   query="$A1PMS_API_PREFIX/v1/policies"
1454
1455   urlbase=${A1PMS_ADAPTER}${query}
1456
1457   httpproxy="NOPROXY"
1458   if [ ! -z "$KUBE_PROXY_PATH" ]; then
1459     httpproxy=$KUBE_PROXY_PATH
1460   fi
1461
1462   for ((i = 1; i <= $pids; i++)); do
1463     uuid=$UUID
1464     if [ -z "$uuid" ]; then
1465       uuid="NOUUID"
1466     fi
1467     echo "" >"./tmp/.pid${i}.res.txt"
1468     echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1469     echo $i
1470   done | xargs -n 1 -I{} -P $pids bash -c '{
1471                 arg=$(echo {})
1472                 echo " Parallel process $arg started"
1473                 tmp=$(< "./tmp/.pid${arg}.txt")
1474                 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1475         }'
1476   msg=""
1477   for ((i = 1; i <= $pids; i++)); do
1478     file="./tmp/.pid${i}.res.txt"
1479     tmp=$(<$file)
1480     if [ -z "$tmp" ]; then
1481       echo " Process $i : unknown result (result file empty"
1482       msg="failed"
1483     else
1484       res=${tmp:0:1}
1485       if [ $res == "0" ]; then
1486         echo " Process $i : OK - "${tmp:1}
1487       else
1488         echo " Process $i : failed - "${tmp:1}
1489         msg="failed"
1490       fi
1491     fi
1492   done
1493   if [ -z $msg ]; then
1494     __collect_endpoint_stats "A1PMS" 02 "POST" $A1PMS_API_PREFIX"/v1/policies" $resp_code $(($count * $num_rics))
1495     __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1496     return 0
1497   fi
1498   __log_test_fail_general "One of more processes failed to execute"
1499   return 1
1500 }
1501
1502 # API Test function: V3 PUT /policies, to run in i parallel for a number of rics
1503 # args: <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <template-file> <count-per-ric> <number-of-threads> <policy-ids-file-path>
1504 # args(V3): <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads> <policy-ids-file-path>
1505 # (Function for test scripts)
1506 a1pms_api_update_policy_parallel() {
1507   __log_test_start $@
1508
1509   if [ $# -ne 12 ]; then
1510     __print_err "These all arguments needed <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads> <policy-ids-file-path>" $@
1511     return 1
1512   fi
1513
1514   resp_code=$1
1515   shift
1516   serv=$1
1517   shift
1518   ric_base=$1
1519   shift
1520   num_rics=$1
1521   shift
1522   type=$1
1523   shift
1524   start_id=$1
1525   shift
1526   transient=$1
1527   shift
1528   noti=$1
1529   shift
1530   template=$1
1531   shift
1532   count=$1
1533   shift
1534   pids=$1
1535   shift
1536   policy_ids_file_path=$1
1537   shift
1538
1539   #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1540   if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1541     echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1542     echo " Info - will execute over a1pms REST"
1543   fi
1544
1545   if [ $serv == "NOSERVICE" ]; then
1546     serv=""
1547   fi
1548   query="$A1PMS_API_PREFIX/v1/policies"
1549
1550   urlbase=${A1PMS_ADAPTER}${query}
1551
1552   httpproxy="NOPROXY"
1553   if [ ! -z "$KUBE_PROXY_PATH" ]; then
1554     httpproxy=$KUBE_PROXY_PATH
1555   fi
1556
1557   for ((i = 1; i <= $pids; i++)); do
1558     uuid=$UUID
1559     if [ -z "$uuid" ]; then
1560       uuid="NOUUID"
1561     fi
1562     echo "" >"./tmp/.pid${i}.res.txt"
1563     echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy $policy_ids_file_path >"./tmp/.pid${i}.txt"
1564     echo $i
1565   done | xargs -n 1 -I{} -P $pids bash -c '{
1566                 arg=$(echo {})
1567                 echo " Parallel process $arg started"
1568                 tmp=$(< "./tmp/.pid${arg}.txt")
1569       python3 ../common/update_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1570         }'
1571   msg=""
1572   for ((i = 1; i <= $pids; i++)); do
1573     file="./tmp/.pid${i}.res.txt"
1574     tmp=$(<$file)
1575     if [ -z "$tmp" ]; then
1576       echo " Process $i : unknown result (result file empty"
1577       msg="failed"
1578     else
1579       res=${tmp:0:1}
1580       if [ $res == "0" ]; then
1581         echo " Process $i : OK - "${tmp:1}
1582       else
1583         echo " Process $i : failed - "${tmp:1}
1584         msg="failed"
1585       fi
1586     fi
1587   done
1588   if [ -z $msg ]; then
1589     __collect_endpoint_stats "A1PMS" 02 "POST" $A1PMS_API_PREFIX"/v1/policies" $resp_code $(($count * $num_rics))
1590     __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1591     return 0
1592   fi
1593   __log_test_fail_general "One of more processes failed to execute"
1594   return 1
1595 }
1596
1597 # API Test function: DELETE /policy, V2 DELETE /v2/policies/{policy_id} and V3 DELETE a1policymanagement/v1/policies/{policy_id}
1598 # args: <response-code> <policy-id> [count]
1599 # (Function for test scripts)
1600 a1pms_api_delete_policy() {
1601   __log_test_start $@
1602
1603   if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1604     __print_err "<response-code> <policy-id> [count]" $@
1605     return 1
1606   fi
1607
1608   count=0
1609   max=1
1610
1611   if [ $# -eq 3 ]; then
1612     max=$3
1613   fi
1614
1615   pid=$2
1616
1617   while [ $count -lt $max ]; do
1618     if [ "$A1PMS_VERSION" == "V2" ]; then
1619       query="/v2/policies/"$UUID$pid
1620     elif [ "$A1PMS_VERSION" == "V3" ]; then
1621       query="/v1/policies/"$UUID$pid
1622     else
1623       query="/policy?id="$UUID$pid
1624     fi
1625     res="$(__do_curl_to_api A1PMS DELETE $query)"
1626     status=${res:${#res}-3}
1627     echo -ne " Executing "${count}"("${max}")${SAMELINE}"
1628
1629     if [ $status -ne $1 ]; then
1630       echo " Executed "${count}"?("${max}")"
1631       __log_test_fail_status_code $1 $status
1632       return 1
1633     fi
1634
1635     let pid=$pid+1
1636     let count=$count+1
1637     echo -ne " Executed  "${count}"("${max}")${SAMELINE}"
1638   done
1639   __collect_endpoint_stats "A1PMS" 03 "DELETE" ${A1PMS_API_PREFIX}${query} ${status} ${max}
1640   echo ""
1641
1642   __log_test_pass
1643   return 0
1644 }
1645
1646 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1647 # args: <response-code> <policy-id> [count]
1648 # (Function for test scripts)
1649 a1pms_api_delete_policy_batch() {
1650   __log_test_start $@
1651
1652   if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1653     __print_err "<response-code> <policy-id> [count]" $@
1654     return 1
1655   fi
1656
1657   count=0
1658   max=1
1659
1660   if [ $# -eq 3 ]; then
1661     max=$3
1662   fi
1663
1664   pid=$2
1665   ARR=""
1666   while [ $count -lt $max ]; do
1667     if [ "$A1PMS_VERSION" == "V2" ]; then
1668       query="/v2/policies/"$UUID$pid
1669     else
1670       query="/policy?id="$UUID$pid
1671     fi
1672     res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)"
1673     status=${res:${#res}-3}
1674     echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1675
1676     if [ $status -ne 200 ]; then
1677       echo " Requested(batch) "$count"?("$max")"
1678       __log_test_fail_status_code 200 $status
1679       return 1
1680     fi
1681     cid=${res:0:${#res}-3}
1682     ARR=$ARR" "$cid
1683     let pid=$pid+1
1684     let count=$count+1
1685     echo -ne " Requested(batch)  "$count"("$max")${SAMELINE}"
1686   done
1687
1688   echo ""
1689
1690   count=0
1691   for cid in $ARR; do
1692
1693     res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1694     status=${res:${#res}-3}
1695     echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1696
1697     if [ $status -ne $1 ]; then
1698       echo " Deleted(batch) "$count"?("$max")"
1699       __log_test_fail_status_code $1 $status
1700       return 1
1701     fi
1702
1703     let count=$count+1
1704     echo -ne " Deleted(batch)  "$count"("$max")${SAMELINE}"
1705   done
1706   __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
1707
1708   echo ""
1709
1710   __log_test_pass
1711   return 0
1712 }
1713
1714 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1715 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1716 # (Function for test scripts)
1717 a1pms_api_delete_policy_parallel() {
1718   __log_test_start $@
1719
1720   if [ $# -ne 5 ]; then
1721     __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1722     return 1
1723   fi
1724   resp_code=$1
1725   shift
1726   num_rics=$1
1727   shift
1728   start_id=$1
1729   shift
1730   count=$1
1731   shift
1732   pids=$1
1733   shift
1734
1735   #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1736   if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1737     echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported"
1738     echo " Info - will execute over a1pms REST"
1739   fi
1740
1741   if [ "$A1PMS_VERSION" == "V2" ]; then
1742     query="$A1PMS_API_PREFIX/v2/policies/"
1743   else
1744     query="/policy"
1745   fi
1746
1747   urlbase=${A1PMS_ADAPTER}${query}
1748
1749   httpproxy="NOPROXY"
1750   if [ ! -z "$KUBE_PROXY_PATH" ]; then
1751     httpproxy=$KUBE_PROXY_PATH
1752   fi
1753
1754   for ((i = 1; i <= $pids; i++)); do
1755     uuid=$UUID
1756     if [ -z "$uuid" ]; then
1757       uuid="NOUUID"
1758     fi
1759     echo "" >"./tmp/.pid${i}.del.res.txt"
1760     echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy >"./tmp/.pid${i}.del.txt"
1761     echo $i
1762   done | xargs -n 1 -I{} -P $pids bash -c '{
1763                 arg=$(echo {})
1764                 echo " Parallel process $arg started"
1765                 tmp=$(< "./tmp/.pid${arg}.del.txt")
1766                 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1767         }'
1768   msg=""
1769   for ((i = 1; i <= $pids; i++)); do
1770     file="./tmp/.pid${i}.del.res.txt"
1771     tmp=$(<$file)
1772     if [ -z "$tmp" ]; then
1773       echo " Process $i : unknown result (result file empty"
1774       msg="failed"
1775     else
1776       res=${tmp:0:1}
1777       if [ $res == "0" ]; then
1778         echo " Process $i : OK - "${tmp:1}
1779       else
1780         echo " Process $i : failed - "${tmp:1}
1781         msg="failed"
1782       fi
1783     fi
1784   done
1785   if [ -z $msg ]; then
1786     __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count * $num_rics))
1787     __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1788     return 0
1789   fi
1790
1791   __log_test_fail_general "One of more processes failed to execute"
1792   return 1
1793 }
1794
1795 # API Test function: V3 DELETE a1policymanagement/v1/policies/{policy_id}, to run in i parallel for a number of rics
1796 # args: <responseCode> <numberOfRics> <PolicyIdsFilePath> <countPerRic> <numberOfThreads>
1797 # (Function for test scripts)
1798 a1pms_api_delete_policy_parallel_v3() {
1799   __log_test_start $@
1800
1801   if [ $# -ne 6 ]; then
1802     __print_err " <responseCode> <numberOfRics> <PolicyIdsFilePath> <StartID> <countPerRic> <numberOfThreads>" $@
1803     return 1
1804   fi
1805   resp_code=$1
1806   shift
1807   num_rics=$1
1808   shift
1809   policy_ids_file_path=$1
1810   shift
1811   start_id=$1
1812   shift
1813   count=$1
1814   shift
1815   pids=$1
1816   shift
1817
1818   #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1819   if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1820     echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported"
1821     echo " Info - will execute over a1pms REST"
1822   fi
1823
1824   query="$A1PMS_API_PREFIX/v1/policies/"
1825   urlbase=${A1PMS_ADAPTER}${query}
1826
1827   urlbase=${A1PMS_ADAPTER}${query}
1828
1829   httpproxy="NOPROXY"
1830   if [ ! -z "$KUBE_PROXY_PATH" ]; then
1831     httpproxy=$KUBE_PROXY_PATH
1832   fi
1833
1834   for ((i = 1; i <= $pids; i++)); do
1835     echo "" >"./tmp/.pid${i}.del.res.txt"
1836     echo $resp_code $urlbase $policy_ids_file_path $start_id $pids $i $httpproxy >"./tmp/.pid${i}.del.txt"
1837     echo $i
1838   done | xargs -n 1 -I{} -P $pids bash -c '{
1839                 arg=$(echo {})
1840                 echo " Parallel process $arg started"
1841                 tmp=$(< "./tmp/.pid${arg}.del.txt")
1842                 python3 ../common/delete_policies_process_v3.py $tmp > ./tmp/.pid${arg}.del.res.txt
1843         }'
1844   msg=""
1845   for ((i = 1; i <= $pids; i++)); do
1846     file="./tmp/.pid${i}.del.res.txt"
1847     tmp=$(<$file)
1848     if [ -z "$tmp" ]; then
1849       echo " Process $i : unknown result (result file empty"
1850       msg="failed"
1851     else
1852       res=${tmp:0:1}
1853       if [ $res == "0" ]; then
1854         echo " Process $i : OK - "${tmp:1}
1855       else
1856         echo " Process $i : failed - "${tmp:1}
1857         msg="failed"
1858       fi
1859     fi
1860   done
1861   if [ -z $msg ]; then
1862     __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v1/policies/{policy_id}" $resp_code $(($count * $num_rics))
1863     __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1864     return 0
1865   fi
1866
1867   __log_test_fail_general "One of more processes failed to execute"
1868   return 1
1869 }
1870
1871 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}, to run in i parallel for a number of rics
1872 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1873 # (Function for test scripts)
1874 a1pms_api_get_policy_parallel() {
1875   __log_test_start $@
1876
1877   if [ $# -ne 5 ]; then
1878     __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1879     return 1
1880   fi
1881   resp_code=$1
1882   shift
1883   num_rics=$1
1884   shift
1885   start_id=$1
1886   shift
1887   count=$1
1888   shift
1889   pids=$1
1890   shift
1891
1892   #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1893   if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1894     echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported"
1895     echo " Info - will execute over a1pms REST"
1896   fi
1897
1898   if [ "$A1PMS_VERSION" == "V2" ]; then
1899     query="$A1PMS_API_PREFIX/v2/policies/"
1900   else
1901     query="/policy"
1902   fi
1903
1904   urlbase=${A1PMS_ADAPTER}${query}
1905
1906   httpproxy="NOPROXY"
1907   if [ ! -z "$KUBE_PROXY_PATH" ]; then
1908     httpproxy=$KUBE_PROXY_PATH
1909   fi
1910
1911   for ((i = 1; i <= $pids; i++)); do
1912     uuid=$UUID
1913     if [ -z "$uuid" ]; then
1914       uuid="NOUUID"
1915     fi
1916     echo "" >"./tmp/.pid${i}.get.res.txt"
1917     echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy >"./tmp/.pid${i}.get.txt"
1918     echo $i
1919   done | xargs -n 1 -I{} -P $pids bash -c '{
1920                 arg=$(echo {})
1921                 echo " Parallel process $arg started"
1922                 tmp=$(< "./tmp/.pid${arg}.get.txt")
1923                 python3 ../common/get_policies_process.py $tmp > ./tmp/.pid${arg}.get.res.txt
1924         }'
1925   msg=""
1926   for ((i = 1; i <= $pids; i++)); do
1927     file="./tmp/.pid${i}.get.res.txt"
1928     tmp=$(<$file)
1929     if [ -z "$tmp" ]; then
1930       echo " Process $i : unknown result (result file empty"
1931       msg="failed"
1932     else
1933       res=${tmp:0:1}
1934       if [ $res == "0" ]; then
1935         echo " Process $i : OK - "${tmp:1}
1936       else
1937         echo " Process $i : failed - "${tmp:1}
1938         msg="failed"
1939       fi
1940     fi
1941   done
1942   if [ -z $msg ]; then
1943     __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count * $num_rics))
1944     __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1945     return 0
1946   fi
1947
1948   __log_test_fail_general "One of more processes failed to execute"
1949   return 1
1950 }
1951
1952 # API Test function: V3 GET a1policymanagement/v1/policies/{policy_id}, to run in i parallel for a number of rics
1953 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1954 # (Function for test scripts)
1955 a1pms_api_get_policy_parallel_v3() {
1956   __log_test_start $@
1957
1958   if [ $# -ne 6 ]; then
1959     __print_err " <responseCode> <numberOfRics> <PolicyIdsFilePath> <startID> <countPerRic> <numberOfThreads>" $@
1960     return 1
1961   fi
1962   resp_code=$1
1963   shift
1964   num_rics=$1
1965   shift
1966   policy_ids_file_path=$1
1967   shift
1968   start_id=$1
1969   shift
1970   count=$1
1971   shift
1972   pids=$1
1973   shift
1974
1975   #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1976   if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1977     echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported"
1978     echo " Info - will execute over a1pms REST"
1979   fi
1980
1981   query="$A1PMS_API_PREFIX/v1/policies/"
1982   urlbase=${A1PMS_ADAPTER}${query}
1983
1984   httpproxy="NOPROXY"
1985   if [ ! -z "$KUBE_PROXY_PATH" ]; then
1986     httpproxy=$KUBE_PROXY_PATH
1987   fi
1988
1989   for ((i = 1; i <= $pids; i++)); do
1990     echo "" >"./tmp/.pid${i}.get.res.txt"
1991     echo $resp_code $urlbase $policy_ids_file_path $start_id $pids $i $httpproxy >"./tmp/.pid${i}.get.txt"
1992     echo $i
1993   done | xargs -n 1 -I{} -P $pids bash -c '{
1994                 arg=$(echo {})
1995                 echo " Parallel process $arg started"
1996                 tmp=$(< "./tmp/.pid${arg}.get.txt")
1997                 python3 ../common/get_policies_process_v3.py $tmp > ./tmp/.pid${arg}.get.res.txt
1998         }'
1999   msg=""
2000   for ((i = 1; i <= $pids; i++)); do
2001     file="./tmp/.pid${i}.get.res.txt"
2002     tmp=$(<$file)
2003     if [ -z "$tmp" ]; then
2004       echo " Process $i : unknown result (result file empty"
2005       msg="failed"
2006     else
2007       res=${tmp:0:1}
2008       if [ $res == "0" ]; then
2009         echo " Process $i : OK - "${tmp:1}
2010       else
2011         echo " Process $i : failed - "${tmp:1}
2012         msg="failed"
2013       fi
2014     fi
2015   done
2016   if [ -z $msg ]; then
2017     __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v1/policies/{policyId}" $resp_code $(($count * $num_rics))
2018     __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
2019     return 0
2020   fi
2021
2022   __log_test_fail_general "One of more processes failed to execute"
2023   return 1
2024 }
2025
2026 # API Test function: GET /policy_ids and V2 GET /v2/policies
2027 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
2028 # (Function for test scripts)
2029 a1pms_api_get_policy_ids() {
2030   __log_test_start $@
2031
2032   if [ $# -lt 4 ]; then
2033     __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
2034     return 1
2035   fi
2036
2037   queryparams=""
2038
2039   if [ "$A1PMS_VERSION" == "V2" ]; then
2040     if [ $2 != "NORIC" ]; then
2041       queryparams="?ric_id="$2
2042     fi
2043
2044     if [ $3 != "NOSERVICE" ]; then
2045       if [ -z $queryparams ]; then
2046         queryparams="?service_id="$3
2047       else
2048         queryparams=$queryparams"&service_id="$3
2049       fi
2050     fi
2051     if [ $4 != "NOTYPE" ]; then
2052       if [ -z $queryparams ]; then
2053         queryparams="?policytype_id="$4
2054       else
2055         queryparams=$queryparams"&policytype_id="$4
2056       fi
2057     fi
2058
2059     query="/v2/policies"$queryparams
2060   else
2061     if [ $2 != "NORIC" ]; then
2062       queryparams="?ric="$2
2063     fi
2064
2065     if [ $3 != "NOSERVICE" ]; then
2066       if [ -z $queryparams ]; then
2067         queryparams="?service="$3
2068       else
2069         queryparams=$queryparams"&service="$3
2070       fi
2071     fi
2072     if [ $4 != "NOTYPE" ]; then
2073       if [ -z $queryparams ]; then
2074         queryparams="?type="$4
2075       else
2076         queryparams=$queryparams"&type="$4
2077       fi
2078     fi
2079
2080     query="/policy_ids"$queryparams
2081   fi
2082
2083   res="$(__do_curl_to_api A1PMS GET $query)"
2084   status=${res:${#res}-3}
2085
2086   if [ $status -ne $1 ]; then
2087     __log_test_fail_status_code $1 $status
2088     return 1
2089   fi
2090
2091   if [ $# -gt 4 ]; then
2092     body=${res:0:${#res}-3}
2093     targetJson="["
2094
2095     for pid in ${@:5}; do
2096       if [ "$targetJson" != "[" ]; then
2097         targetJson=$targetJson","
2098       fi
2099       if [ $pid != "NOID" ]; then
2100         targetJson=$targetJson"\"$UUID$pid\""
2101       fi
2102     done
2103
2104     targetJson=$targetJson"]"
2105     if [ "$A1PMS_VERSION" == "V2" ]; then
2106       targetJson="{\"policy_ids\": $targetJson}"
2107     fi
2108     echo "TARGET JSON: $targetJson" >>$HTTPLOG
2109     res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2110
2111     if [ $res -ne 0 ]; then
2112       __log_test_fail_body
2113       return 1
2114     fi
2115   fi
2116
2117   __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status
2118   __log_test_pass
2119   return 0
2120 }
2121
2122 # API Test function: V3 GET a1policymanagement/v1/policies
2123 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
2124 # (Function for test scripts)
2125 a1pms_api_get_all_policies_v3() {
2126   __log_test_start $@
2127
2128   if [ $# -lt 4 ]; then
2129     __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
2130     return 1
2131   fi
2132
2133   queryparams=""
2134
2135   if [ $2 != "NORIC" ]; then
2136     queryparams="?nearRtRicId="$2
2137   fi
2138
2139   if [ $3 != "NOSERVICE" ]; then
2140     if [ -z $queryparams ]; then
2141       queryparams="?serviceId="$3
2142     else
2143       queryparams=$queryparams"&serviceId="$3
2144     fi
2145   fi
2146   if [ $4 != "NOTYPE" ]; then
2147     if [ -z $queryparams ]; then
2148       queryparams="?policyTypeId="$4
2149     else
2150       queryparams=$queryparams"&policyTypeId="$4
2151     fi
2152   fi
2153
2154   query="/v1/policies"$queryparams
2155
2156   res="$(__do_curl_to_api A1PMS GET $query)"
2157   status=${res:${#res}-3}
2158
2159   if [ $status -ne $1 ]; then
2160     __log_test_fail_status_code $1 $status
2161     return 1
2162   fi
2163
2164   if [ $# -gt 4 ]; then
2165     body=${res:0:${#res}-3}
2166     targetJson="["
2167
2168     for pid in ${@:5}; do
2169       if [ "$targetJson" != "[" ]; then
2170         targetJson=$targetJson","
2171       fi
2172       IFS=':' read -r policy_id ric_id <<<"$pid"
2173       if [ $policy_id != "NOID" ]; then
2174         targetJson=$targetJson"{ \"policyId\": \"${UUID}${policy_id}\", \"nearRtRicId\": \"$ric_id\" }"
2175       fi
2176     done
2177
2178     targetJson=$targetJson"]"
2179     echo "TARGET JSON: $targetJson" >>$HTTPLOG
2180     res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2181
2182     if [ $res -ne 0 ]; then
2183       __log_test_fail_body
2184       return 1
2185     fi
2186   fi
2187
2188   __collect_endpoint_stats "A1PMS" 04 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2189   __log_test_pass
2190   return 0
2191 }
2192
2193 # API Test function: V2 GET a1-policy/v2/policy-types/{policyTypeId} and V3 GET a1policymanagement/v1/policytypes/{policyTypeId}
2194 # args(V2): <response-code> <policy-type-id> [<schema-file>]
2195 # (Function for test scripts)
2196 a1pms_api_get_policy_type() {
2197   __log_test_start $@
2198
2199   if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
2200     __log_test_fail_not_supported
2201     return 1
2202   fi
2203
2204   if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2205     __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
2206     return 1
2207   fi
2208   if [ "$A1PMS_VERSION" == "V2" ]; then
2209     query="/v2/policy-types/$2"
2210   fi
2211   if [ "$A1PMS_VERSION" == "V3" ]; then
2212     query="/v1/policytypes/$2"
2213   fi
2214
2215   res="$(__do_curl_to_api A1PMS GET $query)"
2216   status=${res:${#res}-3}
2217
2218   if [ $status -ne $1 ]; then
2219     __log_test_fail_status_code $1 $status
2220     return 1
2221   fi
2222
2223   if [ $# -eq 3 ]; then
2224
2225     body=${res:0:${#res}-3}
2226
2227     targetJson=$(<$3)
2228     if [ "$A1PMS_VERSION" == "V2" ]; then
2229       targetJson="{\"policy_schema\":$targetJson}"
2230     elif [ "$A1PMS_VERSION" == "V3" ]; then
2231       targetJson="$targetJson"
2232     fi
2233     echo "TARGET JSON: $targetJson" >>$HTTPLOG
2234     res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2235
2236     if [ $res -ne 0 ]; then
2237       __log_test_fail_body
2238       return 1
2239     fi
2240   fi
2241
2242   __collect_endpoint_stats "A1PMS" 05 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2243   __log_test_pass
2244   return 0
2245 }
2246
2247 # API Test function: GET /policy_schema
2248 # args: <response-code> <policy-type-id> [<schema-file>]
2249 # (Function for test scripts)
2250 a1pms_api_get_policy_schema() {
2251   __log_test_start $@
2252
2253   if [ "$A1PMS_VERSION" == "V2" ]; then
2254     __log_test_fail_not_supported
2255     return 1
2256   fi
2257
2258   if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2259     __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
2260     return 1
2261   fi
2262   query="/policy_schema?id=$2"
2263   res="$(__do_curl_to_api A1PMS GET $query)"
2264   status=${res:${#res}-3}
2265
2266   if [ $status -ne $1 ]; then
2267     __log_test_fail_status_code $1 $status
2268     return 1
2269   fi
2270
2271   if [ $# -eq 3 ]; then
2272
2273     body=${res:0:${#res}-3}
2274
2275     targetJson=$(<$3)
2276
2277     echo "TARGET JSON: $targetJson" >>$HTTPLOG
2278     res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2279
2280     if [ $res -ne 0 ]; then
2281       __log_test_fail_body
2282       return 1
2283     fi
2284   fi
2285
2286   __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status
2287   __log_test_pass
2288   return 0
2289 }
2290
2291 # API Test function: GET /policy_schemas
2292 # args: <response-code>  <ric-id>|NORIC [<schema-file>|NOFILE]*
2293 # args(V2): <response-code>
2294 # (Function for test scripts)
2295 a1pms_api_get_policy_schemas() {
2296   __log_test_start $@
2297
2298   if [ "$A1PMS_VERSION" == "V2" ]; then
2299     if [ $# -ne 1 ]; then
2300       __print_err "<response-code>" $@
2301       return 1
2302     fi
2303   else
2304     if [ $# -lt 2 ]; then
2305       __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
2306       return 1
2307     fi
2308   fi
2309   if [ "$A1PMS_VERSION" == "V2" ]; then
2310     query="/v2/policy-schemas"
2311   else
2312     query="/policy_schemas"
2313     if [ $2 != "NORIC" ]; then
2314       query=$query"?ric="$2
2315     fi
2316   fi
2317
2318   res="$(__do_curl_to_api A1PMS GET $query)"
2319   status=${res:${#res}-3}
2320
2321   if [ $status -ne $1 ]; then
2322     __log_test_fail_status_code $1 $status
2323     return 1
2324   fi
2325
2326   if [ $# -gt 2 ]; then
2327     body=${res:0:${#res}-3}
2328     targetJson="["
2329
2330     for file in ${@:3}; do
2331       if [ "$targetJson" != "[" ]; then
2332         targetJson=$targetJson","
2333       fi
2334       if [ $file == "NOFILE" ]; then
2335         targetJson=$targetJson"{}"
2336       else
2337         targetJson=$targetJson$(<$file)
2338       fi
2339     done
2340
2341     targetJson=$targetJson"]"
2342     if [ "$A1PMS_VERSION" == "V2" ]; then
2343       targetJson="{\"policy_schemas\": $targetJson }"
2344     fi
2345     echo "TARGET JSON: $targetJson" >>$HTTPLOG
2346     res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2347
2348     if [ $res -ne 0 ]; then
2349       __log_test_fail_body
2350       return 1
2351     fi
2352   fi
2353
2354   __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status
2355   __log_test_pass
2356   return 0
2357 }
2358
2359 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
2360 # arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
2361 # (Function for test scripts)
2362 a1pms_api_get_policy_status() {
2363   __log_test_start $@
2364
2365   if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2366     __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
2367     return 1
2368   fi
2369
2370   targetJson=""
2371   if [ $# -eq 2 ]; then
2372     :
2373   elif [ "$3" == "STD" ]; then
2374     targetJson="{\"enforceStatus\":\"$4\""
2375     if [ $# -eq 5 ]; then
2376       targetJson=$targetJson",\"reason\":\"$5\""
2377     fi
2378     targetJson=$targetJson"}"
2379   elif [ "$3" == "STD2" ]; then
2380     if [ $4 == "EMPTY" ]; then
2381       targetJson="{\"enforceStatus\":\"\""
2382     else
2383       targetJson="{\"enforceStatus\":\"$4\""
2384     fi
2385     if [ $# -eq 5 ]; then
2386       if [ $5 == "EMPTY" ]; then
2387         targetJson=$targetJson",\"enforceReason\":\"\""
2388       else
2389         targetJson=$targetJson",\"enforceReason\":\"$5\""
2390       fi
2391     fi
2392     targetJson=$targetJson"}"
2393   elif [ "$3" == "OSC" ]; then
2394     if [[ $TEST_ENV_PROFILE =~ ^ORAN-[A-H] ]] || [[ $TEST_ENV_PROFILE =~ ^ONAP-[A-L] ]]; then
2395       targetJson="{\"instance_status\":\"$4\""
2396       if [ $# -eq 5 ]; then
2397         targetJson=$targetJson",\"has_been_deleted\":\"$5\""
2398       fi
2399       targetJson=$targetJson",\"created_at\":\"????\"}"
2400     else
2401       targetJson="{\"enforceStatus\":\"$4\""
2402       if [ $# -eq 5 ]; then
2403         targetJson=$targetJson",\"enforceReason\":\"$5\"}"
2404       fi
2405     fi
2406   else
2407     __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
2408     return 1
2409   fi
2410
2411   if [ "$A1PMS_VERSION" == "V2" ]; then
2412     query="/v2/policies/$UUID$2/status"
2413     targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
2414   else
2415     query="/policy_status?id="$UUID$2
2416   fi
2417
2418   res="$(__do_curl_to_api A1PMS GET $query)"
2419   status=${res:${#res}-3}
2420
2421   if [ $status -ne $1 ]; then
2422     __log_test_fail_status_code $1 $status
2423     return 1
2424   fi
2425   if [ $# -gt 2 ]; then
2426     echo "TARGET JSON: $targetJson" >>$HTTPLOG
2427     body=${res:0:${#res}-3}
2428     res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2429
2430     if [ $res -ne 0 ]; then
2431       __log_test_fail_body
2432       return 1
2433     fi
2434   fi
2435   __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
2436   __log_test_pass
2437   return 0
2438 }
2439
2440 # API Test function: GET /policy_types and V2 GET /v2/policy-types
2441 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
2442 # (Function for test scripts)
2443 a1pms_api_get_policy_types() {
2444   __log_test_start $@
2445
2446   if [ $# -lt 1 ]; then
2447     __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
2448     return 1
2449   fi
2450
2451   if [ "$A1PMS_VERSION" == "V2" ]; then
2452     if [ $# -eq 1 ]; then
2453       query="/v2/policy-types"
2454     elif [ $2 == "NORIC" ]; then
2455       query="/v2/policy-types"
2456     else
2457       query="/v2/policy-types?ric_id=$2"
2458     fi
2459   else
2460     if [ $# -eq 1 ]; then
2461       query="/policy_types"
2462     elif [ $2 == "NORIC" ]; then
2463       query="/policy_types"
2464     else
2465       query="/policy_types?ric=$2"
2466     fi
2467   fi
2468
2469   res="$(__do_curl_to_api A1PMS GET $query)"
2470   status=${res:${#res}-3}
2471
2472   if [ $status -ne $1 ]; then
2473     __log_test_fail_status_code $1 $status
2474     return 1
2475   fi
2476
2477   if [ $# -gt 2 ]; then
2478     body=${res:0:${#res}-3}
2479     targetJson="["
2480
2481     for pid in ${@:3}; do
2482       if [ "$targetJson" != "[" ]; then
2483         targetJson=$targetJson","
2484       fi
2485       if [ $pid == "EMPTY" ]; then
2486         pid=""
2487       fi
2488       targetJson=$targetJson"\"$pid\""
2489     done
2490
2491     targetJson=$targetJson"]"
2492     if [ "$A1PMS_VERSION" == "V2" ]; then
2493       targetJson="{\"policytype_ids\": $targetJson }"
2494     fi
2495     echo "TARGET JSON: $targetJson" >>$HTTPLOG
2496     res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2497
2498     if [ $res -ne 0 ]; then
2499       __log_test_fail_body
2500       return 1
2501     fi
2502   fi
2503
2504   __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
2505   __log_test_pass
2506   return 0
2507 }
2508
2509 # API Test function:  V3 GET a1policymanagement/v1/policytypes
2510 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
2511 # (Function for test scripts)
2512 a1pms_api_get_policy_types_v3() {
2513   __log_test_start $@
2514
2515   if [ $# -lt 1 ]; then
2516     __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
2517     return 1
2518   fi
2519
2520   if [ $# -eq 1 ]; then
2521     query="/v1/policytypes"
2522   elif [ $2 == "NORIC" ]; then
2523     query="/v1/policytypes"
2524   else
2525     query="/v1/policytypes?nearRtRicId=$2"
2526   fi
2527   res="$(__do_curl_to_api A1PMS GET $query)"
2528   status=${res:${#res}-3}
2529
2530   if [ $status -ne $1 ]; then
2531     __log_test_fail_status_code $1 $status
2532     return 1
2533   fi
2534
2535   if [ $# -gt 2 ]; then
2536     body=${res:0:${#res}-3}
2537     targetJson="["
2538
2539     for pid in ${@:3}; do
2540       if [ "$targetJson" != "[" ]; then
2541         targetJson=$targetJson","
2542       fi
2543       IFS=':' read -r policy_type_id ric_id <<<"$pid"
2544       #                 if [ -n "$policy_type_id" ] && [ -n "$ric_id" ]; then
2545       if [ $policy_type_id == "EMPTY" ]; then
2546         policy_type_id=""
2547       fi
2548       targetJson=$targetJson"{ \"policyTypeId\": \"$policy_type_id\", \"nearRtRicId\": \"$ric_id\" }"
2549       #                 fi
2550     done
2551
2552     targetJson=$targetJson"]"
2553
2554     echo "TARGET JSON: $targetJson" >>$HTTPLOG
2555     res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2556
2557     if [ $res -ne 0 ]; then
2558       __log_test_fail_body
2559       return 1
2560     fi
2561   fi
2562
2563   __collect_endpoint_stats "A1PMS" 09 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2564   __log_test_pass
2565   return 0
2566 }
2567
2568 #########################################################
2569 #### Test case functions Health check
2570 #########################################################
2571
2572 # API Test function: GET /status and V2 GET /status or (v1/status for a1pmsV3)
2573 # args: <response-code>
2574 # (Function for test scripts)
2575 a1pms_api_get_status() {
2576   __log_test_start $@
2577   if [ $# -ne 1 ]; then
2578     __print_err "<response-code>" $@
2579     return 1
2580   fi
2581
2582   if [ "$A1PMS_VERSION" == "V2" ]; then
2583     query="/v2/status"
2584   elif [ "$A1PMS_VERSION" == "V3" ]; then
2585     query="/v1/status"
2586   else
2587     query="/status"
2588   fi
2589
2590   res="$(__do_curl_to_api A1PMS GET $query)"
2591   status=${res:${#res}-3}
2592
2593   if [ $status -ne $1 ]; then
2594     __log_test_fail_status_code $1 $status
2595     return 1
2596   fi
2597
2598   __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX$query $status
2599   __log_test_pass
2600   return 0
2601 }
2602
2603 # API Test function: GET /status (root) without api prefix
2604 # args: <response-code>
2605 # (Function for test scripts)
2606 a1pms_api_get_status_root() {
2607   __log_test_start $@
2608   if [ $# -ne 1 ]; then
2609     __print_err "<response-code>" $@
2610     return 1
2611   fi
2612   query="/status"
2613   TMP_PREFIX=$A1PMS_API_PREFIX
2614   A1PMS_API_PREFIX=""
2615   res="$(__do_curl_to_api A1PMS GET $query)"
2616   A1PMS_API_PREFIX=$TMP_PREFIX
2617   status=${res:${#res}-3}
2618
2619   if [ $status -ne $1 ]; then
2620     __log_test_fail_status_code $1 $status
2621     return 1
2622   fi
2623
2624   __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
2625   __log_test_pass
2626   return 0
2627 }
2628
2629 #########################################################
2630 #### Test case functions RIC Repository
2631 #########################################################
2632
2633 # API Test function: GET /ric, V2 GET /v2/rics/ric, and V3 GET a1policymanagement/v1/rics/ric
2634 # args: <reponse-code> <management-element-id> [<ric-id>]
2635 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
2636 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
2637 # (V2) format of ric-info:  <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2638
2639 # (Function for test scripts)
2640 a1pms_api_get_ric() {
2641   __log_test_start $@
2642
2643   if [ "$A1PMS_VERSION" == "V2" ]; then
2644     if [ $# -lt 3 ]; then
2645       __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
2646       return 1
2647     fi
2648     search=""
2649     if [ $2 != "NOME" ]; then
2650       search="?managed_element_id="$2
2651     fi
2652     if [ $3 != "NORIC" ]; then
2653       if [ -z $search ]; then
2654         search="?ric_id="$3
2655       else
2656         search=$search"&ric_id="$3
2657       fi
2658     fi
2659     query="/v2/rics/ric"$search
2660
2661     res="$(__do_curl_to_api A1PMS GET $query)"
2662     status=${res:${#res}-3}
2663
2664     if [ $status -ne $1 ]; then
2665       __log_test_fail_status_code $1 $status
2666       return 1
2667     fi
2668
2669     if [ $# -gt 3 ]; then
2670       body=${res:0:${#res}-3}
2671       res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4")
2672       if [ $res -ne 0 ]; then
2673         __log_test_fail_general "Could not create target ric info json"
2674         return 1
2675       fi
2676
2677       targetJson=$(<./tmp/.tmp_rics.json)
2678       targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
2679       echo " TARGET JSON: $targetJson" >>$HTTPLOG
2680       res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2681       if [ $res -ne 0 ]; then
2682         __log_test_fail_body
2683         return 1
2684       fi
2685     fi
2686   elif [ "$A1PMS_VERSION" == "V3" ]; then
2687     if [ $# -lt 3 ]; then
2688       __print_err "<reponseCode> <managementElementId>|NOME <ricId>|<NORIC> [stringOfRicInfo>]" $@
2689       return 1
2690     fi
2691     search=""
2692     if [ $2 != "NOME" ]; then
2693       search="?managedElementId="$2
2694     fi
2695     if [ $3 != "NORIC" ]; then
2696       if [ -z $search ]; then
2697         search="?ricId="$3
2698       else
2699         search=$search"&ricId="$3
2700       fi
2701     fi
2702     query="/v1/rics/ric"$search
2703
2704     res="$(__do_curl_to_api A1PMS GET $query)"
2705     status=${res:${#res}-3}
2706
2707     if [ $status -ne $1 ]; then
2708       __log_test_fail_status_code $1 $status
2709       return 1
2710     fi
2711
2712     if [ $# -gt 3 ]; then
2713       body=${res:0:${#res}-3}
2714       res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "${A1PMS_VERSION}" "$4")
2715       if [ $res -ne 0 ]; then
2716         __log_test_fail_general "Could not create target ric info json"
2717         return 1
2718       fi
2719
2720       targetJson=$(<./tmp/.tmp_rics.json)
2721       targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
2722       echo " TARGET JSON: $targetJson" >>$HTTPLOG
2723       res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2724       if [ $res -ne 0 ]; then
2725         __log_test_fail_body
2726         return 1
2727       fi
2728     fi
2729   else
2730     if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2731       __print_err "<reponseCode> <managedElementIds> [<ricId>]" $@
2732       return 1
2733     fi
2734
2735     query="/ric?managedElementId="$2
2736
2737     res="$(__do_curl_to_api A1PMS GET $query)"
2738     status=${res:${#res}-3}
2739
2740     if [ $status -ne $1 ]; then
2741       __log_test_fail_status_code $1 $status
2742       return 1
2743     fi
2744
2745     if [ $# -eq 3 ]; then
2746       body=${res:0:${#res}-3}
2747       if [ "$body" != "$3" ]; then
2748         __log_test_fail_body
2749         return 1
2750       fi
2751     fi
2752   fi
2753
2754   __collect_endpoint_stats "A1PMS" 11 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2755   __log_test_pass
2756   return 0
2757 }
2758
2759 # API test function: GET /rics, V2 GET /v2/rics, and V3 GET /a1policymanagement/v1/rics
2760 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
2761 # example of <space-separate-string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4 ricsim_g1_1:me2_........."
2762 # format of ric-info:  <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2763 # (Function for test scripts)
2764 a1pms_api_get_rics() {
2765   __log_test_start $@
2766
2767   if [ $# -lt 2 ]; then
2768     __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
2769     return 1
2770   fi
2771
2772   if [ "$A1PMS_VERSION" == "V2" ]; then
2773     query="/v2/rics"
2774     if [ $2 != "NOTYPE" ]; then
2775       query="/v2/rics?policytype_id="$2
2776     fi
2777   elif [ "$A1PMS_VERSION" == "V3" ]; then
2778     query="/v1/rics"
2779     if [ $2 != "NOTYPE" ]; then
2780       query=${query}"?policyTypeId="$2
2781     fi
2782   else
2783     query="/rics"
2784     if [ $2 != "NOTYPE" ]; then
2785       query="/rics?policyType="$2
2786     fi
2787   fi
2788
2789   res="$(__do_curl_to_api A1PMS GET $query)"
2790   status=${res:${#res}-3}
2791
2792   if [ $status -ne $1 ]; then
2793     __log_test_fail_status_code $1 $status
2794     return 1
2795   fi
2796
2797   if [ $# -gt 2 ]; then
2798     body=${res:0:${#res}-3}
2799     res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "${A1PMS_VERSION}" "$3")
2800     if [ $res -ne 0 ]; then
2801       __log_test_fail_general "Could not create target ric info json"
2802       return 1
2803     fi
2804
2805     targetJson=$(<./tmp/.tmp_rics.json)
2806     if [ "$A1PMS_VERSION" == "V2" ] || [ "$A1PMS_VERSION" == "V3" ]; then
2807       targetJson="{\"rics\": $targetJson }"
2808     fi
2809     echo "TARGET JSON: $targetJson" >>$HTTPLOG
2810     res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2811     if [ $res -ne 0 ]; then
2812       __log_test_fail_body
2813       return 1
2814     fi
2815   fi
2816
2817   __collect_endpoint_stats "A1PMS" 12 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2818   __log_test_pass
2819   return 0
2820 }
2821
2822 ##################################################################
2823 #### API Test case functions Service registry and supervision ####
2824 ##################################################################
2825
2826 # API test function: PUT /service, V2 PUT /service and V3 PUT a1policymanagement/v1/services
2827 # args: <response-code>  <service-name> <keepalive-timeout> <callbackurl>
2828 # (Function for test scripts)
2829 a1pms_api_put_service() {
2830   __log_test_start $@
2831   if [ $# -ne 4 ]; then
2832     __print_err "<response-code>  <service-name> <keepalive-timeout> <callbackurl>" $@
2833     return 1
2834   fi
2835
2836   if [ "$A1PMS_VERSION" == "V2" ]; then
2837     query="/v2/services"
2838     json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2839   elif [ "$A1PMS_VERSION" == "V3" ]; then
2840     query="/v1/services"
2841     json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceId\": \""$2"\"}"
2842   else
2843     query="/service"
2844     json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2845   fi
2846   file="./tmp/.tmp.json"
2847   echo "$json" >$file
2848
2849   res="$(__do_curl_to_api A1PMS PUT $query $file)"
2850   status=${res:${#res}-3}
2851
2852   if [ $status -ne $1 ]; then
2853     __log_test_fail_status_code $1 $status
2854     return 1
2855   fi
2856
2857   __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX$query $status
2858   __log_test_pass
2859   return 0
2860 }
2861
2862 # API test function: GET /services, V2 GET /v2/services and V3 /a1policymanagement/v1/services
2863 #args: <response-code> [ (<query-service-name> <target-service-name> <keepalive-timeout> <callbackurl>) | (NOSERVICE <target-service-name> <keepalive-timeout> <callbackurl> [<target-service-name> <keepalive-timeout> <callbackurl>]* )]
2864 # (Function for test scripts)
2865 a1pms_api_get_services() {
2866   __log_test_start $@
2867   #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2868   paramError=1
2869   if [ $# -eq 1 ]; then
2870     paramError=0
2871   elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2872     paramError=0
2873   elif [ $# -eq 5 ]; then
2874     paramError=0
2875   elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2876     argLen=$(($# - 2))
2877     if [ $(($argLen % 3)) -eq 0 ]; then
2878       paramError=0
2879     fi
2880   fi
2881
2882   if [ $paramError -ne 0 ]; then
2883     __print_err "<response-code> [ (<query-service-name> <target-service-name> <keepalive-timeout> <callbackurl>) | (NOSERVICE <target-service-name> <keepalive-timeout> <callbackurl> [<target-service-name> <keepalive-timeout> <callbackurl>]* )]" $@
2884     return 1
2885   fi
2886
2887   if [ "$A1PMS_VERSION" == "V2" ]; then
2888     query="/v2/services"
2889     if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2890       query="/v2/services?service_id="$2
2891     fi
2892   elif [ "$A1PMS_VERSION" == "V3" ]; then
2893     query="/v1/services"
2894     if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2895       query="/v1/services?serviceId="$2
2896     fi
2897   else
2898     query="/services"
2899
2900     if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2901       query="/services?name="$2
2902     fi
2903   fi
2904   res="$(__do_curl_to_api A1PMS GET $query)"
2905   status=${res:${#res}-3}
2906
2907   if [ $status -ne $1 ]; then
2908     __log_test_fail_status_code $1 $status
2909     return 1
2910   fi
2911
2912   if [ $# -gt 2 ]; then
2913     variableArgCount=$(($# - 2))
2914     body=${res:0:${#res}-3}
2915     targetJson="["
2916     shift
2917     shift
2918     cntr=0
2919     while [ $cntr -lt $variableArgCount ]; do
2920       servicename=$1
2921       shift
2922       timeout=$1
2923       shift
2924       callback=$1
2925       shift
2926       if [ $cntr -gt 0 ]; then
2927         targetJson=$targetJson","
2928       fi
2929       # timeSinceLastActivitySeconds value cannot be checked since value varies
2930       if [ "$A1PMS_VERSION" == "V2" ]; then
2931         targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2932       elif [ "$A1PMS_VERSION" == "V3" ]; then
2933         targetJson=$targetJson"{\"serviceId\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2934       else
2935         targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2936       fi
2937       let cntr=cntr+3
2938     done
2939     targetJson=$targetJson"]"
2940     if [ "$A1PMS_VERSION" == "V2" ]; then
2941       targetJson="{\"service_list\": $targetJson }"
2942       URL_for_Collect_End_Point="/v2/services"
2943     elif [ "$A1PMS_VERSION" == "V3" ]; then
2944       targetJson="{\"serviceList\": $targetJson }"
2945       URL_for_Collect_End_Point="/v1/services"
2946     fi
2947     echo "TARGET JSON: $targetJson" >>$HTTPLOG
2948     res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2949     if [ $res -ne 0 ]; then
2950       __log_test_fail_body
2951       return 1
2952     fi
2953   fi
2954
2955   __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX$URL_for_Collect_End_Point $status
2956   __log_test_pass
2957   return 0
2958 }
2959
2960 # API test function: GET /services, V2 GET /v2/services and V3 /a1policymanagement/v1/services -  (only checking service names)
2961 # args: <response-code> [<service-name>]*"
2962 # (Function for test scripts)
2963 a1pms_api_get_service_ids() {
2964   __log_test_start $@
2965
2966   if [ $# -lt 1 ]; then
2967     __print_err "<response-code> [<service-name>]*" $@
2968     return 1
2969   fi
2970
2971   if [ "$A1PMS_VERSION" == "V2" ]; then
2972     query="/v2/services"
2973   elif [ "$A1PMS_VERSION" == "V3" ]; then
2974     query="/v1/services"
2975   else
2976     query="/services"
2977   fi
2978   res="$(__do_curl_to_api A1PMS GET $query)"
2979   status=${res:${#res}-3}
2980
2981   if [ $status -ne $1 ]; then
2982     __log_test_fail_status_code $1 $status
2983     return 1
2984   fi
2985
2986   body=${res:0:${#res}-3}
2987   targetJson="["
2988   for rapp in ${@:2}; do
2989     if [ "$targetJson" != "[" ]; then
2990       targetJson=$targetJson","
2991     fi
2992     if [ "$A1PMS_VERSION" == "V2" ]; then
2993       targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2994     elif [ "$A1PMS_VERSION" == "V3" ]; then
2995       targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceId\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2996     else
2997       targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2998     fi
2999   done
3000
3001   targetJson=$targetJson"]"
3002   if [ "$A1PMS_VERSION" == "V2" ]; then
3003     targetJson="{\"service_list\": $targetJson }"
3004     URL_for_Collect_End_Point="/v2/services"
3005   elif [ "$A1PMS_VERSION" == "V3" ]; then
3006     targetJson="{\"serviceList\": $targetJson }"
3007     URL_for_Collect_End_Point="/v1/services"
3008   fi
3009   echo "TARGET JSON: $targetJson" >>$HTTPLOG
3010   res=$(python3 ../common/compare_json.py "$targetJson" "$body")
3011
3012   if [ $res -ne 0 ]; then
3013     __log_test_fail_body
3014     return 1
3015   fi
3016
3017   __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX$URL_for_Collect_End_Point $status
3018   __log_test_pass
3019   return 0
3020 }
3021
3022 # API test function: DELETE /services, V2 DELETE /v2/services/{serviceId} and V3 DELETE a1policymanagement/v1/services/{serviceId}
3023 # args: <response-code> <service-name>
3024 # (Function for test scripts)
3025 a1pms_api_delete_services() {
3026   __log_test_start $@
3027
3028   if [ $# -ne 2 ]; then
3029     __print_err "<response-code> <service-name>" $@
3030     return 1
3031   fi
3032   if [ "$A1PMS_VERSION" == "V2" ]; then
3033     url_part="/v2/services/"
3034     query=${url_part}${2}
3035   elif [ "$A1PMS_VERSION" == "V3" ]; then
3036     url_part="/v1/services/"
3037     query=${url_part}${2}
3038   else
3039     query="/services?name="$2
3040   fi
3041   res="$(__do_curl_to_api A1PMS DELETE $query)"
3042   status=${res:${#res}-3}
3043
3044   if [ $status -ne $1 ]; then
3045     __log_test_fail_status_code $1 $status
3046     return 1
3047   fi
3048
3049   __collect_endpoint_stats "A1PMS" 15 "DELETE" ${A1PMS_API_PREFIX}${url_part}"{serviceId}" $status
3050   __log_test_pass
3051   return 0
3052 }
3053
3054 # API test function: PUT /services/keepalive, V2 PUT /v2/services/{service_id}/keepalive and V3 DELETE a1policymanagement/v1/services/{serviceId}
3055 # args: <response-code> <service-name>
3056 # (Function for test scripts)
3057 a1pms_api_put_services_keepalive() {
3058   __log_test_start $@
3059
3060   if [ $# -ne 2 ]; then
3061     __print_err "<response-code> <service-name>" $@
3062     return 1
3063   fi
3064   if [ "$A1PMS_VERSION" == "V2" ]; then
3065     query="/v2/services/$2/keepalive"
3066   elif [ "$A1PMS_VERSION" == "V3" ]; then
3067     query="/v1/services/$2/keepalive"
3068   else
3069     query="/services/keepalive?name="$2
3070   fi
3071
3072   if [ "$A1PMS_VERSION" == "V3" ]; then
3073     empty_json_body={}
3074     res="$(__do_curl_to_api A1PMS PUT ${query} ${empty_json_body})"
3075   else
3076     res="$(__do_curl_to_api A1PMS PUT ${query})"
3077   fi
3078   status=${res:${#res}-3}
3079
3080   if [ $status -ne $1 ]; then
3081     __log_test_fail_status_code ${1} ${status}
3082     return 1
3083   fi
3084
3085   __collect_endpoint_stats "A1PMS" 16 "PUT" ${A1PMS_API_PREFIX}${query} ${status}
3086   __log_test_pass
3087   return 0
3088 }
3089
3090 ##################################################################
3091 #### API Test case functions Configuration                    ####
3092 ##################################################################
3093
3094 # API Test function: PUT "/v2/configuration" or V3 PUT "a1policymanagement/v1/configuration"
3095 # args: <response-code> <config-file>
3096 # (Function for test scripts)
3097 a1pms_api_put_configuration() {
3098   __log_test_start $@
3099
3100   if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
3101     __log_test_fail_not_supported
3102     return 1
3103   fi
3104
3105   if [ $# -ne 2 ]; then
3106     __print_err "<response-code> <config-file>" $@
3107     return 1
3108   fi
3109   if [ ! -f $2 ]; then
3110     __log_test_fail_general "Config file "$2", does not exist"
3111     return 1
3112   fi
3113   inputJson=$(<$2)
3114   # if [ $RUNMODE == "DOCKER" ]; then  #In kube the file already has a header
3115   #     inputJson="{\"config\":"$inputJson"}"
3116   # fi
3117   file="./tmp/.config.json"
3118   echo $inputJson >$file
3119   if [ "$A1PMS_VERSION" == "V2" ]; then
3120     query="/v2/configuration"
3121   elif [ "$A1PMS_VERSION" == "V3" ]; then
3122     #V3 has baseurl changes 'a1-policy/v2' to 'a1policymanagement/v1'
3123     query="/v1/configuration"
3124   fi
3125   res="$(__do_curl_to_api A1PMS PUT $query $file)"
3126   status=${res:${#res}-3}
3127
3128   if [ $status -ne $1 ]; then
3129     __log_test_fail_status_code $1 $status
3130     return 1
3131   fi
3132
3133   __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX$query $status
3134   __log_test_pass
3135   return 0
3136 }
3137
3138 # API Test function: GET /v2/configuration and V3 GET a1policymanagement/v1/configuration
3139 # args: <response-code> [<config-file>]
3140 # (Function for test scripts)
3141 a1pms_api_get_configuration() {
3142   __log_test_start $@
3143
3144   if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
3145     __log_test_fail_not_supported
3146     return 1
3147   fi
3148
3149   if [ $# -lt 1 ] || [ $# -gt 2 ]; then
3150     __print_err "<response-code> [<config-file>]" $@
3151     return 1
3152   fi
3153   if [ ! -f $2 ]; then
3154     __log_test_fail_general "Config file "$2" for comparison, does not exist"
3155     return 1
3156   fi
3157
3158   if [ "$A1PMS_VERSION" == "V3" ]; then
3159     #The V3 of a1-pms URL is a1policymanagement/v1 and the v2 is a1-policy/v2
3160     query="/v1/configuration"
3161   else
3162     query="/v2/configuration"
3163   fi
3164   res="$(__do_curl_to_api A1PMS GET $query)"
3165   status=${res:${#res}-3}
3166
3167   if [ $status -ne $1 ]; then
3168     __log_test_fail_status_code $1 $status
3169     return 1
3170   fi
3171
3172   if [ $# -eq 2 ]; then
3173
3174     body=${res:0:${#res}-3}
3175
3176     targetJson=$(<$2)
3177     # if [ $RUNMODE == "DOCKER" ]; then  #In kube the file already has a header
3178     #   inputJson="{\"config\":"$inputJson"}"
3179     # fi
3180     echo "TARGET JSON: $targetJson" >>$HTTPLOG
3181     res=$(python3 ../common/compare_json.py "$targetJson" "$body")
3182
3183     if [ $res -ne 0 ]; then
3184       __log_test_fail_body
3185       return 1
3186     fi
3187   fi
3188
3189   if [ "$A1PMS_VERSION" == "V3" ]; then
3190     __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v1/configuration" $status
3191   else
3192     __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
3193   fi
3194   __log_test_pass
3195   return 0
3196 }
3197
3198 ##########################################
3199 ####     Reset types and instances    ####
3200 ##########################################
3201
3202 # Admin reset to remove all policies and services
3203 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
3204 # NOTE - only works in kubernetes and the pod should not be running
3205 # args: -
3206 # (Function for test scripts)
3207
3208 a1pms_kube_pvc_reset() {
3209   __log_test_start $@
3210
3211   pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
3212   if [ -z "$pvc_name" ]; then
3213     pvc_name=policymanagementservice-vardata-pvc
3214   fi
3215   echo " Trying to reset pvc: "$pvc_name
3216   __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR
3217
3218   __log_test_pass
3219   return 0
3220 }
3221
3222 # args: <realm> <client-name> <client-secret>
3223 a1pms_configure_sec() {
3224   export A1PMS_CREDS_GRANT_TYPE="client_credentials"
3225   export A1PMS_CREDS_CLIENT_SECRET=$3
3226   export A1PMS_CREDS_CLIENT_ID=$2
3227   export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
3228   export A1PMS_SIDECAR_MOUNT="/token-cache"
3229   export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
3230
3231   export AUTHSIDECAR_APP_NAME
3232   export AUTHSIDECAR_DISPLAY_NAME
3233 }