9a0a1628181861e3aa3e91ccdd0b360163efcd35
[nonrtric.git] / test / common / pa_api_functions.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2021 Nordix Foundation. All rights reserved.
5 #  ========================================================================
6 #  Licensed under the Apache License, Version 2.0 (the "License");
7 #  you may not use this file except in compliance with the License.
8 #  You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #  Unless required by applicable law or agreed to in writing, software
13 #  distributed under the License is distributed on an "AS IS" BASIS,
14 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #  See the License for the specific language governing permissions and
16 #  limitations under the License.
17 #  ============LICENSE_END=================================================
18 #
19
20 # This is a script that contains management and test functions for Policy Agent
21
22 ################ Test engine functions ################
23
24 # Create the image var used during the test
25 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
26 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
27 __PA_imagesetup() {
28         __check_and_create_image_var PA "POLICY_AGENT_IMAGE" "POLICY_AGENT_IMAGE_BASE" "POLICY_AGENT_IMAGE_TAG" $1 "$POLICY_AGENT_DISPLAY_NAME"
29 }
30
31 # Pull image from remote repo or use locally built image
32 # arg: <pull-policy-override> <pull-policy-original>
33 # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
34 # <pull-policy-original> Shall be used for images that does not allow overriding
35 # Both var may contain: 'remote', 'remote-remove' or 'local'
36 __PA_imagepull() {
37         __check_and_pull_image $1 "$POLICY_AGENT_DISPLAY_NAME" $POLICY_AGENT_APP_NAME POLICY_AGENT_IMAGE
38 }
39
40 # Build image (only for simulator or interfaces stubs owned by the test environment)
41 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
42 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
43 __PA_imagebuild() {
44         echo -e $RED" Image for app PA shall never be built"$ERED
45 }
46
47 # Generate a string for each included image using the app display name and a docker images format string
48 # If a custom image repo is used then also the source image from the local repo is listed
49 # arg: <docker-images-format-string> <file-to-append>
50 __PA_image_data() {
51         echo -e "$POLICY_AGENT_DISPLAY_NAME\t$(docker images --format $1 $POLICY_AGENT_IMAGE)" >>   $2
52         if [ ! -z "$POLICY_AGENT_IMAGE_SOURCE" ]; then
53                 echo -e "-- source image --\t$(docker images --format $1 $POLICY_AGENT_IMAGE_SOURCE)" >>   $2
54         fi
55 }
56
57 # Scale kubernetes resources to zero
58 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
59 # This function is called for apps fully managed by the test script
60 __PA_kube_scale_zero() {
61         __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
62 }
63
64 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
65 # This function is called for prestarted apps not managed by the test script.
66 __PA_kube_scale_zero_and_wait() {
67         __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-policymanagementservice
68 }
69
70 # Delete all kube resouces for the app
71 # This function is called for apps managed by the test script.
72 __PA_kube_delete_all() {
73         __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
74 }
75
76 # Store docker logs
77 # This function is called for apps managed by the test script.
78 # args: <log-dir> <file-prexix>
79 __PA_store_docker_logs() {
80         if [ $RUNMODE == "KUBE" ]; then
81                 kubectl $KUBECONF  logs -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_policy-agent.log 2>&1
82         else
83                 docker logs $POLICY_AGENT_APP_NAME > $1$2_policy-agent.log 2>&1
84         fi
85 }
86
87 # Initial setup of protocol, host and ports
88 # This function is called for apps managed by the test script.
89 # args: -
90 __PA_initial_setup() {
91         use_agent_rest_http
92 }
93
94 # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
95 # For docker, the namespace shall be excluded
96 # This function is called for apps managed by the test script as well as for prestarted apps.
97 # args: -
98 __PA_statisics_setup() {
99         if [ $RUNMODE == "KUBE" ]; then
100                 echo "PA $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
101         else
102                 echo "PA $POLICY_AGENT_APP_NAME"
103         fi
104 }
105
106 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
107 # args: -
108 __PA_test_requirements() {
109         :
110 }
111
112
113 #######################################################
114
115 ###########################
116 ### Policy Agents functions
117 ###########################
118
119 # Set http as the protocol to use for all communication to the Policy Agent
120 # args: -
121 # (Function for test scripts)
122 use_agent_rest_http() {
123         __agent_set_protocoll "http" $POLICY_AGENT_INTERNAL_PORT $POLICY_AGENT_EXTERNAL_PORT
124 }
125
126 # Set https as the protocol to use for all communication to the Policy Agent
127 # args: -
128 # (Function for test scripts)
129 use_agent_rest_https() {
130         __agent_set_protocoll "https" $POLICY_AGENT_INTERNAL_SECURE_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT
131 }
132
133 # All calls to the agent will be directed to the agent dmaap interface over http from now on
134 # args: -
135 # (Function for test scripts)
136 use_agent_dmaap_http() {
137         echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
138         echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
139         PA_ADAPTER_TYPE="MR-HTTP"
140         echo ""
141 }
142
143 # All calls to the agent will be directed to the agent dmaap interface over https from now on
144 # args: -
145 # (Function for test scripts)
146 use_agent_dmaap_https() {
147         echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
148         echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
149         echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
150         PA_ADAPTER_TYPE="MR-HTTPS"
151         echo ""
152 }
153
154 # Setup paths to svc/container for internal and external access
155 # args: <protocol> <internal-port> <external-port>
156 __agent_set_protocoll() {
157         echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME protocol setting"$EBOLD
158         echo -e " Using $BOLD $1 $EBOLD towards $POLICY_AGENT_DISPLAY_NAME"
159
160         ## Access to Dmaap adapter
161
162         PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME":"$2  # docker access, container->container and script->container via proxy
163         if [ $RUNMODE == "KUBE" ]; then
164                 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
165         fi
166
167         # PA_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
168         PA_ADAPTER_TYPE="REST"
169         PA_ADAPTER=$PA_SERVICE_PATH
170
171         echo ""
172 }
173
174 # Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
175 AGENT_RETRY_CODES=""
176
177 #Save first worker node the pod is started on
178 __PA_WORKER_NODE=""
179
180 # Export env vars for config files, docker compose and kube resources
181 # args: PROXY|NOPROXY
182 __export_agent_vars() {
183
184                 export POLICY_AGENT_APP_NAME
185                 export POLICY_AGENT_APP_NAME_ALIAS
186                 export POLICY_AGENT_DISPLAY_NAME
187
188                 export KUBE_NONRTRIC_NAMESPACE
189                 export POLICY_AGENT_IMAGE
190                 export POLICY_AGENT_INTERNAL_PORT
191                 export POLICY_AGENT_INTERNAL_SECURE_PORT
192                 export POLICY_AGENT_EXTERNAL_PORT
193                 export POLICY_AGENT_EXTERNAL_SECURE_PORT
194                 export POLICY_AGENT_CONFIG_MOUNT_PATH
195                 export POLICY_AGENT_DATA_MOUNT_PATH
196                 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
197                 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
198                 export POLICY_AGENT_PKG_NAME
199                 export CONSUL_HOST
200                 export CONSUL_INTERNAL_PORT
201                 export CONFIG_BINDING_SERVICE
202                 export POLICY_AGENT_CONFIG_KEY
203                 export DOCKER_SIM_NWNAME
204                 export POLICY_AGENT_HOST_MNT_DIR
205                 export POLICY_AGENT_CONFIG_FILE
206
207                 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
208                 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
209                 ##Create a unique path for the pv each time to prevent a previous volume to be reused
210                 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
211                 export POLICY_AGENT_CONTAINER_MNT_DIR
212
213                 if [ $1 == "PROXY" ]; then
214                         export AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT  #Set if proxy is started
215                         export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
216                         if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
217                                 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
218                         else
219                                 echo " Configured with http proxy"
220                         fi
221                 else
222                         export AGENT_HTTP_PROXY_CONFIG_PORT=0
223                         export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
224                         echo " Configured without http proxy"
225                 fi
226 }
227
228
229 # Start the policy agent
230 # args: (docker) PROXY|NOPROXY <config-file>
231 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
232 # (Function for test scripts)
233 start_policy_agent() {
234         echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
235
236         if [ $RUNMODE == "KUBE" ]; then
237
238                 # Check if app shall be fully managed by the test script
239                 __check_included_image "PA"
240                 retcode_i=$?
241
242                 # Check if app shall only be used by the testscipt
243                 __check_prestarted_image "PA"
244                 retcode_p=$?
245
246                 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
247                         echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
248                         echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
249                         exit
250                 fi
251                 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
252                         echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
253                         echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
254                         exit
255                 fi
256
257                 if [ $retcode_p -eq 0 ]; then
258                         echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
259                         echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
260                         res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
261                         __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
262                 fi
263
264                 if [ $retcode_i -eq 0 ]; then
265
266                         echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
267
268                         #Check if nonrtric namespace exists, if not create it
269                         __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
270
271                         __export_agent_vars $1
272
273                         # Create config map for config
274                         configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
275                         cp $2 $configfile
276                         output_yaml=$PWD/tmp/pa_cfc.yaml
277                         __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
278
279                         # Create config map for data
280                         data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
281                         if [ $# -lt 3 ]; then
282                                 #create empty dummy file
283                                 echo "{}" > $data_json
284                         else
285                                 cp $3 $data_json
286                         fi
287                         output_yaml=$PWD/tmp/pa_cfd.yaml
288                         __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
289
290                         ## Create pv
291                         input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
292                         output_yaml=$PWD/tmp/pa_pv.yaml
293                         __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
294
295                         ## Create pvc
296                         input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
297                         output_yaml=$PWD/tmp/pa_pvc.yaml
298                         __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
299
300                         # Create service
301                         input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
302                         output_yaml=$PWD/tmp/pa_svc.yaml
303                         __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
304
305                         # Create app
306                         input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
307                         output_yaml=$PWD/tmp/pa_app.yaml
308                         __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
309
310                 fi
311
312                 # 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
313                 if [ $retcode_i -eq 0 ]; then
314                         __PA_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
315                         if [ -z "$__PA_WORKER_NODE" ]; then
316                                 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
317                         fi
318                 else
319                         echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
320                 fi
321
322                 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
323
324         else
325                 __check_included_image 'PA'
326                 if [ $? -eq 1 ]; then
327                         echo -e $RED"The Policy Agent app is not included in this test script"$ERED
328                         echo -e $RED"The Policy Agent will not be started"$ERED
329                         exit
330                 fi
331
332                 curdir=$PWD
333                 cd $SIM_GROUP
334                 cd policy_agent
335                 cd $POLICY_AGENT_HOST_MNT_DIR
336                 #cd ..
337                 if [ -d db ]; then
338                         if [ "$(ls -A $DIR)" ]; then
339                                 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
340                                 rm -rf db/*  &> /dev/null
341                                 if [ $? -ne 0 ]; then
342                                         echo -e $RED" Cannot remove database files in: $PWD"$ERED
343                                         exit 1
344                                 fi
345                         fi
346                 else
347                         echo " No files in mounted dir or dir does not exists"
348                 fi
349                 cd $curdir
350
351                 __export_agent_vars $1
352
353                 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
354
355                 envsubst < $2 > $dest_file
356
357                 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
358
359                 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
360         fi
361
362         __collect_endpoint_stats_image_info "PMS" $POLICY_AGENT_IMAGE
363         echo ""
364         return 0
365 }
366
367 # Stop the policy agent
368 # args: -
369 # args: -
370 # (Function for test scripts)
371 stop_policy_agent() {
372         echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
373
374         if [ $RUNMODE == "KUBE" ]; then
375
376                 __check_prestarted_image "PA"
377                 if [ $? -eq 0 ]; then
378                         echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
379                         res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
380                         __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
381                         return 0
382                 fi
383                 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
384                 echo "  Deleting the replica set - a new will be started when the app is started"
385                 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
386                 if [ $? -ne 0 ]; then
387                         echo -e $RED" Could not delete replica set "$RED
388                         ((RES_CONF_FAIL++))
389                         return 1
390                 fi
391         else
392                 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
393                 if [ $? -ne 0 ]; then
394                         __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
395                         cat ./tmp/.dockererr
396                         ((RES_CONF_FAIL++))
397                         return 1
398                 fi
399         fi
400         echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
401         echo ""
402         return 0
403 }
404
405 # Start a previously stopped policy agent
406 # args: -
407 # (Function for test scripts)
408 start_stopped_policy_agent() {
409         echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
410
411         if [ $RUNMODE == "KUBE" ]; then
412
413                 __check_prestarted_image "PA"
414                 if [ $? -eq 0 ]; then
415                         echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
416                         res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
417                         __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
418                         __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
419                         return 0
420                 fi
421
422                 # Tie the PMS to the same worker node it was initially started on
423                 # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume
424                 if [ -z "$__PA_WORKER_NODE" ]; then
425                         echo -e $RED" No initial worker node found for pod "$RED
426                         ((RES_CONF_FAIL++))
427                         return 1
428                 else
429                         echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__PA_WORKER_NODE to deployment for $POLICY_AGENT_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD
430                         echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
431                         tmp=$(kubectl $KUBECONF patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
432                         if [ $? -ne 0 ]; then
433                                 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
434                         fi
435                         __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
436                 fi
437         else
438                 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
439                 if [ $? -ne 0 ]; then
440                         __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
441                         cat ./tmp/.dockererr
442                         ((RES_CONF_FAIL++))
443                         return 1
444                 fi
445         fi
446         __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
447         if [ $? -ne 0 ]; then
448                 return 1
449         fi
450         echo ""
451         return 0
452 }
453
454
455 # Function to perpare the consul configuration according to the current simulator configuration
456 # args: SDNC|NOSDNC <output-file>
457 # (Function for test scripts)
458 prepare_consul_config() {
459         echo -e $BOLD"Prepare Consul config"$EBOLD
460
461         echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
462
463         if [ $# != 2 ];  then
464                 ((RES_CONF_FAIL++))
465         __print_err "need two args,  SDNC|NOSDNC <output-file>" $@
466                 exit 1
467         fi
468
469         if [ $1 == "SDNC" ]; then
470                 echo -e " Config$BOLD including SDNC$EBOLD configuration"
471         elif [ $1 == "NOSDNC" ];  then
472                 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
473         else
474                 ((RES_CONF_FAIL++))
475         __print_err "need two args,  SDNC|NOSDNC <output-file>" $@
476                 exit 1
477         fi
478
479         config_json="\n            {"
480         if [ $1 == "SDNC" ]; then
481                 config_json=$config_json"\n   \"controller\": ["
482                 config_json=$config_json"\n                     {"
483                 config_json=$config_json"\n                       \"name\": \"$SDNC_APP_NAME\","
484                 config_json=$config_json"\n                       \"baseUrl\": \"$SDNC_SERVICE_PATH\","
485                 config_json=$config_json"\n                       \"userName\": \"$SDNC_USER\","
486                 config_json=$config_json"\n                       \"password\": \"$SDNC_PWD\""
487                 config_json=$config_json"\n                     }"
488                 config_json=$config_json"\n   ],"
489         fi
490
491         config_json=$config_json"\n   \"streams_publishes\": {"
492         config_json=$config_json"\n                            \"dmaap_publisher\": {"
493         config_json=$config_json"\n                              \"type\": \"message-router\","
494         config_json=$config_json"\n                              \"dmaap_info\": {"
495         config_json=$config_json"\n                                \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
496         config_json=$config_json"\n                              }"
497         config_json=$config_json"\n                            }"
498         config_json=$config_json"\n   },"
499         config_json=$config_json"\n   \"streams_subscribes\": {"
500         config_json=$config_json"\n                             \"dmaap_subscriber\": {"
501         config_json=$config_json"\n                               \"type\": \"message-router\","
502         config_json=$config_json"\n                               \"dmaap_info\": {"
503         config_json=$config_json"\n                                   \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
504         config_json=$config_json"\n                                 }"
505         config_json=$config_json"\n                               }"
506         config_json=$config_json"\n   },"
507
508         config_json=$config_json"\n   \"ric\": ["
509
510         if [ $RUNMODE == "KUBE" ]; then
511                 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
512                 rics=""
513                 ric_cntr=0
514                 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
515                         for im in $result; do
516                                 if [[ $im != *"-0" ]]; then
517                                         ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
518                                         rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
519                                         let ric_cntr=ric_cntr+1
520                                 fi
521                         done
522                 fi
523                 if [ $ric_cntr -eq 0 ]; then
524                         echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
525                 fi
526         else
527                 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
528                 if [ $? -ne 0 ] || [ -z "$rics" ]; then
529                         echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
530                         ((RES_CONF_FAIL++))
531                         return 1
532                 fi
533         fi
534         cntr=0
535         for ric in $rics; do
536                 if [ $cntr -gt 0 ]; then
537                         config_json=$config_json"\n          ,"
538                 fi
539                 config_json=$config_json"\n          {"
540                 if [ $RUNMODE == "KUBE" ]; then
541                         ric_id=${ric%.*.*} #extract pod id from full hosthame
542                         ric_id=$(echo "$ric_id" | tr '-' '_')
543                 else
544                         if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
545                                 ric_id=$ric
546                         else
547                                 ric_id=$(echo "$ric" | tr '-' '_')  #ric id still needs underscore as it is different from the container name
548                         fi
549                 fi
550                 echo " Found a1 sim: "$ric_id
551                 config_json=$config_json"\n            \"name\": \"$ric_id\","
552                 config_json=$config_json"\n            \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
553                 if [ $1 == "SDNC" ]; then
554                         config_json=$config_json"\n            \"controller\": \"$SDNC_APP_NAME\","
555                 fi
556                 config_json=$config_json"\n            \"managedElementIds\": ["
557                 config_json=$config_json"\n              \"me1_$ric_id\","
558                 config_json=$config_json"\n              \"me2_$ric_id\""
559                 config_json=$config_json"\n            ]"
560                 config_json=$config_json"\n          }"
561                 let cntr=cntr+1
562         done
563
564         config_json=$config_json"\n           ]"
565         config_json=$config_json"\n}"
566
567         if [ $RUNMODE == "KUBE" ]; then
568                 config_json="{\"config\":"$config_json"}"
569         fi
570
571         printf "$config_json">$2
572
573         echo ""
574 }
575
576 # Load the the appl config for the agent into a config map
577 agent_load_config() {
578         echo -e $BOLD"Agent - load config from "$EBOLD$1
579         data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
580         cp $1 $data_json
581         output_yaml=$PWD/tmp/pa_cfd.yaml
582         __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
583         echo ""
584 }
585
586
587 # Turn on debug level tracing in the agent
588 # args: -
589 # (Function for test scripts)
590 set_agent_debug() {
591         echo -e $BOLD"Setting agent debug logging"$EBOLD
592         curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
593         result=$(__do_curl "$curlString")
594         if [ $? -ne 0 ]; then
595                 __print_err "could not set debug mode" $@
596                 ((RES_CONF_FAIL++))
597                 return 1
598         fi
599         echo ""
600         return 0
601 }
602
603 # Turn on trace level tracing in the agent
604 # args: -
605 # (Function for test scripts)
606 set_agent_trace() {
607         echo -e $BOLD"Setting agent trace logging"$EBOLD
608         curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
609         result=$(__do_curl "$curlString")
610         if [ $? -ne 0 ]; then
611                 __print_err "could not set trace mode" $@
612                 ((RES_CONF_FAIL++))
613                 return 1
614         fi
615         echo ""
616         return 0
617 }
618
619 # Perform curl retries when making direct call to the agent for the specified http response codes
620 # Speace separated list of http response codes
621 # args: [<response-code>]*
622 use_agent_retries() {
623         echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
624         AGENT_RETRY_CODES=$@
625         echo ""
626         return
627 }
628
629 # Check the agent logs for WARNINGs and ERRORs
630 # args: -
631 # (Function for test scripts)
632 check_policy_agent_logs() {
633         __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
634 }
635
636 #########################################################
637 #### Test case functions A1 Policy management service
638 #########################################################
639
640 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
641 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
642 # args: json:<url> <target-value> [<timeout-in-seconds]
643 # (Function for test scripts)
644 api_equal() {
645     echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
646         if [ $# -eq 2 ] || [ $# -eq 3 ]; then
647                 if [[ $1 == "json:"* ]]; then
648                         if [ "$PMS_VERSION" == "V2" ]; then
649                                 __var_test "Policy Agent" $PA_SERVICE_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
650                         else
651                                 __var_test "Policy Agent" $PA_SERVICE_PATH"/" $1 "=" $2 $3
652                         fi
653                         return 0
654                 fi
655         fi
656         __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
657         return 1
658 }
659
660 # API Test function: GET /policies and V2 GET /v2/policy-instances
661 # 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>]*]
662 # 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>]*]
663 # (Function for test scripts)
664 api_get_policies() {
665         __log_test_start $@
666
667         if [ "$PMS_VERSION" == "V2" ]; then
668                 paramError=0
669                 variableParams=$(($#-4))
670                 if [ $# -lt 4 ]; then
671                         paramError=1
672                 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
673                         paramError=1
674                 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
675                         paramError=1
676                 fi
677
678                 if [ $paramError -ne 0 ]; then
679                         __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>]*]" $@
680                         return 1
681                 fi
682         else
683                 paramError=0
684                 variableParams=$(($#-4))
685                 if [ $# -lt 4 ]; then
686                         paramError=1
687                 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
688                         paramError=1
689                 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
690                         paramError=1
691                 fi
692
693                 if [ $paramError -ne 0 ]; then
694                         __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>]*]" $@
695                         return 1
696                 fi
697         fi
698
699         queryparams=""
700         if [ "$PMS_VERSION" == "V2" ]; then
701                 if [ $2 != "NORIC" ]; then
702                         queryparams="?ric_id="$2
703                 fi
704                 if [ $3 != "NOSERVICE" ]; then
705                         if [ -z $queryparams ]; then
706                                 queryparams="?service_id="$3
707                         else
708                                 queryparams=$queryparams"&service_id="$3
709                         fi
710                 fi
711                 if [ $4 != "NOTYPE" ]; then
712                         if [ -z $queryparams ]; then
713                                 queryparams="?policytype_id="$4
714                         else
715                                 queryparams=$queryparams"&policytype_id="$4
716                         fi
717                 fi
718
719                 query="/v2/policy-instances"$queryparams
720                 res="$(__do_curl_to_api PA GET $query)"
721                 status=${res:${#res}-3}
722
723                 if [ $status -ne $1 ]; then
724                         __log_test_fail_status_code $1 $status
725                         return 1
726                 fi
727
728                 if [ $# -gt 4 ]; then
729                         body=${res:0:${#res}-3}
730                         if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
731                                 targetJson="["
732                         else
733                                 targetJson="["
734                                 arr=(${@:5})
735
736                                 for ((i=0; i<$(($#-4)); i=i+7)); do
737
738                                         if [ "$targetJson" != "[" ]; then
739                                                 targetJson=$targetJson","
740                                         fi
741                                         targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
742                                         if [ "${arr[$i+3]}" == "EMPTY" ]; then
743                                                 targetJson=$targetJson"\"\","
744                                         else
745                                                 targetJson=$targetJson"\"${arr[$i+3]}\","
746                                         fi
747                                         targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
748                                         file="./tmp/.p.json"
749                                         sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
750                                         json=$(cat $file)
751                                         targetJson=$targetJson"\"policy_data\":"$json"}"
752                                 done
753                         fi
754
755                         targetJson=$targetJson"]"
756                         targetJson="{\"policies\": $targetJson}"
757                         echo "TARGET JSON: $targetJson" >> $HTTPLOG
758                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
759
760                         if [ $res -ne 0 ]; then
761                                 __log_test_fail_body
762                                 return 1
763                         fi
764                 fi
765         else
766                 if [ $2 != "NORIC" ]; then
767                         queryparams="?ric="$2
768                 fi
769                 if [ $3 != "NOSERVICE" ]; then
770                         if [ -z $queryparams ]; then
771                                 queryparams="?service="$3
772                         else
773                                 queryparams=$queryparams"&service="$3
774                         fi
775                 fi
776                 if [ $4 != "NOTYPE" ]; then
777                         if [ -z $queryparams ]; then
778                                 queryparams="?type="$4
779                         else
780                                 queryparams=$queryparams"&type="$4
781                         fi
782                 fi
783
784                 query="/policies"$queryparams
785                 res="$(__do_curl_to_api PA GET $query)"
786                 status=${res:${#res}-3}
787
788                 if [ $status -ne $1 ]; then
789                         __log_test_fail_status_code $1 $status
790                         return 1
791                 fi
792
793                 if [ $# -gt 4 ]; then
794                         if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
795                                 targetJson="["
796                         else
797                                 body=${res:0:${#res}-3}
798                                 targetJson="["
799                                 arr=(${@:5})
800
801                                 for ((i=0; i<$(($#-4)); i=i+5)); do
802
803                                         if [ "$targetJson" != "[" ]; then
804                                                 targetJson=$targetJson","
805                                         fi
806                                         targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
807                                         if [ "${arr[$i+3]}" == "EMPTY" ]; then
808                                                 targetJson=$targetJson"\"\","
809                                         else
810                                                 targetJson=$targetJson"\"${arr[$i+3]}\","
811                                         fi
812                                         file="./tmp/.p.json"
813                                         sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
814                                         json=$(cat $file)
815                                         targetJson=$targetJson"\"json\":"$json"}"
816                                 done
817                         fi
818
819                         targetJson=$targetJson"]"
820                         echo "TARGET JSON: $targetJson" >> $HTTPLOG
821                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
822
823                         if [ $res -ne 0 ]; then
824                                 __log_test_fail_body
825                                 return 1
826                         fi
827                 fi
828         fi
829         __collect_endpoint_stats "PMS" 00 "GET" $PMS_API_PREFIX"/v2/policy-instances" $status
830         __log_test_pass
831         return 0
832
833 }
834
835
836 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
837 # args: <response-code>  <policy-id> [<template-file>]
838 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
839
840 # (Function for test scripts)
841 api_get_policy() {
842         __log_test_start $@
843
844
845         if [ "$PMS_VERSION" == "V2" ]; then
846                 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
847                         __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
848                         return 1
849                 fi
850                 query="/v2/policies/$UUID$2"
851         else
852                 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
853                         __print_err "<response-code>  <policy-id> [<template-file>] " $@
854                         return 1
855                 fi
856                 query="/policy?id=$UUID$2"
857         fi
858         res="$(__do_curl_to_api PA GET $query)"
859         status=${res:${#res}-3}
860
861         if [ $status -ne $1 ]; then
862                 __log_test_fail_status_code $1 $status
863                 return 1
864         fi
865
866         if [ "$PMS_VERSION" == "V2" ]; then
867                 if [ $# -eq 8 ]; then
868
869                         #Create a policy json to compare with
870                         body=${res:0:${#res}-3}
871
872                         targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
873                         if [ $7 != "NOTRANSIENT" ]; then
874                                 targetJson=$targetJson", \"transient\":$7"
875                         fi
876                         if [ $6 != "NOTYPE" ]; then
877                                 targetJson=$targetJson", \"policytype_id\":\"$6\""
878                         else
879                                 targetJson=$targetJson", \"policytype_id\":\"\""
880                         fi
881                         if [ $8 != "NOURL" ]; then
882                                 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
883                         fi
884
885                         data=$(sed 's/XXX/'${2}'/g' $3)
886                         targetJson=$targetJson", \"policy_data\":$data"
887                         targetJson="{$targetJson}"
888
889                         echo "TARGET JSON: $targetJson" >> $HTTPLOG
890                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
891                         if [ $res -ne 0 ]; then
892                                 __log_test_fail_body
893                                 return 1
894                         fi
895                 fi
896         else
897                 if [ $# -eq 3 ]; then
898                         #Create a policy json to compare with
899                         body=${res:0:${#res}-3}
900                         file="./tmp/.p.json"
901                         sed 's/XXX/'${2}'/g' $3 > $file
902                         targetJson=$(< $file)
903                         echo "TARGET JSON: $targetJson" >> $HTTPLOG
904                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
905                         if [ $res -ne 0 ]; then
906                                 __log_test_fail_body
907                         fi
908                 fi
909         fi
910
911         __collect_endpoint_stats "PMS" 01 "GET" $PMS_API_PREFIX"/v2/policies/{policy_id}" $status
912         __log_test_pass
913         return 0
914 }
915
916 # API Test function: PUT /policy and V2 PUT /policies
917 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
918 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
919 # (Function for test scripts)
920 api_put_policy() {
921         __log_test_start $@
922
923         if [ "$PMS_VERSION" == "V2" ]; then
924                 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
925                         __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
926                         return 1
927                 fi
928         else
929                 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
930                         __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
931                         return 1
932                 fi
933         fi
934
935         count=0
936         max=1
937         serv=$2
938         ric=$3
939         pt=$4
940         pid=$5
941         trans=$6
942
943         if [ "$PMS_VERSION" == "V2" ]; then
944                 noti=$7
945                 temp=$8
946                 if [ $# -eq 9 ]; then
947                         max=$9
948                 fi
949         else
950                 temp=$7
951                 if [ $# -eq 8 ]; then
952                         max=$8
953                 fi
954         fi
955
956         while [ $count -lt $max ]; do
957                 if [ "$PMS_VERSION" == "V2" ]; then
958
959                         query="/v2/policies"
960
961                         inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
962                         if [ $trans != "NOTRANSIENT" ]; then
963                                 inputJson=$inputJson", \"transient\":$trans"
964                         fi
965                         if [ $pt != "NOTYPE" ]; then
966                                 inputJson=$inputJson", \"policytype_id\":\"$pt\""
967                         else
968                                 inputJson=$inputJson", \"policytype_id\":\"\""
969                         fi
970                         if [ $noti != "NOURL" ]; then
971                                 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
972                         fi
973                         file="./tmp/.p.json"
974                         data=$(sed 's/XXX/'${pid}'/g' $temp)
975                         inputJson=$inputJson", \"policy_data\":$data"
976                         inputJson="{$inputJson}"
977                         echo $inputJson > $file
978                 else
979                         query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
980
981                         if [ $pt != "NOTYPE" ]; then
982                                 query=$query"&type=$pt"
983                         fi
984
985                         if [ $trans != NOTRANSIENT ]; then
986                                 query=$query"&transient=$trans"
987                         fi
988
989                         file="./tmp/.p.json"
990                         sed 's/XXX/'${pid}'/g' $temp > $file
991                 fi
992         res="$(__do_curl_to_api PA PUT $query $file)"
993         status=${res:${#res}-3}
994                 echo -ne " Executing "$count"("$max")${SAMELINE}"
995                 if [ $status -ne $1 ]; then
996                         echo " Executed "$count"?("$max")"
997                         __log_test_fail_status_code $1 $status
998                         return 1
999                 fi
1000                 let pid=$pid+1
1001                 let count=$count+1
1002                 echo -ne " Executed  "$count"("$max")${SAMELINE}"
1003         done
1004         __collect_endpoint_stats "PMS" 02 "PUT" $PMS_API_PREFIX"/v2/policies" $status $max
1005         echo ""
1006
1007         __log_test_pass
1008         return 0
1009 }
1010
1011 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
1012 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1013 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
1014 # (Function for test scripts)
1015
1016 api_put_policy_batch() {
1017         __log_test_start $@
1018
1019         if [ "$PMS_VERSION" == "V2" ]; then
1020                 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1021                         __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1022                         return 1
1023                 fi
1024         else
1025                 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1026                         __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1027                         return 1
1028                 fi
1029         fi
1030
1031         count=0
1032         max=1
1033         serv=$2
1034         ric=$3
1035         pt=$4
1036         pid=$5
1037         trans=$6
1038         if [ "$PMS_VERSION" == "V2" ]; then
1039                 noti=$7
1040                 temp=$8
1041                 if [ $# -eq 9 ]; then
1042                         max=$9
1043                 fi
1044         else
1045                 temp=$7
1046                 if [ $# -eq 8 ]; then
1047                         max=$8
1048                 fi
1049         fi
1050
1051         ARR=""
1052         while [ $count -lt $max ]; do
1053                 if [ "$PMS_VERSION" == "V2" ]; then
1054                         query="/v2/policies"
1055
1056                         inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1057                         if [ $trans != "NOTRANSIENT" ]; then
1058                                 inputJson=$inputJson", \"transient\":$trans"
1059                         fi
1060                         if [ $pt != "NOTYPE" ]; then
1061                                 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1062                         else
1063                                 inputJson=$inputJson", \"policytype_id\":\"\""
1064                         fi
1065                         if [ $noti != "NOURL" ]; then
1066                                 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1067                         fi
1068                         file="./tmp/.p.json"
1069                         data=$(sed 's/XXX/'${pid}'/g' $temp)
1070                         inputJson=$inputJson", \"policy_data\":$data"
1071                         inputJson="{$inputJson}"
1072                         echo $inputJson > $file
1073                 else
1074                         query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1075
1076                         if [ $pt != "NOTYPE" ]; then
1077                                 query=$query"&type=$pt"
1078                         fi
1079
1080                         if [ $trans != NOTRANSIENT ]; then
1081                                 query=$query"&transient=$trans"
1082                         fi
1083                         file="./tmp/.p.json"
1084                         sed 's/XXX/'${pid}'/g' $temp > $file
1085                 fi
1086         res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
1087         status=${res:${#res}-3}
1088                 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1089
1090                 if [ $status -ne 200 ]; then
1091                         echo " Requested(batch) "$count"?("$max")"
1092                         __log_test_fail_status_code 200 $status
1093                         return 1
1094                 fi
1095                 cid=${res:0:${#res}-3}
1096                 ARR=$ARR" "$cid
1097                 let pid=$pid+1
1098                 let count=$count+1
1099                 echo -ne " Requested(batch)  "$count"("$max")${SAMELINE}"
1100         done
1101
1102         echo ""
1103         count=0
1104         for cid in $ARR; do
1105
1106         res="$(__do_curl_to_api PA RESPONSE $cid)"
1107         status=${res:${#res}-3}
1108                 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
1109
1110                 if [ $status -ne $1 ]; then
1111                         echo " Accepted(batch) "$count"?("$max")"
1112                         __log_test_fail_status_code $1 $status
1113                         return 1
1114                 fi
1115
1116                 let count=$count+1
1117                 echo -ne " Accepted(batch)  "$count"("$max")${SAMELINE}"
1118         done
1119         __collect_endpoint_stats "PMS" 02 "PUT" $PMS_API_PREFIX"/v2/policies" $1 $max
1120
1121         echo ""
1122
1123         __log_test_pass
1124         return 0
1125 }
1126
1127 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1128 # 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>
1129 # 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>
1130 # (Function for test scripts)
1131 api_put_policy_parallel() {
1132         __log_test_start $@
1133
1134         if [ "$PMS_VERSION" == "V2" ]; then
1135                 if [ $# -ne 11 ]; then
1136                         __print_err "<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>" $@
1137                         return 1
1138                 fi
1139         else
1140                 if [ $# -ne 10 ]; then
1141                         __print_err " <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <template-file> <count-per-ric> <number-of-threads>" $@
1142                         return 1
1143                 fi
1144         fi
1145         resp_code=$1; shift;
1146         serv=$1; shift
1147         ric_base=$1; shift;
1148         num_rics=$1; shift;
1149         type=$1; shift;
1150         start_id=$1; shift;
1151         transient=$1; shift;
1152         if [ "$PMS_VERSION" == "V2" ]; then
1153                 noti=$1; shift;
1154         else
1155                 noti=""
1156         fi
1157         template=$1; shift;
1158         count=$1; shift;
1159         pids=$1; shift;
1160
1161         #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1162         if [ $PA_ADAPTER_TYPE != "REST" ]; then
1163                 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1164                 echo " Info - will execute over agent REST"
1165         fi
1166         if [ "$PMS_VERSION" == "V2" ]; then
1167                 if [ $serv == "NOSERVICE" ]; then
1168                         serv=""
1169                 fi
1170                 query="$PMS_API_PREFIX/v2/policies"
1171         else
1172                 if [ $serv == "NOSERVICE" ]; then
1173                         serv=""
1174                 fi
1175                 query="/policy?service=$serv"
1176
1177                 if [ $type != "NOTYPE" ]; then
1178                         query=$query"&type=$type"
1179                 fi
1180
1181                 if [ $transient != NOTRANSIENT ]; then
1182                         query=$query"&transient=$transient"
1183                 fi
1184         fi
1185
1186         urlbase=${PA_ADAPTER}${query}
1187
1188         httpproxy="NOPROXY"
1189         if [ ! -z "$KUBE_PROXY_PATH" ]; then
1190                 httpproxy=$KUBE_PROXY_PATH
1191         fi
1192
1193         for ((i=1; i<=$pids; i++))
1194         do
1195                 uuid=$UUID
1196                 if [ -z "$uuid" ]; then
1197                         uuid="NOUUID"
1198                 fi
1199                 echo "" > "./tmp/.pid${i}.res.txt"
1200                 if [ "$PMS_VERSION" == "V2" ]; then
1201                         echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1202                 else
1203                         echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1204                 fi
1205                 echo $i
1206         done  | xargs -n 1 -I{} -P $pids bash -c '{
1207                 arg=$(echo {})
1208                 echo " Parallel process $arg started"
1209                 tmp=$(< "./tmp/.pid${arg}.txt")
1210                 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1211         }'
1212         msg=""
1213         for ((i=1; i<=$pids; i++))
1214         do
1215                 file="./tmp/.pid${i}.res.txt"
1216                 tmp=$(< $file)
1217                 if [ -z "$tmp" ]; then
1218                         echo " Process $i : unknown result (result file empty"
1219                         msg="failed"
1220                 else
1221                         res=${tmp:0:1}
1222                         if [ $res == "0" ]; then
1223                                 echo " Process $i : OK - "${tmp:1}
1224                         else
1225                                 echo " Process $i : failed - "${tmp:1}
1226                                 msg="failed"
1227                         fi
1228                 fi
1229         done
1230         if [ -z $msg ]; then
1231                 __collect_endpoint_stats "PMS" 02 "PUT" $PMS_API_PREFIX"/v2/policies" $resp_code $(($count*$num_rics))
1232                 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1233                 return 0
1234         fi
1235
1236         __log_test_fail_general "One of more processes failed to execute"
1237         return 1
1238 }
1239
1240 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1241 # args: <response-code> <policy-id> [count]
1242 # (Function for test scripts)
1243 api_delete_policy() {
1244         __log_test_start $@
1245
1246     if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1247         __print_err "<response-code> <policy-id> [count]" $@
1248         return 1
1249     fi
1250
1251         count=0
1252         max=1
1253
1254         if [ $# -eq 3 ]; then
1255                 max=$3
1256         fi
1257
1258         pid=$2
1259
1260         while [ $count -lt $max ]; do
1261                 if [ "$PMS_VERSION" == "V2" ]; then
1262                         query="/v2/policies/"$UUID$pid
1263                 else
1264                         query="/policy?id="$UUID$pid
1265                 fi
1266                 res="$(__do_curl_to_api PA DELETE $query)"
1267                 status=${res:${#res}-3}
1268                 echo -ne " Executing "$count"("$max")${SAMELINE}"
1269
1270                 if [ $status -ne $1 ]; then
1271                         echo " Executed "$count"?("$max")"
1272                         __log_test_fail_status_code $1 $status
1273                         return 1
1274                 fi
1275
1276                 let pid=$pid+1
1277                 let count=$count+1
1278                 echo -ne " Executed  "$count"("$max")${SAMELINE}"
1279         done
1280         __collect_endpoint_stats "PMS" 03 "DELETE" $PMS_API_PREFIX"/v2/policies/{policy_id}" $status $max
1281         echo ""
1282
1283         __log_test_pass
1284         return 0
1285 }
1286
1287 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1288 # args: <response-code> <policy-id> [count]
1289 # (Function for test scripts)
1290 api_delete_policy_batch() {
1291         __log_test_start $@
1292
1293     if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1294         __print_err "<response-code> <policy-id> [count]" $@
1295         return 1
1296     fi
1297
1298         count=0
1299         max=1
1300
1301         if [ $# -eq 3 ]; then
1302                 max=$3
1303         fi
1304
1305         pid=$2
1306         ARR=""
1307         while [ $count -lt $max ]; do
1308                 if [ "$PMS_VERSION" == "V2" ]; then
1309                         query="/v2/policies/"$UUID$pid
1310                 else
1311                         query="/policy?id="$UUID$pid
1312                 fi
1313                 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
1314                 status=${res:${#res}-3}
1315                 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1316
1317                 if [ $status -ne 200 ]; then
1318                         echo " Requested(batch) "$count"?("$max")"
1319                         __log_test_fail_status_code 200 $status
1320                         return 1
1321                 fi
1322                 cid=${res:0:${#res}-3}
1323                 ARR=$ARR" "$cid
1324                 let pid=$pid+1
1325                 let count=$count+1
1326                 echo -ne " Requested(batch)  "$count"("$max")${SAMELINE}"
1327         done
1328
1329         echo ""
1330
1331         count=0
1332         for cid in $ARR; do
1333
1334         res="$(__do_curl_to_api PA RESPONSE $cid)"
1335         status=${res:${#res}-3}
1336                 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1337
1338                 if [ $status -ne $1 ]; then
1339                         echo " Deleted(batch) "$count"?("$max")"
1340                         __log_test_fail_status_code $1 $status
1341                         return 1
1342                 fi
1343
1344                 let count=$count+1
1345                 echo -ne " Deleted(batch)  "$count"("$max")${SAMELINE}"
1346         done
1347         __collect_endpoint_stats "PMS" 03 "DELETE" $PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
1348
1349         echo ""
1350
1351         __log_test_pass
1352         return 0
1353 }
1354
1355 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1356 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1357 # (Function for test scripts)
1358 api_delete_policy_parallel() {
1359         __log_test_start $@
1360
1361     if [ $# -ne 5 ]; then
1362         __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1363         return 1
1364     fi
1365         resp_code=$1; shift;
1366         num_rics=$1; shift;
1367         start_id=$1; shift;
1368         count=$1; shift;
1369         pids=$1; shift;
1370
1371         #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1372         if [ $PA_ADAPTER_TYPE != "REST" ]; then
1373                 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1374                 echo " Info - will execute over agent REST"
1375         fi
1376
1377         if [ "$PMS_VERSION" == "V2" ]; then
1378                 query="$PMS_API_PREFIX/v2/policies/"
1379         else
1380                 query="/policy"
1381         fi
1382
1383         urlbase=${PA_ADAPTER}${query}
1384
1385         httpproxy="NOPROXY"
1386         if [ ! -z "$KUBE_PROXY_PATH" ]; then
1387                 httpproxy=$KUBE_PROXY_PATH
1388         fi
1389
1390         for ((i=1; i<=$pids; i++))
1391         do
1392                 uuid=$UUID
1393                 if [ -z "$uuid" ]; then
1394                         uuid="NOUUID"
1395                 fi
1396                 echo "" > "./tmp/.pid${i}.del.res.txt"
1397                 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1398                 echo $i
1399         done  | xargs -n 1 -I{} -P $pids bash -c '{
1400                 arg=$(echo {})
1401                 echo " Parallel process $arg started"
1402                 tmp=$(< "./tmp/.pid${arg}.del.txt")
1403                 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1404         }'
1405         msg=""
1406         for ((i=1; i<=$pids; i++))
1407         do
1408                 file="./tmp/.pid${i}.del.res.txt"
1409                 tmp=$(< $file)
1410                 if [ -z "$tmp" ]; then
1411                         echo " Process $i : unknown result (result file empty"
1412                         msg="failed"
1413                 else
1414                         res=${tmp:0:1}
1415                         if [ $res == "0" ]; then
1416                                 echo " Process $i : OK - "${tmp:1}
1417                         else
1418                                 echo " Process $i : failed - "${tmp:1}
1419                                 msg="failed"
1420                         fi
1421                 fi
1422         done
1423         if [ -z $msg ]; then
1424                 __collect_endpoint_stats "PMS" 03 "DELETE" $PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count*$num_rics))
1425                 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1426                 return 0
1427         fi
1428
1429         __log_test_fail_general "One of more processes failed to execute"
1430         return 1
1431 }
1432
1433 # API Test function: GET /policy_ids and V2 GET /v2/policies
1434 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1435 # (Function for test scripts)
1436 api_get_policy_ids() {
1437         __log_test_start $@
1438
1439     if [ $# -lt 4 ]; then
1440                 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1441                 return 1
1442         fi
1443
1444         queryparams=""
1445
1446         if [ "$PMS_VERSION" == "V2" ]; then
1447                 if [ $2 != "NORIC" ]; then
1448                         queryparams="?ric_id="$2
1449                 fi
1450
1451                 if [ $3 != "NOSERVICE" ]; then
1452                         if [ -z $queryparams ]; then
1453                                 queryparams="?service_id="$3
1454                         else
1455                                 queryparams=$queryparams"&service_id="$3
1456                         fi
1457                 fi
1458                 if [ $4 != "NOTYPE" ]; then
1459                         if [ -z $queryparams ]; then
1460                                 queryparams="?policytype_id="$4
1461                         else
1462                                 queryparams=$queryparams"&policytype_id="$4
1463                         fi
1464                 fi
1465
1466                 query="/v2/policies"$queryparams
1467         else
1468                 if [ $2 != "NORIC" ]; then
1469                         queryparams="?ric="$2
1470                 fi
1471
1472                 if [ $3 != "NOSERVICE" ]; then
1473                         if [ -z $queryparams ]; then
1474                                 queryparams="?service="$3
1475                         else
1476                                 queryparams=$queryparams"&service="$3
1477                         fi
1478                 fi
1479                 if [ $4 != "NOTYPE" ]; then
1480                         if [ -z $queryparams ]; then
1481                                 queryparams="?type="$4
1482                         else
1483                                 queryparams=$queryparams"&type="$4
1484                         fi
1485                 fi
1486
1487                 query="/policy_ids"$queryparams
1488         fi
1489
1490     res="$(__do_curl_to_api PA GET $query)"
1491     status=${res:${#res}-3}
1492
1493         if [ $status -ne $1 ]; then
1494                 __log_test_fail_status_code $1 $status
1495                 return 1
1496         fi
1497
1498         if [ $# -gt 4 ]; then
1499                 body=${res:0:${#res}-3}
1500                 targetJson="["
1501
1502                 for pid in ${@:5} ; do
1503                         if [ "$targetJson" != "[" ]; then
1504                                 targetJson=$targetJson","
1505                         fi
1506                         if [ $pid != "NOID" ]; then
1507                                 targetJson=$targetJson"\"$UUID$pid\""
1508                         fi
1509                 done
1510
1511                 targetJson=$targetJson"]"
1512                 if [ "$PMS_VERSION" == "V2" ]; then
1513                         targetJson="{\"policy_ids\": $targetJson}"
1514                 fi
1515                 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1516                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1517
1518                 if [ $res -ne 0 ]; then
1519                         __log_test_fail_body
1520                         return 1
1521                 fi
1522         fi
1523
1524         __collect_endpoint_stats "PMS" 04 "GET" $PMS_API_PREFIX"/v2/policies" $status
1525         __log_test_pass
1526         return 0
1527 }
1528
1529 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1530 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1531 # (Function for test scripts)
1532 api_get_policy_type() {
1533         __log_test_start $@
1534
1535         if [ "$PMS_VERSION" != "V2" ]; then
1536                 __log_test_fail_not_supported
1537                 return 1
1538         fi
1539
1540     if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1541         __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1542         return 1
1543     fi
1544         query="/v2/policy-types/$2"
1545
1546         res="$(__do_curl_to_api PA GET $query)"
1547         status=${res:${#res}-3}
1548
1549         if [ $status -ne $1 ]; then
1550                 __log_test_fail_status_code $1 $status
1551                 return 1
1552         fi
1553
1554         if [ $# -eq 3 ]; then
1555
1556                 body=${res:0:${#res}-3}
1557
1558                 targetJson=$(< $3)
1559                 targetJson="{\"policy_schema\":$targetJson}"
1560                 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1561                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1562
1563                 if [ $res -ne 0 ]; then
1564                         __log_test_fail_body
1565                         return 1
1566                 fi
1567         fi
1568
1569         __collect_endpoint_stats "PMS" 05 "GET" $PMS_API_PREFIX"/v2/policy-types/{policyTypeId}" $status
1570         __log_test_pass
1571         return 0
1572 }
1573
1574 # API Test function: GET /policy_schema
1575 # args: <response-code> <policy-type-id> [<schema-file>]
1576 # (Function for test scripts)
1577 api_get_policy_schema() {
1578         __log_test_start $@
1579
1580         if [ "$PMS_VERSION" == "V2" ]; then
1581                 __log_test_fail_not_supported
1582                 return 1
1583         fi
1584
1585     if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1586         __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1587         return 1
1588     fi
1589         query="/policy_schema?id=$2"
1590         res="$(__do_curl_to_api PA GET $query)"
1591         status=${res:${#res}-3}
1592
1593         if [ $status -ne $1 ]; then
1594                 __log_test_fail_status_code $1 $status
1595                 return 1
1596         fi
1597
1598         if [ $# -eq 3 ]; then
1599
1600                 body=${res:0:${#res}-3}
1601
1602                 targetJson=$(< $3)
1603
1604                 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1605                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1606
1607                 if [ $res -ne 0 ]; then
1608                         __log_test_fail_body
1609                         return 1
1610                 fi
1611         fi
1612
1613         __collect_endpoint_stats "PMS" 06 "GET" $PMS_API_PREFIX"/v2/policy_schema" $status
1614         __log_test_pass
1615         return 0
1616 }
1617
1618 # API Test function: GET /policy_schemas
1619 # args: <response-code>  <ric-id>|NORIC [<schema-file>|NOFILE]*
1620 # args(V2): <response-code>
1621 # (Function for test scripts)
1622 api_get_policy_schemas() {
1623         __log_test_start $@
1624
1625         if [ "$PMS_VERSION" == "V2" ]; then
1626                 if [ $# -ne 1 ]; then
1627                         __print_err "<response-code>" $@
1628                         return 1
1629                 fi
1630         else
1631                 if [ $# -lt 2 ]; then
1632                         __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1633                         return 1
1634                 fi
1635         fi
1636         if [ "$PMS_VERSION" == "V2" ]; then
1637                 query="/v2/policy-schemas"
1638         else
1639                 query="/policy_schemas"
1640                 if [ $2 != "NORIC" ]; then
1641                         query=$query"?ric="$2
1642                 fi
1643         fi
1644
1645         res="$(__do_curl_to_api PA GET $query)"
1646         status=${res:${#res}-3}
1647
1648         if [ $status -ne $1 ]; then
1649                 __log_test_fail_status_code $1 $status
1650                 return 1
1651         fi
1652
1653         if [ $# -gt 2 ]; then
1654                 body=${res:0:${#res}-3}
1655                 targetJson="["
1656
1657                 for file in ${@:3} ; do
1658                         if [ "$targetJson" != "[" ]; then
1659                                 targetJson=$targetJson","
1660                         fi
1661                         if [ $file == "NOFILE" ]; then
1662                                 targetJson=$targetJson"{}"
1663                         else
1664                                 targetJson=$targetJson$(< $file)
1665                         fi
1666                 done
1667
1668                 targetJson=$targetJson"]"
1669                 if [ "$PMS_VERSION" == "V2" ]; then
1670                         targetJson="{\"policy_schemas\": $targetJson }"
1671                 fi
1672                 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1673                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1674
1675                 if [ $res -ne 0 ]; then
1676                         __log_test_fail_body
1677                         return 1
1678                 fi
1679         fi
1680
1681         __collect_endpoint_stats "PMS" 07 "GET" $PMS_API_PREFIX"/v2/policy-schemas" $status
1682         __log_test_pass
1683         return 0
1684 }
1685
1686 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1687 # arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
1688 # (Function for test scripts)
1689 api_get_policy_status() {
1690         __log_test_start $@
1691
1692     if [ $# -lt 2 ] || [ $# -gt 5 ]; then
1693                 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
1694                 return 1
1695         fi
1696
1697         targetJson=""
1698         if [ $# -eq 2 ]; then
1699                 :
1700         elif [ "$3" == "STD" ]; then
1701                 targetJson="{\"enforceStatus\":\"$4\""
1702                 if [ $# -eq 5 ]; then
1703                         targetJson=$targetJson",\"reason\":\"$5\""
1704                 fi
1705                 targetJson=$targetJson"}"
1706         elif [ "$3" == "STD2" ]; then
1707                 if [ $4 == "EMPTY" ]; then
1708                         targetJson="{\"enforceStatus\":\"\""
1709                 else
1710                         targetJson="{\"enforceStatus\":\"$4\""
1711                 fi
1712                 if [ $# -eq 5 ]; then
1713                         if [ $5 == "EMPTY" ]; then
1714                                 targetJson=$targetJson",\"enforceReason\":\"\""
1715                         else
1716                                 targetJson=$targetJson",\"enforceReason\":\"$5\""
1717                         fi
1718                 fi
1719                 targetJson=$targetJson"}"
1720         elif [ "$3" == "OSC" ]; then
1721                 targetJson="{\"instance_status\":\"$4\""
1722                 if [ $# -eq 5 ]; then
1723                         targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1724                 fi
1725                 targetJson=$targetJson",\"created_at\":\"????\"}"
1726         else
1727                 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1728                 return 1
1729         fi
1730
1731         if [ "$PMS_VERSION" == "V2" ]; then
1732                 query="/v2/policies/$UUID$2/status"
1733                 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1734         else
1735                 query="/policy_status?id="$UUID$2
1736         fi
1737
1738         res="$(__do_curl_to_api PA GET $query)"
1739     status=${res:${#res}-3}
1740
1741         if [ $status -ne $1 ]; then
1742                 __log_test_fail_status_code $1 $status
1743                 return 1
1744         fi
1745         if [ $# -gt 2 ]; then
1746                 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1747                 body=${res:0:${#res}-3}
1748                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1749
1750                 if [ $res -ne 0 ]; then
1751                         __log_test_fail_body
1752                         return 1
1753                 fi
1754         fi
1755         __collect_endpoint_stats "PMS" 08 "GET" $PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
1756         __log_test_pass
1757         return 0
1758 }
1759
1760 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1761 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1762 # (Function for test scripts)
1763 api_get_policy_types() {
1764         __log_test_start $@
1765
1766     if [ $# -lt 1 ]; then
1767                 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1768                 return 1
1769         fi
1770
1771         if [ "$PMS_VERSION" == "V2" ]; then
1772                 if [ $# -eq 1 ]; then
1773                         query="/v2/policy-types"
1774                 elif [ $2 == "NORIC" ]; then
1775                         query="/v2/policy-types"
1776                 else
1777                         query="/v2/policy-types?ric_id=$2"
1778                 fi
1779         else
1780                 if [ $# -eq 1 ]; then
1781                         query="/policy_types"
1782                 elif [ $2 == "NORIC" ]; then
1783                         query="/policy_types"
1784                 else
1785                         query="/policy_types?ric=$2"
1786                 fi
1787         fi
1788
1789     res="$(__do_curl_to_api PA GET $query)"
1790     status=${res:${#res}-3}
1791
1792         if [ $status -ne $1 ]; then
1793                 __log_test_fail_status_code $1 $status
1794                 return 1
1795         fi
1796
1797         if [ $# -gt 2 ]; then
1798                 body=${res:0:${#res}-3}
1799                 targetJson="["
1800
1801                 for pid in ${@:3} ; do
1802                         if [ "$targetJson" != "[" ]; then
1803                                 targetJson=$targetJson","
1804                         fi
1805                         if [ $pid == "EMPTY" ]; then
1806                                 pid=""
1807                         fi
1808                         targetJson=$targetJson"\"$pid\""
1809                 done
1810
1811                 targetJson=$targetJson"]"
1812                 if [ "$PMS_VERSION" == "V2" ]; then
1813                         targetJson="{\"policytype_ids\": $targetJson }"
1814                 fi
1815                 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1816                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1817
1818                 if [ $res -ne 0 ]; then
1819                         __log_test_fail_body
1820                         return 1
1821                 fi
1822         fi
1823
1824         __collect_endpoint_stats "PMS" 09 "GET" $PMS_API_PREFIX"/v2/policy-types" $status
1825         __log_test_pass
1826         return 0
1827 }
1828
1829 #########################################################
1830 #### Test case functions Health check
1831 #########################################################
1832
1833 # API Test function: GET /status and V2 GET /status
1834 # args: <response-code>
1835 # (Function for test scripts)
1836 api_get_status() {
1837         __log_test_start $@
1838     if [ $# -ne 1 ]; then
1839                 __print_err "<response-code>" $@
1840                 return 1
1841         fi
1842         if [ "$PMS_VERSION" == "V2" ]; then
1843                 query="/v2/status"
1844         else
1845                 query="/status"
1846         fi
1847     res="$(__do_curl_to_api PA GET $query)"
1848     status=${res:${#res}-3}
1849
1850         if [ $status -ne $1 ]; then
1851                 __log_test_fail_status_code $1 $status
1852                 return 1
1853         fi
1854
1855         __collect_endpoint_stats "PMS" 10 "GET" $PMS_API_PREFIX"/v2/status" $status
1856         __log_test_pass
1857         return 0
1858 }
1859
1860 # API Test function: GET /status (root) without api prefix
1861 # args: <response-code>
1862 # (Function for test scripts)
1863 api_get_status_root() {
1864         __log_test_start $@
1865     if [ $# -ne 1 ]; then
1866                 __print_err "<response-code>" $@
1867                 return 1
1868         fi
1869         query="/status"
1870         TMP_PREFIX=$PMS_API_PREFIX
1871         PMS_API_PREFIX=""
1872     res="$(__do_curl_to_api PA GET $query)"
1873         PMS_API_PREFIX=$TMP_PREFIX
1874     status=${res:${#res}-3}
1875
1876         if [ $status -ne $1 ]; then
1877                 __log_test_fail_status_code $1 $status
1878                 return 1
1879         fi
1880
1881         __collect_endpoint_stats "PMS" 19 "GET" "/status" $status
1882         __log_test_pass
1883         return 0
1884 }
1885
1886 #########################################################
1887 #### Test case functions RIC Repository
1888 #########################################################
1889
1890 # API Test function: GET /ric and V2 GET /v2/rics/ric
1891 # args: <reponse-code> <management-element-id> [<ric-id>]
1892 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1893 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1894 # (V2) format of ric-info:  <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1895
1896
1897 # (Function for test scripts)
1898 api_get_ric() {
1899         __log_test_start $@
1900
1901         if [ "$PMS_VERSION" == "V2" ]; then
1902                 if [ $# -lt 3 ]; then
1903                         __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1904                         return 1
1905                 fi
1906                 search=""
1907                 if [ $2 != "NOME" ]; then
1908                         search="?managed_element_id="$2
1909                 fi
1910                 if [ $3 != "NORIC" ]; then
1911                         if [ -z $search ]; then
1912                                 search="?ric_id="$3
1913                         else
1914                                 search=$search"&ric_id="$3
1915                         fi
1916                 fi
1917                 query="/v2/rics/ric"$search
1918
1919                 res="$(__do_curl_to_api PA GET $query)"
1920                 status=${res:${#res}-3}
1921
1922                 if [ $status -ne $1 ]; then
1923                         __log_test_fail_status_code $1 $status
1924                         return 1
1925                 fi
1926
1927                 if [ $# -gt 3 ]; then
1928                         body=${res:0:${#res}-3}
1929                         res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1930                         if [ $res -ne 0 ]; then
1931                                 __log_test_fail_general "Could not create target ric info json"
1932                                 return 1
1933                         fi
1934
1935                         targetJson=$(<./tmp/.tmp_rics.json)
1936                         targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1937                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
1938                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1939                         if [ $res -ne 0 ]; then
1940                                 __log_test_fail_body
1941                                 return 1
1942                         fi
1943                 fi
1944         else
1945                 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1946                         __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1947                         return 1
1948                 fi
1949
1950                 query="/ric?managedElementId="$2
1951
1952                 res="$(__do_curl_to_api PA GET $query)"
1953                 status=${res:${#res}-3}
1954
1955                 if [ $status -ne $1 ]; then
1956                         __log_test_fail_status_code $1 $status
1957                         return 1
1958                 fi
1959
1960                 if [ $# -eq 3 ]; then
1961                         body=${res:0:${#res}-3}
1962                         if [ "$body" != "$3" ]; then
1963                                 __log_test_fail_body
1964                                 return 1
1965                         fi
1966                 fi
1967         fi
1968
1969         __collect_endpoint_stats "PMS" 11 "GET" $PMS_API_PREFIX"/v2/rics/ric" $status
1970         __log_test_pass
1971         return 0
1972 }
1973
1974 # API test function: GET /rics and V2 GET /v2/rics
1975 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1976 # 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_........."
1977 # format of ric-info:  <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1978 # (Function for test scripts)
1979 api_get_rics() {
1980         __log_test_start $@
1981
1982     if [ $# -lt 2 ]; then
1983                 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1984                 return 1
1985         fi
1986
1987         if [ "$PMS_VERSION" == "V2" ]; then
1988                 query="/v2/rics"
1989                 if [ $2 != "NOTYPE" ]; then
1990                         query="/v2/rics?policytype_id="$2
1991                 fi
1992         else
1993                 query="/rics"
1994                 if [ $2 != "NOTYPE" ]; then
1995                         query="/rics?policyType="$2
1996                 fi
1997         fi
1998
1999     res="$(__do_curl_to_api PA GET $query)"
2000     status=${res:${#res}-3}
2001
2002         if [ $status -ne $1 ]; then
2003                 __log_test_fail_status_code $1 $status
2004                 return 1
2005         fi
2006
2007         if [ $# -gt 2 ]; then
2008                 body=${res:0:${#res}-3}
2009                 if [ "$PMS_VERSION" == "V2" ]; then
2010                         res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
2011                 else
2012                         res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
2013                 fi
2014                 if [ $res -ne 0 ]; then
2015                         __log_test_fail_general "Could not create target ric info json"
2016                         return 1
2017                 fi
2018
2019                 targetJson=$(<./tmp/.tmp_rics.json)
2020                 if [ "$PMS_VERSION" == "V2" ]; then
2021                         targetJson="{\"rics\": $targetJson }"
2022                 fi
2023         echo "TARGET JSON: $targetJson" >> $HTTPLOG
2024                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2025                 if [ $res -ne 0 ]; then
2026                         __log_test_fail_body
2027                         return 1
2028                 fi
2029         fi
2030
2031         __collect_endpoint_stats "PMS" 12 "GET" $PMS_API_PREFIX"/v2/rics" $status
2032         __log_test_pass
2033         return 0
2034 }
2035
2036 ##################################################################
2037 #### API Test case functions Service registry and supervision ####
2038 ##################################################################
2039
2040 # API test function: PUT /service and V2 PUT /service
2041 # args: <response-code>  <service-name> <keepalive-timeout> <callbackurl>
2042 # (Function for test scripts)
2043 api_put_service() {
2044         __log_test_start $@
2045     if [ $# -ne 4 ]; then
2046         __print_err "<response-code>  <service-name> <keepalive-timeout> <callbackurl>" $@
2047         return 1
2048     fi
2049
2050         if [ "$PMS_VERSION" == "V2" ]; then
2051                 query="/v2/services"
2052                 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2053         else
2054                 query="/service"
2055                 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2056         fi
2057     file="./tmp/.tmp.json"
2058         echo "$json" > $file
2059
2060     res="$(__do_curl_to_api PA PUT $query $file)"
2061     status=${res:${#res}-3}
2062
2063         if [ $status -ne $1 ]; then
2064                 __log_test_fail_status_code $1 $status
2065                 return 1
2066         fi
2067
2068         __collect_endpoint_stats "PMS" 13 "PUT" $PMS_API_PREFIX"/v2/service" $status
2069         __log_test_pass
2070         return 0
2071 }
2072
2073 # API test function: GET /services and V2 GET /v2/services
2074 #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>]* )]
2075 # (Function for test scripts)
2076 api_get_services() {
2077         __log_test_start $@
2078         #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2079         paramError=1
2080         if [ $# -eq 1 ]; then
2081                 paramError=0
2082         elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2083                 paramError=0
2084         elif [ $# -eq 5 ]; then
2085                 paramError=0
2086         elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2087                 argLen=$(($#-2))
2088                 if [ $(($argLen%3)) -eq 0 ]; then
2089                         paramError=0
2090                 fi
2091         fi
2092
2093     if [ $paramError -ne 0 ]; then
2094                 __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>]* )]" $@
2095                 return 1
2096         fi
2097
2098         if [ "$PMS_VERSION" == "V2" ]; then
2099                 query="/v2/services"
2100
2101                 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2102                         query="/v2/services?service_id="$2
2103                 fi
2104         else
2105                 query="/services"
2106
2107                 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2108                         query="/services?name="$2
2109                 fi
2110         fi
2111     res="$(__do_curl_to_api PA GET $query)"
2112     status=${res:${#res}-3}
2113
2114         if [ $status -ne $1 ]; then
2115                 __log_test_fail_status_code $1 $status
2116                 return 1
2117         fi
2118
2119         if [ $# -gt 2 ]; then
2120                 variableArgCount=$(($#-2))
2121                 body=${res:0:${#res}-3}
2122         targetJson="["
2123                 shift; shift;
2124                 cntr=0
2125                 while [ $cntr -lt $variableArgCount ]; do
2126                         servicename=$1; shift;
2127                         timeout=$1; shift;
2128                         callback=$1; shift;
2129                         if [ $cntr -gt 0 ]; then
2130                                 targetJson=$targetJson","
2131                         fi
2132                         # timeSinceLastActivitySeconds value cannot be checked since value varies
2133                         if [ "$PMS_VERSION" == "V2" ]; then
2134                                 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2135                         else
2136                                 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2137                         fi
2138                         let cntr=cntr+3
2139                 done
2140                 targetJson=$targetJson"]"
2141                 if [ "$PMS_VERSION" == "V2" ]; then
2142                         targetJson="{\"service_list\": $targetJson }"
2143                 fi
2144                 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2145                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2146                 if [ $res -ne 0 ]; then
2147                         __log_test_fail_body
2148                         return 1
2149                 fi
2150         fi
2151
2152         __collect_endpoint_stats "PMS" 14 "GET" $PMS_API_PREFIX"/v2/services" $status
2153         __log_test_pass
2154         return 0
2155 }
2156
2157 # API test function: GET /services V2 GET /v2/services -  (only checking service names)
2158 # args: <response-code> [<service-name>]*"
2159 # (Function for test scripts)
2160 api_get_service_ids() {
2161         __log_test_start $@
2162
2163     if [ $# -lt 1 ]; then
2164                 __print_err "<response-code> [<service-name>]*" $@
2165                 return 1
2166         fi
2167
2168         if [ "$PMS_VERSION" == "V2" ]; then
2169             query="/v2/services"
2170         else
2171         query="/services"
2172         fi
2173     res="$(__do_curl_to_api PA GET $query)"
2174     status=${res:${#res}-3}
2175
2176         if [ $status -ne $1 ]; then
2177                 __log_test_fail_status_code $1 $status
2178                 return 1
2179         fi
2180
2181         body=${res:0:${#res}-3}
2182         targetJson="["
2183         for rapp in ${@:2} ; do
2184                 if [ "$targetJson" != "[" ]; then
2185                         targetJson=$targetJson","
2186                 fi
2187                 if [ "$PMS_VERSION" == "V2" ]; then
2188                         targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2189                 else
2190                         targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2191                 fi
2192         done
2193
2194         targetJson=$targetJson"]"
2195         if [ "$PMS_VERSION" == "V2" ]; then
2196                 targetJson="{\"service_list\": $targetJson }"
2197         fi
2198         echo "TARGET JSON: $targetJson" >> $HTTPLOG
2199         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2200
2201         if [ $res -ne 0 ]; then
2202                 __log_test_fail_body
2203                 return 1
2204         fi
2205
2206         __collect_endpoint_stats "PMS" 14 "GET" $PMS_API_PREFIX"/v2/services" $status
2207         __log_test_pass
2208         return 0
2209 }
2210
2211 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2212 # args: <response-code> <service-name>
2213 # (Function for test scripts)
2214 api_delete_services() {
2215         __log_test_start $@
2216
2217     if [ $# -ne 2 ]; then
2218                 __print_err "<response-code> <service-name>" $@
2219                 return 1
2220         fi
2221         if [ "$PMS_VERSION" == "V2" ]; then
2222                 query="/v2/services/"$2
2223         else
2224                 query="/services?name="$2
2225         fi
2226     res="$(__do_curl_to_api PA DELETE $query)"
2227     status=${res:${#res}-3}
2228
2229         if [ $status -ne $1 ]; then
2230                 __log_test_fail_status_code $1 $status
2231                 return 1
2232         fi
2233
2234         __collect_endpoint_stats "PMS" 15 "DELETE" $PMS_API_PREFIX"/v2/services/{serviceId}" $status
2235         __log_test_pass
2236         return 0
2237 }
2238
2239 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2240 # args: <response-code> <service-name>
2241 # (Function for test scripts)
2242 api_put_services_keepalive() {
2243         __log_test_start $@
2244
2245     if [ $# -ne 2 ]; then
2246                 __print_err "<response-code> <service-name>" $@
2247                 return 1
2248         fi
2249         if [ "$PMS_VERSION" == "V2" ]; then
2250                 query="/v2/services/$2/keepalive"
2251         else
2252         query="/services/keepalive?name="$2
2253         fi
2254
2255     res="$(__do_curl_to_api PA PUT $query)"
2256     status=${res:${#res}-3}
2257
2258         if [ $status -ne $1 ]; then
2259                 __log_test_fail_status_code $1 $status
2260                 return 1
2261         fi
2262
2263         __collect_endpoint_stats "PMS" 16 "PUT" $PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
2264         __log_test_pass
2265         return 0
2266 }
2267
2268 ##################################################################
2269 #### API Test case functions Configuration                    ####
2270 ##################################################################
2271
2272 # API Test function: PUT /v2/configuration
2273 # args: <response-code> <config-file>
2274 # (Function for test scripts)
2275 api_put_configuration() {
2276         __log_test_start $@
2277
2278         if [ "$PMS_VERSION" != "V2" ]; then
2279                 __log_test_fail_not_supported
2280                 return 1
2281         fi
2282
2283     if [ $# -ne 2 ]; then
2284         __print_err "<response-code> <config-file>" $@
2285         return 1
2286     fi
2287         if [ ! -f $2 ]; then
2288                 __log_test_fail_general "Config file "$2", does not exist"
2289                 return 1
2290         fi
2291         inputJson=$(< $2)
2292         if [ $RUNMODE == "DOCKER" ]; then  #In kube the file already has a header
2293                 inputJson="{\"config\":"$inputJson"}"
2294         fi
2295         file="./tmp/.config.json"
2296         echo $inputJson > $file
2297         query="/v2/configuration"
2298         res="$(__do_curl_to_api PA PUT $query $file)"
2299         status=${res:${#res}-3}
2300
2301         if [ $status -ne $1 ]; then
2302                 __log_test_fail_status_code $1 $status
2303                 return 1
2304         fi
2305
2306         __collect_endpoint_stats "PMS" 17 "PUT" $PMS_API_PREFIX"/v2/configuration" $status
2307         __log_test_pass
2308         return 0
2309 }
2310
2311 # API Test function: GET /v2/configuration
2312 # args: <response-code> [<config-file>]
2313 # (Function for test scripts)
2314 api_get_configuration() {
2315         __log_test_start $@
2316
2317         if [ "$PMS_VERSION" != "V2" ]; then
2318                 __log_test_fail_not_supported
2319                 return 1
2320         fi
2321
2322     if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2323         __print_err "<response-code> [<config-file>]" $@
2324         return 1
2325     fi
2326         if [ ! -f $2 ]; then
2327                 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2328                 return 1
2329         fi
2330
2331         query="/v2/configuration"
2332         res="$(__do_curl_to_api PA GET $query)"
2333         status=${res:${#res}-3}
2334
2335         if [ $status -ne $1 ]; then
2336                 __log_test_fail_status_code $1 $status
2337                 return 1
2338         fi
2339
2340         if [ $# -eq 2 ]; then
2341
2342                 body=${res:0:${#res}-3}
2343
2344                 targetJson=$(< $2)
2345                 targetJson="{\"config\":"$targetJson"}"
2346                 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2347                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2348
2349                 if [ $res -ne 0 ]; then
2350                         __log_test_fail_body
2351                         return 1
2352                 fi
2353         fi
2354
2355         __collect_endpoint_stats "PMS" 18 "GET" $PMS_API_PREFIX"/v2/configuration" $status
2356         __log_test_pass
2357         return 0
2358 }
2359
2360 ##########################################
2361 ####     Reset types and instances    ####
2362 ##########################################
2363
2364 # Admin reset to remove all policies and services
2365 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2366 # NOTE - only works in kubernetes and the pod should not be running
2367 # args: -
2368 # (Function for test scripts)
2369
2370 pms_kube_pvc_reset() {
2371         __log_test_start $@
2372
2373         pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE  --no-headers -o custom-columns=":metadata.name" | grep policy)
2374         if [ -z "$pvc_name" ]; then
2375                 pvc_name=policymanagementservice-vardata-pvc
2376         fi
2377         echo " Trying to reset pvc: "$pvc_name
2378         __kube_clean_pvc $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $POLICY_AGENT_CONTAINER_MNT_DIR
2379
2380         __log_test_pass
2381         return 0
2382 }