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
48 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
52 # API Test function: GET /policies and V2 GET /v2/policy-instances
53 # 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>]*]
54 # 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>]*]
55 # (Function for test scripts)
57 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
58 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
61 if [ "$PMS_VERSION" == "V2" ]; then
63 variableParams=$(($#-4))
66 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
68 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
72 if [ $paramError -ne 0 ]; then
73 __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>]*]" $@
78 variableParams=$(($#-4))
81 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
83 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
87 if [ $paramError -ne 0 ]; then
88 __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>]*]" $@
94 if [ "$PMS_VERSION" == "V2" ]; then
95 if [ $2 != "NORIC" ]; then
96 queryparams="?ric_id="$2
98 if [ $3 != "NOSERVICE" ]; then
99 if [ -z $queryparams ]; then
100 queryparams="?service_id="$3
102 queryparams=$queryparams"&service_id="$3
105 if [ $4 != "NOTYPE" ]; then
106 if [ -z $queryparams ]; then
107 queryparams="?policytype_id="$4
109 queryparams=$queryparams"&policytype_id="$4
113 query="/v2/policy-instances"$queryparams
114 res="$(__do_curl_to_api PA GET $query)"
115 status=${res:${#res}-3}
117 if [ $status -ne $1 ]; then
118 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
120 __check_stop_at_error
124 if [ $# -gt 4 ]; then
125 body=${res:0:${#res}-3}
126 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
132 for ((i=0; i<$(($#-4)); i=i+7)); do
134 if [ "$targetJson" != "[" ]; then
135 targetJson=$targetJson","
137 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
138 if [ "${arr[$i+3]}" == "EMPTY" ]; then
139 targetJson=$targetJson"\"\","
141 targetJson=$targetJson"\"${arr[$i+3]}\","
143 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
145 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
147 targetJson=$targetJson"\"policy_data\":"$json"}"
151 targetJson=$targetJson"]"
152 targetJson="{\"policies\": $targetJson}"
153 echo "TARGET JSON: $targetJson" >> $HTTPLOG
154 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
156 if [ $res -ne 0 ]; then
157 echo -e $RED" FAIL, returned body not correct"$ERED
159 __check_stop_at_error
164 if [ $2 != "NORIC" ]; then
165 queryparams="?ric="$2
167 if [ $3 != "NOSERVICE" ]; then
168 if [ -z $queryparams ]; then
169 queryparams="?service="$3
171 queryparams=$queryparams"&service="$3
174 if [ $4 != "NOTYPE" ]; then
175 if [ -z $queryparams ]; then
176 queryparams="?type="$4
178 queryparams=$queryparams"&type="$4
182 query="/policies"$queryparams
183 res="$(__do_curl_to_api PA GET $query)"
184 status=${res:${#res}-3}
186 if [ $status -ne $1 ]; then
187 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
189 __check_stop_at_error
193 if [ $# -gt 4 ]; then
194 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
197 body=${res:0:${#res}-3}
201 for ((i=0; i<$(($#-4)); i=i+5)); do
203 if [ "$targetJson" != "[" ]; then
204 targetJson=$targetJson","
206 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
207 if [ "${arr[$i+3]}" == "EMPTY" ]; then
208 targetJson=$targetJson"\"\","
210 targetJson=$targetJson"\"${arr[$i+3]}\","
213 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
215 targetJson=$targetJson"\"json\":"$json"}"
219 targetJson=$targetJson"]"
220 echo "TARGET JSON: $targetJson" >> $HTTPLOG
221 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
223 if [ $res -ne 0 ]; then
224 echo -e $RED" FAIL, returned body not correct"$ERED
226 __check_stop_at_error
233 echo -e $GREEN" PASS"$EGREEN
239 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
240 # args: <response-code> <policy-id> [<template-file>]
241 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
243 # (Function for test scripts)
245 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
246 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
250 if [ "$PMS_VERSION" == "V2" ]; then
251 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
252 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
255 query="/v2/policies/$UUID$2"
257 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
258 __print_err "<response-code> <policy-id> [<template-file>] " $@
261 query="/policy?id=$UUID$2"
263 res="$(__do_curl_to_api PA GET $query)"
264 status=${res:${#res}-3}
266 if [ $status -ne $1 ]; then
267 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
269 __check_stop_at_error
273 if [ "$PMS_VERSION" == "V2" ]; then
274 if [ $# -eq 8 ]; then
276 #Create a policy json to compare with
277 body=${res:0:${#res}-3}
280 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
281 if [ $7 != "NOTRANSIENT" ]; then
282 targetJson=$targetJson", \"transient\":$7"
284 if [ $6 != "NOTYPE" ]; then
285 targetJson=$targetJson", \"policytype_id\":\"$6\""
287 targetJson=$targetJson", \"policytype_id\":\"\""
289 if [ $8 != "NOURL" ]; then
290 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
293 data=$(sed 's/XXX/'${2}'/g' $temp)
294 targetJson=$targetJson", \"policy_data\":$data"
295 targetJson="{$targetJson}"
297 echo "TARGET JSON: $targetJson" >> $HTTPLOG
298 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
299 if [ $res -ne 0 ]; then
300 echo -e $RED" FAIL, returned body not correct"$ERED
302 __check_stop_at_error
307 if [ $# -eq 3 ]; then
308 #Create a policy json to compare with
309 body=${res:0:${#res}-3}
311 sed 's/XXX/'${2}'/g' $3 > $file
312 targetJson=$(< $file)
313 echo "TARGET JSON: $targetJson" >> $HTTPLOG
314 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
315 if [ $res -ne 0 ]; then
316 echo -e $RED" FAIL, returned body not correct"$ERED
318 __check_stop_at_error
325 echo -e $GREEN" PASS"$EGREEN
329 # API Test function: PUT /policy and V2 PUT /policies
330 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
331 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
332 # (Function for test scripts)
334 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
335 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
338 if [ "$PMS_VERSION" == "V2" ]; then
339 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
340 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
344 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
345 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
358 if [ "$PMS_VERSION" == "V2" ]; then
361 if [ $# -eq 9 ]; then
366 if [ $# -eq 8 ]; then
371 while [ $count -lt $max ]; do
372 if [ "$PMS_VERSION" == "V2" ]; then
376 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
377 if [ $trans != "NOTRANSIENT" ]; then
378 inputJson=$inputJson", \"transient\":$trans"
380 if [ $pt != "NOTYPE" ]; then
381 inputJson=$inputJson", \"policytype_id\":\"$pt\""
383 inputJson=$inputJson", \"policytype_id\":\"\""
385 if [ $noti != "NOURL" ]; then
386 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
389 data=$(sed 's/XXX/'${pid}'/g' $temp)
390 inputJson=$inputJson", \"policy_data\":$data"
391 inputJson="{$inputJson}"
392 echo $inputJson > $file
394 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
396 if [ $pt != "NOTYPE" ]; then
397 query=$query"&type=$pt"
400 if [ $trans != NOTRANSIENT ]; then
401 query=$query"&transient=$trans"
405 sed 's/XXX/'${pid}'/g' $temp > $file
407 res="$(__do_curl_to_api PA PUT $query $file)"
408 status=${res:${#res}-3}
409 echo -ne " Executing "$count"("$max")${SAMELINE}"
410 if [ $status -ne $1 ]; then
411 echo " Executed "$count"?("$max")"
412 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
414 __check_stop_at_error
420 echo -ne " Executed "$count"("$max")${SAMELINE}"
425 echo -e $GREEN" PASS"$EGREEN
429 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
430 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
431 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
432 # (Function for test scripts)
434 api_put_policy_batch() {
435 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
436 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
439 if [ "$PMS_VERSION" == "V2" ]; then
440 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
441 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
445 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
446 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
458 if [ "$PMS_VERSION" == "V2" ]; then
461 if [ $# -eq 9 ]; then
466 if [ $# -eq 8 ]; then
472 while [ $count -lt $max ]; do
473 if [ "$PMS_VERSION" == "V2" ]; then
476 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
477 if [ $trans != "NOTRANSIENT" ]; then
478 inputJson=$inputJson", \"transient\":$trans"
480 if [ $pt != "NOTYPE" ]; then
481 inputJson=$inputJson", \"policytype_id\":\"$pt\""
483 inputJson=$inputJson", \"policytype_id\":\"\""
485 if [ $noti != "NOURL" ]; then
486 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
489 data=$(sed 's/XXX/'${pid}'/g' $temp)
490 inputJson=$inputJson", \"policy_data\":$data"
491 inputJson="{$inputJson}"
492 echo $inputJson > $file
494 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
496 if [ $pt != "NOTYPE" ]; then
497 query=$query"&type=$pt"
500 if [ $trans != NOTRANSIENT ]; then
501 query=$query"&transient=$trans"
504 sed 's/XXX/'${pid}'/g' $temp > $file
506 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
507 status=${res:${#res}-3}
508 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
510 if [ $status -ne 200 ]; then
511 echo " Requested(batch) "$count"?("$max")"
512 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
514 __check_stop_at_error
517 cid=${res:0:${#res}-3}
521 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
528 res="$(__do_curl_to_api PA RESPONSE $cid)"
529 status=${res:${#res}-3}
530 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
532 if [ $status -ne $1 ]; then
533 echo " Accepted(batch) "$count"?("$max")"
534 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
536 __check_stop_at_error
541 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
547 echo -e $GREEN" PASS"$EGREEN
551 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
552 # 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>
553 # 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>
554 # (Function for test scripts)
555 api_put_policy_parallel() {
556 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
557 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
560 if [ "$PMS_VERSION" == "V2" ]; then
561 if [ $# -ne 11 ]; then
562 __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>" $@
566 if [ $# -ne 10 ]; then
567 __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>" $@
578 if [ "$PMS_VERSION" == "V2" ]; then
587 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
588 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
589 echo " Info - will execute over agent REST"
591 if [ "$PMS_VERSION" == "V2" ]; then
592 if [ $serv == "NOSERVICE" ]; then
597 if [ $serv == "NOSERVICE" ]; then
600 query="/policy?service=$serv"
602 if [ $type != "NOTYPE" ]; then
603 query=$query"&type=$type"
606 if [ $transient != NOTRANSIENT ]; then
607 query=$query"&transient=$transient"
611 urlbase=${ADAPTER}${query}
613 for ((i=1; i<=$pids; i++))
616 if [ -z "$uuid" ]; then
619 echo "" > "./tmp/.pid${i}.res.txt"
620 if [ "$PMS_VERSION" == "V2" ]; then
621 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i > "./tmp/.pid${i}.txt"
623 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt"
626 done | xargs -n 1 -I{} -P $pids bash -c '{
628 echo " Parallel process $arg started"
629 tmp=$(< "./tmp/.pid${arg}.txt")
630 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
633 for ((i=1; i<=$pids; i++))
635 file="./tmp/.pid${i}.res.txt"
637 if [ -z "$tmp" ]; then
638 echo " Process $i : unknown result (result file empty"
642 if [ $res == "0" ]; then
643 echo " Process $i : OK - "${tmp:1}
645 echo " Process $i : failed - "${tmp:1}
651 echo " $(($count*$num_rics)) policy request(s) executed"
653 echo -e $GREEN" PASS"$EGREEN
657 echo -e $RED" FAIL. One of more processes failed to execute" $ERED
659 __check_stop_at_error
663 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
664 # args: <response-code> <policy-id> [count]
665 # (Function for test scripts)
666 api_delete_policy() {
667 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
668 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
671 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
672 __print_err "<response-code> <policy-id> [count]" $@
679 if [ $# -eq 3 ]; then
685 while [ $count -lt $max ]; do
686 if [ "$PMS_VERSION" == "V2" ]; then
687 query="/v2/policies/"$UUID$pid
689 query="/policy?id="$UUID$pid
691 res="$(__do_curl_to_api PA DELETE $query)"
692 status=${res:${#res}-3}
693 echo -ne " Executing "$count"("$max")${SAMELINE}"
695 if [ $status -ne $1 ]; then
696 echo " Executed "$count"?("$max")"
697 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
699 __check_stop_at_error
704 echo -ne " Executed "$count"("$max")${SAMELINE}"
709 echo -e $GREEN" PASS"$EGREEN
713 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
714 # args: <response-code> <policy-id> [count]
715 # (Function for test scripts)
716 api_delete_policy_batch() {
717 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
718 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
721 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
722 __print_err "<response-code> <policy-id> [count]" $@
729 if [ $# -eq 3 ]; then
735 while [ $count -lt $max ]; do
736 if [ "$PMS_VERSION" == "V2" ]; then
737 query="/v2/policies/"$UUID$pid
739 query="/policy?id="$UUID$pid
741 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
742 status=${res:${#res}-3}
743 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
745 if [ $status -ne 200 ]; then
746 echo " Requested(batch) "$count"?("$max")"
747 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
749 __check_stop_at_error
752 cid=${res:0:${#res}-3}
756 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
764 res="$(__do_curl_to_api PA RESPONSE $cid)"
765 status=${res:${#res}-3}
766 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
768 if [ $status -ne $1 ]; then
769 echo " Deleted(batch) "$count"?("$max")"
770 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
772 __check_stop_at_error
777 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
783 echo -e $GREEN" PASS"$EGREEN
787 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
788 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
789 # (Function for test scripts)
790 api_delete_policy_parallel() {
791 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
792 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
795 if [ $# -ne 5 ]; then
796 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
805 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
806 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
807 echo " Info - will execute over agent REST"
810 if [ "$PMS_VERSION" == "V2" ]; then
811 query="/v2/policies/"
816 urlbase=${ADAPTER}${query}
818 for ((i=1; i<=$pids; i++))
821 if [ -z "$uuid" ]; then
824 echo "" > "./tmp/.pid${i}.del.res.txt"
825 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > "./tmp/.pid${i}.del.txt"
827 done | xargs -n 1 -I{} -P $pids bash -c '{
829 echo " Parallel process $arg started"
830 tmp=$(< "./tmp/.pid${arg}.del.txt")
831 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
834 for ((i=1; i<=$pids; i++))
836 file="./tmp/.pid${i}.del.res.txt"
838 if [ -z "$tmp" ]; then
839 echo " Process $i : unknown result (result file empty"
843 if [ $res == "0" ]; then
844 echo " Process $i : OK - "${tmp:1}
846 echo " Process $i : failed - "${tmp:1}
852 echo " $(($count*$num_rics)) policy request(s) executed"
854 echo -e $GREEN" PASS"$EGREEN
858 echo -e $RED" FAIL. One of more processes failed to execute" $ERED
860 __check_stop_at_error
864 # API Test function: GET /policy_ids and V2 GET /v2/policies
865 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
866 # (Function for test scripts)
867 api_get_policy_ids() {
868 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
869 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
872 if [ $# -lt 4 ]; then
873 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
879 if [ "$PMS_VERSION" == "V2" ]; then
880 if [ $2 != "NORIC" ]; then
881 queryparams="?ric_id="$2
884 if [ $3 != "NOSERVICE" ]; then
885 if [ -z $queryparams ]; then
886 queryparams="?service_id="$3
888 queryparams=$queryparams"&service_id="$3
891 if [ $4 != "NOTYPE" ]; then
892 if [ -z $queryparams ]; then
893 queryparams="?policytype_id="$4
895 queryparams=$queryparams"&policytype_id="$4
899 query="/v2/policies"$queryparams
901 if [ $2 != "NORIC" ]; then
902 queryparams="?ric="$2
905 if [ $3 != "NOSERVICE" ]; then
906 if [ -z $queryparams ]; then
907 queryparams="?service="$3
909 queryparams=$queryparams"&service="$3
912 if [ $4 != "NOTYPE" ]; then
913 if [ -z $queryparams ]; then
914 queryparams="?type="$4
916 queryparams=$queryparams"&type="$4
920 query="/policy_ids"$queryparams
923 res="$(__do_curl_to_api PA GET $query)"
924 status=${res:${#res}-3}
926 if [ $status -ne $1 ]; then
927 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
929 __check_stop_at_error
933 if [ $# -gt 4 ]; then
934 body=${res:0:${#res}-3}
937 for pid in ${@:5} ; do
938 if [ "$targetJson" != "[" ]; then
939 targetJson=$targetJson","
941 if [ $pid != "NOID" ]; then
942 targetJson=$targetJson"\"$UUID$pid\""
946 targetJson=$targetJson"]"
947 if [ "$PMS_VERSION" == "V2" ]; then
948 targetJson="{\"policy_ids\": $targetJson}"
950 echo "TARGET JSON: $targetJson" >> $HTTPLOG
951 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
953 if [ $res -ne 0 ]; then
954 echo -e $RED" FAIL, returned body not correct"$ERED
956 __check_stop_at_error
962 echo -e $GREEN" PASS"$EGREEN
966 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
967 # args(V2): <response-code> <policy-type-id> [<schema-file>]
968 # (Function for test scripts)
969 api_get_policy_type() {
970 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
971 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
974 if [ "$PMS_VERSION" != "V2" ]; then
975 echo -e $RED" FAIL, function not supported"$ERED
977 __check_stop_at_error
981 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
982 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
985 query="/v2/policy-types/$2"
987 res="$(__do_curl_to_api PA GET $query)"
988 status=${res:${#res}-3}
990 if [ $status -ne $1 ]; then
991 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
993 __check_stop_at_error
997 if [ $# -eq 3 ]; then
999 body=${res:0:${#res}-3}
1002 targetJson="{\"policy_schema\":$targetJson}"
1003 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1004 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1006 if [ $res -ne 0 ]; then
1007 echo -e $RED" FAIL, returned body not correct"$ERED
1009 __check_stop_at_error
1015 echo -e $GREEN" PASS"$EGREEN
1019 # API Test function: GET /policy_schema
1020 # args: <response-code> <policy-type-id> [<schema-file>]
1021 # (Function for test scripts)
1022 api_get_policy_schema() {
1023 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1024 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1027 if [ "$PMS_VERSION" == "V2" ]; then
1028 echo -e $RED" FAIL, function not supported"$ERED
1030 __check_stop_at_error
1034 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1035 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1038 query="/policy_schema?id=$2"
1039 res="$(__do_curl_to_api PA GET $query)"
1040 status=${res:${#res}-3}
1042 if [ $status -ne $1 ]; then
1043 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1045 __check_stop_at_error
1049 if [ $# -eq 3 ]; then
1051 body=${res:0:${#res}-3}
1055 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1056 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1058 if [ $res -ne 0 ]; then
1059 echo -e $RED" FAIL, returned body not correct"$ERED
1061 __check_stop_at_error
1067 echo -e $GREEN" PASS"$EGREEN
1071 # API Test function: GET /policy_schemas
1072 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1073 # args(V2): <response-code>
1074 # (Function for test scripts)
1075 api_get_policy_schemas() {
1076 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1077 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1080 if [ "$PMS_VERSION" == "V2" ]; then
1081 if [ $# -ne 1 ]; then
1082 __print_err "<response-code>" $@
1086 if [ $# -lt 2 ]; then
1087 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1091 if [ "$PMS_VERSION" == "V2" ]; then
1092 query="/v2/policy-schemas"
1094 query="/policy_schemas"
1095 if [ $2 != "NORIC" ]; then
1096 query=$query"?ric="$2
1100 res="$(__do_curl_to_api PA GET $query)"
1101 status=${res:${#res}-3}
1103 if [ $status -ne $1 ]; then
1104 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1106 __check_stop_at_error
1110 if [ $# -gt 2 ]; then
1111 body=${res:0:${#res}-3}
1114 for file in ${@:3} ; do
1115 if [ "$targetJson" != "[" ]; then
1116 targetJson=$targetJson","
1118 if [ $file == "NOFILE" ]; then
1119 targetJson=$targetJson"{}"
1121 targetJson=$targetJson$(< $file)
1125 targetJson=$targetJson"]"
1126 if [ "$PMS_VERSION" == "V2" ]; then
1127 targetJson="{\"policy_schemas\": $targetJson }"
1129 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1130 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1132 if [ $res -ne 0 ]; then
1133 echo -e $RED" FAIL, returned body not correct"$ERED
1135 __check_stop_at_error
1141 echo -e $GREEN" PASS"$EGREEN
1145 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1146 # arg: <response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)
1147 # (Function for test scripts)
1148 api_get_policy_status() {
1149 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1150 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1153 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1154 __print_err "<response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1160 if [ $3 == "STD" ]; then
1161 targetJson="{\"enforceStatus\":\"$4\""
1162 if [ $# -eq 5 ]; then
1163 targetJson=$targetJson",\"reason\":\"$5\""
1165 targetJson=$targetJson"}"
1166 elif [ $3 == "OSC" ]; then
1167 targetJson="{\"instance_status\":\"$4\""
1168 if [ $# -eq 5 ]; then
1169 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1171 targetJson=$targetJson",\"created_at\":\"????\"}"
1173 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1177 if [ "$PMS_VERSION" == "V2" ]; then
1178 query="/v2/policies/$UUID$2/status"
1179 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1181 query="/policy_status?id="$UUID$2
1184 res="$(__do_curl_to_api PA GET $query)"
1185 status=${res:${#res}-3}
1187 if [ $status -ne $1 ]; then
1188 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1190 __check_stop_at_error
1194 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1195 body=${res:0:${#res}-3}
1196 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1198 if [ $res -ne 0 ]; then
1199 echo -e $RED" FAIL, returned body not correct"$ERED
1201 __check_stop_at_error
1206 echo -e $GREEN" PASS"$EGREEN
1210 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1211 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1212 # (Function for test scripts)
1213 api_get_policy_types() {
1214 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1215 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1218 if [ $# -lt 1 ]; then
1219 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1223 if [ "$PMS_VERSION" == "V2" ]; then
1224 if [ $# -eq 1 ]; then
1225 query="/v2/policy-types"
1226 elif [ $2 == "NORIC" ]; then
1227 query="/v2/policy-types"
1229 query="/v2/policy-types?ric_id=$2"
1232 if [ $# -eq 1 ]; then
1233 query="/policy_types"
1234 elif [ $2 == "NORIC" ]; then
1235 query="/policy_types"
1237 query="/policy_types?ric=$2"
1241 res="$(__do_curl_to_api PA GET $query)"
1242 status=${res:${#res}-3}
1244 if [ $status -ne $1 ]; then
1245 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1247 __check_stop_at_error
1251 if [ $# -gt 2 ]; then
1252 body=${res:0:${#res}-3}
1255 for pid in ${@:3} ; do
1256 if [ "$targetJson" != "[" ]; then
1257 targetJson=$targetJson","
1259 if [ $pid == "EMPTY" ]; then
1262 targetJson=$targetJson"\"$pid\""
1265 targetJson=$targetJson"]"
1266 if [ "$PMS_VERSION" == "V2" ]; then
1267 targetJson="{\"policytype_ids\": $targetJson }"
1269 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1270 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1272 if [ $res -ne 0 ]; then
1273 echo -e $RED" FAIL, returned body not correct"$ERED
1275 __check_stop_at_error
1281 echo -e $GREEN" PASS"$EGREEN
1285 #########################################################
1286 #### Test case functions Health check
1287 #########################################################
1289 # API Test function: GET /status and V2 GET /status
1290 # args: <response-code>
1291 # (Function for test scripts)
1293 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1294 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1296 if [ $# -ne 1 ]; then
1297 __print_err "<response-code>" $@
1300 if [ "$PMS_VERSION" == "V2" ]; then
1305 res="$(__do_curl_to_api PA GET $query)"
1306 status=${res:${#res}-3}
1308 if [ $status -ne $1 ]; then
1309 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1311 __check_stop_at_error
1316 echo -e $GREEN" PASS"$EGREEN
1320 #########################################################
1321 #### Test case functions RIC Repository
1322 #########################################################
1324 # API Test function: GET /ric and V2 GET /v2/rics/ric
1325 # args: <reponse-code> <management-element-id> [<ric-id>]
1326 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1327 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1328 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1331 # (Function for test scripts)
1333 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1334 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1337 if [ "$PMS_VERSION" == "V2" ]; then
1338 if [ $# -lt 3 ]; then
1339 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1343 if [ $2 != "NOME" ]; then
1344 search="?managed_element_id="$2
1346 if [ $3 != "NORIC" ]; then
1347 if [ -z $search ]; then
1350 search=$search"&ric_id="$3
1353 query="/v2/rics/ric"$search
1355 res="$(__do_curl_to_api PA GET $query)"
1356 status=${res:${#res}-3}
1358 if [ $status -ne $1 ]; then
1359 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1361 __check_stop_at_error
1365 if [ $# -gt 3 ]; then
1366 body=${res:0:${#res}-3}
1367 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1368 if [ $res -ne 0 ]; then
1369 echo -e $RED" FAIL, could not create target ric info json"$ERED
1371 __check_stop_at_error
1375 targetJson=$(<./tmp/.tmp_rics.json)
1376 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1377 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1378 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1379 if [ $res -ne 0 ]; then
1380 echo -e $RED" FAIL, returned body not correct"$ERED
1382 __check_stop_at_error
1387 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1388 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1392 query="/ric?managedElementId="$2
1394 res="$(__do_curl_to_api PA GET $query)"
1395 status=${res:${#res}-3}
1397 if [ $status -ne $1 ]; then
1398 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1400 __check_stop_at_error
1404 if [ $# -eq 3 ]; then
1405 body=${res:0:${#res}-3}
1406 if [ "$body" != "$3" ]; then
1407 echo -e $RED" FAIL, returned body not correct"$ERED
1409 __check_stop_at_error
1415 echo -e $GREEN" PASS"$EGREEN
1419 # API test function: GET /rics and V2 GET /v2/rics
1420 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1421 # 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_........."
1422 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1423 # (Function for test scripts)
1425 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1426 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1429 if [ $# -lt 2 ]; then
1430 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1434 if [ "$PMS_VERSION" == "V2" ]; then
1436 if [ $2 != "NOTYPE" ]; then
1437 query="/v2/rics?policytype_id="$2
1441 if [ $2 != "NOTYPE" ]; then
1442 query="/rics?policyType="$2
1446 res="$(__do_curl_to_api PA GET $query)"
1447 status=${res:${#res}-3}
1449 if [ $status -ne $1 ]; then
1450 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1452 __check_stop_at_error
1456 if [ $# -gt 2 ]; then
1457 body=${res:0:${#res}-3}
1458 if [ "$PMS_VERSION" == "V2" ]; then
1459 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1461 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1463 if [ $res -ne 0 ]; then
1464 echo -e $RED" FAIL, could not create target ric info json"$ERED
1466 __check_stop_at_error
1470 targetJson=$(<./tmp/.tmp_rics.json)
1471 if [ "$PMS_VERSION" == "V2" ]; then
1472 targetJson="{\"rics\": $targetJson }"
1474 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1475 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1476 if [ $res -ne 0 ]; then
1477 echo -e $RED" FAIL, returned body not correct"$ERED
1479 __check_stop_at_error
1485 echo -e $GREEN" PASS"$EGREEN
1489 ##################################################################
1490 #### API Test case functions Service registry and supervision ####
1491 ##################################################################
1493 # API test function: PUT /service and V2 PUT /service
1494 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1495 # (Function for test scripts)
1497 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1498 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1500 if [ $# -ne 4 ]; then
1501 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1505 if [ "$PMS_VERSION" == "V2" ]; then
1506 query="/v2/services"
1507 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1510 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1512 file="./tmp/.tmp.json"
1513 echo "$json" > $file
1515 res="$(__do_curl_to_api PA PUT $query $file)"
1516 status=${res:${#res}-3}
1518 if [ $status -ne $1 ]; then
1519 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1521 __check_stop_at_error
1526 echo -e $GREEN" PASS"$EGREEN
1530 # API test function: GET /services and V2 GET /v2/services
1531 #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>]* )]
1532 # (Function for test scripts)
1533 api_get_services() {
1534 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1535 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1537 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1539 if [ $# -eq 1 ]; then
1541 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1543 elif [ $# -eq 5 ]; then
1545 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1547 if [ $(($argLen%3)) -eq 0 ]; then
1552 if [ $paramError -ne 0 ]; then
1553 __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>]* )]" $@
1557 if [ "$PMS_VERSION" == "V2" ]; then
1558 query="/v2/services"
1560 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1561 query="/v2/services?service_id="$2
1566 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1567 query="/services?name="$2
1570 res="$(__do_curl_to_api PA GET $query)"
1571 status=${res:${#res}-3}
1573 if [ $status -ne $1 ]; then
1574 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1576 __check_stop_at_error
1580 if [ $# -gt 2 ]; then
1581 variableArgCount=$(($#-2))
1582 body=${res:0:${#res}-3}
1586 while [ $cntr -lt $variableArgCount ]; do
1587 servicename=$1; shift;
1590 if [ $cntr -gt 0 ]; then
1591 targetJson=$targetJson","
1593 # timeSinceLastActivitySeconds value cannot be checked since value varies
1594 if [ "$PMS_VERSION" == "V2" ]; then
1595 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1597 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1601 targetJson=$targetJson"]"
1602 if [ "$PMS_VERSION" == "V2" ]; then
1603 targetJson="{\"service_list\": $targetJson }"
1605 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1606 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1607 if [ $res -ne 0 ]; then
1608 echo -e $RED" FAIL, returned body not correct"$ERED
1610 __check_stop_at_error
1616 echo -e $GREEN" PASS"$EGREEN
1620 # API test function: GET /services V2 GET /v2/services - (only checking service names)
1621 # args: <response-code> [<service-name>]*"
1622 # (Function for test scripts)
1623 api_get_service_ids() {
1624 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1625 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1628 if [ $# -lt 1 ]; then
1629 __print_err "<response-code> [<service-name>]*" $@
1633 if [ "$PMS_VERSION" == "V2" ]; then
1634 query="/v2/services"
1638 res="$(__do_curl_to_api PA GET $query)"
1639 status=${res:${#res}-3}
1641 if [ $status -ne $1 ]; then
1642 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1644 __check_stop_at_error
1648 body=${res:0:${#res}-3}
1650 for rapp in ${@:2} ; do
1651 if [ "$targetJson" != "[" ]; then
1652 targetJson=$targetJson","
1654 if [ "$PMS_VERSION" == "V2" ]; then
1655 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
1657 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1661 targetJson=$targetJson"]"
1662 if [ "$PMS_VERSION" == "V2" ]; then
1663 targetJson="{\"service_list\": $targetJson }"
1665 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1666 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1668 if [ $res -ne 0 ]; then
1669 echo -e $RED" FAIL, returned body not correct"$ERED
1671 __check_stop_at_error
1676 echo -e $GREEN" PASS"$EGREEN
1680 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
1681 # args: <response-code> <service-name>
1682 # (Function for test scripts)
1683 api_delete_services() {
1684 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1685 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1688 if [ $# -ne 2 ]; then
1689 __print_err "<response-code> <service-name>" $@
1692 if [ "$PMS_VERSION" == "V2" ]; then
1693 query="/v2/services/"$2
1695 query="/services?name="$2
1697 res="$(__do_curl_to_api PA DELETE $query)"
1698 status=${res:${#res}-3}
1700 if [ $status -ne $1 ]; then
1701 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1703 __check_stop_at_error
1708 echo -e $GREEN" PASS"$EGREEN
1712 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
1713 # args: <response-code> <service-name>
1714 # (Function for test scripts)
1715 api_put_services_keepalive() {
1716 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1717 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1720 if [ $# -ne 2 ]; then
1721 __print_err "<response-code> <service-name>" $@
1724 if [ "$PMS_VERSION" == "V2" ]; then
1725 query="/v2/services/$2/keepalive"
1727 query="/services/keepalive?name="$2
1730 res="$(__do_curl_to_api PA PUT $query)"
1731 status=${res:${#res}-3}
1733 if [ $status -ne $1 ]; then
1734 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1736 __check_stop_at_error
1741 echo -e $GREEN" PASS"$EGREEN