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 agent_load_config() {
261 echo -e $BOLD"Agent - load config from "$EBOLD$1
262 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
264 output_yaml=$PWD/tmp/pa_cfd.yaml
265 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
269 # Turn on debug level tracing in the agent
271 # (Function for test scripts)
273 echo -e $BOLD"Setting agent debug logging"$EBOLD
274 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
275 result=$(__do_curl "$curlString")
276 if [ $? -ne 0 ]; then
277 __print_err "could not set debug mode" $@
285 # Turn on trace level tracing in the agent
287 # (Function for test scripts)
289 echo -e $BOLD"Setting agent trace logging"$EBOLD
290 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
291 result=$(__do_curl "$curlString")
292 if [ $? -ne 0 ]; then
293 __print_err "could not set trace mode" $@
301 # Perform curl retries when making direct call to the agent for the specified http response codes
302 # Speace separated list of http response codes
303 # args: [<response-code>]*
304 use_agent_retries() {
305 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
311 #########################################################
312 #### Test case functions A1 Policy management service
313 #########################################################
315 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
316 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
317 # args: json:<url> <target-value> [<timeout-in-seconds]
318 # (Function for test scripts)
320 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
321 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
322 if [[ $1 == "json:"* ]]; then
323 if [ "$PMS_VERSION" == "V2" ]; then
324 __var_test "Policy Agent" $PA_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
326 __var_test "Policy Agent" $PA_PATH"/" $1 "=" $2 $3
331 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
335 # API Test function: GET /policies and V2 GET /v2/policy-instances
336 # 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>]*]
337 # 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>]*]
338 # (Function for test scripts)
342 if [ "$PMS_VERSION" == "V2" ]; then
344 variableParams=$(($#-4))
345 if [ $# -lt 4 ]; then
347 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
349 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
353 if [ $paramError -ne 0 ]; then
354 __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>]*]" $@
359 variableParams=$(($#-4))
360 if [ $# -lt 4 ]; then
362 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
364 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
368 if [ $paramError -ne 0 ]; then
369 __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>]*]" $@
375 if [ "$PMS_VERSION" == "V2" ]; then
376 if [ $2 != "NORIC" ]; then
377 queryparams="?ric_id="$2
379 if [ $3 != "NOSERVICE" ]; then
380 if [ -z $queryparams ]; then
381 queryparams="?service_id="$3
383 queryparams=$queryparams"&service_id="$3
386 if [ $4 != "NOTYPE" ]; then
387 if [ -z $queryparams ]; then
388 queryparams="?policytype_id="$4
390 queryparams=$queryparams"&policytype_id="$4
394 query="/v2/policy-instances"$queryparams
395 res="$(__do_curl_to_api PA GET $query)"
396 status=${res:${#res}-3}
398 if [ $status -ne $1 ]; then
399 __log_test_fail_status_code $1 $status
403 if [ $# -gt 4 ]; then
404 body=${res:0:${#res}-3}
405 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
411 for ((i=0; i<$(($#-4)); i=i+7)); do
413 if [ "$targetJson" != "[" ]; then
414 targetJson=$targetJson","
416 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
417 if [ "${arr[$i+3]}" == "EMPTY" ]; then
418 targetJson=$targetJson"\"\","
420 targetJson=$targetJson"\"${arr[$i+3]}\","
422 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
424 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
426 targetJson=$targetJson"\"policy_data\":"$json"}"
430 targetJson=$targetJson"]"
431 targetJson="{\"policies\": $targetJson}"
432 echo "TARGET JSON: $targetJson" >> $HTTPLOG
433 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
435 if [ $res -ne 0 ]; then
441 if [ $2 != "NORIC" ]; then
442 queryparams="?ric="$2
444 if [ $3 != "NOSERVICE" ]; then
445 if [ -z $queryparams ]; then
446 queryparams="?service="$3
448 queryparams=$queryparams"&service="$3
451 if [ $4 != "NOTYPE" ]; then
452 if [ -z $queryparams ]; then
453 queryparams="?type="$4
455 queryparams=$queryparams"&type="$4
459 query="/policies"$queryparams
460 res="$(__do_curl_to_api PA GET $query)"
461 status=${res:${#res}-3}
463 if [ $status -ne $1 ]; then
464 __log_test_fail_status_code $1 $status
468 if [ $# -gt 4 ]; then
469 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
472 body=${res:0:${#res}-3}
476 for ((i=0; i<$(($#-4)); i=i+5)); do
478 if [ "$targetJson" != "[" ]; then
479 targetJson=$targetJson","
481 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
482 if [ "${arr[$i+3]}" == "EMPTY" ]; then
483 targetJson=$targetJson"\"\","
485 targetJson=$targetJson"\"${arr[$i+3]}\","
488 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
490 targetJson=$targetJson"\"json\":"$json"}"
494 targetJson=$targetJson"]"
495 echo "TARGET JSON: $targetJson" >> $HTTPLOG
496 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
498 if [ $res -ne 0 ]; then
511 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
512 # args: <response-code> <policy-id> [<template-file>]
513 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
515 # (Function for test scripts)
520 if [ "$PMS_VERSION" == "V2" ]; then
521 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
522 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
525 query="/v2/policies/$UUID$2"
527 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
528 __print_err "<response-code> <policy-id> [<template-file>] " $@
531 query="/policy?id=$UUID$2"
533 res="$(__do_curl_to_api PA GET $query)"
534 status=${res:${#res}-3}
536 if [ $status -ne $1 ]; then
537 __log_test_fail_status_code $1 $status
541 if [ "$PMS_VERSION" == "V2" ]; then
542 if [ $# -eq 8 ]; then
544 #Create a policy json to compare with
545 body=${res:0:${#res}-3}
547 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
548 if [ $7 != "NOTRANSIENT" ]; then
549 targetJson=$targetJson", \"transient\":$7"
551 if [ $6 != "NOTYPE" ]; then
552 targetJson=$targetJson", \"policytype_id\":\"$6\""
554 targetJson=$targetJson", \"policytype_id\":\"\""
556 if [ $8 != "NOURL" ]; then
557 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
560 data=$(sed 's/XXX/'${2}'/g' $3)
561 targetJson=$targetJson", \"policy_data\":$data"
562 targetJson="{$targetJson}"
564 echo "TARGET JSON: $targetJson" >> $HTTPLOG
565 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
566 if [ $res -ne 0 ]; then
572 if [ $# -eq 3 ]; then
573 #Create a policy json to compare with
574 body=${res:0:${#res}-3}
576 sed 's/XXX/'${2}'/g' $3 > $file
577 targetJson=$(< $file)
578 echo "TARGET JSON: $targetJson" >> $HTTPLOG
579 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
580 if [ $res -ne 0 ]; then
590 # API Test function: PUT /policy and V2 PUT /policies
591 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
592 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
593 # (Function for test scripts)
597 if [ "$PMS_VERSION" == "V2" ]; then
598 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
599 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
603 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
604 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
617 if [ "$PMS_VERSION" == "V2" ]; then
620 if [ $# -eq 9 ]; then
625 if [ $# -eq 8 ]; then
630 while [ $count -lt $max ]; do
631 if [ "$PMS_VERSION" == "V2" ]; then
635 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
636 if [ $trans != "NOTRANSIENT" ]; then
637 inputJson=$inputJson", \"transient\":$trans"
639 if [ $pt != "NOTYPE" ]; then
640 inputJson=$inputJson", \"policytype_id\":\"$pt\""
642 inputJson=$inputJson", \"policytype_id\":\"\""
644 if [ $noti != "NOURL" ]; then
645 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
648 data=$(sed 's/XXX/'${pid}'/g' $temp)
649 inputJson=$inputJson", \"policy_data\":$data"
650 inputJson="{$inputJson}"
651 echo $inputJson > $file
653 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
655 if [ $pt != "NOTYPE" ]; then
656 query=$query"&type=$pt"
659 if [ $trans != NOTRANSIENT ]; then
660 query=$query"&transient=$trans"
664 sed 's/XXX/'${pid}'/g' $temp > $file
666 res="$(__do_curl_to_api PA PUT $query $file)"
667 status=${res:${#res}-3}
668 echo -ne " Executing "$count"("$max")${SAMELINE}"
669 if [ $status -ne $1 ]; then
670 echo " Executed "$count"?("$max")"
671 __log_test_fail_status_code $1 $status
677 echo -ne " Executed "$count"("$max")${SAMELINE}"
685 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
686 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
687 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
688 # (Function for test scripts)
690 api_put_policy_batch() {
693 if [ "$PMS_VERSION" == "V2" ]; then
694 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
695 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
699 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
700 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
712 if [ "$PMS_VERSION" == "V2" ]; then
715 if [ $# -eq 9 ]; then
720 if [ $# -eq 8 ]; then
726 while [ $count -lt $max ]; do
727 if [ "$PMS_VERSION" == "V2" ]; then
730 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
731 if [ $trans != "NOTRANSIENT" ]; then
732 inputJson=$inputJson", \"transient\":$trans"
734 if [ $pt != "NOTYPE" ]; then
735 inputJson=$inputJson", \"policytype_id\":\"$pt\""
737 inputJson=$inputJson", \"policytype_id\":\"\""
739 if [ $noti != "NOURL" ]; then
740 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
743 data=$(sed 's/XXX/'${pid}'/g' $temp)
744 inputJson=$inputJson", \"policy_data\":$data"
745 inputJson="{$inputJson}"
746 echo $inputJson > $file
748 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
750 if [ $pt != "NOTYPE" ]; then
751 query=$query"&type=$pt"
754 if [ $trans != NOTRANSIENT ]; then
755 query=$query"&transient=$trans"
758 sed 's/XXX/'${pid}'/g' $temp > $file
760 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
761 status=${res:${#res}-3}
762 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
764 if [ $status -ne 200 ]; then
765 echo " Requested(batch) "$count"?("$max")"
766 __log_test_fail_status_code 200 $status
769 cid=${res:0:${#res}-3}
773 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
780 res="$(__do_curl_to_api PA RESPONSE $cid)"
781 status=${res:${#res}-3}
782 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
784 if [ $status -ne $1 ]; then
785 echo " Accepted(batch) "$count"?("$max")"
786 __log_test_fail_status_code $1 $status
791 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
800 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
801 # 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>
802 # 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>
803 # (Function for test scripts)
804 api_put_policy_parallel() {
807 if [ "$PMS_VERSION" == "V2" ]; then
808 if [ $# -ne 11 ]; then
809 __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>" $@
813 if [ $# -ne 10 ]; then
814 __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>" $@
825 if [ "$PMS_VERSION" == "V2" ]; then
834 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
835 if [ $PA_ADAPTER_TYPE != "REST" ]; then
836 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
837 echo " Info - will execute over agent REST"
839 if [ "$PMS_VERSION" == "V2" ]; then
840 if [ $serv == "NOSERVICE" ]; then
843 query="$PMS_API_PREFIX/v2/policies"
845 if [ $serv == "NOSERVICE" ]; then
848 query="/policy?service=$serv"
850 if [ $type != "NOTYPE" ]; then
851 query=$query"&type=$type"
854 if [ $transient != NOTRANSIENT ]; then
855 query=$query"&transient=$transient"
859 urlbase=${PA_ADAPTER}${query}
861 for ((i=1; i<=$pids; i++))
864 if [ -z "$uuid" ]; then
867 echo "" > "./tmp/.pid${i}.res.txt"
868 if [ "$PMS_VERSION" == "V2" ]; then
869 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i > "./tmp/.pid${i}.txt"
871 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt"
874 done | xargs -n 1 -I{} -P $pids bash -c '{
876 echo " Parallel process $arg started"
877 tmp=$(< "./tmp/.pid${arg}.txt")
878 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
881 for ((i=1; i<=$pids; i++))
883 file="./tmp/.pid${i}.res.txt"
885 if [ -z "$tmp" ]; then
886 echo " Process $i : unknown result (result file empty"
890 if [ $res == "0" ]; then
891 echo " Process $i : OK - "${tmp:1}
893 echo " Process $i : failed - "${tmp:1}
899 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
903 __log_test_fail_general "One of more processes failed to execute"
907 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
908 # args: <response-code> <policy-id> [count]
909 # (Function for test scripts)
910 api_delete_policy() {
913 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
914 __print_err "<response-code> <policy-id> [count]" $@
921 if [ $# -eq 3 ]; then
927 while [ $count -lt $max ]; do
928 if [ "$PMS_VERSION" == "V2" ]; then
929 query="/v2/policies/"$UUID$pid
931 query="/policy?id="$UUID$pid
933 res="$(__do_curl_to_api PA DELETE $query)"
934 status=${res:${#res}-3}
935 echo -ne " Executing "$count"("$max")${SAMELINE}"
937 if [ $status -ne $1 ]; then
938 echo " Executed "$count"?("$max")"
939 __log_test_fail_status_code $1 $status
944 echo -ne " Executed "$count"("$max")${SAMELINE}"
952 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
953 # args: <response-code> <policy-id> [count]
954 # (Function for test scripts)
955 api_delete_policy_batch() {
958 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
959 __print_err "<response-code> <policy-id> [count]" $@
966 if [ $# -eq 3 ]; then
972 while [ $count -lt $max ]; do
973 if [ "$PMS_VERSION" == "V2" ]; then
974 query="/v2/policies/"$UUID$pid
976 query="/policy?id="$UUID$pid
978 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
979 status=${res:${#res}-3}
980 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
982 if [ $status -ne 200 ]; then
983 echo " Requested(batch) "$count"?("$max")"
984 __log_test_fail_status_code 200 $status
987 cid=${res:0:${#res}-3}
991 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
999 res="$(__do_curl_to_api PA RESPONSE $cid)"
1000 status=${res:${#res}-3}
1001 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1003 if [ $status -ne $1 ]; then
1004 echo " Deleted(batch) "$count"?("$max")"
1005 __log_test_fail_status_code $1 $status
1010 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1019 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1020 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1021 # (Function for test scripts)
1022 api_delete_policy_parallel() {
1025 if [ $# -ne 5 ]; then
1026 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1029 resp_code=$1; shift;
1035 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1036 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1037 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1038 echo " Info - will execute over agent REST"
1041 if [ "$PMS_VERSION" == "V2" ]; then
1042 query="$PMS_API_PREFIX/v2/policies/"
1047 urlbase=${PA_ADAPTER}${query}
1049 for ((i=1; i<=$pids; i++))
1052 if [ -z "$uuid" ]; then
1055 echo "" > "./tmp/.pid${i}.del.res.txt"
1056 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > "./tmp/.pid${i}.del.txt"
1058 done | xargs -n 1 -I{} -P $pids bash -c '{
1060 echo " Parallel process $arg started"
1061 tmp=$(< "./tmp/.pid${arg}.del.txt")
1062 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1065 for ((i=1; i<=$pids; i++))
1067 file="./tmp/.pid${i}.del.res.txt"
1069 if [ -z "$tmp" ]; then
1070 echo " Process $i : unknown result (result file empty"
1074 if [ $res == "0" ]; then
1075 echo " Process $i : OK - "${tmp:1}
1077 echo " Process $i : failed - "${tmp:1}
1082 if [ -z $msg ]; then
1083 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1087 __log_test_fail_general "One of more processes failed to execute"
1091 # API Test function: GET /policy_ids and V2 GET /v2/policies
1092 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1093 # (Function for test scripts)
1094 api_get_policy_ids() {
1097 if [ $# -lt 4 ]; then
1098 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1104 if [ "$PMS_VERSION" == "V2" ]; then
1105 if [ $2 != "NORIC" ]; then
1106 queryparams="?ric_id="$2
1109 if [ $3 != "NOSERVICE" ]; then
1110 if [ -z $queryparams ]; then
1111 queryparams="?service_id="$3
1113 queryparams=$queryparams"&service_id="$3
1116 if [ $4 != "NOTYPE" ]; then
1117 if [ -z $queryparams ]; then
1118 queryparams="?policytype_id="$4
1120 queryparams=$queryparams"&policytype_id="$4
1124 query="/v2/policies"$queryparams
1126 if [ $2 != "NORIC" ]; then
1127 queryparams="?ric="$2
1130 if [ $3 != "NOSERVICE" ]; then
1131 if [ -z $queryparams ]; then
1132 queryparams="?service="$3
1134 queryparams=$queryparams"&service="$3
1137 if [ $4 != "NOTYPE" ]; then
1138 if [ -z $queryparams ]; then
1139 queryparams="?type="$4
1141 queryparams=$queryparams"&type="$4
1145 query="/policy_ids"$queryparams
1148 res="$(__do_curl_to_api PA GET $query)"
1149 status=${res:${#res}-3}
1151 if [ $status -ne $1 ]; then
1152 __log_test_fail_status_code $1 $status
1156 if [ $# -gt 4 ]; then
1157 body=${res:0:${#res}-3}
1160 for pid in ${@:5} ; do
1161 if [ "$targetJson" != "[" ]; then
1162 targetJson=$targetJson","
1164 if [ $pid != "NOID" ]; then
1165 targetJson=$targetJson"\"$UUID$pid\""
1169 targetJson=$targetJson"]"
1170 if [ "$PMS_VERSION" == "V2" ]; then
1171 targetJson="{\"policy_ids\": $targetJson}"
1173 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1174 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1176 if [ $res -ne 0 ]; then
1177 __log_test_fail_body
1186 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1187 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1188 # (Function for test scripts)
1189 api_get_policy_type() {
1192 if [ "$PMS_VERSION" != "V2" ]; then
1193 __log_test_fail_not_supported
1197 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1198 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1201 query="/v2/policy-types/$2"
1203 res="$(__do_curl_to_api PA GET $query)"
1204 status=${res:${#res}-3}
1206 if [ $status -ne $1 ]; then
1207 __log_test_fail_status_code $1 $status
1211 if [ $# -eq 3 ]; then
1213 body=${res:0:${#res}-3}
1216 targetJson="{\"policy_schema\":$targetJson}"
1217 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1218 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1220 if [ $res -ne 0 ]; then
1221 __log_test_fail_body
1230 # API Test function: GET /policy_schema
1231 # args: <response-code> <policy-type-id> [<schema-file>]
1232 # (Function for test scripts)
1233 api_get_policy_schema() {
1236 if [ "$PMS_VERSION" == "V2" ]; then
1237 __log_test_fail_not_supported
1241 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1242 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1245 query="/policy_schema?id=$2"
1246 res="$(__do_curl_to_api PA GET $query)"
1247 status=${res:${#res}-3}
1249 if [ $status -ne $1 ]; then
1250 __log_test_fail_status_code $1 $status
1254 if [ $# -eq 3 ]; then
1256 body=${res:0:${#res}-3}
1260 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1261 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1263 if [ $res -ne 0 ]; then
1264 __log_test_fail_body
1273 # API Test function: GET /policy_schemas
1274 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1275 # args(V2): <response-code>
1276 # (Function for test scripts)
1277 api_get_policy_schemas() {
1280 if [ "$PMS_VERSION" == "V2" ]; then
1281 if [ $# -ne 1 ]; then
1282 __print_err "<response-code>" $@
1286 if [ $# -lt 2 ]; then
1287 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1291 if [ "$PMS_VERSION" == "V2" ]; then
1292 query="/v2/policy-schemas"
1294 query="/policy_schemas"
1295 if [ $2 != "NORIC" ]; then
1296 query=$query"?ric="$2
1300 res="$(__do_curl_to_api PA GET $query)"
1301 status=${res:${#res}-3}
1303 if [ $status -ne $1 ]; then
1304 __log_test_fail_status_code $1 $status
1308 if [ $# -gt 2 ]; then
1309 body=${res:0:${#res}-3}
1312 for file in ${@:3} ; do
1313 if [ "$targetJson" != "[" ]; then
1314 targetJson=$targetJson","
1316 if [ $file == "NOFILE" ]; then
1317 targetJson=$targetJson"{}"
1319 targetJson=$targetJson$(< $file)
1323 targetJson=$targetJson"]"
1324 if [ "$PMS_VERSION" == "V2" ]; then
1325 targetJson="{\"policy_schemas\": $targetJson }"
1327 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1328 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1330 if [ $res -ne 0 ]; then
1331 __log_test_fail_body
1340 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1341 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1342 # (Function for test scripts)
1343 api_get_policy_status() {
1346 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1347 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1353 if [ $3 == "STD" ]; then
1354 targetJson="{\"enforceStatus\":\"$4\""
1355 if [ $# -eq 5 ]; then
1356 targetJson=$targetJson",\"reason\":\"$5\""
1358 targetJson=$targetJson"}"
1359 elif [ $3 == "STD2" ]; then
1360 if [ $4 == "EMPTY" ]; then
1361 targetJson="{\"enforceStatus\":\"\""
1363 targetJson="{\"enforceStatus\":\"$4\""
1365 if [ $# -eq 5 ]; then
1366 if [ $5 == "EMPTY" ]; then
1367 targetJson=$targetJson",\"enforceReason\":\"\""
1369 targetJson=$targetJson",\"enforceReason\":\"$5\""
1372 targetJson=$targetJson"}"
1373 elif [ $3 == "OSC" ]; then
1374 targetJson="{\"instance_status\":\"$4\""
1375 if [ $# -eq 5 ]; then
1376 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1378 targetJson=$targetJson",\"created_at\":\"????\"}"
1380 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1384 if [ "$PMS_VERSION" == "V2" ]; then
1385 query="/v2/policies/$UUID$2/status"
1386 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1388 query="/policy_status?id="$UUID$2
1391 res="$(__do_curl_to_api PA GET $query)"
1392 status=${res:${#res}-3}
1394 if [ $status -ne $1 ]; then
1395 __log_test_fail_status_code $1 $status
1399 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1400 body=${res:0:${#res}-3}
1401 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1403 if [ $res -ne 0 ]; then
1404 __log_test_fail_body
1412 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1413 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1414 # (Function for test scripts)
1415 api_get_policy_types() {
1418 if [ $# -lt 1 ]; then
1419 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1423 if [ "$PMS_VERSION" == "V2" ]; then
1424 if [ $# -eq 1 ]; then
1425 query="/v2/policy-types"
1426 elif [ $2 == "NORIC" ]; then
1427 query="/v2/policy-types"
1429 query="/v2/policy-types?ric_id=$2"
1432 if [ $# -eq 1 ]; then
1433 query="/policy_types"
1434 elif [ $2 == "NORIC" ]; then
1435 query="/policy_types"
1437 query="/policy_types?ric=$2"
1441 res="$(__do_curl_to_api PA GET $query)"
1442 status=${res:${#res}-3}
1444 if [ $status -ne $1 ]; then
1445 __log_test_fail_status_code $1 $status
1449 if [ $# -gt 2 ]; then
1450 body=${res:0:${#res}-3}
1453 for pid in ${@:3} ; do
1454 if [ "$targetJson" != "[" ]; then
1455 targetJson=$targetJson","
1457 if [ $pid == "EMPTY" ]; then
1460 targetJson=$targetJson"\"$pid\""
1463 targetJson=$targetJson"]"
1464 if [ "$PMS_VERSION" == "V2" ]; then
1465 targetJson="{\"policytype_ids\": $targetJson }"
1467 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1468 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1470 if [ $res -ne 0 ]; then
1471 __log_test_fail_body
1480 #########################################################
1481 #### Test case functions Health check
1482 #########################################################
1484 # API Test function: GET /status and V2 GET /status
1485 # args: <response-code>
1486 # (Function for test scripts)
1489 if [ $# -ne 1 ]; then
1490 __print_err "<response-code>" $@
1493 if [ "$PMS_VERSION" == "V2" ]; then
1498 res="$(__do_curl_to_api PA GET $query)"
1499 status=${res:${#res}-3}
1501 if [ $status -ne $1 ]; then
1502 __log_test_fail_status_code $1 $status
1510 #########################################################
1511 #### Test case functions RIC Repository
1512 #########################################################
1514 # API Test function: GET /ric and V2 GET /v2/rics/ric
1515 # args: <reponse-code> <management-element-id> [<ric-id>]
1516 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1517 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1518 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1521 # (Function for test scripts)
1525 if [ "$PMS_VERSION" == "V2" ]; then
1526 if [ $# -lt 3 ]; then
1527 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1531 if [ $2 != "NOME" ]; then
1532 search="?managed_element_id="$2
1534 if [ $3 != "NORIC" ]; then
1535 if [ -z $search ]; then
1538 search=$search"&ric_id="$3
1541 query="/v2/rics/ric"$search
1543 res="$(__do_curl_to_api PA GET $query)"
1544 status=${res:${#res}-3}
1546 if [ $status -ne $1 ]; then
1547 __log_test_fail_status_code $1 $status
1551 if [ $# -gt 3 ]; then
1552 body=${res:0:${#res}-3}
1553 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1554 if [ $res -ne 0 ]; then
1555 __log_test_fail_general "Could not create target ric info json"
1559 targetJson=$(<./tmp/.tmp_rics.json)
1560 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1561 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1562 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1563 if [ $res -ne 0 ]; then
1564 __log_test_fail_body
1569 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1570 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1574 query="/ric?managedElementId="$2
1576 res="$(__do_curl_to_api PA GET $query)"
1577 status=${res:${#res}-3}
1579 if [ $status -ne $1 ]; then
1580 __log_test_fail_status_code $1 $status
1584 if [ $# -eq 3 ]; then
1585 body=${res:0:${#res}-3}
1586 if [ "$body" != "$3" ]; then
1587 __log_test_fail_body
1596 # API test function: GET /rics and V2 GET /v2/rics
1597 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1598 # 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_........."
1599 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1600 # (Function for test scripts)
1604 if [ $# -lt 2 ]; then
1605 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1609 if [ "$PMS_VERSION" == "V2" ]; then
1611 if [ $2 != "NOTYPE" ]; then
1612 query="/v2/rics?policytype_id="$2
1616 if [ $2 != "NOTYPE" ]; then
1617 query="/rics?policyType="$2
1621 res="$(__do_curl_to_api PA GET $query)"
1622 status=${res:${#res}-3}
1624 if [ $status -ne $1 ]; then
1625 __log_test_fail_status_code $1 $status
1629 if [ $# -gt 2 ]; then
1630 body=${res:0:${#res}-3}
1631 if [ "$PMS_VERSION" == "V2" ]; then
1632 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1634 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1636 if [ $res -ne 0 ]; then
1637 __log_test_fail_general "Could not create target ric info json"
1641 targetJson=$(<./tmp/.tmp_rics.json)
1642 if [ "$PMS_VERSION" == "V2" ]; then
1643 targetJson="{\"rics\": $targetJson }"
1645 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1646 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1647 if [ $res -ne 0 ]; then
1648 __log_test_fail_body
1657 ##################################################################
1658 #### API Test case functions Service registry and supervision ####
1659 ##################################################################
1661 # API test function: PUT /service and V2 PUT /service
1662 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1663 # (Function for test scripts)
1666 if [ $# -ne 4 ]; then
1667 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1671 if [ "$PMS_VERSION" == "V2" ]; then
1672 query="/v2/services"
1673 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1676 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1678 file="./tmp/.tmp.json"
1679 echo "$json" > $file
1681 res="$(__do_curl_to_api PA PUT $query $file)"
1682 status=${res:${#res}-3}
1684 if [ $status -ne $1 ]; then
1685 __log_test_fail_status_code $1 $status
1693 # API test function: GET /services and V2 GET /v2/services
1694 #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>]* )]
1695 # (Function for test scripts)
1696 api_get_services() {
1698 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1700 if [ $# -eq 1 ]; then
1702 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1704 elif [ $# -eq 5 ]; then
1706 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1708 if [ $(($argLen%3)) -eq 0 ]; then
1713 if [ $paramError -ne 0 ]; then
1714 __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>]* )]" $@
1718 if [ "$PMS_VERSION" == "V2" ]; then
1719 query="/v2/services"
1721 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1722 query="/v2/services?service_id="$2
1727 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1728 query="/services?name="$2
1731 res="$(__do_curl_to_api PA GET $query)"
1732 status=${res:${#res}-3}
1734 if [ $status -ne $1 ]; then
1735 __log_test_fail_status_code $1 $status
1739 if [ $# -gt 2 ]; then
1740 variableArgCount=$(($#-2))
1741 body=${res:0:${#res}-3}
1745 while [ $cntr -lt $variableArgCount ]; do
1746 servicename=$1; shift;
1749 if [ $cntr -gt 0 ]; then
1750 targetJson=$targetJson","
1752 # timeSinceLastActivitySeconds value cannot be checked since value varies
1753 if [ "$PMS_VERSION" == "V2" ]; then
1754 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1756 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1760 targetJson=$targetJson"]"
1761 if [ "$PMS_VERSION" == "V2" ]; then
1762 targetJson="{\"service_list\": $targetJson }"
1764 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1765 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1766 if [ $res -ne 0 ]; then
1767 __log_test_fail_body
1776 # API test function: GET /services V2 GET /v2/services - (only checking service names)
1777 # args: <response-code> [<service-name>]*"
1778 # (Function for test scripts)
1779 api_get_service_ids() {
1782 if [ $# -lt 1 ]; then
1783 __print_err "<response-code> [<service-name>]*" $@
1787 if [ "$PMS_VERSION" == "V2" ]; then
1788 query="/v2/services"
1792 res="$(__do_curl_to_api PA GET $query)"
1793 status=${res:${#res}-3}
1795 if [ $status -ne $1 ]; then
1796 __log_test_fail_status_code $1 $status
1800 body=${res:0:${#res}-3}
1802 for rapp in ${@:2} ; do
1803 if [ "$targetJson" != "[" ]; then
1804 targetJson=$targetJson","
1806 if [ "$PMS_VERSION" == "V2" ]; then
1807 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
1809 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1813 targetJson=$targetJson"]"
1814 if [ "$PMS_VERSION" == "V2" ]; then
1815 targetJson="{\"service_list\": $targetJson }"
1817 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1818 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1820 if [ $res -ne 0 ]; then
1821 __log_test_fail_body
1829 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
1830 # args: <response-code> <service-name>
1831 # (Function for test scripts)
1832 api_delete_services() {
1835 if [ $# -ne 2 ]; then
1836 __print_err "<response-code> <service-name>" $@
1839 if [ "$PMS_VERSION" == "V2" ]; then
1840 query="/v2/services/"$2
1842 query="/services?name="$2
1844 res="$(__do_curl_to_api PA DELETE $query)"
1845 status=${res:${#res}-3}
1847 if [ $status -ne $1 ]; then
1848 __log_test_fail_status_code $1 $status
1856 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
1857 # args: <response-code> <service-name>
1858 # (Function for test scripts)
1859 api_put_services_keepalive() {
1862 if [ $# -ne 2 ]; then
1863 __print_err "<response-code> <service-name>" $@
1866 if [ "$PMS_VERSION" == "V2" ]; then
1867 query="/v2/services/$2/keepalive"
1869 query="/services/keepalive?name="$2
1872 res="$(__do_curl_to_api PA PUT $query)"
1873 status=${res:${#res}-3}
1875 if [ $status -ne $1 ]; then
1876 __log_test_fail_status_code $1 $status
1884 ##################################################################
1885 #### API Test case functions Configuration ####
1886 ##################################################################
1888 # API Test function: PUT /v2/configuration
1889 # args: <response-code> <config-file>
1890 # (Function for test scripts)
1891 api_put_configuration() {
1894 if [ "$PMS_VERSION" != "V2" ]; then
1895 __log_test_fail_not_supported
1899 if [ $# -ne 2 ]; then
1900 __print_err "<response-code> <config-file>" $@
1903 if [ ! -f $2 ]; then
1904 _log_test_fail_general "Config file "$2", does not exist"
1908 inputJson="{\"config\":"$inputJson"}"
1909 file="./tmp/.config.json"
1910 echo $inputJson > $file
1911 query="/v2/configuration"
1912 res="$(__do_curl_to_api PA PUT $query $file)"
1913 status=${res:${#res}-3}
1915 if [ $status -ne $1 ]; then
1916 __log_test_fail_status_code $1 $status
1924 # API Test function: GET /v2/configuration
1925 # args: <response-code> [<config-file>]
1926 # (Function for test scripts)
1927 api_get_configuration() {
1930 if [ "$PMS_VERSION" != "V2" ]; then
1931 __log_test_fail_not_supported
1935 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
1936 __print_err "<response-code> [<config-file>]" $@
1939 if [ ! -f $2 ]; then
1940 _log_test_fail_general "Config file "$2" for comparison, does not exist"
1944 query="/v2/configuration"
1945 res="$(__do_curl_to_api PA GET $query)"
1946 status=${res:${#res}-3}
1948 if [ $status -ne $1 ]; then
1949 __log_test_fail_status_code $1 $status
1953 if [ $# -eq 2 ]; then
1955 body=${res:0:${#res}-3}
1958 targetJson="{\"config\":"$targetJson"}"
1959 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1960 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1962 if [ $res -ne 0 ]; then
1963 __log_test_fail_body