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 __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/" $1 "=" $2 $3
44 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
48 # API Test function: GET /policies
49 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-ype-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*]
50 # (Function for test scripts)
52 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
53 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
58 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
60 elif [ $# -gt 4 ] && [ $(($#%5)) -ne 4 ]; then
64 if [ $paramError -ne 0 ]; then
65 __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>]*]" $@
69 if [ $2 != "NORIC" ]; then
72 if [ $3 != "NOSERVICE" ]; then
73 if [ -z $queryparams ]; then
74 queryparams="?service="$3
76 queryparams=$queryparams"&service="$3
79 if [ $4 != "NOTYPE" ]; then
80 if [ -z $queryparams ]; then
81 queryparams="?type="$4
83 queryparams=$queryparams"&type="$4
87 query="/policies"$queryparams
88 res="$(__do_curl_to_api PA GET $query)"
89 status=${res:${#res}-3}
91 if [ $status -ne $1 ]; then
92 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
99 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
102 body=${res:0:${#res}-3}
106 for ((i=0; i<$(($#-4)); i=i+5)); do
108 if [ "$targetJson" != "[" ]; then
109 targetJson=$targetJson","
111 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
112 if [ "${arr[$i+3]}" == "EMPTY" ]; then
113 targetJson=$targetJson"\"\","
115 targetJson=$targetJson"\"${arr[$i+3]}\","
118 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
120 targetJson=$targetJson"\"json\":"$json"}"
124 targetJson=$targetJson"]"
125 echo "TARGET JSON: $targetJson" >> $HTTPLOG
126 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
128 if [ $res -ne 0 ]; then
129 echo -e $RED" FAIL, returned body not correct"$ERED
131 __check_stop_at_error
137 echo -e $GREEN" PASS"$EGREEN
142 # API Test function: GET /policy
143 #args: <response-code> <policy-id> [<template-file>]
144 # (Function for test scripts)
146 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
147 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
150 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
151 __print_err "<response-code> <policy-id> [<template-file>] " $@
155 query="/policy?id=$UUID$2"
156 res="$(__do_curl_to_api PA GET $query)"
157 status=${res:${#res}-3}
159 if [ $status -ne $1 ]; then
160 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
162 __check_stop_at_error
166 if [ $# -eq 3 ]; then
167 #Create a policy json to compare with
168 body=${res:0:${#res}-3}
170 sed 's/XXX/'${2}'/g' $3 > $file
171 targetJson=$(< $file)
172 echo "TARGET JSON: $targetJson" >> $HTTPLOG
173 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
174 if [ $res -ne 0 ]; then
175 echo -e $RED" FAIL, returned body not correct"$ERED
177 __check_stop_at_error
183 echo -e $GREEN" PASS"$EGREEN
187 # API Test function: PUT /policy
188 # args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]
189 # (Function for test scripts)
191 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
192 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
195 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
196 __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
204 if [ $# -eq 8 ]; then
211 while [ $count -lt $max ]; do
212 query="/policy?id=$UUID$pid&ric=$ric&service=$2"
214 if [ $4 != "NOTYPE" ]; then
215 query=$query"&type=$4"
218 if [ $6 != NOTRANSIENT ]; then
219 query=$query"&transient=$6"
223 sed 's/XXX/'${pid}'/g' $7 > $file
224 res="$(__do_curl_to_api PA PUT $query $file)"
225 status=${res:${#res}-3}
226 echo -ne " Executing "$count"("$max")${SAMELINE}"
227 if [ $status -ne $1 ]; then
228 echo " Executed "$count"?("$max")"
229 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
231 __check_stop_at_error
237 echo -ne " Executed "$count"("$max")${SAMELINE}"
242 echo -e $GREEN" PASS"$EGREEN
246 # API Test function: PUT /policy to run in batch
247 # args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]
248 # (Function for test scripts)
249 api_put_policy_batch() {
250 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
251 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
254 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
255 __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]" $@
263 if [ $# -eq 8 ]; then
270 while [ $count -lt $max ]; do
271 query="/policy?id=$UUID$pid&ric=$ric&service=$2"
273 if [ $4 != "NOTYPE" ]; then
274 query=$query"&type=$4"
277 if [ $6 != NOTRANSIENT ]; then
278 query=$query"&transient=$6"
282 sed 's/XXX/'${pid}'/g' $7 > $file
283 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
284 status=${res:${#res}-3}
285 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
287 if [ $status -ne 200 ]; then
288 echo " Requested(batch) "$count"?("$max")"
289 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
291 __check_stop_at_error
294 cid=${res:0:${#res}-3}
298 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
305 res="$(__do_curl_to_api PA RESPONSE $cid)"
306 status=${res:${#res}-3}
307 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
309 if [ $status -ne $1 ]; then
310 echo " Requested(batch) "$count"?("$max")"
311 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
313 __check_stop_at_error
318 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
324 echo -e $GREEN" PASS"$EGREEN
328 # API Test function: PUT /policy to run in i parallel for a number of rics
329 # 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>
330 # (Function for test scripts)
331 api_put_policy_parallel() {
332 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
333 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
336 if [ $# -ne 10 ]; then
337 __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>" $@
351 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
352 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
353 echo " Info - will execute over agent REST"
356 if [ $serv == "NOSERVICE" ]; then
359 query="/policy?service=$serv"
361 if [ $type != "NOTYPE" ]; then
362 query=$query"&type=$type"
365 if [ $transient != NOTRANSIENT ]; then
366 query=$query"&transient=$transient"
369 urlbase=${ADAPTER}${query}
371 for ((i=1; i<=$pids; i++))
374 if [ -z "$uuid" ]; then
377 echo "" > "./tmp/.pid${i}.res.txt"
378 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt"
380 done | xargs -n 1 -I{} -P $pids bash -c '{
382 echo " Parallel process $arg started"
383 tmp=$(< "./tmp/.pid${arg}.txt")
384 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
387 for ((i=1; i<=$pids; i++))
389 file="./tmp/.pid${i}.res.txt"
391 if [ -z "$tmp" ]; then
392 echo " Process $i : unknown result (result file empty"
396 if [ $res == "0" ]; then
397 echo " Process $i : OK"
399 echo " Process $i : failed - "${tmp:1}
405 echo " $(($count*$num_rics)) policy request(s) executed"
407 echo -e $GREEN" PASS"$EGREEN
411 echo -e $RED" FAIL. One of more processes failed to execute" $ERED
413 __check_stop_at_error
417 # API Test function: DELETE /policy
418 # args: <response-code> <policy-id> [count]
419 # (Function for test scripts)
420 api_delete_policy() {
421 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
422 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
425 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
426 __print_err "<response-code> <policy-id> [count]" $@
433 if [ $# -eq 3 ]; then
439 while [ $count -lt $max ]; do
440 query="/policy?id="$UUID$pid
441 res="$(__do_curl_to_api PA DELETE $query)"
442 status=${res:${#res}-3}
443 echo -ne " Executing "$count"("$max")${SAMELINE}"
445 if [ $status -ne $1 ]; then
446 echo " Executed "$count"?("$max")"
447 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
449 __check_stop_at_error
454 echo -ne " Executed "$count"("$max")${SAMELINE}"
459 echo -e $GREEN" PASS"$EGREEN
463 # API Test function: DELETE /policy to run in batch
464 # args: <response-code> <policy-id> [count]
465 # (Function for test scripts)
466 api_delete_policy_batch() {
467 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
468 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
471 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
472 __print_err "<response-code> <policy-id> [count]" $@
479 if [ $# -eq 3 ]; then
485 while [ $count -lt $max ]; do
486 query="/policy?id="$UUID$pid
487 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
488 status=${res:${#res}-3}
489 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
491 if [ $status -ne 200 ]; then
492 echo " Requested(batch) "$count"?("$max")"
493 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
495 __check_stop_at_error
498 cid=${res:0:${#res}-3}
502 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
510 res="$(__do_curl_to_api PA RESPONSE $cid)"
511 status=${res:${#res}-3}
512 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
514 if [ $status -ne $1 ]; then
515 echo " Deleted(batch) "$count"?("$max")"
516 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
518 __check_stop_at_error
523 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
527 echo -e $GREEN" PASS"$EGREEN
531 # API Test function: DELETE /policy to run in i parallel for a number of rics
532 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
533 # (Function for test scripts)
534 api_delete_policy_parallel() {
535 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
536 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
539 if [ $# -ne 5 ]; then
540 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
549 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
550 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
551 echo " Info - will execute over agent REST"
556 urlbase=${ADAPTER}${query}
558 for ((i=1; i<=$pids; i++))
561 if [ -z "$uuid" ]; then
564 echo "" > "./tmp/.pid${i}.del.res.txt"
565 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > "./tmp/.pid${i}.del.txt"
567 done | xargs -n 1 -I{} -P $pids bash -c '{
569 echo " Parallel process $arg started"
570 tmp=$(< "./tmp/pid${arg}.del.txt")
571 python3 ../common/delete_policies_process.py $tmp > ./tmp/pid${arg}.del.res.txt
574 for ((i=1; i<=$pids; i++))
576 file="./tmp/.pid${i}.del.res.txt"
578 if [ -z "$tmp" ]; then
579 echo " Process $i : unknown result (result file empty"
583 if [ $res == "0" ]; then
584 echo " Process $i : OK"
586 echo " Process $i : failed - "${tmp:1}
592 echo " $(($count*$num_rics)) policy request(s) executed"
594 echo -e $GREEN" PASS"$EGREEN
598 echo -e $RED" FAIL. One of more processes failed to execute" $ERED
600 __check_stop_at_error
604 # API Test function: GET /policy_ids
605 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
606 # (Function for test scripts)
607 api_get_policy_ids() {
608 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
609 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
612 if [ $# -lt 4 ]; then
613 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
619 if [ $2 != "NORIC" ]; then
620 queryparams="?ric="$2
623 if [ $3 != "NOSERVICE" ]; then
624 if [ -z $queryparams ]; then
625 queryparams="?service="$3
627 queryparams=$queryparams"&service="$3
630 if [ $4 != "NOTYPE" ]; then
631 if [ -z $queryparams ]; then
632 queryparams="?type="$4
634 queryparams=$queryparams"&type="$4
638 query="/policy_ids"$queryparams
639 res="$(__do_curl_to_api PA GET $query)"
640 status=${res:${#res}-3}
642 if [ $status -ne $1 ]; then
643 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
645 __check_stop_at_error
649 if [ $# -gt 4 ]; then
650 body=${res:0:${#res}-3}
653 for pid in ${@:5} ; do
654 if [ "$targetJson" != "[" ]; then
655 targetJson=$targetJson","
657 if [ $pid != "NOID" ]; then
658 targetJson=$targetJson"\"$UUID$pid\""
662 targetJson=$targetJson"]"
663 echo "TARGET JSON: $targetJson" >> $HTTPLOG
664 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
666 if [ $res -ne 0 ]; then
667 echo -e $RED" FAIL, returned body not correct"$ERED
669 __check_stop_at_error
675 echo -e $GREEN" PASS"$EGREEN
679 # API Test function: GET /policy_schema
680 # args: <response-code> <policy-type-id> [<schema-file>]
681 # (Function for test scripts)
682 api_get_policy_schema() {
683 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
684 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
687 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
688 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
692 query="/policy_schema?id=$2"
693 res="$(__do_curl_to_api PA GET $query)"
694 status=${res:${#res}-3}
696 if [ $status -ne $1 ]; then
697 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
699 __check_stop_at_error
703 if [ $# -eq 3 ]; then
705 body=${res:0:${#res}-3}
708 echo "TARGET JSON: $targetJson" >> $HTTPLOG
709 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
711 if [ $res -ne 0 ]; then
712 echo -e $RED" FAIL, returned body not correct"$ERED
714 __check_stop_at_error
720 echo -e $GREEN" PASS"$EGREEN
724 # API Test function: GET /policy_schemas
725 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
726 # (Function for test scripts)
727 api_get_policy_schemas() {
728 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
729 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
732 if [ $# -lt 2 ]; then
733 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
737 query="/policy_schemas"
738 if [ $2 != "NORIC" ]; then
739 query=$query"?ric="$2
742 res="$(__do_curl_to_api PA GET $query)"
743 status=${res:${#res}-3}
745 if [ $status -ne $1 ]; then
746 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
748 __check_stop_at_error
752 if [ $# -gt 2 ]; then
753 body=${res:0:${#res}-3}
756 for file in ${@:3} ; do
757 if [ "$targetJson" != "[" ]; then
758 targetJson=$targetJson","
760 if [ $file == "NOFILE" ]; then
761 targetJson=$targetJson"{}"
763 targetJson=$targetJson$(< $file)
767 targetJson=$targetJson"]"
768 echo "TARGET JSON: $targetJson" >> $HTTPLOG
769 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
771 if [ $res -ne 0 ]; then
772 echo -e $RED" FAIL, returned body not correct"$ERED
774 __check_stop_at_error
780 echo -e $GREEN" PASS"$EGREEN
784 # API Test function: GET /policy_status
785 # arg: <response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)
786 # (Function for test scripts)
787 api_get_policy_status() {
788 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
789 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
791 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
792 __print_err "<response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
798 if [ $3 == "STD" ]; then
799 targetJson="{\"enforceStatus\":\"$4\""
800 if [ $# -eq 5 ]; then
801 targetJson=$targetJson",\"reason\":\"$5\""
803 targetJson=$targetJson"}"
804 elif [ $3 == "OSC" ]; then
805 targetJson="{\"instance_status\":\"$4\""
806 if [ $# -eq 5 ]; then
807 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
809 targetJson=$targetJson",\"created_at\":\"????\"}"
811 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
815 query="/policy_status?id="$UUID$2
817 res="$(__do_curl_to_api PA GET $query)"
818 status=${res:${#res}-3}
820 if [ $status -ne $1 ]; then
821 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
823 __check_stop_at_error
827 echo "TARGET JSON: $targetJson" >> $HTTPLOG
828 body=${res:0:${#res}-3}
829 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
831 if [ $res -ne 0 ]; then
832 echo -e $RED" FAIL, returned body not correct"$ERED
834 __check_stop_at_error
839 echo -e $GREEN" PASS"$EGREEN
843 # API Test function: GET /policy_types
844 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
845 # (Function for test scripts)
846 api_get_policy_types() {
847 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
848 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
851 if [ $# -lt 1 ]; then
852 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
856 if [ $# -eq 1 ]; then
857 query="/policy_types"
858 elif [ $2 == "NORIC" ]; then
859 query="/policy_types"
861 query="/policy_types?ric=$2"
864 res="$(__do_curl_to_api PA GET $query)"
865 status=${res:${#res}-3}
867 if [ $status -ne $1 ]; then
868 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
870 __check_stop_at_error
874 if [ $# -gt 2 ]; then
875 body=${res:0:${#res}-3}
878 for pid in ${@:3} ; do
879 if [ "$targetJson" != "[" ]; then
880 targetJson=$targetJson","
882 if [ $pid == "EMPTY" ]; then
885 targetJson=$targetJson"\"$pid\""
888 targetJson=$targetJson"]"
889 echo "TARGET JSON: $targetJson" >> $HTTPLOG
890 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
892 if [ $res -ne 0 ]; then
893 echo -e $RED" FAIL, returned body not correct"$ERED
895 __check_stop_at_error
901 echo -e $GREEN" PASS"$EGREEN
905 #########################################################
906 #### Test case functions Health check
907 #########################################################
909 # API Test function: GET /status
910 # args: <response-code>
911 # (Function for test scripts)
913 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
914 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
916 if [ $# -ne 1 ]; then
917 __print_err "<response-code>" $@
921 res="$(__do_curl_to_api PA GET $query)"
922 status=${res:${#res}-3}
924 if [ $status -ne $1 ]; then
925 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
927 __check_stop_at_error
932 echo -e $GREEN" PASS"$EGREEN
936 #########################################################
937 #### Test case functions RIC Repository
938 #########################################################
940 # API Test function: GET /ric
941 # args: <reponse-code> <management-element-id> [<ric-id>]
942 # (Function for test scripts)
944 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
945 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
947 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
948 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
952 query="/ric?managedElementId="$2
954 res="$(__do_curl_to_api PA GET $query)"
955 status=${res:${#res}-3}
957 if [ $status -ne $1 ]; then
958 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
960 __check_stop_at_error
964 if [ $# -eq 3 ]; then
965 body=${res:0:${#res}-3}
966 if [ "$body" != "$3" ]; then
967 echo -e $RED" FAIL, returned body not correct"$ERED
969 __check_stop_at_error
975 echo -e $GREEN" PASS"$EGREEN
979 # API test function: GET /rics
980 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
981 # 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_........."
982 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
983 # (Function for test scripts)
985 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
986 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
989 if [ $# -lt 2 ]; then
990 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
995 if [ $2 != "NOTYPE" ]; then
996 query="/rics?policyType="$2
999 res="$(__do_curl_to_api PA GET $query)"
1000 status=${res:${#res}-3}
1002 if [ $status -ne $1 ]; then
1003 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1005 __check_stop_at_error
1009 if [ $# -gt 2 ]; then
1010 body=${res:0:${#res}-3}
1011 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "$3" )
1012 if [ $res -ne 0 ]; then
1013 echo -e $RED" FAIL, could not create target ric info json"$ERED
1015 __check_stop_at_error
1019 targetJson=$(<./tmp/.tmp_rics.json)
1020 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1021 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1022 if [ $res -ne 0 ]; then
1023 echo -e $RED" FAIL, returned body not correct"$ERED
1025 __check_stop_at_error
1031 echo -e $GREEN" PASS"$EGREEN
1035 ##################################################################
1036 #### API Test case functions Service registry and supervision ####
1037 ##################################################################
1039 # API test function: PUT /service
1040 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1041 # (Function for test scripts)
1043 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1044 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1046 if [ $# -ne 4 ]; then
1047 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1052 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1053 file="./tmp/.tmp.json"
1054 echo "$json" > $file
1056 res="$(__do_curl_to_api PA PUT $query $file)"
1057 status=${res:${#res}-3}
1059 if [ $status -ne $1 ]; then
1060 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1062 __check_stop_at_error
1067 echo -e $GREEN" PASS"$EGREEN
1071 # API test function: GET /services
1072 #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>]* )]
1073 # (Function for test scripts)
1074 api_get_services() {
1075 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1076 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1078 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1080 if [ $# -eq 1 ]; then
1082 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1084 elif [ $# -eq 5 ]; then
1086 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1088 if [ $(($argLen%3)) -eq 0 ]; then
1093 if [ $paramError -ne 0 ]; then
1094 __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>]* )]" $@
1100 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1101 query="/services?name="$2
1104 res="$(__do_curl_to_api PA GET $query)"
1105 status=${res:${#res}-3}
1107 if [ $status -ne $1 ]; then
1108 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1110 __check_stop_at_error
1114 if [ $# -gt 2 ]; then
1115 variableArgCount=$(($#-2))
1116 body=${res:0:${#res}-3}
1120 while [ $cntr -lt $variableArgCount ]; do
1121 servicename=$1; shift;
1124 if [ $cntr -gt 0 ]; then
1125 targetJson=$targetJson","
1127 # timeSinceLastActivitySeconds value cannot be checked since value varies
1128 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1131 targetJson=$targetJson"]"
1132 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1133 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1134 if [ $res -ne 0 ]; then
1135 echo -e $RED" FAIL, returned body not correct"$ERED
1137 __check_stop_at_error
1143 echo -e $GREEN" PASS"$EGREEN
1147 # API test function: GET /services (only checking service names)
1148 # args: <response-code> [<service-name>]*"
1149 # (Function for test scripts)
1150 api_get_service_ids() {
1151 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1152 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1155 if [ $# -lt 1 ]; then
1156 __print_err "<response-code> [<service-name>]*" $@
1161 res="$(__do_curl_to_api PA GET $query)"
1162 status=${res:${#res}-3}
1164 if [ $status -ne $1 ]; then
1165 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1167 __check_stop_at_error
1171 body=${res:0:${#res}-3}
1173 for rapp in ${@:2} ; do
1174 if [ "$targetJson" != "[" ]; then
1175 targetJson=$targetJson","
1177 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1180 targetJson=$targetJson"]"
1181 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1182 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1184 if [ $res -ne 0 ]; then
1185 echo -e $RED" FAIL, returned body not correct"$ERED
1187 __check_stop_at_error
1192 echo -e $GREEN" PASS"$EGREEN
1196 # API test function: DELETE /services
1197 # args: <response-code> <service-name>
1198 # (Function for test scripts)
1199 api_delete_services() {
1200 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1201 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1204 if [ $# -ne 2 ]; then
1205 __print_err "<response-code> <service-name>" $@
1209 query="/services?name="$2
1210 res="$(__do_curl_to_api PA DELETE $query)"
1211 status=${res:${#res}-3}
1213 if [ $status -ne $1 ]; then
1214 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1216 __check_stop_at_error
1221 echo -e $GREEN" PASS"$EGREEN
1225 # API test function: PUT /services/keepalive
1226 # args: <response-code> <service-name>
1227 # (Function for test scripts)
1228 api_put_services_keepalive() {
1229 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1230 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1233 if [ $# -ne 2 ]; then
1234 __print_err "<response-code> <service-name>" $@
1238 query="/services/keepalive?name="$2
1239 res="$(__do_curl_to_api PA PUT $query)"
1240 status=${res:${#res}-3}
1242 if [ $status -ne $1 ]; then
1243 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1245 __check_stop_at_error
1250 echo -e $GREEN" PASS"$EGREEN