3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020 Nordix Foundation. All rights reserved.
5 # ========================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=================================================
20 # This is a script that contains management and test functions for Policy Agent
22 ################ Test engine functions ################
24 # Create the image var used during the test
25 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
26 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
28 __check_and_create_image_var PA "POLICY_AGENT_IMAGE" "POLICY_AGENT_IMAGE_BASE" "POLICY_AGENT_IMAGE_TAG" $1 "$POLICY_AGENT_DISPLAY_NAME"
31 # Pull image from remote repo or use locally built image
32 # arg: <pull-policy-override> <pull-policy-original>
33 # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
34 # <pull-policy-original> Shall be used for images that does not allow overriding
35 # Both var may contain: 'remote', 'remote-remove' or 'local'
37 __check_and_pull_image $1 "$POLICY_AGENT_DISPLAY_NAME" $POLICY_AGENT_APP_NAME $POLICY_AGENT_IMAGE
40 # Build image (only for simulator or interfaces stubs owned by the test environment)
41 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
42 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
44 echo -e $RED" Image for app PA shall never be built"$ERED
47 # Generate a string for each included image using the app display name and a docker images format string
48 # arg: <docker-images-format-string> <file-to-append>
50 echo -e "$POLICY_AGENT_DISPLAY_NAME\t$(docker images --format $1 $POLICY_AGENT_IMAGE)" >> $2
53 # Scale kubernetes resources to zero
54 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
55 # This function is called for apps fully managed by the test script
56 __PA_kube_scale_zero() {
57 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
60 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
61 # This function is called for prestarted apps not managed by the test script.
62 __PA_kube_scale_zero_and_wait() {
63 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-policymanagementservice
66 # Delete all kube resouces for the app
67 # This function is called for apps managed by the test script.
68 __PA_kube_delete_all() {
69 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
73 # This function is called for apps managed by the test script.
74 # args: <log-dir> <file-prexix>
75 __PA_store_docker_logs() {
76 docker logs $POLICY_AGENT_APP_NAME > $1$2_policy-agent.log 2>&1
79 #######################################################
81 ## Access to Policy agent
82 # Host name may be changed if app started by kube
83 # Direct access from script
85 PA_HOST_NAME=$LOCALHOST_NAME
86 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
88 # PA_ADAPTER used for switch between REST and DMAAP
89 PA_ADAPTER_TYPE="REST"
92 # Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
95 ###########################
96 ### Policy Agents functions
97 ###########################
99 # All calls to the agent will be directed to the agent REST interface from now on
101 # (Function for test scripts)
102 use_agent_rest_http() {
103 echo -e $BOLD"Agent protocol setting"$EBOLD
104 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
106 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
108 PA_ADAPTER_TYPE="REST"
113 # All calls to the agent will be directed to the agent REST interface from now on
115 # (Function for test scripts)
116 use_agent_rest_https() {
117 echo -e $BOLD"Agent protocol setting"$EBOLD
118 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
120 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
122 PA_ADAPTER_TYPE="REST"
127 # All calls to the agent will be directed to the agent dmaap interface over http from now on
129 # (Function for test scripts)
130 use_agent_dmaap_http() {
131 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
132 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
133 PA_ADAPTER_TYPE="MR-HTTP"
137 # All calls to the agent will be directed to the agent dmaap interface over https from now on
139 # (Function for test scripts)
140 use_agent_dmaap_https() {
141 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
142 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
143 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
144 PA_ADAPTER_TYPE="MR-HTTPS"
148 # Start the policy agent
149 # args: (docker) PROXY|NOPROXY <config-file>
150 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
151 # (Function for test scripts)
152 start_policy_agent() {
153 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
155 if [ $RUNMODE == "KUBE" ]; then
157 # Check if app shall be fully managed by the test script
158 __check_included_image "PA"
161 # Check if app shall only be used by the testscipt
162 __check_prestarted_image "PA"
165 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
166 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
167 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
170 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
171 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
172 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
176 if [ $retcode_p -eq 0 ]; then
177 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
178 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
179 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
182 if [ $retcode_i -eq 0 ]; then
184 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
186 #Check if nonrtric namespace exists, if not create it
187 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
189 #Export all vars needed for service and deployment
190 export POLICY_AGENT_APP_NAME
191 export KUBE_NONRTRIC_NAMESPACE
192 export POLICY_AGENT_IMAGE
193 export POLICY_AGENT_INTERNAL_PORT
194 export POLICY_AGENT_INTERNAL_SECURE_PORT
195 export POLICY_AGENT_EXTERNAL_PORT
196 export POLICY_AGENT_EXTERNAL_SECURE_PORT
197 export POLICY_AGENT_CONFIG_MOUNT_PATH
198 export POLICY_AGENT_DATA_MOUNT_PATH
199 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
200 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
201 export POLICY_AGENT_PKG_NAME
202 if [ $1 == "PROXY" ]; then
203 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
204 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
205 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
206 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
208 echo " Configured with http proxy"
211 AGENT_HTTP_PROXY_CONFIG_PORT=0
212 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
213 echo " Configured without http proxy"
215 export AGENT_HTTP_PROXY_CONFIG_PORT
216 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
219 # Create config map for config
220 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
222 output_yaml=$PWD/tmp/pa_cfc.yaml
223 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
225 # Create config map for data
226 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
227 if [ $# -lt 3 ]; then
228 #create empty dummy file
229 echo "{}" > $data_json
233 output_yaml=$PWD/tmp/pa_cfd.yaml
234 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
237 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
238 output_yaml=$PWD/tmp/pa_svc.yaml
239 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
242 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
243 output_yaml=$PWD/tmp/pa_app.yaml
244 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
248 echo " Retrieving host and ports for service..."
249 PA_HOST_NAME=$(__kube_get_service_host $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
250 POLICY_AGENT_EXTERNAL_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
251 POLICY_AGENT_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
253 echo " Host IP, http port, https port: $PA_HOST_NAME $POLICY_AGENT_EXTERNAL_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT"
255 if [ $PA_HTTPX == "http" ]; then
256 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
258 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
260 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
262 if [ $PA_ADAPTER_TYPE == "REST" ]; then
266 __check_included_image 'PA'
267 if [ $? -eq 1 ]; then
268 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
269 echo -e $RED"The Policy Agent will not be started"$ERED
273 #Export all vars needed for docker-compose
274 export POLICY_AGENT_APP_NAME
275 export POLICY_AGENT_APP_NAME_ALIAS
276 export POLICY_AGENT_INTERNAL_PORT
277 export POLICY_AGENT_EXTERNAL_PORT
278 export POLICY_AGENT_INTERNAL_SECURE_PORT
279 export POLICY_AGENT_EXTERNAL_SECURE_PORT
281 export CONSUL_INTERNAL_PORT
282 export CONFIG_BINDING_SERVICE
283 export POLICY_AGENT_CONFIG_KEY
284 export DOCKER_SIM_NWNAME
285 export POLICY_AGENT_HOST_MNT_DIR
286 export POLICY_AGENT_CONFIG_MOUNT_PATH
287 export POLICY_AGENT_CONFIG_FILE
288 export POLICY_AGENT_PKG_NAME
289 export POLICY_AGENT_DISPLAY_NAME
291 if [ $1 == "PROXY" ]; then
292 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
293 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
294 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
295 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
297 echo " Configured with http proxy"
300 AGENT_HTTP_PROXY_CONFIG_PORT=0
301 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
302 echo " Configured without http proxy"
304 export AGENT_HTTP_PROXY_CONFIG_PORT
305 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
307 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
309 envsubst < $2 > $dest_file
311 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
313 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
319 # Load the the appl config for the agent into a config map
320 agent_load_config() {
321 echo -e $BOLD"Agent - load config from "$EBOLD$1
322 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
324 output_yaml=$PWD/tmp/pa_cfd.yaml
325 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
330 # Turn on debug level tracing in the agent
332 # (Function for test scripts)
334 echo -e $BOLD"Setting agent debug logging"$EBOLD
335 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
336 result=$(__do_curl "$curlString")
337 if [ $? -ne 0 ]; then
338 __print_err "could not set debug mode" $@
346 # Turn on trace level tracing in the agent
348 # (Function for test scripts)
350 echo -e $BOLD"Setting agent trace logging"$EBOLD
351 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
352 result=$(__do_curl "$curlString")
353 if [ $? -ne 0 ]; then
354 __print_err "could not set trace mode" $@
362 # Perform curl retries when making direct call to the agent for the specified http response codes
363 # Speace separated list of http response codes
364 # args: [<response-code>]*
365 use_agent_retries() {
366 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
372 # Check the agent logs for WARNINGs and ERRORs
374 # (Function for test scripts)
375 check_policy_agent_logs() {
376 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
379 #########################################################
380 #### Test case functions A1 Policy management service
381 #########################################################
383 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
384 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
385 # args: json:<url> <target-value> [<timeout-in-seconds]
386 # (Function for test scripts)
388 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
389 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
390 if [[ $1 == "json:"* ]]; then
391 if [ "$PMS_VERSION" == "V2" ]; then
392 __var_test "Policy Agent" $PA_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
394 __var_test "Policy Agent" $PA_PATH"/" $1 "=" $2 $3
399 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
403 # API Test function: GET /policies and V2 GET /v2/policy-instances
404 # 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>]*]
405 # 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>]*]
406 # (Function for test scripts)
410 if [ "$PMS_VERSION" == "V2" ]; then
412 variableParams=$(($#-4))
413 if [ $# -lt 4 ]; then
415 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
417 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
421 if [ $paramError -ne 0 ]; then
422 __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>]*]" $@
427 variableParams=$(($#-4))
428 if [ $# -lt 4 ]; then
430 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
432 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
436 if [ $paramError -ne 0 ]; then
437 __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>]*]" $@
443 if [ "$PMS_VERSION" == "V2" ]; then
444 if [ $2 != "NORIC" ]; then
445 queryparams="?ric_id="$2
447 if [ $3 != "NOSERVICE" ]; then
448 if [ -z $queryparams ]; then
449 queryparams="?service_id="$3
451 queryparams=$queryparams"&service_id="$3
454 if [ $4 != "NOTYPE" ]; then
455 if [ -z $queryparams ]; then
456 queryparams="?policytype_id="$4
458 queryparams=$queryparams"&policytype_id="$4
462 query="/v2/policy-instances"$queryparams
463 res="$(__do_curl_to_api PA GET $query)"
464 status=${res:${#res}-3}
466 if [ $status -ne $1 ]; then
467 __log_test_fail_status_code $1 $status
471 if [ $# -gt 4 ]; then
472 body=${res:0:${#res}-3}
473 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
479 for ((i=0; i<$(($#-4)); i=i+7)); do
481 if [ "$targetJson" != "[" ]; then
482 targetJson=$targetJson","
484 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
485 if [ "${arr[$i+3]}" == "EMPTY" ]; then
486 targetJson=$targetJson"\"\","
488 targetJson=$targetJson"\"${arr[$i+3]}\","
490 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
492 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
494 targetJson=$targetJson"\"policy_data\":"$json"}"
498 targetJson=$targetJson"]"
499 targetJson="{\"policies\": $targetJson}"
500 echo "TARGET JSON: $targetJson" >> $HTTPLOG
501 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
503 if [ $res -ne 0 ]; then
509 if [ $2 != "NORIC" ]; then
510 queryparams="?ric="$2
512 if [ $3 != "NOSERVICE" ]; then
513 if [ -z $queryparams ]; then
514 queryparams="?service="$3
516 queryparams=$queryparams"&service="$3
519 if [ $4 != "NOTYPE" ]; then
520 if [ -z $queryparams ]; then
521 queryparams="?type="$4
523 queryparams=$queryparams"&type="$4
527 query="/policies"$queryparams
528 res="$(__do_curl_to_api PA GET $query)"
529 status=${res:${#res}-3}
531 if [ $status -ne $1 ]; then
532 __log_test_fail_status_code $1 $status
536 if [ $# -gt 4 ]; then
537 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
540 body=${res:0:${#res}-3}
544 for ((i=0; i<$(($#-4)); i=i+5)); do
546 if [ "$targetJson" != "[" ]; then
547 targetJson=$targetJson","
549 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
550 if [ "${arr[$i+3]}" == "EMPTY" ]; then
551 targetJson=$targetJson"\"\","
553 targetJson=$targetJson"\"${arr[$i+3]}\","
556 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
558 targetJson=$targetJson"\"json\":"$json"}"
562 targetJson=$targetJson"]"
563 echo "TARGET JSON: $targetJson" >> $HTTPLOG
564 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
566 if [ $res -ne 0 ]; then
579 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
580 # args: <response-code> <policy-id> [<template-file>]
581 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
583 # (Function for test scripts)
588 if [ "$PMS_VERSION" == "V2" ]; then
589 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
590 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
593 query="/v2/policies/$UUID$2"
595 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
596 __print_err "<response-code> <policy-id> [<template-file>] " $@
599 query="/policy?id=$UUID$2"
601 res="$(__do_curl_to_api PA GET $query)"
602 status=${res:${#res}-3}
604 if [ $status -ne $1 ]; then
605 __log_test_fail_status_code $1 $status
609 if [ "$PMS_VERSION" == "V2" ]; then
610 if [ $# -eq 8 ]; then
612 #Create a policy json to compare with
613 body=${res:0:${#res}-3}
615 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
616 if [ $7 != "NOTRANSIENT" ]; then
617 targetJson=$targetJson", \"transient\":$7"
619 if [ $6 != "NOTYPE" ]; then
620 targetJson=$targetJson", \"policytype_id\":\"$6\""
622 targetJson=$targetJson", \"policytype_id\":\"\""
624 if [ $8 != "NOURL" ]; then
625 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
628 data=$(sed 's/XXX/'${2}'/g' $3)
629 targetJson=$targetJson", \"policy_data\":$data"
630 targetJson="{$targetJson}"
632 echo "TARGET JSON: $targetJson" >> $HTTPLOG
633 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
634 if [ $res -ne 0 ]; then
640 if [ $# -eq 3 ]; then
641 #Create a policy json to compare with
642 body=${res:0:${#res}-3}
644 sed 's/XXX/'${2}'/g' $3 > $file
645 targetJson=$(< $file)
646 echo "TARGET JSON: $targetJson" >> $HTTPLOG
647 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
648 if [ $res -ne 0 ]; then
658 # API Test function: PUT /policy and V2 PUT /policies
659 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
660 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
661 # (Function for test scripts)
665 if [ "$PMS_VERSION" == "V2" ]; then
666 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
667 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
671 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
672 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
685 if [ "$PMS_VERSION" == "V2" ]; then
688 if [ $# -eq 9 ]; then
693 if [ $# -eq 8 ]; then
698 while [ $count -lt $max ]; do
699 if [ "$PMS_VERSION" == "V2" ]; then
703 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
704 if [ $trans != "NOTRANSIENT" ]; then
705 inputJson=$inputJson", \"transient\":$trans"
707 if [ $pt != "NOTYPE" ]; then
708 inputJson=$inputJson", \"policytype_id\":\"$pt\""
710 inputJson=$inputJson", \"policytype_id\":\"\""
712 if [ $noti != "NOURL" ]; then
713 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
716 data=$(sed 's/XXX/'${pid}'/g' $temp)
717 inputJson=$inputJson", \"policy_data\":$data"
718 inputJson="{$inputJson}"
719 echo $inputJson > $file
721 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
723 if [ $pt != "NOTYPE" ]; then
724 query=$query"&type=$pt"
727 if [ $trans != NOTRANSIENT ]; then
728 query=$query"&transient=$trans"
732 sed 's/XXX/'${pid}'/g' $temp > $file
734 res="$(__do_curl_to_api PA PUT $query $file)"
735 status=${res:${#res}-3}
736 echo -ne " Executing "$count"("$max")${SAMELINE}"
737 if [ $status -ne $1 ]; then
738 echo " Executed "$count"?("$max")"
739 __log_test_fail_status_code $1 $status
745 echo -ne " Executed "$count"("$max")${SAMELINE}"
753 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
754 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
755 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
756 # (Function for test scripts)
758 api_put_policy_batch() {
761 if [ "$PMS_VERSION" == "V2" ]; then
762 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
763 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
767 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
768 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
780 if [ "$PMS_VERSION" == "V2" ]; then
783 if [ $# -eq 9 ]; then
788 if [ $# -eq 8 ]; then
794 while [ $count -lt $max ]; do
795 if [ "$PMS_VERSION" == "V2" ]; then
798 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
799 if [ $trans != "NOTRANSIENT" ]; then
800 inputJson=$inputJson", \"transient\":$trans"
802 if [ $pt != "NOTYPE" ]; then
803 inputJson=$inputJson", \"policytype_id\":\"$pt\""
805 inputJson=$inputJson", \"policytype_id\":\"\""
807 if [ $noti != "NOURL" ]; then
808 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
811 data=$(sed 's/XXX/'${pid}'/g' $temp)
812 inputJson=$inputJson", \"policy_data\":$data"
813 inputJson="{$inputJson}"
814 echo $inputJson > $file
816 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
818 if [ $pt != "NOTYPE" ]; then
819 query=$query"&type=$pt"
822 if [ $trans != NOTRANSIENT ]; then
823 query=$query"&transient=$trans"
826 sed 's/XXX/'${pid}'/g' $temp > $file
828 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
829 status=${res:${#res}-3}
830 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
832 if [ $status -ne 200 ]; then
833 echo " Requested(batch) "$count"?("$max")"
834 __log_test_fail_status_code 200 $status
837 cid=${res:0:${#res}-3}
841 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
848 res="$(__do_curl_to_api PA RESPONSE $cid)"
849 status=${res:${#res}-3}
850 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
852 if [ $status -ne $1 ]; then
853 echo " Accepted(batch) "$count"?("$max")"
854 __log_test_fail_status_code $1 $status
859 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
868 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
869 # 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>
870 # 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>
871 # (Function for test scripts)
872 api_put_policy_parallel() {
875 if [ "$PMS_VERSION" == "V2" ]; then
876 if [ $# -ne 11 ]; then
877 __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>" $@
881 if [ $# -ne 10 ]; then
882 __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>" $@
893 if [ "$PMS_VERSION" == "V2" ]; then
902 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
903 if [ $PA_ADAPTER_TYPE != "REST" ]; then
904 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
905 echo " Info - will execute over agent REST"
907 if [ "$PMS_VERSION" == "V2" ]; then
908 if [ $serv == "NOSERVICE" ]; then
911 query="$PMS_API_PREFIX/v2/policies"
913 if [ $serv == "NOSERVICE" ]; then
916 query="/policy?service=$serv"
918 if [ $type != "NOTYPE" ]; then
919 query=$query"&type=$type"
922 if [ $transient != NOTRANSIENT ]; then
923 query=$query"&transient=$transient"
927 urlbase=${PA_ADAPTER}${query}
930 if [ $RUNMODE == "KUBE" ]; then
931 if [ ! -z "$CLUSTER_KUBE_PROXY_NODEPORT" ]; then
932 httpproxy="http://localhost:$CLUSTER_KUBE_PROXY_NODEPORT"
936 for ((i=1; i<=$pids; i++))
939 if [ -z "$uuid" ]; then
942 echo "" > "./tmp/.pid${i}.res.txt"
943 if [ "$PMS_VERSION" == "V2" ]; then
944 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
946 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
949 done | xargs -n 1 -I{} -P $pids bash -c '{
951 echo " Parallel process $arg started"
952 tmp=$(< "./tmp/.pid${arg}.txt")
953 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
956 for ((i=1; i<=$pids; i++))
958 file="./tmp/.pid${i}.res.txt"
960 if [ -z "$tmp" ]; then
961 echo " Process $i : unknown result (result file empty"
965 if [ $res == "0" ]; then
966 echo " Process $i : OK - "${tmp:1}
968 echo " Process $i : failed - "${tmp:1}
974 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
978 __log_test_fail_general "One of more processes failed to execute"
982 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
983 # args: <response-code> <policy-id> [count]
984 # (Function for test scripts)
985 api_delete_policy() {
988 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
989 __print_err "<response-code> <policy-id> [count]" $@
996 if [ $# -eq 3 ]; then
1002 while [ $count -lt $max ]; do
1003 if [ "$PMS_VERSION" == "V2" ]; then
1004 query="/v2/policies/"$UUID$pid
1006 query="/policy?id="$UUID$pid
1008 res="$(__do_curl_to_api PA DELETE $query)"
1009 status=${res:${#res}-3}
1010 echo -ne " Executing "$count"("$max")${SAMELINE}"
1012 if [ $status -ne $1 ]; then
1013 echo " Executed "$count"?("$max")"
1014 __log_test_fail_status_code $1 $status
1019 echo -ne " Executed "$count"("$max")${SAMELINE}"
1027 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1028 # args: <response-code> <policy-id> [count]
1029 # (Function for test scripts)
1030 api_delete_policy_batch() {
1033 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1034 __print_err "<response-code> <policy-id> [count]" $@
1041 if [ $# -eq 3 ]; then
1047 while [ $count -lt $max ]; do
1048 if [ "$PMS_VERSION" == "V2" ]; then
1049 query="/v2/policies/"$UUID$pid
1051 query="/policy?id="$UUID$pid
1053 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
1054 status=${res:${#res}-3}
1055 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1057 if [ $status -ne 200 ]; then
1058 echo " Requested(batch) "$count"?("$max")"
1059 __log_test_fail_status_code 200 $status
1062 cid=${res:0:${#res}-3}
1066 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1074 res="$(__do_curl_to_api PA RESPONSE $cid)"
1075 status=${res:${#res}-3}
1076 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1078 if [ $status -ne $1 ]; then
1079 echo " Deleted(batch) "$count"?("$max")"
1080 __log_test_fail_status_code $1 $status
1085 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1094 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1095 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1096 # (Function for test scripts)
1097 api_delete_policy_parallel() {
1100 if [ $# -ne 5 ]; then
1101 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1104 resp_code=$1; shift;
1110 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1111 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1112 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1113 echo " Info - will execute over agent REST"
1116 if [ "$PMS_VERSION" == "V2" ]; then
1117 query="$PMS_API_PREFIX/v2/policies/"
1122 urlbase=${PA_ADAPTER}${query}
1125 if [ $RUNMODE == "KUBE" ]; then
1126 if [ ! -z "$CLUSTER_KUBE_PROXY_NODEPORT" ]; then
1127 httpproxy="http://localhost:$CLUSTER_KUBE_PROXY_NODEPORT"
1131 for ((i=1; i<=$pids; i++))
1134 if [ -z "$uuid" ]; then
1137 echo "" > "./tmp/.pid${i}.del.res.txt"
1138 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1140 done | xargs -n 1 -I{} -P $pids bash -c '{
1142 echo " Parallel process $arg started"
1143 tmp=$(< "./tmp/.pid${arg}.del.txt")
1144 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1147 for ((i=1; i<=$pids; i++))
1149 file="./tmp/.pid${i}.del.res.txt"
1151 if [ -z "$tmp" ]; then
1152 echo " Process $i : unknown result (result file empty"
1156 if [ $res == "0" ]; then
1157 echo " Process $i : OK - "${tmp:1}
1159 echo " Process $i : failed - "${tmp:1}
1164 if [ -z $msg ]; then
1165 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1169 __log_test_fail_general "One of more processes failed to execute"
1173 # API Test function: GET /policy_ids and V2 GET /v2/policies
1174 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1175 # (Function for test scripts)
1176 api_get_policy_ids() {
1179 if [ $# -lt 4 ]; then
1180 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1186 if [ "$PMS_VERSION" == "V2" ]; then
1187 if [ $2 != "NORIC" ]; then
1188 queryparams="?ric_id="$2
1191 if [ $3 != "NOSERVICE" ]; then
1192 if [ -z $queryparams ]; then
1193 queryparams="?service_id="$3
1195 queryparams=$queryparams"&service_id="$3
1198 if [ $4 != "NOTYPE" ]; then
1199 if [ -z $queryparams ]; then
1200 queryparams="?policytype_id="$4
1202 queryparams=$queryparams"&policytype_id="$4
1206 query="/v2/policies"$queryparams
1208 if [ $2 != "NORIC" ]; then
1209 queryparams="?ric="$2
1212 if [ $3 != "NOSERVICE" ]; then
1213 if [ -z $queryparams ]; then
1214 queryparams="?service="$3
1216 queryparams=$queryparams"&service="$3
1219 if [ $4 != "NOTYPE" ]; then
1220 if [ -z $queryparams ]; then
1221 queryparams="?type="$4
1223 queryparams=$queryparams"&type="$4
1227 query="/policy_ids"$queryparams
1230 res="$(__do_curl_to_api PA GET $query)"
1231 status=${res:${#res}-3}
1233 if [ $status -ne $1 ]; then
1234 __log_test_fail_status_code $1 $status
1238 if [ $# -gt 4 ]; then
1239 body=${res:0:${#res}-3}
1242 for pid in ${@:5} ; do
1243 if [ "$targetJson" != "[" ]; then
1244 targetJson=$targetJson","
1246 if [ $pid != "NOID" ]; then
1247 targetJson=$targetJson"\"$UUID$pid\""
1251 targetJson=$targetJson"]"
1252 if [ "$PMS_VERSION" == "V2" ]; then
1253 targetJson="{\"policy_ids\": $targetJson}"
1255 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1256 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1258 if [ $res -ne 0 ]; then
1259 __log_test_fail_body
1268 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1269 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1270 # (Function for test scripts)
1271 api_get_policy_type() {
1274 if [ "$PMS_VERSION" != "V2" ]; then
1275 __log_test_fail_not_supported
1279 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1280 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1283 query="/v2/policy-types/$2"
1285 res="$(__do_curl_to_api PA GET $query)"
1286 status=${res:${#res}-3}
1288 if [ $status -ne $1 ]; then
1289 __log_test_fail_status_code $1 $status
1293 if [ $# -eq 3 ]; then
1295 body=${res:0:${#res}-3}
1298 targetJson="{\"policy_schema\":$targetJson}"
1299 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1300 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1302 if [ $res -ne 0 ]; then
1303 __log_test_fail_body
1312 # API Test function: GET /policy_schema
1313 # args: <response-code> <policy-type-id> [<schema-file>]
1314 # (Function for test scripts)
1315 api_get_policy_schema() {
1318 if [ "$PMS_VERSION" == "V2" ]; then
1319 __log_test_fail_not_supported
1323 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1324 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1327 query="/policy_schema?id=$2"
1328 res="$(__do_curl_to_api PA GET $query)"
1329 status=${res:${#res}-3}
1331 if [ $status -ne $1 ]; then
1332 __log_test_fail_status_code $1 $status
1336 if [ $# -eq 3 ]; then
1338 body=${res:0:${#res}-3}
1342 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1343 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1345 if [ $res -ne 0 ]; then
1346 __log_test_fail_body
1355 # API Test function: GET /policy_schemas
1356 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1357 # args(V2): <response-code>
1358 # (Function for test scripts)
1359 api_get_policy_schemas() {
1362 if [ "$PMS_VERSION" == "V2" ]; then
1363 if [ $# -ne 1 ]; then
1364 __print_err "<response-code>" $@
1368 if [ $# -lt 2 ]; then
1369 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1373 if [ "$PMS_VERSION" == "V2" ]; then
1374 query="/v2/policy-schemas"
1376 query="/policy_schemas"
1377 if [ $2 != "NORIC" ]; then
1378 query=$query"?ric="$2
1382 res="$(__do_curl_to_api PA GET $query)"
1383 status=${res:${#res}-3}
1385 if [ $status -ne $1 ]; then
1386 __log_test_fail_status_code $1 $status
1390 if [ $# -gt 2 ]; then
1391 body=${res:0:${#res}-3}
1394 for file in ${@:3} ; do
1395 if [ "$targetJson" != "[" ]; then
1396 targetJson=$targetJson","
1398 if [ $file == "NOFILE" ]; then
1399 targetJson=$targetJson"{}"
1401 targetJson=$targetJson$(< $file)
1405 targetJson=$targetJson"]"
1406 if [ "$PMS_VERSION" == "V2" ]; then
1407 targetJson="{\"policy_schemas\": $targetJson }"
1409 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1410 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1412 if [ $res -ne 0 ]; then
1413 __log_test_fail_body
1422 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1423 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1424 # (Function for test scripts)
1425 api_get_policy_status() {
1428 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1429 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1435 if [ $3 == "STD" ]; then
1436 targetJson="{\"enforceStatus\":\"$4\""
1437 if [ $# -eq 5 ]; then
1438 targetJson=$targetJson",\"reason\":\"$5\""
1440 targetJson=$targetJson"}"
1441 elif [ $3 == "STD2" ]; then
1442 if [ $4 == "EMPTY" ]; then
1443 targetJson="{\"enforceStatus\":\"\""
1445 targetJson="{\"enforceStatus\":\"$4\""
1447 if [ $# -eq 5 ]; then
1448 if [ $5 == "EMPTY" ]; then
1449 targetJson=$targetJson",\"enforceReason\":\"\""
1451 targetJson=$targetJson",\"enforceReason\":\"$5\""
1454 targetJson=$targetJson"}"
1455 elif [ $3 == "OSC" ]; then
1456 targetJson="{\"instance_status\":\"$4\""
1457 if [ $# -eq 5 ]; then
1458 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1460 targetJson=$targetJson",\"created_at\":\"????\"}"
1462 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1466 if [ "$PMS_VERSION" == "V2" ]; then
1467 query="/v2/policies/$UUID$2/status"
1468 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1470 query="/policy_status?id="$UUID$2
1473 res="$(__do_curl_to_api PA GET $query)"
1474 status=${res:${#res}-3}
1476 if [ $status -ne $1 ]; then
1477 __log_test_fail_status_code $1 $status
1481 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1482 body=${res:0:${#res}-3}
1483 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1485 if [ $res -ne 0 ]; then
1486 __log_test_fail_body
1494 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1495 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1496 # (Function for test scripts)
1497 api_get_policy_types() {
1500 if [ $# -lt 1 ]; then
1501 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1505 if [ "$PMS_VERSION" == "V2" ]; then
1506 if [ $# -eq 1 ]; then
1507 query="/v2/policy-types"
1508 elif [ $2 == "NORIC" ]; then
1509 query="/v2/policy-types"
1511 query="/v2/policy-types?ric_id=$2"
1514 if [ $# -eq 1 ]; then
1515 query="/policy_types"
1516 elif [ $2 == "NORIC" ]; then
1517 query="/policy_types"
1519 query="/policy_types?ric=$2"
1523 res="$(__do_curl_to_api PA GET $query)"
1524 status=${res:${#res}-3}
1526 if [ $status -ne $1 ]; then
1527 __log_test_fail_status_code $1 $status
1531 if [ $# -gt 2 ]; then
1532 body=${res:0:${#res}-3}
1535 for pid in ${@:3} ; do
1536 if [ "$targetJson" != "[" ]; then
1537 targetJson=$targetJson","
1539 if [ $pid == "EMPTY" ]; then
1542 targetJson=$targetJson"\"$pid\""
1545 targetJson=$targetJson"]"
1546 if [ "$PMS_VERSION" == "V2" ]; then
1547 targetJson="{\"policytype_ids\": $targetJson }"
1549 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1550 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1552 if [ $res -ne 0 ]; then
1553 __log_test_fail_body
1562 #########################################################
1563 #### Test case functions Health check
1564 #########################################################
1566 # API Test function: GET /status and V2 GET /status
1567 # args: <response-code>
1568 # (Function for test scripts)
1571 if [ $# -ne 1 ]; then
1572 __print_err "<response-code>" $@
1575 if [ "$PMS_VERSION" == "V2" ]; then
1580 res="$(__do_curl_to_api PA GET $query)"
1581 status=${res:${#res}-3}
1583 if [ $status -ne $1 ]; then
1584 __log_test_fail_status_code $1 $status
1592 #########################################################
1593 #### Test case functions RIC Repository
1594 #########################################################
1596 # API Test function: GET /ric and V2 GET /v2/rics/ric
1597 # args: <reponse-code> <management-element-id> [<ric-id>]
1598 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1599 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1600 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1603 # (Function for test scripts)
1607 if [ "$PMS_VERSION" == "V2" ]; then
1608 if [ $# -lt 3 ]; then
1609 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1613 if [ $2 != "NOME" ]; then
1614 search="?managed_element_id="$2
1616 if [ $3 != "NORIC" ]; then
1617 if [ -z $search ]; then
1620 search=$search"&ric_id="$3
1623 query="/v2/rics/ric"$search
1625 res="$(__do_curl_to_api PA GET $query)"
1626 status=${res:${#res}-3}
1628 if [ $status -ne $1 ]; then
1629 __log_test_fail_status_code $1 $status
1633 if [ $# -gt 3 ]; then
1634 body=${res:0:${#res}-3}
1635 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
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 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1643 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1644 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1645 if [ $res -ne 0 ]; then
1646 __log_test_fail_body
1651 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1652 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1656 query="/ric?managedElementId="$2
1658 res="$(__do_curl_to_api PA GET $query)"
1659 status=${res:${#res}-3}
1661 if [ $status -ne $1 ]; then
1662 __log_test_fail_status_code $1 $status
1666 if [ $# -eq 3 ]; then
1667 body=${res:0:${#res}-3}
1668 if [ "$body" != "$3" ]; then
1669 __log_test_fail_body
1678 # API test function: GET /rics and V2 GET /v2/rics
1679 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1680 # 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_........."
1681 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1682 # (Function for test scripts)
1686 if [ $# -lt 2 ]; then
1687 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1691 if [ "$PMS_VERSION" == "V2" ]; then
1693 if [ $2 != "NOTYPE" ]; then
1694 query="/v2/rics?policytype_id="$2
1698 if [ $2 != "NOTYPE" ]; then
1699 query="/rics?policyType="$2
1703 res="$(__do_curl_to_api PA GET $query)"
1704 status=${res:${#res}-3}
1706 if [ $status -ne $1 ]; then
1707 __log_test_fail_status_code $1 $status
1711 if [ $# -gt 2 ]; then
1712 body=${res:0:${#res}-3}
1713 if [ "$PMS_VERSION" == "V2" ]; then
1714 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1716 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1718 if [ $res -ne 0 ]; then
1719 __log_test_fail_general "Could not create target ric info json"
1723 targetJson=$(<./tmp/.tmp_rics.json)
1724 if [ "$PMS_VERSION" == "V2" ]; then
1725 targetJson="{\"rics\": $targetJson }"
1727 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1728 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1729 if [ $res -ne 0 ]; then
1730 __log_test_fail_body
1739 ##################################################################
1740 #### API Test case functions Service registry and supervision ####
1741 ##################################################################
1743 # API test function: PUT /service and V2 PUT /service
1744 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1745 # (Function for test scripts)
1748 if [ $# -ne 4 ]; then
1749 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1753 if [ "$PMS_VERSION" == "V2" ]; then
1754 query="/v2/services"
1755 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1758 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1760 file="./tmp/.tmp.json"
1761 echo "$json" > $file
1763 res="$(__do_curl_to_api PA PUT $query $file)"
1764 status=${res:${#res}-3}
1766 if [ $status -ne $1 ]; then
1767 __log_test_fail_status_code $1 $status
1775 # API test function: GET /services and V2 GET /v2/services
1776 #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>]* )]
1777 # (Function for test scripts)
1778 api_get_services() {
1780 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1782 if [ $# -eq 1 ]; then
1784 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1786 elif [ $# -eq 5 ]; then
1788 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1790 if [ $(($argLen%3)) -eq 0 ]; then
1795 if [ $paramError -ne 0 ]; then
1796 __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>]* )]" $@
1800 if [ "$PMS_VERSION" == "V2" ]; then
1801 query="/v2/services"
1803 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1804 query="/v2/services?service_id="$2
1809 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1810 query="/services?name="$2
1813 res="$(__do_curl_to_api PA GET $query)"
1814 status=${res:${#res}-3}
1816 if [ $status -ne $1 ]; then
1817 __log_test_fail_status_code $1 $status
1821 if [ $# -gt 2 ]; then
1822 variableArgCount=$(($#-2))
1823 body=${res:0:${#res}-3}
1827 while [ $cntr -lt $variableArgCount ]; do
1828 servicename=$1; shift;
1831 if [ $cntr -gt 0 ]; then
1832 targetJson=$targetJson","
1834 # timeSinceLastActivitySeconds value cannot be checked since value varies
1835 if [ "$PMS_VERSION" == "V2" ]; then
1836 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1838 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1842 targetJson=$targetJson"]"
1843 if [ "$PMS_VERSION" == "V2" ]; then
1844 targetJson="{\"service_list\": $targetJson }"
1846 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1847 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1848 if [ $res -ne 0 ]; then
1849 __log_test_fail_body
1858 # API test function: GET /services V2 GET /v2/services - (only checking service names)
1859 # args: <response-code> [<service-name>]*"
1860 # (Function for test scripts)
1861 api_get_service_ids() {
1864 if [ $# -lt 1 ]; then
1865 __print_err "<response-code> [<service-name>]*" $@
1869 if [ "$PMS_VERSION" == "V2" ]; then
1870 query="/v2/services"
1874 res="$(__do_curl_to_api PA GET $query)"
1875 status=${res:${#res}-3}
1877 if [ $status -ne $1 ]; then
1878 __log_test_fail_status_code $1 $status
1882 body=${res:0:${#res}-3}
1884 for rapp in ${@:2} ; do
1885 if [ "$targetJson" != "[" ]; then
1886 targetJson=$targetJson","
1888 if [ "$PMS_VERSION" == "V2" ]; then
1889 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
1891 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1895 targetJson=$targetJson"]"
1896 if [ "$PMS_VERSION" == "V2" ]; then
1897 targetJson="{\"service_list\": $targetJson }"
1899 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1900 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1902 if [ $res -ne 0 ]; then
1903 __log_test_fail_body
1911 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
1912 # args: <response-code> <service-name>
1913 # (Function for test scripts)
1914 api_delete_services() {
1917 if [ $# -ne 2 ]; then
1918 __print_err "<response-code> <service-name>" $@
1921 if [ "$PMS_VERSION" == "V2" ]; then
1922 query="/v2/services/"$2
1924 query="/services?name="$2
1926 res="$(__do_curl_to_api PA DELETE $query)"
1927 status=${res:${#res}-3}
1929 if [ $status -ne $1 ]; then
1930 __log_test_fail_status_code $1 $status
1938 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
1939 # args: <response-code> <service-name>
1940 # (Function for test scripts)
1941 api_put_services_keepalive() {
1944 if [ $# -ne 2 ]; then
1945 __print_err "<response-code> <service-name>" $@
1948 if [ "$PMS_VERSION" == "V2" ]; then
1949 query="/v2/services/$2/keepalive"
1951 query="/services/keepalive?name="$2
1954 res="$(__do_curl_to_api PA PUT $query)"
1955 status=${res:${#res}-3}
1957 if [ $status -ne $1 ]; then
1958 __log_test_fail_status_code $1 $status
1966 ##################################################################
1967 #### API Test case functions Configuration ####
1968 ##################################################################
1970 # API Test function: PUT /v2/configuration
1971 # args: <response-code> <config-file>
1972 # (Function for test scripts)
1973 api_put_configuration() {
1976 if [ "$PMS_VERSION" != "V2" ]; then
1977 __log_test_fail_not_supported
1981 if [ $# -ne 2 ]; then
1982 __print_err "<response-code> <config-file>" $@
1985 if [ ! -f $2 ]; then
1986 _log_test_fail_general "Config file "$2", does not exist"
1990 inputJson="{\"config\":"$inputJson"}"
1991 file="./tmp/.config.json"
1992 echo $inputJson > $file
1993 query="/v2/configuration"
1994 res="$(__do_curl_to_api PA PUT $query $file)"
1995 status=${res:${#res}-3}
1997 if [ $status -ne $1 ]; then
1998 __log_test_fail_status_code $1 $status
2006 # API Test function: GET /v2/configuration
2007 # args: <response-code> [<config-file>]
2008 # (Function for test scripts)
2009 api_get_configuration() {
2012 if [ "$PMS_VERSION" != "V2" ]; then
2013 __log_test_fail_not_supported
2017 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2018 __print_err "<response-code> [<config-file>]" $@
2021 if [ ! -f $2 ]; then
2022 _log_test_fail_general "Config file "$2" for comparison, does not exist"
2026 query="/v2/configuration"
2027 res="$(__do_curl_to_api PA GET $query)"
2028 status=${res:${#res}-3}
2030 if [ $status -ne $1 ]; then
2031 __log_test_fail_status_code $1 $status
2035 if [ $# -eq 2 ]; then
2037 body=${res:0:${#res}-3}
2040 targetJson="{\"config\":"$targetJson"}"
2041 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2042 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2044 if [ $res -ne 0 ]; then
2045 __log_test_fail_body