3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020 Nordix Foundation. All rights reserved.
5 # ========================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=================================================
20 # This is a script that contains management and test functions for Policy Agent
22 ################ Test engine functions ################
24 # Create the image var used during the test
25 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
26 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
28 __check_and_create_image_var PA "POLICY_AGENT_IMAGE" "POLICY_AGENT_IMAGE_BASE" "POLICY_AGENT_IMAGE_TAG" $1 "$POLICY_AGENT_DISPLAY_NAME"
31 # Pull image from remote repo or use locally built image
32 # arg: <pull-policy-override> <pull-policy-original>
33 # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
34 # <pull-policy-original> Shall be used for images that does not allow overriding
35 # Both var may contain: 'remote', 'remote-remove' or 'local'
37 __check_and_pull_image $1 "$POLICY_AGENT_DISPLAY_NAME" $POLICY_AGENT_APP_NAME POLICY_AGENT_IMAGE
40 # Build image (only for simulator or interfaces stubs owned by the test environment)
41 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
42 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
44 echo -e $RED" Image for app PA shall never be built"$ERED
47 # Generate a string for each included image using the app display name and a docker images format string
48 # If a custom image repo is used then also the source image from the local repo is listed
49 # arg: <docker-images-format-string> <file-to-append>
51 echo -e "$POLICY_AGENT_DISPLAY_NAME\t$(docker images --format $1 $POLICY_AGENT_IMAGE)" >> $2
52 if [ ! -z "$POLICY_AGENT_IMAGE_SOURCE" ]; then
53 echo -e "-- source image --\t$(docker images --format $1 $POLICY_AGENT_IMAGE_SOURCE)" >> $2
57 # Scale kubernetes resources to zero
58 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
59 # This function is called for apps fully managed by the test script
60 __PA_kube_scale_zero() {
61 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
64 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
65 # This function is called for prestarted apps not managed by the test script.
66 __PA_kube_scale_zero_and_wait() {
67 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-policymanagementservice
70 # Delete all kube resouces for the app
71 # This function is called for apps managed by the test script.
72 __PA_kube_delete_all() {
73 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
77 # This function is called for apps managed by the test script.
78 # args: <log-dir> <file-prexix>
79 __PA_store_docker_logs() {
80 if [ $RUNMODE == "KUBE" ]; then
81 kubectl logs -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_policy-agent.log 2>&1
83 docker logs $POLICY_AGENT_APP_NAME > $1$2_policy-agent.log 2>&1
87 # Initial setup of protocol, host and ports
88 # This function is called for apps managed by the test script.
90 __PA_initial_setup() {
94 # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
95 # For docker, the namespace shall be excluded
96 # This function is called for apps managed by the test script as well as for prestarted apps.
98 __PA_statisics_setup() {
99 if [ $RUNMODE == "KUBE" ]; then
100 echo "PA $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
102 echo "PA $POLICY_AGENT_APP_NAME"
107 #######################################################
109 ###########################
110 ### Policy Agents functions
111 ###########################
113 # Set http as the protocol to use for all communication to the Policy Agent
115 # (Function for test scripts)
116 use_agent_rest_http() {
117 __agent_set_protocoll "http" $POLICY_AGENT_INTERNAL_PORT $POLICY_AGENT_EXTERNAL_PORT
120 # Set https as the protocol to use for all communication to the Policy Agent
122 # (Function for test scripts)
123 use_agent_rest_https() {
124 __agent_set_protocoll "https" $POLICY_AGENT_INTERNAL_SECURE_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT
127 # All calls to the agent will be directed to the agent dmaap interface over http from now on
129 # (Function for test scripts)
130 use_agent_dmaap_http() {
131 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
132 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
133 PA_ADAPTER_TYPE="MR-HTTP"
137 # All calls to the agent will be directed to the agent dmaap interface over https from now on
139 # (Function for test scripts)
140 use_agent_dmaap_https() {
141 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
142 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
143 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
144 PA_ADAPTER_TYPE="MR-HTTPS"
148 # Setup paths to svc/container for internal and external access
149 # args: <protocol> <internal-port> <external-port>
150 __agent_set_protocoll() {
151 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME protocol setting"$EBOLD
152 echo -e " Using $BOLD http $EBOLD towards $POLICY_AGENT_DISPLAY_NAME"
154 ## Access to Dmaap adapter
156 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME":"$2 # docker access, container->container and script->container via proxy
157 if [ $RUNMODE == "KUBE" ]; then
158 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
161 # PA_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
162 PA_ADAPTER_TYPE="REST"
163 PA_ADAPTER=$PA_SERVICE_PATH
168 # Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
171 #Save first worker node the pod is started on
174 # Export env vars for config files, docker compose and kube resources
175 # args: PROXY|NOPROXY
176 __export_agent_vars() {
178 export POLICY_AGENT_APP_NAME
179 export POLICY_AGENT_APP_NAME_ALIAS
180 export POLICY_AGENT_DISPLAY_NAME
182 export KUBE_NONRTRIC_NAMESPACE
183 export POLICY_AGENT_IMAGE
184 export POLICY_AGENT_INTERNAL_PORT
185 export POLICY_AGENT_INTERNAL_SECURE_PORT
186 export POLICY_AGENT_EXTERNAL_PORT
187 export POLICY_AGENT_EXTERNAL_SECURE_PORT
188 export POLICY_AGENT_CONFIG_MOUNT_PATH
189 export POLICY_AGENT_DATA_MOUNT_PATH
190 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
191 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
192 export POLICY_AGENT_PKG_NAME
194 export CONSUL_INTERNAL_PORT
195 export CONFIG_BINDING_SERVICE
196 export POLICY_AGENT_CONFIG_KEY
197 export DOCKER_SIM_NWNAME
198 export POLICY_AGENT_HOST_MNT_DIR
199 export POLICY_AGENT_CONFIG_FILE
201 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
202 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
203 ##Create a unique path for the pv each time to prevent a previous volume to be reused
204 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
205 export POLICY_AGENT_CONTAINER_MNT_DIR
207 if [ $1 == "PROXY" ]; then
208 export AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
209 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
210 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
211 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
213 echo " Configured with http proxy"
216 export AGENT_HTTP_PROXY_CONFIG_PORT=0
217 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
218 echo " Configured without http proxy"
223 # Start the policy agent
224 # args: (docker) PROXY|NOPROXY <config-file>
225 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
226 # (Function for test scripts)
227 start_policy_agent() {
228 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
230 if [ $RUNMODE == "KUBE" ]; then
232 # Check if app shall be fully managed by the test script
233 __check_included_image "PA"
236 # Check if app shall only be used by the testscipt
237 __check_prestarted_image "PA"
240 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
241 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
242 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
245 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
246 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
247 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
251 if [ $retcode_p -eq 0 ]; then
252 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
253 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
254 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
255 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
258 if [ $retcode_i -eq 0 ]; then
260 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
262 #Check if nonrtric namespace exists, if not create it
263 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
265 __export_agent_vars $1
267 # Create config map for config
268 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
270 output_yaml=$PWD/tmp/pa_cfc.yaml
271 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
273 # Create config map for data
274 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
275 if [ $# -lt 3 ]; then
276 #create empty dummy file
277 echo "{}" > $data_json
281 output_yaml=$PWD/tmp/pa_cfd.yaml
282 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
285 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
286 output_yaml=$PWD/tmp/pa_pv.yaml
287 __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
290 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
291 output_yaml=$PWD/tmp/pa_pvc.yaml
292 __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
295 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
296 output_yaml=$PWD/tmp/pa_svc.yaml
297 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
300 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
301 output_yaml=$PWD/tmp/pa_app.yaml
302 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
306 # Keep the initial worker node in case the pod need to be "restarted" - must be made to the same node due to a volume mounted on the host
307 if [ $retcode_i -eq 0 ]; then
308 __PA_WORKER_NODE=$(kubectl get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
309 if [ -z "$__PA_WORKER_NODE" ]; then
310 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
313 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
316 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
319 __check_included_image 'PA'
320 if [ $? -eq 1 ]; then
321 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
322 echo -e $RED"The Policy Agent will not be started"$ERED
329 cd $POLICY_AGENT_HOST_MNT_DIR
332 if [ "$(ls -A $DIR)" ]; then
333 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
334 rm -rf db/* &> /dev/null
335 if [ $? -ne 0 ]; then
336 echo -e $RED" Cannot remove database files in: $PWD"$ERED
341 echo " No files in mounted dir or dir does not exists"
345 __export_agent_vars $1
347 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
349 envsubst < $2 > $dest_file
351 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
353 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
359 # Stop the policy agent
362 # (Function for test scripts)
363 stop_policy_agent() {
364 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
366 if [ $RUNMODE == "KUBE" ]; then
368 __check_prestarted_image "PA"
369 if [ $? -eq 0 ]; then
370 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
371 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
372 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
375 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
376 echo " Deleting the replica set - a new will be started when the app is started"
377 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
378 if [ $? -ne 0 ]; then
379 echo -e $RED" Could not delete replica set "$RED
384 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
385 if [ $? -ne 0 ]; then
386 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
392 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
397 # Start a previously stopped policy agent
399 # (Function for test scripts)
400 start_stopped_policy_agent() {
401 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
403 if [ $RUNMODE == "KUBE" ]; then
405 __check_prestarted_image "PA"
406 if [ $? -eq 0 ]; then
407 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
408 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
409 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
410 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
414 # Tie the PMS to the same worker node it was initially started on
415 # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume
416 if [ -z "$__PA_WORKER_NODE" ]; then
417 echo -e $RED" No initial worker node found for pod "$RED
421 echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__PA_WORKER_NODE to deployment for $POLICY_AGENT_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD
422 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
423 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
424 if [ $? -ne 0 ]; then
425 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
427 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
430 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
431 if [ $? -ne 0 ]; then
432 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
438 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
439 if [ $? -ne 0 ]; then
448 # Load the the appl config for the agent into a config map
449 agent_load_config() {
450 echo -e $BOLD"Agent - load config from "$EBOLD$1
451 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
453 output_yaml=$PWD/tmp/pa_cfd.yaml
454 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
459 # Turn on debug level tracing in the agent
461 # (Function for test scripts)
463 echo -e $BOLD"Setting agent debug logging"$EBOLD
464 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
465 result=$(__do_curl "$curlString")
466 if [ $? -ne 0 ]; then
467 __print_err "could not set debug mode" $@
475 # Turn on trace level tracing in the agent
477 # (Function for test scripts)
479 echo -e $BOLD"Setting agent trace logging"$EBOLD
480 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
481 result=$(__do_curl "$curlString")
482 if [ $? -ne 0 ]; then
483 __print_err "could not set trace mode" $@
491 # Perform curl retries when making direct call to the agent for the specified http response codes
492 # Speace separated list of http response codes
493 # args: [<response-code>]*
494 use_agent_retries() {
495 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
501 # Check the agent logs for WARNINGs and ERRORs
503 # (Function for test scripts)
504 check_policy_agent_logs() {
505 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
508 #########################################################
509 #### Test case functions A1 Policy management service
510 #########################################################
512 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
513 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
514 # args: json:<url> <target-value> [<timeout-in-seconds]
515 # (Function for test scripts)
517 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
518 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
519 if [[ $1 == "json:"* ]]; then
520 if [ "$PMS_VERSION" == "V2" ]; then
521 __var_test "Policy Agent" $PA_SERVICE_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
523 __var_test "Policy Agent" $PA_SERVICE_PATH"/" $1 "=" $2 $3
528 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
532 # API Test function: GET /policies and V2 GET /v2/policy-instances
533 # 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>]*]
534 # 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>]*]
535 # (Function for test scripts)
539 if [ "$PMS_VERSION" == "V2" ]; then
541 variableParams=$(($#-4))
542 if [ $# -lt 4 ]; then
544 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
546 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
550 if [ $paramError -ne 0 ]; then
551 __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>]*]" $@
556 variableParams=$(($#-4))
557 if [ $# -lt 4 ]; then
559 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
561 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
565 if [ $paramError -ne 0 ]; then
566 __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>]*]" $@
572 if [ "$PMS_VERSION" == "V2" ]; then
573 if [ $2 != "NORIC" ]; then
574 queryparams="?ric_id="$2
576 if [ $3 != "NOSERVICE" ]; then
577 if [ -z $queryparams ]; then
578 queryparams="?service_id="$3
580 queryparams=$queryparams"&service_id="$3
583 if [ $4 != "NOTYPE" ]; then
584 if [ -z $queryparams ]; then
585 queryparams="?policytype_id="$4
587 queryparams=$queryparams"&policytype_id="$4
591 query="/v2/policy-instances"$queryparams
592 res="$(__do_curl_to_api PA GET $query)"
593 status=${res:${#res}-3}
595 if [ $status -ne $1 ]; then
596 __log_test_fail_status_code $1 $status
600 if [ $# -gt 4 ]; then
601 body=${res:0:${#res}-3}
602 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
608 for ((i=0; i<$(($#-4)); i=i+7)); do
610 if [ "$targetJson" != "[" ]; then
611 targetJson=$targetJson","
613 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
614 if [ "${arr[$i+3]}" == "EMPTY" ]; then
615 targetJson=$targetJson"\"\","
617 targetJson=$targetJson"\"${arr[$i+3]}\","
619 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
621 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
623 targetJson=$targetJson"\"policy_data\":"$json"}"
627 targetJson=$targetJson"]"
628 targetJson="{\"policies\": $targetJson}"
629 echo "TARGET JSON: $targetJson" >> $HTTPLOG
630 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
632 if [ $res -ne 0 ]; then
638 if [ $2 != "NORIC" ]; then
639 queryparams="?ric="$2
641 if [ $3 != "NOSERVICE" ]; then
642 if [ -z $queryparams ]; then
643 queryparams="?service="$3
645 queryparams=$queryparams"&service="$3
648 if [ $4 != "NOTYPE" ]; then
649 if [ -z $queryparams ]; then
650 queryparams="?type="$4
652 queryparams=$queryparams"&type="$4
656 query="/policies"$queryparams
657 res="$(__do_curl_to_api PA GET $query)"
658 status=${res:${#res}-3}
660 if [ $status -ne $1 ]; then
661 __log_test_fail_status_code $1 $status
665 if [ $# -gt 4 ]; then
666 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
669 body=${res:0:${#res}-3}
673 for ((i=0; i<$(($#-4)); i=i+5)); do
675 if [ "$targetJson" != "[" ]; then
676 targetJson=$targetJson","
678 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
679 if [ "${arr[$i+3]}" == "EMPTY" ]; then
680 targetJson=$targetJson"\"\","
682 targetJson=$targetJson"\"${arr[$i+3]}\","
685 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
687 targetJson=$targetJson"\"json\":"$json"}"
691 targetJson=$targetJson"]"
692 echo "TARGET JSON: $targetJson" >> $HTTPLOG
693 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
695 if [ $res -ne 0 ]; then
708 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
709 # args: <response-code> <policy-id> [<template-file>]
710 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
712 # (Function for test scripts)
717 if [ "$PMS_VERSION" == "V2" ]; then
718 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
719 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
722 query="/v2/policies/$UUID$2"
724 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
725 __print_err "<response-code> <policy-id> [<template-file>] " $@
728 query="/policy?id=$UUID$2"
730 res="$(__do_curl_to_api PA GET $query)"
731 status=${res:${#res}-3}
733 if [ $status -ne $1 ]; then
734 __log_test_fail_status_code $1 $status
738 if [ "$PMS_VERSION" == "V2" ]; then
739 if [ $# -eq 8 ]; then
741 #Create a policy json to compare with
742 body=${res:0:${#res}-3}
744 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
745 if [ $7 != "NOTRANSIENT" ]; then
746 targetJson=$targetJson", \"transient\":$7"
748 if [ $6 != "NOTYPE" ]; then
749 targetJson=$targetJson", \"policytype_id\":\"$6\""
751 targetJson=$targetJson", \"policytype_id\":\"\""
753 if [ $8 != "NOURL" ]; then
754 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
757 data=$(sed 's/XXX/'${2}'/g' $3)
758 targetJson=$targetJson", \"policy_data\":$data"
759 targetJson="{$targetJson}"
761 echo "TARGET JSON: $targetJson" >> $HTTPLOG
762 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
763 if [ $res -ne 0 ]; then
769 if [ $# -eq 3 ]; then
770 #Create a policy json to compare with
771 body=${res:0:${#res}-3}
773 sed 's/XXX/'${2}'/g' $3 > $file
774 targetJson=$(< $file)
775 echo "TARGET JSON: $targetJson" >> $HTTPLOG
776 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
777 if [ $res -ne 0 ]; then
787 # API Test function: PUT /policy and V2 PUT /policies
788 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
789 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
790 # (Function for test scripts)
794 if [ "$PMS_VERSION" == "V2" ]; then
795 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
796 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
800 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
801 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
814 if [ "$PMS_VERSION" == "V2" ]; then
817 if [ $# -eq 9 ]; then
822 if [ $# -eq 8 ]; then
827 while [ $count -lt $max ]; do
828 if [ "$PMS_VERSION" == "V2" ]; then
832 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
833 if [ $trans != "NOTRANSIENT" ]; then
834 inputJson=$inputJson", \"transient\":$trans"
836 if [ $pt != "NOTYPE" ]; then
837 inputJson=$inputJson", \"policytype_id\":\"$pt\""
839 inputJson=$inputJson", \"policytype_id\":\"\""
841 if [ $noti != "NOURL" ]; then
842 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
845 data=$(sed 's/XXX/'${pid}'/g' $temp)
846 inputJson=$inputJson", \"policy_data\":$data"
847 inputJson="{$inputJson}"
848 echo $inputJson > $file
850 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
852 if [ $pt != "NOTYPE" ]; then
853 query=$query"&type=$pt"
856 if [ $trans != NOTRANSIENT ]; then
857 query=$query"&transient=$trans"
861 sed 's/XXX/'${pid}'/g' $temp > $file
863 res="$(__do_curl_to_api PA PUT $query $file)"
864 status=${res:${#res}-3}
865 echo -ne " Executing "$count"("$max")${SAMELINE}"
866 if [ $status -ne $1 ]; then
867 echo " Executed "$count"?("$max")"
868 __log_test_fail_status_code $1 $status
874 echo -ne " Executed "$count"("$max")${SAMELINE}"
882 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
883 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
884 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
885 # (Function for test scripts)
887 api_put_policy_batch() {
890 if [ "$PMS_VERSION" == "V2" ]; then
891 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
892 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
896 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
897 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
909 if [ "$PMS_VERSION" == "V2" ]; then
912 if [ $# -eq 9 ]; then
917 if [ $# -eq 8 ]; then
923 while [ $count -lt $max ]; do
924 if [ "$PMS_VERSION" == "V2" ]; then
927 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
928 if [ $trans != "NOTRANSIENT" ]; then
929 inputJson=$inputJson", \"transient\":$trans"
931 if [ $pt != "NOTYPE" ]; then
932 inputJson=$inputJson", \"policytype_id\":\"$pt\""
934 inputJson=$inputJson", \"policytype_id\":\"\""
936 if [ $noti != "NOURL" ]; then
937 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
940 data=$(sed 's/XXX/'${pid}'/g' $temp)
941 inputJson=$inputJson", \"policy_data\":$data"
942 inputJson="{$inputJson}"
943 echo $inputJson > $file
945 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
947 if [ $pt != "NOTYPE" ]; then
948 query=$query"&type=$pt"
951 if [ $trans != NOTRANSIENT ]; then
952 query=$query"&transient=$trans"
955 sed 's/XXX/'${pid}'/g' $temp > $file
957 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
958 status=${res:${#res}-3}
959 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
961 if [ $status -ne 200 ]; then
962 echo " Requested(batch) "$count"?("$max")"
963 __log_test_fail_status_code 200 $status
966 cid=${res:0:${#res}-3}
970 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
977 res="$(__do_curl_to_api PA RESPONSE $cid)"
978 status=${res:${#res}-3}
979 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
981 if [ $status -ne $1 ]; then
982 echo " Accepted(batch) "$count"?("$max")"
983 __log_test_fail_status_code $1 $status
988 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
997 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
998 # 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>
999 # 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>
1000 # (Function for test scripts)
1001 api_put_policy_parallel() {
1004 if [ "$PMS_VERSION" == "V2" ]; then
1005 if [ $# -ne 11 ]; then
1006 __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>" $@
1010 if [ $# -ne 10 ]; then
1011 __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>" $@
1015 resp_code=$1; shift;
1021 transient=$1; shift;
1022 if [ "$PMS_VERSION" == "V2" ]; then
1031 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1032 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1033 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1034 echo " Info - will execute over agent REST"
1036 if [ "$PMS_VERSION" == "V2" ]; then
1037 if [ $serv == "NOSERVICE" ]; then
1040 query="$PMS_API_PREFIX/v2/policies"
1042 if [ $serv == "NOSERVICE" ]; then
1045 query="/policy?service=$serv"
1047 if [ $type != "NOTYPE" ]; then
1048 query=$query"&type=$type"
1051 if [ $transient != NOTRANSIENT ]; then
1052 query=$query"&transient=$transient"
1056 urlbase=${PA_ADAPTER}${query}
1059 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1060 httpproxy=$KUBE_PROXY_PATH
1063 for ((i=1; i<=$pids; i++))
1066 if [ -z "$uuid" ]; then
1069 echo "" > "./tmp/.pid${i}.res.txt"
1070 if [ "$PMS_VERSION" == "V2" ]; then
1071 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1073 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1076 done | xargs -n 1 -I{} -P $pids bash -c '{
1078 echo " Parallel process $arg started"
1079 tmp=$(< "./tmp/.pid${arg}.txt")
1080 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1083 for ((i=1; i<=$pids; i++))
1085 file="./tmp/.pid${i}.res.txt"
1087 if [ -z "$tmp" ]; then
1088 echo " Process $i : unknown result (result file empty"
1092 if [ $res == "0" ]; then
1093 echo " Process $i : OK - "${tmp:1}
1095 echo " Process $i : failed - "${tmp:1}
1100 if [ -z $msg ]; then
1101 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1105 __log_test_fail_general "One of more processes failed to execute"
1109 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1110 # args: <response-code> <policy-id> [count]
1111 # (Function for test scripts)
1112 api_delete_policy() {
1115 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1116 __print_err "<response-code> <policy-id> [count]" $@
1123 if [ $# -eq 3 ]; then
1129 while [ $count -lt $max ]; do
1130 if [ "$PMS_VERSION" == "V2" ]; then
1131 query="/v2/policies/"$UUID$pid
1133 query="/policy?id="$UUID$pid
1135 res="$(__do_curl_to_api PA DELETE $query)"
1136 status=${res:${#res}-3}
1137 echo -ne " Executing "$count"("$max")${SAMELINE}"
1139 if [ $status -ne $1 ]; then
1140 echo " Executed "$count"?("$max")"
1141 __log_test_fail_status_code $1 $status
1146 echo -ne " Executed "$count"("$max")${SAMELINE}"
1154 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1155 # args: <response-code> <policy-id> [count]
1156 # (Function for test scripts)
1157 api_delete_policy_batch() {
1160 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1161 __print_err "<response-code> <policy-id> [count]" $@
1168 if [ $# -eq 3 ]; then
1174 while [ $count -lt $max ]; do
1175 if [ "$PMS_VERSION" == "V2" ]; then
1176 query="/v2/policies/"$UUID$pid
1178 query="/policy?id="$UUID$pid
1180 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
1181 status=${res:${#res}-3}
1182 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1184 if [ $status -ne 200 ]; then
1185 echo " Requested(batch) "$count"?("$max")"
1186 __log_test_fail_status_code 200 $status
1189 cid=${res:0:${#res}-3}
1193 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1201 res="$(__do_curl_to_api PA RESPONSE $cid)"
1202 status=${res:${#res}-3}
1203 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1205 if [ $status -ne $1 ]; then
1206 echo " Deleted(batch) "$count"?("$max")"
1207 __log_test_fail_status_code $1 $status
1212 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1221 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1222 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1223 # (Function for test scripts)
1224 api_delete_policy_parallel() {
1227 if [ $# -ne 5 ]; then
1228 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1231 resp_code=$1; shift;
1237 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1238 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1239 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1240 echo " Info - will execute over agent REST"
1243 if [ "$PMS_VERSION" == "V2" ]; then
1244 query="$PMS_API_PREFIX/v2/policies/"
1249 urlbase=${PA_ADAPTER}${query}
1252 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1253 httpproxy=$KUBE_PROXY_PATH
1256 for ((i=1; i<=$pids; i++))
1259 if [ -z "$uuid" ]; then
1262 echo "" > "./tmp/.pid${i}.del.res.txt"
1263 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1265 done | xargs -n 1 -I{} -P $pids bash -c '{
1267 echo " Parallel process $arg started"
1268 tmp=$(< "./tmp/.pid${arg}.del.txt")
1269 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1272 for ((i=1; i<=$pids; i++))
1274 file="./tmp/.pid${i}.del.res.txt"
1276 if [ -z "$tmp" ]; then
1277 echo " Process $i : unknown result (result file empty"
1281 if [ $res == "0" ]; then
1282 echo " Process $i : OK - "${tmp:1}
1284 echo " Process $i : failed - "${tmp:1}
1289 if [ -z $msg ]; then
1290 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1294 __log_test_fail_general "One of more processes failed to execute"
1298 # API Test function: GET /policy_ids and V2 GET /v2/policies
1299 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1300 # (Function for test scripts)
1301 api_get_policy_ids() {
1304 if [ $# -lt 4 ]; then
1305 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1311 if [ "$PMS_VERSION" == "V2" ]; then
1312 if [ $2 != "NORIC" ]; then
1313 queryparams="?ric_id="$2
1316 if [ $3 != "NOSERVICE" ]; then
1317 if [ -z $queryparams ]; then
1318 queryparams="?service_id="$3
1320 queryparams=$queryparams"&service_id="$3
1323 if [ $4 != "NOTYPE" ]; then
1324 if [ -z $queryparams ]; then
1325 queryparams="?policytype_id="$4
1327 queryparams=$queryparams"&policytype_id="$4
1331 query="/v2/policies"$queryparams
1333 if [ $2 != "NORIC" ]; then
1334 queryparams="?ric="$2
1337 if [ $3 != "NOSERVICE" ]; then
1338 if [ -z $queryparams ]; then
1339 queryparams="?service="$3
1341 queryparams=$queryparams"&service="$3
1344 if [ $4 != "NOTYPE" ]; then
1345 if [ -z $queryparams ]; then
1346 queryparams="?type="$4
1348 queryparams=$queryparams"&type="$4
1352 query="/policy_ids"$queryparams
1355 res="$(__do_curl_to_api PA GET $query)"
1356 status=${res:${#res}-3}
1358 if [ $status -ne $1 ]; then
1359 __log_test_fail_status_code $1 $status
1363 if [ $# -gt 4 ]; then
1364 body=${res:0:${#res}-3}
1367 for pid in ${@:5} ; do
1368 if [ "$targetJson" != "[" ]; then
1369 targetJson=$targetJson","
1371 if [ $pid != "NOID" ]; then
1372 targetJson=$targetJson"\"$UUID$pid\""
1376 targetJson=$targetJson"]"
1377 if [ "$PMS_VERSION" == "V2" ]; then
1378 targetJson="{\"policy_ids\": $targetJson}"
1380 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1381 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1383 if [ $res -ne 0 ]; then
1384 __log_test_fail_body
1393 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1394 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1395 # (Function for test scripts)
1396 api_get_policy_type() {
1399 if [ "$PMS_VERSION" != "V2" ]; then
1400 __log_test_fail_not_supported
1404 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1405 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1408 query="/v2/policy-types/$2"
1410 res="$(__do_curl_to_api PA GET $query)"
1411 status=${res:${#res}-3}
1413 if [ $status -ne $1 ]; then
1414 __log_test_fail_status_code $1 $status
1418 if [ $# -eq 3 ]; then
1420 body=${res:0:${#res}-3}
1423 targetJson="{\"policy_schema\":$targetJson}"
1424 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1425 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1427 if [ $res -ne 0 ]; then
1428 __log_test_fail_body
1437 # API Test function: GET /policy_schema
1438 # args: <response-code> <policy-type-id> [<schema-file>]
1439 # (Function for test scripts)
1440 api_get_policy_schema() {
1443 if [ "$PMS_VERSION" == "V2" ]; then
1444 __log_test_fail_not_supported
1448 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1449 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1452 query="/policy_schema?id=$2"
1453 res="$(__do_curl_to_api PA GET $query)"
1454 status=${res:${#res}-3}
1456 if [ $status -ne $1 ]; then
1457 __log_test_fail_status_code $1 $status
1461 if [ $# -eq 3 ]; then
1463 body=${res:0:${#res}-3}
1467 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1468 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1470 if [ $res -ne 0 ]; then
1471 __log_test_fail_body
1480 # API Test function: GET /policy_schemas
1481 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1482 # args(V2): <response-code>
1483 # (Function for test scripts)
1484 api_get_policy_schemas() {
1487 if [ "$PMS_VERSION" == "V2" ]; then
1488 if [ $# -ne 1 ]; then
1489 __print_err "<response-code>" $@
1493 if [ $# -lt 2 ]; then
1494 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1498 if [ "$PMS_VERSION" == "V2" ]; then
1499 query="/v2/policy-schemas"
1501 query="/policy_schemas"
1502 if [ $2 != "NORIC" ]; then
1503 query=$query"?ric="$2
1507 res="$(__do_curl_to_api PA GET $query)"
1508 status=${res:${#res}-3}
1510 if [ $status -ne $1 ]; then
1511 __log_test_fail_status_code $1 $status
1515 if [ $# -gt 2 ]; then
1516 body=${res:0:${#res}-3}
1519 for file in ${@:3} ; do
1520 if [ "$targetJson" != "[" ]; then
1521 targetJson=$targetJson","
1523 if [ $file == "NOFILE" ]; then
1524 targetJson=$targetJson"{}"
1526 targetJson=$targetJson$(< $file)
1530 targetJson=$targetJson"]"
1531 if [ "$PMS_VERSION" == "V2" ]; then
1532 targetJson="{\"policy_schemas\": $targetJson }"
1534 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1535 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1537 if [ $res -ne 0 ]; then
1538 __log_test_fail_body
1547 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1548 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1549 # (Function for test scripts)
1550 api_get_policy_status() {
1553 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1554 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1560 if [ $3 == "STD" ]; then
1561 targetJson="{\"enforceStatus\":\"$4\""
1562 if [ $# -eq 5 ]; then
1563 targetJson=$targetJson",\"reason\":\"$5\""
1565 targetJson=$targetJson"}"
1566 elif [ $3 == "STD2" ]; then
1567 if [ $4 == "EMPTY" ]; then
1568 targetJson="{\"enforceStatus\":\"\""
1570 targetJson="{\"enforceStatus\":\"$4\""
1572 if [ $# -eq 5 ]; then
1573 if [ $5 == "EMPTY" ]; then
1574 targetJson=$targetJson",\"enforceReason\":\"\""
1576 targetJson=$targetJson",\"enforceReason\":\"$5\""
1579 targetJson=$targetJson"}"
1580 elif [ $3 == "OSC" ]; then
1581 targetJson="{\"instance_status\":\"$4\""
1582 if [ $# -eq 5 ]; then
1583 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1585 targetJson=$targetJson",\"created_at\":\"????\"}"
1587 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1591 if [ "$PMS_VERSION" == "V2" ]; then
1592 query="/v2/policies/$UUID$2/status"
1593 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1595 query="/policy_status?id="$UUID$2
1598 res="$(__do_curl_to_api PA GET $query)"
1599 status=${res:${#res}-3}
1601 if [ $status -ne $1 ]; then
1602 __log_test_fail_status_code $1 $status
1606 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1607 body=${res:0:${#res}-3}
1608 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1610 if [ $res -ne 0 ]; then
1611 __log_test_fail_body
1619 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1620 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1621 # (Function for test scripts)
1622 api_get_policy_types() {
1625 if [ $# -lt 1 ]; then
1626 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1630 if [ "$PMS_VERSION" == "V2" ]; then
1631 if [ $# -eq 1 ]; then
1632 query="/v2/policy-types"
1633 elif [ $2 == "NORIC" ]; then
1634 query="/v2/policy-types"
1636 query="/v2/policy-types?ric_id=$2"
1639 if [ $# -eq 1 ]; then
1640 query="/policy_types"
1641 elif [ $2 == "NORIC" ]; then
1642 query="/policy_types"
1644 query="/policy_types?ric=$2"
1648 res="$(__do_curl_to_api PA GET $query)"
1649 status=${res:${#res}-3}
1651 if [ $status -ne $1 ]; then
1652 __log_test_fail_status_code $1 $status
1656 if [ $# -gt 2 ]; then
1657 body=${res:0:${#res}-3}
1660 for pid in ${@:3} ; do
1661 if [ "$targetJson" != "[" ]; then
1662 targetJson=$targetJson","
1664 if [ $pid == "EMPTY" ]; then
1667 targetJson=$targetJson"\"$pid\""
1670 targetJson=$targetJson"]"
1671 if [ "$PMS_VERSION" == "V2" ]; then
1672 targetJson="{\"policytype_ids\": $targetJson }"
1674 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1675 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1677 if [ $res -ne 0 ]; then
1678 __log_test_fail_body
1687 #########################################################
1688 #### Test case functions Health check
1689 #########################################################
1691 # API Test function: GET /status and V2 GET /status
1692 # args: <response-code>
1693 # (Function for test scripts)
1696 if [ $# -ne 1 ]; then
1697 __print_err "<response-code>" $@
1700 if [ "$PMS_VERSION" == "V2" ]; then
1705 res="$(__do_curl_to_api PA GET $query)"
1706 status=${res:${#res}-3}
1708 if [ $status -ne $1 ]; then
1709 __log_test_fail_status_code $1 $status
1717 #########################################################
1718 #### Test case functions RIC Repository
1719 #########################################################
1721 # API Test function: GET /ric and V2 GET /v2/rics/ric
1722 # args: <reponse-code> <management-element-id> [<ric-id>]
1723 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1724 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1725 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1728 # (Function for test scripts)
1732 if [ "$PMS_VERSION" == "V2" ]; then
1733 if [ $# -lt 3 ]; then
1734 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1738 if [ $2 != "NOME" ]; then
1739 search="?managed_element_id="$2
1741 if [ $3 != "NORIC" ]; then
1742 if [ -z $search ]; then
1745 search=$search"&ric_id="$3
1748 query="/v2/rics/ric"$search
1750 res="$(__do_curl_to_api PA GET $query)"
1751 status=${res:${#res}-3}
1753 if [ $status -ne $1 ]; then
1754 __log_test_fail_status_code $1 $status
1758 if [ $# -gt 3 ]; then
1759 body=${res:0:${#res}-3}
1760 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1761 if [ $res -ne 0 ]; then
1762 __log_test_fail_general "Could not create target ric info json"
1766 targetJson=$(<./tmp/.tmp_rics.json)
1767 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1768 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1769 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1770 if [ $res -ne 0 ]; then
1771 __log_test_fail_body
1776 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1777 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1781 query="/ric?managedElementId="$2
1783 res="$(__do_curl_to_api PA GET $query)"
1784 status=${res:${#res}-3}
1786 if [ $status -ne $1 ]; then
1787 __log_test_fail_status_code $1 $status
1791 if [ $# -eq 3 ]; then
1792 body=${res:0:${#res}-3}
1793 if [ "$body" != "$3" ]; then
1794 __log_test_fail_body
1803 # API test function: GET /rics and V2 GET /v2/rics
1804 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1805 # 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_........."
1806 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1807 # (Function for test scripts)
1811 if [ $# -lt 2 ]; then
1812 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1816 if [ "$PMS_VERSION" == "V2" ]; then
1818 if [ $2 != "NOTYPE" ]; then
1819 query="/v2/rics?policytype_id="$2
1823 if [ $2 != "NOTYPE" ]; then
1824 query="/rics?policyType="$2
1828 res="$(__do_curl_to_api PA GET $query)"
1829 status=${res:${#res}-3}
1831 if [ $status -ne $1 ]; then
1832 __log_test_fail_status_code $1 $status
1836 if [ $# -gt 2 ]; then
1837 body=${res:0:${#res}-3}
1838 if [ "$PMS_VERSION" == "V2" ]; then
1839 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1841 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1843 if [ $res -ne 0 ]; then
1844 __log_test_fail_general "Could not create target ric info json"
1848 targetJson=$(<./tmp/.tmp_rics.json)
1849 if [ "$PMS_VERSION" == "V2" ]; then
1850 targetJson="{\"rics\": $targetJson }"
1852 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1853 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1854 if [ $res -ne 0 ]; then
1855 __log_test_fail_body
1864 ##################################################################
1865 #### API Test case functions Service registry and supervision ####
1866 ##################################################################
1868 # API test function: PUT /service and V2 PUT /service
1869 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1870 # (Function for test scripts)
1873 if [ $# -ne 4 ]; then
1874 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1878 if [ "$PMS_VERSION" == "V2" ]; then
1879 query="/v2/services"
1880 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1883 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1885 file="./tmp/.tmp.json"
1886 echo "$json" > $file
1888 res="$(__do_curl_to_api PA PUT $query $file)"
1889 status=${res:${#res}-3}
1891 if [ $status -ne $1 ]; then
1892 __log_test_fail_status_code $1 $status
1900 # API test function: GET /services and V2 GET /v2/services
1901 #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>]* )]
1902 # (Function for test scripts)
1903 api_get_services() {
1905 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1907 if [ $# -eq 1 ]; then
1909 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1911 elif [ $# -eq 5 ]; then
1913 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1915 if [ $(($argLen%3)) -eq 0 ]; then
1920 if [ $paramError -ne 0 ]; then
1921 __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>]* )]" $@
1925 if [ "$PMS_VERSION" == "V2" ]; then
1926 query="/v2/services"
1928 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1929 query="/v2/services?service_id="$2
1934 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1935 query="/services?name="$2
1938 res="$(__do_curl_to_api PA GET $query)"
1939 status=${res:${#res}-3}
1941 if [ $status -ne $1 ]; then
1942 __log_test_fail_status_code $1 $status
1946 if [ $# -gt 2 ]; then
1947 variableArgCount=$(($#-2))
1948 body=${res:0:${#res}-3}
1952 while [ $cntr -lt $variableArgCount ]; do
1953 servicename=$1; shift;
1956 if [ $cntr -gt 0 ]; then
1957 targetJson=$targetJson","
1959 # timeSinceLastActivitySeconds value cannot be checked since value varies
1960 if [ "$PMS_VERSION" == "V2" ]; then
1961 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1963 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1967 targetJson=$targetJson"]"
1968 if [ "$PMS_VERSION" == "V2" ]; then
1969 targetJson="{\"service_list\": $targetJson }"
1971 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1972 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1973 if [ $res -ne 0 ]; then
1974 __log_test_fail_body
1983 # API test function: GET /services V2 GET /v2/services - (only checking service names)
1984 # args: <response-code> [<service-name>]*"
1985 # (Function for test scripts)
1986 api_get_service_ids() {
1989 if [ $# -lt 1 ]; then
1990 __print_err "<response-code> [<service-name>]*" $@
1994 if [ "$PMS_VERSION" == "V2" ]; then
1995 query="/v2/services"
1999 res="$(__do_curl_to_api PA GET $query)"
2000 status=${res:${#res}-3}
2002 if [ $status -ne $1 ]; then
2003 __log_test_fail_status_code $1 $status
2007 body=${res:0:${#res}-3}
2009 for rapp in ${@:2} ; do
2010 if [ "$targetJson" != "[" ]; then
2011 targetJson=$targetJson","
2013 if [ "$PMS_VERSION" == "V2" ]; then
2014 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2016 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2020 targetJson=$targetJson"]"
2021 if [ "$PMS_VERSION" == "V2" ]; then
2022 targetJson="{\"service_list\": $targetJson }"
2024 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2025 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2027 if [ $res -ne 0 ]; then
2028 __log_test_fail_body
2036 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2037 # args: <response-code> <service-name>
2038 # (Function for test scripts)
2039 api_delete_services() {
2042 if [ $# -ne 2 ]; then
2043 __print_err "<response-code> <service-name>" $@
2046 if [ "$PMS_VERSION" == "V2" ]; then
2047 query="/v2/services/"$2
2049 query="/services?name="$2
2051 res="$(__do_curl_to_api PA DELETE $query)"
2052 status=${res:${#res}-3}
2054 if [ $status -ne $1 ]; then
2055 __log_test_fail_status_code $1 $status
2063 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2064 # args: <response-code> <service-name>
2065 # (Function for test scripts)
2066 api_put_services_keepalive() {
2069 if [ $# -ne 2 ]; then
2070 __print_err "<response-code> <service-name>" $@
2073 if [ "$PMS_VERSION" == "V2" ]; then
2074 query="/v2/services/$2/keepalive"
2076 query="/services/keepalive?name="$2
2079 res="$(__do_curl_to_api PA PUT $query)"
2080 status=${res:${#res}-3}
2082 if [ $status -ne $1 ]; then
2083 __log_test_fail_status_code $1 $status
2091 ##################################################################
2092 #### API Test case functions Configuration ####
2093 ##################################################################
2095 # API Test function: PUT /v2/configuration
2096 # args: <response-code> <config-file>
2097 # (Function for test scripts)
2098 api_put_configuration() {
2101 if [ "$PMS_VERSION" != "V2" ]; then
2102 __log_test_fail_not_supported
2106 if [ $# -ne 2 ]; then
2107 __print_err "<response-code> <config-file>" $@
2110 if [ ! -f $2 ]; then
2111 __log_test_fail_general "Config file "$2", does not exist"
2115 inputJson="{\"config\":"$inputJson"}"
2116 file="./tmp/.config.json"
2117 echo $inputJson > $file
2118 query="/v2/configuration"
2119 res="$(__do_curl_to_api PA PUT $query $file)"
2120 status=${res:${#res}-3}
2122 if [ $status -ne $1 ]; then
2123 __log_test_fail_status_code $1 $status
2131 # API Test function: GET /v2/configuration
2132 # args: <response-code> [<config-file>]
2133 # (Function for test scripts)
2134 api_get_configuration() {
2137 if [ "$PMS_VERSION" != "V2" ]; then
2138 __log_test_fail_not_supported
2142 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2143 __print_err "<response-code> [<config-file>]" $@
2146 if [ ! -f $2 ]; then
2147 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2151 query="/v2/configuration"
2152 res="$(__do_curl_to_api PA GET $query)"
2153 status=${res:${#res}-3}
2155 if [ $status -ne $1 ]; then
2156 __log_test_fail_status_code $1 $status
2160 if [ $# -eq 2 ]; then
2162 body=${res:0:${#res}-3}
2165 targetJson="{\"config\":"$targetJson"}"
2166 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2167 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2169 if [ $res -ne 0 ]; then
2170 __log_test_fail_body
2179 ##########################################
2180 #### Reset types and instances ####
2181 ##########################################
2183 # Admin reset to remove all policies and services
2184 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2185 # NOTE - only works in kubernetes and the pod should not be running
2187 # (Function for test scripts)
2189 pms_kube_pvc_reset() {
2192 pvc_name=$(kubectl get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2193 if [ -z "$pvc_name" ]; then
2194 pvc_name=policymanagementservice-vardata-pvc
2196 echo " Trying to reset pvc: "$pvc_name
2197 __kube_clean_pvc $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $POLICY_AGENT_CONTAINER_MNT_DIR