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"
106 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
108 __PA_test_requirements() {
113 #######################################################
115 ###########################
116 ### Policy Agents functions
117 ###########################
119 # Set http as the protocol to use for all communication to the Policy Agent
121 # (Function for test scripts)
122 use_agent_rest_http() {
123 __agent_set_protocoll "http" $POLICY_AGENT_INTERNAL_PORT $POLICY_AGENT_EXTERNAL_PORT
126 # Set https as the protocol to use for all communication to the Policy Agent
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
133 # All calls to the agent will be directed to the agent dmaap interface over http from now on
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"
143 # All calls to the agent will be directed to the agent dmaap interface over https from now on
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"
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"
160 ## Access to Dmaap adapter
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
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
174 # Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
177 #Save first worker node the pod is started on
180 # Export env vars for config files, docker compose and kube resources
181 # args: PROXY|NOPROXY
182 __export_agent_vars() {
184 export POLICY_AGENT_APP_NAME
185 export POLICY_AGENT_APP_NAME_ALIAS
186 export POLICY_AGENT_DISPLAY_NAME
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
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
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
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
219 echo " Configured with http proxy"
222 export AGENT_HTTP_PROXY_CONFIG_PORT=0
223 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
224 echo " Configured without http proxy"
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
236 if [ $RUNMODE == "KUBE" ]; then
238 # Check if app shall be fully managed by the test script
239 __check_included_image "PA"
242 # Check if app shall only be used by the testscipt
243 __check_prestarted_image "PA"
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
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
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
264 if [ $retcode_i -eq 0 ]; then
266 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
268 #Check if nonrtric namespace exists, if not create it
269 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
271 __export_agent_vars $1
273 # Create config map for config
274 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
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
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
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
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
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
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
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
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 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
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
322 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
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
335 cd $POLICY_AGENT_HOST_MNT_DIR
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
347 echo " No files in mounted dir or dir does not exists"
351 __export_agent_vars $1
353 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
355 envsubst < $2 > $dest_file
357 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
359 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
365 # Stop the policy agent
368 # (Function for test scripts)
369 stop_policy_agent() {
370 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
372 if [ $RUNMODE == "KUBE" ]; then
374 __check_prestarted_image "PA"
375 if [ $? -eq 0 ]; then
376 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
377 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
378 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
381 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
382 echo " Deleting the replica set - a new will be started when the app is started"
383 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
384 if [ $? -ne 0 ]; then
385 echo -e $RED" Could not delete replica set "$RED
390 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
391 if [ $? -ne 0 ]; then
392 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
398 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
403 # Start a previously stopped policy agent
405 # (Function for test scripts)
406 start_stopped_policy_agent() {
407 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
409 if [ $RUNMODE == "KUBE" ]; then
411 __check_prestarted_image "PA"
412 if [ $? -eq 0 ]; then
413 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
414 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
415 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
416 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
420 # Tie the PMS to the same worker node it was initially started on
421 # 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
422 if [ -z "$__PA_WORKER_NODE" ]; then
423 echo -e $RED" No initial worker node found for pod "$RED
427 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
428 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
429 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
430 if [ $? -ne 0 ]; then
431 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
433 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
436 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
437 if [ $? -ne 0 ]; then
438 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
444 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
445 if [ $? -ne 0 ]; then
453 # Function to perpare the consul configuration according to the current simulator configuration
454 # args: SDNC|NOSDNC <output-file>
455 # (Function for test scripts)
456 prepare_consul_config() {
457 echo -e $BOLD"Prepare Consul config"$EBOLD
459 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
463 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
467 if [ $1 == "SDNC" ]; then
468 echo -e " Config$BOLD including SDNC$EBOLD configuration"
469 elif [ $1 == "NOSDNC" ]; then
470 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
473 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
478 if [ $1 == "SDNC" ]; then
479 config_json=$config_json"\n \"controller\": ["
480 config_json=$config_json"\n {"
481 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
482 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
483 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
484 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
485 config_json=$config_json"\n }"
486 config_json=$config_json"\n ],"
489 config_json=$config_json"\n \"streams_publishes\": {"
490 config_json=$config_json"\n \"dmaap_publisher\": {"
491 config_json=$config_json"\n \"type\": \"message-router\","
492 config_json=$config_json"\n \"dmaap_info\": {"
493 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
494 config_json=$config_json"\n }"
495 config_json=$config_json"\n }"
496 config_json=$config_json"\n },"
497 config_json=$config_json"\n \"streams_subscribes\": {"
498 config_json=$config_json"\n \"dmaap_subscriber\": {"
499 config_json=$config_json"\n \"type\": \"message-router\","
500 config_json=$config_json"\n \"dmaap_info\": {"
501 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
502 config_json=$config_json"\n }"
503 config_json=$config_json"\n }"
504 config_json=$config_json"\n },"
506 config_json=$config_json"\n \"ric\": ["
508 if [ $RUNMODE == "KUBE" ]; then
509 result=$(kubectl get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
512 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
513 for im in $result; do
514 if [[ $im != *"-0" ]]; then
515 ric_subdomain=$(kubectl get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
516 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
517 let ric_cntr=ric_cntr+1
521 if [ $ric_cntr -eq 0 ]; then
522 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
525 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
526 if [ $? -ne 0 ] || [ -z "$rics" ]; then
527 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
534 if [ $cntr -gt 0 ]; then
535 config_json=$config_json"\n ,"
537 config_json=$config_json"\n {"
538 if [ $RUNMODE == "KUBE" ]; then
539 ric_id=${ric%.*.*} #extract pod id from full hosthame
540 ric_id=$(echo "$ric_id" | tr '-' '_')
542 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
545 ric_id=$(echo "$ric" | tr '-' '_') #ric id still needs underscore as it is different from the container name
548 echo " Found a1 sim: "$ric_id
549 config_json=$config_json"\n \"name\": \"$ric_id\","
550 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
551 if [ $1 == "SDNC" ]; then
552 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
554 config_json=$config_json"\n \"managedElementIds\": ["
555 config_json=$config_json"\n \"me1_$ric_id\","
556 config_json=$config_json"\n \"me2_$ric_id\""
557 config_json=$config_json"\n ]"
558 config_json=$config_json"\n }"
562 config_json=$config_json"\n ]"
563 config_json=$config_json"\n}"
565 if [ $RUNMODE == "KUBE" ]; then
566 config_json="{\"config\":"$config_json"}"
569 printf "$config_json">$2
574 # Load the the appl config for the agent into a config map
575 agent_load_config() {
576 echo -e $BOLD"Agent - load config from "$EBOLD$1
577 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
579 output_yaml=$PWD/tmp/pa_cfd.yaml
580 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
585 # Turn on debug level tracing in the agent
587 # (Function for test scripts)
589 echo -e $BOLD"Setting agent debug logging"$EBOLD
590 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
591 result=$(__do_curl "$curlString")
592 if [ $? -ne 0 ]; then
593 __print_err "could not set debug mode" $@
601 # Turn on trace level tracing in the agent
603 # (Function for test scripts)
605 echo -e $BOLD"Setting agent trace logging"$EBOLD
606 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
607 result=$(__do_curl "$curlString")
608 if [ $? -ne 0 ]; then
609 __print_err "could not set trace mode" $@
617 # Perform curl retries when making direct call to the agent for the specified http response codes
618 # Speace separated list of http response codes
619 # args: [<response-code>]*
620 use_agent_retries() {
621 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
627 # Check the agent logs for WARNINGs and ERRORs
629 # (Function for test scripts)
630 check_policy_agent_logs() {
631 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
634 #########################################################
635 #### Test case functions A1 Policy management service
636 #########################################################
638 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
639 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
640 # args: json:<url> <target-value> [<timeout-in-seconds]
641 # (Function for test scripts)
643 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
644 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
645 if [[ $1 == "json:"* ]]; then
646 if [ "$PMS_VERSION" == "V2" ]; then
647 __var_test "Policy Agent" $PA_SERVICE_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
649 __var_test "Policy Agent" $PA_SERVICE_PATH"/" $1 "=" $2 $3
654 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
658 # API Test function: GET /policies and V2 GET /v2/policy-instances
659 # 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>]*]
660 # 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>]*]
661 # (Function for test scripts)
665 if [ "$PMS_VERSION" == "V2" ]; then
667 variableParams=$(($#-4))
668 if [ $# -lt 4 ]; then
670 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
672 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
676 if [ $paramError -ne 0 ]; then
677 __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>]*]" $@
682 variableParams=$(($#-4))
683 if [ $# -lt 4 ]; then
685 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
687 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
691 if [ $paramError -ne 0 ]; then
692 __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>]*]" $@
698 if [ "$PMS_VERSION" == "V2" ]; then
699 if [ $2 != "NORIC" ]; then
700 queryparams="?ric_id="$2
702 if [ $3 != "NOSERVICE" ]; then
703 if [ -z $queryparams ]; then
704 queryparams="?service_id="$3
706 queryparams=$queryparams"&service_id="$3
709 if [ $4 != "NOTYPE" ]; then
710 if [ -z $queryparams ]; then
711 queryparams="?policytype_id="$4
713 queryparams=$queryparams"&policytype_id="$4
717 query="/v2/policy-instances"$queryparams
718 res="$(__do_curl_to_api PA GET $query)"
719 status=${res:${#res}-3}
721 if [ $status -ne $1 ]; then
722 __log_test_fail_status_code $1 $status
726 if [ $# -gt 4 ]; then
727 body=${res:0:${#res}-3}
728 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
734 for ((i=0; i<$(($#-4)); i=i+7)); do
736 if [ "$targetJson" != "[" ]; then
737 targetJson=$targetJson","
739 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
740 if [ "${arr[$i+3]}" == "EMPTY" ]; then
741 targetJson=$targetJson"\"\","
743 targetJson=$targetJson"\"${arr[$i+3]}\","
745 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
747 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
749 targetJson=$targetJson"\"policy_data\":"$json"}"
753 targetJson=$targetJson"]"
754 targetJson="{\"policies\": $targetJson}"
755 echo "TARGET JSON: $targetJson" >> $HTTPLOG
756 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
758 if [ $res -ne 0 ]; then
764 if [ $2 != "NORIC" ]; then
765 queryparams="?ric="$2
767 if [ $3 != "NOSERVICE" ]; then
768 if [ -z $queryparams ]; then
769 queryparams="?service="$3
771 queryparams=$queryparams"&service="$3
774 if [ $4 != "NOTYPE" ]; then
775 if [ -z $queryparams ]; then
776 queryparams="?type="$4
778 queryparams=$queryparams"&type="$4
782 query="/policies"$queryparams
783 res="$(__do_curl_to_api PA GET $query)"
784 status=${res:${#res}-3}
786 if [ $status -ne $1 ]; then
787 __log_test_fail_status_code $1 $status
791 if [ $# -gt 4 ]; then
792 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
795 body=${res:0:${#res}-3}
799 for ((i=0; i<$(($#-4)); i=i+5)); do
801 if [ "$targetJson" != "[" ]; then
802 targetJson=$targetJson","
804 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
805 if [ "${arr[$i+3]}" == "EMPTY" ]; then
806 targetJson=$targetJson"\"\","
808 targetJson=$targetJson"\"${arr[$i+3]}\","
811 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
813 targetJson=$targetJson"\"json\":"$json"}"
817 targetJson=$targetJson"]"
818 echo "TARGET JSON: $targetJson" >> $HTTPLOG
819 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
821 if [ $res -ne 0 ]; then
834 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
835 # args: <response-code> <policy-id> [<template-file>]
836 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
838 # (Function for test scripts)
843 if [ "$PMS_VERSION" == "V2" ]; then
844 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
845 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
848 query="/v2/policies/$UUID$2"
850 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
851 __print_err "<response-code> <policy-id> [<template-file>] " $@
854 query="/policy?id=$UUID$2"
856 res="$(__do_curl_to_api PA GET $query)"
857 status=${res:${#res}-3}
859 if [ $status -ne $1 ]; then
860 __log_test_fail_status_code $1 $status
864 if [ "$PMS_VERSION" == "V2" ]; then
865 if [ $# -eq 8 ]; then
867 #Create a policy json to compare with
868 body=${res:0:${#res}-3}
870 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
871 if [ $7 != "NOTRANSIENT" ]; then
872 targetJson=$targetJson", \"transient\":$7"
874 if [ $6 != "NOTYPE" ]; then
875 targetJson=$targetJson", \"policytype_id\":\"$6\""
877 targetJson=$targetJson", \"policytype_id\":\"\""
879 if [ $8 != "NOURL" ]; then
880 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
883 data=$(sed 's/XXX/'${2}'/g' $3)
884 targetJson=$targetJson", \"policy_data\":$data"
885 targetJson="{$targetJson}"
887 echo "TARGET JSON: $targetJson" >> $HTTPLOG
888 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
889 if [ $res -ne 0 ]; then
895 if [ $# -eq 3 ]; then
896 #Create a policy json to compare with
897 body=${res:0:${#res}-3}
899 sed 's/XXX/'${2}'/g' $3 > $file
900 targetJson=$(< $file)
901 echo "TARGET JSON: $targetJson" >> $HTTPLOG
902 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
903 if [ $res -ne 0 ]; then
913 # API Test function: PUT /policy and V2 PUT /policies
914 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
915 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
916 # (Function for test scripts)
920 if [ "$PMS_VERSION" == "V2" ]; then
921 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
922 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
926 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
927 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
940 if [ "$PMS_VERSION" == "V2" ]; then
943 if [ $# -eq 9 ]; then
948 if [ $# -eq 8 ]; then
953 while [ $count -lt $max ]; do
954 if [ "$PMS_VERSION" == "V2" ]; then
958 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
959 if [ $trans != "NOTRANSIENT" ]; then
960 inputJson=$inputJson", \"transient\":$trans"
962 if [ $pt != "NOTYPE" ]; then
963 inputJson=$inputJson", \"policytype_id\":\"$pt\""
965 inputJson=$inputJson", \"policytype_id\":\"\""
967 if [ $noti != "NOURL" ]; then
968 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
971 data=$(sed 's/XXX/'${pid}'/g' $temp)
972 inputJson=$inputJson", \"policy_data\":$data"
973 inputJson="{$inputJson}"
974 echo $inputJson > $file
976 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
978 if [ $pt != "NOTYPE" ]; then
979 query=$query"&type=$pt"
982 if [ $trans != NOTRANSIENT ]; then
983 query=$query"&transient=$trans"
987 sed 's/XXX/'${pid}'/g' $temp > $file
989 res="$(__do_curl_to_api PA PUT $query $file)"
990 status=${res:${#res}-3}
991 echo -ne " Executing "$count"("$max")${SAMELINE}"
992 if [ $status -ne $1 ]; then
993 echo " Executed "$count"?("$max")"
994 __log_test_fail_status_code $1 $status
1000 echo -ne " Executed "$count"("$max")${SAMELINE}"
1008 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
1009 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1010 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
1011 # (Function for test scripts)
1013 api_put_policy_batch() {
1016 if [ "$PMS_VERSION" == "V2" ]; then
1017 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1018 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1022 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1023 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1035 if [ "$PMS_VERSION" == "V2" ]; then
1038 if [ $# -eq 9 ]; then
1043 if [ $# -eq 8 ]; then
1049 while [ $count -lt $max ]; do
1050 if [ "$PMS_VERSION" == "V2" ]; then
1051 query="/v2/policies"
1053 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1054 if [ $trans != "NOTRANSIENT" ]; then
1055 inputJson=$inputJson", \"transient\":$trans"
1057 if [ $pt != "NOTYPE" ]; then
1058 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1060 inputJson=$inputJson", \"policytype_id\":\"\""
1062 if [ $noti != "NOURL" ]; then
1063 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1065 file="./tmp/.p.json"
1066 data=$(sed 's/XXX/'${pid}'/g' $temp)
1067 inputJson=$inputJson", \"policy_data\":$data"
1068 inputJson="{$inputJson}"
1069 echo $inputJson > $file
1071 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1073 if [ $pt != "NOTYPE" ]; then
1074 query=$query"&type=$pt"
1077 if [ $trans != NOTRANSIENT ]; then
1078 query=$query"&transient=$trans"
1080 file="./tmp/.p.json"
1081 sed 's/XXX/'${pid}'/g' $temp > $file
1083 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
1084 status=${res:${#res}-3}
1085 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1087 if [ $status -ne 200 ]; then
1088 echo " Requested(batch) "$count"?("$max")"
1089 __log_test_fail_status_code 200 $status
1092 cid=${res:0:${#res}-3}
1096 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1103 res="$(__do_curl_to_api PA RESPONSE $cid)"
1104 status=${res:${#res}-3}
1105 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
1107 if [ $status -ne $1 ]; then
1108 echo " Accepted(batch) "$count"?("$max")"
1109 __log_test_fail_status_code $1 $status
1114 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1123 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1124 # 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>
1125 # 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>
1126 # (Function for test scripts)
1127 api_put_policy_parallel() {
1130 if [ "$PMS_VERSION" == "V2" ]; then
1131 if [ $# -ne 11 ]; then
1132 __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>" $@
1136 if [ $# -ne 10 ]; then
1137 __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>" $@
1141 resp_code=$1; shift;
1147 transient=$1; shift;
1148 if [ "$PMS_VERSION" == "V2" ]; then
1157 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1158 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1159 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1160 echo " Info - will execute over agent REST"
1162 if [ "$PMS_VERSION" == "V2" ]; then
1163 if [ $serv == "NOSERVICE" ]; then
1166 query="$PMS_API_PREFIX/v2/policies"
1168 if [ $serv == "NOSERVICE" ]; then
1171 query="/policy?service=$serv"
1173 if [ $type != "NOTYPE" ]; then
1174 query=$query"&type=$type"
1177 if [ $transient != NOTRANSIENT ]; then
1178 query=$query"&transient=$transient"
1182 urlbase=${PA_ADAPTER}${query}
1185 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1186 httpproxy=$KUBE_PROXY_PATH
1189 for ((i=1; i<=$pids; i++))
1192 if [ -z "$uuid" ]; then
1195 echo "" > "./tmp/.pid${i}.res.txt"
1196 if [ "$PMS_VERSION" == "V2" ]; then
1197 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1199 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1202 done | xargs -n 1 -I{} -P $pids bash -c '{
1204 echo " Parallel process $arg started"
1205 tmp=$(< "./tmp/.pid${arg}.txt")
1206 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1209 for ((i=1; i<=$pids; i++))
1211 file="./tmp/.pid${i}.res.txt"
1213 if [ -z "$tmp" ]; then
1214 echo " Process $i : unknown result (result file empty"
1218 if [ $res == "0" ]; then
1219 echo " Process $i : OK - "${tmp:1}
1221 echo " Process $i : failed - "${tmp:1}
1226 if [ -z $msg ]; then
1227 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1231 __log_test_fail_general "One of more processes failed to execute"
1235 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1236 # args: <response-code> <policy-id> [count]
1237 # (Function for test scripts)
1238 api_delete_policy() {
1241 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1242 __print_err "<response-code> <policy-id> [count]" $@
1249 if [ $# -eq 3 ]; then
1255 while [ $count -lt $max ]; do
1256 if [ "$PMS_VERSION" == "V2" ]; then
1257 query="/v2/policies/"$UUID$pid
1259 query="/policy?id="$UUID$pid
1261 res="$(__do_curl_to_api PA DELETE $query)"
1262 status=${res:${#res}-3}
1263 echo -ne " Executing "$count"("$max")${SAMELINE}"
1265 if [ $status -ne $1 ]; then
1266 echo " Executed "$count"?("$max")"
1267 __log_test_fail_status_code $1 $status
1272 echo -ne " Executed "$count"("$max")${SAMELINE}"
1280 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1281 # args: <response-code> <policy-id> [count]
1282 # (Function for test scripts)
1283 api_delete_policy_batch() {
1286 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1287 __print_err "<response-code> <policy-id> [count]" $@
1294 if [ $# -eq 3 ]; then
1300 while [ $count -lt $max ]; do
1301 if [ "$PMS_VERSION" == "V2" ]; then
1302 query="/v2/policies/"$UUID$pid
1304 query="/policy?id="$UUID$pid
1306 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
1307 status=${res:${#res}-3}
1308 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1310 if [ $status -ne 200 ]; then
1311 echo " Requested(batch) "$count"?("$max")"
1312 __log_test_fail_status_code 200 $status
1315 cid=${res:0:${#res}-3}
1319 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1327 res="$(__do_curl_to_api PA RESPONSE $cid)"
1328 status=${res:${#res}-3}
1329 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1331 if [ $status -ne $1 ]; then
1332 echo " Deleted(batch) "$count"?("$max")"
1333 __log_test_fail_status_code $1 $status
1338 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1347 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1348 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1349 # (Function for test scripts)
1350 api_delete_policy_parallel() {
1353 if [ $# -ne 5 ]; then
1354 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1357 resp_code=$1; shift;
1363 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1364 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1365 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1366 echo " Info - will execute over agent REST"
1369 if [ "$PMS_VERSION" == "V2" ]; then
1370 query="$PMS_API_PREFIX/v2/policies/"
1375 urlbase=${PA_ADAPTER}${query}
1378 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1379 httpproxy=$KUBE_PROXY_PATH
1382 for ((i=1; i<=$pids; i++))
1385 if [ -z "$uuid" ]; then
1388 echo "" > "./tmp/.pid${i}.del.res.txt"
1389 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1391 done | xargs -n 1 -I{} -P $pids bash -c '{
1393 echo " Parallel process $arg started"
1394 tmp=$(< "./tmp/.pid${arg}.del.txt")
1395 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1398 for ((i=1; i<=$pids; i++))
1400 file="./tmp/.pid${i}.del.res.txt"
1402 if [ -z "$tmp" ]; then
1403 echo " Process $i : unknown result (result file empty"
1407 if [ $res == "0" ]; then
1408 echo " Process $i : OK - "${tmp:1}
1410 echo " Process $i : failed - "${tmp:1}
1415 if [ -z $msg ]; then
1416 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1420 __log_test_fail_general "One of more processes failed to execute"
1424 # API Test function: GET /policy_ids and V2 GET /v2/policies
1425 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1426 # (Function for test scripts)
1427 api_get_policy_ids() {
1430 if [ $# -lt 4 ]; then
1431 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1437 if [ "$PMS_VERSION" == "V2" ]; then
1438 if [ $2 != "NORIC" ]; then
1439 queryparams="?ric_id="$2
1442 if [ $3 != "NOSERVICE" ]; then
1443 if [ -z $queryparams ]; then
1444 queryparams="?service_id="$3
1446 queryparams=$queryparams"&service_id="$3
1449 if [ $4 != "NOTYPE" ]; then
1450 if [ -z $queryparams ]; then
1451 queryparams="?policytype_id="$4
1453 queryparams=$queryparams"&policytype_id="$4
1457 query="/v2/policies"$queryparams
1459 if [ $2 != "NORIC" ]; then
1460 queryparams="?ric="$2
1463 if [ $3 != "NOSERVICE" ]; then
1464 if [ -z $queryparams ]; then
1465 queryparams="?service="$3
1467 queryparams=$queryparams"&service="$3
1470 if [ $4 != "NOTYPE" ]; then
1471 if [ -z $queryparams ]; then
1472 queryparams="?type="$4
1474 queryparams=$queryparams"&type="$4
1478 query="/policy_ids"$queryparams
1481 res="$(__do_curl_to_api PA GET $query)"
1482 status=${res:${#res}-3}
1484 if [ $status -ne $1 ]; then
1485 __log_test_fail_status_code $1 $status
1489 if [ $# -gt 4 ]; then
1490 body=${res:0:${#res}-3}
1493 for pid in ${@:5} ; do
1494 if [ "$targetJson" != "[" ]; then
1495 targetJson=$targetJson","
1497 if [ $pid != "NOID" ]; then
1498 targetJson=$targetJson"\"$UUID$pid\""
1502 targetJson=$targetJson"]"
1503 if [ "$PMS_VERSION" == "V2" ]; then
1504 targetJson="{\"policy_ids\": $targetJson}"
1506 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1507 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1509 if [ $res -ne 0 ]; then
1510 __log_test_fail_body
1519 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1520 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1521 # (Function for test scripts)
1522 api_get_policy_type() {
1525 if [ "$PMS_VERSION" != "V2" ]; then
1526 __log_test_fail_not_supported
1530 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1531 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1534 query="/v2/policy-types/$2"
1536 res="$(__do_curl_to_api PA GET $query)"
1537 status=${res:${#res}-3}
1539 if [ $status -ne $1 ]; then
1540 __log_test_fail_status_code $1 $status
1544 if [ $# -eq 3 ]; then
1546 body=${res:0:${#res}-3}
1549 targetJson="{\"policy_schema\":$targetJson}"
1550 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1551 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1553 if [ $res -ne 0 ]; then
1554 __log_test_fail_body
1563 # API Test function: GET /policy_schema
1564 # args: <response-code> <policy-type-id> [<schema-file>]
1565 # (Function for test scripts)
1566 api_get_policy_schema() {
1569 if [ "$PMS_VERSION" == "V2" ]; then
1570 __log_test_fail_not_supported
1574 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1575 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1578 query="/policy_schema?id=$2"
1579 res="$(__do_curl_to_api PA GET $query)"
1580 status=${res:${#res}-3}
1582 if [ $status -ne $1 ]; then
1583 __log_test_fail_status_code $1 $status
1587 if [ $# -eq 3 ]; then
1589 body=${res:0:${#res}-3}
1593 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1594 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1596 if [ $res -ne 0 ]; then
1597 __log_test_fail_body
1606 # API Test function: GET /policy_schemas
1607 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1608 # args(V2): <response-code>
1609 # (Function for test scripts)
1610 api_get_policy_schemas() {
1613 if [ "$PMS_VERSION" == "V2" ]; then
1614 if [ $# -ne 1 ]; then
1615 __print_err "<response-code>" $@
1619 if [ $# -lt 2 ]; then
1620 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1624 if [ "$PMS_VERSION" == "V2" ]; then
1625 query="/v2/policy-schemas"
1627 query="/policy_schemas"
1628 if [ $2 != "NORIC" ]; then
1629 query=$query"?ric="$2
1633 res="$(__do_curl_to_api PA GET $query)"
1634 status=${res:${#res}-3}
1636 if [ $status -ne $1 ]; then
1637 __log_test_fail_status_code $1 $status
1641 if [ $# -gt 2 ]; then
1642 body=${res:0:${#res}-3}
1645 for file in ${@:3} ; do
1646 if [ "$targetJson" != "[" ]; then
1647 targetJson=$targetJson","
1649 if [ $file == "NOFILE" ]; then
1650 targetJson=$targetJson"{}"
1652 targetJson=$targetJson$(< $file)
1656 targetJson=$targetJson"]"
1657 if [ "$PMS_VERSION" == "V2" ]; then
1658 targetJson="{\"policy_schemas\": $targetJson }"
1660 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1661 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1663 if [ $res -ne 0 ]; then
1664 __log_test_fail_body
1673 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1674 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1675 # (Function for test scripts)
1676 api_get_policy_status() {
1679 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1680 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1686 if [ $3 == "STD" ]; then
1687 targetJson="{\"enforceStatus\":\"$4\""
1688 if [ $# -eq 5 ]; then
1689 targetJson=$targetJson",\"reason\":\"$5\""
1691 targetJson=$targetJson"}"
1692 elif [ $3 == "STD2" ]; then
1693 if [ $4 == "EMPTY" ]; then
1694 targetJson="{\"enforceStatus\":\"\""
1696 targetJson="{\"enforceStatus\":\"$4\""
1698 if [ $# -eq 5 ]; then
1699 if [ $5 == "EMPTY" ]; then
1700 targetJson=$targetJson",\"enforceReason\":\"\""
1702 targetJson=$targetJson",\"enforceReason\":\"$5\""
1705 targetJson=$targetJson"}"
1706 elif [ $3 == "OSC" ]; then
1707 targetJson="{\"instance_status\":\"$4\""
1708 if [ $# -eq 5 ]; then
1709 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1711 targetJson=$targetJson",\"created_at\":\"????\"}"
1713 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1717 if [ "$PMS_VERSION" == "V2" ]; then
1718 query="/v2/policies/$UUID$2/status"
1719 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1721 query="/policy_status?id="$UUID$2
1724 res="$(__do_curl_to_api PA GET $query)"
1725 status=${res:${#res}-3}
1727 if [ $status -ne $1 ]; then
1728 __log_test_fail_status_code $1 $status
1732 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1733 body=${res:0:${#res}-3}
1734 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1736 if [ $res -ne 0 ]; then
1737 __log_test_fail_body
1745 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1746 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1747 # (Function for test scripts)
1748 api_get_policy_types() {
1751 if [ $# -lt 1 ]; then
1752 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1756 if [ "$PMS_VERSION" == "V2" ]; then
1757 if [ $# -eq 1 ]; then
1758 query="/v2/policy-types"
1759 elif [ $2 == "NORIC" ]; then
1760 query="/v2/policy-types"
1762 query="/v2/policy-types?ric_id=$2"
1765 if [ $# -eq 1 ]; then
1766 query="/policy_types"
1767 elif [ $2 == "NORIC" ]; then
1768 query="/policy_types"
1770 query="/policy_types?ric=$2"
1774 res="$(__do_curl_to_api PA GET $query)"
1775 status=${res:${#res}-3}
1777 if [ $status -ne $1 ]; then
1778 __log_test_fail_status_code $1 $status
1782 if [ $# -gt 2 ]; then
1783 body=${res:0:${#res}-3}
1786 for pid in ${@:3} ; do
1787 if [ "$targetJson" != "[" ]; then
1788 targetJson=$targetJson","
1790 if [ $pid == "EMPTY" ]; then
1793 targetJson=$targetJson"\"$pid\""
1796 targetJson=$targetJson"]"
1797 if [ "$PMS_VERSION" == "V2" ]; then
1798 targetJson="{\"policytype_ids\": $targetJson }"
1800 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1801 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1803 if [ $res -ne 0 ]; then
1804 __log_test_fail_body
1813 #########################################################
1814 #### Test case functions Health check
1815 #########################################################
1817 # API Test function: GET /status and V2 GET /status
1818 # args: <response-code>
1819 # (Function for test scripts)
1822 if [ $# -ne 1 ]; then
1823 __print_err "<response-code>" $@
1826 if [ "$PMS_VERSION" == "V2" ]; then
1831 res="$(__do_curl_to_api PA GET $query)"
1832 status=${res:${#res}-3}
1834 if [ $status -ne $1 ]; then
1835 __log_test_fail_status_code $1 $status
1843 #########################################################
1844 #### Test case functions RIC Repository
1845 #########################################################
1847 # API Test function: GET /ric and V2 GET /v2/rics/ric
1848 # args: <reponse-code> <management-element-id> [<ric-id>]
1849 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1850 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1851 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1854 # (Function for test scripts)
1858 if [ "$PMS_VERSION" == "V2" ]; then
1859 if [ $# -lt 3 ]; then
1860 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1864 if [ $2 != "NOME" ]; then
1865 search="?managed_element_id="$2
1867 if [ $3 != "NORIC" ]; then
1868 if [ -z $search ]; then
1871 search=$search"&ric_id="$3
1874 query="/v2/rics/ric"$search
1876 res="$(__do_curl_to_api PA GET $query)"
1877 status=${res:${#res}-3}
1879 if [ $status -ne $1 ]; then
1880 __log_test_fail_status_code $1 $status
1884 if [ $# -gt 3 ]; then
1885 body=${res:0:${#res}-3}
1886 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1887 if [ $res -ne 0 ]; then
1888 __log_test_fail_general "Could not create target ric info json"
1892 targetJson=$(<./tmp/.tmp_rics.json)
1893 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1894 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1895 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1896 if [ $res -ne 0 ]; then
1897 __log_test_fail_body
1902 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1903 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1907 query="/ric?managedElementId="$2
1909 res="$(__do_curl_to_api PA GET $query)"
1910 status=${res:${#res}-3}
1912 if [ $status -ne $1 ]; then
1913 __log_test_fail_status_code $1 $status
1917 if [ $# -eq 3 ]; then
1918 body=${res:0:${#res}-3}
1919 if [ "$body" != "$3" ]; then
1920 __log_test_fail_body
1929 # API test function: GET /rics and V2 GET /v2/rics
1930 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1931 # 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_........."
1932 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1933 # (Function for test scripts)
1937 if [ $# -lt 2 ]; then
1938 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1942 if [ "$PMS_VERSION" == "V2" ]; then
1944 if [ $2 != "NOTYPE" ]; then
1945 query="/v2/rics?policytype_id="$2
1949 if [ $2 != "NOTYPE" ]; then
1950 query="/rics?policyType="$2
1954 res="$(__do_curl_to_api PA GET $query)"
1955 status=${res:${#res}-3}
1957 if [ $status -ne $1 ]; then
1958 __log_test_fail_status_code $1 $status
1962 if [ $# -gt 2 ]; then
1963 body=${res:0:${#res}-3}
1964 if [ "$PMS_VERSION" == "V2" ]; then
1965 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1967 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1969 if [ $res -ne 0 ]; then
1970 __log_test_fail_general "Could not create target ric info json"
1974 targetJson=$(<./tmp/.tmp_rics.json)
1975 if [ "$PMS_VERSION" == "V2" ]; then
1976 targetJson="{\"rics\": $targetJson }"
1978 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1979 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1980 if [ $res -ne 0 ]; then
1981 __log_test_fail_body
1990 ##################################################################
1991 #### API Test case functions Service registry and supervision ####
1992 ##################################################################
1994 # API test function: PUT /service and V2 PUT /service
1995 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1996 # (Function for test scripts)
1999 if [ $# -ne 4 ]; then
2000 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2004 if [ "$PMS_VERSION" == "V2" ]; then
2005 query="/v2/services"
2006 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2009 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2011 file="./tmp/.tmp.json"
2012 echo "$json" > $file
2014 res="$(__do_curl_to_api PA PUT $query $file)"
2015 status=${res:${#res}-3}
2017 if [ $status -ne $1 ]; then
2018 __log_test_fail_status_code $1 $status
2026 # API test function: GET /services and V2 GET /v2/services
2027 #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>]* )]
2028 # (Function for test scripts)
2029 api_get_services() {
2031 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2033 if [ $# -eq 1 ]; then
2035 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2037 elif [ $# -eq 5 ]; then
2039 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2041 if [ $(($argLen%3)) -eq 0 ]; then
2046 if [ $paramError -ne 0 ]; then
2047 __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>]* )]" $@
2051 if [ "$PMS_VERSION" == "V2" ]; then
2052 query="/v2/services"
2054 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2055 query="/v2/services?service_id="$2
2060 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2061 query="/services?name="$2
2064 res="$(__do_curl_to_api PA GET $query)"
2065 status=${res:${#res}-3}
2067 if [ $status -ne $1 ]; then
2068 __log_test_fail_status_code $1 $status
2072 if [ $# -gt 2 ]; then
2073 variableArgCount=$(($#-2))
2074 body=${res:0:${#res}-3}
2078 while [ $cntr -lt $variableArgCount ]; do
2079 servicename=$1; shift;
2082 if [ $cntr -gt 0 ]; then
2083 targetJson=$targetJson","
2085 # timeSinceLastActivitySeconds value cannot be checked since value varies
2086 if [ "$PMS_VERSION" == "V2" ]; then
2087 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2089 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2093 targetJson=$targetJson"]"
2094 if [ "$PMS_VERSION" == "V2" ]; then
2095 targetJson="{\"service_list\": $targetJson }"
2097 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2098 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2099 if [ $res -ne 0 ]; then
2100 __log_test_fail_body
2109 # API test function: GET /services V2 GET /v2/services - (only checking service names)
2110 # args: <response-code> [<service-name>]*"
2111 # (Function for test scripts)
2112 api_get_service_ids() {
2115 if [ $# -lt 1 ]; then
2116 __print_err "<response-code> [<service-name>]*" $@
2120 if [ "$PMS_VERSION" == "V2" ]; then
2121 query="/v2/services"
2125 res="$(__do_curl_to_api PA GET $query)"
2126 status=${res:${#res}-3}
2128 if [ $status -ne $1 ]; then
2129 __log_test_fail_status_code $1 $status
2133 body=${res:0:${#res}-3}
2135 for rapp in ${@:2} ; do
2136 if [ "$targetJson" != "[" ]; then
2137 targetJson=$targetJson","
2139 if [ "$PMS_VERSION" == "V2" ]; then
2140 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2142 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2146 targetJson=$targetJson"]"
2147 if [ "$PMS_VERSION" == "V2" ]; then
2148 targetJson="{\"service_list\": $targetJson }"
2150 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2151 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2153 if [ $res -ne 0 ]; then
2154 __log_test_fail_body
2162 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2163 # args: <response-code> <service-name>
2164 # (Function for test scripts)
2165 api_delete_services() {
2168 if [ $# -ne 2 ]; then
2169 __print_err "<response-code> <service-name>" $@
2172 if [ "$PMS_VERSION" == "V2" ]; then
2173 query="/v2/services/"$2
2175 query="/services?name="$2
2177 res="$(__do_curl_to_api PA DELETE $query)"
2178 status=${res:${#res}-3}
2180 if [ $status -ne $1 ]; then
2181 __log_test_fail_status_code $1 $status
2189 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2190 # args: <response-code> <service-name>
2191 # (Function for test scripts)
2192 api_put_services_keepalive() {
2195 if [ $# -ne 2 ]; then
2196 __print_err "<response-code> <service-name>" $@
2199 if [ "$PMS_VERSION" == "V2" ]; then
2200 query="/v2/services/$2/keepalive"
2202 query="/services/keepalive?name="$2
2205 res="$(__do_curl_to_api PA PUT $query)"
2206 status=${res:${#res}-3}
2208 if [ $status -ne $1 ]; then
2209 __log_test_fail_status_code $1 $status
2217 ##################################################################
2218 #### API Test case functions Configuration ####
2219 ##################################################################
2221 # API Test function: PUT /v2/configuration
2222 # args: <response-code> <config-file>
2223 # (Function for test scripts)
2224 api_put_configuration() {
2227 if [ "$PMS_VERSION" != "V2" ]; then
2228 __log_test_fail_not_supported
2232 if [ $# -ne 2 ]; then
2233 __print_err "<response-code> <config-file>" $@
2236 if [ ! -f $2 ]; then
2237 __log_test_fail_general "Config file "$2", does not exist"
2241 inputJson="{\"config\":"$inputJson"}"
2242 file="./tmp/.config.json"
2243 echo $inputJson > $file
2244 query="/v2/configuration"
2245 res="$(__do_curl_to_api PA PUT $query $file)"
2246 status=${res:${#res}-3}
2248 if [ $status -ne $1 ]; then
2249 __log_test_fail_status_code $1 $status
2257 # API Test function: GET /v2/configuration
2258 # args: <response-code> [<config-file>]
2259 # (Function for test scripts)
2260 api_get_configuration() {
2263 if [ "$PMS_VERSION" != "V2" ]; then
2264 __log_test_fail_not_supported
2268 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2269 __print_err "<response-code> [<config-file>]" $@
2272 if [ ! -f $2 ]; then
2273 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2277 query="/v2/configuration"
2278 res="$(__do_curl_to_api PA GET $query)"
2279 status=${res:${#res}-3}
2281 if [ $status -ne $1 ]; then
2282 __log_test_fail_status_code $1 $status
2286 if [ $# -eq 2 ]; then
2288 body=${res:0:${#res}-3}
2291 targetJson="{\"config\":"$targetJson"}"
2292 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2293 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2295 if [ $res -ne 0 ]; then
2296 __log_test_fail_body
2305 ##########################################
2306 #### Reset types and instances ####
2307 ##########################################
2309 # Admin reset to remove all policies and services
2310 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2311 # NOTE - only works in kubernetes and the pod should not be running
2313 # (Function for test scripts)
2315 pms_kube_pvc_reset() {
2318 pvc_name=$(kubectl get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2319 if [ -z "$pvc_name" ]; then
2320 pvc_name=policymanagementservice-vardata-pvc
2322 echo " Trying to reset pvc: "$pvc_name
2323 __kube_clean_pvc $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $POLICY_AGENT_CONTAINER_MNT_DIR