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-type-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
283 __check_stop_at_error
287 if [ $# -gt 4 ]; then
288 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
291 body=${res:0:${#res}-3}
295 for ((i=0; i<$(($#-4)); i=i+5)); do
297 if [ "$targetJson" != "[" ]; then
298 targetJson=$targetJson","
300 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
301 if [ "${arr[$i+3]}" == "EMPTY" ]; then
302 targetJson=$targetJson"\"\","
304 targetJson=$targetJson"\"${arr[$i+3]}\","
307 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
309 targetJson=$targetJson"\"json\":"$json"}"
313 targetJson=$targetJson"]"
314 echo "TARGET JSON: $targetJson" >> $HTTPLOG
315 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
317 if [ $res -ne 0 ]; then
318 echo -e $RED" FAIL, returned body not correct"$ERED
320 __check_stop_at_error
326 echo -e $GREEN" PASS"$EGREEN
331 # API Test function: GET /policy
332 #args: <response-code> <policy-id> [<template-file>]
333 # (Function for test scripts)
335 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
336 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
339 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
340 __print_err "<response-code> <policy-id> [<template-file>] " $@
344 query="/policy?id=$UUID$2"
345 res="$(__do_curl_to_agent GET $query)"
346 status=${res:${#res}-3}
348 if [ $status -ne $1 ]; then
349 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
351 __check_stop_at_error
355 if [ $# -eq 3 ]; then
356 #Create a policy json to compare with
357 body=${res:0:${#res}-3}
359 sed 's/XXX/'${2}'/g' $3 > $file
360 targetJson=$(< $file)
361 echo "TARGET JSON: $targetJson" >> $HTTPLOG
362 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
363 if [ $res -ne 0 ]; then
364 echo -e $RED" FAIL, returned body not correct"$ERED
366 __check_stop_at_error
372 echo -e $GREEN" PASS"$EGREEN
376 # API Test function: PUT /policy
377 # args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]
378 # (Function for test scripts)
380 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
381 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
384 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
385 __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
393 if [ $# -eq 8 ]; then
400 while [ $count -lt $max ]; do
401 query="/policy?id=$UUID$pid&ric=$ric&service=$2"
403 if [ $4 != "NOTYPE" ]; then
404 query=$query"&type=$4"
407 if [ $6 != NOTRANSIENT ]; then
408 query=$query"&transient=$6"
412 sed 's/XXX/'${pid}'/g' $7 > $file
413 res="$(__do_curl_to_agent PUT $query $file)"
414 status=${res:${#res}-3}
415 echo -ne " Creating "$count"("$max")${SAMELINE}"
416 if [ $status -ne $1 ]; then
417 echo " Created "$count"?("$max")"
418 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
420 __check_stop_at_error
426 echo -ne " Created "$count"("$max")${SAMELINE}"
431 echo -e $GREEN" PASS"$EGREEN
435 # API Test function: PUT /policy to run in batch
436 # args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]
437 # (Function for test scripts)
438 api_put_policy_batch() {
439 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
440 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
443 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
444 __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]" $@
452 if [ $# -eq 8 ]; then
459 while [ $count -lt $max ]; do
460 query="/policy?id=$UUID$pid&ric=$ric&service=$2"
462 if [ $4 != "NOTYPE" ]; then
463 query=$query"&type=$4"
466 if [ $6 != NOTRANSIENT ]; then
467 query=$query"&transient=$6"
471 sed 's/XXX/'${pid}'/g' $7 > $file
472 res="$(__do_curl_to_agent PUT_BATCH $query $file)"
473 status=${res:${#res}-3}
474 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
476 if [ $status -ne 200 ]; then
477 echo " Requested(batch) "$count"?("$max")"
478 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
480 __check_stop_at_error
483 cid=${res:0:${#res}-3}
487 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
494 res="$(__do_curl_to_agent RESPONSE $cid)"
495 status=${res:${#res}-3}
496 echo -ne " Created(batch) "$count"("$max")${SAMELINE}"
498 if [ $status -ne $1 ]; then
499 echo " Created(batch) "$count"?("$max")"
500 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
502 __check_stop_at_error
507 echo -ne " Created(batch) "$count"("$max")${SAMELINE}"
513 echo -e $GREEN" PASS"$EGREEN
517 # API Test function: PUT /policy to run in i parallel for a number of rics
518 # 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>
519 # (Function for test scripts)
520 api_put_policy_parallel() {
521 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
522 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
525 if [ $# -ne 10 ]; then
526 __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>" $@
540 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
541 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
542 echo " Info - will execute over agent REST"
545 if [ $serv == "NOSERVICE" ]; then
548 query="/policy?service=$serv"
550 if [ $type != "NOTYPE" ]; then
551 query=$query"&type=$type"
554 if [ $transient != NOTRANSIENT ]; then
555 query=$query"&transient=$transient"
558 urlbase=${ADAPTER}${query}
560 for ((i=1; i<=$pids; i++))
563 if [ -z "$uuid" ]; then
566 echo "" > ".pid${i}.res.txt"
567 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > ".pid${i}.txt"
569 done | xargs -n 1 -I{} -P $pids bash -c '{
571 echo " Parallel process $arg started"
572 tmp=$(< ".pid${arg}.txt")
573 python3 ../common/create_policies_process.py $tmp > .pid${arg}.res.txt
576 for ((i=1; i<=$pids; i++))
578 file=".pid${i}.res.txt"
580 if [ -z "$tmp" ]; then
581 echo " Process $i : unknown result (result file empty"
585 if [ $res == "0" ]; then
586 echo " Process $i : OK"
588 echo " Process $i : failed - "${tmp:1}
594 echo " $(($count*$num_rics)) policies created/updated"
596 echo -e $GREEN" PASS"$EGREEN
600 echo -e $RED" FAIL. One of more processes failed to execute" $ERED
602 __check_stop_at_error
606 # API Test function: DELETE /policy
607 # args: <response-code> <policy-id> [count]
608 # (Function for test scripts)
609 api_delete_policy() {
610 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
611 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
614 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
615 __print_err "<response-code> <policy-id> [count]" $@
622 if [ $# -eq 3 ]; then
628 while [ $count -lt $max ]; do
629 query="/policy?id="$UUID$pid
630 res="$(__do_curl_to_agent DELETE $query)"
631 status=${res:${#res}-3}
632 echo -ne " Deleting "$count"("$max")${SAMELINE}"
634 if [ $status -ne $1 ]; then
635 echo " Deleted "$count"?("$max")"
636 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
638 __check_stop_at_error
643 echo -ne " Deleted "$count"("$max")${SAMELINE}"
648 echo -e $GREEN" PASS"$EGREEN
652 # API Test function: DELETE /policy to run in batch
653 # args: <response-code> <policy-id> [count]
654 # (Function for test scripts)
655 api_delete_policy_batch() {
656 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
657 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
660 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
661 __print_err "<response-code> <policy-id> [count]" $@
668 if [ $# -eq 3 ]; then
674 while [ $count -lt $max ]; do
675 query="/policy?id="$UUID$pid
676 res="$(__do_curl_to_agent DELETE_BATCH $query)"
677 status=${res:${#res}-3}
678 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
680 if [ $status -ne 200 ]; then
681 echo " Requested(batch) "$count"?("$max")"
682 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
684 __check_stop_at_error
687 cid=${res:0:${#res}-3}
691 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
699 res="$(__do_curl_to_agent RESPONSE $cid)"
700 status=${res:${#res}-3}
701 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
703 if [ $status -ne $1 ]; then
704 echo " Deleted(batch) "$count"?("$max")"
705 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
707 __check_stop_at_error
712 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
716 echo -e $GREEN" PASS"$EGREEN
720 # API Test function: DELETE /policy to run in i parallel for a number of rics
721 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
722 # (Function for test scripts)
723 api_delete_policy_parallel() {
724 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
725 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
728 if [ $# -ne 5 ]; then
729 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
738 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
739 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
740 echo " Info - will execute over agent REST"
745 urlbase=${ADAPTER}${query}
747 for ((i=1; i<=$pids; i++))
750 if [ -z "$uuid" ]; then
753 echo "" > ".pid${i}.del.res.txt"
754 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > ".pid${i}.del.txt"
756 done | xargs -n 1 -I{} -P $pids bash -c '{
758 echo " Parallel process $arg started"
759 tmp=$(< ".pid${arg}.del.txt")
760 python3 ../common/delete_policies_process.py $tmp > .pid${arg}.del.res.txt
763 for ((i=1; i<=$pids; i++))
765 file=".pid${i}.del.res.txt"
767 if [ -z "$tmp" ]; then
768 echo " Process $i : unknown result (result file empty"
772 if [ $res == "0" ]; then
773 echo " Process $i : OK"
775 echo " Process $i : failed - "${tmp:1}
781 echo " $(($count*$num_rics)) deleted"
783 echo -e $GREEN" PASS"$EGREEN
787 echo -e $RED" FAIL. One of more processes failed to execute" $ERED
789 __check_stop_at_error
793 # API Test function: GET /policy_ids
794 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
795 # (Function for test scripts)
796 api_get_policy_ids() {
797 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
798 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
801 if [ $# -lt 4 ]; then
802 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
808 if [ $2 != "NORIC" ]; then
809 queryparams="?ric="$2
812 if [ $3 != "NOSERVICE" ]; then
813 if [ -z $queryparams ]; then
814 queryparams="?service="$3
816 queryparams=$queryparams"&service="$3
819 if [ $4 != "NOTYPE" ]; then
820 if [ -z $queryparams ]; then
821 queryparams="?type="$4
823 queryparams=$queryparams"&type="$4
827 query="/policy_ids"$queryparams
828 res="$(__do_curl_to_agent GET $query)"
829 status=${res:${#res}-3}
831 if [ $status -ne $1 ]; then
832 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
834 __check_stop_at_error
838 if [ $# -gt 4 ]; then
839 body=${res:0:${#res}-3}
842 for pid in ${@:5} ; do
843 if [ "$targetJson" != "[" ]; then
844 targetJson=$targetJson","
846 if [ $pid != "NOID" ]; then
847 targetJson=$targetJson"\"$UUID$pid\""
851 targetJson=$targetJson"]"
852 echo "TARGET JSON: $targetJson" >> $HTTPLOG
853 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
855 if [ $res -ne 0 ]; then
856 echo -e $RED" FAIL, returned body not correct"$ERED
858 __check_stop_at_error
864 echo -e $GREEN" PASS"$EGREEN
868 # API Test function: GET /policy_schema
869 # args: <response-code> <policy-type-id> [<schema-file>]
870 # (Function for test scripts)
871 api_get_policy_schema() {
872 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
873 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
876 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
877 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
881 query="/policy_schema?id=$2"
882 res="$(__do_curl_to_agent GET $query)"
883 status=${res:${#res}-3}
885 if [ $status -ne $1 ]; then
886 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
888 __check_stop_at_error
892 if [ $# -eq 3 ]; then
894 body=${res:0:${#res}-3}
897 echo "TARGET JSON: $targetJson" >> $HTTPLOG
898 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
900 if [ $res -ne 0 ]; then
901 echo -e $RED" FAIL, returned body not correct"$ERED
903 __check_stop_at_error
909 echo -e $GREEN" PASS"$EGREEN
913 # API Test function: GET /policy_schemas
914 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
915 # (Function for test scripts)
916 api_get_policy_schemas() {
917 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
918 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
921 if [ $# -lt 2 ]; then
922 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
926 query="/policy_schemas"
927 if [ $2 != "NORIC" ]; then
928 query=$query"?ric="$2
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
937 __check_stop_at_error
941 if [ $# -gt 2 ]; then
942 body=${res:0:${#res}-3}
945 for file in ${@:3} ; do
946 if [ "$targetJson" != "[" ]; then
947 targetJson=$targetJson","
949 if [ $file == "NOFILE" ]; then
950 targetJson=$targetJson"{}"
952 targetJson=$targetJson$(< $file)
956 targetJson=$targetJson"]"
957 echo "TARGET JSON: $targetJson" >> $HTTPLOG
958 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
960 if [ $res -ne 0 ]; then
961 echo -e $RED" FAIL, returned body not correct"$ERED
963 __check_stop_at_error
969 echo -e $GREEN" PASS"$EGREEN
973 # API Test function: GET /policy_status
974 # arg: <response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)
975 # (Function for test scripts)
976 api_get_policy_status() {
977 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
978 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
980 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
981 __print_err "<response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
987 if [ $3 == "STD" ]; then
988 targetJson="{\"enforceStatus\":\"$4\""
989 if [ $# -eq 5 ]; then
990 targetJson=$targetJson",\"reason\":\"$5\""
992 targetJson=$targetJson"}"
993 elif [ $3 == "OSC" ]; then
994 targetJson="{\"instance_status\":\"$4\""
995 if [ $# -eq 5 ]; then
996 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
998 targetJson=$targetJson",\"created_at\":\"????\"}"
1000 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1004 query="/policy_status?id="$UUID$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
1012 __check_stop_at_error
1016 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1017 body=${res:0:${#res}-3}
1018 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1020 if [ $res -ne 0 ]; then
1021 echo -e $RED" FAIL, returned body not correct"$ERED
1023 __check_stop_at_error
1028 echo -e $GREEN" PASS"$EGREEN
1032 # API Test function: GET /policy_types
1033 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1034 # (Function for test scripts)
1035 api_get_policy_types() {
1036 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1037 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1040 if [ $# -lt 1 ]; then
1041 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1045 if [ $# -eq 1 ]; then
1046 query="/policy_types"
1047 elif [ $2 == "NORIC" ]; then
1048 query="/policy_types"
1050 query="/policy_types?ric=$2"
1053 res="$(__do_curl_to_agent GET $query)"
1054 status=${res:${#res}-3}
1056 if [ $status -ne $1 ]; then
1057 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1059 __check_stop_at_error
1063 if [ $# -gt 2 ]; then
1064 body=${res:0:${#res}-3}
1067 for pid in ${@:3} ; do
1068 if [ "$targetJson" != "[" ]; then
1069 targetJson=$targetJson","
1071 if [ $pid == "EMPTY" ]; then
1074 targetJson=$targetJson"\"$pid\""
1077 targetJson=$targetJson"]"
1078 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1079 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1081 if [ $res -ne 0 ]; then
1082 echo -e $RED" FAIL, returned body not correct"$ERED
1084 __check_stop_at_error
1090 echo -e $GREEN" PASS"$EGREEN
1094 #########################################################
1095 #### Test case functions Health check
1096 #########################################################
1098 # API Test function: GET /status
1099 # args: <response-code>
1100 # (Function for test scripts)
1102 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1103 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1105 if [ $# -ne 1 ]; then
1106 __print_err "<response-code>" $@
1110 res="$(__do_curl_to_agent GET $query)"
1111 status=${res:${#res}-3}
1113 if [ $status -ne $1 ]; then
1114 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1116 __check_stop_at_error
1121 echo -e $GREEN" PASS"$EGREEN
1125 #########################################################
1126 #### Test case functions RIC Repository
1127 #########################################################
1129 # API Test function: GET /ric
1130 # args: <reponse-code> <management-element-id> [<ric-id>]
1131 # (Function for test scripts)
1133 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1134 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1136 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1137 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1141 query="/ric?managedElementId="$2
1143 res="$(__do_curl_to_agent GET $query)"
1144 status=${res:${#res}-3}
1146 if [ $status -ne $1 ]; then
1147 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1149 __check_stop_at_error
1153 if [ $# -eq 3 ]; then
1154 body=${res:0:${#res}-3}
1155 if [ "$body" != "$3" ]; then
1156 echo -e $RED" FAIL, returned body not correct"$ERED
1158 __check_stop_at_error
1164 echo -e $GREEN" PASS"$EGREEN
1168 # API test function: GET /rics
1169 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1170 # 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_........."
1171 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1172 # (Function for test scripts)
1174 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1175 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1178 if [ $# -lt 2 ]; then
1179 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1184 if [ $2 != "NOTYPE" ]; then
1185 query="/rics?policyType="$2
1188 res="$(__do_curl_to_agent GET $query)"
1189 status=${res:${#res}-3}
1191 if [ $status -ne $1 ]; then
1192 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1194 __check_stop_at_error
1198 if [ $# -gt 2 ]; then
1199 body=${res:0:${#res}-3}
1200 res=$(python3 ../common/create_rics_json.py ".tmp_rics.json" "$3" )
1201 if [ $res -ne 0 ]; then
1202 echo -e $RED" FAIL, could not create target ric info json"$ERED
1204 __check_stop_at_error
1208 targetJson=$(<.tmp_rics.json)
1209 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1210 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1211 if [ $res -ne 0 ]; then
1212 echo -e $RED" FAIL, returned body not correct"$ERED
1214 __check_stop_at_error
1220 echo -e $GREEN" PASS"$EGREEN
1224 ##################################################################
1225 #### API Test case functions Service registry and supervision ####
1226 ##################################################################
1228 # API test function: PUT /service
1229 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1230 # (Function for test scripts)
1232 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1233 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1235 if [ $# -ne 4 ]; then
1236 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1241 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1243 echo "$json" > $file
1245 res="$(__do_curl_to_agent PUT $query $file)"
1246 status=${res:${#res}-3}
1248 if [ $status -ne $1 ]; then
1249 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1251 __check_stop_at_error
1256 echo -e $GREEN" PASS"$EGREEN
1260 # API test function: GET /services
1261 #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>]* )]
1262 # (Function for test scripts)
1263 api_get_services() {
1264 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1265 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1267 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1269 if [ $# -eq 1 ]; then
1271 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1273 elif [ $# -eq 5 ]; then
1275 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1277 if [ $(($argLen%3)) -eq 0 ]; then
1282 if [ $paramError -ne 0 ]; then
1283 __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>]* )]" $@
1289 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1290 query="/services?name="$2
1293 res="$(__do_curl_to_agent GET $query)"
1294 status=${res:${#res}-3}
1296 if [ $status -ne $1 ]; then
1297 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1299 __check_stop_at_error
1303 if [ $# -gt 2 ]; then
1304 variableArgCount=$(($#-2))
1305 body=${res:0:${#res}-3}
1309 while [ $cntr -lt $variableArgCount ]; do
1310 servicename=$1; shift;
1313 if [ $cntr -gt 0 ]; then
1314 targetJson=$targetJson","
1316 # timeSinceLastActivitySeconds value cannot be checked since value varies
1317 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1320 targetJson=$targetJson"]"
1321 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1322 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1323 if [ $res -ne 0 ]; then
1324 echo -e $RED" FAIL, returned body not correct"$ERED
1326 __check_stop_at_error
1332 echo -e $GREEN" PASS"$EGREEN
1336 # API test function: GET /services (only checking service names)
1337 # args: <response-code> [<service-name>]*"
1338 # (Function for test scripts)
1339 api_get_service_ids() {
1340 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1341 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1344 if [ $# -lt 1 ]; then
1345 __print_err "<response-code> [<service-name>]*" $@
1350 res="$(__do_curl_to_agent GET $query)"
1351 status=${res:${#res}-3}
1353 if [ $status -ne $1 ]; then
1354 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1356 __check_stop_at_error
1360 body=${res:0:${#res}-3}
1362 for rapp in ${@:2} ; do
1363 if [ "$targetJson" != "[" ]; then
1364 targetJson=$targetJson","
1366 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1369 targetJson=$targetJson"]"
1370 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1371 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1373 if [ $res -ne 0 ]; then
1374 echo -e $RED" FAIL, returned body not correct"$ERED
1376 __check_stop_at_error
1381 echo -e $GREEN" PASS"$EGREEN
1385 # API test function: DELETE /services
1386 # args: <response-code> <service-name>
1387 # (Function for test scripts)
1388 api_delete_services() {
1389 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1390 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1393 if [ $# -ne 2 ]; then
1394 __print_err "<response-code> <service-name>" $@
1398 query="/services?name="$2
1399 res="$(__do_curl_to_agent DELETE $query)"
1400 status=${res:${#res}-3}
1402 if [ $status -ne $1 ]; then
1403 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1405 __check_stop_at_error
1410 echo -e $GREEN" PASS"$EGREEN
1414 # API test function: PUT /services/keepalive
1415 # args: <response-code> <service-name>
1416 # (Function for test scripts)
1417 api_put_services_keepalive() {
1418 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1419 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1422 if [ $# -ne 2 ]; then
1423 __print_err "<response-code> <service-name>" $@
1427 query="/services/keepalive?name="$2
1428 res="$(__do_curl_to_agent PUT $query)"
1429 status=${res:${#res}-3}
1431 if [ $status -ne $1 ]; then
1432 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1434 __check_stop_at_error
1439 echo -e $GREEN" PASS"$EGREEN