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 ###########################
100 ### Policy Agents functions
101 ###########################
103 # All calls to the agent will be directed to the agent REST interface from now on
105 # (Function for test scripts)
106 use_agent_rest_http() {
107 echo -e $BOLD"Agent protocol setting"$EBOLD
108 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
110 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
112 PA_ADAPTER_TYPE="REST"
117 # All calls to the agent will be directed to the agent REST interface from now on
119 # (Function for test scripts)
120 use_agent_rest_https() {
121 echo -e $BOLD"Agent protocol setting"$EBOLD
122 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
124 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
126 PA_ADAPTER_TYPE="REST"
131 # All calls to the agent will be directed to the agent dmaap interface over http from now on
133 # (Function for test scripts)
134 use_agent_dmaap_http() {
135 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
136 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
137 PA_ADAPTER_TYPE="MR-HTTP"
141 # All calls to the agent will be directed to the agent dmaap interface over https from now on
143 # (Function for test scripts)
144 use_agent_dmaap_https() {
145 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
146 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
147 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
148 PA_ADAPTER_TYPE="MR-HTTPS"
152 # Start the policy agent
153 # args: (docker) PROXY|NOPROXY <config-file>
154 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
155 # (Function for test scripts)
156 start_policy_agent() {
157 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
159 if [ $RUNMODE == "KUBE" ]; then
161 # Check if app shall be fully managed by the test script
162 __check_included_image "PA"
165 # Check if app shall only be used by the testscipt
166 __check_prestarted_image "PA"
169 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
170 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
171 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
174 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
175 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
176 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
180 if [ $retcode_p -eq 0 ]; then
181 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
182 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
183 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
186 if [ $retcode_i -eq 0 ]; then
188 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
190 #Check if nonrtric namespace exists, if not create it
191 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
193 #Export all vars needed for service and deployment
194 export POLICY_AGENT_APP_NAME
195 export KUBE_NONRTRIC_NAMESPACE
196 export POLICY_AGENT_IMAGE
197 export POLICY_AGENT_INTERNAL_PORT
198 export POLICY_AGENT_INTERNAL_SECURE_PORT
199 export POLICY_AGENT_EXTERNAL_PORT
200 export POLICY_AGENT_EXTERNAL_SECURE_PORT
201 export POLICY_AGENT_CONFIG_MOUNT_PATH
202 export POLICY_AGENT_DATA_MOUNT_PATH
203 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
204 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
205 export POLICY_AGENT_PKG_NAME
206 if [ $1 == "PROXY" ]; then
207 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
208 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
209 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
210 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
212 echo " Configured with http proxy"
215 AGENT_HTTP_PROXY_CONFIG_PORT=0
216 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
217 echo " Configured without http proxy"
219 export AGENT_HTTP_PROXY_CONFIG_PORT
220 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
223 # Create config map for config
224 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
226 output_yaml=$PWD/tmp/pa_cfc.yaml
227 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
229 # Create config map for data
230 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
231 if [ $# -lt 3 ]; then
232 #create empty dummy file
233 echo "{}" > $data_json
237 output_yaml=$PWD/tmp/pa_cfd.yaml
238 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
241 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
242 output_yaml=$PWD/tmp/pa_svc.yaml
243 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
246 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
247 output_yaml=$PWD/tmp/pa_app.yaml
248 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
252 echo " Retrieving host and ports for service..."
253 PA_HOST_NAME=$(__kube_get_service_host $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
254 POLICY_AGENT_EXTERNAL_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
255 POLICY_AGENT_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
257 echo " Host IP, http port, https port: $PA_HOST_NAME $POLICY_AGENT_EXTERNAL_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT"
259 if [ $PA_HTTPX == "http" ]; then
260 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
262 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
264 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
266 if [ $PA_ADAPTER_TYPE == "REST" ]; then
270 __check_included_image 'PA'
271 if [ $? -eq 1 ]; then
272 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
273 echo -e $RED"The Policy Agent will not be started"$ERED
277 #Export all vars needed for docker-compose
278 export POLICY_AGENT_APP_NAME
279 export POLICY_AGENT_APP_NAME_ALIAS
280 export POLICY_AGENT_INTERNAL_PORT
281 export POLICY_AGENT_EXTERNAL_PORT
282 export POLICY_AGENT_INTERNAL_SECURE_PORT
283 export POLICY_AGENT_EXTERNAL_SECURE_PORT
285 export CONSUL_INTERNAL_PORT
286 export CONFIG_BINDING_SERVICE
287 export POLICY_AGENT_CONFIG_KEY
288 export DOCKER_SIM_NWNAME
289 export POLICY_AGENT_HOST_MNT_DIR
290 export POLICY_AGENT_CONFIG_MOUNT_PATH
291 export POLICY_AGENT_CONFIG_FILE
292 export POLICY_AGENT_PKG_NAME
293 export POLICY_AGENT_DISPLAY_NAME
295 if [ $1 == "PROXY" ]; then
296 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
297 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
298 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
299 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
301 echo " Configured with http proxy"
304 AGENT_HTTP_PROXY_CONFIG_PORT=0
305 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
306 echo " Configured without http proxy"
308 export AGENT_HTTP_PROXY_CONFIG_PORT
309 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
311 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
313 envsubst < $2 > $dest_file
315 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
317 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
323 # Load the the appl config for the agent into a config map
324 agent_load_config() {
325 echo -e $BOLD"Agent - load config from "$EBOLD$1
326 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
328 output_yaml=$PWD/tmp/pa_cfd.yaml
329 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
334 # Turn on debug level tracing in the agent
336 # (Function for test scripts)
338 echo -e $BOLD"Setting agent debug logging"$EBOLD
339 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
340 result=$(__do_curl "$curlString")
341 if [ $? -ne 0 ]; then
342 __print_err "could not set debug mode" $@
350 # Turn on trace level tracing in the agent
352 # (Function for test scripts)
354 echo -e $BOLD"Setting agent trace logging"$EBOLD
355 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
356 result=$(__do_curl "$curlString")
357 if [ $? -ne 0 ]; then
358 __print_err "could not set trace mode" $@
366 # Perform curl retries when making direct call to the agent for the specified http response codes
367 # Speace separated list of http response codes
368 # args: [<response-code>]*
369 use_agent_retries() {
370 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
376 # Check the agent logs for WARNINGs and ERRORs
378 # (Function for test scripts)
379 check_policy_agent_logs() {
380 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
383 #########################################################
384 #### Test case functions A1 Policy management service
385 #########################################################
387 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
388 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
389 # args: json:<url> <target-value> [<timeout-in-seconds]
390 # (Function for test scripts)
392 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
393 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
394 if [[ $1 == "json:"* ]]; then
395 if [ "$PMS_VERSION" == "V2" ]; then
396 __var_test "Policy Agent" $PA_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
398 __var_test "Policy Agent" $PA_PATH"/" $1 "=" $2 $3
403 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
407 # API Test function: GET /policies and V2 GET /v2/policy-instances
408 # 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>]*]
409 # 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>]*]
410 # (Function for test scripts)
414 if [ "$PMS_VERSION" == "V2" ]; then
416 variableParams=$(($#-4))
417 if [ $# -lt 4 ]; then
419 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
421 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
425 if [ $paramError -ne 0 ]; then
426 __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>]*]" $@
431 variableParams=$(($#-4))
432 if [ $# -lt 4 ]; then
434 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
436 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
440 if [ $paramError -ne 0 ]; then
441 __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>]*]" $@
447 if [ "$PMS_VERSION" == "V2" ]; then
448 if [ $2 != "NORIC" ]; then
449 queryparams="?ric_id="$2
451 if [ $3 != "NOSERVICE" ]; then
452 if [ -z $queryparams ]; then
453 queryparams="?service_id="$3
455 queryparams=$queryparams"&service_id="$3
458 if [ $4 != "NOTYPE" ]; then
459 if [ -z $queryparams ]; then
460 queryparams="?policytype_id="$4
462 queryparams=$queryparams"&policytype_id="$4
466 query="/v2/policy-instances"$queryparams
467 res="$(__do_curl_to_api PA GET $query)"
468 status=${res:${#res}-3}
470 if [ $status -ne $1 ]; then
471 __log_test_fail_status_code $1 $status
475 if [ $# -gt 4 ]; then
476 body=${res:0:${#res}-3}
477 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
483 for ((i=0; i<$(($#-4)); i=i+7)); do
485 if [ "$targetJson" != "[" ]; then
486 targetJson=$targetJson","
488 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
489 if [ "${arr[$i+3]}" == "EMPTY" ]; then
490 targetJson=$targetJson"\"\","
492 targetJson=$targetJson"\"${arr[$i+3]}\","
494 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
496 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
498 targetJson=$targetJson"\"policy_data\":"$json"}"
502 targetJson=$targetJson"]"
503 targetJson="{\"policies\": $targetJson}"
504 echo "TARGET JSON: $targetJson" >> $HTTPLOG
505 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
507 if [ $res -ne 0 ]; then
513 if [ $2 != "NORIC" ]; then
514 queryparams="?ric="$2
516 if [ $3 != "NOSERVICE" ]; then
517 if [ -z $queryparams ]; then
518 queryparams="?service="$3
520 queryparams=$queryparams"&service="$3
523 if [ $4 != "NOTYPE" ]; then
524 if [ -z $queryparams ]; then
525 queryparams="?type="$4
527 queryparams=$queryparams"&type="$4
531 query="/policies"$queryparams
532 res="$(__do_curl_to_api PA GET $query)"
533 status=${res:${#res}-3}
535 if [ $status -ne $1 ]; then
536 __log_test_fail_status_code $1 $status
540 if [ $# -gt 4 ]; then
541 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
544 body=${res:0:${#res}-3}
548 for ((i=0; i<$(($#-4)); i=i+5)); do
550 if [ "$targetJson" != "[" ]; then
551 targetJson=$targetJson","
553 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
554 if [ "${arr[$i+3]}" == "EMPTY" ]; then
555 targetJson=$targetJson"\"\","
557 targetJson=$targetJson"\"${arr[$i+3]}\","
560 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
562 targetJson=$targetJson"\"json\":"$json"}"
566 targetJson=$targetJson"]"
567 echo "TARGET JSON: $targetJson" >> $HTTPLOG
568 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
570 if [ $res -ne 0 ]; then
583 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
584 # args: <response-code> <policy-id> [<template-file>]
585 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
587 # (Function for test scripts)
592 if [ "$PMS_VERSION" == "V2" ]; then
593 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
594 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
597 query="/v2/policies/$UUID$2"
599 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
600 __print_err "<response-code> <policy-id> [<template-file>] " $@
603 query="/policy?id=$UUID$2"
605 res="$(__do_curl_to_api PA GET $query)"
606 status=${res:${#res}-3}
608 if [ $status -ne $1 ]; then
609 __log_test_fail_status_code $1 $status
613 if [ "$PMS_VERSION" == "V2" ]; then
614 if [ $# -eq 8 ]; then
616 #Create a policy json to compare with
617 body=${res:0:${#res}-3}
619 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
620 if [ $7 != "NOTRANSIENT" ]; then
621 targetJson=$targetJson", \"transient\":$7"
623 if [ $6 != "NOTYPE" ]; then
624 targetJson=$targetJson", \"policytype_id\":\"$6\""
626 targetJson=$targetJson", \"policytype_id\":\"\""
628 if [ $8 != "NOURL" ]; then
629 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
632 data=$(sed 's/XXX/'${2}'/g' $3)
633 targetJson=$targetJson", \"policy_data\":$data"
634 targetJson="{$targetJson}"
636 echo "TARGET JSON: $targetJson" >> $HTTPLOG
637 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
638 if [ $res -ne 0 ]; then
644 if [ $# -eq 3 ]; then
645 #Create a policy json to compare with
646 body=${res:0:${#res}-3}
648 sed 's/XXX/'${2}'/g' $3 > $file
649 targetJson=$(< $file)
650 echo "TARGET JSON: $targetJson" >> $HTTPLOG
651 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
652 if [ $res -ne 0 ]; then
662 # API Test function: PUT /policy and V2 PUT /policies
663 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
664 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
665 # (Function for test scripts)
669 if [ "$PMS_VERSION" == "V2" ]; then
670 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
671 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
675 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
676 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
689 if [ "$PMS_VERSION" == "V2" ]; then
692 if [ $# -eq 9 ]; then
697 if [ $# -eq 8 ]; then
702 while [ $count -lt $max ]; do
703 if [ "$PMS_VERSION" == "V2" ]; then
707 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
708 if [ $trans != "NOTRANSIENT" ]; then
709 inputJson=$inputJson", \"transient\":$trans"
711 if [ $pt != "NOTYPE" ]; then
712 inputJson=$inputJson", \"policytype_id\":\"$pt\""
714 inputJson=$inputJson", \"policytype_id\":\"\""
716 if [ $noti != "NOURL" ]; then
717 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
720 data=$(sed 's/XXX/'${pid}'/g' $temp)
721 inputJson=$inputJson", \"policy_data\":$data"
722 inputJson="{$inputJson}"
723 echo $inputJson > $file
725 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
727 if [ $pt != "NOTYPE" ]; then
728 query=$query"&type=$pt"
731 if [ $trans != NOTRANSIENT ]; then
732 query=$query"&transient=$trans"
736 sed 's/XXX/'${pid}'/g' $temp > $file
738 res="$(__do_curl_to_api PA PUT $query $file)"
739 status=${res:${#res}-3}
740 echo -ne " Executing "$count"("$max")${SAMELINE}"
741 if [ $status -ne $1 ]; then
742 echo " Executed "$count"?("$max")"
743 __log_test_fail_status_code $1 $status
749 echo -ne " Executed "$count"("$max")${SAMELINE}"
757 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
758 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
759 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
760 # (Function for test scripts)
762 api_put_policy_batch() {
765 if [ "$PMS_VERSION" == "V2" ]; then
766 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
767 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
771 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
772 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
784 if [ "$PMS_VERSION" == "V2" ]; then
787 if [ $# -eq 9 ]; then
792 if [ $# -eq 8 ]; then
798 while [ $count -lt $max ]; do
799 if [ "$PMS_VERSION" == "V2" ]; then
802 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
803 if [ $trans != "NOTRANSIENT" ]; then
804 inputJson=$inputJson", \"transient\":$trans"
806 if [ $pt != "NOTYPE" ]; then
807 inputJson=$inputJson", \"policytype_id\":\"$pt\""
809 inputJson=$inputJson", \"policytype_id\":\"\""
811 if [ $noti != "NOURL" ]; then
812 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
815 data=$(sed 's/XXX/'${pid}'/g' $temp)
816 inputJson=$inputJson", \"policy_data\":$data"
817 inputJson="{$inputJson}"
818 echo $inputJson > $file
820 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
822 if [ $pt != "NOTYPE" ]; then
823 query=$query"&type=$pt"
826 if [ $trans != NOTRANSIENT ]; then
827 query=$query"&transient=$trans"
830 sed 's/XXX/'${pid}'/g' $temp > $file
832 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
833 status=${res:${#res}-3}
834 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
836 if [ $status -ne 200 ]; then
837 echo " Requested(batch) "$count"?("$max")"
838 __log_test_fail_status_code 200 $status
841 cid=${res:0:${#res}-3}
845 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
852 res="$(__do_curl_to_api PA RESPONSE $cid)"
853 status=${res:${#res}-3}
854 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
856 if [ $status -ne $1 ]; then
857 echo " Accepted(batch) "$count"?("$max")"
858 __log_test_fail_status_code $1 $status
863 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
872 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
873 # 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>
874 # 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>
875 # (Function for test scripts)
876 api_put_policy_parallel() {
879 if [ "$PMS_VERSION" == "V2" ]; then
880 if [ $# -ne 11 ]; then
881 __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>" $@
885 if [ $# -ne 10 ]; then
886 __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>" $@
897 if [ "$PMS_VERSION" == "V2" ]; then
906 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
907 if [ $PA_ADAPTER_TYPE != "REST" ]; then
908 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
909 echo " Info - will execute over agent REST"
911 if [ "$PMS_VERSION" == "V2" ]; then
912 if [ $serv == "NOSERVICE" ]; then
915 query="$PMS_API_PREFIX/v2/policies"
917 if [ $serv == "NOSERVICE" ]; then
920 query="/policy?service=$serv"
922 if [ $type != "NOTYPE" ]; then
923 query=$query"&type=$type"
926 if [ $transient != NOTRANSIENT ]; then
927 query=$query"&transient=$transient"
931 urlbase=${PA_ADAPTER}${query}
934 if [ $RUNMODE == "KUBE" ]; then
935 if [ ! -z "$KUBE_PROXY_PATH" ]; then
936 httpproxy=$KUBE_PROXY_PATH
940 for ((i=1; i<=$pids; i++))
943 if [ -z "$uuid" ]; then
946 echo "" > "./tmp/.pid${i}.res.txt"
947 if [ "$PMS_VERSION" == "V2" ]; then
948 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
950 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
953 done | xargs -n 1 -I{} -P $pids bash -c '{
955 echo " Parallel process $arg started"
956 tmp=$(< "./tmp/.pid${arg}.txt")
957 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
960 for ((i=1; i<=$pids; i++))
962 file="./tmp/.pid${i}.res.txt"
964 if [ -z "$tmp" ]; then
965 echo " Process $i : unknown result (result file empty"
969 if [ $res == "0" ]; then
970 echo " Process $i : OK - "${tmp:1}
972 echo " Process $i : failed - "${tmp:1}
978 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
982 __log_test_fail_general "One of more processes failed to execute"
986 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
987 # args: <response-code> <policy-id> [count]
988 # (Function for test scripts)
989 api_delete_policy() {
992 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
993 __print_err "<response-code> <policy-id> [count]" $@
1000 if [ $# -eq 3 ]; then
1006 while [ $count -lt $max ]; do
1007 if [ "$PMS_VERSION" == "V2" ]; then
1008 query="/v2/policies/"$UUID$pid
1010 query="/policy?id="$UUID$pid
1012 res="$(__do_curl_to_api PA DELETE $query)"
1013 status=${res:${#res}-3}
1014 echo -ne " Executing "$count"("$max")${SAMELINE}"
1016 if [ $status -ne $1 ]; then
1017 echo " Executed "$count"?("$max")"
1018 __log_test_fail_status_code $1 $status
1023 echo -ne " Executed "$count"("$max")${SAMELINE}"
1031 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1032 # args: <response-code> <policy-id> [count]
1033 # (Function for test scripts)
1034 api_delete_policy_batch() {
1037 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1038 __print_err "<response-code> <policy-id> [count]" $@
1045 if [ $# -eq 3 ]; then
1051 while [ $count -lt $max ]; do
1052 if [ "$PMS_VERSION" == "V2" ]; then
1053 query="/v2/policies/"$UUID$pid
1055 query="/policy?id="$UUID$pid
1057 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
1058 status=${res:${#res}-3}
1059 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1061 if [ $status -ne 200 ]; then
1062 echo " Requested(batch) "$count"?("$max")"
1063 __log_test_fail_status_code 200 $status
1066 cid=${res:0:${#res}-3}
1070 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1078 res="$(__do_curl_to_api PA RESPONSE $cid)"
1079 status=${res:${#res}-3}
1080 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1082 if [ $status -ne $1 ]; then
1083 echo " Deleted(batch) "$count"?("$max")"
1084 __log_test_fail_status_code $1 $status
1089 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1098 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1099 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1100 # (Function for test scripts)
1101 api_delete_policy_parallel() {
1104 if [ $# -ne 5 ]; then
1105 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1108 resp_code=$1; shift;
1114 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1115 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1116 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1117 echo " Info - will execute over agent REST"
1120 if [ "$PMS_VERSION" == "V2" ]; then
1121 query="$PMS_API_PREFIX/v2/policies/"
1126 urlbase=${PA_ADAPTER}${query}
1129 if [ $RUNMODE == "KUBE" ]; then
1130 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1131 httpproxy=$KUBE_PROXY_PATH
1135 for ((i=1; i<=$pids; i++))
1138 if [ -z "$uuid" ]; then
1141 echo "" > "./tmp/.pid${i}.del.res.txt"
1142 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1144 done | xargs -n 1 -I{} -P $pids bash -c '{
1146 echo " Parallel process $arg started"
1147 tmp=$(< "./tmp/.pid${arg}.del.txt")
1148 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1151 for ((i=1; i<=$pids; i++))
1153 file="./tmp/.pid${i}.del.res.txt"
1155 if [ -z "$tmp" ]; then
1156 echo " Process $i : unknown result (result file empty"
1160 if [ $res == "0" ]; then
1161 echo " Process $i : OK - "${tmp:1}
1163 echo " Process $i : failed - "${tmp:1}
1168 if [ -z $msg ]; then
1169 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1173 __log_test_fail_general "One of more processes failed to execute"
1177 # API Test function: GET /policy_ids and V2 GET /v2/policies
1178 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1179 # (Function for test scripts)
1180 api_get_policy_ids() {
1183 if [ $# -lt 4 ]; then
1184 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1190 if [ "$PMS_VERSION" == "V2" ]; then
1191 if [ $2 != "NORIC" ]; then
1192 queryparams="?ric_id="$2
1195 if [ $3 != "NOSERVICE" ]; then
1196 if [ -z $queryparams ]; then
1197 queryparams="?service_id="$3
1199 queryparams=$queryparams"&service_id="$3
1202 if [ $4 != "NOTYPE" ]; then
1203 if [ -z $queryparams ]; then
1204 queryparams="?policytype_id="$4
1206 queryparams=$queryparams"&policytype_id="$4
1210 query="/v2/policies"$queryparams
1212 if [ $2 != "NORIC" ]; then
1213 queryparams="?ric="$2
1216 if [ $3 != "NOSERVICE" ]; then
1217 if [ -z $queryparams ]; then
1218 queryparams="?service="$3
1220 queryparams=$queryparams"&service="$3
1223 if [ $4 != "NOTYPE" ]; then
1224 if [ -z $queryparams ]; then
1225 queryparams="?type="$4
1227 queryparams=$queryparams"&type="$4
1231 query="/policy_ids"$queryparams
1234 res="$(__do_curl_to_api PA GET $query)"
1235 status=${res:${#res}-3}
1237 if [ $status -ne $1 ]; then
1238 __log_test_fail_status_code $1 $status
1242 if [ $# -gt 4 ]; then
1243 body=${res:0:${#res}-3}
1246 for pid in ${@:5} ; do
1247 if [ "$targetJson" != "[" ]; then
1248 targetJson=$targetJson","
1250 if [ $pid != "NOID" ]; then
1251 targetJson=$targetJson"\"$UUID$pid\""
1255 targetJson=$targetJson"]"
1256 if [ "$PMS_VERSION" == "V2" ]; then
1257 targetJson="{\"policy_ids\": $targetJson}"
1259 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1260 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1262 if [ $res -ne 0 ]; then
1263 __log_test_fail_body
1272 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1273 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1274 # (Function for test scripts)
1275 api_get_policy_type() {
1278 if [ "$PMS_VERSION" != "V2" ]; then
1279 __log_test_fail_not_supported
1283 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1284 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1287 query="/v2/policy-types/$2"
1289 res="$(__do_curl_to_api PA GET $query)"
1290 status=${res:${#res}-3}
1292 if [ $status -ne $1 ]; then
1293 __log_test_fail_status_code $1 $status
1297 if [ $# -eq 3 ]; then
1299 body=${res:0:${#res}-3}
1302 targetJson="{\"policy_schema\":$targetJson}"
1303 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1304 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1306 if [ $res -ne 0 ]; then
1307 __log_test_fail_body
1316 # API Test function: GET /policy_schema
1317 # args: <response-code> <policy-type-id> [<schema-file>]
1318 # (Function for test scripts)
1319 api_get_policy_schema() {
1322 if [ "$PMS_VERSION" == "V2" ]; then
1323 __log_test_fail_not_supported
1327 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1328 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1331 query="/policy_schema?id=$2"
1332 res="$(__do_curl_to_api PA GET $query)"
1333 status=${res:${#res}-3}
1335 if [ $status -ne $1 ]; then
1336 __log_test_fail_status_code $1 $status
1340 if [ $# -eq 3 ]; then
1342 body=${res:0:${#res}-3}
1346 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1347 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1349 if [ $res -ne 0 ]; then
1350 __log_test_fail_body
1359 # API Test function: GET /policy_schemas
1360 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1361 # args(V2): <response-code>
1362 # (Function for test scripts)
1363 api_get_policy_schemas() {
1366 if [ "$PMS_VERSION" == "V2" ]; then
1367 if [ $# -ne 1 ]; then
1368 __print_err "<response-code>" $@
1372 if [ $# -lt 2 ]; then
1373 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1377 if [ "$PMS_VERSION" == "V2" ]; then
1378 query="/v2/policy-schemas"
1380 query="/policy_schemas"
1381 if [ $2 != "NORIC" ]; then
1382 query=$query"?ric="$2
1386 res="$(__do_curl_to_api PA GET $query)"
1387 status=${res:${#res}-3}
1389 if [ $status -ne $1 ]; then
1390 __log_test_fail_status_code $1 $status
1394 if [ $# -gt 2 ]; then
1395 body=${res:0:${#res}-3}
1398 for file in ${@:3} ; do
1399 if [ "$targetJson" != "[" ]; then
1400 targetJson=$targetJson","
1402 if [ $file == "NOFILE" ]; then
1403 targetJson=$targetJson"{}"
1405 targetJson=$targetJson$(< $file)
1409 targetJson=$targetJson"]"
1410 if [ "$PMS_VERSION" == "V2" ]; then
1411 targetJson="{\"policy_schemas\": $targetJson }"
1413 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1414 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1416 if [ $res -ne 0 ]; then
1417 __log_test_fail_body
1426 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1427 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1428 # (Function for test scripts)
1429 api_get_policy_status() {
1432 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1433 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1439 if [ $3 == "STD" ]; then
1440 targetJson="{\"enforceStatus\":\"$4\""
1441 if [ $# -eq 5 ]; then
1442 targetJson=$targetJson",\"reason\":\"$5\""
1444 targetJson=$targetJson"}"
1445 elif [ $3 == "STD2" ]; then
1446 if [ $4 == "EMPTY" ]; then
1447 targetJson="{\"enforceStatus\":\"\""
1449 targetJson="{\"enforceStatus\":\"$4\""
1451 if [ $# -eq 5 ]; then
1452 if [ $5 == "EMPTY" ]; then
1453 targetJson=$targetJson",\"enforceReason\":\"\""
1455 targetJson=$targetJson",\"enforceReason\":\"$5\""
1458 targetJson=$targetJson"}"
1459 elif [ $3 == "OSC" ]; then
1460 targetJson="{\"instance_status\":\"$4\""
1461 if [ $# -eq 5 ]; then
1462 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1464 targetJson=$targetJson",\"created_at\":\"????\"}"
1466 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1470 if [ "$PMS_VERSION" == "V2" ]; then
1471 query="/v2/policies/$UUID$2/status"
1472 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1474 query="/policy_status?id="$UUID$2
1477 res="$(__do_curl_to_api PA GET $query)"
1478 status=${res:${#res}-3}
1480 if [ $status -ne $1 ]; then
1481 __log_test_fail_status_code $1 $status
1485 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1486 body=${res:0:${#res}-3}
1487 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1489 if [ $res -ne 0 ]; then
1490 __log_test_fail_body
1498 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1499 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1500 # (Function for test scripts)
1501 api_get_policy_types() {
1504 if [ $# -lt 1 ]; then
1505 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1509 if [ "$PMS_VERSION" == "V2" ]; then
1510 if [ $# -eq 1 ]; then
1511 query="/v2/policy-types"
1512 elif [ $2 == "NORIC" ]; then
1513 query="/v2/policy-types"
1515 query="/v2/policy-types?ric_id=$2"
1518 if [ $# -eq 1 ]; then
1519 query="/policy_types"
1520 elif [ $2 == "NORIC" ]; then
1521 query="/policy_types"
1523 query="/policy_types?ric=$2"
1527 res="$(__do_curl_to_api PA GET $query)"
1528 status=${res:${#res}-3}
1530 if [ $status -ne $1 ]; then
1531 __log_test_fail_status_code $1 $status
1535 if [ $# -gt 2 ]; then
1536 body=${res:0:${#res}-3}
1539 for pid in ${@:3} ; do
1540 if [ "$targetJson" != "[" ]; then
1541 targetJson=$targetJson","
1543 if [ $pid == "EMPTY" ]; then
1546 targetJson=$targetJson"\"$pid\""
1549 targetJson=$targetJson"]"
1550 if [ "$PMS_VERSION" == "V2" ]; then
1551 targetJson="{\"policytype_ids\": $targetJson }"
1553 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1554 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1556 if [ $res -ne 0 ]; then
1557 __log_test_fail_body
1566 #########################################################
1567 #### Test case functions Health check
1568 #########################################################
1570 # API Test function: GET /status and V2 GET /status
1571 # args: <response-code>
1572 # (Function for test scripts)
1575 if [ $# -ne 1 ]; then
1576 __print_err "<response-code>" $@
1579 if [ "$PMS_VERSION" == "V2" ]; then
1584 res="$(__do_curl_to_api PA GET $query)"
1585 status=${res:${#res}-3}
1587 if [ $status -ne $1 ]; then
1588 __log_test_fail_status_code $1 $status
1596 #########################################################
1597 #### Test case functions RIC Repository
1598 #########################################################
1600 # API Test function: GET /ric and V2 GET /v2/rics/ric
1601 # args: <reponse-code> <management-element-id> [<ric-id>]
1602 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1603 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1604 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1607 # (Function for test scripts)
1611 if [ "$PMS_VERSION" == "V2" ]; then
1612 if [ $# -lt 3 ]; then
1613 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1617 if [ $2 != "NOME" ]; then
1618 search="?managed_element_id="$2
1620 if [ $3 != "NORIC" ]; then
1621 if [ -z $search ]; then
1624 search=$search"&ric_id="$3
1627 query="/v2/rics/ric"$search
1629 res="$(__do_curl_to_api PA GET $query)"
1630 status=${res:${#res}-3}
1632 if [ $status -ne $1 ]; then
1633 __log_test_fail_status_code $1 $status
1637 if [ $# -gt 3 ]; then
1638 body=${res:0:${#res}-3}
1639 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1640 if [ $res -ne 0 ]; then
1641 __log_test_fail_general "Could not create target ric info json"
1645 targetJson=$(<./tmp/.tmp_rics.json)
1646 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1647 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1648 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1649 if [ $res -ne 0 ]; then
1650 __log_test_fail_body
1655 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1656 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1660 query="/ric?managedElementId="$2
1662 res="$(__do_curl_to_api PA GET $query)"
1663 status=${res:${#res}-3}
1665 if [ $status -ne $1 ]; then
1666 __log_test_fail_status_code $1 $status
1670 if [ $# -eq 3 ]; then
1671 body=${res:0:${#res}-3}
1672 if [ "$body" != "$3" ]; then
1673 __log_test_fail_body
1682 # API test function: GET /rics and V2 GET /v2/rics
1683 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1684 # 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_........."
1685 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1686 # (Function for test scripts)
1690 if [ $# -lt 2 ]; then
1691 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1695 if [ "$PMS_VERSION" == "V2" ]; then
1697 if [ $2 != "NOTYPE" ]; then
1698 query="/v2/rics?policytype_id="$2
1702 if [ $2 != "NOTYPE" ]; then
1703 query="/rics?policyType="$2
1707 res="$(__do_curl_to_api PA GET $query)"
1708 status=${res:${#res}-3}
1710 if [ $status -ne $1 ]; then
1711 __log_test_fail_status_code $1 $status
1715 if [ $# -gt 2 ]; then
1716 body=${res:0:${#res}-3}
1717 if [ "$PMS_VERSION" == "V2" ]; then
1718 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1720 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1722 if [ $res -ne 0 ]; then
1723 __log_test_fail_general "Could not create target ric info json"
1727 targetJson=$(<./tmp/.tmp_rics.json)
1728 if [ "$PMS_VERSION" == "V2" ]; then
1729 targetJson="{\"rics\": $targetJson }"
1731 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1732 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1733 if [ $res -ne 0 ]; then
1734 __log_test_fail_body
1743 ##################################################################
1744 #### API Test case functions Service registry and supervision ####
1745 ##################################################################
1747 # API test function: PUT /service and V2 PUT /service
1748 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1749 # (Function for test scripts)
1752 if [ $# -ne 4 ]; then
1753 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1757 if [ "$PMS_VERSION" == "V2" ]; then
1758 query="/v2/services"
1759 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1762 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1764 file="./tmp/.tmp.json"
1765 echo "$json" > $file
1767 res="$(__do_curl_to_api PA PUT $query $file)"
1768 status=${res:${#res}-3}
1770 if [ $status -ne $1 ]; then
1771 __log_test_fail_status_code $1 $status
1779 # API test function: GET /services and V2 GET /v2/services
1780 #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>]* )]
1781 # (Function for test scripts)
1782 api_get_services() {
1784 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1786 if [ $# -eq 1 ]; then
1788 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1790 elif [ $# -eq 5 ]; then
1792 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1794 if [ $(($argLen%3)) -eq 0 ]; then
1799 if [ $paramError -ne 0 ]; then
1800 __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>]* )]" $@
1804 if [ "$PMS_VERSION" == "V2" ]; then
1805 query="/v2/services"
1807 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1808 query="/v2/services?service_id="$2
1813 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1814 query="/services?name="$2
1817 res="$(__do_curl_to_api PA GET $query)"
1818 status=${res:${#res}-3}
1820 if [ $status -ne $1 ]; then
1821 __log_test_fail_status_code $1 $status
1825 if [ $# -gt 2 ]; then
1826 variableArgCount=$(($#-2))
1827 body=${res:0:${#res}-3}
1831 while [ $cntr -lt $variableArgCount ]; do
1832 servicename=$1; shift;
1835 if [ $cntr -gt 0 ]; then
1836 targetJson=$targetJson","
1838 # timeSinceLastActivitySeconds value cannot be checked since value varies
1839 if [ "$PMS_VERSION" == "V2" ]; then
1840 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1842 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1846 targetJson=$targetJson"]"
1847 if [ "$PMS_VERSION" == "V2" ]; then
1848 targetJson="{\"service_list\": $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 # API test function: GET /services V2 GET /v2/services - (only checking service names)
1863 # args: <response-code> [<service-name>]*"
1864 # (Function for test scripts)
1865 api_get_service_ids() {
1868 if [ $# -lt 1 ]; then
1869 __print_err "<response-code> [<service-name>]*" $@
1873 if [ "$PMS_VERSION" == "V2" ]; then
1874 query="/v2/services"
1878 res="$(__do_curl_to_api PA GET $query)"
1879 status=${res:${#res}-3}
1881 if [ $status -ne $1 ]; then
1882 __log_test_fail_status_code $1 $status
1886 body=${res:0:${#res}-3}
1888 for rapp in ${@:2} ; do
1889 if [ "$targetJson" != "[" ]; then
1890 targetJson=$targetJson","
1892 if [ "$PMS_VERSION" == "V2" ]; then
1893 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
1895 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1899 targetJson=$targetJson"]"
1900 if [ "$PMS_VERSION" == "V2" ]; then
1901 targetJson="{\"service_list\": $targetJson }"
1903 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1904 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1906 if [ $res -ne 0 ]; then
1907 __log_test_fail_body
1915 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
1916 # args: <response-code> <service-name>
1917 # (Function for test scripts)
1918 api_delete_services() {
1921 if [ $# -ne 2 ]; then
1922 __print_err "<response-code> <service-name>" $@
1925 if [ "$PMS_VERSION" == "V2" ]; then
1926 query="/v2/services/"$2
1928 query="/services?name="$2
1930 res="$(__do_curl_to_api PA DELETE $query)"
1931 status=${res:${#res}-3}
1933 if [ $status -ne $1 ]; then
1934 __log_test_fail_status_code $1 $status
1942 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
1943 # args: <response-code> <service-name>
1944 # (Function for test scripts)
1945 api_put_services_keepalive() {
1948 if [ $# -ne 2 ]; then
1949 __print_err "<response-code> <service-name>" $@
1952 if [ "$PMS_VERSION" == "V2" ]; then
1953 query="/v2/services/$2/keepalive"
1955 query="/services/keepalive?name="$2
1958 res="$(__do_curl_to_api PA PUT $query)"
1959 status=${res:${#res}-3}
1961 if [ $status -ne $1 ]; then
1962 __log_test_fail_status_code $1 $status
1970 ##################################################################
1971 #### API Test case functions Configuration ####
1972 ##################################################################
1974 # API Test function: PUT /v2/configuration
1975 # args: <response-code> <config-file>
1976 # (Function for test scripts)
1977 api_put_configuration() {
1980 if [ "$PMS_VERSION" != "V2" ]; then
1981 __log_test_fail_not_supported
1985 if [ $# -ne 2 ]; then
1986 __print_err "<response-code> <config-file>" $@
1989 if [ ! -f $2 ]; then
1990 _log_test_fail_general "Config file "$2", does not exist"
1994 inputJson="{\"config\":"$inputJson"}"
1995 file="./tmp/.config.json"
1996 echo $inputJson > $file
1997 query="/v2/configuration"
1998 res="$(__do_curl_to_api PA PUT $query $file)"
1999 status=${res:${#res}-3}
2001 if [ $status -ne $1 ]; then
2002 __log_test_fail_status_code $1 $status
2010 # API Test function: GET /v2/configuration
2011 # args: <response-code> [<config-file>]
2012 # (Function for test scripts)
2013 api_get_configuration() {
2016 if [ "$PMS_VERSION" != "V2" ]; then
2017 __log_test_fail_not_supported
2021 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2022 __print_err "<response-code> [<config-file>]" $@
2025 if [ ! -f $2 ]; then
2026 _log_test_fail_general "Config file "$2" for comparison, does not exist"
2030 query="/v2/configuration"
2031 res="$(__do_curl_to_api PA GET $query)"
2032 status=${res:${#res}-3}
2034 if [ $status -ne $1 ]; then
2035 __log_test_fail_status_code $1 $status
2039 if [ $# -eq 2 ]; then
2041 body=${res:0:${#res}-3}
2044 targetJson="{\"config\":"$targetJson"}"
2045 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2046 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2048 if [ $res -ne 0 ]; then
2049 __log_test_fail_body