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 # Generic function to query the agent via the REST or DMAAP interface.
25 # Used by all other agent api test functions
26 # REST or DMAAP is controlled of the base url of $ADAPTER
27 # arg: GET|PUT|POST|DELETE <url> [<file>]
28 # (Not for test scripts)
29 __do_curl_to_agent() {
30 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
33 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
39 httpcode=" -sw %{http_code}"
44 content=" -H Content-Type:application/json"
46 if [ $1 == "GET" ]; then
51 elif [ $1 == "PUT" ]; then
54 file=" --data-binary @$3"
56 accept=" -H accept:application/json"
57 elif [ $1 == "POST" ]; then
59 accept=" -H accept:*/*"
63 elif [ $1 == "DELETE" ]; then
73 if [ $paramError -eq 1 ]; then
75 echo "-Incorrect number of parameters to __do_curl_agent " $@ >> $HTTPLOG
76 echo "-Expected: GET|PUT|POST|DELETE <url> [<file>]" >> $HTTPLOG
77 echo "-Returning response 000" >> $HTTPLOG
82 if [ $ADAPTER == $RESTBASE ]; then
85 curlString="curl"${oper}${timeout}${httpcode}${accept}${content}${url}${file}
86 echo " CMD: "$curlString >> $HTTPLOG
88 echo " FILE: $(<$3)" >> $HTTPLOG
91 # Do retry for configured response codes, otherwise only one attempt
93 while [ $maxretries -ge 0 ]; do
95 let maxretries=maxretries-1
98 if [ $retcode -ne 0 ]; then
99 echo " RETCODE: "$retcode >> $HTTPLOG
104 echo " RESP: "$res >> $HTTPLOG
105 status=${res:${#res}-3}
106 if [ ! -z "${AGENT_RETRY_CODES}" ]; then
107 for retrycode in $AGENT_RETRY_CODES; do
108 if [ $retrycode -eq $status ]; then
109 echo -e $RED" Retrying (according to set codes for retry), got status $status....."$ERED >> $HTTPLOG
115 if [ $retry -eq 0 ]; then
123 if [ $1 == "PUT" ] && [ $# -eq 3 ]; then
124 payload="$(cat $3 | tr -d '\n' | tr -d ' ' )"
125 echo "payload: "$payload >> $HTTPLOG
126 file=" --data-binary "$payload
128 #urlencode the request url since it will be carried by send-request url
129 requestUrl=$(python -c "from __future__ import print_function; import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$2")
130 url=" "${ADAPTER}"/send-request?url="${requestUrl}"&operation="${oper}
131 curlString="curl -X POST${timeout}${httpcode}${content}${url}${file}"
132 echo " CMD: "$curlString >> $HTTPLOG
135 if [ $retcode -ne 0 ]; then
136 echo " RETCODE: "$retcode >> $HTTPLOG
140 echo " RESP: "$res >> $HTTPLOG
141 status=${res:${#res}-3}
142 if [ $status -ne 200 ]; then
146 cid=${res:0:${#res}-3}
147 url=" "${ADAPTER}"/receive-response?correlationid="${cid}
148 curlString="curl -X GET"${timeout}${httpcode}${url}
149 echo " CMD: "$curlString >> $HTTPLOG
152 if [ $retcode -ne 0 ]; then
153 echo " RETCODE: "$retcode >> $HTTPLOG
157 echo " RESP: "$res >> $HTTPLOG
158 status=${res:${#res}-3}
160 # wait of the reply from the agent...
161 while [ $status -eq 204 ]; do
162 if [ $(($SECONDS - $TS)) -gt 90 ]; then
163 echo " RETCODE: (timeout after 90s)" >> $HTTPLOG
168 echo " CMD: "$curlString >> $HTTPLOG
170 if [ $retcode -ne 0 ]; then
171 echo " RETCODE: "$retcode >> $HTTPLOG
175 echo " RESP: "$res >> $HTTPLOG
176 status=${res:${#res}-3}
178 if [ $status -eq 200 ]; then
179 body=${res:0:${#res}-3}
183 echo "Status not 200, returning response 000" >> $HTTPLOG
190 #########################################################
191 #### Test case functions A1 Policy management service
192 #########################################################
194 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
195 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
196 # args: json:<url> <target-value> [<timeout-in-seconds]
197 # (Function for test scripts)
199 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
200 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
201 if [[ $1 == "json:"* ]]; then
202 __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/" $1 "=" $2 $3
208 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
212 # API Test function: GET /policies
213 # 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>]*]
214 # (Function for test scripts)
216 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
217 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
220 if [ $# -lt 4 ]; then
222 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
224 elif [ $# -gt 4 ] && [ $(($#%5)) -ne 4 ]; then
228 if [ $paramError -ne 0 ]; then
229 __print_err "<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>]*]" $@
233 if [ $2 != "NORIC" ]; then
234 queryparams="?ric="$2
236 if [ $3 != "NOSERVICE" ]; then
237 if [ -z $queryparams ]; then
238 queryparams="?service="$3
240 queryparams=$queryparams"&service="$3
243 if [ $4 != "NOTYPE" ]; then
244 if [ -z $queryparams ]; then
245 queryparams="?type="$4
247 queryparams=$queryparams"&type="$4
251 query="/policies"$queryparams
252 res="$(__do_curl_to_agent GET $query)"
253 status=${res:${#res}-3}
255 if [ $status -ne $1 ]; then
256 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
261 if [ $# -gt 4 ]; then
262 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
265 body=${res:0:${#res}-3}
269 for ((i=0; i<$(($#-4)); i=i+5)); do
271 if [ "$targetJson" != "[" ]; then
272 targetJson=$targetJson","
274 targetJson=$targetJson"{\"id\":\"${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
275 if [ "${arr[$i+3]}" == "EMPTY" ]; then
276 targetJson=$targetJson"\"\","
278 targetJson=$targetJson"\"${arr[$i+3]}\","
281 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
283 targetJson=$targetJson"\"json\":"$json"}"
287 targetJson=$targetJson"]"
288 echo "TARGET JSON: $targetJson" >> $HTTPLOG
289 res=$(python ../common/compare_json.py "$targetJson" "$body" "id")
291 if [ $res -ne 0 ]; then
292 echo -e $RED" FAIL, returned body not correct"$ERED
299 echo -e $GREEN" PASS"$EGREEN
304 # API Test function: GET /policy
305 #args: <response-code> <policy-id> [<template-file>]
306 # (Function for test scripts)
308 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
309 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
312 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
313 __print_err "<response-code> <policy-id> [<template-file>] " $@
317 query="/policy?id=$2"
318 res="$(__do_curl_to_agent GET $query)"
319 status=${res:${#res}-3}
321 if [ $status -ne $1 ]; then
322 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
327 if [ $# -eq 3 ]; then
328 #Create a policy json to compare with
329 body=${res:0:${#res}-3}
331 sed 's/XXX/'${2}'/g' $3 > $file
332 targetJson=$(< $file)
333 echo "TARGET JSON: $targetJson" >> $HTTPLOG
334 res=$(python ../common/compare_json.py "$targetJson" "$body")
335 if [ $res -ne 0 ]; then
336 echo -e $RED" FAIL, returned body not correct"$ERED
343 echo -e $GREEN" PASS"$EGREEN
347 # API Test function: PUT /policy
348 # args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <template-file> [<count>]
349 # (Function for test scripts)
351 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
352 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
355 if [ $# -lt 6 ] || [ $# -gt 7 ]; then
356 __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <template-file> [<count>]" $@
364 if [ $# -eq 7 ]; then
371 while [ $count -lt $max ]; do
372 query="/policy?id=$pid&ric=$ric&service=$2"
374 if [ $4 == "NOTYPE" ]; then
375 query="/policy?id=$pid&ric=$ric&service=$2"
377 query="/policy?id=$pid&ric=$ric&service=$2&type=$4"
381 sed 's/XXX/'${pid}'/g' $6 > $file
382 res="$(__do_curl_to_agent PUT $query $file)"
383 status=${res:${#res}-3}
384 echo -ne " Creating "$count"("$max")\033[0K\r"
386 if [ $status -ne $1 ]; then
388 echo " Created "$count"?("$max")"
389 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
396 echo -ne " Created "$count"("$max")\033[0K\r"
401 echo -e $GREEN" PASS"$EGREEN
406 # API Test function: DELETE /policy
407 # args: <response-code> <policy-id> [count]
408 # (Function for test scripts)
409 api_delete_policy() {
410 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
411 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
414 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
415 __print_err "<response-code> <policy-id> [count]" $@
422 if [ $# -eq 3 ]; then
428 while [ $count -lt $max ]; do
429 query="/policy?id="$pid
430 res="$(__do_curl_to_agent DELETE $query)"
431 status=${res:${#res}-3}
432 echo -ne " Deleting "$count"("$max")\033[0K\r"
434 if [ $status -ne $1 ]; then
435 echo " Deleted "$count"?("$max")"
436 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
442 echo -ne " Deleted "$count"("$max")\033[0K\r"
447 echo -e $GREEN" PASS"$EGREEN
451 # API Test function: GET /policy_ids
452 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
453 # (Function for test scripts)
454 api_get_policy_ids() {
455 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
456 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
459 if [ $# -lt 4 ]; then
460 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
466 if [ $2 != "NORIC" ]; then
467 queryparams="?ric="$2
470 if [ $3 != "NOSERVICE" ]; then
471 if [ -z $queryparams ]; then
472 queryparams="?service="$3
474 queryparams=$queryparams"&service="$3
477 if [ $4 != "NOTYPE" ]; then
478 if [ -z $queryparams ]; then
479 queryparams="?type="$4
481 queryparams=$queryparams"&type="$4
485 query="/policy_ids"$queryparams
486 res="$(__do_curl_to_agent GET $query)"
487 status=${res:${#res}-3}
489 if [ $status -ne $1 ]; then
490 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
495 if [ $# -gt 4 ]; then
496 body=${res:0:${#res}-3}
499 for pid in ${@:5} ; do
500 if [ "$targetJson" != "[" ]; then
501 targetJson=$targetJson","
503 if [ $pid != "NOID" ]; then
504 targetJson=$targetJson"\"$pid\""
508 targetJson=$targetJson"]"
509 echo "TARGET JSON: $targetJson" >> $HTTPLOG
510 res=$(python ../common/compare_json.py "$targetJson" "$body")
512 if [ $res -ne 0 ]; then
513 echo -e $RED" FAIL, returned body not correct"$ERED
520 echo -e $GREEN" PASS"$EGREEN
524 # API Test function: GET /policy_schema
525 # args: <response-code> <policy-type-id> [<schema-file>]
526 # (Function for test scripts)
527 api_get_policy_schema() {
528 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
529 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
532 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
533 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
537 query="/policy_schema?id=$2"
538 res="$(__do_curl_to_agent GET $query)"
539 status=${res:${#res}-3}
541 if [ $status -ne $1 ]; then
542 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
547 if [ $# -eq 3 ]; then
549 body=${res:0:${#res}-3}
552 echo "TARGET JSON: $targetJson" >> $HTTPLOG
553 res=$(python ../common/compare_json.py "$targetJson" "$body")
555 if [ $res -ne 0 ]; then
556 echo -e $RED" FAIL, returned body not correct"$ERED
563 echo -e $GREEN" PASS"$EGREEN
567 # API Test function: GET /policy_schemas
568 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
569 # (Function for test scripts)
570 api_get_policy_schemas() {
571 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
572 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
575 if [ $# -lt 2 ]; then
576 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
580 query="/policy_schemas"
581 if [ $2 != "NORIC" ]; then
582 query=$query"?ric="$2
585 res="$(__do_curl_to_agent GET $query)"
586 status=${res:${#res}-3}
588 if [ $status -ne $1 ]; then
589 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
594 if [ $# -gt 2 ]; then
595 body=${res:0:${#res}-3}
598 for file in ${@:3} ; do
599 if [ "$targetJson" != "[" ]; then
600 targetJson=$targetJson","
602 if [ $file == "NOFILE" ]; then
603 targetJson=$targetJson"{}"
605 targetJson=$targetJson$(< $3)
609 targetJson=$targetJson"]"
610 echo "TARGET JSON: $targetJson" >> $HTTPLOG
611 res=$(python ../common/compare_json.py "$targetJson" "$body")
613 if [ $res -ne 0 ]; then
614 echo -e $RED" FAIL, returned body not correct"$ERED
621 echo -e $GREEN" PASS"$EGREEN
625 # API Test function: GET /policy_status
626 # arg: <response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)
627 # (Function for test scripts)
628 api_get_policy_status() {
629 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
630 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
632 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
633 __print_err "<response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
639 if [ $3 == "STD" ]; then
640 targetJson="{\"enforceStatus\":\"$4\""
641 if [ $# -eq 5 ]; then
642 targetJson=$targetJson",\"reason\":\"$5\""
644 targetJson=$targetJson"}"
645 elif [ $3 == "OSC" ]; then
646 targetJson="{\"instance_status\":\"$4\""
647 if [ $# -eq 5 ]; then
648 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
650 targetJson=$targetJson",\"created_at\":\"????\"}"
652 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
656 query="/policy_status?id="$2
658 res="$(__do_curl_to_agent GET $query)"
659 status=${res:${#res}-3}
661 if [ $status -ne $1 ]; then
662 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
667 echo "TARGET JSON: $targetJson" >> $HTTPLOG
668 body=${res:0:${#res}-3}
669 res=$(python ../common/compare_json.py "$targetJson" "$body")
671 if [ $res -ne 0 ]; then
672 echo -e $RED" FAIL, returned body not correct"$ERED
678 echo -e $GREEN" PASS"$EGREEN
682 # API Test function: GET /policy_types
683 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
684 # (Function for test scripts)
685 api_get_policy_types() {
686 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
687 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
690 if [ $# -lt 1 ]; then
691 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
695 if [ $# -eq 1 ]; then
696 query="/policy_types"
697 elif [ $2 == "NORIC" ]; then
698 query="/policy_types"
700 query="/policy_types?ric=$2"
703 res="$(__do_curl_to_agent GET $query)"
704 status=${res:${#res}-3}
706 if [ $status -ne $1 ]; then
707 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
712 if [ $# -gt 2 ]; then
713 body=${res:0:${#res}-3}
716 for pid in ${@:3} ; do
717 if [ "$targetJson" != "[" ]; then
718 targetJson=$targetJson","
720 if [ $pid == "EMPTY" ]; then
723 targetJson=$targetJson"\"$pid\""
726 targetJson=$targetJson"]"
727 echo "TARGET JSON: $targetJson" >> $HTTPLOG
728 res=$(python ../common/compare_json.py "$targetJson" "$body")
730 if [ $res -ne 0 ]; then
731 echo -e $RED" FAIL, returned body not correct"$ERED
738 echo -e $GREEN" PASS"$EGREEN
742 #########################################################
743 #### Test case functions Health check
744 #########################################################
746 # API Test function: GET /status
747 # args: <response-code>
748 # (Function for test scripts)
750 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
751 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
753 if [ $# -ne 1 ]; then
754 __print_err "<response-code>" $@
758 res="$(__do_curl_to_agent GET $query)"
759 status=${res:${#res}-3}
761 if [ $status -ne $1 ]; then
762 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
768 echo -e $GREEN" PASS"$EGREEN
772 #########################################################
773 #### Test case functions RIC Repository
774 #########################################################
776 # API Test function: GET /ric
777 # args: <reponse-code> <management-element-id> [<ric-id>]
778 # (Function for test scripts)
780 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
781 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
783 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
784 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
788 query="/ric?managedElementId="$2
790 res="$(__do_curl_to_agent GET $query)"
791 status=${res:${#res}-3}
793 if [ $status -ne $1 ]; then
794 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
799 if [ $# -eq 3 ]; then
800 body=${res:0:${#res}-3}
801 if [ "$body" != "$3" ]; then
802 echo -e $RED" FAIL, returned body not correct"$ERED
809 echo -e $GREEN" PASS"$EGREEN
813 # API test function: GET /rics
814 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
815 # 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_........."
816 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
817 # (Function for test scripts)
819 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
820 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
823 if [ $# -lt 2 ]; then
824 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
829 if [ $2 != "NOTYPE" ]; then
830 query="/rics?policyType="$2
833 res="$(__do_curl_to_agent GET $query)"
834 status=${res:${#res}-3}
836 if [ $status -ne $1 ]; then
837 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
842 if [ $# -gt 2 ]; then
843 body=${res:0:${#res}-3}
844 res=$(python ../common/create_rics_json.py ".tmp_rics.json" "$3" )
845 if [ $res -ne 0 ]; then
846 echo -e $RED" FAIL, could not create target ric info json"$ERED
851 targetJson=$(<.tmp_rics.json)
852 echo "TARGET JSON: $targetJson" >> $HTTPLOG
853 res=$(python ../common/compare_json.py "$targetJson" "$body")
854 if [ $res -ne 0 ]; then
855 echo -e $RED" FAIL, returned body not correct"$ERED
862 echo -e $GREEN" PASS"$EGREEN
866 ##################################################################
867 #### API Test case functions Service registry and supervision ####
868 ##################################################################
870 # API test function: PUT /service
871 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
872 # (Function for test scripts)
874 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
875 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
877 if [ $# -ne 4 ]; then
878 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
883 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
887 res="$(__do_curl_to_agent PUT $query $file)"
888 status=${res:${#res}-3}
890 if [ $status -ne $1 ]; then
891 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
897 echo -e $GREEN" PASS"$EGREEN
901 # API test function: GET /services
902 #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>]* )]
903 # (Function for test scripts)
905 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
906 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
909 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
911 if [ $# -eq 1 ]; then
913 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
915 elif [ $# -eq 5 ]; then
917 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
919 if [ $(($argLen%3)) -eq 0 ]; then
924 if [ $paramError -ne 0 ]; then
925 __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>]* )]" $@
931 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
932 query="/services?name="$2
935 res="$(__do_curl_to_agent GET $query)"
936 status=${res:${#res}-3}
938 if [ $status -ne $1 ]; then
939 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
944 if [ $# -gt 2 ]; then
945 variableArgCount=$(($#-2))
946 body=${res:0:${#res}-3}
950 while [ $cntr -lt $variableArgCount ]; do
951 servicename=$1; shift;
954 if [ $cntr -gt 0 ]; then
955 targetJson=$targetJson","
957 # timeSinceLastActivitySeconds value cannot be checked since value varies
958 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
961 targetJson=$targetJson"]"
962 echo "TARGET JSON: $targetJson" >> $HTTPLOG
963 res=$(python ../common/compare_json.py "$targetJson" "$body" "serviceName")
964 if [ $res -ne 0 ]; then
965 echo -e $RED" FAIL, returned body not correct"$ERED
972 echo -e $GREEN" PASS"$EGREEN
976 # API test function: GET /services (only checking service names)
977 # args: <response-code> [<service-name>]*"
978 # (Function for test scripts)
979 api_get_service_ids() {
980 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
981 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
984 if [ $# -lt 1 ]; then
985 __print_err "<response-code> [<service-name>]*" $@
990 res="$(__do_curl_to_agent GET $query)"
991 status=${res:${#res}-3}
993 if [ $status -ne $1 ]; then
994 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
999 body=${res:0:${#res}-3}
1001 for rapp in ${@:2} ; do
1002 if [ "$targetJson" != "[" ]; then
1003 targetJson=$targetJson","
1005 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1008 targetJson=$targetJson"]"
1009 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1010 res=$(python ../common/compare_json.py "$targetJson" "$body" "serviceName")
1012 if [ $res -ne 0 ]; then
1013 echo -e $RED" FAIL, returned body not correct"$ERED
1019 echo -e $GREEN" PASS"$EGREEN
1023 # API test function: DELETE /services
1024 # args: <response-code> <service-name>
1025 # (Function for test scripts)
1026 api_delete_services() {
1027 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1028 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1031 if [ $# -ne 2 ]; then
1032 __print_err "<response-code> <service-name>" $@
1036 query="/services?name="$2
1037 res="$(__do_curl_to_agent DELETE $query)"
1038 status=${res:${#res}-3}
1040 if [ $status -ne $1 ]; then
1041 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1047 echo -e $GREEN" PASS"$EGREEN
1051 # API test function: PUT /services/keepalive
1052 # args: <response-code> <service-name>
1053 # (Function for test scripts)
1054 api_put_services_keepalive() {
1055 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1056 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1059 if [ $# -ne 2 ]; then
1060 __print_err "<response-code> <service-name>" $@
1064 query="/services/keepalive?name="$2
1065 res="$(__do_curl_to_agent PUT $query)"
1066 status=${res:${#res}-3}
1068 if [ $status -ne $1 ]; then
1069 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1075 echo -e $GREEN" PASS"$EGREEN