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 # If operation prefix is '_BATCH' the the send and get response is split in two sequences,
27 # one for sending the requests and one for receiving the response
28 # but only when using the DMAAP interface
29 # REST or DMAAP is controlled of the base url of $ADAPTER
30 # arg: (GET|PUT|POST|DELETE|GET_BATCH|PUT_BATCH|POST_BATCH|DELETE_BATCH <url> [<file>]) | (RESPONSE <correlation-id>)
31 # (Not for test scripts)
32 __do_curl_to_agent() {
33 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
36 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
42 httpcode=" -sw %{http_code}"
46 if [[ $1 == *"_BATCH" ]]; then
50 content=" -H Content-Type:application/json"
52 if [ $1 == "GET" ] || [ $1 == "GET_BATCH" ]; then
57 elif [ $1 == "PUT" ] || [ $1 == "PUT_BATCH" ]; then
60 file=" --data-binary @$3"
62 accept=" -H accept:application/json"
63 elif [ $1 == "POST" ] || [ $1 == "POST_BATCH" ]; then
65 accept=" -H accept:*/*"
69 elif [ $1 == "DELETE" ] || [ $1 == "DELETE_BATCH" ]; then
74 elif [ $1 == "RESPONSE" ]; then
79 if ! [ $ADAPTER == $DMAAPBASE ]; then
87 if [ $paramError -eq 1 ]; then
89 echo "-Incorrect number of parameters to __do_curl_agent " $@ >> $HTTPLOG
90 echo "-Expected: (GET|PUT|POST|DELETE|GET_BATCH|PUT_BATCH|POST_BATCH|DELETE_BATCH <url> [<file>]) | (RESPONSE <correlation-id>) [<file>]" >> $HTTPLOG
91 echo "-Returning response 000" >> $HTTPLOG
96 if [ $ADAPTER == $RESTBASE ] || [ $ADAPTER == $RESTBASE_SECURE ]; then
99 curlString="curl -k "${oper}${timeout}${httpcode}${accept}${content}${url}${file}
100 echo " CMD: "$curlString >> $HTTPLOG
101 if [ $# -eq 3 ]; then
102 echo " FILE: $(<$3)" >> $HTTPLOG
105 # Do retry for configured response codes, otherwise only one attempt
107 while [ $maxretries -ge 0 ]; do
109 let maxretries=maxretries-1
112 if [ $retcode -ne 0 ]; then
113 echo " RETCODE: "$retcode >> $HTTPLOG
118 echo " RESP: "$res >> $HTTPLOG
119 status=${res:${#res}-3}
120 if [ ! -z "${AGENT_RETRY_CODES}" ]; then
121 for retrycode in $AGENT_RETRY_CODES; do
122 if [ $retrycode -eq $status ]; then
123 echo -e $RED" Retrying (according to set codes for retry), got status $status....."$ERED >> $HTTPLOG
129 if [ $retry -eq 0 ]; then
136 if [ $oper != "RESPONSE" ]; then
138 if [ $1 == "PUT" ] && [ $# -eq 3 ]; then
139 payload="$(cat $3 | tr -d '\n' | tr -d ' ' )"
140 echo "payload: "$payload >> $HTTPLOG
141 file=" --data-binary "$payload
143 #urlencode the request url since it will be carried by send-request url
144 requestUrl=$(python3 -c "from __future__ import print_function; import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$2")
145 url=" "${ADAPTER}"/send-request?url="${requestUrl}"&operation="${oper}
146 curlString="curl -X POST${timeout}${httpcode}${content}${url}${file}"
147 echo " CMD: "$curlString >> $HTTPLOG
150 if [ $retcode -ne 0 ]; then
151 echo " RETCODE: "$retcode >> $HTTPLOG
155 echo " RESP: "$res >> $HTTPLOG
156 status=${res:${#res}-3}
157 if [ $status -ne 200 ]; then
161 cid=${res:0:${#res}-3}
162 if [[ $batch -eq 1 ]]; then
167 if [ $oper == "RESPONSE" ] || [ $batch -eq 0 ]; then
168 if [ $oper == "RESPONSE" ]; then
171 url=" "${ADAPTER}"/receive-response?correlationid="${cid}
172 curlString="curl -X GET"${timeout}${httpcode}${url}
173 echo " CMD: "$curlString >> $HTTPLOG
176 if [ $retcode -ne 0 ]; then
177 echo " RETCODE: "$retcode >> $HTTPLOG
181 echo " RESP: "$res >> $HTTPLOG
182 status=${res:${#res}-3}
184 # wait of the reply from the agent...
185 while [ $status -eq 204 ]; do
186 if [ $(($SECONDS - $TS)) -gt 90 ]; then
187 echo " RETCODE: (timeout after 90s)" >> $HTTPLOG
192 echo " CMD: "$curlString >> $HTTPLOG
194 if [ $retcode -ne 0 ]; then
195 echo " RETCODE: "$retcode >> $HTTPLOG
199 echo " RESP: "$res >> $HTTPLOG
200 status=${res:${#res}-3}
202 if [ $status -eq 200 ]; then
203 body=${res:0:${#res}-3}
207 echo "Status not 200, returning response 000" >> $HTTPLOG
215 #########################################################
216 #### Test case functions A1 Policy management service
217 #########################################################
219 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
220 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
221 # args: json:<url> <target-value> [<timeout-in-seconds]
222 # (Function for test scripts)
224 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
225 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
226 if [[ $1 == "json:"* ]]; then
227 __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/" $1 "=" $2 $3
233 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
237 # API Test function: GET /policies
238 # 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>]*]
239 # (Function for test scripts)
241 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
242 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
245 if [ $# -lt 4 ]; then
247 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
249 elif [ $# -gt 4 ] && [ $(($#%5)) -ne 4 ]; then
253 if [ $paramError -ne 0 ]; then
254 __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>]*]" $@
258 if [ $2 != "NORIC" ]; then
259 queryparams="?ric="$2
261 if [ $3 != "NOSERVICE" ]; then
262 if [ -z $queryparams ]; then
263 queryparams="?service="$3
265 queryparams=$queryparams"&service="$3
268 if [ $4 != "NOTYPE" ]; then
269 if [ -z $queryparams ]; then
270 queryparams="?type="$4
272 queryparams=$queryparams"&type="$4
276 query="/policies"$queryparams
277 res="$(__do_curl_to_agent GET $query)"
278 status=${res:${#res}-3}
280 if [ $status -ne $1 ]; then
281 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
286 if [ $# -gt 4 ]; then
287 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
290 body=${res:0:${#res}-3}
294 for ((i=0; i<$(($#-4)); i=i+5)); do
296 if [ "$targetJson" != "[" ]; then
297 targetJson=$targetJson","
299 targetJson=$targetJson"{\"id\":\"${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
300 if [ "${arr[$i+3]}" == "EMPTY" ]; then
301 targetJson=$targetJson"\"\","
303 targetJson=$targetJson"\"${arr[$i+3]}\","
306 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
308 targetJson=$targetJson"\"json\":"$json"}"
312 targetJson=$targetJson"]"
313 echo "TARGET JSON: $targetJson" >> $HTTPLOG
314 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
316 if [ $res -ne 0 ]; then
317 echo -e $RED" FAIL, returned body not correct"$ERED
324 echo -e $GREEN" PASS"$EGREEN
329 # API Test function: GET /policy
330 #args: <response-code> <policy-id> [<template-file>]
331 # (Function for test scripts)
333 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
334 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
337 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
338 __print_err "<response-code> <policy-id> [<template-file>] " $@
342 query="/policy?id=$2"
343 res="$(__do_curl_to_agent GET $query)"
344 status=${res:${#res}-3}
346 if [ $status -ne $1 ]; then
347 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
352 if [ $# -eq 3 ]; then
353 #Create a policy json to compare with
354 body=${res:0:${#res}-3}
356 sed 's/XXX/'${2}'/g' $3 > $file
357 targetJson=$(< $file)
358 echo "TARGET JSON: $targetJson" >> $HTTPLOG
359 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
360 if [ $res -ne 0 ]; then
361 echo -e $RED" FAIL, returned body not correct"$ERED
368 echo -e $GREEN" PASS"$EGREEN
372 # API Test function: PUT /policy
373 # args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <template-file> [<count>]
374 # (Function for test scripts)
376 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
377 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
380 if [ $# -lt 6 ] || [ $# -gt 7 ]; then
381 __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <template-file> [<count>]" $@
389 if [ $# -eq 7 ]; then
396 while [ $count -lt $max ]; do
397 query="/policy?id=$pid&ric=$ric&service=$2"
399 if [ $4 == "NOTYPE" ]; then
400 query="/policy?id=$pid&ric=$ric&service=$2"
402 query="/policy?id=$pid&ric=$ric&service=$2&type=$4"
406 sed 's/XXX/'${pid}'/g' $6 > $file
407 res="$(__do_curl_to_agent PUT $query $file)"
408 status=${res:${#res}-3}
409 echo -ne " Creating "$count"("$max")${SAMELINE}"
411 if [ $status -ne $1 ]; then
413 echo " Created "$count"?("$max")"
414 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
421 echo -ne " Created "$count"("$max")${SAMELINE}"
426 echo -e $GREEN" PASS"$EGREEN
430 # API Test function: PUT /policy to run in batch
431 # args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <template-file> [<count>]
432 # (Function for test scripts)
433 api_put_policy_batch() {
434 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
435 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
438 if [ $# -lt 6 ] || [ $# -gt 7 ]; then
439 __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <template-file> [<count>]" $@
447 if [ $# -eq 7 ]; then
454 while [ $count -lt $max ]; do
455 query="/policy?id=$pid&ric=$ric&service=$2"
457 if [ $4 == "NOTYPE" ]; then
458 query="/policy?id=$pid&ric=$ric&service=$2"
460 query="/policy?id=$pid&ric=$ric&service=$2&type=$4"
464 sed 's/XXX/'${pid}'/g' $6 > $file
465 res="$(__do_curl_to_agent PUT_BATCH $query $file)"
466 status=${res:${#res}-3}
467 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
469 if [ $status -ne 200 ]; then
471 echo " Requested(batch) "$count"?("$max")"
472 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
476 cid=${res:0:${#res}-3}
480 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
487 res="$(__do_curl_to_agent RESPONSE $cid)"
488 status=${res:${#res}-3}
489 echo -ne " Created(batch) "$count"("$max")${SAMELINE}"
491 if [ $status -ne $1 ]; then
493 echo " Created(batch) "$count"?("$max")"
494 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
500 echo -ne " Created(batch) "$count"("$max")${SAMELINE}"
506 echo -e $GREEN" PASS"$EGREEN
511 # API Test function: DELETE /policy
512 # args: <response-code> <policy-id> [count]
513 # (Function for test scripts)
514 api_delete_policy() {
515 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
516 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
519 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
520 __print_err "<response-code> <policy-id> [count]" $@
527 if [ $# -eq 3 ]; then
533 while [ $count -lt $max ]; do
534 query="/policy?id="$pid
535 res="$(__do_curl_to_agent DELETE $query)"
536 status=${res:${#res}-3}
537 echo -ne " Deleting "$count"("$max")${SAMELINE}"
539 if [ $status -ne $1 ]; then
540 echo " Deleted "$count"?("$max")"
541 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
547 echo -ne " Deleted "$count"("$max")${SAMELINE}"
552 echo -e $GREEN" PASS"$EGREEN
556 # API Test function: DELETE /policy to run in batch
557 # args: <response-code> <policy-id> [count]
558 # (Function for test scripts)
559 api_delete_policy_batch() {
560 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
561 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
564 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
565 __print_err "<response-code> <policy-id> [count]" $@
572 if [ $# -eq 3 ]; then
578 while [ $count -lt $max ]; do
579 query="/policy?id="$pid
580 res="$(__do_curl_to_agent DELETE_BATCH $query)"
581 status=${res:${#res}-3}
582 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
584 if [ $status -ne 200 ]; then
586 echo " Requested(batch) "$count"?("$max")"
587 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
591 cid=${res:0:${#res}-3}
595 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
603 res="$(__do_curl_to_agent RESPONSE $cid)"
604 status=${res:${#res}-3}
605 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
607 if [ $status -ne $1 ]; then
609 echo " Deleted(batch) "$count"?("$max")"
610 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
616 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
620 echo -e $GREEN" PASS"$EGREEN
624 # API Test function: GET /policy_ids
625 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
626 # (Function for test scripts)
627 api_get_policy_ids() {
628 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
629 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
632 if [ $# -lt 4 ]; then
633 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
639 if [ $2 != "NORIC" ]; then
640 queryparams="?ric="$2
643 if [ $3 != "NOSERVICE" ]; then
644 if [ -z $queryparams ]; then
645 queryparams="?service="$3
647 queryparams=$queryparams"&service="$3
650 if [ $4 != "NOTYPE" ]; then
651 if [ -z $queryparams ]; then
652 queryparams="?type="$4
654 queryparams=$queryparams"&type="$4
658 query="/policy_ids"$queryparams
659 res="$(__do_curl_to_agent GET $query)"
660 status=${res:${#res}-3}
662 if [ $status -ne $1 ]; then
663 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
668 if [ $# -gt 4 ]; then
669 body=${res:0:${#res}-3}
672 for pid in ${@:5} ; do
673 if [ "$targetJson" != "[" ]; then
674 targetJson=$targetJson","
676 if [ $pid != "NOID" ]; then
677 targetJson=$targetJson"\"$pid\""
681 targetJson=$targetJson"]"
682 echo "TARGET JSON: $targetJson" >> $HTTPLOG
683 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
685 if [ $res -ne 0 ]; then
686 echo -e $RED" FAIL, returned body not correct"$ERED
693 echo -e $GREEN" PASS"$EGREEN
697 # API Test function: GET /policy_schema
698 # args: <response-code> <policy-type-id> [<schema-file>]
699 # (Function for test scripts)
700 api_get_policy_schema() {
701 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
702 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
705 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
706 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
710 query="/policy_schema?id=$2"
711 res="$(__do_curl_to_agent GET $query)"
712 status=${res:${#res}-3}
714 if [ $status -ne $1 ]; then
715 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
720 if [ $# -eq 3 ]; then
722 body=${res:0:${#res}-3}
725 echo "TARGET JSON: $targetJson" >> $HTTPLOG
726 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
728 if [ $res -ne 0 ]; then
729 echo -e $RED" FAIL, returned body not correct"$ERED
736 echo -e $GREEN" PASS"$EGREEN
740 # API Test function: GET /policy_schemas
741 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
742 # (Function for test scripts)
743 api_get_policy_schemas() {
744 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
745 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
748 if [ $# -lt 2 ]; then
749 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
753 query="/policy_schemas"
754 if [ $2 != "NORIC" ]; then
755 query=$query"?ric="$2
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
767 if [ $# -gt 2 ]; then
768 body=${res:0:${#res}-3}
771 for file in ${@:3} ; do
772 if [ "$targetJson" != "[" ]; then
773 targetJson=$targetJson","
775 if [ $file == "NOFILE" ]; then
776 targetJson=$targetJson"{}"
778 targetJson=$targetJson$(< $file)
782 targetJson=$targetJson"]"
783 echo "TARGET JSON: $targetJson" >> $HTTPLOG
784 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
786 if [ $res -ne 0 ]; then
787 echo -e $RED" FAIL, returned body not correct"$ERED
794 echo -e $GREEN" PASS"$EGREEN
798 # API Test function: GET /policy_status
799 # arg: <response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)
800 # (Function for test scripts)
801 api_get_policy_status() {
802 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
803 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
805 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
806 __print_err "<response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
812 if [ $3 == "STD" ]; then
813 targetJson="{\"enforceStatus\":\"$4\""
814 if [ $# -eq 5 ]; then
815 targetJson=$targetJson",\"reason\":\"$5\""
817 targetJson=$targetJson"}"
818 elif [ $3 == "OSC" ]; then
819 targetJson="{\"instance_status\":\"$4\""
820 if [ $# -eq 5 ]; then
821 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
823 targetJson=$targetJson",\"created_at\":\"????\"}"
825 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
829 query="/policy_status?id="$2
831 res="$(__do_curl_to_agent GET $query)"
832 status=${res:${#res}-3}
834 if [ $status -ne $1 ]; then
835 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
840 echo "TARGET JSON: $targetJson" >> $HTTPLOG
841 body=${res:0:${#res}-3}
842 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
844 if [ $res -ne 0 ]; then
845 echo -e $RED" FAIL, returned body not correct"$ERED
851 echo -e $GREEN" PASS"$EGREEN
855 # API Test function: GET /policy_types
856 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
857 # (Function for test scripts)
858 api_get_policy_types() {
859 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
860 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
863 if [ $# -lt 1 ]; then
864 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
868 if [ $# -eq 1 ]; then
869 query="/policy_types"
870 elif [ $2 == "NORIC" ]; then
871 query="/policy_types"
873 query="/policy_types?ric=$2"
876 res="$(__do_curl_to_agent GET $query)"
877 status=${res:${#res}-3}
879 if [ $status -ne $1 ]; then
880 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
885 if [ $# -gt 2 ]; then
886 body=${res:0:${#res}-3}
889 for pid in ${@:3} ; do
890 if [ "$targetJson" != "[" ]; then
891 targetJson=$targetJson","
893 if [ $pid == "EMPTY" ]; then
896 targetJson=$targetJson"\"$pid\""
899 targetJson=$targetJson"]"
900 echo "TARGET JSON: $targetJson" >> $HTTPLOG
901 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
903 if [ $res -ne 0 ]; then
904 echo -e $RED" FAIL, returned body not correct"$ERED
911 echo -e $GREEN" PASS"$EGREEN
915 #########################################################
916 #### Test case functions Health check
917 #########################################################
919 # API Test function: GET /status
920 # args: <response-code>
921 # (Function for test scripts)
923 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
924 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
926 if [ $# -ne 1 ]; then
927 __print_err "<response-code>" $@
931 res="$(__do_curl_to_agent GET $query)"
932 status=${res:${#res}-3}
934 if [ $status -ne $1 ]; then
935 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
941 echo -e $GREEN" PASS"$EGREEN
945 #########################################################
946 #### Test case functions RIC Repository
947 #########################################################
949 # API Test function: GET /ric
950 # args: <reponse-code> <management-element-id> [<ric-id>]
951 # (Function for test scripts)
953 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
954 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
956 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
957 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
961 query="/ric?managedElementId="$2
963 res="$(__do_curl_to_agent GET $query)"
964 status=${res:${#res}-3}
966 if [ $status -ne $1 ]; then
967 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
972 if [ $# -eq 3 ]; then
973 body=${res:0:${#res}-3}
974 if [ "$body" != "$3" ]; then
975 echo -e $RED" FAIL, returned body not correct"$ERED
982 echo -e $GREEN" PASS"$EGREEN
986 # API test function: GET /rics
987 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
988 # 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_........."
989 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
990 # (Function for test scripts)
992 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
993 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
996 if [ $# -lt 2 ]; then
997 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1002 if [ $2 != "NOTYPE" ]; then
1003 query="/rics?policyType="$2
1006 res="$(__do_curl_to_agent GET $query)"
1007 status=${res:${#res}-3}
1009 if [ $status -ne $1 ]; then
1010 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1015 if [ $# -gt 2 ]; then
1016 body=${res:0:${#res}-3}
1017 res=$(python3 ../common/create_rics_json.py ".tmp_rics.json" "$3" )
1018 if [ $res -ne 0 ]; then
1019 echo -e $RED" FAIL, could not create target ric info json"$ERED
1024 targetJson=$(<.tmp_rics.json)
1025 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1026 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1027 if [ $res -ne 0 ]; then
1028 echo -e $RED" FAIL, returned body not correct"$ERED
1035 echo -e $GREEN" PASS"$EGREEN
1039 ##################################################################
1040 #### API Test case functions Service registry and supervision ####
1041 ##################################################################
1043 # API test function: PUT /service
1044 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1045 # (Function for test scripts)
1047 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1048 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1050 if [ $# -ne 4 ]; then
1051 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1056 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1058 echo "$json" > $file
1060 res="$(__do_curl_to_agent PUT $query $file)"
1061 status=${res:${#res}-3}
1063 if [ $status -ne $1 ]; then
1064 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1070 echo -e $GREEN" PASS"$EGREEN
1074 # API test function: GET /services
1075 #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>]* )]
1076 # (Function for test scripts)
1077 api_get_services() {
1078 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1079 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1081 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1083 if [ $# -eq 1 ]; then
1085 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1087 elif [ $# -eq 5 ]; then
1089 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1091 if [ $(($argLen%3)) -eq 0 ]; then
1096 if [ $paramError -ne 0 ]; then
1097 __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>]* )]" $@
1103 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1104 query="/services?name="$2
1107 res="$(__do_curl_to_agent GET $query)"
1108 status=${res:${#res}-3}
1110 if [ $status -ne $1 ]; then
1111 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1116 if [ $# -gt 2 ]; then
1117 variableArgCount=$(($#-2))
1118 body=${res:0:${#res}-3}
1122 while [ $cntr -lt $variableArgCount ]; do
1123 servicename=$1; shift;
1126 if [ $cntr -gt 0 ]; then
1127 targetJson=$targetJson","
1129 # timeSinceLastActivitySeconds value cannot be checked since value varies
1130 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1133 targetJson=$targetJson"]"
1134 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1135 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1136 if [ $res -ne 0 ]; then
1137 echo -e $RED" FAIL, returned body not correct"$ERED
1144 echo -e $GREEN" PASS"$EGREEN
1148 # API test function: GET /services (only checking service names)
1149 # args: <response-code> [<service-name>]*"
1150 # (Function for test scripts)
1151 api_get_service_ids() {
1152 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1153 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1156 if [ $# -lt 1 ]; then
1157 __print_err "<response-code> [<service-name>]*" $@
1162 res="$(__do_curl_to_agent GET $query)"
1163 status=${res:${#res}-3}
1165 if [ $status -ne $1 ]; then
1166 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
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
1191 echo -e $GREEN" PASS"$EGREEN
1195 # API test function: DELETE /services
1196 # args: <response-code> <service-name>
1197 # (Function for test scripts)
1198 api_delete_services() {
1199 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1200 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1203 if [ $# -ne 2 ]; then
1204 __print_err "<response-code> <service-name>" $@
1208 query="/services?name="$2
1209 res="$(__do_curl_to_agent DELETE $query)"
1210 status=${res:${#res}-3}
1212 if [ $status -ne $1 ]; then
1213 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1219 echo -e $GREEN" PASS"$EGREEN
1223 # API test function: PUT /services/keepalive
1224 # args: <response-code> <service-name>
1225 # (Function for test scripts)
1226 api_put_services_keepalive() {
1227 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1228 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1231 if [ $# -ne 2 ]; then
1232 __print_err "<response-code> <service-name>" $@
1236 query="/services/keepalive?name="$2
1237 res="$(__do_curl_to_agent PUT $query)"
1238 status=${res:${#res}-3}
1240 if [ $status -ne $1 ]; then
1241 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1247 echo -e $GREEN" PASS"$EGREEN