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> <transient> <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 7 ] || [ $# -gt 8 ]; then
381 __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]" $@
389 if [ $# -eq 8 ]; then
396 while [ $count -lt $max ]; do
397 query="/policy?id=$pid&ric=$ric&service=$2"
399 if [ $4 != "NOTYPE" ]; then
400 query=$query"&type=$4"
403 if [ $6 != NOTRANSIENT ]; then
404 query=$query"&transient=$6"
408 sed 's/XXX/'${pid}'/g' $7 > $file
409 res="$(__do_curl_to_agent PUT $query $file)"
410 status=${res:${#res}-3}
411 echo -ne " Creating "$count"("$max")${SAMELINE}"
412 if [ $status -ne $1 ]; then
414 echo " Created "$count"?("$max")"
415 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
422 echo -ne " Created "$count"("$max")${SAMELINE}"
427 echo -e $GREEN" PASS"$EGREEN
431 # API Test function: PUT /policy to run in batch
432 # args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]
433 # (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 [ $# -lt 7 ] || [ $# -gt 8 ]; then
440 __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]" $@
448 if [ $# -eq 8 ]; then
455 while [ $count -lt $max ]; do
456 query="/policy?id=$pid&ric=$ric&service=$2"
458 if [ $4 != "NOTYPE" ]; then
459 query=$query"&type=$4"
462 if [ $6 != NOTRANSIENT ]; then
463 query=$query"&transient=$6"
467 sed 's/XXX/'${pid}'/g' $7 > $file
468 res="$(__do_curl_to_agent PUT_BATCH $query $file)"
469 status=${res:${#res}-3}
470 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
472 if [ $status -ne 200 ]; then
474 echo " Requested(batch) "$count"?("$max")"
475 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
479 cid=${res:0:${#res}-3}
483 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
490 res="$(__do_curl_to_agent RESPONSE $cid)"
491 status=${res:${#res}-3}
492 echo -ne " Created(batch) "$count"("$max")${SAMELINE}"
494 if [ $status -ne $1 ]; then
496 echo " Created(batch) "$count"?("$max")"
497 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
503 echo -ne " Created(batch) "$count"("$max")${SAMELINE}"
509 echo -e $GREEN" PASS"$EGREEN
513 # API Test function: PUT /policy to run in i parallel for a number of rics
514 # 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>
515 # (Function for test scripts)
516 api_put_policy_parallel() {
517 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
518 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
521 if [ $# -ne 10 ]; then
522 __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>" $@
536 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
537 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
538 echo " Info - will execute over agent REST"
541 if [ $serv == "NOSERVICE" ]; then
544 query="/policy?service=$serv"
546 if [ $type != "NOTYPE" ]; then
547 query=$query"&type=$type"
550 if [ $transient != NOTRANSIENT ]; then
551 query=$query"&transient=$transient"
554 urlbase=${ADAPTER}${query}
556 for ((i=1; i<=$pids; i++))
558 echo "" > ".pid${i}.res.txt"
559 echo $resp_code $urlbase $ric_base $num_rics $start_id $template $count $pids $i > ".pid${i}.txt"
561 done | xargs -n 1 -I{} -P $pids bash -c '{
563 echo " Parallel process $arg started"
564 tmp=$(< ".pid${arg}.txt")
565 python3 ../common/create_policies_process.py $tmp > .pid${arg}.res.txt
568 for ((i=1; i<=$pids; i++))
570 file=".pid${i}.res.txt"
572 if [ -z "$tmp" ]; then
573 echo " Process $i : unknown result (result file empty"
577 if [ $res == "0" ]; then
578 echo " Process $i : OK"
580 echo " Process $i : failed - "${tmp:1}
586 echo " $(($count*$num_rics)) policies created/updated"
588 echo -e $GREEN" PASS"$EGREEN
592 echo -e $RED" FAIL. One of more processes failed to execute" $ERED
597 # API Test function: DELETE /policy
598 # args: <response-code> <policy-id> [count]
599 # (Function for test scripts)
600 api_delete_policy() {
601 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
602 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
605 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
606 __print_err "<response-code> <policy-id> [count]" $@
613 if [ $# -eq 3 ]; then
619 while [ $count -lt $max ]; do
620 query="/policy?id="$pid
621 res="$(__do_curl_to_agent DELETE $query)"
622 status=${res:${#res}-3}
623 echo -ne " Deleting "$count"("$max")${SAMELINE}"
625 if [ $status -ne $1 ]; then
626 echo " Deleted "$count"?("$max")"
627 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
633 echo -ne " Deleted "$count"("$max")${SAMELINE}"
638 echo -e $GREEN" PASS"$EGREEN
642 # API Test function: DELETE /policy to run in batch
643 # args: <response-code> <policy-id> [count]
644 # (Function for test scripts)
645 api_delete_policy_batch() {
646 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
647 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
650 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
651 __print_err "<response-code> <policy-id> [count]" $@
658 if [ $# -eq 3 ]; then
664 while [ $count -lt $max ]; do
665 query="/policy?id="$pid
666 res="$(__do_curl_to_agent DELETE_BATCH $query)"
667 status=${res:${#res}-3}
668 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
670 if [ $status -ne 200 ]; then
672 echo " Requested(batch) "$count"?("$max")"
673 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
677 cid=${res:0:${#res}-3}
681 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
689 res="$(__do_curl_to_agent RESPONSE $cid)"
690 status=${res:${#res}-3}
691 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
693 if [ $status -ne $1 ]; then
695 echo " Deleted(batch) "$count"?("$max")"
696 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
702 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
706 echo -e $GREEN" PASS"$EGREEN
710 # API Test function: DELETE /policy to run in i parallel for a number of rics
711 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
712 # (Function for test scripts)
713 api_delete_policy_parallel() {
714 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
715 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
718 if [ $# -ne 5 ]; then
719 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
728 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
729 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
730 echo " Info - will execute over agent REST"
735 urlbase=${ADAPTER}${query}
737 for ((i=1; i<=$pids; i++))
739 echo "" > ".pid${i}.del.res.txt"
740 echo $resp_code $urlbase $num_rics $start_id $count $pids $i > ".pid${i}.del.txt"
742 done | xargs -n 1 -I{} -P $pids bash -c '{
744 echo " Parallel process $arg started"
745 tmp=$(< ".pid${arg}.del.txt")
746 python3 ../common/delete_policies_process.py $tmp > .pid${arg}.del.res.txt
749 for ((i=1; i<=$pids; i++))
751 file=".pid${i}.del.res.txt"
753 if [ -z "$tmp" ]; then
754 echo " Process $i : unknown result (result file empty"
758 if [ $res == "0" ]; then
759 echo " Process $i : OK"
761 echo " Process $i : failed - "${tmp:1}
767 echo " $(($count*$num_rics)) deleted"
769 echo -e $GREEN" PASS"$EGREEN
773 echo -e $RED" FAIL. One of more processes failed to execute" $ERED
778 # API Test function: GET /policy_ids
779 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
780 # (Function for test scripts)
781 api_get_policy_ids() {
782 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
783 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
786 if [ $# -lt 4 ]; then
787 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
793 if [ $2 != "NORIC" ]; then
794 queryparams="?ric="$2
797 if [ $3 != "NOSERVICE" ]; then
798 if [ -z $queryparams ]; then
799 queryparams="?service="$3
801 queryparams=$queryparams"&service="$3
804 if [ $4 != "NOTYPE" ]; then
805 if [ -z $queryparams ]; then
806 queryparams="?type="$4
808 queryparams=$queryparams"&type="$4
812 query="/policy_ids"$queryparams
813 res="$(__do_curl_to_agent GET $query)"
814 status=${res:${#res}-3}
816 if [ $status -ne $1 ]; then
817 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
822 if [ $# -gt 4 ]; then
823 body=${res:0:${#res}-3}
826 for pid in ${@:5} ; do
827 if [ "$targetJson" != "[" ]; then
828 targetJson=$targetJson","
830 if [ $pid != "NOID" ]; then
831 targetJson=$targetJson"\"$pid\""
835 targetJson=$targetJson"]"
836 echo "TARGET JSON: $targetJson" >> $HTTPLOG
837 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
839 if [ $res -ne 0 ]; then
840 echo -e $RED" FAIL, returned body not correct"$ERED
847 echo -e $GREEN" PASS"$EGREEN
851 # API Test function: GET /policy_schema
852 # args: <response-code> <policy-type-id> [<schema-file>]
853 # (Function for test scripts)
854 api_get_policy_schema() {
855 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
856 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
859 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
860 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
864 query="/policy_schema?id=$2"
865 res="$(__do_curl_to_agent GET $query)"
866 status=${res:${#res}-3}
868 if [ $status -ne $1 ]; then
869 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
874 if [ $# -eq 3 ]; then
876 body=${res:0:${#res}-3}
879 echo "TARGET JSON: $targetJson" >> $HTTPLOG
880 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
882 if [ $res -ne 0 ]; then
883 echo -e $RED" FAIL, returned body not correct"$ERED
890 echo -e $GREEN" PASS"$EGREEN
894 # API Test function: GET /policy_schemas
895 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
896 # (Function for test scripts)
897 api_get_policy_schemas() {
898 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
899 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
902 if [ $# -lt 2 ]; then
903 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
907 query="/policy_schemas"
908 if [ $2 != "NORIC" ]; then
909 query=$query"?ric="$2
912 res="$(__do_curl_to_agent GET $query)"
913 status=${res:${#res}-3}
915 if [ $status -ne $1 ]; then
916 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
921 if [ $# -gt 2 ]; then
922 body=${res:0:${#res}-3}
925 for file in ${@:3} ; do
926 if [ "$targetJson" != "[" ]; then
927 targetJson=$targetJson","
929 if [ $file == "NOFILE" ]; then
930 targetJson=$targetJson"{}"
932 targetJson=$targetJson$(< $file)
936 targetJson=$targetJson"]"
937 echo "TARGET JSON: $targetJson" >> $HTTPLOG
938 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
940 if [ $res -ne 0 ]; then
941 echo -e $RED" FAIL, returned body not correct"$ERED
948 echo -e $GREEN" PASS"$EGREEN
952 # API Test function: GET /policy_status
953 # arg: <response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)
954 # (Function for test scripts)
955 api_get_policy_status() {
956 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
957 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
959 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
960 __print_err "<response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
966 if [ $3 == "STD" ]; then
967 targetJson="{\"enforceStatus\":\"$4\""
968 if [ $# -eq 5 ]; then
969 targetJson=$targetJson",\"reason\":\"$5\""
971 targetJson=$targetJson"}"
972 elif [ $3 == "OSC" ]; then
973 targetJson="{\"instance_status\":\"$4\""
974 if [ $# -eq 5 ]; then
975 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
977 targetJson=$targetJson",\"created_at\":\"????\"}"
979 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
983 query="/policy_status?id="$2
985 res="$(__do_curl_to_agent GET $query)"
986 status=${res:${#res}-3}
988 if [ $status -ne $1 ]; then
989 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
994 echo "TARGET JSON: $targetJson" >> $HTTPLOG
995 body=${res:0:${#res}-3}
996 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
998 if [ $res -ne 0 ]; then
999 echo -e $RED" FAIL, returned body not correct"$ERED
1005 echo -e $GREEN" PASS"$EGREEN
1009 # API Test function: GET /policy_types
1010 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1011 # (Function for test scripts)
1012 api_get_policy_types() {
1013 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1014 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1017 if [ $# -lt 1 ]; then
1018 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1022 if [ $# -eq 1 ]; then
1023 query="/policy_types"
1024 elif [ $2 == "NORIC" ]; then
1025 query="/policy_types"
1027 query="/policy_types?ric=$2"
1030 res="$(__do_curl_to_agent GET $query)"
1031 status=${res:${#res}-3}
1033 if [ $status -ne $1 ]; then
1034 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1039 if [ $# -gt 2 ]; then
1040 body=${res:0:${#res}-3}
1043 for pid in ${@:3} ; do
1044 if [ "$targetJson" != "[" ]; then
1045 targetJson=$targetJson","
1047 if [ $pid == "EMPTY" ]; then
1050 targetJson=$targetJson"\"$pid\""
1053 targetJson=$targetJson"]"
1054 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1055 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1057 if [ $res -ne 0 ]; then
1058 echo -e $RED" FAIL, returned body not correct"$ERED
1065 echo -e $GREEN" PASS"$EGREEN
1069 #########################################################
1070 #### Test case functions Health check
1071 #########################################################
1073 # API Test function: GET /status
1074 # args: <response-code>
1075 # (Function for test scripts)
1077 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1078 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1080 if [ $# -ne 1 ]; then
1081 __print_err "<response-code>" $@
1085 res="$(__do_curl_to_agent GET $query)"
1086 status=${res:${#res}-3}
1088 if [ $status -ne $1 ]; then
1089 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1095 echo -e $GREEN" PASS"$EGREEN
1099 #########################################################
1100 #### Test case functions RIC Repository
1101 #########################################################
1103 # API Test function: GET /ric
1104 # args: <reponse-code> <management-element-id> [<ric-id>]
1105 # (Function for test scripts)
1107 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1108 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1110 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1111 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1115 query="/ric?managedElementId="$2
1117 res="$(__do_curl_to_agent GET $query)"
1118 status=${res:${#res}-3}
1120 if [ $status -ne $1 ]; then
1121 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1126 if [ $# -eq 3 ]; then
1127 body=${res:0:${#res}-3}
1128 if [ "$body" != "$3" ]; then
1129 echo -e $RED" FAIL, returned body not correct"$ERED
1136 echo -e $GREEN" PASS"$EGREEN
1140 # API test function: GET /rics
1141 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1142 # 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_........."
1143 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1144 # (Function for test scripts)
1146 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1147 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1150 if [ $# -lt 2 ]; then
1151 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1156 if [ $2 != "NOTYPE" ]; then
1157 query="/rics?policyType="$2
1160 res="$(__do_curl_to_agent GET $query)"
1161 status=${res:${#res}-3}
1163 if [ $status -ne $1 ]; then
1164 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1169 if [ $# -gt 2 ]; then
1170 body=${res:0:${#res}-3}
1171 res=$(python3 ../common/create_rics_json.py ".tmp_rics.json" "$3" )
1172 if [ $res -ne 0 ]; then
1173 echo -e $RED" FAIL, could not create target ric info json"$ERED
1178 targetJson=$(<.tmp_rics.json)
1179 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1180 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1181 if [ $res -ne 0 ]; then
1182 echo -e $RED" FAIL, returned body not correct"$ERED
1189 echo -e $GREEN" PASS"$EGREEN
1193 ##################################################################
1194 #### API Test case functions Service registry and supervision ####
1195 ##################################################################
1197 # API test function: PUT /service
1198 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1199 # (Function for test scripts)
1201 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1202 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1204 if [ $# -ne 4 ]; then
1205 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1210 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1212 echo "$json" > $file
1214 res="$(__do_curl_to_agent PUT $query $file)"
1215 status=${res:${#res}-3}
1217 if [ $status -ne $1 ]; then
1218 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1224 echo -e $GREEN" PASS"$EGREEN
1228 # API test function: GET /services
1229 #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>]* )]
1230 # (Function for test scripts)
1231 api_get_services() {
1232 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1233 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1235 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1237 if [ $# -eq 1 ]; then
1239 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1241 elif [ $# -eq 5 ]; then
1243 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1245 if [ $(($argLen%3)) -eq 0 ]; then
1250 if [ $paramError -ne 0 ]; then
1251 __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>]* )]" $@
1257 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1258 query="/services?name="$2
1261 res="$(__do_curl_to_agent GET $query)"
1262 status=${res:${#res}-3}
1264 if [ $status -ne $1 ]; then
1265 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1270 if [ $# -gt 2 ]; then
1271 variableArgCount=$(($#-2))
1272 body=${res:0:${#res}-3}
1276 while [ $cntr -lt $variableArgCount ]; do
1277 servicename=$1; shift;
1280 if [ $cntr -gt 0 ]; then
1281 targetJson=$targetJson","
1283 # timeSinceLastActivitySeconds value cannot be checked since value varies
1284 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1287 targetJson=$targetJson"]"
1288 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1289 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1290 if [ $res -ne 0 ]; then
1291 echo -e $RED" FAIL, returned body not correct"$ERED
1298 echo -e $GREEN" PASS"$EGREEN
1302 # API test function: GET /services (only checking service names)
1303 # args: <response-code> [<service-name>]*"
1304 # (Function for test scripts)
1305 api_get_service_ids() {
1306 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1307 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1310 if [ $# -lt 1 ]; then
1311 __print_err "<response-code> [<service-name>]*" $@
1316 res="$(__do_curl_to_agent GET $query)"
1317 status=${res:${#res}-3}
1319 if [ $status -ne $1 ]; then
1320 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1325 body=${res:0:${#res}-3}
1327 for rapp in ${@:2} ; do
1328 if [ "$targetJson" != "[" ]; then
1329 targetJson=$targetJson","
1331 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1334 targetJson=$targetJson"]"
1335 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1336 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1338 if [ $res -ne 0 ]; then
1339 echo -e $RED" FAIL, returned body not correct"$ERED
1345 echo -e $GREEN" PASS"$EGREEN
1349 # API test function: DELETE /services
1350 # args: <response-code> <service-name>
1351 # (Function for test scripts)
1352 api_delete_services() {
1353 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1354 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1357 if [ $# -ne 2 ]; then
1358 __print_err "<response-code> <service-name>" $@
1362 query="/services?name="$2
1363 res="$(__do_curl_to_agent DELETE $query)"
1364 status=${res:${#res}-3}
1366 if [ $status -ne $1 ]; then
1367 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1373 echo -e $GREEN" PASS"$EGREEN
1377 # API test function: PUT /services/keepalive
1378 # args: <response-code> <service-name>
1379 # (Function for test scripts)
1380 api_put_services_keepalive() {
1381 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1382 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1385 if [ $# -ne 2 ]; then
1386 __print_err "<response-code> <service-name>" $@
1390 query="/services/keepalive?name="$2
1391 res="$(__do_curl_to_agent PUT $query)"
1392 status=${res:${#res}-3}
1394 if [ $status -ne $1 ]; then
1395 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1401 echo -e $GREEN" PASS"$EGREEN