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 nonrtric-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 docker logs $POLICY_AGENT_APP_NAME > $1$2_policy-agent.log 2>&1
83 #######################################################
85 ## Access to Policy agent
86 # Host name may be changed if app started by kube
87 # Direct access from script
89 PA_HOST_NAME=$LOCALHOST_NAME
90 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
92 # PA_ADAPTER used for switch between REST and DMAAP
93 PA_ADAPTER_TYPE="REST"
96 # Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
99 #Save first worker node the pod is started on
102 ###########################
103 ### Policy Agents functions
104 ###########################
106 # All calls to the agent will be directed to the agent REST interface from now on
108 # (Function for test scripts)
109 use_agent_rest_http() {
110 echo -e $BOLD"Agent protocol setting"$EBOLD
111 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
113 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
115 PA_ADAPTER_TYPE="REST"
120 # All calls to the agent will be directed to the agent REST interface from now on
122 # (Function for test scripts)
123 use_agent_rest_https() {
124 echo -e $BOLD"Agent protocol setting"$EBOLD
125 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
127 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
129 PA_ADAPTER_TYPE="REST"
134 # All calls to the agent will be directed to the agent dmaap interface over http from now on
136 # (Function for test scripts)
137 use_agent_dmaap_http() {
138 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
139 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
140 PA_ADAPTER_TYPE="MR-HTTP"
144 # All calls to the agent will be directed to the agent dmaap interface over https from now on
146 # (Function for test scripts)
147 use_agent_dmaap_https() {
148 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
149 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
150 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
151 PA_ADAPTER_TYPE="MR-HTTPS"
155 # Start the policy agent
156 # args: (docker) PROXY|NOPROXY <config-file>
157 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
158 # (Function for test scripts)
159 start_policy_agent() {
160 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
162 if [ $RUNMODE == "KUBE" ]; then
164 # Check if app shall be fully managed by the test script
165 __check_included_image "PA"
168 # Check if app shall only be used by the testscipt
169 __check_prestarted_image "PA"
172 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
173 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
174 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
177 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
178 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
179 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
183 if [ $retcode_p -eq 0 ]; then
184 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
185 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
186 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
189 if [ $retcode_i -eq 0 ]; then
191 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
193 #Check if nonrtric namespace exists, if not create it
194 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
196 #Export all vars needed for service and deployment
197 export POLICY_AGENT_APP_NAME
198 export KUBE_NONRTRIC_NAMESPACE
199 export POLICY_AGENT_IMAGE
200 export POLICY_AGENT_INTERNAL_PORT
201 export POLICY_AGENT_INTERNAL_SECURE_PORT
202 export POLICY_AGENT_EXTERNAL_PORT
203 export POLICY_AGENT_EXTERNAL_SECURE_PORT
204 export POLICY_AGENT_CONFIG_MOUNT_PATH
205 export POLICY_AGENT_DATA_MOUNT_PATH
206 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
207 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
208 export POLICY_AGENT_PKG_NAME
210 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
211 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
212 ##Create a unique path for the pv each time to prevent a previous volume to be reused
213 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
214 export POLICY_AGENT_CONTAINER_MNT_DIR
216 if [ $1 == "PROXY" ]; then
217 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
218 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
219 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
220 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
222 echo " Configured with http proxy"
225 AGENT_HTTP_PROXY_CONFIG_PORT=0
226 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
227 echo " Configured without http proxy"
229 export AGENT_HTTP_PROXY_CONFIG_PORT
230 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
233 # Create config map for config
234 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
236 output_yaml=$PWD/tmp/pa_cfc.yaml
237 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
239 # Create config map for data
240 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
241 if [ $# -lt 3 ]; then
242 #create empty dummy file
243 echo "{}" > $data_json
247 output_yaml=$PWD/tmp/pa_cfd.yaml
248 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
251 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
252 output_yaml=$PWD/tmp/pa_pv.yaml
253 __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
256 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
257 output_yaml=$PWD/tmp/pa_pvc.yaml
258 __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
261 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
262 output_yaml=$PWD/tmp/pa_svc.yaml
263 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
266 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
267 output_yaml=$PWD/tmp/pa_app.yaml
268 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
272 # 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
273 __PA_WORKER_NODE=$(kubectl get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
274 if [ -z "$__PA_WORKER_NODE" ]; then
275 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
278 echo " Retrieving host and ports for service..."
279 PA_HOST_NAME=$(__kube_get_service_host $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
280 POLICY_AGENT_EXTERNAL_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
281 POLICY_AGENT_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
283 echo " Host IP, http port, https port: $PA_HOST_NAME $POLICY_AGENT_EXTERNAL_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT"
285 if [ $PA_HTTPX == "http" ]; then
286 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
288 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
290 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
292 if [ $PA_ADAPTER_TYPE == "REST" ]; then
296 __check_included_image 'PA'
297 if [ $? -eq 1 ]; then
298 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
299 echo -e $RED"The Policy Agent will not be started"$ERED
306 cd $POLICY_AGENT_HOST_MNT_DIR
309 if [ "$(ls -A $DIR)" ]; then
310 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
311 rm -rf db/* &> /dev/null
312 if [ $? -ne 0 ]; then
313 echo -e $RED" Cannot remove database files in: $PWD"$ERED
318 echo " No files in mounted dir or dir does not exists"
322 #Export all vars needed for docker-compose
323 export POLICY_AGENT_APP_NAME
324 export POLICY_AGENT_APP_NAME_ALIAS
325 export POLICY_AGENT_INTERNAL_PORT
326 export POLICY_AGENT_EXTERNAL_PORT
327 export POLICY_AGENT_INTERNAL_SECURE_PORT
328 export POLICY_AGENT_EXTERNAL_SECURE_PORT
330 export CONSUL_INTERNAL_PORT
331 export CONFIG_BINDING_SERVICE
332 export POLICY_AGENT_CONFIG_KEY
333 export DOCKER_SIM_NWNAME
334 export POLICY_AGENT_HOST_MNT_DIR
335 export POLICY_AGENT_CONFIG_MOUNT_PATH
336 export POLICY_AGENT_CONFIG_FILE
337 export POLICY_AGENT_PKG_NAME
338 export POLICY_AGENT_DISPLAY_NAME
339 export POLICY_AGENT_CONTAINER_MNT_DIR
341 if [ $1 == "PROXY" ]; then
342 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
343 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
344 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
345 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
347 echo " Configured with http proxy"
350 AGENT_HTTP_PROXY_CONFIG_PORT=0
351 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
352 echo " Configured without http proxy"
354 export AGENT_HTTP_PROXY_CONFIG_PORT
355 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
357 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
359 envsubst < $2 > $dest_file
361 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
363 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
369 # Stop the policy agent
372 # (Function for test scripts)
373 stop_policy_agent() {
374 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
376 if [ $RUNMODE == "KUBE" ]; then
377 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
378 echo " Deleting the replica set - a new will be started when the app is started"
379 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
380 if [ $? -ne 0 ]; then
381 echo -e $RED" Could not delete replica set "$RED
386 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
387 if [ $? -ne 0 ]; then
388 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
394 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
399 # Start a previously stopped policy agent
401 # (Function for test scripts)
402 start_stopped_policy_agent() {
403 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
405 if [ $RUNMODE == "KUBE" ]; then
407 # Tie the PMS to the same worker node it was initially started on
408 # 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
409 if [ -z "$__PA_WORKER_NODE" ]; then
410 echo -e $RED" No initial worker node found for pod "$RED
414 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
415 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
416 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
417 if [ $? -ne 0 ]; then
418 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
420 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
424 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
425 if [ $? -ne 0 ]; then
426 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
432 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
433 if [ $? -ne 0 ]; then
442 # Load the the appl config for the agent into a config map
443 agent_load_config() {
444 echo -e $BOLD"Agent - load config from "$EBOLD$1
445 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
447 output_yaml=$PWD/tmp/pa_cfd.yaml
448 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
453 # Turn on debug level tracing in the agent
455 # (Function for test scripts)
457 echo -e $BOLD"Setting agent debug logging"$EBOLD
458 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
459 result=$(__do_curl "$curlString")
460 if [ $? -ne 0 ]; then
461 __print_err "could not set debug mode" $@
469 # Turn on trace level tracing in the agent
471 # (Function for test scripts)
473 echo -e $BOLD"Setting agent trace logging"$EBOLD
474 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
475 result=$(__do_curl "$curlString")
476 if [ $? -ne 0 ]; then
477 __print_err "could not set trace mode" $@
485 # Perform curl retries when making direct call to the agent for the specified http response codes
486 # Speace separated list of http response codes
487 # args: [<response-code>]*
488 use_agent_retries() {
489 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
495 # Check the agent logs for WARNINGs and ERRORs
497 # (Function for test scripts)
498 check_policy_agent_logs() {
499 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
502 #########################################################
503 #### Test case functions A1 Policy management service
504 #########################################################
506 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
507 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
508 # args: json:<url> <target-value> [<timeout-in-seconds]
509 # (Function for test scripts)
511 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
512 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
513 if [[ $1 == "json:"* ]]; then
514 if [ "$PMS_VERSION" == "V2" ]; then
515 __var_test "Policy Agent" $PA_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
517 __var_test "Policy Agent" $PA_PATH"/" $1 "=" $2 $3
522 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
526 # API Test function: GET /policies and V2 GET /v2/policy-instances
527 # 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>]*]
528 # 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>]*]
529 # (Function for test scripts)
533 if [ "$PMS_VERSION" == "V2" ]; then
535 variableParams=$(($#-4))
536 if [ $# -lt 4 ]; then
538 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
540 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
544 if [ $paramError -ne 0 ]; then
545 __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>]*]" $@
550 variableParams=$(($#-4))
551 if [ $# -lt 4 ]; then
553 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
555 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
559 if [ $paramError -ne 0 ]; then
560 __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>]*]" $@
566 if [ "$PMS_VERSION" == "V2" ]; then
567 if [ $2 != "NORIC" ]; then
568 queryparams="?ric_id="$2
570 if [ $3 != "NOSERVICE" ]; then
571 if [ -z $queryparams ]; then
572 queryparams="?service_id="$3
574 queryparams=$queryparams"&service_id="$3
577 if [ $4 != "NOTYPE" ]; then
578 if [ -z $queryparams ]; then
579 queryparams="?policytype_id="$4
581 queryparams=$queryparams"&policytype_id="$4
585 query="/v2/policy-instances"$queryparams
586 res="$(__do_curl_to_api PA GET $query)"
587 status=${res:${#res}-3}
589 if [ $status -ne $1 ]; then
590 __log_test_fail_status_code $1 $status
594 if [ $# -gt 4 ]; then
595 body=${res:0:${#res}-3}
596 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
602 for ((i=0; i<$(($#-4)); i=i+7)); do
604 if [ "$targetJson" != "[" ]; then
605 targetJson=$targetJson","
607 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
608 if [ "${arr[$i+3]}" == "EMPTY" ]; then
609 targetJson=$targetJson"\"\","
611 targetJson=$targetJson"\"${arr[$i+3]}\","
613 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
615 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
617 targetJson=$targetJson"\"policy_data\":"$json"}"
621 targetJson=$targetJson"]"
622 targetJson="{\"policies\": $targetJson}"
623 echo "TARGET JSON: $targetJson" >> $HTTPLOG
624 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
626 if [ $res -ne 0 ]; then
632 if [ $2 != "NORIC" ]; then
633 queryparams="?ric="$2
635 if [ $3 != "NOSERVICE" ]; then
636 if [ -z $queryparams ]; then
637 queryparams="?service="$3
639 queryparams=$queryparams"&service="$3
642 if [ $4 != "NOTYPE" ]; then
643 if [ -z $queryparams ]; then
644 queryparams="?type="$4
646 queryparams=$queryparams"&type="$4
650 query="/policies"$queryparams
651 res="$(__do_curl_to_api PA GET $query)"
652 status=${res:${#res}-3}
654 if [ $status -ne $1 ]; then
655 __log_test_fail_status_code $1 $status
659 if [ $# -gt 4 ]; then
660 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
663 body=${res:0:${#res}-3}
667 for ((i=0; i<$(($#-4)); i=i+5)); do
669 if [ "$targetJson" != "[" ]; then
670 targetJson=$targetJson","
672 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
673 if [ "${arr[$i+3]}" == "EMPTY" ]; then
674 targetJson=$targetJson"\"\","
676 targetJson=$targetJson"\"${arr[$i+3]}\","
679 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
681 targetJson=$targetJson"\"json\":"$json"}"
685 targetJson=$targetJson"]"
686 echo "TARGET JSON: $targetJson" >> $HTTPLOG
687 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
689 if [ $res -ne 0 ]; then
702 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
703 # args: <response-code> <policy-id> [<template-file>]
704 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
706 # (Function for test scripts)
711 if [ "$PMS_VERSION" == "V2" ]; then
712 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
713 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
716 query="/v2/policies/$UUID$2"
718 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
719 __print_err "<response-code> <policy-id> [<template-file>] " $@
722 query="/policy?id=$UUID$2"
724 res="$(__do_curl_to_api PA GET $query)"
725 status=${res:${#res}-3}
727 if [ $status -ne $1 ]; then
728 __log_test_fail_status_code $1 $status
732 if [ "$PMS_VERSION" == "V2" ]; then
733 if [ $# -eq 8 ]; then
735 #Create a policy json to compare with
736 body=${res:0:${#res}-3}
738 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
739 if [ $7 != "NOTRANSIENT" ]; then
740 targetJson=$targetJson", \"transient\":$7"
742 if [ $6 != "NOTYPE" ]; then
743 targetJson=$targetJson", \"policytype_id\":\"$6\""
745 targetJson=$targetJson", \"policytype_id\":\"\""
747 if [ $8 != "NOURL" ]; then
748 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
751 data=$(sed 's/XXX/'${2}'/g' $3)
752 targetJson=$targetJson", \"policy_data\":$data"
753 targetJson="{$targetJson}"
755 echo "TARGET JSON: $targetJson" >> $HTTPLOG
756 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
757 if [ $res -ne 0 ]; then
763 if [ $# -eq 3 ]; then
764 #Create a policy json to compare with
765 body=${res:0:${#res}-3}
767 sed 's/XXX/'${2}'/g' $3 > $file
768 targetJson=$(< $file)
769 echo "TARGET JSON: $targetJson" >> $HTTPLOG
770 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
771 if [ $res -ne 0 ]; then
781 # API Test function: PUT /policy and V2 PUT /policies
782 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
783 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
784 # (Function for test scripts)
788 if [ "$PMS_VERSION" == "V2" ]; then
789 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
790 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
794 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
795 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
808 if [ "$PMS_VERSION" == "V2" ]; then
811 if [ $# -eq 9 ]; then
816 if [ $# -eq 8 ]; then
821 while [ $count -lt $max ]; do
822 if [ "$PMS_VERSION" == "V2" ]; then
826 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
827 if [ $trans != "NOTRANSIENT" ]; then
828 inputJson=$inputJson", \"transient\":$trans"
830 if [ $pt != "NOTYPE" ]; then
831 inputJson=$inputJson", \"policytype_id\":\"$pt\""
833 inputJson=$inputJson", \"policytype_id\":\"\""
835 if [ $noti != "NOURL" ]; then
836 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
839 data=$(sed 's/XXX/'${pid}'/g' $temp)
840 inputJson=$inputJson", \"policy_data\":$data"
841 inputJson="{$inputJson}"
842 echo $inputJson > $file
844 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
846 if [ $pt != "NOTYPE" ]; then
847 query=$query"&type=$pt"
850 if [ $trans != NOTRANSIENT ]; then
851 query=$query"&transient=$trans"
855 sed 's/XXX/'${pid}'/g' $temp > $file
857 res="$(__do_curl_to_api PA PUT $query $file)"
858 status=${res:${#res}-3}
859 echo -ne " Executing "$count"("$max")${SAMELINE}"
860 if [ $status -ne $1 ]; then
861 echo " Executed "$count"?("$max")"
862 __log_test_fail_status_code $1 $status
868 echo -ne " Executed "$count"("$max")${SAMELINE}"
876 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
877 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
878 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
879 # (Function for test scripts)
881 api_put_policy_batch() {
884 if [ "$PMS_VERSION" == "V2" ]; then
885 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
886 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
890 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
891 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
903 if [ "$PMS_VERSION" == "V2" ]; then
906 if [ $# -eq 9 ]; then
911 if [ $# -eq 8 ]; then
917 while [ $count -lt $max ]; do
918 if [ "$PMS_VERSION" == "V2" ]; then
921 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
922 if [ $trans != "NOTRANSIENT" ]; then
923 inputJson=$inputJson", \"transient\":$trans"
925 if [ $pt != "NOTYPE" ]; then
926 inputJson=$inputJson", \"policytype_id\":\"$pt\""
928 inputJson=$inputJson", \"policytype_id\":\"\""
930 if [ $noti != "NOURL" ]; then
931 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
934 data=$(sed 's/XXX/'${pid}'/g' $temp)
935 inputJson=$inputJson", \"policy_data\":$data"
936 inputJson="{$inputJson}"
937 echo $inputJson > $file
939 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
941 if [ $pt != "NOTYPE" ]; then
942 query=$query"&type=$pt"
945 if [ $trans != NOTRANSIENT ]; then
946 query=$query"&transient=$trans"
949 sed 's/XXX/'${pid}'/g' $temp > $file
951 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
952 status=${res:${#res}-3}
953 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
955 if [ $status -ne 200 ]; then
956 echo " Requested(batch) "$count"?("$max")"
957 __log_test_fail_status_code 200 $status
960 cid=${res:0:${#res}-3}
964 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
971 res="$(__do_curl_to_api PA RESPONSE $cid)"
972 status=${res:${#res}-3}
973 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
975 if [ $status -ne $1 ]; then
976 echo " Accepted(batch) "$count"?("$max")"
977 __log_test_fail_status_code $1 $status
982 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
991 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
992 # 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>
993 # 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>
994 # (Function for test scripts)
995 api_put_policy_parallel() {
998 if [ "$PMS_VERSION" == "V2" ]; then
999 if [ $# -ne 11 ]; then
1000 __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>" $@
1004 if [ $# -ne 10 ]; then
1005 __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>" $@
1009 resp_code=$1; shift;
1015 transient=$1; shift;
1016 if [ "$PMS_VERSION" == "V2" ]; then
1025 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1026 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1027 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1028 echo " Info - will execute over agent REST"
1030 if [ "$PMS_VERSION" == "V2" ]; then
1031 if [ $serv == "NOSERVICE" ]; then
1034 query="$PMS_API_PREFIX/v2/policies"
1036 if [ $serv == "NOSERVICE" ]; then
1039 query="/policy?service=$serv"
1041 if [ $type != "NOTYPE" ]; then
1042 query=$query"&type=$type"
1045 if [ $transient != NOTRANSIENT ]; then
1046 query=$query"&transient=$transient"
1050 urlbase=${PA_ADAPTER}${query}
1053 if [ $RUNMODE == "KUBE" ]; then
1054 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1055 httpproxy=$KUBE_PROXY_PATH
1059 for ((i=1; i<=$pids; i++))
1062 if [ -z "$uuid" ]; then
1065 echo "" > "./tmp/.pid${i}.res.txt"
1066 if [ "$PMS_VERSION" == "V2" ]; then
1067 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1069 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1072 done | xargs -n 1 -I{} -P $pids bash -c '{
1074 echo " Parallel process $arg started"
1075 tmp=$(< "./tmp/.pid${arg}.txt")
1076 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1079 for ((i=1; i<=$pids; i++))
1081 file="./tmp/.pid${i}.res.txt"
1083 if [ -z "$tmp" ]; then
1084 echo " Process $i : unknown result (result file empty"
1088 if [ $res == "0" ]; then
1089 echo " Process $i : OK - "${tmp:1}
1091 echo " Process $i : failed - "${tmp:1}
1096 if [ -z $msg ]; then
1097 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1101 __log_test_fail_general "One of more processes failed to execute"
1105 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1106 # args: <response-code> <policy-id> [count]
1107 # (Function for test scripts)
1108 api_delete_policy() {
1111 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1112 __print_err "<response-code> <policy-id> [count]" $@
1119 if [ $# -eq 3 ]; then
1125 while [ $count -lt $max ]; do
1126 if [ "$PMS_VERSION" == "V2" ]; then
1127 query="/v2/policies/"$UUID$pid
1129 query="/policy?id="$UUID$pid
1131 res="$(__do_curl_to_api PA DELETE $query)"
1132 status=${res:${#res}-3}
1133 echo -ne " Executing "$count"("$max")${SAMELINE}"
1135 if [ $status -ne $1 ]; then
1136 echo " Executed "$count"?("$max")"
1137 __log_test_fail_status_code $1 $status
1142 echo -ne " Executed "$count"("$max")${SAMELINE}"
1150 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1151 # args: <response-code> <policy-id> [count]
1152 # (Function for test scripts)
1153 api_delete_policy_batch() {
1156 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1157 __print_err "<response-code> <policy-id> [count]" $@
1164 if [ $# -eq 3 ]; then
1170 while [ $count -lt $max ]; do
1171 if [ "$PMS_VERSION" == "V2" ]; then
1172 query="/v2/policies/"$UUID$pid
1174 query="/policy?id="$UUID$pid
1176 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
1177 status=${res:${#res}-3}
1178 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1180 if [ $status -ne 200 ]; then
1181 echo " Requested(batch) "$count"?("$max")"
1182 __log_test_fail_status_code 200 $status
1185 cid=${res:0:${#res}-3}
1189 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1197 res="$(__do_curl_to_api PA RESPONSE $cid)"
1198 status=${res:${#res}-3}
1199 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1201 if [ $status -ne $1 ]; then
1202 echo " Deleted(batch) "$count"?("$max")"
1203 __log_test_fail_status_code $1 $status
1208 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1217 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1218 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1219 # (Function for test scripts)
1220 api_delete_policy_parallel() {
1223 if [ $# -ne 5 ]; then
1224 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1227 resp_code=$1; shift;
1233 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1234 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1235 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1236 echo " Info - will execute over agent REST"
1239 if [ "$PMS_VERSION" == "V2" ]; then
1240 query="$PMS_API_PREFIX/v2/policies/"
1245 urlbase=${PA_ADAPTER}${query}
1248 if [ $RUNMODE == "KUBE" ]; then
1249 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1250 httpproxy=$KUBE_PROXY_PATH
1254 for ((i=1; i<=$pids; i++))
1257 if [ -z "$uuid" ]; then
1260 echo "" > "./tmp/.pid${i}.del.res.txt"
1261 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1263 done | xargs -n 1 -I{} -P $pids bash -c '{
1265 echo " Parallel process $arg started"
1266 tmp=$(< "./tmp/.pid${arg}.del.txt")
1267 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1270 for ((i=1; i<=$pids; i++))
1272 file="./tmp/.pid${i}.del.res.txt"
1274 if [ -z "$tmp" ]; then
1275 echo " Process $i : unknown result (result file empty"
1279 if [ $res == "0" ]; then
1280 echo " Process $i : OK - "${tmp:1}
1282 echo " Process $i : failed - "${tmp:1}
1287 if [ -z $msg ]; then
1288 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1292 __log_test_fail_general "One of more processes failed to execute"
1296 # API Test function: GET /policy_ids and V2 GET /v2/policies
1297 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1298 # (Function for test scripts)
1299 api_get_policy_ids() {
1302 if [ $# -lt 4 ]; then
1303 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1309 if [ "$PMS_VERSION" == "V2" ]; then
1310 if [ $2 != "NORIC" ]; then
1311 queryparams="?ric_id="$2
1314 if [ $3 != "NOSERVICE" ]; then
1315 if [ -z $queryparams ]; then
1316 queryparams="?service_id="$3
1318 queryparams=$queryparams"&service_id="$3
1321 if [ $4 != "NOTYPE" ]; then
1322 if [ -z $queryparams ]; then
1323 queryparams="?policytype_id="$4
1325 queryparams=$queryparams"&policytype_id="$4
1329 query="/v2/policies"$queryparams
1331 if [ $2 != "NORIC" ]; then
1332 queryparams="?ric="$2
1335 if [ $3 != "NOSERVICE" ]; then
1336 if [ -z $queryparams ]; then
1337 queryparams="?service="$3
1339 queryparams=$queryparams"&service="$3
1342 if [ $4 != "NOTYPE" ]; then
1343 if [ -z $queryparams ]; then
1344 queryparams="?type="$4
1346 queryparams=$queryparams"&type="$4
1350 query="/policy_ids"$queryparams
1353 res="$(__do_curl_to_api PA GET $query)"
1354 status=${res:${#res}-3}
1356 if [ $status -ne $1 ]; then
1357 __log_test_fail_status_code $1 $status
1361 if [ $# -gt 4 ]; then
1362 body=${res:0:${#res}-3}
1365 for pid in ${@:5} ; do
1366 if [ "$targetJson" != "[" ]; then
1367 targetJson=$targetJson","
1369 if [ $pid != "NOID" ]; then
1370 targetJson=$targetJson"\"$UUID$pid\""
1374 targetJson=$targetJson"]"
1375 if [ "$PMS_VERSION" == "V2" ]; then
1376 targetJson="{\"policy_ids\": $targetJson}"
1378 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1379 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1381 if [ $res -ne 0 ]; then
1382 __log_test_fail_body
1391 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1392 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1393 # (Function for test scripts)
1394 api_get_policy_type() {
1397 if [ "$PMS_VERSION" != "V2" ]; then
1398 __log_test_fail_not_supported
1402 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1403 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1406 query="/v2/policy-types/$2"
1408 res="$(__do_curl_to_api PA GET $query)"
1409 status=${res:${#res}-3}
1411 if [ $status -ne $1 ]; then
1412 __log_test_fail_status_code $1 $status
1416 if [ $# -eq 3 ]; then
1418 body=${res:0:${#res}-3}
1421 targetJson="{\"policy_schema\":$targetJson}"
1422 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1423 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1425 if [ $res -ne 0 ]; then
1426 __log_test_fail_body
1435 # API Test function: GET /policy_schema
1436 # args: <response-code> <policy-type-id> [<schema-file>]
1437 # (Function for test scripts)
1438 api_get_policy_schema() {
1441 if [ "$PMS_VERSION" == "V2" ]; then
1442 __log_test_fail_not_supported
1446 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1447 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1450 query="/policy_schema?id=$2"
1451 res="$(__do_curl_to_api PA GET $query)"
1452 status=${res:${#res}-3}
1454 if [ $status -ne $1 ]; then
1455 __log_test_fail_status_code $1 $status
1459 if [ $# -eq 3 ]; then
1461 body=${res:0:${#res}-3}
1465 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1466 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1468 if [ $res -ne 0 ]; then
1469 __log_test_fail_body
1478 # API Test function: GET /policy_schemas
1479 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1480 # args(V2): <response-code>
1481 # (Function for test scripts)
1482 api_get_policy_schemas() {
1485 if [ "$PMS_VERSION" == "V2" ]; then
1486 if [ $# -ne 1 ]; then
1487 __print_err "<response-code>" $@
1491 if [ $# -lt 2 ]; then
1492 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1496 if [ "$PMS_VERSION" == "V2" ]; then
1497 query="/v2/policy-schemas"
1499 query="/policy_schemas"
1500 if [ $2 != "NORIC" ]; then
1501 query=$query"?ric="$2
1505 res="$(__do_curl_to_api PA GET $query)"
1506 status=${res:${#res}-3}
1508 if [ $status -ne $1 ]; then
1509 __log_test_fail_status_code $1 $status
1513 if [ $# -gt 2 ]; then
1514 body=${res:0:${#res}-3}
1517 for file in ${@:3} ; do
1518 if [ "$targetJson" != "[" ]; then
1519 targetJson=$targetJson","
1521 if [ $file == "NOFILE" ]; then
1522 targetJson=$targetJson"{}"
1524 targetJson=$targetJson$(< $file)
1528 targetJson=$targetJson"]"
1529 if [ "$PMS_VERSION" == "V2" ]; then
1530 targetJson="{\"policy_schemas\": $targetJson }"
1532 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1533 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1535 if [ $res -ne 0 ]; then
1536 __log_test_fail_body
1545 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1546 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1547 # (Function for test scripts)
1548 api_get_policy_status() {
1551 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1552 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1558 if [ $3 == "STD" ]; then
1559 targetJson="{\"enforceStatus\":\"$4\""
1560 if [ $# -eq 5 ]; then
1561 targetJson=$targetJson",\"reason\":\"$5\""
1563 targetJson=$targetJson"}"
1564 elif [ $3 == "STD2" ]; then
1565 if [ $4 == "EMPTY" ]; then
1566 targetJson="{\"enforceStatus\":\"\""
1568 targetJson="{\"enforceStatus\":\"$4\""
1570 if [ $# -eq 5 ]; then
1571 if [ $5 == "EMPTY" ]; then
1572 targetJson=$targetJson",\"enforceReason\":\"\""
1574 targetJson=$targetJson",\"enforceReason\":\"$5\""
1577 targetJson=$targetJson"}"
1578 elif [ $3 == "OSC" ]; then
1579 targetJson="{\"instance_status\":\"$4\""
1580 if [ $# -eq 5 ]; then
1581 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1583 targetJson=$targetJson",\"created_at\":\"????\"}"
1585 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1589 if [ "$PMS_VERSION" == "V2" ]; then
1590 query="/v2/policies/$UUID$2/status"
1591 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1593 query="/policy_status?id="$UUID$2
1596 res="$(__do_curl_to_api PA GET $query)"
1597 status=${res:${#res}-3}
1599 if [ $status -ne $1 ]; then
1600 __log_test_fail_status_code $1 $status
1604 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1605 body=${res:0:${#res}-3}
1606 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1608 if [ $res -ne 0 ]; then
1609 __log_test_fail_body
1617 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1618 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1619 # (Function for test scripts)
1620 api_get_policy_types() {
1623 if [ $# -lt 1 ]; then
1624 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1628 if [ "$PMS_VERSION" == "V2" ]; then
1629 if [ $# -eq 1 ]; then
1630 query="/v2/policy-types"
1631 elif [ $2 == "NORIC" ]; then
1632 query="/v2/policy-types"
1634 query="/v2/policy-types?ric_id=$2"
1637 if [ $# -eq 1 ]; then
1638 query="/policy_types"
1639 elif [ $2 == "NORIC" ]; then
1640 query="/policy_types"
1642 query="/policy_types?ric=$2"
1646 res="$(__do_curl_to_api PA GET $query)"
1647 status=${res:${#res}-3}
1649 if [ $status -ne $1 ]; then
1650 __log_test_fail_status_code $1 $status
1654 if [ $# -gt 2 ]; then
1655 body=${res:0:${#res}-3}
1658 for pid in ${@:3} ; do
1659 if [ "$targetJson" != "[" ]; then
1660 targetJson=$targetJson","
1662 if [ $pid == "EMPTY" ]; then
1665 targetJson=$targetJson"\"$pid\""
1668 targetJson=$targetJson"]"
1669 if [ "$PMS_VERSION" == "V2" ]; then
1670 targetJson="{\"policytype_ids\": $targetJson }"
1672 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1673 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1675 if [ $res -ne 0 ]; then
1676 __log_test_fail_body
1685 #########################################################
1686 #### Test case functions Health check
1687 #########################################################
1689 # API Test function: GET /status and V2 GET /status
1690 # args: <response-code>
1691 # (Function for test scripts)
1694 if [ $# -ne 1 ]; then
1695 __print_err "<response-code>" $@
1698 if [ "$PMS_VERSION" == "V2" ]; then
1703 res="$(__do_curl_to_api PA GET $query)"
1704 status=${res:${#res}-3}
1706 if [ $status -ne $1 ]; then
1707 __log_test_fail_status_code $1 $status
1715 #########################################################
1716 #### Test case functions RIC Repository
1717 #########################################################
1719 # API Test function: GET /ric and V2 GET /v2/rics/ric
1720 # args: <reponse-code> <management-element-id> [<ric-id>]
1721 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1722 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1723 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1726 # (Function for test scripts)
1730 if [ "$PMS_VERSION" == "V2" ]; then
1731 if [ $# -lt 3 ]; then
1732 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1736 if [ $2 != "NOME" ]; then
1737 search="?managed_element_id="$2
1739 if [ $3 != "NORIC" ]; then
1740 if [ -z $search ]; then
1743 search=$search"&ric_id="$3
1746 query="/v2/rics/ric"$search
1748 res="$(__do_curl_to_api PA GET $query)"
1749 status=${res:${#res}-3}
1751 if [ $status -ne $1 ]; then
1752 __log_test_fail_status_code $1 $status
1756 if [ $# -gt 3 ]; then
1757 body=${res:0:${#res}-3}
1758 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1759 if [ $res -ne 0 ]; then
1760 __log_test_fail_general "Could not create target ric info json"
1764 targetJson=$(<./tmp/.tmp_rics.json)
1765 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1766 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1767 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1768 if [ $res -ne 0 ]; then
1769 __log_test_fail_body
1774 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1775 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1779 query="/ric?managedElementId="$2
1781 res="$(__do_curl_to_api PA GET $query)"
1782 status=${res:${#res}-3}
1784 if [ $status -ne $1 ]; then
1785 __log_test_fail_status_code $1 $status
1789 if [ $# -eq 3 ]; then
1790 body=${res:0:${#res}-3}
1791 if [ "$body" != "$3" ]; then
1792 __log_test_fail_body
1801 # API test function: GET /rics and V2 GET /v2/rics
1802 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1803 # 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_........."
1804 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1805 # (Function for test scripts)
1809 if [ $# -lt 2 ]; then
1810 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1814 if [ "$PMS_VERSION" == "V2" ]; then
1816 if [ $2 != "NOTYPE" ]; then
1817 query="/v2/rics?policytype_id="$2
1821 if [ $2 != "NOTYPE" ]; then
1822 query="/rics?policyType="$2
1826 res="$(__do_curl_to_api PA GET $query)"
1827 status=${res:${#res}-3}
1829 if [ $status -ne $1 ]; then
1830 __log_test_fail_status_code $1 $status
1834 if [ $# -gt 2 ]; then
1835 body=${res:0:${#res}-3}
1836 if [ "$PMS_VERSION" == "V2" ]; then
1837 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1839 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1841 if [ $res -ne 0 ]; then
1842 __log_test_fail_general "Could not create target ric info json"
1846 targetJson=$(<./tmp/.tmp_rics.json)
1847 if [ "$PMS_VERSION" == "V2" ]; then
1848 targetJson="{\"rics\": $targetJson }"
1850 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1851 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1852 if [ $res -ne 0 ]; then
1853 __log_test_fail_body
1862 ##################################################################
1863 #### API Test case functions Service registry and supervision ####
1864 ##################################################################
1866 # API test function: PUT /service and V2 PUT /service
1867 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1868 # (Function for test scripts)
1871 if [ $# -ne 4 ]; then
1872 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1876 if [ "$PMS_VERSION" == "V2" ]; then
1877 query="/v2/services"
1878 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1881 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1883 file="./tmp/.tmp.json"
1884 echo "$json" > $file
1886 res="$(__do_curl_to_api PA PUT $query $file)"
1887 status=${res:${#res}-3}
1889 if [ $status -ne $1 ]; then
1890 __log_test_fail_status_code $1 $status
1898 # API test function: GET /services and V2 GET /v2/services
1899 #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>]* )]
1900 # (Function for test scripts)
1901 api_get_services() {
1903 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1905 if [ $# -eq 1 ]; then
1907 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1909 elif [ $# -eq 5 ]; then
1911 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1913 if [ $(($argLen%3)) -eq 0 ]; then
1918 if [ $paramError -ne 0 ]; then
1919 __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>]* )]" $@
1923 if [ "$PMS_VERSION" == "V2" ]; then
1924 query="/v2/services"
1926 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1927 query="/v2/services?service_id="$2
1932 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1933 query="/services?name="$2
1936 res="$(__do_curl_to_api PA GET $query)"
1937 status=${res:${#res}-3}
1939 if [ $status -ne $1 ]; then
1940 __log_test_fail_status_code $1 $status
1944 if [ $# -gt 2 ]; then
1945 variableArgCount=$(($#-2))
1946 body=${res:0:${#res}-3}
1950 while [ $cntr -lt $variableArgCount ]; do
1951 servicename=$1; shift;
1954 if [ $cntr -gt 0 ]; then
1955 targetJson=$targetJson","
1957 # timeSinceLastActivitySeconds value cannot be checked since value varies
1958 if [ "$PMS_VERSION" == "V2" ]; then
1959 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1961 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1965 targetJson=$targetJson"]"
1966 if [ "$PMS_VERSION" == "V2" ]; then
1967 targetJson="{\"service_list\": $targetJson }"
1969 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1970 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1971 if [ $res -ne 0 ]; then
1972 __log_test_fail_body
1981 # API test function: GET /services V2 GET /v2/services - (only checking service names)
1982 # args: <response-code> [<service-name>]*"
1983 # (Function for test scripts)
1984 api_get_service_ids() {
1987 if [ $# -lt 1 ]; then
1988 __print_err "<response-code> [<service-name>]*" $@
1992 if [ "$PMS_VERSION" == "V2" ]; then
1993 query="/v2/services"
1997 res="$(__do_curl_to_api PA GET $query)"
1998 status=${res:${#res}-3}
2000 if [ $status -ne $1 ]; then
2001 __log_test_fail_status_code $1 $status
2005 body=${res:0:${#res}-3}
2007 for rapp in ${@:2} ; do
2008 if [ "$targetJson" != "[" ]; then
2009 targetJson=$targetJson","
2011 if [ "$PMS_VERSION" == "V2" ]; then
2012 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2014 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2018 targetJson=$targetJson"]"
2019 if [ "$PMS_VERSION" == "V2" ]; then
2020 targetJson="{\"service_list\": $targetJson }"
2022 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2023 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2025 if [ $res -ne 0 ]; then
2026 __log_test_fail_body
2034 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2035 # args: <response-code> <service-name>
2036 # (Function for test scripts)
2037 api_delete_services() {
2040 if [ $# -ne 2 ]; then
2041 __print_err "<response-code> <service-name>" $@
2044 if [ "$PMS_VERSION" == "V2" ]; then
2045 query="/v2/services/"$2
2047 query="/services?name="$2
2049 res="$(__do_curl_to_api PA DELETE $query)"
2050 status=${res:${#res}-3}
2052 if [ $status -ne $1 ]; then
2053 __log_test_fail_status_code $1 $status
2061 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2062 # args: <response-code> <service-name>
2063 # (Function for test scripts)
2064 api_put_services_keepalive() {
2067 if [ $# -ne 2 ]; then
2068 __print_err "<response-code> <service-name>" $@
2071 if [ "$PMS_VERSION" == "V2" ]; then
2072 query="/v2/services/$2/keepalive"
2074 query="/services/keepalive?name="$2
2077 res="$(__do_curl_to_api PA PUT $query)"
2078 status=${res:${#res}-3}
2080 if [ $status -ne $1 ]; then
2081 __log_test_fail_status_code $1 $status
2089 ##################################################################
2090 #### API Test case functions Configuration ####
2091 ##################################################################
2093 # API Test function: PUT /v2/configuration
2094 # args: <response-code> <config-file>
2095 # (Function for test scripts)
2096 api_put_configuration() {
2099 if [ "$PMS_VERSION" != "V2" ]; then
2100 __log_test_fail_not_supported
2104 if [ $# -ne 2 ]; then
2105 __print_err "<response-code> <config-file>" $@
2108 if [ ! -f $2 ]; then
2109 _log_test_fail_general "Config file "$2", does not exist"
2113 inputJson="{\"config\":"$inputJson"}"
2114 file="./tmp/.config.json"
2115 echo $inputJson > $file
2116 query="/v2/configuration"
2117 res="$(__do_curl_to_api PA PUT $query $file)"
2118 status=${res:${#res}-3}
2120 if [ $status -ne $1 ]; then
2121 __log_test_fail_status_code $1 $status
2129 # API Test function: GET /v2/configuration
2130 # args: <response-code> [<config-file>]
2131 # (Function for test scripts)
2132 api_get_configuration() {
2135 if [ "$PMS_VERSION" != "V2" ]; then
2136 __log_test_fail_not_supported
2140 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2141 __print_err "<response-code> [<config-file>]" $@
2144 if [ ! -f $2 ]; then
2145 _log_test_fail_general "Config file "$2" for comparison, does not exist"
2149 query="/v2/configuration"
2150 res="$(__do_curl_to_api PA GET $query)"
2151 status=${res:${#res}-3}
2153 if [ $status -ne $1 ]; then
2154 __log_test_fail_status_code $1 $status
2158 if [ $# -eq 2 ]; then
2160 body=${res:0:${#res}-3}
2163 targetJson="{\"config\":"$targetJson"}"
2164 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2165 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2167 if [ $res -ne 0 ]; then
2168 __log_test_fail_body