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 specific test functions for Policy Agent API
22 ### API functiond towards the Policy Agent
24 . ../common/api_curl.sh
26 #########################################################
27 #### Test case functions A1 Policy management service
28 #########################################################
30 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
31 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
32 # args: json:<url> <target-value> [<timeout-in-seconds]
33 # (Function for test scripts)
35 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
36 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
37 if [[ $1 == "json:"* ]]; then
38 if [ "$PMS_VERSION" == "V2" ]; then
39 __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/v2/" $1 "=" $2 $3
41 __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/" $1 "=" $2 $3
46 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
50 # API Test function: GET /policies and V2 GET /v2/policy-instances
51 # 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>]*]
52 # 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>]*]
53 # (Function for test scripts)
57 if [ "$PMS_VERSION" == "V2" ]; then
59 variableParams=$(($#-4))
62 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
64 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
68 if [ $paramError -ne 0 ]; then
69 __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>]*]" $@
74 variableParams=$(($#-4))
77 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
79 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
83 if [ $paramError -ne 0 ]; then
84 __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>]*]" $@
90 if [ "$PMS_VERSION" == "V2" ]; then
91 if [ $2 != "NORIC" ]; then
92 queryparams="?ric_id="$2
94 if [ $3 != "NOSERVICE" ]; then
95 if [ -z $queryparams ]; then
96 queryparams="?service_id="$3
98 queryparams=$queryparams"&service_id="$3
101 if [ $4 != "NOTYPE" ]; then
102 if [ -z $queryparams ]; then
103 queryparams="?policytype_id="$4
105 queryparams=$queryparams"&policytype_id="$4
109 query="/v2/policy-instances"$queryparams
110 res="$(__do_curl_to_api PA GET $query)"
111 status=${res:${#res}-3}
113 if [ $status -ne $1 ]; then
114 __log_test_fail_status_code $1 $status
118 if [ $# -gt 4 ]; then
119 body=${res:0:${#res}-3}
120 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
126 for ((i=0; i<$(($#-4)); i=i+7)); do
128 if [ "$targetJson" != "[" ]; then
129 targetJson=$targetJson","
131 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
132 if [ "${arr[$i+3]}" == "EMPTY" ]; then
133 targetJson=$targetJson"\"\","
135 targetJson=$targetJson"\"${arr[$i+3]}\","
137 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
139 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
141 targetJson=$targetJson"\"policy_data\":"$json"}"
145 targetJson=$targetJson"]"
146 targetJson="{\"policies\": $targetJson}"
147 echo "TARGET JSON: $targetJson" >> $HTTPLOG
148 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
150 if [ $res -ne 0 ]; then
156 if [ $2 != "NORIC" ]; then
157 queryparams="?ric="$2
159 if [ $3 != "NOSERVICE" ]; then
160 if [ -z $queryparams ]; then
161 queryparams="?service="$3
163 queryparams=$queryparams"&service="$3
166 if [ $4 != "NOTYPE" ]; then
167 if [ -z $queryparams ]; then
168 queryparams="?type="$4
170 queryparams=$queryparams"&type="$4
174 query="/policies"$queryparams
175 res="$(__do_curl_to_api PA GET $query)"
176 status=${res:${#res}-3}
178 if [ $status -ne $1 ]; then
179 __log_test_fail_status_code $1 $status
183 if [ $# -gt 4 ]; then
184 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
187 body=${res:0:${#res}-3}
191 for ((i=0; i<$(($#-4)); i=i+5)); do
193 if [ "$targetJson" != "[" ]; then
194 targetJson=$targetJson","
196 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
197 if [ "${arr[$i+3]}" == "EMPTY" ]; then
198 targetJson=$targetJson"\"\","
200 targetJson=$targetJson"\"${arr[$i+3]}\","
203 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
205 targetJson=$targetJson"\"json\":"$json"}"
209 targetJson=$targetJson"]"
210 echo "TARGET JSON: $targetJson" >> $HTTPLOG
211 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
213 if [ $res -ne 0 ]; then
226 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
227 # args: <response-code> <policy-id> [<template-file>]
228 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
230 # (Function for test scripts)
235 if [ "$PMS_VERSION" == "V2" ]; then
236 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
237 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
240 query="/v2/policies/$UUID$2"
242 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
243 __print_err "<response-code> <policy-id> [<template-file>] " $@
246 query="/policy?id=$UUID$2"
248 res="$(__do_curl_to_api PA GET $query)"
249 status=${res:${#res}-3}
251 if [ $status -ne $1 ]; then
252 __log_test_fail_status_code $1 $status
256 if [ "$PMS_VERSION" == "V2" ]; then
257 if [ $# -eq 8 ]; then
259 #Create a policy json to compare with
260 body=${res:0:${#res}-3}
262 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
263 if [ $7 != "NOTRANSIENT" ]; then
264 targetJson=$targetJson", \"transient\":$7"
266 if [ $6 != "NOTYPE" ]; then
267 targetJson=$targetJson", \"policytype_id\":\"$6\""
269 targetJson=$targetJson", \"policytype_id\":\"\""
271 if [ $8 != "NOURL" ]; then
272 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
275 data=$(sed 's/XXX/'${2}'/g' $3)
276 targetJson=$targetJson", \"policy_data\":$data"
277 targetJson="{$targetJson}"
279 echo "TARGET JSON: $targetJson" >> $HTTPLOG
280 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
281 if [ $res -ne 0 ]; then
287 if [ $# -eq 3 ]; then
288 #Create a policy json to compare with
289 body=${res:0:${#res}-3}
291 sed 's/XXX/'${2}'/g' $3 > $file
292 targetJson=$(< $file)
293 echo "TARGET JSON: $targetJson" >> $HTTPLOG
294 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
295 if [ $res -ne 0 ]; then
305 # API Test function: PUT /policy and V2 PUT /policies
306 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
307 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
308 # (Function for test scripts)
312 if [ "$PMS_VERSION" == "V2" ]; then
313 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
314 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
318 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
319 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
332 if [ "$PMS_VERSION" == "V2" ]; then
335 if [ $# -eq 9 ]; then
340 if [ $# -eq 8 ]; then
345 while [ $count -lt $max ]; do
346 if [ "$PMS_VERSION" == "V2" ]; then
350 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
351 if [ $trans != "NOTRANSIENT" ]; then
352 inputJson=$inputJson", \"transient\":$trans"
354 if [ $pt != "NOTYPE" ]; then
355 inputJson=$inputJson", \"policytype_id\":\"$pt\""
357 inputJson=$inputJson", \"policytype_id\":\"\""
359 if [ $noti != "NOURL" ]; then
360 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
363 data=$(sed 's/XXX/'${pid}'/g' $temp)
364 inputJson=$inputJson", \"policy_data\":$data"
365 inputJson="{$inputJson}"
366 echo $inputJson > $file
368 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
370 if [ $pt != "NOTYPE" ]; then
371 query=$query"&type=$pt"
374 if [ $trans != NOTRANSIENT ]; then
375 query=$query"&transient=$trans"
379 sed 's/XXX/'${pid}'/g' $temp > $file
381 res="$(__do_curl_to_api PA PUT $query $file)"
382 status=${res:${#res}-3}
383 echo -ne " Executing "$count"("$max")${SAMELINE}"
384 if [ $status -ne $1 ]; then
385 echo " Executed "$count"?("$max")"
386 __log_test_fail_status_code $1 $status
392 echo -ne " Executed "$count"("$max")${SAMELINE}"
400 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
401 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
402 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
403 # (Function for test scripts)
405 api_put_policy_batch() {
408 if [ "$PMS_VERSION" == "V2" ]; then
409 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
410 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
414 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
415 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
427 if [ "$PMS_VERSION" == "V2" ]; then
430 if [ $# -eq 9 ]; then
435 if [ $# -eq 8 ]; then
441 while [ $count -lt $max ]; do
442 if [ "$PMS_VERSION" == "V2" ]; then
445 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
446 if [ $trans != "NOTRANSIENT" ]; then
447 inputJson=$inputJson", \"transient\":$trans"
449 if [ $pt != "NOTYPE" ]; then
450 inputJson=$inputJson", \"policytype_id\":\"$pt\""
452 inputJson=$inputJson", \"policytype_id\":\"\""
454 if [ $noti != "NOURL" ]; then
455 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
458 data=$(sed 's/XXX/'${pid}'/g' $temp)
459 inputJson=$inputJson", \"policy_data\":$data"
460 inputJson="{$inputJson}"
461 echo $inputJson > $file
463 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
465 if [ $pt != "NOTYPE" ]; then
466 query=$query"&type=$pt"
469 if [ $trans != NOTRANSIENT ]; then
470 query=$query"&transient=$trans"
473 sed 's/XXX/'${pid}'/g' $temp > $file
475 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
476 status=${res:${#res}-3}
477 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
479 if [ $status -ne 200 ]; then
480 echo " Requested(batch) "$count"?("$max")"
481 __log_test_fail_status_code 200 $status
484 cid=${res:0:${#res}-3}
488 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
495 res="$(__do_curl_to_api PA RESPONSE $cid)"
496 status=${res:${#res}-3}
497 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
499 if [ $status -ne $1 ]; then
500 echo " Accepted(batch) "$count"?("$max")"
501 __log_test_fail_status_code $1 $status
506 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
515 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
516 # 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>
517 # 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>
518 # (Function for test scripts)
519 api_put_policy_parallel() {
522 if [ "$PMS_VERSION" == "V2" ]; then
523 if [ $# -ne 11 ]; then
524 __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>" $@
528 if [ $# -ne 10 ]; then
529 __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>" $@
540 if [ "$PMS_VERSION" == "V2" ]; then
549 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
550 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
551 echo " Info - will execute over agent REST"
553 if [ "$PMS_VERSION" == "V2" ]; then
554 if [ $serv == "NOSERVICE" ]; then
559 if [ $serv == "NOSERVICE" ]; then
562 query="/policy?service=$serv"
564 if [ $type != "NOTYPE" ]; then
565 query=$query"&type=$type"
568 if [ $transient != NOTRANSIENT ]; then
569 query=$query"&transient=$transient"
573 urlbase=${ADAPTER}${query}
575 for ((i=1; i<=$pids; i++))
578 if [ -z "$uuid" ]; then
581 echo "" > "./tmp/.pid${i}.res.txt"
582 if [ "$PMS_VERSION" == "V2" ]; then
583 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i > "./tmp/.pid${i}.txt"
585 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt"
588 done | xargs -n 1 -I{} -P $pids bash -c '{
590 echo " Parallel process $arg started"
591 tmp=$(< "./tmp/.pid${arg}.txt")
592 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
595 for ((i=1; i<=$pids; i++))
597 file="./tmp/.pid${i}.res.txt"
599 if [ -z "$tmp" ]; then
600 echo " Process $i : unknown result (result file empty"
604 if [ $res == "0" ]; then
605 echo " Process $i : OK - "${tmp:1}
607 echo " Process $i : failed - "${tmp:1}
613 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
617 __log_test_fail_general "One of more processes failed to execute"
621 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
622 # args: <response-code> <policy-id> [count]
623 # (Function for test scripts)
624 api_delete_policy() {
627 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
628 __print_err "<response-code> <policy-id> [count]" $@
635 if [ $# -eq 3 ]; then
641 while [ $count -lt $max ]; do
642 if [ "$PMS_VERSION" == "V2" ]; then
643 query="/v2/policies/"$UUID$pid
645 query="/policy?id="$UUID$pid
647 res="$(__do_curl_to_api PA DELETE $query)"
648 status=${res:${#res}-3}
649 echo -ne " Executing "$count"("$max")${SAMELINE}"
651 if [ $status -ne $1 ]; then
652 echo " Executed "$count"?("$max")"
653 __log_test_fail_status_code $1 $status
658 echo -ne " Executed "$count"("$max")${SAMELINE}"
666 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
667 # args: <response-code> <policy-id> [count]
668 # (Function for test scripts)
669 api_delete_policy_batch() {
672 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
673 __print_err "<response-code> <policy-id> [count]" $@
680 if [ $# -eq 3 ]; then
686 while [ $count -lt $max ]; do
687 if [ "$PMS_VERSION" == "V2" ]; then
688 query="/v2/policies/"$UUID$pid
690 query="/policy?id="$UUID$pid
692 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
693 status=${res:${#res}-3}
694 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
696 if [ $status -ne 200 ]; then
697 echo " Requested(batch) "$count"?("$max")"
698 __log_test_fail_status_code 200 $status
701 cid=${res:0:${#res}-3}
705 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
713 res="$(__do_curl_to_api PA RESPONSE $cid)"
714 status=${res:${#res}-3}
715 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
717 if [ $status -ne $1 ]; then
718 echo " Deleted(batch) "$count"?("$max")"
719 __log_test_fail_status_code $1 $status
724 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
733 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
734 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
735 # (Function for test scripts)
736 api_delete_policy_parallel() {
739 if [ $# -ne 5 ]; then
740 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
749 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
750 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
751 echo " Info - will execute over agent REST"
754 if [ "$PMS_VERSION" == "V2" ]; then
755 query="/v2/policies/"
760 urlbase=${ADAPTER}${query}
762 for ((i=1; i<=$pids; i++))
765 if [ -z "$uuid" ]; then
768 echo "" > "./tmp/.pid${i}.del.res.txt"
769 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > "./tmp/.pid${i}.del.txt"
771 done | xargs -n 1 -I{} -P $pids bash -c '{
773 echo " Parallel process $arg started"
774 tmp=$(< "./tmp/.pid${arg}.del.txt")
775 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
778 for ((i=1; i<=$pids; i++))
780 file="./tmp/.pid${i}.del.res.txt"
782 if [ -z "$tmp" ]; then
783 echo " Process $i : unknown result (result file empty"
787 if [ $res == "0" ]; then
788 echo " Process $i : OK - "${tmp:1}
790 echo " Process $i : failed - "${tmp:1}
796 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
800 __log_test_fail_general "One of more processes failed to execute"
804 # API Test function: GET /policy_ids and V2 GET /v2/policies
805 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
806 # (Function for test scripts)
807 api_get_policy_ids() {
810 if [ $# -lt 4 ]; then
811 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
817 if [ "$PMS_VERSION" == "V2" ]; then
818 if [ $2 != "NORIC" ]; then
819 queryparams="?ric_id="$2
822 if [ $3 != "NOSERVICE" ]; then
823 if [ -z $queryparams ]; then
824 queryparams="?service_id="$3
826 queryparams=$queryparams"&service_id="$3
829 if [ $4 != "NOTYPE" ]; then
830 if [ -z $queryparams ]; then
831 queryparams="?policytype_id="$4
833 queryparams=$queryparams"&policytype_id="$4
837 query="/v2/policies"$queryparams
839 if [ $2 != "NORIC" ]; then
840 queryparams="?ric="$2
843 if [ $3 != "NOSERVICE" ]; then
844 if [ -z $queryparams ]; then
845 queryparams="?service="$3
847 queryparams=$queryparams"&service="$3
850 if [ $4 != "NOTYPE" ]; then
851 if [ -z $queryparams ]; then
852 queryparams="?type="$4
854 queryparams=$queryparams"&type="$4
858 query="/policy_ids"$queryparams
861 res="$(__do_curl_to_api PA GET $query)"
862 status=${res:${#res}-3}
864 if [ $status -ne $1 ]; then
865 __log_test_fail_status_code $1 $status
869 if [ $# -gt 4 ]; then
870 body=${res:0:${#res}-3}
873 for pid in ${@:5} ; do
874 if [ "$targetJson" != "[" ]; then
875 targetJson=$targetJson","
877 if [ $pid != "NOID" ]; then
878 targetJson=$targetJson"\"$UUID$pid\""
882 targetJson=$targetJson"]"
883 if [ "$PMS_VERSION" == "V2" ]; then
884 targetJson="{\"policy_ids\": $targetJson}"
886 echo "TARGET JSON: $targetJson" >> $HTTPLOG
887 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
889 if [ $res -ne 0 ]; then
899 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
900 # args(V2): <response-code> <policy-type-id> [<schema-file>]
901 # (Function for test scripts)
902 api_get_policy_type() {
905 if [ "$PMS_VERSION" != "V2" ]; then
906 __log_test_fail_not_supported
910 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
911 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
914 query="/v2/policy-types/$2"
916 res="$(__do_curl_to_api PA GET $query)"
917 status=${res:${#res}-3}
919 if [ $status -ne $1 ]; then
920 __log_test_fail_status_code $1 $status
924 if [ $# -eq 3 ]; then
926 body=${res:0:${#res}-3}
929 targetJson="{\"policy_schema\":$targetJson}"
930 echo "TARGET JSON: $targetJson" >> $HTTPLOG
931 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
933 if [ $res -ne 0 ]; then
943 # API Test function: GET /policy_schema
944 # args: <response-code> <policy-type-id> [<schema-file>]
945 # (Function for test scripts)
946 api_get_policy_schema() {
949 if [ "$PMS_VERSION" == "V2" ]; then
950 __log_test_fail_not_supported
954 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
955 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
958 query="/policy_schema?id=$2"
959 res="$(__do_curl_to_api PA GET $query)"
960 status=${res:${#res}-3}
962 if [ $status -ne $1 ]; then
963 __log_test_fail_status_code $1 $status
967 if [ $# -eq 3 ]; then
969 body=${res:0:${#res}-3}
973 echo "TARGET JSON: $targetJson" >> $HTTPLOG
974 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
976 if [ $res -ne 0 ]; then
986 # API Test function: GET /policy_schemas
987 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
988 # args(V2): <response-code>
989 # (Function for test scripts)
990 api_get_policy_schemas() {
993 if [ "$PMS_VERSION" == "V2" ]; then
994 if [ $# -ne 1 ]; then
995 __print_err "<response-code>" $@
999 if [ $# -lt 2 ]; then
1000 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1004 if [ "$PMS_VERSION" == "V2" ]; then
1005 query="/v2/policy-schemas"
1007 query="/policy_schemas"
1008 if [ $2 != "NORIC" ]; then
1009 query=$query"?ric="$2
1013 res="$(__do_curl_to_api PA GET $query)"
1014 status=${res:${#res}-3}
1016 if [ $status -ne $1 ]; then
1017 __log_test_fail_status_code $1 $status
1021 if [ $# -gt 2 ]; then
1022 body=${res:0:${#res}-3}
1025 for file in ${@:3} ; do
1026 if [ "$targetJson" != "[" ]; then
1027 targetJson=$targetJson","
1029 if [ $file == "NOFILE" ]; then
1030 targetJson=$targetJson"{}"
1032 targetJson=$targetJson$(< $file)
1036 targetJson=$targetJson"]"
1037 if [ "$PMS_VERSION" == "V2" ]; then
1038 targetJson="{\"policy_schemas\": $targetJson }"
1040 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1041 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1043 if [ $res -ne 0 ]; then
1044 __log_test_fail_body
1053 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1054 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1055 # (Function for test scripts)
1056 api_get_policy_status() {
1059 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1060 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1066 if [ $3 == "STD" ]; then
1067 targetJson="{\"enforceStatus\":\"$4\""
1068 if [ $# -eq 5 ]; then
1069 targetJson=$targetJson",\"reason\":\"$5\""
1071 targetJson=$targetJson"}"
1072 elif [ $3 == "STD2" ]; then
1073 if [ $4 == "EMPTY" ]; then
1074 targetJson="{\"enforceStatus\":\"\""
1076 targetJson="{\"enforceStatus\":\"$4\""
1078 if [ $# -eq 5 ]; then
1079 if [ $5 == "EMPTY" ]; then
1080 targetJson=$targetJson",\"enforceReason\":\"\""
1082 targetJson=$targetJson",\"enforceReason\":\"$5\""
1085 targetJson=$targetJson"}"
1086 elif [ $3 == "OSC" ]; then
1087 targetJson="{\"instance_status\":\"$4\""
1088 if [ $# -eq 5 ]; then
1089 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1091 targetJson=$targetJson",\"created_at\":\"????\"}"
1093 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1097 if [ "$PMS_VERSION" == "V2" ]; then
1098 query="/v2/policies/$UUID$2/status"
1099 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1101 query="/policy_status?id="$UUID$2
1104 res="$(__do_curl_to_api PA GET $query)"
1105 status=${res:${#res}-3}
1107 if [ $status -ne $1 ]; then
1108 __log_test_fail_status_code $1 $status
1112 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1113 body=${res:0:${#res}-3}
1114 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1116 if [ $res -ne 0 ]; then
1117 __log_test_fail_body
1125 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1126 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1127 # (Function for test scripts)
1128 api_get_policy_types() {
1131 if [ $# -lt 1 ]; then
1132 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1136 if [ "$PMS_VERSION" == "V2" ]; then
1137 if [ $# -eq 1 ]; then
1138 query="/v2/policy-types"
1139 elif [ $2 == "NORIC" ]; then
1140 query="/v2/policy-types"
1142 query="/v2/policy-types?ric_id=$2"
1145 if [ $# -eq 1 ]; then
1146 query="/policy_types"
1147 elif [ $2 == "NORIC" ]; then
1148 query="/policy_types"
1150 query="/policy_types?ric=$2"
1154 res="$(__do_curl_to_api PA GET $query)"
1155 status=${res:${#res}-3}
1157 if [ $status -ne $1 ]; then
1158 __log_test_fail_status_code $1 $status
1162 if [ $# -gt 2 ]; then
1163 body=${res:0:${#res}-3}
1166 for pid in ${@:3} ; do
1167 if [ "$targetJson" != "[" ]; then
1168 targetJson=$targetJson","
1170 if [ $pid == "EMPTY" ]; then
1173 targetJson=$targetJson"\"$pid\""
1176 targetJson=$targetJson"]"
1177 if [ "$PMS_VERSION" == "V2" ]; then
1178 targetJson="{\"policytype_ids\": $targetJson }"
1180 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1181 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1183 if [ $res -ne 0 ]; then
1184 __log_test_fail_body
1193 #########################################################
1194 #### Test case functions Health check
1195 #########################################################
1197 # API Test function: GET /status and V2 GET /status
1198 # args: <response-code>
1199 # (Function for test scripts)
1202 if [ $# -ne 1 ]; then
1203 __print_err "<response-code>" $@
1206 if [ "$PMS_VERSION" == "V2" ]; then
1211 res="$(__do_curl_to_api PA GET $query)"
1212 status=${res:${#res}-3}
1214 if [ $status -ne $1 ]; then
1215 __log_test_fail_status_code $1 $status
1223 #########################################################
1224 #### Test case functions RIC Repository
1225 #########################################################
1227 # API Test function: GET /ric and V2 GET /v2/rics/ric
1228 # args: <reponse-code> <management-element-id> [<ric-id>]
1229 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1230 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1231 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1234 # (Function for test scripts)
1238 if [ "$PMS_VERSION" == "V2" ]; then
1239 if [ $# -lt 3 ]; then
1240 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1244 if [ $2 != "NOME" ]; then
1245 search="?managed_element_id="$2
1247 if [ $3 != "NORIC" ]; then
1248 if [ -z $search ]; then
1251 search=$search"&ric_id="$3
1254 query="/v2/rics/ric"$search
1256 res="$(__do_curl_to_api PA GET $query)"
1257 status=${res:${#res}-3}
1259 if [ $status -ne $1 ]; then
1260 __log_test_fail_status_code $1 $status
1264 if [ $# -gt 3 ]; then
1265 body=${res:0:${#res}-3}
1266 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1267 if [ $res -ne 0 ]; then
1268 __log_test_fail_general "Could not create target ric info json"
1272 targetJson=$(<./tmp/.tmp_rics.json)
1273 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1274 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1275 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1276 if [ $res -ne 0 ]; then
1277 __log_test_fail_body
1282 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1283 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1287 query="/ric?managedElementId="$2
1289 res="$(__do_curl_to_api PA GET $query)"
1290 status=${res:${#res}-3}
1292 if [ $status -ne $1 ]; then
1293 __log_test_fail_status_code $1 $status
1297 if [ $# -eq 3 ]; then
1298 body=${res:0:${#res}-3}
1299 if [ "$body" != "$3" ]; then
1300 __log_test_fail_body
1309 # API test function: GET /rics and V2 GET /v2/rics
1310 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1311 # 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_........."
1312 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1313 # (Function for test scripts)
1317 if [ $# -lt 2 ]; then
1318 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1322 if [ "$PMS_VERSION" == "V2" ]; then
1324 if [ $2 != "NOTYPE" ]; then
1325 query="/v2/rics?policytype_id="$2
1329 if [ $2 != "NOTYPE" ]; then
1330 query="/rics?policyType="$2
1334 res="$(__do_curl_to_api PA GET $query)"
1335 status=${res:${#res}-3}
1337 if [ $status -ne $1 ]; then
1338 __log_test_fail_status_code $1 $status
1342 if [ $# -gt 2 ]; then
1343 body=${res:0:${#res}-3}
1344 if [ "$PMS_VERSION" == "V2" ]; then
1345 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1347 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1349 if [ $res -ne 0 ]; then
1350 __log_test_fail_general "Could not create target ric info json"
1354 targetJson=$(<./tmp/.tmp_rics.json)
1355 if [ "$PMS_VERSION" == "V2" ]; then
1356 targetJson="{\"rics\": $targetJson }"
1358 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1359 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1360 if [ $res -ne 0 ]; then
1361 __log_test_fail_body
1370 ##################################################################
1371 #### API Test case functions Service registry and supervision ####
1372 ##################################################################
1374 # API test function: PUT /service and V2 PUT /service
1375 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1376 # (Function for test scripts)
1379 if [ $# -ne 4 ]; then
1380 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1384 if [ "$PMS_VERSION" == "V2" ]; then
1385 query="/v2/services"
1386 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1389 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1391 file="./tmp/.tmp.json"
1392 echo "$json" > $file
1394 res="$(__do_curl_to_api PA PUT $query $file)"
1395 status=${res:${#res}-3}
1397 if [ $status -ne $1 ]; then
1398 __log_test_fail_status_code $1 $status
1406 # API test function: GET /services and V2 GET /v2/services
1407 #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>]* )]
1408 # (Function for test scripts)
1409 api_get_services() {
1411 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1413 if [ $# -eq 1 ]; then
1415 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1417 elif [ $# -eq 5 ]; then
1419 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1421 if [ $(($argLen%3)) -eq 0 ]; then
1426 if [ $paramError -ne 0 ]; then
1427 __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>]* )]" $@
1431 if [ "$PMS_VERSION" == "V2" ]; then
1432 query="/v2/services"
1434 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1435 query="/v2/services?service_id="$2
1440 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1441 query="/services?name="$2
1444 res="$(__do_curl_to_api PA GET $query)"
1445 status=${res:${#res}-3}
1447 if [ $status -ne $1 ]; then
1448 __log_test_fail_status_code $1 $status
1452 if [ $# -gt 2 ]; then
1453 variableArgCount=$(($#-2))
1454 body=${res:0:${#res}-3}
1458 while [ $cntr -lt $variableArgCount ]; do
1459 servicename=$1; shift;
1462 if [ $cntr -gt 0 ]; then
1463 targetJson=$targetJson","
1465 # timeSinceLastActivitySeconds value cannot be checked since value varies
1466 if [ "$PMS_VERSION" == "V2" ]; then
1467 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1469 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1473 targetJson=$targetJson"]"
1474 if [ "$PMS_VERSION" == "V2" ]; then
1475 targetJson="{\"service_list\": $targetJson }"
1477 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1478 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1479 if [ $res -ne 0 ]; then
1480 __log_test_fail_body
1489 # API test function: GET /services V2 GET /v2/services - (only checking service names)
1490 # args: <response-code> [<service-name>]*"
1491 # (Function for test scripts)
1492 api_get_service_ids() {
1495 if [ $# -lt 1 ]; then
1496 __print_err "<response-code> [<service-name>]*" $@
1500 if [ "$PMS_VERSION" == "V2" ]; then
1501 query="/v2/services"
1505 res="$(__do_curl_to_api PA GET $query)"
1506 status=${res:${#res}-3}
1508 if [ $status -ne $1 ]; then
1509 __log_test_fail_status_code $1 $status
1513 body=${res:0:${#res}-3}
1515 for rapp in ${@:2} ; do
1516 if [ "$targetJson" != "[" ]; then
1517 targetJson=$targetJson","
1519 if [ "$PMS_VERSION" == "V2" ]; then
1520 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
1522 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1526 targetJson=$targetJson"]"
1527 if [ "$PMS_VERSION" == "V2" ]; then
1528 targetJson="{\"service_list\": $targetJson }"
1530 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1531 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1533 if [ $res -ne 0 ]; then
1534 __log_test_fail_body
1542 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
1543 # args: <response-code> <service-name>
1544 # (Function for test scripts)
1545 api_delete_services() {
1548 if [ $# -ne 2 ]; then
1549 __print_err "<response-code> <service-name>" $@
1552 if [ "$PMS_VERSION" == "V2" ]; then
1553 query="/v2/services/"$2
1555 query="/services?name="$2
1557 res="$(__do_curl_to_api PA DELETE $query)"
1558 status=${res:${#res}-3}
1560 if [ $status -ne $1 ]; then
1561 __log_test_fail_status_code $1 $status
1569 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
1570 # args: <response-code> <service-name>
1571 # (Function for test scripts)
1572 api_put_services_keepalive() {
1575 if [ $# -ne 2 ]; then
1576 __print_err "<response-code> <service-name>" $@
1579 if [ "$PMS_VERSION" == "V2" ]; then
1580 query="/v2/services/$2/keepalive"
1582 query="/services/keepalive?name="$2
1585 res="$(__do_curl_to_api PA PUT $query)"
1586 status=${res:${#res}-3}
1588 if [ $status -ne $1 ]; then
1589 __log_test_fail_status_code $1 $status
1597 ##################################################################
1598 #### API Test case functions Configuration ####
1599 ##################################################################
1601 # API Test function: PUT /v2/configuration
1602 # args: <response-code> <config-file>
1603 # (Function for test scripts)
1604 api_put_configuration() {
1607 if [ "$PMS_VERSION" != "V2" ]; then
1608 __log_test_fail_not_supported
1612 if [ $# -ne 2 ]; then
1613 __print_err "<response-code> <config-file>" $@
1616 if [ ! -f $2 ]; then
1617 _log_test_fail_general "Config file "$2", does not exist"
1621 inputJson="{\"config\":"$inputJson"}"
1622 file="./tmp/.config.json"
1623 echo $inputJson > $file
1624 query="/v2/configuration"
1625 res="$(__do_curl_to_api PA PUT $query $file)"
1626 status=${res:${#res}-3}
1628 if [ $status -ne $1 ]; then
1629 __log_test_fail_status_code $1 $status
1637 # API Test function: GET /v2/configuration
1638 # args: <response-code> [<config-file>]
1639 # (Function for test scripts)
1640 api_get_configuration() {
1643 if [ "$PMS_VERSION" != "V2" ]; then
1644 __log_test_fail_not_supported
1648 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
1649 __print_err "<response-code> [<config-file>]" $@
1652 if [ ! -f $2 ]; then
1653 _log_test_fail_general "Config file "$2" for comparison, does not exist"
1657 query="/v2/configuration"
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 2 ]; then
1668 body=${res:0:${#res}-3}
1671 targetJson="{\"config\":"$targetJson"}"
1672 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1673 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1675 if [ $res -ne 0 ]; then
1676 __log_test_fail_body