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: (docker) PROXY|NOPROXY <config-file>
92 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
93 # (Function for test scripts)
94 start_policy_agent() {
95 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
97 if [ $RUNMODE == "KUBE" ]; then
99 # Check if app shall be fully managed by the test script
100 __check_included_image "PA"
103 # Check if app shall only be used by the testscipt
104 __check_prestarted_image "PA"
107 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
108 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
109 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
112 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
113 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
114 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
118 if [ $retcode_p -eq 0 ]; then
119 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
120 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
121 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
124 if [ $retcode_i -eq 0 ]; then
126 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
128 #Check if nonrtric namespace exists, if not create it
129 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
131 #Export all vars needed for service and deployment
132 export POLICY_AGENT_APP_NAME
133 export KUBE_NONRTRIC_NAMESPACE
134 export POLICY_AGENT_IMAGE
135 export POLICY_AGENT_INTERNAL_PORT
136 export POLICY_AGENT_INTERNAL_SECURE_PORT
137 export POLICY_AGENT_EXTERNAL_PORT
138 export POLICY_AGENT_EXTERNAL_SECURE_PORT
139 export POLICY_AGENT_CONFIG_MOUNT_PATH
140 export POLICY_AGENT_DATA_MOUNT_PATH
141 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
142 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
143 export POLICY_AGENT_PKG_NAME
144 if [ $1 == "PROXY" ]; then
145 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
146 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
147 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
148 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
150 echo " Configured with http proxy"
153 AGENT_HTTP_PROXY_CONFIG_PORT=0
154 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
155 echo " Configured without http proxy"
157 export AGENT_HTTP_PROXY_CONFIG_PORT
158 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
161 # Create config map for config
162 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
164 output_yaml=$PWD/tmp/pa_cfc.yaml
165 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
167 # Create config map for data
168 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
169 if [ $# -lt 3 ]; then
170 #create empty dummy file
171 echo "{}" > $data_json
175 output_yaml=$PWD/tmp/pa_cfd.yaml
176 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
179 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
180 output_yaml=$PWD/tmp/pa_svc.yaml
181 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
184 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
185 output_yaml=$PWD/tmp/pa_app.yaml
186 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
190 echo " Retrieving host and ports for service..."
191 PA_HOST_NAME=$(__kube_get_service_host $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
192 POLICY_AGENT_EXTERNAL_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
193 POLICY_AGENT_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
195 echo " Host IP, http port, https port: $PA_HOST_NAME $POLICY_AGENT_EXTERNAL_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT"
197 if [ $PA_HTTPX == "http" ]; then
198 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
200 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
202 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
204 if [ $PA_ADAPTER_TYPE == "REST" ]; then
208 __check_included_image 'PA'
209 if [ $? -eq 1 ]; then
210 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
211 echo -e $RED"The Policy Agent will not be started"$ERED
215 #Export all vars needed for docker-compose
216 export POLICY_AGENT_APP_NAME
217 export POLICY_AGENT_APP_NAME_ALIAS
218 export POLICY_AGENT_INTERNAL_PORT
219 export POLICY_AGENT_EXTERNAL_PORT
220 export POLICY_AGENT_INTERNAL_SECURE_PORT
221 export POLICY_AGENT_EXTERNAL_SECURE_PORT
223 export CONSUL_INTERNAL_PORT
224 export CONFIG_BINDING_SERVICE
225 export POLICY_AGENT_CONFIG_KEY
226 export DOCKER_SIM_NWNAME
227 export POLICY_AGENT_HOST_MNT_DIR
228 export POLICY_AGENT_CONFIG_MOUNT_PATH
229 export POLICY_AGENT_CONFIG_FILE
230 export POLICY_AGENT_PKG_NAME
232 if [ $1 == "PROXY" ]; then
233 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
234 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
235 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
236 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
238 echo " Configured with http proxy"
241 AGENT_HTTP_PROXY_CONFIG_PORT=0
242 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
243 echo " Configured without http proxy"
245 export AGENT_HTTP_PROXY_CONFIG_PORT
246 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
248 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
250 envsubst < $2 > $dest_file
252 __start_container $POLICY_AGENT_COMPOSE_DIR NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
254 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
260 # Load the the appl config for the agent into a config map
261 agent_load_config() {
262 echo -e $BOLD"Agent - load config from "$EBOLD$1
263 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
265 output_yaml=$PWD/tmp/pa_cfd.yaml
266 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
270 # Turn on debug level tracing in the agent
272 # (Function for test scripts)
274 echo -e $BOLD"Setting agent debug logging"$EBOLD
275 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
276 result=$(__do_curl "$curlString")
277 if [ $? -ne 0 ]; then
278 __print_err "could not set debug mode" $@
286 # Turn on trace level tracing in the agent
288 # (Function for test scripts)
290 echo -e $BOLD"Setting agent trace logging"$EBOLD
291 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
292 result=$(__do_curl "$curlString")
293 if [ $? -ne 0 ]; then
294 __print_err "could not set trace mode" $@
302 # Perform curl retries when making direct call to the agent for the specified http response codes
303 # Speace separated list of http response codes
304 # args: [<response-code>]*
305 use_agent_retries() {
306 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
312 #########################################################
313 #### Test case functions A1 Policy management service
314 #########################################################
316 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
317 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
318 # args: json:<url> <target-value> [<timeout-in-seconds]
319 # (Function for test scripts)
321 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
322 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
323 if [[ $1 == "json:"* ]]; then
324 if [ "$PMS_VERSION" == "V2" ]; then
325 __var_test "Policy Agent" $PA_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
327 __var_test "Policy Agent" $PA_PATH"/" $1 "=" $2 $3
332 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
336 # API Test function: GET /policies and V2 GET /v2/policy-instances
337 # 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>]*]
338 # 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>]*]
339 # (Function for test scripts)
343 if [ "$PMS_VERSION" == "V2" ]; then
345 variableParams=$(($#-4))
346 if [ $# -lt 4 ]; then
348 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
350 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
354 if [ $paramError -ne 0 ]; then
355 __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>]*]" $@
360 variableParams=$(($#-4))
361 if [ $# -lt 4 ]; then
363 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
365 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
369 if [ $paramError -ne 0 ]; then
370 __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>]*]" $@
376 if [ "$PMS_VERSION" == "V2" ]; then
377 if [ $2 != "NORIC" ]; then
378 queryparams="?ric_id="$2
380 if [ $3 != "NOSERVICE" ]; then
381 if [ -z $queryparams ]; then
382 queryparams="?service_id="$3
384 queryparams=$queryparams"&service_id="$3
387 if [ $4 != "NOTYPE" ]; then
388 if [ -z $queryparams ]; then
389 queryparams="?policytype_id="$4
391 queryparams=$queryparams"&policytype_id="$4
395 query="/v2/policy-instances"$queryparams
396 res="$(__do_curl_to_api PA GET $query)"
397 status=${res:${#res}-3}
399 if [ $status -ne $1 ]; then
400 __log_test_fail_status_code $1 $status
404 if [ $# -gt 4 ]; then
405 body=${res:0:${#res}-3}
406 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
412 for ((i=0; i<$(($#-4)); i=i+7)); do
414 if [ "$targetJson" != "[" ]; then
415 targetJson=$targetJson","
417 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
418 if [ "${arr[$i+3]}" == "EMPTY" ]; then
419 targetJson=$targetJson"\"\","
421 targetJson=$targetJson"\"${arr[$i+3]}\","
423 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
425 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
427 targetJson=$targetJson"\"policy_data\":"$json"}"
431 targetJson=$targetJson"]"
432 targetJson="{\"policies\": $targetJson}"
433 echo "TARGET JSON: $targetJson" >> $HTTPLOG
434 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
436 if [ $res -ne 0 ]; then
442 if [ $2 != "NORIC" ]; then
443 queryparams="?ric="$2
445 if [ $3 != "NOSERVICE" ]; then
446 if [ -z $queryparams ]; then
447 queryparams="?service="$3
449 queryparams=$queryparams"&service="$3
452 if [ $4 != "NOTYPE" ]; then
453 if [ -z $queryparams ]; then
454 queryparams="?type="$4
456 queryparams=$queryparams"&type="$4
460 query="/policies"$queryparams
461 res="$(__do_curl_to_api PA GET $query)"
462 status=${res:${#res}-3}
464 if [ $status -ne $1 ]; then
465 __log_test_fail_status_code $1 $status
469 if [ $# -gt 4 ]; then
470 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
473 body=${res:0:${#res}-3}
477 for ((i=0; i<$(($#-4)); i=i+5)); do
479 if [ "$targetJson" != "[" ]; then
480 targetJson=$targetJson","
482 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
483 if [ "${arr[$i+3]}" == "EMPTY" ]; then
484 targetJson=$targetJson"\"\","
486 targetJson=$targetJson"\"${arr[$i+3]}\","
489 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
491 targetJson=$targetJson"\"json\":"$json"}"
495 targetJson=$targetJson"]"
496 echo "TARGET JSON: $targetJson" >> $HTTPLOG
497 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
499 if [ $res -ne 0 ]; then
512 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
513 # args: <response-code> <policy-id> [<template-file>]
514 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
516 # (Function for test scripts)
521 if [ "$PMS_VERSION" == "V2" ]; then
522 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
523 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
526 query="/v2/policies/$UUID$2"
528 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
529 __print_err "<response-code> <policy-id> [<template-file>] " $@
532 query="/policy?id=$UUID$2"
534 res="$(__do_curl_to_api PA GET $query)"
535 status=${res:${#res}-3}
537 if [ $status -ne $1 ]; then
538 __log_test_fail_status_code $1 $status
542 if [ "$PMS_VERSION" == "V2" ]; then
543 if [ $# -eq 8 ]; then
545 #Create a policy json to compare with
546 body=${res:0:${#res}-3}
548 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
549 if [ $7 != "NOTRANSIENT" ]; then
550 targetJson=$targetJson", \"transient\":$7"
552 if [ $6 != "NOTYPE" ]; then
553 targetJson=$targetJson", \"policytype_id\":\"$6\""
555 targetJson=$targetJson", \"policytype_id\":\"\""
557 if [ $8 != "NOURL" ]; then
558 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
561 data=$(sed 's/XXX/'${2}'/g' $3)
562 targetJson=$targetJson", \"policy_data\":$data"
563 targetJson="{$targetJson}"
565 echo "TARGET JSON: $targetJson" >> $HTTPLOG
566 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
567 if [ $res -ne 0 ]; then
573 if [ $# -eq 3 ]; then
574 #Create a policy json to compare with
575 body=${res:0:${#res}-3}
577 sed 's/XXX/'${2}'/g' $3 > $file
578 targetJson=$(< $file)
579 echo "TARGET JSON: $targetJson" >> $HTTPLOG
580 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
581 if [ $res -ne 0 ]; then
591 # API Test function: PUT /policy and V2 PUT /policies
592 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
593 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
594 # (Function for test scripts)
598 if [ "$PMS_VERSION" == "V2" ]; then
599 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
600 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
604 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
605 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
618 if [ "$PMS_VERSION" == "V2" ]; then
621 if [ $# -eq 9 ]; then
626 if [ $# -eq 8 ]; then
631 while [ $count -lt $max ]; do
632 if [ "$PMS_VERSION" == "V2" ]; then
636 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
637 if [ $trans != "NOTRANSIENT" ]; then
638 inputJson=$inputJson", \"transient\":$trans"
640 if [ $pt != "NOTYPE" ]; then
641 inputJson=$inputJson", \"policytype_id\":\"$pt\""
643 inputJson=$inputJson", \"policytype_id\":\"\""
645 if [ $noti != "NOURL" ]; then
646 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
649 data=$(sed 's/XXX/'${pid}'/g' $temp)
650 inputJson=$inputJson", \"policy_data\":$data"
651 inputJson="{$inputJson}"
652 echo $inputJson > $file
654 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
656 if [ $pt != "NOTYPE" ]; then
657 query=$query"&type=$pt"
660 if [ $trans != NOTRANSIENT ]; then
661 query=$query"&transient=$trans"
665 sed 's/XXX/'${pid}'/g' $temp > $file
667 res="$(__do_curl_to_api PA PUT $query $file)"
668 status=${res:${#res}-3}
669 echo -ne " Executing "$count"("$max")${SAMELINE}"
670 if [ $status -ne $1 ]; then
671 echo " Executed "$count"?("$max")"
672 __log_test_fail_status_code $1 $status
678 echo -ne " Executed "$count"("$max")${SAMELINE}"
686 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
687 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
688 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
689 # (Function for test scripts)
691 api_put_policy_batch() {
694 if [ "$PMS_VERSION" == "V2" ]; then
695 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
696 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
700 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
701 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
713 if [ "$PMS_VERSION" == "V2" ]; then
716 if [ $# -eq 9 ]; then
721 if [ $# -eq 8 ]; then
727 while [ $count -lt $max ]; do
728 if [ "$PMS_VERSION" == "V2" ]; then
731 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
732 if [ $trans != "NOTRANSIENT" ]; then
733 inputJson=$inputJson", \"transient\":$trans"
735 if [ $pt != "NOTYPE" ]; then
736 inputJson=$inputJson", \"policytype_id\":\"$pt\""
738 inputJson=$inputJson", \"policytype_id\":\"\""
740 if [ $noti != "NOURL" ]; then
741 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
744 data=$(sed 's/XXX/'${pid}'/g' $temp)
745 inputJson=$inputJson", \"policy_data\":$data"
746 inputJson="{$inputJson}"
747 echo $inputJson > $file
749 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
751 if [ $pt != "NOTYPE" ]; then
752 query=$query"&type=$pt"
755 if [ $trans != NOTRANSIENT ]; then
756 query=$query"&transient=$trans"
759 sed 's/XXX/'${pid}'/g' $temp > $file
761 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
762 status=${res:${#res}-3}
763 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
765 if [ $status -ne 200 ]; then
766 echo " Requested(batch) "$count"?("$max")"
767 __log_test_fail_status_code 200 $status
770 cid=${res:0:${#res}-3}
774 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
781 res="$(__do_curl_to_api PA RESPONSE $cid)"
782 status=${res:${#res}-3}
783 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
785 if [ $status -ne $1 ]; then
786 echo " Accepted(batch) "$count"?("$max")"
787 __log_test_fail_status_code $1 $status
792 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
801 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
802 # 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>
803 # 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>
804 # (Function for test scripts)
805 api_put_policy_parallel() {
808 if [ "$PMS_VERSION" == "V2" ]; then
809 if [ $# -ne 11 ]; then
810 __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>" $@
814 if [ $# -ne 10 ]; then
815 __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>" $@
826 if [ "$PMS_VERSION" == "V2" ]; then
835 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
836 if [ $PA_ADAPTER_TYPE != "REST" ]; then
837 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
838 echo " Info - will execute over agent REST"
840 if [ "$PMS_VERSION" == "V2" ]; then
841 if [ $serv == "NOSERVICE" ]; then
844 query="$PMS_API_PREFIX/v2/policies"
846 if [ $serv == "NOSERVICE" ]; then
849 query="/policy?service=$serv"
851 if [ $type != "NOTYPE" ]; then
852 query=$query"&type=$type"
855 if [ $transient != NOTRANSIENT ]; then
856 query=$query"&transient=$transient"
860 urlbase=${PA_ADAPTER}${query}
862 for ((i=1; i<=$pids; i++))
865 if [ -z "$uuid" ]; then
868 echo "" > "./tmp/.pid${i}.res.txt"
869 if [ "$PMS_VERSION" == "V2" ]; then
870 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i > "./tmp/.pid${i}.txt"
872 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt"
875 done | xargs -n 1 -I{} -P $pids bash -c '{
877 echo " Parallel process $arg started"
878 tmp=$(< "./tmp/.pid${arg}.txt")
879 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
882 for ((i=1; i<=$pids; i++))
884 file="./tmp/.pid${i}.res.txt"
886 if [ -z "$tmp" ]; then
887 echo " Process $i : unknown result (result file empty"
891 if [ $res == "0" ]; then
892 echo " Process $i : OK - "${tmp:1}
894 echo " Process $i : failed - "${tmp:1}
900 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
904 __log_test_fail_general "One of more processes failed to execute"
908 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
909 # args: <response-code> <policy-id> [count]
910 # (Function for test scripts)
911 api_delete_policy() {
914 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
915 __print_err "<response-code> <policy-id> [count]" $@
922 if [ $# -eq 3 ]; then
928 while [ $count -lt $max ]; do
929 if [ "$PMS_VERSION" == "V2" ]; then
930 query="/v2/policies/"$UUID$pid
932 query="/policy?id="$UUID$pid
934 res="$(__do_curl_to_api PA DELETE $query)"
935 status=${res:${#res}-3}
936 echo -ne " Executing "$count"("$max")${SAMELINE}"
938 if [ $status -ne $1 ]; then
939 echo " Executed "$count"?("$max")"
940 __log_test_fail_status_code $1 $status
945 echo -ne " Executed "$count"("$max")${SAMELINE}"
953 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
954 # args: <response-code> <policy-id> [count]
955 # (Function for test scripts)
956 api_delete_policy_batch() {
959 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
960 __print_err "<response-code> <policy-id> [count]" $@
967 if [ $# -eq 3 ]; then
973 while [ $count -lt $max ]; do
974 if [ "$PMS_VERSION" == "V2" ]; then
975 query="/v2/policies/"$UUID$pid
977 query="/policy?id="$UUID$pid
979 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
980 status=${res:${#res}-3}
981 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
983 if [ $status -ne 200 ]; then
984 echo " Requested(batch) "$count"?("$max")"
985 __log_test_fail_status_code 200 $status
988 cid=${res:0:${#res}-3}
992 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1000 res="$(__do_curl_to_api PA RESPONSE $cid)"
1001 status=${res:${#res}-3}
1002 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1004 if [ $status -ne $1 ]; then
1005 echo " Deleted(batch) "$count"?("$max")"
1006 __log_test_fail_status_code $1 $status
1011 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1020 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1021 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1022 # (Function for test scripts)
1023 api_delete_policy_parallel() {
1026 if [ $# -ne 5 ]; then
1027 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1030 resp_code=$1; shift;
1036 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1037 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1038 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1039 echo " Info - will execute over agent REST"
1042 if [ "$PMS_VERSION" == "V2" ]; then
1043 query="$PMS_API_PREFIX/v2/policies/"
1048 urlbase=${PA_ADAPTER}${query}
1050 for ((i=1; i<=$pids; i++))
1053 if [ -z "$uuid" ]; then
1056 echo "" > "./tmp/.pid${i}.del.res.txt"
1057 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > "./tmp/.pid${i}.del.txt"
1059 done | xargs -n 1 -I{} -P $pids bash -c '{
1061 echo " Parallel process $arg started"
1062 tmp=$(< "./tmp/.pid${arg}.del.txt")
1063 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1066 for ((i=1; i<=$pids; i++))
1068 file="./tmp/.pid${i}.del.res.txt"
1070 if [ -z "$tmp" ]; then
1071 echo " Process $i : unknown result (result file empty"
1075 if [ $res == "0" ]; then
1076 echo " Process $i : OK - "${tmp:1}
1078 echo " Process $i : failed - "${tmp:1}
1083 if [ -z $msg ]; then
1084 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1088 __log_test_fail_general "One of more processes failed to execute"
1092 # API Test function: GET /policy_ids and V2 GET /v2/policies
1093 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1094 # (Function for test scripts)
1095 api_get_policy_ids() {
1098 if [ $# -lt 4 ]; then
1099 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1105 if [ "$PMS_VERSION" == "V2" ]; then
1106 if [ $2 != "NORIC" ]; then
1107 queryparams="?ric_id="$2
1110 if [ $3 != "NOSERVICE" ]; then
1111 if [ -z $queryparams ]; then
1112 queryparams="?service_id="$3
1114 queryparams=$queryparams"&service_id="$3
1117 if [ $4 != "NOTYPE" ]; then
1118 if [ -z $queryparams ]; then
1119 queryparams="?policytype_id="$4
1121 queryparams=$queryparams"&policytype_id="$4
1125 query="/v2/policies"$queryparams
1127 if [ $2 != "NORIC" ]; then
1128 queryparams="?ric="$2
1131 if [ $3 != "NOSERVICE" ]; then
1132 if [ -z $queryparams ]; then
1133 queryparams="?service="$3
1135 queryparams=$queryparams"&service="$3
1138 if [ $4 != "NOTYPE" ]; then
1139 if [ -z $queryparams ]; then
1140 queryparams="?type="$4
1142 queryparams=$queryparams"&type="$4
1146 query="/policy_ids"$queryparams
1149 res="$(__do_curl_to_api PA GET $query)"
1150 status=${res:${#res}-3}
1152 if [ $status -ne $1 ]; then
1153 __log_test_fail_status_code $1 $status
1157 if [ $# -gt 4 ]; then
1158 body=${res:0:${#res}-3}
1161 for pid in ${@:5} ; do
1162 if [ "$targetJson" != "[" ]; then
1163 targetJson=$targetJson","
1165 if [ $pid != "NOID" ]; then
1166 targetJson=$targetJson"\"$UUID$pid\""
1170 targetJson=$targetJson"]"
1171 if [ "$PMS_VERSION" == "V2" ]; then
1172 targetJson="{\"policy_ids\": $targetJson}"
1174 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1175 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1177 if [ $res -ne 0 ]; then
1178 __log_test_fail_body
1187 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1188 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1189 # (Function for test scripts)
1190 api_get_policy_type() {
1193 if [ "$PMS_VERSION" != "V2" ]; then
1194 __log_test_fail_not_supported
1198 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1199 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1202 query="/v2/policy-types/$2"
1204 res="$(__do_curl_to_api PA GET $query)"
1205 status=${res:${#res}-3}
1207 if [ $status -ne $1 ]; then
1208 __log_test_fail_status_code $1 $status
1212 if [ $# -eq 3 ]; then
1214 body=${res:0:${#res}-3}
1217 targetJson="{\"policy_schema\":$targetJson}"
1218 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1219 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1221 if [ $res -ne 0 ]; then
1222 __log_test_fail_body
1231 # API Test function: GET /policy_schema
1232 # args: <response-code> <policy-type-id> [<schema-file>]
1233 # (Function for test scripts)
1234 api_get_policy_schema() {
1237 if [ "$PMS_VERSION" == "V2" ]; then
1238 __log_test_fail_not_supported
1242 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1243 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1246 query="/policy_schema?id=$2"
1247 res="$(__do_curl_to_api PA GET $query)"
1248 status=${res:${#res}-3}
1250 if [ $status -ne $1 ]; then
1251 __log_test_fail_status_code $1 $status
1255 if [ $# -eq 3 ]; then
1257 body=${res:0:${#res}-3}
1261 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1262 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1264 if [ $res -ne 0 ]; then
1265 __log_test_fail_body
1274 # API Test function: GET /policy_schemas
1275 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1276 # args(V2): <response-code>
1277 # (Function for test scripts)
1278 api_get_policy_schemas() {
1281 if [ "$PMS_VERSION" == "V2" ]; then
1282 if [ $# -ne 1 ]; then
1283 __print_err "<response-code>" $@
1287 if [ $# -lt 2 ]; then
1288 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1292 if [ "$PMS_VERSION" == "V2" ]; then
1293 query="/v2/policy-schemas"
1295 query="/policy_schemas"
1296 if [ $2 != "NORIC" ]; then
1297 query=$query"?ric="$2
1301 res="$(__do_curl_to_api PA GET $query)"
1302 status=${res:${#res}-3}
1304 if [ $status -ne $1 ]; then
1305 __log_test_fail_status_code $1 $status
1309 if [ $# -gt 2 ]; then
1310 body=${res:0:${#res}-3}
1313 for file in ${@:3} ; do
1314 if [ "$targetJson" != "[" ]; then
1315 targetJson=$targetJson","
1317 if [ $file == "NOFILE" ]; then
1318 targetJson=$targetJson"{}"
1320 targetJson=$targetJson$(< $file)
1324 targetJson=$targetJson"]"
1325 if [ "$PMS_VERSION" == "V2" ]; then
1326 targetJson="{\"policy_schemas\": $targetJson }"
1328 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1329 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1331 if [ $res -ne 0 ]; then
1332 __log_test_fail_body
1341 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1342 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1343 # (Function for test scripts)
1344 api_get_policy_status() {
1347 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1348 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1354 if [ $3 == "STD" ]; then
1355 targetJson="{\"enforceStatus\":\"$4\""
1356 if [ $# -eq 5 ]; then
1357 targetJson=$targetJson",\"reason\":\"$5\""
1359 targetJson=$targetJson"}"
1360 elif [ $3 == "STD2" ]; then
1361 if [ $4 == "EMPTY" ]; then
1362 targetJson="{\"enforceStatus\":\"\""
1364 targetJson="{\"enforceStatus\":\"$4\""
1366 if [ $# -eq 5 ]; then
1367 if [ $5 == "EMPTY" ]; then
1368 targetJson=$targetJson",\"enforceReason\":\"\""
1370 targetJson=$targetJson",\"enforceReason\":\"$5\""
1373 targetJson=$targetJson"}"
1374 elif [ $3 == "OSC" ]; then
1375 targetJson="{\"instance_status\":\"$4\""
1376 if [ $# -eq 5 ]; then
1377 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1379 targetJson=$targetJson",\"created_at\":\"????\"}"
1381 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1385 if [ "$PMS_VERSION" == "V2" ]; then
1386 query="/v2/policies/$UUID$2/status"
1387 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1389 query="/policy_status?id="$UUID$2
1392 res="$(__do_curl_to_api PA GET $query)"
1393 status=${res:${#res}-3}
1395 if [ $status -ne $1 ]; then
1396 __log_test_fail_status_code $1 $status
1400 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1401 body=${res:0:${#res}-3}
1402 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1404 if [ $res -ne 0 ]; then
1405 __log_test_fail_body
1413 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1414 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1415 # (Function for test scripts)
1416 api_get_policy_types() {
1419 if [ $# -lt 1 ]; then
1420 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1424 if [ "$PMS_VERSION" == "V2" ]; then
1425 if [ $# -eq 1 ]; then
1426 query="/v2/policy-types"
1427 elif [ $2 == "NORIC" ]; then
1428 query="/v2/policy-types"
1430 query="/v2/policy-types?ric_id=$2"
1433 if [ $# -eq 1 ]; then
1434 query="/policy_types"
1435 elif [ $2 == "NORIC" ]; then
1436 query="/policy_types"
1438 query="/policy_types?ric=$2"
1442 res="$(__do_curl_to_api PA GET $query)"
1443 status=${res:${#res}-3}
1445 if [ $status -ne $1 ]; then
1446 __log_test_fail_status_code $1 $status
1450 if [ $# -gt 2 ]; then
1451 body=${res:0:${#res}-3}
1454 for pid in ${@:3} ; do
1455 if [ "$targetJson" != "[" ]; then
1456 targetJson=$targetJson","
1458 if [ $pid == "EMPTY" ]; then
1461 targetJson=$targetJson"\"$pid\""
1464 targetJson=$targetJson"]"
1465 if [ "$PMS_VERSION" == "V2" ]; then
1466 targetJson="{\"policytype_ids\": $targetJson }"
1468 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1469 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1471 if [ $res -ne 0 ]; then
1472 __log_test_fail_body
1481 #########################################################
1482 #### Test case functions Health check
1483 #########################################################
1485 # API Test function: GET /status and V2 GET /status
1486 # args: <response-code>
1487 # (Function for test scripts)
1490 if [ $# -ne 1 ]; then
1491 __print_err "<response-code>" $@
1494 if [ "$PMS_VERSION" == "V2" ]; then
1499 res="$(__do_curl_to_api PA GET $query)"
1500 status=${res:${#res}-3}
1502 if [ $status -ne $1 ]; then
1503 __log_test_fail_status_code $1 $status
1511 #########################################################
1512 #### Test case functions RIC Repository
1513 #########################################################
1515 # API Test function: GET /ric and V2 GET /v2/rics/ric
1516 # args: <reponse-code> <management-element-id> [<ric-id>]
1517 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1518 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1519 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1522 # (Function for test scripts)
1526 if [ "$PMS_VERSION" == "V2" ]; then
1527 if [ $# -lt 3 ]; then
1528 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1532 if [ $2 != "NOME" ]; then
1533 search="?managed_element_id="$2
1535 if [ $3 != "NORIC" ]; then
1536 if [ -z $search ]; then
1539 search=$search"&ric_id="$3
1542 query="/v2/rics/ric"$search
1544 res="$(__do_curl_to_api PA GET $query)"
1545 status=${res:${#res}-3}
1547 if [ $status -ne $1 ]; then
1548 __log_test_fail_status_code $1 $status
1552 if [ $# -gt 3 ]; then
1553 body=${res:0:${#res}-3}
1554 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1555 if [ $res -ne 0 ]; then
1556 __log_test_fail_general "Could not create target ric info json"
1560 targetJson=$(<./tmp/.tmp_rics.json)
1561 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1562 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1563 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1564 if [ $res -ne 0 ]; then
1565 __log_test_fail_body
1570 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1571 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1575 query="/ric?managedElementId="$2
1577 res="$(__do_curl_to_api PA GET $query)"
1578 status=${res:${#res}-3}
1580 if [ $status -ne $1 ]; then
1581 __log_test_fail_status_code $1 $status
1585 if [ $# -eq 3 ]; then
1586 body=${res:0:${#res}-3}
1587 if [ "$body" != "$3" ]; then
1588 __log_test_fail_body
1597 # API test function: GET /rics and V2 GET /v2/rics
1598 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1599 # 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_........."
1600 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1601 # (Function for test scripts)
1605 if [ $# -lt 2 ]; then
1606 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1610 if [ "$PMS_VERSION" == "V2" ]; then
1612 if [ $2 != "NOTYPE" ]; then
1613 query="/v2/rics?policytype_id="$2
1617 if [ $2 != "NOTYPE" ]; then
1618 query="/rics?policyType="$2
1622 res="$(__do_curl_to_api PA GET $query)"
1623 status=${res:${#res}-3}
1625 if [ $status -ne $1 ]; then
1626 __log_test_fail_status_code $1 $status
1630 if [ $# -gt 2 ]; then
1631 body=${res:0:${#res}-3}
1632 if [ "$PMS_VERSION" == "V2" ]; then
1633 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1635 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1637 if [ $res -ne 0 ]; then
1638 __log_test_fail_general "Could not create target ric info json"
1642 targetJson=$(<./tmp/.tmp_rics.json)
1643 if [ "$PMS_VERSION" == "V2" ]; then
1644 targetJson="{\"rics\": $targetJson }"
1646 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1647 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1648 if [ $res -ne 0 ]; then
1649 __log_test_fail_body
1658 ##################################################################
1659 #### API Test case functions Service registry and supervision ####
1660 ##################################################################
1662 # API test function: PUT /service and V2 PUT /service
1663 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1664 # (Function for test scripts)
1667 if [ $# -ne 4 ]; then
1668 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1672 if [ "$PMS_VERSION" == "V2" ]; then
1673 query="/v2/services"
1674 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1677 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1679 file="./tmp/.tmp.json"
1680 echo "$json" > $file
1682 res="$(__do_curl_to_api PA PUT $query $file)"
1683 status=${res:${#res}-3}
1685 if [ $status -ne $1 ]; then
1686 __log_test_fail_status_code $1 $status
1694 # API test function: GET /services and V2 GET /v2/services
1695 #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>]* )]
1696 # (Function for test scripts)
1697 api_get_services() {
1699 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1701 if [ $# -eq 1 ]; then
1703 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1705 elif [ $# -eq 5 ]; then
1707 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1709 if [ $(($argLen%3)) -eq 0 ]; then
1714 if [ $paramError -ne 0 ]; then
1715 __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>]* )]" $@
1719 if [ "$PMS_VERSION" == "V2" ]; then
1720 query="/v2/services"
1722 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1723 query="/v2/services?service_id="$2
1728 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1729 query="/services?name="$2
1732 res="$(__do_curl_to_api PA GET $query)"
1733 status=${res:${#res}-3}
1735 if [ $status -ne $1 ]; then
1736 __log_test_fail_status_code $1 $status
1740 if [ $# -gt 2 ]; then
1741 variableArgCount=$(($#-2))
1742 body=${res:0:${#res}-3}
1746 while [ $cntr -lt $variableArgCount ]; do
1747 servicename=$1; shift;
1750 if [ $cntr -gt 0 ]; then
1751 targetJson=$targetJson","
1753 # timeSinceLastActivitySeconds value cannot be checked since value varies
1754 if [ "$PMS_VERSION" == "V2" ]; then
1755 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1757 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1761 targetJson=$targetJson"]"
1762 if [ "$PMS_VERSION" == "V2" ]; then
1763 targetJson="{\"service_list\": $targetJson }"
1765 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1766 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1767 if [ $res -ne 0 ]; then
1768 __log_test_fail_body
1777 # API test function: GET /services V2 GET /v2/services - (only checking service names)
1778 # args: <response-code> [<service-name>]*"
1779 # (Function for test scripts)
1780 api_get_service_ids() {
1783 if [ $# -lt 1 ]; then
1784 __print_err "<response-code> [<service-name>]*" $@
1788 if [ "$PMS_VERSION" == "V2" ]; then
1789 query="/v2/services"
1793 res="$(__do_curl_to_api PA GET $query)"
1794 status=${res:${#res}-3}
1796 if [ $status -ne $1 ]; then
1797 __log_test_fail_status_code $1 $status
1801 body=${res:0:${#res}-3}
1803 for rapp in ${@:2} ; do
1804 if [ "$targetJson" != "[" ]; then
1805 targetJson=$targetJson","
1807 if [ "$PMS_VERSION" == "V2" ]; then
1808 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
1810 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1814 targetJson=$targetJson"]"
1815 if [ "$PMS_VERSION" == "V2" ]; then
1816 targetJson="{\"service_list\": $targetJson }"
1818 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1819 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1821 if [ $res -ne 0 ]; then
1822 __log_test_fail_body
1830 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
1831 # args: <response-code> <service-name>
1832 # (Function for test scripts)
1833 api_delete_services() {
1836 if [ $# -ne 2 ]; then
1837 __print_err "<response-code> <service-name>" $@
1840 if [ "$PMS_VERSION" == "V2" ]; then
1841 query="/v2/services/"$2
1843 query="/services?name="$2
1845 res="$(__do_curl_to_api PA DELETE $query)"
1846 status=${res:${#res}-3}
1848 if [ $status -ne $1 ]; then
1849 __log_test_fail_status_code $1 $status
1857 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
1858 # args: <response-code> <service-name>
1859 # (Function for test scripts)
1860 api_put_services_keepalive() {
1863 if [ $# -ne 2 ]; then
1864 __print_err "<response-code> <service-name>" $@
1867 if [ "$PMS_VERSION" == "V2" ]; then
1868 query="/v2/services/$2/keepalive"
1870 query="/services/keepalive?name="$2
1873 res="$(__do_curl_to_api PA PUT $query)"
1874 status=${res:${#res}-3}
1876 if [ $status -ne $1 ]; then
1877 __log_test_fail_status_code $1 $status
1885 ##################################################################
1886 #### API Test case functions Configuration ####
1887 ##################################################################
1889 # API Test function: PUT /v2/configuration
1890 # args: <response-code> <config-file>
1891 # (Function for test scripts)
1892 api_put_configuration() {
1895 if [ "$PMS_VERSION" != "V2" ]; then
1896 __log_test_fail_not_supported
1900 if [ $# -ne 2 ]; then
1901 __print_err "<response-code> <config-file>" $@
1904 if [ ! -f $2 ]; then
1905 _log_test_fail_general "Config file "$2", does not exist"
1909 inputJson="{\"config\":"$inputJson"}"
1910 file="./tmp/.config.json"
1911 echo $inputJson > $file
1912 query="/v2/configuration"
1913 res="$(__do_curl_to_api PA PUT $query $file)"
1914 status=${res:${#res}-3}
1916 if [ $status -ne $1 ]; then
1917 __log_test_fail_status_code $1 $status
1925 # API Test function: GET /v2/configuration
1926 # args: <response-code> [<config-file>]
1927 # (Function for test scripts)
1928 api_get_configuration() {
1931 if [ "$PMS_VERSION" != "V2" ]; then
1932 __log_test_fail_not_supported
1936 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
1937 __print_err "<response-code> [<config-file>]" $@
1940 if [ ! -f $2 ]; then
1941 _log_test_fail_general "Config file "$2" for comparison, does not exist"
1945 query="/v2/configuration"
1946 res="$(__do_curl_to_api PA GET $query)"
1947 status=${res:${#res}-3}
1949 if [ $status -ne $1 ]; then
1950 __log_test_fail_status_code $1 $status
1954 if [ $# -eq 2 ]; then
1956 body=${res:0:${#res}-3}
1959 targetJson="{\"config\":"$targetJson"}"
1960 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1961 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1963 if [ $res -ne 0 ]; then
1964 __log_test_fail_body