3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020 Nordix Foundation. All rights reserved.
5 # ========================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
20 # This is a script that contains management and test functions for Policy Agent
22 ################ Test engine functions ################
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
28 __check_and_create_image_var PA "POLICY_AGENT_IMAGE" "POLICY_AGENT_IMAGE_BASE" "POLICY_AGENT_IMAGE_TAG" $1 "$POLICY_AGENT_DISPLAY_NAME"
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'
37 __check_and_pull_image $1 "$POLICY_AGENT_DISPLAY_NAME" $POLICY_AGENT_APP_NAME POLICY_AGENT_IMAGE
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
44 echo -e $RED" Image for app PA shall never be built"$ERED
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>
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
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
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
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
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 logs -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_policy-agent.log 2>&1
83 docker logs $POLICY_AGENT_APP_NAME > $1$2_policy-agent.log 2>&1
87 # Initial setup of protocol, host and ports
88 # This function is called for apps managed by the test script.
90 __PA_initial_setup() {
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.
98 __PA_statisics_setup() {
99 if [ $RUNMODE == "KUBE" ]; then
100 echo "PA $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
102 echo "PA $POLICY_AGENT_APP_NAME"
107 #######################################################
109 ###########################
110 ### Policy Agents functions
111 ###########################
113 # Set http as the protocol to use for all communication to the Policy Agent
115 # (Function for test scripts)
116 use_agent_rest_http() {
117 __agent_set_protocoll "http" $POLICY_AGENT_INTERNAL_PORT $POLICY_AGENT_EXTERNAL_PORT
120 # Set https as the protocol to use for all communication to the Policy Agent
122 # (Function for test scripts)
123 use_agent_rest_https() {
124 __agent_set_protocoll "https" $POLICY_AGENT_INTERNAL_SECURE_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT
127 # All calls to the agent will be directed to the agent dmaap interface over http from now on
129 # (Function for test scripts)
130 use_agent_dmaap_http() {
131 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
132 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
133 PA_ADAPTER_TYPE="MR-HTTP"
137 # All calls to the agent will be directed to the agent dmaap interface over https from now on
139 # (Function for test scripts)
140 use_agent_dmaap_https() {
141 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
142 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
143 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
144 PA_ADAPTER_TYPE="MR-HTTPS"
148 # Setup paths to svc/container for internal and external access
149 # args: <protocol> <internal-port> <external-port>
150 __agent_set_protocoll() {
151 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME protocol setting"$EBOLD
152 echo -e " Using $BOLD $1 $EBOLD towards $POLICY_AGENT_DISPLAY_NAME"
154 ## Access to Dmaap adapter
156 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME":"$2 # docker access, container->container and script->container via proxy
157 if [ $RUNMODE == "KUBE" ]; then
158 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
161 # PA_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
162 PA_ADAPTER_TYPE="REST"
163 PA_ADAPTER=$PA_SERVICE_PATH
168 # Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
171 #Save first worker node the pod is started on
174 # Export env vars for config files, docker compose and kube resources
175 # args: PROXY|NOPROXY
176 __export_agent_vars() {
178 export POLICY_AGENT_APP_NAME
179 export POLICY_AGENT_APP_NAME_ALIAS
180 export POLICY_AGENT_DISPLAY_NAME
182 export KUBE_NONRTRIC_NAMESPACE
183 export POLICY_AGENT_IMAGE
184 export POLICY_AGENT_INTERNAL_PORT
185 export POLICY_AGENT_INTERNAL_SECURE_PORT
186 export POLICY_AGENT_EXTERNAL_PORT
187 export POLICY_AGENT_EXTERNAL_SECURE_PORT
188 export POLICY_AGENT_CONFIG_MOUNT_PATH
189 export POLICY_AGENT_DATA_MOUNT_PATH
190 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
191 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
192 export POLICY_AGENT_PKG_NAME
194 export CONSUL_INTERNAL_PORT
195 export CONFIG_BINDING_SERVICE
196 export POLICY_AGENT_CONFIG_KEY
197 export DOCKER_SIM_NWNAME
198 export POLICY_AGENT_HOST_MNT_DIR
199 export POLICY_AGENT_CONFIG_FILE
201 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
202 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
203 ##Create a unique path for the pv each time to prevent a previous volume to be reused
204 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
205 export POLICY_AGENT_CONTAINER_MNT_DIR
207 if [ $1 == "PROXY" ]; then
208 export AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
209 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
210 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
211 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
213 echo " Configured with http proxy"
216 export AGENT_HTTP_PROXY_CONFIG_PORT=0
217 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
218 echo " Configured without http proxy"
223 # Start the policy agent
224 # args: (docker) PROXY|NOPROXY <config-file>
225 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
226 # (Function for test scripts)
227 start_policy_agent() {
228 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
230 if [ $RUNMODE == "KUBE" ]; then
232 # Check if app shall be fully managed by the test script
233 __check_included_image "PA"
236 # Check if app shall only be used by the testscipt
237 __check_prestarted_image "PA"
240 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
241 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
242 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
245 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
246 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
247 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
251 if [ $retcode_p -eq 0 ]; then
252 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
253 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
254 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
255 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
258 if [ $retcode_i -eq 0 ]; then
260 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
262 #Check if nonrtric namespace exists, if not create it
263 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
265 __export_agent_vars $1
267 # Create config map for config
268 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
270 output_yaml=$PWD/tmp/pa_cfc.yaml
271 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
273 # Create config map for data
274 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
275 if [ $# -lt 3 ]; then
276 #create empty dummy file
277 echo "{}" > $data_json
281 output_yaml=$PWD/tmp/pa_cfd.yaml
282 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
285 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
286 output_yaml=$PWD/tmp/pa_pv.yaml
287 __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
290 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
291 output_yaml=$PWD/tmp/pa_pvc.yaml
292 __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
295 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
296 output_yaml=$PWD/tmp/pa_svc.yaml
297 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
300 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
301 output_yaml=$PWD/tmp/pa_app.yaml
302 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
306 # 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
307 if [ $retcode_i -eq 0 ]; then
308 __PA_WORKER_NODE=$(kubectl get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
309 if [ -z "$__PA_WORKER_NODE" ]; then
310 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
313 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
316 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
319 __check_included_image 'PA'
320 if [ $? -eq 1 ]; then
321 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
322 echo -e $RED"The Policy Agent will not be started"$ERED
329 cd $POLICY_AGENT_HOST_MNT_DIR
332 if [ "$(ls -A $DIR)" ]; then
333 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
334 rm -rf db/* &> /dev/null
335 if [ $? -ne 0 ]; then
336 echo -e $RED" Cannot remove database files in: $PWD"$ERED
341 echo " No files in mounted dir or dir does not exists"
345 __export_agent_vars $1
347 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
349 envsubst < $2 > $dest_file
351 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
353 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
359 # Stop the policy agent
362 # (Function for test scripts)
363 stop_policy_agent() {
364 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
366 if [ $RUNMODE == "KUBE" ]; then
368 __check_prestarted_image "PA"
369 if [ $? -eq 0 ]; then
370 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
371 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
372 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
375 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
376 echo " Deleting the replica set - a new will be started when the app is started"
377 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
378 if [ $? -ne 0 ]; then
379 echo -e $RED" Could not delete replica set "$RED
384 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
385 if [ $? -ne 0 ]; then
386 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
392 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
397 # Start a previously stopped policy agent
399 # (Function for test scripts)
400 start_stopped_policy_agent() {
401 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
403 if [ $RUNMODE == "KUBE" ]; then
405 __check_prestarted_image "PA"
406 if [ $? -eq 0 ]; then
407 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
408 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
409 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
410 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
414 # Tie the PMS to the same worker node it was initially started on
415 # 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
416 if [ -z "$__PA_WORKER_NODE" ]; then
417 echo -e $RED" No initial worker node found for pod "$RED
421 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
422 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
423 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
424 if [ $? -ne 0 ]; then
425 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
427 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
430 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
431 if [ $? -ne 0 ]; then
432 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
438 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
439 if [ $? -ne 0 ]; then
447 # Function to perpare the consul configuration according to the current simulator configuration
448 # args: SDNC|NOSDNC <output-file>
449 # (Function for test scripts)
450 prepare_consul_config() {
451 echo -e $BOLD"Prepare Consul config"$EBOLD
453 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
457 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
461 if [ $1 == "SDNC" ]; then
462 echo -e " Config$BOLD including SDNC$EBOLD configuration"
463 elif [ $1 == "NOSDNC" ]; then
464 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
467 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
472 if [ $1 == "SDNC" ]; then
473 config_json=$config_json"\n \"controller\": ["
474 config_json=$config_json"\n {"
475 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
476 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
477 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
478 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
479 config_json=$config_json"\n }"
480 config_json=$config_json"\n ],"
483 config_json=$config_json"\n \"streams_publishes\": {"
484 config_json=$config_json"\n \"dmaap_publisher\": {"
485 config_json=$config_json"\n \"type\": \"message-router\","
486 config_json=$config_json"\n \"dmaap_info\": {"
487 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
488 config_json=$config_json"\n }"
489 config_json=$config_json"\n }"
490 config_json=$config_json"\n },"
491 config_json=$config_json"\n \"streams_subscribes\": {"
492 config_json=$config_json"\n \"dmaap_subscriber\": {"
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_READ_URL\""
496 config_json=$config_json"\n }"
497 config_json=$config_json"\n }"
498 config_json=$config_json"\n },"
500 config_json=$config_json"\n \"ric\": ["
502 if [ $RUNMODE == "KUBE" ]; then
503 result=$(kubectl get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
506 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
507 for im in $result; do
508 if [[ $im != *"-0" ]]; then
509 ric_subdomain=$(kubectl get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
510 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
511 let ric_cntr=ric_cntr+1
515 if [ $ric_cntr -eq 0 ]; then
516 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
519 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
520 if [ $? -ne 0 ] || [ -z "$rics" ]; then
521 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
528 if [ $cntr -gt 0 ]; then
529 config_json=$config_json"\n ,"
531 config_json=$config_json"\n {"
532 if [ $RUNMODE == "KUBE" ]; then
533 ric_id=${ric%.*.*} #extract pod id from full hosthame
534 ric_id=$(echo "$ric_id" | tr '-' '_')
536 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
539 ric_id=$(echo "$ric" | tr '-' '_') #ric id still needs underscore as it is different from the container name
542 echo " Found a1 sim: "$ric_id
543 config_json=$config_json"\n \"name\": \"$ric_id\","
544 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
545 if [ $1 == "SDNC" ]; then
546 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
548 config_json=$config_json"\n \"managedElementIds\": ["
549 config_json=$config_json"\n \"me1_$ric_id\","
550 config_json=$config_json"\n \"me2_$ric_id\""
551 config_json=$config_json"\n ]"
552 config_json=$config_json"\n }"
556 config_json=$config_json"\n ]"
557 config_json=$config_json"\n}"
559 if [ $RUNMODE == "KUBE" ]; then
560 config_json="{\"config\":"$config_json"}"
563 printf "$config_json">$2
568 # Load the the appl config for the agent into a config map
569 agent_load_config() {
570 echo -e $BOLD"Agent - load config from "$EBOLD$1
571 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
573 output_yaml=$PWD/tmp/pa_cfd.yaml
574 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
579 # Turn on debug level tracing in the agent
581 # (Function for test scripts)
583 echo -e $BOLD"Setting agent debug logging"$EBOLD
584 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
585 result=$(__do_curl "$curlString")
586 if [ $? -ne 0 ]; then
587 __print_err "could not set debug mode" $@
595 # Turn on trace level tracing in the agent
597 # (Function for test scripts)
599 echo -e $BOLD"Setting agent trace logging"$EBOLD
600 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
601 result=$(__do_curl "$curlString")
602 if [ $? -ne 0 ]; then
603 __print_err "could not set trace mode" $@
611 # Perform curl retries when making direct call to the agent for the specified http response codes
612 # Speace separated list of http response codes
613 # args: [<response-code>]*
614 use_agent_retries() {
615 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
621 # Check the agent logs for WARNINGs and ERRORs
623 # (Function for test scripts)
624 check_policy_agent_logs() {
625 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
628 #########################################################
629 #### Test case functions A1 Policy management service
630 #########################################################
632 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
633 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
634 # args: json:<url> <target-value> [<timeout-in-seconds]
635 # (Function for test scripts)
637 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
638 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
639 if [[ $1 == "json:"* ]]; then
640 if [ "$PMS_VERSION" == "V2" ]; then
641 __var_test "Policy Agent" $PA_SERVICE_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
643 __var_test "Policy Agent" $PA_SERVICE_PATH"/" $1 "=" $2 $3
648 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
652 # API Test function: GET /policies and V2 GET /v2/policy-instances
653 # 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>]*]
654 # 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>]*]
655 # (Function for test scripts)
659 if [ "$PMS_VERSION" == "V2" ]; then
661 variableParams=$(($#-4))
662 if [ $# -lt 4 ]; then
664 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
666 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
670 if [ $paramError -ne 0 ]; then
671 __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>]*]" $@
676 variableParams=$(($#-4))
677 if [ $# -lt 4 ]; then
679 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
681 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
685 if [ $paramError -ne 0 ]; then
686 __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>]*]" $@
692 if [ "$PMS_VERSION" == "V2" ]; then
693 if [ $2 != "NORIC" ]; then
694 queryparams="?ric_id="$2
696 if [ $3 != "NOSERVICE" ]; then
697 if [ -z $queryparams ]; then
698 queryparams="?service_id="$3
700 queryparams=$queryparams"&service_id="$3
703 if [ $4 != "NOTYPE" ]; then
704 if [ -z $queryparams ]; then
705 queryparams="?policytype_id="$4
707 queryparams=$queryparams"&policytype_id="$4
711 query="/v2/policy-instances"$queryparams
712 res="$(__do_curl_to_api PA GET $query)"
713 status=${res:${#res}-3}
715 if [ $status -ne $1 ]; then
716 __log_test_fail_status_code $1 $status
720 if [ $# -gt 4 ]; then
721 body=${res:0:${#res}-3}
722 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
728 for ((i=0; i<$(($#-4)); i=i+7)); do
730 if [ "$targetJson" != "[" ]; then
731 targetJson=$targetJson","
733 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
734 if [ "${arr[$i+3]}" == "EMPTY" ]; then
735 targetJson=$targetJson"\"\","
737 targetJson=$targetJson"\"${arr[$i+3]}\","
739 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
741 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
743 targetJson=$targetJson"\"policy_data\":"$json"}"
747 targetJson=$targetJson"]"
748 targetJson="{\"policies\": $targetJson}"
749 echo "TARGET JSON: $targetJson" >> $HTTPLOG
750 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
752 if [ $res -ne 0 ]; then
758 if [ $2 != "NORIC" ]; then
759 queryparams="?ric="$2
761 if [ $3 != "NOSERVICE" ]; then
762 if [ -z $queryparams ]; then
763 queryparams="?service="$3
765 queryparams=$queryparams"&service="$3
768 if [ $4 != "NOTYPE" ]; then
769 if [ -z $queryparams ]; then
770 queryparams="?type="$4
772 queryparams=$queryparams"&type="$4
776 query="/policies"$queryparams
777 res="$(__do_curl_to_api PA GET $query)"
778 status=${res:${#res}-3}
780 if [ $status -ne $1 ]; then
781 __log_test_fail_status_code $1 $status
785 if [ $# -gt 4 ]; then
786 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
789 body=${res:0:${#res}-3}
793 for ((i=0; i<$(($#-4)); i=i+5)); do
795 if [ "$targetJson" != "[" ]; then
796 targetJson=$targetJson","
798 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
799 if [ "${arr[$i+3]}" == "EMPTY" ]; then
800 targetJson=$targetJson"\"\","
802 targetJson=$targetJson"\"${arr[$i+3]}\","
805 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
807 targetJson=$targetJson"\"json\":"$json"}"
811 targetJson=$targetJson"]"
812 echo "TARGET JSON: $targetJson" >> $HTTPLOG
813 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
815 if [ $res -ne 0 ]; then
828 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
829 # args: <response-code> <policy-id> [<template-file>]
830 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
832 # (Function for test scripts)
837 if [ "$PMS_VERSION" == "V2" ]; then
838 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
839 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
842 query="/v2/policies/$UUID$2"
844 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
845 __print_err "<response-code> <policy-id> [<template-file>] " $@
848 query="/policy?id=$UUID$2"
850 res="$(__do_curl_to_api PA GET $query)"
851 status=${res:${#res}-3}
853 if [ $status -ne $1 ]; then
854 __log_test_fail_status_code $1 $status
858 if [ "$PMS_VERSION" == "V2" ]; then
859 if [ $# -eq 8 ]; then
861 #Create a policy json to compare with
862 body=${res:0:${#res}-3}
864 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
865 if [ $7 != "NOTRANSIENT" ]; then
866 targetJson=$targetJson", \"transient\":$7"
868 if [ $6 != "NOTYPE" ]; then
869 targetJson=$targetJson", \"policytype_id\":\"$6\""
871 targetJson=$targetJson", \"policytype_id\":\"\""
873 if [ $8 != "NOURL" ]; then
874 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
877 data=$(sed 's/XXX/'${2}'/g' $3)
878 targetJson=$targetJson", \"policy_data\":$data"
879 targetJson="{$targetJson}"
881 echo "TARGET JSON: $targetJson" >> $HTTPLOG
882 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
883 if [ $res -ne 0 ]; then
889 if [ $# -eq 3 ]; then
890 #Create a policy json to compare with
891 body=${res:0:${#res}-3}
893 sed 's/XXX/'${2}'/g' $3 > $file
894 targetJson=$(< $file)
895 echo "TARGET JSON: $targetJson" >> $HTTPLOG
896 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
897 if [ $res -ne 0 ]; then
907 # API Test function: PUT /policy and V2 PUT /policies
908 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
909 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
910 # (Function for test scripts)
914 if [ "$PMS_VERSION" == "V2" ]; then
915 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
916 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
920 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
921 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
934 if [ "$PMS_VERSION" == "V2" ]; then
937 if [ $# -eq 9 ]; then
942 if [ $# -eq 8 ]; then
947 while [ $count -lt $max ]; do
948 if [ "$PMS_VERSION" == "V2" ]; then
952 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
953 if [ $trans != "NOTRANSIENT" ]; then
954 inputJson=$inputJson", \"transient\":$trans"
956 if [ $pt != "NOTYPE" ]; then
957 inputJson=$inputJson", \"policytype_id\":\"$pt\""
959 inputJson=$inputJson", \"policytype_id\":\"\""
961 if [ $noti != "NOURL" ]; then
962 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
965 data=$(sed 's/XXX/'${pid}'/g' $temp)
966 inputJson=$inputJson", \"policy_data\":$data"
967 inputJson="{$inputJson}"
968 echo $inputJson > $file
970 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
972 if [ $pt != "NOTYPE" ]; then
973 query=$query"&type=$pt"
976 if [ $trans != NOTRANSIENT ]; then
977 query=$query"&transient=$trans"
981 sed 's/XXX/'${pid}'/g' $temp > $file
983 res="$(__do_curl_to_api PA PUT $query $file)"
984 status=${res:${#res}-3}
985 echo -ne " Executing "$count"("$max")${SAMELINE}"
986 if [ $status -ne $1 ]; then
987 echo " Executed "$count"?("$max")"
988 __log_test_fail_status_code $1 $status
994 echo -ne " Executed "$count"("$max")${SAMELINE}"
1002 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
1003 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1004 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
1005 # (Function for test scripts)
1007 api_put_policy_batch() {
1010 if [ "$PMS_VERSION" == "V2" ]; then
1011 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1012 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1016 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1017 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1029 if [ "$PMS_VERSION" == "V2" ]; then
1032 if [ $# -eq 9 ]; then
1037 if [ $# -eq 8 ]; then
1043 while [ $count -lt $max ]; do
1044 if [ "$PMS_VERSION" == "V2" ]; then
1045 query="/v2/policies"
1047 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1048 if [ $trans != "NOTRANSIENT" ]; then
1049 inputJson=$inputJson", \"transient\":$trans"
1051 if [ $pt != "NOTYPE" ]; then
1052 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1054 inputJson=$inputJson", \"policytype_id\":\"\""
1056 if [ $noti != "NOURL" ]; then
1057 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1059 file="./tmp/.p.json"
1060 data=$(sed 's/XXX/'${pid}'/g' $temp)
1061 inputJson=$inputJson", \"policy_data\":$data"
1062 inputJson="{$inputJson}"
1063 echo $inputJson > $file
1065 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1067 if [ $pt != "NOTYPE" ]; then
1068 query=$query"&type=$pt"
1071 if [ $trans != NOTRANSIENT ]; then
1072 query=$query"&transient=$trans"
1074 file="./tmp/.p.json"
1075 sed 's/XXX/'${pid}'/g' $temp > $file
1077 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
1078 status=${res:${#res}-3}
1079 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1081 if [ $status -ne 200 ]; then
1082 echo " Requested(batch) "$count"?("$max")"
1083 __log_test_fail_status_code 200 $status
1086 cid=${res:0:${#res}-3}
1090 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1097 res="$(__do_curl_to_api PA RESPONSE $cid)"
1098 status=${res:${#res}-3}
1099 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
1101 if [ $status -ne $1 ]; then
1102 echo " Accepted(batch) "$count"?("$max")"
1103 __log_test_fail_status_code $1 $status
1108 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1117 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1118 # 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>
1119 # 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>
1120 # (Function for test scripts)
1121 api_put_policy_parallel() {
1124 if [ "$PMS_VERSION" == "V2" ]; then
1125 if [ $# -ne 11 ]; then
1126 __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>" $@
1130 if [ $# -ne 10 ]; then
1131 __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>" $@
1135 resp_code=$1; shift;
1141 transient=$1; shift;
1142 if [ "$PMS_VERSION" == "V2" ]; then
1151 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1152 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1153 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1154 echo " Info - will execute over agent REST"
1156 if [ "$PMS_VERSION" == "V2" ]; then
1157 if [ $serv == "NOSERVICE" ]; then
1160 query="$PMS_API_PREFIX/v2/policies"
1162 if [ $serv == "NOSERVICE" ]; then
1165 query="/policy?service=$serv"
1167 if [ $type != "NOTYPE" ]; then
1168 query=$query"&type=$type"
1171 if [ $transient != NOTRANSIENT ]; then
1172 query=$query"&transient=$transient"
1176 urlbase=${PA_ADAPTER}${query}
1179 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1180 httpproxy=$KUBE_PROXY_PATH
1183 for ((i=1; i<=$pids; i++))
1186 if [ -z "$uuid" ]; then
1189 echo "" > "./tmp/.pid${i}.res.txt"
1190 if [ "$PMS_VERSION" == "V2" ]; then
1191 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1193 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1196 done | xargs -n 1 -I{} -P $pids bash -c '{
1198 echo " Parallel process $arg started"
1199 tmp=$(< "./tmp/.pid${arg}.txt")
1200 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1203 for ((i=1; i<=$pids; i++))
1205 file="./tmp/.pid${i}.res.txt"
1207 if [ -z "$tmp" ]; then
1208 echo " Process $i : unknown result (result file empty"
1212 if [ $res == "0" ]; then
1213 echo " Process $i : OK - "${tmp:1}
1215 echo " Process $i : failed - "${tmp:1}
1220 if [ -z $msg ]; then
1221 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1225 __log_test_fail_general "One of more processes failed to execute"
1229 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1230 # args: <response-code> <policy-id> [count]
1231 # (Function for test scripts)
1232 api_delete_policy() {
1235 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1236 __print_err "<response-code> <policy-id> [count]" $@
1243 if [ $# -eq 3 ]; then
1249 while [ $count -lt $max ]; do
1250 if [ "$PMS_VERSION" == "V2" ]; then
1251 query="/v2/policies/"$UUID$pid
1253 query="/policy?id="$UUID$pid
1255 res="$(__do_curl_to_api PA DELETE $query)"
1256 status=${res:${#res}-3}
1257 echo -ne " Executing "$count"("$max")${SAMELINE}"
1259 if [ $status -ne $1 ]; then
1260 echo " Executed "$count"?("$max")"
1261 __log_test_fail_status_code $1 $status
1266 echo -ne " Executed "$count"("$max")${SAMELINE}"
1274 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1275 # args: <response-code> <policy-id> [count]
1276 # (Function for test scripts)
1277 api_delete_policy_batch() {
1280 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1281 __print_err "<response-code> <policy-id> [count]" $@
1288 if [ $# -eq 3 ]; then
1294 while [ $count -lt $max ]; do
1295 if [ "$PMS_VERSION" == "V2" ]; then
1296 query="/v2/policies/"$UUID$pid
1298 query="/policy?id="$UUID$pid
1300 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
1301 status=${res:${#res}-3}
1302 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1304 if [ $status -ne 200 ]; then
1305 echo " Requested(batch) "$count"?("$max")"
1306 __log_test_fail_status_code 200 $status
1309 cid=${res:0:${#res}-3}
1313 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1321 res="$(__do_curl_to_api PA RESPONSE $cid)"
1322 status=${res:${#res}-3}
1323 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1325 if [ $status -ne $1 ]; then
1326 echo " Deleted(batch) "$count"?("$max")"
1327 __log_test_fail_status_code $1 $status
1332 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1341 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1342 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1343 # (Function for test scripts)
1344 api_delete_policy_parallel() {
1347 if [ $# -ne 5 ]; then
1348 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1351 resp_code=$1; shift;
1357 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1358 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1359 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1360 echo " Info - will execute over agent REST"
1363 if [ "$PMS_VERSION" == "V2" ]; then
1364 query="$PMS_API_PREFIX/v2/policies/"
1369 urlbase=${PA_ADAPTER}${query}
1372 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1373 httpproxy=$KUBE_PROXY_PATH
1376 for ((i=1; i<=$pids; i++))
1379 if [ -z "$uuid" ]; then
1382 echo "" > "./tmp/.pid${i}.del.res.txt"
1383 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1385 done | xargs -n 1 -I{} -P $pids bash -c '{
1387 echo " Parallel process $arg started"
1388 tmp=$(< "./tmp/.pid${arg}.del.txt")
1389 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1392 for ((i=1; i<=$pids; i++))
1394 file="./tmp/.pid${i}.del.res.txt"
1396 if [ -z "$tmp" ]; then
1397 echo " Process $i : unknown result (result file empty"
1401 if [ $res == "0" ]; then
1402 echo " Process $i : OK - "${tmp:1}
1404 echo " Process $i : failed - "${tmp:1}
1409 if [ -z $msg ]; then
1410 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1414 __log_test_fail_general "One of more processes failed to execute"
1418 # API Test function: GET /policy_ids and V2 GET /v2/policies
1419 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1420 # (Function for test scripts)
1421 api_get_policy_ids() {
1424 if [ $# -lt 4 ]; then
1425 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1431 if [ "$PMS_VERSION" == "V2" ]; then
1432 if [ $2 != "NORIC" ]; then
1433 queryparams="?ric_id="$2
1436 if [ $3 != "NOSERVICE" ]; then
1437 if [ -z $queryparams ]; then
1438 queryparams="?service_id="$3
1440 queryparams=$queryparams"&service_id="$3
1443 if [ $4 != "NOTYPE" ]; then
1444 if [ -z $queryparams ]; then
1445 queryparams="?policytype_id="$4
1447 queryparams=$queryparams"&policytype_id="$4
1451 query="/v2/policies"$queryparams
1453 if [ $2 != "NORIC" ]; then
1454 queryparams="?ric="$2
1457 if [ $3 != "NOSERVICE" ]; then
1458 if [ -z $queryparams ]; then
1459 queryparams="?service="$3
1461 queryparams=$queryparams"&service="$3
1464 if [ $4 != "NOTYPE" ]; then
1465 if [ -z $queryparams ]; then
1466 queryparams="?type="$4
1468 queryparams=$queryparams"&type="$4
1472 query="/policy_ids"$queryparams
1475 res="$(__do_curl_to_api PA GET $query)"
1476 status=${res:${#res}-3}
1478 if [ $status -ne $1 ]; then
1479 __log_test_fail_status_code $1 $status
1483 if [ $# -gt 4 ]; then
1484 body=${res:0:${#res}-3}
1487 for pid in ${@:5} ; do
1488 if [ "$targetJson" != "[" ]; then
1489 targetJson=$targetJson","
1491 if [ $pid != "NOID" ]; then
1492 targetJson=$targetJson"\"$UUID$pid\""
1496 targetJson=$targetJson"]"
1497 if [ "$PMS_VERSION" == "V2" ]; then
1498 targetJson="{\"policy_ids\": $targetJson}"
1500 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1501 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1503 if [ $res -ne 0 ]; then
1504 __log_test_fail_body
1513 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1514 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1515 # (Function for test scripts)
1516 api_get_policy_type() {
1519 if [ "$PMS_VERSION" != "V2" ]; then
1520 __log_test_fail_not_supported
1524 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1525 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1528 query="/v2/policy-types/$2"
1530 res="$(__do_curl_to_api PA GET $query)"
1531 status=${res:${#res}-3}
1533 if [ $status -ne $1 ]; then
1534 __log_test_fail_status_code $1 $status
1538 if [ $# -eq 3 ]; then
1540 body=${res:0:${#res}-3}
1543 targetJson="{\"policy_schema\":$targetJson}"
1544 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1545 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1547 if [ $res -ne 0 ]; then
1548 __log_test_fail_body
1557 # API Test function: GET /policy_schema
1558 # args: <response-code> <policy-type-id> [<schema-file>]
1559 # (Function for test scripts)
1560 api_get_policy_schema() {
1563 if [ "$PMS_VERSION" == "V2" ]; then
1564 __log_test_fail_not_supported
1568 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1569 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1572 query="/policy_schema?id=$2"
1573 res="$(__do_curl_to_api PA GET $query)"
1574 status=${res:${#res}-3}
1576 if [ $status -ne $1 ]; then
1577 __log_test_fail_status_code $1 $status
1581 if [ $# -eq 3 ]; then
1583 body=${res:0:${#res}-3}
1587 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1588 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1590 if [ $res -ne 0 ]; then
1591 __log_test_fail_body
1600 # API Test function: GET /policy_schemas
1601 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1602 # args(V2): <response-code>
1603 # (Function for test scripts)
1604 api_get_policy_schemas() {
1607 if [ "$PMS_VERSION" == "V2" ]; then
1608 if [ $# -ne 1 ]; then
1609 __print_err "<response-code>" $@
1613 if [ $# -lt 2 ]; then
1614 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1618 if [ "$PMS_VERSION" == "V2" ]; then
1619 query="/v2/policy-schemas"
1621 query="/policy_schemas"
1622 if [ $2 != "NORIC" ]; then
1623 query=$query"?ric="$2
1627 res="$(__do_curl_to_api PA GET $query)"
1628 status=${res:${#res}-3}
1630 if [ $status -ne $1 ]; then
1631 __log_test_fail_status_code $1 $status
1635 if [ $# -gt 2 ]; then
1636 body=${res:0:${#res}-3}
1639 for file in ${@:3} ; do
1640 if [ "$targetJson" != "[" ]; then
1641 targetJson=$targetJson","
1643 if [ $file == "NOFILE" ]; then
1644 targetJson=$targetJson"{}"
1646 targetJson=$targetJson$(< $file)
1650 targetJson=$targetJson"]"
1651 if [ "$PMS_VERSION" == "V2" ]; then
1652 targetJson="{\"policy_schemas\": $targetJson }"
1654 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1655 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1657 if [ $res -ne 0 ]; then
1658 __log_test_fail_body
1667 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1668 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1669 # (Function for test scripts)
1670 api_get_policy_status() {
1673 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1674 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1680 if [ $3 == "STD" ]; then
1681 targetJson="{\"enforceStatus\":\"$4\""
1682 if [ $# -eq 5 ]; then
1683 targetJson=$targetJson",\"reason\":\"$5\""
1685 targetJson=$targetJson"}"
1686 elif [ $3 == "STD2" ]; then
1687 if [ $4 == "EMPTY" ]; then
1688 targetJson="{\"enforceStatus\":\"\""
1690 targetJson="{\"enforceStatus\":\"$4\""
1692 if [ $# -eq 5 ]; then
1693 if [ $5 == "EMPTY" ]; then
1694 targetJson=$targetJson",\"enforceReason\":\"\""
1696 targetJson=$targetJson",\"enforceReason\":\"$5\""
1699 targetJson=$targetJson"}"
1700 elif [ $3 == "OSC" ]; then
1701 targetJson="{\"instance_status\":\"$4\""
1702 if [ $# -eq 5 ]; then
1703 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1705 targetJson=$targetJson",\"created_at\":\"????\"}"
1707 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1711 if [ "$PMS_VERSION" == "V2" ]; then
1712 query="/v2/policies/$UUID$2/status"
1713 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1715 query="/policy_status?id="$UUID$2
1718 res="$(__do_curl_to_api PA GET $query)"
1719 status=${res:${#res}-3}
1721 if [ $status -ne $1 ]; then
1722 __log_test_fail_status_code $1 $status
1726 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1727 body=${res:0:${#res}-3}
1728 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1730 if [ $res -ne 0 ]; then
1731 __log_test_fail_body
1739 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1740 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1741 # (Function for test scripts)
1742 api_get_policy_types() {
1745 if [ $# -lt 1 ]; then
1746 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1750 if [ "$PMS_VERSION" == "V2" ]; then
1751 if [ $# -eq 1 ]; then
1752 query="/v2/policy-types"
1753 elif [ $2 == "NORIC" ]; then
1754 query="/v2/policy-types"
1756 query="/v2/policy-types?ric_id=$2"
1759 if [ $# -eq 1 ]; then
1760 query="/policy_types"
1761 elif [ $2 == "NORIC" ]; then
1762 query="/policy_types"
1764 query="/policy_types?ric=$2"
1768 res="$(__do_curl_to_api PA GET $query)"
1769 status=${res:${#res}-3}
1771 if [ $status -ne $1 ]; then
1772 __log_test_fail_status_code $1 $status
1776 if [ $# -gt 2 ]; then
1777 body=${res:0:${#res}-3}
1780 for pid in ${@:3} ; do
1781 if [ "$targetJson" != "[" ]; then
1782 targetJson=$targetJson","
1784 if [ $pid == "EMPTY" ]; then
1787 targetJson=$targetJson"\"$pid\""
1790 targetJson=$targetJson"]"
1791 if [ "$PMS_VERSION" == "V2" ]; then
1792 targetJson="{\"policytype_ids\": $targetJson }"
1794 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1795 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1797 if [ $res -ne 0 ]; then
1798 __log_test_fail_body
1807 #########################################################
1808 #### Test case functions Health check
1809 #########################################################
1811 # API Test function: GET /status and V2 GET /status
1812 # args: <response-code>
1813 # (Function for test scripts)
1816 if [ $# -ne 1 ]; then
1817 __print_err "<response-code>" $@
1820 if [ "$PMS_VERSION" == "V2" ]; then
1825 res="$(__do_curl_to_api PA GET $query)"
1826 status=${res:${#res}-3}
1828 if [ $status -ne $1 ]; then
1829 __log_test_fail_status_code $1 $status
1837 #########################################################
1838 #### Test case functions RIC Repository
1839 #########################################################
1841 # API Test function: GET /ric and V2 GET /v2/rics/ric
1842 # args: <reponse-code> <management-element-id> [<ric-id>]
1843 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1844 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1845 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1848 # (Function for test scripts)
1852 if [ "$PMS_VERSION" == "V2" ]; then
1853 if [ $# -lt 3 ]; then
1854 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1858 if [ $2 != "NOME" ]; then
1859 search="?managed_element_id="$2
1861 if [ $3 != "NORIC" ]; then
1862 if [ -z $search ]; then
1865 search=$search"&ric_id="$3
1868 query="/v2/rics/ric"$search
1870 res="$(__do_curl_to_api PA GET $query)"
1871 status=${res:${#res}-3}
1873 if [ $status -ne $1 ]; then
1874 __log_test_fail_status_code $1 $status
1878 if [ $# -gt 3 ]; then
1879 body=${res:0:${#res}-3}
1880 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1881 if [ $res -ne 0 ]; then
1882 __log_test_fail_general "Could not create target ric info json"
1886 targetJson=$(<./tmp/.tmp_rics.json)
1887 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1888 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1889 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1890 if [ $res -ne 0 ]; then
1891 __log_test_fail_body
1896 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1897 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1901 query="/ric?managedElementId="$2
1903 res="$(__do_curl_to_api PA GET $query)"
1904 status=${res:${#res}-3}
1906 if [ $status -ne $1 ]; then
1907 __log_test_fail_status_code $1 $status
1911 if [ $# -eq 3 ]; then
1912 body=${res:0:${#res}-3}
1913 if [ "$body" != "$3" ]; then
1914 __log_test_fail_body
1923 # API test function: GET /rics and V2 GET /v2/rics
1924 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1925 # 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_........."
1926 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1927 # (Function for test scripts)
1931 if [ $# -lt 2 ]; then
1932 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1936 if [ "$PMS_VERSION" == "V2" ]; then
1938 if [ $2 != "NOTYPE" ]; then
1939 query="/v2/rics?policytype_id="$2
1943 if [ $2 != "NOTYPE" ]; then
1944 query="/rics?policyType="$2
1948 res="$(__do_curl_to_api PA GET $query)"
1949 status=${res:${#res}-3}
1951 if [ $status -ne $1 ]; then
1952 __log_test_fail_status_code $1 $status
1956 if [ $# -gt 2 ]; then
1957 body=${res:0:${#res}-3}
1958 if [ "$PMS_VERSION" == "V2" ]; then
1959 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1961 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1963 if [ $res -ne 0 ]; then
1964 __log_test_fail_general "Could not create target ric info json"
1968 targetJson=$(<./tmp/.tmp_rics.json)
1969 if [ "$PMS_VERSION" == "V2" ]; then
1970 targetJson="{\"rics\": $targetJson }"
1972 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1973 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1974 if [ $res -ne 0 ]; then
1975 __log_test_fail_body
1984 ##################################################################
1985 #### API Test case functions Service registry and supervision ####
1986 ##################################################################
1988 # API test function: PUT /service and V2 PUT /service
1989 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1990 # (Function for test scripts)
1993 if [ $# -ne 4 ]; then
1994 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1998 if [ "$PMS_VERSION" == "V2" ]; then
1999 query="/v2/services"
2000 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2003 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2005 file="./tmp/.tmp.json"
2006 echo "$json" > $file
2008 res="$(__do_curl_to_api PA PUT $query $file)"
2009 status=${res:${#res}-3}
2011 if [ $status -ne $1 ]; then
2012 __log_test_fail_status_code $1 $status
2020 # API test function: GET /services and V2 GET /v2/services
2021 #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>]* )]
2022 # (Function for test scripts)
2023 api_get_services() {
2025 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2027 if [ $# -eq 1 ]; then
2029 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2031 elif [ $# -eq 5 ]; then
2033 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2035 if [ $(($argLen%3)) -eq 0 ]; then
2040 if [ $paramError -ne 0 ]; then
2041 __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>]* )]" $@
2045 if [ "$PMS_VERSION" == "V2" ]; then
2046 query="/v2/services"
2048 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2049 query="/v2/services?service_id="$2
2054 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2055 query="/services?name="$2
2058 res="$(__do_curl_to_api PA GET $query)"
2059 status=${res:${#res}-3}
2061 if [ $status -ne $1 ]; then
2062 __log_test_fail_status_code $1 $status
2066 if [ $# -gt 2 ]; then
2067 variableArgCount=$(($#-2))
2068 body=${res:0:${#res}-3}
2072 while [ $cntr -lt $variableArgCount ]; do
2073 servicename=$1; shift;
2076 if [ $cntr -gt 0 ]; then
2077 targetJson=$targetJson","
2079 # timeSinceLastActivitySeconds value cannot be checked since value varies
2080 if [ "$PMS_VERSION" == "V2" ]; then
2081 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2083 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2087 targetJson=$targetJson"]"
2088 if [ "$PMS_VERSION" == "V2" ]; then
2089 targetJson="{\"service_list\": $targetJson }"
2091 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2092 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2093 if [ $res -ne 0 ]; then
2094 __log_test_fail_body
2103 # API test function: GET /services V2 GET /v2/services - (only checking service names)
2104 # args: <response-code> [<service-name>]*"
2105 # (Function for test scripts)
2106 api_get_service_ids() {
2109 if [ $# -lt 1 ]; then
2110 __print_err "<response-code> [<service-name>]*" $@
2114 if [ "$PMS_VERSION" == "V2" ]; then
2115 query="/v2/services"
2119 res="$(__do_curl_to_api PA GET $query)"
2120 status=${res:${#res}-3}
2122 if [ $status -ne $1 ]; then
2123 __log_test_fail_status_code $1 $status
2127 body=${res:0:${#res}-3}
2129 for rapp in ${@:2} ; do
2130 if [ "$targetJson" != "[" ]; then
2131 targetJson=$targetJson","
2133 if [ "$PMS_VERSION" == "V2" ]; then
2134 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2136 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2140 targetJson=$targetJson"]"
2141 if [ "$PMS_VERSION" == "V2" ]; then
2142 targetJson="{\"service_list\": $targetJson }"
2144 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2145 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2147 if [ $res -ne 0 ]; then
2148 __log_test_fail_body
2156 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2157 # args: <response-code> <service-name>
2158 # (Function for test scripts)
2159 api_delete_services() {
2162 if [ $# -ne 2 ]; then
2163 __print_err "<response-code> <service-name>" $@
2166 if [ "$PMS_VERSION" == "V2" ]; then
2167 query="/v2/services/"$2
2169 query="/services?name="$2
2171 res="$(__do_curl_to_api PA DELETE $query)"
2172 status=${res:${#res}-3}
2174 if [ $status -ne $1 ]; then
2175 __log_test_fail_status_code $1 $status
2183 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2184 # args: <response-code> <service-name>
2185 # (Function for test scripts)
2186 api_put_services_keepalive() {
2189 if [ $# -ne 2 ]; then
2190 __print_err "<response-code> <service-name>" $@
2193 if [ "$PMS_VERSION" == "V2" ]; then
2194 query="/v2/services/$2/keepalive"
2196 query="/services/keepalive?name="$2
2199 res="$(__do_curl_to_api PA PUT $query)"
2200 status=${res:${#res}-3}
2202 if [ $status -ne $1 ]; then
2203 __log_test_fail_status_code $1 $status
2211 ##################################################################
2212 #### API Test case functions Configuration ####
2213 ##################################################################
2215 # API Test function: PUT /v2/configuration
2216 # args: <response-code> <config-file>
2217 # (Function for test scripts)
2218 api_put_configuration() {
2221 if [ "$PMS_VERSION" != "V2" ]; then
2222 __log_test_fail_not_supported
2226 if [ $# -ne 2 ]; then
2227 __print_err "<response-code> <config-file>" $@
2230 if [ ! -f $2 ]; then
2231 __log_test_fail_general "Config file "$2", does not exist"
2235 inputJson="{\"config\":"$inputJson"}"
2236 file="./tmp/.config.json"
2237 echo $inputJson > $file
2238 query="/v2/configuration"
2239 res="$(__do_curl_to_api PA PUT $query $file)"
2240 status=${res:${#res}-3}
2242 if [ $status -ne $1 ]; then
2243 __log_test_fail_status_code $1 $status
2251 # API Test function: GET /v2/configuration
2252 # args: <response-code> [<config-file>]
2253 # (Function for test scripts)
2254 api_get_configuration() {
2257 if [ "$PMS_VERSION" != "V2" ]; then
2258 __log_test_fail_not_supported
2262 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2263 __print_err "<response-code> [<config-file>]" $@
2266 if [ ! -f $2 ]; then
2267 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2271 query="/v2/configuration"
2272 res="$(__do_curl_to_api PA GET $query)"
2273 status=${res:${#res}-3}
2275 if [ $status -ne $1 ]; then
2276 __log_test_fail_status_code $1 $status
2280 if [ $# -eq 2 ]; then
2282 body=${res:0:${#res}-3}
2285 targetJson="{\"config\":"$targetJson"}"
2286 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2287 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2289 if [ $res -ne 0 ]; then
2290 __log_test_fail_body
2299 ##########################################
2300 #### Reset types and instances ####
2301 ##########################################
2303 # Admin reset to remove all policies and services
2304 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2305 # NOTE - only works in kubernetes and the pod should not be running
2307 # (Function for test scripts)
2309 pms_kube_pvc_reset() {
2312 pvc_name=$(kubectl get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2313 if [ -z "$pvc_name" ]; then
2314 pvc_name=policymanagementservice-vardata-pvc
2316 echo " Trying to reset pvc: "$pvc_name
2317 __kube_clean_pvc $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $POLICY_AGENT_CONTAINER_MNT_DIR