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 #######################################################
96 ###########################
97 ### Policy Agents functions
98 ###########################
100 # Set http as the protocol to use for all communication to the Policy Agent
102 # (Function for test scripts)
103 use_agent_rest_http() {
104 __agent_set_protocoll "http" $POLICY_AGENT_INTERNAL_PORT $POLICY_AGENT_EXTERNAL_PORT
107 # Set https as the protocol to use for all communication to the Policy Agent
109 # (Function for test scripts)
110 use_agent_rest_https() {
111 __agent_set_protocoll "https" $POLICY_AGENT_INTERNAL_SECURE_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT
114 # All calls to the agent will be directed to the agent dmaap interface over http from now on
116 # (Function for test scripts)
117 use_agent_dmaap_http() {
118 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
119 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
120 PA_ADAPTER_TYPE="MR-HTTP"
124 # All calls to the agent will be directed to the agent dmaap interface over https from now on
126 # (Function for test scripts)
127 use_agent_dmaap_https() {
128 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
129 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
130 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
131 PA_ADAPTER_TYPE="MR-HTTPS"
135 # Setup paths to svc/container for internal and external access
136 # args: <protocol> <internal-port> <external-port>
137 __agent_set_protocoll() {
138 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME protocol setting"$EBOLD
139 echo -e " Using $BOLD http $EBOLD towards $POLICY_AGENT_DISPLAY_NAME"
141 ## Access to Dmaap adapter
143 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME":"$2 # docker access, container->container and script->container via proxy
144 if [ $RUNMODE == "KUBE" ]; then
145 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
148 # PA_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
149 PA_ADAPTER_TYPE="REST"
150 PA_ADAPTER=$PA_SERVICE_PATH
155 # Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
158 #Save first worker node the pod is started on
161 # Export env vars for config files, docker compose and kube resources
162 # args: PROXY|NOPROXY
163 __export_agent_vars() {
165 export POLICY_AGENT_APP_NAME
166 export POLICY_AGENT_APP_NAME_ALIAS
167 export POLICY_AGENT_DISPLAY_NAME
169 export KUBE_NONRTRIC_NAMESPACE
170 export POLICY_AGENT_IMAGE
171 export POLICY_AGENT_INTERNAL_PORT
172 export POLICY_AGENT_INTERNAL_SECURE_PORT
173 export POLICY_AGENT_EXTERNAL_PORT
174 export POLICY_AGENT_EXTERNAL_SECURE_PORT
175 export POLICY_AGENT_CONFIG_MOUNT_PATH
176 export POLICY_AGENT_DATA_MOUNT_PATH
177 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
178 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
179 export POLICY_AGENT_PKG_NAME
181 export CONSUL_INTERNAL_PORT
182 export CONFIG_BINDING_SERVICE
183 export POLICY_AGENT_CONFIG_KEY
184 export DOCKER_SIM_NWNAME
185 export POLICY_AGENT_HOST_MNT_DIR
186 export POLICY_AGENT_CONFIG_FILE
188 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
189 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
190 ##Create a unique path for the pv each time to prevent a previous volume to be reused
191 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
192 export POLICY_AGENT_CONTAINER_MNT_DIR
194 if [ $1 == "PROXY" ]; then
195 export AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
196 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
197 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
198 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
200 echo " Configured with http proxy"
203 export AGENT_HTTP_PROXY_CONFIG_PORT=0
204 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
205 echo " Configured without http proxy"
210 # Start the policy agent
211 # args: (docker) PROXY|NOPROXY <config-file>
212 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
213 # (Function for test scripts)
214 start_policy_agent() {
215 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
217 if [ $RUNMODE == "KUBE" ]; then
219 # Check if app shall be fully managed by the test script
220 __check_included_image "PA"
223 # Check if app shall only be used by the testscipt
224 __check_prestarted_image "PA"
227 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
228 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
229 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
232 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
233 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
234 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
238 if [ $retcode_p -eq 0 ]; then
239 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
240 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
241 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
242 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
245 if [ $retcode_i -eq 0 ]; then
247 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
249 #Check if nonrtric namespace exists, if not create it
250 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
252 __export_agent_vars $1
254 # Create config map for config
255 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
257 output_yaml=$PWD/tmp/pa_cfc.yaml
258 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
260 # Create config map for data
261 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
262 if [ $# -lt 3 ]; then
263 #create empty dummy file
264 echo "{}" > $data_json
268 output_yaml=$PWD/tmp/pa_cfd.yaml
269 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
272 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
273 output_yaml=$PWD/tmp/pa_pv.yaml
274 __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
277 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
278 output_yaml=$PWD/tmp/pa_pvc.yaml
279 __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
282 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
283 output_yaml=$PWD/tmp/pa_svc.yaml
284 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
287 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
288 output_yaml=$PWD/tmp/pa_app.yaml
289 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
293 # 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
294 if [ $retcode_i -eq 0 ]; then
295 __PA_WORKER_NODE=$(kubectl get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
296 if [ -z "$__PA_WORKER_NODE" ]; then
297 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
300 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
303 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
306 __check_included_image 'PA'
307 if [ $? -eq 1 ]; then
308 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
309 echo -e $RED"The Policy Agent will not be started"$ERED
316 cd $POLICY_AGENT_HOST_MNT_DIR
319 if [ "$(ls -A $DIR)" ]; then
320 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
321 rm -rf db/* &> /dev/null
322 if [ $? -ne 0 ]; then
323 echo -e $RED" Cannot remove database files in: $PWD"$ERED
328 echo " No files in mounted dir or dir does not exists"
332 __export_agent_vars $1
334 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
336 envsubst < $2 > $dest_file
338 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
340 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
346 # Stop the policy agent
349 # (Function for test scripts)
350 stop_policy_agent() {
351 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
353 if [ $RUNMODE == "KUBE" ]; then
355 __check_prestarted_image "PA"
356 if [ $? -eq 0 ]; then
357 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
358 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
359 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
362 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
363 echo " Deleting the replica set - a new will be started when the app is started"
364 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
365 if [ $? -ne 0 ]; then
366 echo -e $RED" Could not delete replica set "$RED
371 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
372 if [ $? -ne 0 ]; then
373 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
379 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
384 # Start a previously stopped policy agent
386 # (Function for test scripts)
387 start_stopped_policy_agent() {
388 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
390 if [ $RUNMODE == "KUBE" ]; then
392 __check_prestarted_image "PA"
393 if [ $? -eq 0 ]; then
394 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
395 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
396 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
397 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
401 # Tie the PMS to the same worker node it was initially started on
402 # 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
403 if [ -z "$__PA_WORKER_NODE" ]; then
404 echo -e $RED" No initial worker node found for pod "$RED
408 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
409 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
410 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
411 if [ $? -ne 0 ]; then
412 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
414 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
417 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
418 if [ $? -ne 0 ]; then
419 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
425 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
426 if [ $? -ne 0 ]; then
435 # Load the the appl config for the agent into a config map
436 agent_load_config() {
437 echo -e $BOLD"Agent - load config from "$EBOLD$1
438 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
440 output_yaml=$PWD/tmp/pa_cfd.yaml
441 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
446 # Turn on debug level tracing in the agent
448 # (Function for test scripts)
450 echo -e $BOLD"Setting agent debug logging"$EBOLD
451 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
452 result=$(__do_curl "$curlString")
453 if [ $? -ne 0 ]; then
454 __print_err "could not set debug mode" $@
462 # Turn on trace level tracing in the agent
464 # (Function for test scripts)
466 echo -e $BOLD"Setting agent trace logging"$EBOLD
467 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
468 result=$(__do_curl "$curlString")
469 if [ $? -ne 0 ]; then
470 __print_err "could not set trace mode" $@
478 # Perform curl retries when making direct call to the agent for the specified http response codes
479 # Speace separated list of http response codes
480 # args: [<response-code>]*
481 use_agent_retries() {
482 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
488 # Check the agent logs for WARNINGs and ERRORs
490 # (Function for test scripts)
491 check_policy_agent_logs() {
492 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
495 #########################################################
496 #### Test case functions A1 Policy management service
497 #########################################################
499 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
500 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
501 # args: json:<url> <target-value> [<timeout-in-seconds]
502 # (Function for test scripts)
504 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
505 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
506 if [[ $1 == "json:"* ]]; then
507 if [ "$PMS_VERSION" == "V2" ]; then
508 __var_test "Policy Agent" $PA_SERVICE_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
510 __var_test "Policy Agent" $PA_SERVICE_PATH"/" $1 "=" $2 $3
515 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
519 # API Test function: GET /policies and V2 GET /v2/policy-instances
520 # 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>]*]
521 # 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>]*]
522 # (Function for test scripts)
526 if [ "$PMS_VERSION" == "V2" ]; then
528 variableParams=$(($#-4))
529 if [ $# -lt 4 ]; then
531 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
533 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
537 if [ $paramError -ne 0 ]; then
538 __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>]*]" $@
543 variableParams=$(($#-4))
544 if [ $# -lt 4 ]; then
546 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
548 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
552 if [ $paramError -ne 0 ]; then
553 __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>]*]" $@
559 if [ "$PMS_VERSION" == "V2" ]; then
560 if [ $2 != "NORIC" ]; then
561 queryparams="?ric_id="$2
563 if [ $3 != "NOSERVICE" ]; then
564 if [ -z $queryparams ]; then
565 queryparams="?service_id="$3
567 queryparams=$queryparams"&service_id="$3
570 if [ $4 != "NOTYPE" ]; then
571 if [ -z $queryparams ]; then
572 queryparams="?policytype_id="$4
574 queryparams=$queryparams"&policytype_id="$4
578 query="/v2/policy-instances"$queryparams
579 res="$(__do_curl_to_api PA GET $query)"
580 status=${res:${#res}-3}
582 if [ $status -ne $1 ]; then
583 __log_test_fail_status_code $1 $status
587 if [ $# -gt 4 ]; then
588 body=${res:0:${#res}-3}
589 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
595 for ((i=0; i<$(($#-4)); i=i+7)); do
597 if [ "$targetJson" != "[" ]; then
598 targetJson=$targetJson","
600 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
601 if [ "${arr[$i+3]}" == "EMPTY" ]; then
602 targetJson=$targetJson"\"\","
604 targetJson=$targetJson"\"${arr[$i+3]}\","
606 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
608 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
610 targetJson=$targetJson"\"policy_data\":"$json"}"
614 targetJson=$targetJson"]"
615 targetJson="{\"policies\": $targetJson}"
616 echo "TARGET JSON: $targetJson" >> $HTTPLOG
617 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
619 if [ $res -ne 0 ]; then
625 if [ $2 != "NORIC" ]; then
626 queryparams="?ric="$2
628 if [ $3 != "NOSERVICE" ]; then
629 if [ -z $queryparams ]; then
630 queryparams="?service="$3
632 queryparams=$queryparams"&service="$3
635 if [ $4 != "NOTYPE" ]; then
636 if [ -z $queryparams ]; then
637 queryparams="?type="$4
639 queryparams=$queryparams"&type="$4
643 query="/policies"$queryparams
644 res="$(__do_curl_to_api PA GET $query)"
645 status=${res:${#res}-3}
647 if [ $status -ne $1 ]; then
648 __log_test_fail_status_code $1 $status
652 if [ $# -gt 4 ]; then
653 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
656 body=${res:0:${#res}-3}
660 for ((i=0; i<$(($#-4)); i=i+5)); do
662 if [ "$targetJson" != "[" ]; then
663 targetJson=$targetJson","
665 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
666 if [ "${arr[$i+3]}" == "EMPTY" ]; then
667 targetJson=$targetJson"\"\","
669 targetJson=$targetJson"\"${arr[$i+3]}\","
672 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
674 targetJson=$targetJson"\"json\":"$json"}"
678 targetJson=$targetJson"]"
679 echo "TARGET JSON: $targetJson" >> $HTTPLOG
680 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
682 if [ $res -ne 0 ]; then
695 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
696 # args: <response-code> <policy-id> [<template-file>]
697 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
699 # (Function for test scripts)
704 if [ "$PMS_VERSION" == "V2" ]; then
705 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
706 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
709 query="/v2/policies/$UUID$2"
711 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
712 __print_err "<response-code> <policy-id> [<template-file>] " $@
715 query="/policy?id=$UUID$2"
717 res="$(__do_curl_to_api PA GET $query)"
718 status=${res:${#res}-3}
720 if [ $status -ne $1 ]; then
721 __log_test_fail_status_code $1 $status
725 if [ "$PMS_VERSION" == "V2" ]; then
726 if [ $# -eq 8 ]; then
728 #Create a policy json to compare with
729 body=${res:0:${#res}-3}
731 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
732 if [ $7 != "NOTRANSIENT" ]; then
733 targetJson=$targetJson", \"transient\":$7"
735 if [ $6 != "NOTYPE" ]; then
736 targetJson=$targetJson", \"policytype_id\":\"$6\""
738 targetJson=$targetJson", \"policytype_id\":\"\""
740 if [ $8 != "NOURL" ]; then
741 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
744 data=$(sed 's/XXX/'${2}'/g' $3)
745 targetJson=$targetJson", \"policy_data\":$data"
746 targetJson="{$targetJson}"
748 echo "TARGET JSON: $targetJson" >> $HTTPLOG
749 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
750 if [ $res -ne 0 ]; then
756 if [ $# -eq 3 ]; then
757 #Create a policy json to compare with
758 body=${res:0:${#res}-3}
760 sed 's/XXX/'${2}'/g' $3 > $file
761 targetJson=$(< $file)
762 echo "TARGET JSON: $targetJson" >> $HTTPLOG
763 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
764 if [ $res -ne 0 ]; then
774 # API Test function: PUT /policy and V2 PUT /policies
775 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
776 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
777 # (Function for test scripts)
781 if [ "$PMS_VERSION" == "V2" ]; then
782 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
783 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
787 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
788 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
801 if [ "$PMS_VERSION" == "V2" ]; then
804 if [ $# -eq 9 ]; then
809 if [ $# -eq 8 ]; then
814 while [ $count -lt $max ]; do
815 if [ "$PMS_VERSION" == "V2" ]; then
819 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
820 if [ $trans != "NOTRANSIENT" ]; then
821 inputJson=$inputJson", \"transient\":$trans"
823 if [ $pt != "NOTYPE" ]; then
824 inputJson=$inputJson", \"policytype_id\":\"$pt\""
826 inputJson=$inputJson", \"policytype_id\":\"\""
828 if [ $noti != "NOURL" ]; then
829 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
832 data=$(sed 's/XXX/'${pid}'/g' $temp)
833 inputJson=$inputJson", \"policy_data\":$data"
834 inputJson="{$inputJson}"
835 echo $inputJson > $file
837 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
839 if [ $pt != "NOTYPE" ]; then
840 query=$query"&type=$pt"
843 if [ $trans != NOTRANSIENT ]; then
844 query=$query"&transient=$trans"
848 sed 's/XXX/'${pid}'/g' $temp > $file
850 res="$(__do_curl_to_api PA PUT $query $file)"
851 status=${res:${#res}-3}
852 echo -ne " Executing "$count"("$max")${SAMELINE}"
853 if [ $status -ne $1 ]; then
854 echo " Executed "$count"?("$max")"
855 __log_test_fail_status_code $1 $status
861 echo -ne " Executed "$count"("$max")${SAMELINE}"
869 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
870 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
871 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
872 # (Function for test scripts)
874 api_put_policy_batch() {
877 if [ "$PMS_VERSION" == "V2" ]; then
878 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
879 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
883 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
884 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
896 if [ "$PMS_VERSION" == "V2" ]; then
899 if [ $# -eq 9 ]; then
904 if [ $# -eq 8 ]; then
910 while [ $count -lt $max ]; do
911 if [ "$PMS_VERSION" == "V2" ]; then
914 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
915 if [ $trans != "NOTRANSIENT" ]; then
916 inputJson=$inputJson", \"transient\":$trans"
918 if [ $pt != "NOTYPE" ]; then
919 inputJson=$inputJson", \"policytype_id\":\"$pt\""
921 inputJson=$inputJson", \"policytype_id\":\"\""
923 if [ $noti != "NOURL" ]; then
924 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
927 data=$(sed 's/XXX/'${pid}'/g' $temp)
928 inputJson=$inputJson", \"policy_data\":$data"
929 inputJson="{$inputJson}"
930 echo $inputJson > $file
932 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
934 if [ $pt != "NOTYPE" ]; then
935 query=$query"&type=$pt"
938 if [ $trans != NOTRANSIENT ]; then
939 query=$query"&transient=$trans"
942 sed 's/XXX/'${pid}'/g' $temp > $file
944 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
945 status=${res:${#res}-3}
946 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
948 if [ $status -ne 200 ]; then
949 echo " Requested(batch) "$count"?("$max")"
950 __log_test_fail_status_code 200 $status
953 cid=${res:0:${#res}-3}
957 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
964 res="$(__do_curl_to_api PA RESPONSE $cid)"
965 status=${res:${#res}-3}
966 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
968 if [ $status -ne $1 ]; then
969 echo " Accepted(batch) "$count"?("$max")"
970 __log_test_fail_status_code $1 $status
975 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
984 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
985 # 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>
986 # 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>
987 # (Function for test scripts)
988 api_put_policy_parallel() {
991 if [ "$PMS_VERSION" == "V2" ]; then
992 if [ $# -ne 11 ]; then
993 __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>" $@
997 if [ $# -ne 10 ]; then
998 __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>" $@
1002 resp_code=$1; shift;
1008 transient=$1; shift;
1009 if [ "$PMS_VERSION" == "V2" ]; then
1018 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1019 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1020 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1021 echo " Info - will execute over agent REST"
1023 if [ "$PMS_VERSION" == "V2" ]; then
1024 if [ $serv == "NOSERVICE" ]; then
1027 query="$PMS_API_PREFIX/v2/policies"
1029 if [ $serv == "NOSERVICE" ]; then
1032 query="/policy?service=$serv"
1034 if [ $type != "NOTYPE" ]; then
1035 query=$query"&type=$type"
1038 if [ $transient != NOTRANSIENT ]; then
1039 query=$query"&transient=$transient"
1043 urlbase=${PA_ADAPTER}${query}
1046 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1047 httpproxy=$KUBE_PROXY_PATH
1050 for ((i=1; i<=$pids; i++))
1053 if [ -z "$uuid" ]; then
1056 echo "" > "./tmp/.pid${i}.res.txt"
1057 if [ "$PMS_VERSION" == "V2" ]; then
1058 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1060 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1063 done | xargs -n 1 -I{} -P $pids bash -c '{
1065 echo " Parallel process $arg started"
1066 tmp=$(< "./tmp/.pid${arg}.txt")
1067 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1070 for ((i=1; i<=$pids; i++))
1072 file="./tmp/.pid${i}.res.txt"
1074 if [ -z "$tmp" ]; then
1075 echo " Process $i : unknown result (result file empty"
1079 if [ $res == "0" ]; then
1080 echo " Process $i : OK - "${tmp:1}
1082 echo " Process $i : failed - "${tmp:1}
1087 if [ -z $msg ]; then
1088 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1092 __log_test_fail_general "One of more processes failed to execute"
1096 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1097 # args: <response-code> <policy-id> [count]
1098 # (Function for test scripts)
1099 api_delete_policy() {
1102 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1103 __print_err "<response-code> <policy-id> [count]" $@
1110 if [ $# -eq 3 ]; then
1116 while [ $count -lt $max ]; do
1117 if [ "$PMS_VERSION" == "V2" ]; then
1118 query="/v2/policies/"$UUID$pid
1120 query="/policy?id="$UUID$pid
1122 res="$(__do_curl_to_api PA DELETE $query)"
1123 status=${res:${#res}-3}
1124 echo -ne " Executing "$count"("$max")${SAMELINE}"
1126 if [ $status -ne $1 ]; then
1127 echo " Executed "$count"?("$max")"
1128 __log_test_fail_status_code $1 $status
1133 echo -ne " Executed "$count"("$max")${SAMELINE}"
1141 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1142 # args: <response-code> <policy-id> [count]
1143 # (Function for test scripts)
1144 api_delete_policy_batch() {
1147 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1148 __print_err "<response-code> <policy-id> [count]" $@
1155 if [ $# -eq 3 ]; then
1161 while [ $count -lt $max ]; do
1162 if [ "$PMS_VERSION" == "V2" ]; then
1163 query="/v2/policies/"$UUID$pid
1165 query="/policy?id="$UUID$pid
1167 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
1168 status=${res:${#res}-3}
1169 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1171 if [ $status -ne 200 ]; then
1172 echo " Requested(batch) "$count"?("$max")"
1173 __log_test_fail_status_code 200 $status
1176 cid=${res:0:${#res}-3}
1180 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1188 res="$(__do_curl_to_api PA RESPONSE $cid)"
1189 status=${res:${#res}-3}
1190 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1192 if [ $status -ne $1 ]; then
1193 echo " Deleted(batch) "$count"?("$max")"
1194 __log_test_fail_status_code $1 $status
1199 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1208 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1209 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1210 # (Function for test scripts)
1211 api_delete_policy_parallel() {
1214 if [ $# -ne 5 ]; then
1215 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1218 resp_code=$1; shift;
1224 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1225 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1226 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1227 echo " Info - will execute over agent REST"
1230 if [ "$PMS_VERSION" == "V2" ]; then
1231 query="$PMS_API_PREFIX/v2/policies/"
1236 urlbase=${PA_ADAPTER}${query}
1239 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1240 httpproxy=$KUBE_PROXY_PATH
1243 for ((i=1; i<=$pids; i++))
1246 if [ -z "$uuid" ]; then
1249 echo "" > "./tmp/.pid${i}.del.res.txt"
1250 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1252 done | xargs -n 1 -I{} -P $pids bash -c '{
1254 echo " Parallel process $arg started"
1255 tmp=$(< "./tmp/.pid${arg}.del.txt")
1256 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1259 for ((i=1; i<=$pids; i++))
1261 file="./tmp/.pid${i}.del.res.txt"
1263 if [ -z "$tmp" ]; then
1264 echo " Process $i : unknown result (result file empty"
1268 if [ $res == "0" ]; then
1269 echo " Process $i : OK - "${tmp:1}
1271 echo " Process $i : failed - "${tmp:1}
1276 if [ -z $msg ]; then
1277 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1281 __log_test_fail_general "One of more processes failed to execute"
1285 # API Test function: GET /policy_ids and V2 GET /v2/policies
1286 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1287 # (Function for test scripts)
1288 api_get_policy_ids() {
1291 if [ $# -lt 4 ]; then
1292 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1298 if [ "$PMS_VERSION" == "V2" ]; then
1299 if [ $2 != "NORIC" ]; then
1300 queryparams="?ric_id="$2
1303 if [ $3 != "NOSERVICE" ]; then
1304 if [ -z $queryparams ]; then
1305 queryparams="?service_id="$3
1307 queryparams=$queryparams"&service_id="$3
1310 if [ $4 != "NOTYPE" ]; then
1311 if [ -z $queryparams ]; then
1312 queryparams="?policytype_id="$4
1314 queryparams=$queryparams"&policytype_id="$4
1318 query="/v2/policies"$queryparams
1320 if [ $2 != "NORIC" ]; then
1321 queryparams="?ric="$2
1324 if [ $3 != "NOSERVICE" ]; then
1325 if [ -z $queryparams ]; then
1326 queryparams="?service="$3
1328 queryparams=$queryparams"&service="$3
1331 if [ $4 != "NOTYPE" ]; then
1332 if [ -z $queryparams ]; then
1333 queryparams="?type="$4
1335 queryparams=$queryparams"&type="$4
1339 query="/policy_ids"$queryparams
1342 res="$(__do_curl_to_api PA GET $query)"
1343 status=${res:${#res}-3}
1345 if [ $status -ne $1 ]; then
1346 __log_test_fail_status_code $1 $status
1350 if [ $# -gt 4 ]; then
1351 body=${res:0:${#res}-3}
1354 for pid in ${@:5} ; do
1355 if [ "$targetJson" != "[" ]; then
1356 targetJson=$targetJson","
1358 if [ $pid != "NOID" ]; then
1359 targetJson=$targetJson"\"$UUID$pid\""
1363 targetJson=$targetJson"]"
1364 if [ "$PMS_VERSION" == "V2" ]; then
1365 targetJson="{\"policy_ids\": $targetJson}"
1367 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1368 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1370 if [ $res -ne 0 ]; then
1371 __log_test_fail_body
1380 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1381 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1382 # (Function for test scripts)
1383 api_get_policy_type() {
1386 if [ "$PMS_VERSION" != "V2" ]; then
1387 __log_test_fail_not_supported
1391 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1392 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1395 query="/v2/policy-types/$2"
1397 res="$(__do_curl_to_api PA GET $query)"
1398 status=${res:${#res}-3}
1400 if [ $status -ne $1 ]; then
1401 __log_test_fail_status_code $1 $status
1405 if [ $# -eq 3 ]; then
1407 body=${res:0:${#res}-3}
1410 targetJson="{\"policy_schema\":$targetJson}"
1411 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1412 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1414 if [ $res -ne 0 ]; then
1415 __log_test_fail_body
1424 # API Test function: GET /policy_schema
1425 # args: <response-code> <policy-type-id> [<schema-file>]
1426 # (Function for test scripts)
1427 api_get_policy_schema() {
1430 if [ "$PMS_VERSION" == "V2" ]; then
1431 __log_test_fail_not_supported
1435 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1436 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1439 query="/policy_schema?id=$2"
1440 res="$(__do_curl_to_api PA GET $query)"
1441 status=${res:${#res}-3}
1443 if [ $status -ne $1 ]; then
1444 __log_test_fail_status_code $1 $status
1448 if [ $# -eq 3 ]; then
1450 body=${res:0:${#res}-3}
1454 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1455 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1457 if [ $res -ne 0 ]; then
1458 __log_test_fail_body
1467 # API Test function: GET /policy_schemas
1468 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1469 # args(V2): <response-code>
1470 # (Function for test scripts)
1471 api_get_policy_schemas() {
1474 if [ "$PMS_VERSION" == "V2" ]; then
1475 if [ $# -ne 1 ]; then
1476 __print_err "<response-code>" $@
1480 if [ $# -lt 2 ]; then
1481 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1485 if [ "$PMS_VERSION" == "V2" ]; then
1486 query="/v2/policy-schemas"
1488 query="/policy_schemas"
1489 if [ $2 != "NORIC" ]; then
1490 query=$query"?ric="$2
1494 res="$(__do_curl_to_api PA GET $query)"
1495 status=${res:${#res}-3}
1497 if [ $status -ne $1 ]; then
1498 __log_test_fail_status_code $1 $status
1502 if [ $# -gt 2 ]; then
1503 body=${res:0:${#res}-3}
1506 for file in ${@:3} ; do
1507 if [ "$targetJson" != "[" ]; then
1508 targetJson=$targetJson","
1510 if [ $file == "NOFILE" ]; then
1511 targetJson=$targetJson"{}"
1513 targetJson=$targetJson$(< $file)
1517 targetJson=$targetJson"]"
1518 if [ "$PMS_VERSION" == "V2" ]; then
1519 targetJson="{\"policy_schemas\": $targetJson }"
1521 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1522 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1524 if [ $res -ne 0 ]; then
1525 __log_test_fail_body
1534 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1535 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1536 # (Function for test scripts)
1537 api_get_policy_status() {
1540 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1541 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1547 if [ $3 == "STD" ]; then
1548 targetJson="{\"enforceStatus\":\"$4\""
1549 if [ $# -eq 5 ]; then
1550 targetJson=$targetJson",\"reason\":\"$5\""
1552 targetJson=$targetJson"}"
1553 elif [ $3 == "STD2" ]; then
1554 if [ $4 == "EMPTY" ]; then
1555 targetJson="{\"enforceStatus\":\"\""
1557 targetJson="{\"enforceStatus\":\"$4\""
1559 if [ $# -eq 5 ]; then
1560 if [ $5 == "EMPTY" ]; then
1561 targetJson=$targetJson",\"enforceReason\":\"\""
1563 targetJson=$targetJson",\"enforceReason\":\"$5\""
1566 targetJson=$targetJson"}"
1567 elif [ $3 == "OSC" ]; then
1568 targetJson="{\"instance_status\":\"$4\""
1569 if [ $# -eq 5 ]; then
1570 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1572 targetJson=$targetJson",\"created_at\":\"????\"}"
1574 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1578 if [ "$PMS_VERSION" == "V2" ]; then
1579 query="/v2/policies/$UUID$2/status"
1580 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1582 query="/policy_status?id="$UUID$2
1585 res="$(__do_curl_to_api PA GET $query)"
1586 status=${res:${#res}-3}
1588 if [ $status -ne $1 ]; then
1589 __log_test_fail_status_code $1 $status
1593 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1594 body=${res:0:${#res}-3}
1595 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1597 if [ $res -ne 0 ]; then
1598 __log_test_fail_body
1606 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1607 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1608 # (Function for test scripts)
1609 api_get_policy_types() {
1612 if [ $# -lt 1 ]; then
1613 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1617 if [ "$PMS_VERSION" == "V2" ]; then
1618 if [ $# -eq 1 ]; then
1619 query="/v2/policy-types"
1620 elif [ $2 == "NORIC" ]; then
1621 query="/v2/policy-types"
1623 query="/v2/policy-types?ric_id=$2"
1626 if [ $# -eq 1 ]; then
1627 query="/policy_types"
1628 elif [ $2 == "NORIC" ]; then
1629 query="/policy_types"
1631 query="/policy_types?ric=$2"
1635 res="$(__do_curl_to_api PA GET $query)"
1636 status=${res:${#res}-3}
1638 if [ $status -ne $1 ]; then
1639 __log_test_fail_status_code $1 $status
1643 if [ $# -gt 2 ]; then
1644 body=${res:0:${#res}-3}
1647 for pid in ${@:3} ; do
1648 if [ "$targetJson" != "[" ]; then
1649 targetJson=$targetJson","
1651 if [ $pid == "EMPTY" ]; then
1654 targetJson=$targetJson"\"$pid\""
1657 targetJson=$targetJson"]"
1658 if [ "$PMS_VERSION" == "V2" ]; then
1659 targetJson="{\"policytype_ids\": $targetJson }"
1661 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1662 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1664 if [ $res -ne 0 ]; then
1665 __log_test_fail_body
1674 #########################################################
1675 #### Test case functions Health check
1676 #########################################################
1678 # API Test function: GET /status and V2 GET /status
1679 # args: <response-code>
1680 # (Function for test scripts)
1683 if [ $# -ne 1 ]; then
1684 __print_err "<response-code>" $@
1687 if [ "$PMS_VERSION" == "V2" ]; then
1692 res="$(__do_curl_to_api PA GET $query)"
1693 status=${res:${#res}-3}
1695 if [ $status -ne $1 ]; then
1696 __log_test_fail_status_code $1 $status
1704 #########################################################
1705 #### Test case functions RIC Repository
1706 #########################################################
1708 # API Test function: GET /ric and V2 GET /v2/rics/ric
1709 # args: <reponse-code> <management-element-id> [<ric-id>]
1710 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1711 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1712 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1715 # (Function for test scripts)
1719 if [ "$PMS_VERSION" == "V2" ]; then
1720 if [ $# -lt 3 ]; then
1721 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1725 if [ $2 != "NOME" ]; then
1726 search="?managed_element_id="$2
1728 if [ $3 != "NORIC" ]; then
1729 if [ -z $search ]; then
1732 search=$search"&ric_id="$3
1735 query="/v2/rics/ric"$search
1737 res="$(__do_curl_to_api PA GET $query)"
1738 status=${res:${#res}-3}
1740 if [ $status -ne $1 ]; then
1741 __log_test_fail_status_code $1 $status
1745 if [ $# -gt 3 ]; then
1746 body=${res:0:${#res}-3}
1747 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1748 if [ $res -ne 0 ]; then
1749 __log_test_fail_general "Could not create target ric info json"
1753 targetJson=$(<./tmp/.tmp_rics.json)
1754 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1755 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1756 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1757 if [ $res -ne 0 ]; then
1758 __log_test_fail_body
1763 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1764 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1768 query="/ric?managedElementId="$2
1770 res="$(__do_curl_to_api PA GET $query)"
1771 status=${res:${#res}-3}
1773 if [ $status -ne $1 ]; then
1774 __log_test_fail_status_code $1 $status
1778 if [ $# -eq 3 ]; then
1779 body=${res:0:${#res}-3}
1780 if [ "$body" != "$3" ]; then
1781 __log_test_fail_body
1790 # API test function: GET /rics and V2 GET /v2/rics
1791 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1792 # 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_........."
1793 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1794 # (Function for test scripts)
1798 if [ $# -lt 2 ]; then
1799 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1803 if [ "$PMS_VERSION" == "V2" ]; then
1805 if [ $2 != "NOTYPE" ]; then
1806 query="/v2/rics?policytype_id="$2
1810 if [ $2 != "NOTYPE" ]; then
1811 query="/rics?policyType="$2
1815 res="$(__do_curl_to_api PA GET $query)"
1816 status=${res:${#res}-3}
1818 if [ $status -ne $1 ]; then
1819 __log_test_fail_status_code $1 $status
1823 if [ $# -gt 2 ]; then
1824 body=${res:0:${#res}-3}
1825 if [ "$PMS_VERSION" == "V2" ]; then
1826 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1828 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1830 if [ $res -ne 0 ]; then
1831 __log_test_fail_general "Could not create target ric info json"
1835 targetJson=$(<./tmp/.tmp_rics.json)
1836 if [ "$PMS_VERSION" == "V2" ]; then
1837 targetJson="{\"rics\": $targetJson }"
1839 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1840 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1841 if [ $res -ne 0 ]; then
1842 __log_test_fail_body
1851 ##################################################################
1852 #### API Test case functions Service registry and supervision ####
1853 ##################################################################
1855 # API test function: PUT /service and V2 PUT /service
1856 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1857 # (Function for test scripts)
1860 if [ $# -ne 4 ]; then
1861 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1865 if [ "$PMS_VERSION" == "V2" ]; then
1866 query="/v2/services"
1867 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1870 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1872 file="./tmp/.tmp.json"
1873 echo "$json" > $file
1875 res="$(__do_curl_to_api PA PUT $query $file)"
1876 status=${res:${#res}-3}
1878 if [ $status -ne $1 ]; then
1879 __log_test_fail_status_code $1 $status
1887 # API test function: GET /services and V2 GET /v2/services
1888 #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>]* )]
1889 # (Function for test scripts)
1890 api_get_services() {
1892 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1894 if [ $# -eq 1 ]; then
1896 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1898 elif [ $# -eq 5 ]; then
1900 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1902 if [ $(($argLen%3)) -eq 0 ]; then
1907 if [ $paramError -ne 0 ]; then
1908 __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>]* )]" $@
1912 if [ "$PMS_VERSION" == "V2" ]; then
1913 query="/v2/services"
1915 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1916 query="/v2/services?service_id="$2
1921 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1922 query="/services?name="$2
1925 res="$(__do_curl_to_api PA GET $query)"
1926 status=${res:${#res}-3}
1928 if [ $status -ne $1 ]; then
1929 __log_test_fail_status_code $1 $status
1933 if [ $# -gt 2 ]; then
1934 variableArgCount=$(($#-2))
1935 body=${res:0:${#res}-3}
1939 while [ $cntr -lt $variableArgCount ]; do
1940 servicename=$1; shift;
1943 if [ $cntr -gt 0 ]; then
1944 targetJson=$targetJson","
1946 # timeSinceLastActivitySeconds value cannot be checked since value varies
1947 if [ "$PMS_VERSION" == "V2" ]; then
1948 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1950 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1954 targetJson=$targetJson"]"
1955 if [ "$PMS_VERSION" == "V2" ]; then
1956 targetJson="{\"service_list\": $targetJson }"
1958 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1959 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1960 if [ $res -ne 0 ]; then
1961 __log_test_fail_body
1970 # API test function: GET /services V2 GET /v2/services - (only checking service names)
1971 # args: <response-code> [<service-name>]*"
1972 # (Function for test scripts)
1973 api_get_service_ids() {
1976 if [ $# -lt 1 ]; then
1977 __print_err "<response-code> [<service-name>]*" $@
1981 if [ "$PMS_VERSION" == "V2" ]; then
1982 query="/v2/services"
1986 res="$(__do_curl_to_api PA GET $query)"
1987 status=${res:${#res}-3}
1989 if [ $status -ne $1 ]; then
1990 __log_test_fail_status_code $1 $status
1994 body=${res:0:${#res}-3}
1996 for rapp in ${@:2} ; do
1997 if [ "$targetJson" != "[" ]; then
1998 targetJson=$targetJson","
2000 if [ "$PMS_VERSION" == "V2" ]; then
2001 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2003 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2007 targetJson=$targetJson"]"
2008 if [ "$PMS_VERSION" == "V2" ]; then
2009 targetJson="{\"service_list\": $targetJson }"
2011 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2012 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2014 if [ $res -ne 0 ]; then
2015 __log_test_fail_body
2023 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2024 # args: <response-code> <service-name>
2025 # (Function for test scripts)
2026 api_delete_services() {
2029 if [ $# -ne 2 ]; then
2030 __print_err "<response-code> <service-name>" $@
2033 if [ "$PMS_VERSION" == "V2" ]; then
2034 query="/v2/services/"$2
2036 query="/services?name="$2
2038 res="$(__do_curl_to_api PA DELETE $query)"
2039 status=${res:${#res}-3}
2041 if [ $status -ne $1 ]; then
2042 __log_test_fail_status_code $1 $status
2050 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2051 # args: <response-code> <service-name>
2052 # (Function for test scripts)
2053 api_put_services_keepalive() {
2056 if [ $# -ne 2 ]; then
2057 __print_err "<response-code> <service-name>" $@
2060 if [ "$PMS_VERSION" == "V2" ]; then
2061 query="/v2/services/$2/keepalive"
2063 query="/services/keepalive?name="$2
2066 res="$(__do_curl_to_api PA PUT $query)"
2067 status=${res:${#res}-3}
2069 if [ $status -ne $1 ]; then
2070 __log_test_fail_status_code $1 $status
2078 ##################################################################
2079 #### API Test case functions Configuration ####
2080 ##################################################################
2082 # API Test function: PUT /v2/configuration
2083 # args: <response-code> <config-file>
2084 # (Function for test scripts)
2085 api_put_configuration() {
2088 if [ "$PMS_VERSION" != "V2" ]; then
2089 __log_test_fail_not_supported
2093 if [ $# -ne 2 ]; then
2094 __print_err "<response-code> <config-file>" $@
2097 if [ ! -f $2 ]; then
2098 __log_test_fail_general "Config file "$2", does not exist"
2102 inputJson="{\"config\":"$inputJson"}"
2103 file="./tmp/.config.json"
2104 echo $inputJson > $file
2105 query="/v2/configuration"
2106 res="$(__do_curl_to_api PA PUT $query $file)"
2107 status=${res:${#res}-3}
2109 if [ $status -ne $1 ]; then
2110 __log_test_fail_status_code $1 $status
2118 # API Test function: GET /v2/configuration
2119 # args: <response-code> [<config-file>]
2120 # (Function for test scripts)
2121 api_get_configuration() {
2124 if [ "$PMS_VERSION" != "V2" ]; then
2125 __log_test_fail_not_supported
2129 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2130 __print_err "<response-code> [<config-file>]" $@
2133 if [ ! -f $2 ]; then
2134 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2138 query="/v2/configuration"
2139 res="$(__do_curl_to_api PA GET $query)"
2140 status=${res:${#res}-3}
2142 if [ $status -ne $1 ]; then
2143 __log_test_fail_status_code $1 $status
2147 if [ $# -eq 2 ]; then
2149 body=${res:0:${#res}-3}
2152 targetJson="{\"config\":"$targetJson"}"
2153 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2154 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2156 if [ $res -ne 0 ]; then
2157 __log_test_fail_body
2166 ##########################################
2167 #### Reset types and instances ####
2168 ##########################################
2170 # Admin reset to remove all policies and services
2171 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2172 # NOTE - only works in kubernetes and the pod should not be running
2174 # (Function for test scripts)
2176 pms_kube_pvc_reset() {
2179 pvc_name=$(kubectl get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2180 if [ -z "$pvc_name" ]; then
2181 pvc_name=policymanagementservice-vardata-pvc
2183 echo " Trying to reset pvc: "$pvc_name
2184 __kube_clean_pvc $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $POLICY_AGENT_CONTAINER_MNT_DIR