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
23 ## Access to Policy agent
24 # Host name may be changed if app started by kube
25 # Direct access from script
27 PA_HOST_NAME=$LOCALHOST_NAME
28 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
30 # PA_ADAPTER used for switch between REST and DMAAP
31 PA_ADAPTER_TYPE="REST"
34 # Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
37 ###########################
38 ### Policy Agents functions
39 ###########################
41 # All calls to the agent will be directed to the agent REST interface from now on
43 # (Function for test scripts)
44 use_agent_rest_http() {
45 echo -e $BOLD"Agent protocol setting"$EBOLD
46 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
48 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
50 PA_ADAPTER_TYPE="REST"
55 # All calls to the agent will be directed to the agent REST interface from now on
57 # (Function for test scripts)
58 use_agent_rest_https() {
59 echo -e $BOLD"Agent protocol setting"$EBOLD
60 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
62 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
64 PA_ADAPTER_TYPE="REST"
69 # All calls to the agent will be directed to the agent dmaap interface over http from now on
71 # (Function for test scripts)
72 use_agent_dmaap_http() {
73 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
74 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
75 PA_ADAPTER_TYPE="MR-HTTP"
79 # All calls to the agent will be directed to the agent dmaap interface over https from now on
81 # (Function for test scripts)
82 use_agent_dmaap_https() {
83 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
84 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
85 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
86 PA_ADAPTER_TYPE="MR-HTTPS"
90 # Start the policy agent
91 # args: (kube only) PROXY|NOPROXY <config-file> [ <data-file>]
92 # (Function for test scripts)
93 start_policy_agent() {
94 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
96 if [ $RUNMODE == "KUBE" ]; then
98 # Check if app shall be fully managed by the test script
99 __check_included_image "PA"
102 # Check if app shall only be used by the testscipt
103 __check_prestarted_image "PA"
106 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
107 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
108 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
111 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
112 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
113 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
117 if [ $retcode_p -eq 0 ]; then
118 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
119 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
120 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
123 if [ $retcode_i -eq 0 ]; then
125 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
127 #Check if nonrtric namespace exists, if not create it
128 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
130 #Export all vars needed for service and deployment
131 export POLICY_AGENT_APP_NAME
132 export KUBE_NONRTRIC_NAMESPACE
133 export POLICY_AGENT_IMAGE
134 export POLICY_AGENT_INTERNAL_PORT
135 export POLICY_AGENT_INTERNAL_SECURE_PORT
136 export POLICY_AGENT_EXTERNAL_PORT
137 export POLICY_AGENT_EXTERNAL_SECURE_PORT
138 export POLICY_AGENT_CONFIG_MOUNT_PATH
139 export POLICY_AGENT_DATA_MOUNT_PATH
140 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
141 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
142 export POLICY_AGENT_PKG_NAME
143 if [ $1 == "PROXY" ]; then
144 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
145 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
147 AGENT_HTTP_PROXY_CONFIG_PORT=0
148 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
150 export AGENT_HTTP_PROXY_CONFIG_PORT
151 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
154 # Create config map for config
155 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
157 output_yaml=$PWD/tmp/pa_cfc.yaml
158 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
160 # Create config map for data
161 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
162 if [ $# -lt 3 ]; then
163 #create empty dummy file
164 echo "{}" > $data_json
168 output_yaml=$PWD/tmp/pa_cfd.yaml
169 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
172 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
173 output_yaml=$PWD/tmp/pa_svc.yaml
174 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
177 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
178 output_yaml=$PWD/tmp/pa_app.yaml
179 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
183 echo " Retrieving host and ports for service..."
184 PA_HOST_NAME=$(__kube_get_service_host $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
185 POLICY_AGENT_EXTERNAL_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
186 POLICY_AGENT_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
188 echo " Host IP, http port, https port: $PA_HOST_NAME $POLICY_AGENT_EXTERNAL_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT"
190 if [ $PA_HTTPX == "http" ]; then
191 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
193 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
195 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
197 if [ $PA_ADAPTER_TYPE == "REST" ]; then
201 __check_included_image 'PA'
202 if [ $? -eq 1 ]; then
203 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
204 echo -e $RED"The Policy Agent will not be started"$ERED
208 #Export all vars needed for docker-compose
209 export POLICY_AGENT_APP_NAME
210 export POLICY_AGENT_APP_NAME_ALIAS
211 export POLICY_AGENT_INTERNAL_PORT
212 export POLICY_AGENT_EXTERNAL_PORT
213 export POLICY_AGENT_INTERNAL_SECURE_PORT
214 export POLICY_AGENT_EXTERNAL_SECURE_PORT
216 export CONSUL_INTERNAL_PORT
217 export CONFIG_BINDING_SERVICE
218 export POLICY_AGENT_CONFIG_KEY
219 export DOCKER_SIM_NWNAME
220 export POLICY_AGENT_HOST_MNT_DIR
221 export POLICY_AGENT_CONFIG_MOUNT_PATH
222 export POLICY_AGENT_CONFIG_FILE
223 export POLICY_AGENT_PKG_NAME
225 if [ $1 == "PROXY" ]; then
226 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
227 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
229 AGENT_HTTP_PROXY_CONFIG_PORT=0
230 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
232 export AGENT_HTTP_PROXY_CONFIG_PORT
233 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
235 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
237 envsubst < $2 > $dest_file
239 __start_container $POLICY_AGENT_COMPOSE_DIR NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
241 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
247 agent_load_config() {
248 echo -e $BOLD"Agent - load config from "$EBOLD$1
249 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
251 output_yaml=$PWD/tmp/pa_cfd.yaml
252 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
256 # Turn on debug level tracing in the agent
258 # (Function for test scripts)
260 echo -e $BOLD"Setting agent debug logging"$EBOLD
261 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
262 result=$(__do_curl "$curlString")
263 if [ $? -ne 0 ]; then
264 __print_err "could not set debug mode" $@
272 # Turn on trace level tracing in the agent
274 # (Function for test scripts)
276 echo -e $BOLD"Setting agent trace logging"$EBOLD
277 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
278 result=$(__do_curl "$curlString")
279 if [ $? -ne 0 ]; then
280 __print_err "could not set trace mode" $@
288 # Perform curl retries when making direct call to the agent for the specified http response codes
289 # Speace separated list of http response codes
290 # args: [<response-code>]*
291 use_agent_retries() {
292 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
298 #########################################################
299 #### Test case functions A1 Policy management service
300 #########################################################
302 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
303 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
304 # args: json:<url> <target-value> [<timeout-in-seconds]
305 # (Function for test scripts)
307 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
308 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
309 if [[ $1 == "json:"* ]]; then
310 if [ "$PMS_VERSION" == "V2" ]; then
311 __var_test "Policy Agent" $PA_PATH"/v2/" $1 "=" $2 $3
313 __var_test "Policy Agent" $PA_PATH"/" $1 "=" $2 $3
318 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
322 # API Test function: GET /policies and V2 GET /v2/policy-instances
323 # 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>]*]
324 # 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>]*]
325 # (Function for test scripts)
329 if [ "$PMS_VERSION" == "V2" ]; then
331 variableParams=$(($#-4))
332 if [ $# -lt 4 ]; then
334 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
336 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
340 if [ $paramError -ne 0 ]; then
341 __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>]*]" $@
346 variableParams=$(($#-4))
347 if [ $# -lt 4 ]; then
349 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
351 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
355 if [ $paramError -ne 0 ]; then
356 __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>]*]" $@
362 if [ "$PMS_VERSION" == "V2" ]; then
363 if [ $2 != "NORIC" ]; then
364 queryparams="?ric_id="$2
366 if [ $3 != "NOSERVICE" ]; then
367 if [ -z $queryparams ]; then
368 queryparams="?service_id="$3
370 queryparams=$queryparams"&service_id="$3
373 if [ $4 != "NOTYPE" ]; then
374 if [ -z $queryparams ]; then
375 queryparams="?policytype_id="$4
377 queryparams=$queryparams"&policytype_id="$4
381 query="/v2/policy-instances"$queryparams
382 res="$(__do_curl_to_api PA GET $query)"
383 status=${res:${#res}-3}
385 if [ $status -ne $1 ]; then
386 __log_test_fail_status_code $1 $status
390 if [ $# -gt 4 ]; then
391 body=${res:0:${#res}-3}
392 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
398 for ((i=0; i<$(($#-4)); i=i+7)); do
400 if [ "$targetJson" != "[" ]; then
401 targetJson=$targetJson","
403 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
404 if [ "${arr[$i+3]}" == "EMPTY" ]; then
405 targetJson=$targetJson"\"\","
407 targetJson=$targetJson"\"${arr[$i+3]}\","
409 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
411 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
413 targetJson=$targetJson"\"policy_data\":"$json"}"
417 targetJson=$targetJson"]"
418 targetJson="{\"policies\": $targetJson}"
419 echo "TARGET JSON: $targetJson" >> $HTTPLOG
420 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
422 if [ $res -ne 0 ]; then
428 if [ $2 != "NORIC" ]; then
429 queryparams="?ric="$2
431 if [ $3 != "NOSERVICE" ]; then
432 if [ -z $queryparams ]; then
433 queryparams="?service="$3
435 queryparams=$queryparams"&service="$3
438 if [ $4 != "NOTYPE" ]; then
439 if [ -z $queryparams ]; then
440 queryparams="?type="$4
442 queryparams=$queryparams"&type="$4
446 query="/policies"$queryparams
447 res="$(__do_curl_to_api PA GET $query)"
448 status=${res:${#res}-3}
450 if [ $status -ne $1 ]; then
451 __log_test_fail_status_code $1 $status
455 if [ $# -gt 4 ]; then
456 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
459 body=${res:0:${#res}-3}
463 for ((i=0; i<$(($#-4)); i=i+5)); do
465 if [ "$targetJson" != "[" ]; then
466 targetJson=$targetJson","
468 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
469 if [ "${arr[$i+3]}" == "EMPTY" ]; then
470 targetJson=$targetJson"\"\","
472 targetJson=$targetJson"\"${arr[$i+3]}\","
475 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
477 targetJson=$targetJson"\"json\":"$json"}"
481 targetJson=$targetJson"]"
482 echo "TARGET JSON: $targetJson" >> $HTTPLOG
483 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
485 if [ $res -ne 0 ]; then
498 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
499 # args: <response-code> <policy-id> [<template-file>]
500 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
502 # (Function for test scripts)
507 if [ "$PMS_VERSION" == "V2" ]; then
508 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
509 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
512 query="/v2/policies/$UUID$2"
514 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
515 __print_err "<response-code> <policy-id> [<template-file>] " $@
518 query="/policy?id=$UUID$2"
520 res="$(__do_curl_to_api PA GET $query)"
521 status=${res:${#res}-3}
523 if [ $status -ne $1 ]; then
524 __log_test_fail_status_code $1 $status
528 if [ "$PMS_VERSION" == "V2" ]; then
529 if [ $# -eq 8 ]; then
531 #Create a policy json to compare with
532 body=${res:0:${#res}-3}
534 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
535 if [ $7 != "NOTRANSIENT" ]; then
536 targetJson=$targetJson", \"transient\":$7"
538 if [ $6 != "NOTYPE" ]; then
539 targetJson=$targetJson", \"policytype_id\":\"$6\""
541 targetJson=$targetJson", \"policytype_id\":\"\""
543 if [ $8 != "NOURL" ]; then
544 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
547 data=$(sed 's/XXX/'${2}'/g' $3)
548 targetJson=$targetJson", \"policy_data\":$data"
549 targetJson="{$targetJson}"
551 echo "TARGET JSON: $targetJson" >> $HTTPLOG
552 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
553 if [ $res -ne 0 ]; then
559 if [ $# -eq 3 ]; then
560 #Create a policy json to compare with
561 body=${res:0:${#res}-3}
563 sed 's/XXX/'${2}'/g' $3 > $file
564 targetJson=$(< $file)
565 echo "TARGET JSON: $targetJson" >> $HTTPLOG
566 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
567 if [ $res -ne 0 ]; then
577 # API Test function: PUT /policy and V2 PUT /policies
578 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
579 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
580 # (Function for test scripts)
584 if [ "$PMS_VERSION" == "V2" ]; then
585 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
586 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
590 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
591 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
604 if [ "$PMS_VERSION" == "V2" ]; then
607 if [ $# -eq 9 ]; then
612 if [ $# -eq 8 ]; then
617 while [ $count -lt $max ]; do
618 if [ "$PMS_VERSION" == "V2" ]; then
622 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
623 if [ $trans != "NOTRANSIENT" ]; then
624 inputJson=$inputJson", \"transient\":$trans"
626 if [ $pt != "NOTYPE" ]; then
627 inputJson=$inputJson", \"policytype_id\":\"$pt\""
629 inputJson=$inputJson", \"policytype_id\":\"\""
631 if [ $noti != "NOURL" ]; then
632 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
635 data=$(sed 's/XXX/'${pid}'/g' $temp)
636 inputJson=$inputJson", \"policy_data\":$data"
637 inputJson="{$inputJson}"
638 echo $inputJson > $file
640 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
642 if [ $pt != "NOTYPE" ]; then
643 query=$query"&type=$pt"
646 if [ $trans != NOTRANSIENT ]; then
647 query=$query"&transient=$trans"
651 sed 's/XXX/'${pid}'/g' $temp > $file
653 res="$(__do_curl_to_api PA PUT $query $file)"
654 status=${res:${#res}-3}
655 echo -ne " Executing "$count"("$max")${SAMELINE}"
656 if [ $status -ne $1 ]; then
657 echo " Executed "$count"?("$max")"
658 __log_test_fail_status_code $1 $status
664 echo -ne " Executed "$count"("$max")${SAMELINE}"
672 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
673 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
674 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
675 # (Function for test scripts)
677 api_put_policy_batch() {
680 if [ "$PMS_VERSION" == "V2" ]; then
681 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
682 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
686 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
687 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
699 if [ "$PMS_VERSION" == "V2" ]; then
702 if [ $# -eq 9 ]; then
707 if [ $# -eq 8 ]; then
713 while [ $count -lt $max ]; do
714 if [ "$PMS_VERSION" == "V2" ]; then
717 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
718 if [ $trans != "NOTRANSIENT" ]; then
719 inputJson=$inputJson", \"transient\":$trans"
721 if [ $pt != "NOTYPE" ]; then
722 inputJson=$inputJson", \"policytype_id\":\"$pt\""
724 inputJson=$inputJson", \"policytype_id\":\"\""
726 if [ $noti != "NOURL" ]; then
727 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
730 data=$(sed 's/XXX/'${pid}'/g' $temp)
731 inputJson=$inputJson", \"policy_data\":$data"
732 inputJson="{$inputJson}"
733 echo $inputJson > $file
735 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
737 if [ $pt != "NOTYPE" ]; then
738 query=$query"&type=$pt"
741 if [ $trans != NOTRANSIENT ]; then
742 query=$query"&transient=$trans"
745 sed 's/XXX/'${pid}'/g' $temp > $file
747 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
748 status=${res:${#res}-3}
749 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
751 if [ $status -ne 200 ]; then
752 echo " Requested(batch) "$count"?("$max")"
753 __log_test_fail_status_code 200 $status
756 cid=${res:0:${#res}-3}
760 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
767 res="$(__do_curl_to_api PA RESPONSE $cid)"
768 status=${res:${#res}-3}
769 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
771 if [ $status -ne $1 ]; then
772 echo " Accepted(batch) "$count"?("$max")"
773 __log_test_fail_status_code $1 $status
778 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
787 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
788 # 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>
789 # 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>
790 # (Function for test scripts)
791 api_put_policy_parallel() {
794 if [ "$PMS_VERSION" == "V2" ]; then
795 if [ $# -ne 11 ]; then
796 __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>" $@
800 if [ $# -ne 10 ]; then
801 __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>" $@
812 if [ "$PMS_VERSION" == "V2" ]; then
821 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
822 if [ $__ADAPTER_TYPE != "REST" ]; then
823 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
824 echo " Info - will execute over agent REST"
826 if [ "$PMS_VERSION" == "V2" ]; then
827 if [ $serv == "NOSERVICE" ]; then
832 if [ $serv == "NOSERVICE" ]; then
835 query="/policy?service=$serv"
837 if [ $type != "NOTYPE" ]; then
838 query=$query"&type=$type"
841 if [ $transient != NOTRANSIENT ]; then
842 query=$query"&transient=$transient"
846 urlbase=${PA_ADAPTER}${query}
848 for ((i=1; i<=$pids; i++))
851 if [ -z "$uuid" ]; then
854 echo "" > "./tmp/.pid${i}.res.txt"
855 if [ "$PMS_VERSION" == "V2" ]; then
856 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i > "./tmp/.pid${i}.txt"
858 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt"
861 done | xargs -n 1 -I{} -P $pids bash -c '{
863 echo " Parallel process $arg started"
864 tmp=$(< "./tmp/.pid${arg}.txt")
865 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
868 for ((i=1; i<=$pids; i++))
870 file="./tmp/.pid${i}.res.txt"
872 if [ -z "$tmp" ]; then
873 echo " Process $i : unknown result (result file empty"
877 if [ $res == "0" ]; then
878 echo " Process $i : OK - "${tmp:1}
880 echo " Process $i : failed - "${tmp:1}
886 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
890 __log_test_fail_general "One of more processes failed to execute"
894 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
895 # args: <response-code> <policy-id> [count]
896 # (Function for test scripts)
897 api_delete_policy() {
900 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
901 __print_err "<response-code> <policy-id> [count]" $@
908 if [ $# -eq 3 ]; then
914 while [ $count -lt $max ]; do
915 if [ "$PMS_VERSION" == "V2" ]; then
916 query="/v2/policies/"$UUID$pid
918 query="/policy?id="$UUID$pid
920 res="$(__do_curl_to_api PA DELETE $query)"
921 status=${res:${#res}-3}
922 echo -ne " Executing "$count"("$max")${SAMELINE}"
924 if [ $status -ne $1 ]; then
925 echo " Executed "$count"?("$max")"
926 __log_test_fail_status_code $1 $status
931 echo -ne " Executed "$count"("$max")${SAMELINE}"
939 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
940 # args: <response-code> <policy-id> [count]
941 # (Function for test scripts)
942 api_delete_policy_batch() {
945 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
946 __print_err "<response-code> <policy-id> [count]" $@
953 if [ $# -eq 3 ]; then
959 while [ $count -lt $max ]; do
960 if [ "$PMS_VERSION" == "V2" ]; then
961 query="/v2/policies/"$UUID$pid
963 query="/policy?id="$UUID$pid
965 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
966 status=${res:${#res}-3}
967 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
969 if [ $status -ne 200 ]; then
970 echo " Requested(batch) "$count"?("$max")"
971 __log_test_fail_status_code 200 $status
974 cid=${res:0:${#res}-3}
978 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
986 res="$(__do_curl_to_api PA RESPONSE $cid)"
987 status=${res:${#res}-3}
988 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
990 if [ $status -ne $1 ]; then
991 echo " Deleted(batch) "$count"?("$max")"
992 __log_test_fail_status_code $1 $status
997 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1006 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1007 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1008 # (Function for test scripts)
1009 api_delete_policy_parallel() {
1012 if [ $# -ne 5 ]; then
1013 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1016 resp_code=$1; shift;
1022 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1023 if [ $__ADAPTER_TYPE != "REST" ]; then
1024 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1025 echo " Info - will execute over agent REST"
1028 if [ "$PMS_VERSION" == "V2" ]; then
1029 query="/v2/policies/"
1034 urlbase=${PA_ADAPTER}${query}
1036 for ((i=1; i<=$pids; i++))
1039 if [ -z "$uuid" ]; then
1042 echo "" > "./tmp/.pid${i}.del.res.txt"
1043 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > "./tmp/.pid${i}.del.txt"
1045 done | xargs -n 1 -I{} -P $pids bash -c '{
1047 echo " Parallel process $arg started"
1048 tmp=$(< "./tmp/.pid${arg}.del.txt")
1049 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1052 for ((i=1; i<=$pids; i++))
1054 file="./tmp/.pid${i}.del.res.txt"
1056 if [ -z "$tmp" ]; then
1057 echo " Process $i : unknown result (result file empty"
1061 if [ $res == "0" ]; then
1062 echo " Process $i : OK - "${tmp:1}
1064 echo " Process $i : failed - "${tmp:1}
1069 if [ -z $msg ]; then
1070 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1074 __log_test_fail_general "One of more processes failed to execute"
1078 # API Test function: GET /policy_ids and V2 GET /v2/policies
1079 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1080 # (Function for test scripts)
1081 api_get_policy_ids() {
1084 if [ $# -lt 4 ]; then
1085 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1091 if [ "$PMS_VERSION" == "V2" ]; then
1092 if [ $2 != "NORIC" ]; then
1093 queryparams="?ric_id="$2
1096 if [ $3 != "NOSERVICE" ]; then
1097 if [ -z $queryparams ]; then
1098 queryparams="?service_id="$3
1100 queryparams=$queryparams"&service_id="$3
1103 if [ $4 != "NOTYPE" ]; then
1104 if [ -z $queryparams ]; then
1105 queryparams="?policytype_id="$4
1107 queryparams=$queryparams"&policytype_id="$4
1111 query="/v2/policies"$queryparams
1113 if [ $2 != "NORIC" ]; then
1114 queryparams="?ric="$2
1117 if [ $3 != "NOSERVICE" ]; then
1118 if [ -z $queryparams ]; then
1119 queryparams="?service="$3
1121 queryparams=$queryparams"&service="$3
1124 if [ $4 != "NOTYPE" ]; then
1125 if [ -z $queryparams ]; then
1126 queryparams="?type="$4
1128 queryparams=$queryparams"&type="$4
1132 query="/policy_ids"$queryparams
1135 res="$(__do_curl_to_api PA GET $query)"
1136 status=${res:${#res}-3}
1138 if [ $status -ne $1 ]; then
1139 __log_test_fail_status_code $1 $status
1143 if [ $# -gt 4 ]; then
1144 body=${res:0:${#res}-3}
1147 for pid in ${@:5} ; do
1148 if [ "$targetJson" != "[" ]; then
1149 targetJson=$targetJson","
1151 if [ $pid != "NOID" ]; then
1152 targetJson=$targetJson"\"$UUID$pid\""
1156 targetJson=$targetJson"]"
1157 if [ "$PMS_VERSION" == "V2" ]; then
1158 targetJson="{\"policy_ids\": $targetJson}"
1160 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1161 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1163 if [ $res -ne 0 ]; then
1164 __log_test_fail_body
1173 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1174 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1175 # (Function for test scripts)
1176 api_get_policy_type() {
1179 if [ "$PMS_VERSION" != "V2" ]; then
1180 __log_test_fail_not_supported
1184 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1185 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1188 query="/v2/policy-types/$2"
1190 res="$(__do_curl_to_api PA GET $query)"
1191 status=${res:${#res}-3}
1193 if [ $status -ne $1 ]; then
1194 __log_test_fail_status_code $1 $status
1198 if [ $# -eq 3 ]; then
1200 body=${res:0:${#res}-3}
1203 targetJson="{\"policy_schema\":$targetJson}"
1204 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1205 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1207 if [ $res -ne 0 ]; then
1208 __log_test_fail_body
1217 # API Test function: GET /policy_schema
1218 # args: <response-code> <policy-type-id> [<schema-file>]
1219 # (Function for test scripts)
1220 api_get_policy_schema() {
1223 if [ "$PMS_VERSION" == "V2" ]; then
1224 __log_test_fail_not_supported
1228 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1229 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1232 query="/policy_schema?id=$2"
1233 res="$(__do_curl_to_api PA GET $query)"
1234 status=${res:${#res}-3}
1236 if [ $status -ne $1 ]; then
1237 __log_test_fail_status_code $1 $status
1241 if [ $# -eq 3 ]; then
1243 body=${res:0:${#res}-3}
1247 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1248 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1250 if [ $res -ne 0 ]; then
1251 __log_test_fail_body
1260 # API Test function: GET /policy_schemas
1261 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1262 # args(V2): <response-code>
1263 # (Function for test scripts)
1264 api_get_policy_schemas() {
1267 if [ "$PMS_VERSION" == "V2" ]; then
1268 if [ $# -ne 1 ]; then
1269 __print_err "<response-code>" $@
1273 if [ $# -lt 2 ]; then
1274 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1278 if [ "$PMS_VERSION" == "V2" ]; then
1279 query="/v2/policy-schemas"
1281 query="/policy_schemas"
1282 if [ $2 != "NORIC" ]; then
1283 query=$query"?ric="$2
1287 res="$(__do_curl_to_api PA GET $query)"
1288 status=${res:${#res}-3}
1290 if [ $status -ne $1 ]; then
1291 __log_test_fail_status_code $1 $status
1295 if [ $# -gt 2 ]; then
1296 body=${res:0:${#res}-3}
1299 for file in ${@:3} ; do
1300 if [ "$targetJson" != "[" ]; then
1301 targetJson=$targetJson","
1303 if [ $file == "NOFILE" ]; then
1304 targetJson=$targetJson"{}"
1306 targetJson=$targetJson$(< $file)
1310 targetJson=$targetJson"]"
1311 if [ "$PMS_VERSION" == "V2" ]; then
1312 targetJson="{\"policy_schemas\": $targetJson }"
1314 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1315 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1317 if [ $res -ne 0 ]; then
1318 __log_test_fail_body
1327 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1328 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1329 # (Function for test scripts)
1330 api_get_policy_status() {
1333 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1334 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1340 if [ $3 == "STD" ]; then
1341 targetJson="{\"enforceStatus\":\"$4\""
1342 if [ $# -eq 5 ]; then
1343 targetJson=$targetJson",\"reason\":\"$5\""
1345 targetJson=$targetJson"}"
1346 elif [ $3 == "STD2" ]; then
1347 if [ $4 == "EMPTY" ]; then
1348 targetJson="{\"enforceStatus\":\"\""
1350 targetJson="{\"enforceStatus\":\"$4\""
1352 if [ $# -eq 5 ]; then
1353 if [ $5 == "EMPTY" ]; then
1354 targetJson=$targetJson",\"enforceReason\":\"\""
1356 targetJson=$targetJson",\"enforceReason\":\"$5\""
1359 targetJson=$targetJson"}"
1360 elif [ $3 == "OSC" ]; then
1361 targetJson="{\"instance_status\":\"$4\""
1362 if [ $# -eq 5 ]; then
1363 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1365 targetJson=$targetJson",\"created_at\":\"????\"}"
1367 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1371 if [ "$PMS_VERSION" == "V2" ]; then
1372 query="/v2/policies/$UUID$2/status"
1373 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1375 query="/policy_status?id="$UUID$2
1378 res="$(__do_curl_to_api PA GET $query)"
1379 status=${res:${#res}-3}
1381 if [ $status -ne $1 ]; then
1382 __log_test_fail_status_code $1 $status
1386 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1387 body=${res:0:${#res}-3}
1388 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1390 if [ $res -ne 0 ]; then
1391 __log_test_fail_body
1399 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1400 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1401 # (Function for test scripts)
1402 api_get_policy_types() {
1405 if [ $# -lt 1 ]; then
1406 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1410 if [ "$PMS_VERSION" == "V2" ]; then
1411 if [ $# -eq 1 ]; then
1412 query="/v2/policy-types"
1413 elif [ $2 == "NORIC" ]; then
1414 query="/v2/policy-types"
1416 query="/v2/policy-types?ric_id=$2"
1419 if [ $# -eq 1 ]; then
1420 query="/policy_types"
1421 elif [ $2 == "NORIC" ]; then
1422 query="/policy_types"
1424 query="/policy_types?ric=$2"
1428 res="$(__do_curl_to_api PA GET $query)"
1429 status=${res:${#res}-3}
1431 if [ $status -ne $1 ]; then
1432 __log_test_fail_status_code $1 $status
1436 if [ $# -gt 2 ]; then
1437 body=${res:0:${#res}-3}
1440 for pid in ${@:3} ; do
1441 if [ "$targetJson" != "[" ]; then
1442 targetJson=$targetJson","
1444 if [ $pid == "EMPTY" ]; then
1447 targetJson=$targetJson"\"$pid\""
1450 targetJson=$targetJson"]"
1451 if [ "$PMS_VERSION" == "V2" ]; then
1452 targetJson="{\"policytype_ids\": $targetJson }"
1454 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1455 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1457 if [ $res -ne 0 ]; then
1458 __log_test_fail_body
1467 #########################################################
1468 #### Test case functions Health check
1469 #########################################################
1471 # API Test function: GET /status and V2 GET /status
1472 # args: <response-code>
1473 # (Function for test scripts)
1476 if [ $# -ne 1 ]; then
1477 __print_err "<response-code>" $@
1480 if [ "$PMS_VERSION" == "V2" ]; then
1485 res="$(__do_curl_to_api PA GET $query)"
1486 status=${res:${#res}-3}
1488 if [ $status -ne $1 ]; then
1489 __log_test_fail_status_code $1 $status
1497 #########################################################
1498 #### Test case functions RIC Repository
1499 #########################################################
1501 # API Test function: GET /ric and V2 GET /v2/rics/ric
1502 # args: <reponse-code> <management-element-id> [<ric-id>]
1503 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1504 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1505 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1508 # (Function for test scripts)
1512 if [ "$PMS_VERSION" == "V2" ]; then
1513 if [ $# -lt 3 ]; then
1514 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1518 if [ $2 != "NOME" ]; then
1519 search="?managed_element_id="$2
1521 if [ $3 != "NORIC" ]; then
1522 if [ -z $search ]; then
1525 search=$search"&ric_id="$3
1528 query="/v2/rics/ric"$search
1530 res="$(__do_curl_to_api PA GET $query)"
1531 status=${res:${#res}-3}
1533 if [ $status -ne $1 ]; then
1534 __log_test_fail_status_code $1 $status
1538 if [ $# -gt 3 ]; then
1539 body=${res:0:${#res}-3}
1540 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1541 if [ $res -ne 0 ]; then
1542 __log_test_fail_general "Could not create target ric info json"
1546 targetJson=$(<./tmp/.tmp_rics.json)
1547 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1548 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1549 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1550 if [ $res -ne 0 ]; then
1551 __log_test_fail_body
1556 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1557 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1561 query="/ric?managedElementId="$2
1563 res="$(__do_curl_to_api PA GET $query)"
1564 status=${res:${#res}-3}
1566 if [ $status -ne $1 ]; then
1567 __log_test_fail_status_code $1 $status
1571 if [ $# -eq 3 ]; then
1572 body=${res:0:${#res}-3}
1573 if [ "$body" != "$3" ]; then
1574 __log_test_fail_body
1583 # API test function: GET /rics and V2 GET /v2/rics
1584 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1585 # 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_........."
1586 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1587 # (Function for test scripts)
1591 if [ $# -lt 2 ]; then
1592 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1596 if [ "$PMS_VERSION" == "V2" ]; then
1598 if [ $2 != "NOTYPE" ]; then
1599 query="/v2/rics?policytype_id="$2
1603 if [ $2 != "NOTYPE" ]; then
1604 query="/rics?policyType="$2
1608 res="$(__do_curl_to_api PA GET $query)"
1609 status=${res:${#res}-3}
1611 if [ $status -ne $1 ]; then
1612 __log_test_fail_status_code $1 $status
1616 if [ $# -gt 2 ]; then
1617 body=${res:0:${#res}-3}
1618 if [ "$PMS_VERSION" == "V2" ]; then
1619 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1621 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1623 if [ $res -ne 0 ]; then
1624 __log_test_fail_general "Could not create target ric info json"
1628 targetJson=$(<./tmp/.tmp_rics.json)
1629 if [ "$PMS_VERSION" == "V2" ]; then
1630 targetJson="{\"rics\": $targetJson }"
1632 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1633 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1634 if [ $res -ne 0 ]; then
1635 __log_test_fail_body
1644 ##################################################################
1645 #### API Test case functions Service registry and supervision ####
1646 ##################################################################
1648 # API test function: PUT /service and V2 PUT /service
1649 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1650 # (Function for test scripts)
1653 if [ $# -ne 4 ]; then
1654 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1658 if [ "$PMS_VERSION" == "V2" ]; then
1659 query="/v2/services"
1660 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1663 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1665 file="./tmp/.tmp.json"
1666 echo "$json" > $file
1668 res="$(__do_curl_to_api PA PUT $query $file)"
1669 status=${res:${#res}-3}
1671 if [ $status -ne $1 ]; then
1672 __log_test_fail_status_code $1 $status
1680 # API test function: GET /services and V2 GET /v2/services
1681 #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>]* )]
1682 # (Function for test scripts)
1683 api_get_services() {
1685 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1687 if [ $# -eq 1 ]; then
1689 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1691 elif [ $# -eq 5 ]; then
1693 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1695 if [ $(($argLen%3)) -eq 0 ]; then
1700 if [ $paramError -ne 0 ]; then
1701 __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>]* )]" $@
1705 if [ "$PMS_VERSION" == "V2" ]; then
1706 query="/v2/services"
1708 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1709 query="/v2/services?service_id="$2
1714 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1715 query="/services?name="$2
1718 res="$(__do_curl_to_api PA GET $query)"
1719 status=${res:${#res}-3}
1721 if [ $status -ne $1 ]; then
1722 __log_test_fail_status_code $1 $status
1726 if [ $# -gt 2 ]; then
1727 variableArgCount=$(($#-2))
1728 body=${res:0:${#res}-3}
1732 while [ $cntr -lt $variableArgCount ]; do
1733 servicename=$1; shift;
1736 if [ $cntr -gt 0 ]; then
1737 targetJson=$targetJson","
1739 # timeSinceLastActivitySeconds value cannot be checked since value varies
1740 if [ "$PMS_VERSION" == "V2" ]; then
1741 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1743 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1747 targetJson=$targetJson"]"
1748 if [ "$PMS_VERSION" == "V2" ]; then
1749 targetJson="{\"service_list\": $targetJson }"
1751 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1752 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1753 if [ $res -ne 0 ]; then
1754 __log_test_fail_body
1763 # API test function: GET /services V2 GET /v2/services - (only checking service names)
1764 # args: <response-code> [<service-name>]*"
1765 # (Function for test scripts)
1766 api_get_service_ids() {
1769 if [ $# -lt 1 ]; then
1770 __print_err "<response-code> [<service-name>]*" $@
1774 if [ "$PMS_VERSION" == "V2" ]; then
1775 query="/v2/services"
1779 res="$(__do_curl_to_api PA GET $query)"
1780 status=${res:${#res}-3}
1782 if [ $status -ne $1 ]; then
1783 __log_test_fail_status_code $1 $status
1787 body=${res:0:${#res}-3}
1789 for rapp in ${@:2} ; do
1790 if [ "$targetJson" != "[" ]; then
1791 targetJson=$targetJson","
1793 if [ "$PMS_VERSION" == "V2" ]; then
1794 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
1796 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1800 targetJson=$targetJson"]"
1801 if [ "$PMS_VERSION" == "V2" ]; then
1802 targetJson="{\"service_list\": $targetJson }"
1804 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1805 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1807 if [ $res -ne 0 ]; then
1808 __log_test_fail_body
1816 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
1817 # args: <response-code> <service-name>
1818 # (Function for test scripts)
1819 api_delete_services() {
1822 if [ $# -ne 2 ]; then
1823 __print_err "<response-code> <service-name>" $@
1826 if [ "$PMS_VERSION" == "V2" ]; then
1827 query="/v2/services/"$2
1829 query="/services?name="$2
1831 res="$(__do_curl_to_api PA DELETE $query)"
1832 status=${res:${#res}-3}
1834 if [ $status -ne $1 ]; then
1835 __log_test_fail_status_code $1 $status
1843 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
1844 # args: <response-code> <service-name>
1845 # (Function for test scripts)
1846 api_put_services_keepalive() {
1849 if [ $# -ne 2 ]; then
1850 __print_err "<response-code> <service-name>" $@
1853 if [ "$PMS_VERSION" == "V2" ]; then
1854 query="/v2/services/$2/keepalive"
1856 query="/services/keepalive?name="$2
1859 res="$(__do_curl_to_api PA PUT $query)"
1860 status=${res:${#res}-3}
1862 if [ $status -ne $1 ]; then
1863 __log_test_fail_status_code $1 $status
1871 ##################################################################
1872 #### API Test case functions Configuration ####
1873 ##################################################################
1875 # API Test function: PUT /v2/configuration
1876 # args: <response-code> <config-file>
1877 # (Function for test scripts)
1878 api_put_configuration() {
1881 if [ "$PMS_VERSION" != "V2" ]; then
1882 __log_test_fail_not_supported
1886 if [ $# -ne 2 ]; then
1887 __print_err "<response-code> <config-file>" $@
1890 if [ ! -f $2 ]; then
1891 _log_test_fail_general "Config file "$2", does not exist"
1895 inputJson="{\"config\":"$inputJson"}"
1896 file="./tmp/.config.json"
1897 echo $inputJson > $file
1898 query="/v2/configuration"
1899 res="$(__do_curl_to_api PA PUT $query $file)"
1900 status=${res:${#res}-3}
1902 if [ $status -ne $1 ]; then
1903 __log_test_fail_status_code $1 $status
1911 # API Test function: GET /v2/configuration
1912 # args: <response-code> [<config-file>]
1913 # (Function for test scripts)
1914 api_get_configuration() {
1917 if [ "$PMS_VERSION" != "V2" ]; then
1918 __log_test_fail_not_supported
1922 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
1923 __print_err "<response-code> [<config-file>]" $@
1926 if [ ! -f $2 ]; then
1927 _log_test_fail_general "Config file "$2" for comparison, does not exist"
1931 query="/v2/configuration"
1932 res="$(__do_curl_to_api PA GET $query)"
1933 status=${res:${#res}-3}
1935 if [ $status -ne $1 ]; then
1936 __log_test_fail_status_code $1 $status
1940 if [ $# -eq 2 ]; then
1942 body=${res:0:${#res}-3}
1945 targetJson="{\"config\":"$targetJson"}"
1946 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1947 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1949 if [ $res -ne 0 ]; then
1950 __log_test_fail_body