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
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\":\"${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=$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> <template-file> [<count>]" $@
393 if [ $# -eq 8 ]; then
400 while [ $count -lt $max ]; do
401 query="/policy?id=$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
418 echo " Created "$count"?("$max")"
419 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
421 __check_stop_at_error
427 echo -ne " Created "$count"("$max")${SAMELINE}"
432 echo -e $GREEN" PASS"$EGREEN
436 # API Test function: PUT /policy to run in batch
437 # args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]
438 # (Function for test scripts)
439 api_put_policy_batch() {
440 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
441 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
444 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
445 __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]" $@
453 if [ $# -eq 8 ]; then
460 while [ $count -lt $max ]; do
461 query="/policy?id=$pid&ric=$ric&service=$2"
463 if [ $4 != "NOTYPE" ]; then
464 query=$query"&type=$4"
467 if [ $6 != NOTRANSIENT ]; then
468 query=$query"&transient=$6"
472 sed 's/XXX/'${pid}'/g' $7 > $file
473 res="$(__do_curl_to_agent PUT_BATCH $query $file)"
474 status=${res:${#res}-3}
475 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
477 if [ $status -ne 200 ]; then
479 echo " Requested(batch) "$count"?("$max")"
480 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
482 __check_stop_at_error
485 cid=${res:0:${#res}-3}
489 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
496 res="$(__do_curl_to_agent RESPONSE $cid)"
497 status=${res:${#res}-3}
498 echo -ne " Created(batch) "$count"("$max")${SAMELINE}"
500 if [ $status -ne $1 ]; then
502 echo " Created(batch) "$count"?("$max")"
503 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
505 __check_stop_at_error
510 echo -ne " Created(batch) "$count"("$max")${SAMELINE}"
516 echo -e $GREEN" PASS"$EGREEN
520 # API Test function: PUT /policy to run in i parallel for a number of rics
521 # 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>
522 # (Function for test scripts)
523 api_put_policy_parallel() {
524 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
525 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
528 if [ $# -ne 10 ]; then
529 __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>" $@
543 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
544 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
545 echo " Info - will execute over agent REST"
548 if [ $serv == "NOSERVICE" ]; then
551 query="/policy?service=$serv"
553 if [ $type != "NOTYPE" ]; then
554 query=$query"&type=$type"
557 if [ $transient != NOTRANSIENT ]; then
558 query=$query"&transient=$transient"
561 urlbase=${ADAPTER}${query}
563 for ((i=1; i<=$pids; i++))
565 echo "" > ".pid${i}.res.txt"
566 echo $resp_code $urlbase $ric_base $num_rics $start_id $template $count $pids $i > ".pid${i}.txt"
568 done | xargs -n 1 -I{} -P $pids bash -c '{
570 echo " Parallel process $arg started"
571 tmp=$(< ".pid${arg}.txt")
572 python3 ../common/create_policies_process.py $tmp > .pid${arg}.res.txt
575 for ((i=1; i<=$pids; i++))
577 file=".pid${i}.res.txt"
579 if [ -z "$tmp" ]; then
580 echo " Process $i : unknown result (result file empty"
584 if [ $res == "0" ]; then
585 echo " Process $i : OK"
587 echo " Process $i : failed - "${tmp:1}
593 echo " $(($count*$num_rics)) policies created/updated"
595 echo -e $GREEN" PASS"$EGREEN
599 echo -e $RED" FAIL. One of more processes failed to execute" $ERED
601 __check_stop_at_error
605 # API Test function: DELETE /policy
606 # args: <response-code> <policy-id> [count]
607 # (Function for test scripts)
608 api_delete_policy() {
609 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
610 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
613 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
614 __print_err "<response-code> <policy-id> [count]" $@
621 if [ $# -eq 3 ]; then
627 while [ $count -lt $max ]; do
628 query="/policy?id="$pid
629 res="$(__do_curl_to_agent DELETE $query)"
630 status=${res:${#res}-3}
631 echo -ne " Deleting "$count"("$max")${SAMELINE}"
633 if [ $status -ne $1 ]; then
634 echo " Deleted "$count"?("$max")"
635 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
637 __check_stop_at_error
642 echo -ne " Deleted "$count"("$max")${SAMELINE}"
647 echo -e $GREEN" PASS"$EGREEN
651 # API Test function: DELETE /policy to run in batch
652 # args: <response-code> <policy-id> [count]
653 # (Function for test scripts)
654 api_delete_policy_batch() {
655 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
656 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
659 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
660 __print_err "<response-code> <policy-id> [count]" $@
667 if [ $# -eq 3 ]; then
673 while [ $count -lt $max ]; do
674 query="/policy?id="$pid
675 res="$(__do_curl_to_agent DELETE_BATCH $query)"
676 status=${res:${#res}-3}
677 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
679 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
705 echo " Deleted(batch) "$count"?("$max")"
706 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
708 __check_stop_at_error
713 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
717 echo -e $GREEN" PASS"$EGREEN
721 # API Test function: DELETE /policy to run in i parallel for a number of rics
722 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
723 # (Function for test scripts)
724 api_delete_policy_parallel() {
725 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
726 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
729 if [ $# -ne 5 ]; then
730 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
739 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
740 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
741 echo " Info - will execute over agent REST"
746 urlbase=${ADAPTER}${query}
748 for ((i=1; i<=$pids; i++))
750 echo "" > ".pid${i}.del.res.txt"
751 echo $resp_code $urlbase $num_rics $start_id $count $pids $i > ".pid${i}.del.txt"
753 done | xargs -n 1 -I{} -P $pids bash -c '{
755 echo " Parallel process $arg started"
756 tmp=$(< ".pid${arg}.del.txt")
757 python3 ../common/delete_policies_process.py $tmp > .pid${arg}.del.res.txt
760 for ((i=1; i<=$pids; i++))
762 file=".pid${i}.del.res.txt"
764 if [ -z "$tmp" ]; then
765 echo " Process $i : unknown result (result file empty"
769 if [ $res == "0" ]; then
770 echo " Process $i : OK"
772 echo " Process $i : failed - "${tmp:1}
778 echo " $(($count*$num_rics)) deleted"
780 echo -e $GREEN" PASS"$EGREEN
784 echo -e $RED" FAIL. One of more processes failed to execute" $ERED
786 __check_stop_at_error
790 # API Test function: GET /policy_ids
791 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
792 # (Function for test scripts)
793 api_get_policy_ids() {
794 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
795 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
798 if [ $# -lt 4 ]; then
799 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
805 if [ $2 != "NORIC" ]; then
806 queryparams="?ric="$2
809 if [ $3 != "NOSERVICE" ]; then
810 if [ -z $queryparams ]; then
811 queryparams="?service="$3
813 queryparams=$queryparams"&service="$3
816 if [ $4 != "NOTYPE" ]; then
817 if [ -z $queryparams ]; then
818 queryparams="?type="$4
820 queryparams=$queryparams"&type="$4
824 query="/policy_ids"$queryparams
825 res="$(__do_curl_to_agent GET $query)"
826 status=${res:${#res}-3}
828 if [ $status -ne $1 ]; then
829 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
831 __check_stop_at_error
835 if [ $# -gt 4 ]; then
836 body=${res:0:${#res}-3}
839 for pid in ${@:5} ; do
840 if [ "$targetJson" != "[" ]; then
841 targetJson=$targetJson","
843 if [ $pid != "NOID" ]; then
844 targetJson=$targetJson"\"$pid\""
848 targetJson=$targetJson"]"
849 echo "TARGET JSON: $targetJson" >> $HTTPLOG
850 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
852 if [ $res -ne 0 ]; then
853 echo -e $RED" FAIL, returned body not correct"$ERED
855 __check_stop_at_error
861 echo -e $GREEN" PASS"$EGREEN
865 # API Test function: GET /policy_schema
866 # args: <response-code> <policy-type-id> [<schema-file>]
867 # (Function for test scripts)
868 api_get_policy_schema() {
869 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
870 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
873 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
874 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
878 query="/policy_schema?id=$2"
879 res="$(__do_curl_to_agent GET $query)"
880 status=${res:${#res}-3}
882 if [ $status -ne $1 ]; then
883 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
885 __check_stop_at_error
889 if [ $# -eq 3 ]; then
891 body=${res:0:${#res}-3}
894 echo "TARGET JSON: $targetJson" >> $HTTPLOG
895 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
897 if [ $res -ne 0 ]; then
898 echo -e $RED" FAIL, returned body not correct"$ERED
900 __check_stop_at_error
906 echo -e $GREEN" PASS"$EGREEN
910 # API Test function: GET /policy_schemas
911 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
912 # (Function for test scripts)
913 api_get_policy_schemas() {
914 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
915 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
918 if [ $# -lt 2 ]; then
919 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
923 query="/policy_schemas"
924 if [ $2 != "NORIC" ]; then
925 query=$query"?ric="$2
928 res="$(__do_curl_to_agent GET $query)"
929 status=${res:${#res}-3}
931 if [ $status -ne $1 ]; then
932 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
934 __check_stop_at_error
938 if [ $# -gt 2 ]; then
939 body=${res:0:${#res}-3}
942 for file in ${@:3} ; do
943 if [ "$targetJson" != "[" ]; then
944 targetJson=$targetJson","
946 if [ $file == "NOFILE" ]; then
947 targetJson=$targetJson"{}"
949 targetJson=$targetJson$(< $file)
953 targetJson=$targetJson"]"
954 echo "TARGET JSON: $targetJson" >> $HTTPLOG
955 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
957 if [ $res -ne 0 ]; then
958 echo -e $RED" FAIL, returned body not correct"$ERED
960 __check_stop_at_error
966 echo -e $GREEN" PASS"$EGREEN
970 # API Test function: GET /policy_status
971 # arg: <response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)
972 # (Function for test scripts)
973 api_get_policy_status() {
974 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
975 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
977 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
978 __print_err "<response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
984 if [ $3 == "STD" ]; then
985 targetJson="{\"enforceStatus\":\"$4\""
986 if [ $# -eq 5 ]; then
987 targetJson=$targetJson",\"reason\":\"$5\""
989 targetJson=$targetJson"}"
990 elif [ $3 == "OSC" ]; then
991 targetJson="{\"instance_status\":\"$4\""
992 if [ $# -eq 5 ]; then
993 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
995 targetJson=$targetJson",\"created_at\":\"????\"}"
997 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1001 query="/policy_status?id="$2
1003 res="$(__do_curl_to_agent GET $query)"
1004 status=${res:${#res}-3}
1006 if [ $status -ne $1 ]; then
1007 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1009 __check_stop_at_error
1013 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1014 body=${res:0:${#res}-3}
1015 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1017 if [ $res -ne 0 ]; then
1018 echo -e $RED" FAIL, returned body not correct"$ERED
1020 __check_stop_at_error
1025 echo -e $GREEN" PASS"$EGREEN
1029 # API Test function: GET /policy_types
1030 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1031 # (Function for test scripts)
1032 api_get_policy_types() {
1033 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1034 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1037 if [ $# -lt 1 ]; then
1038 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1042 if [ $# -eq 1 ]; then
1043 query="/policy_types"
1044 elif [ $2 == "NORIC" ]; then
1045 query="/policy_types"
1047 query="/policy_types?ric=$2"
1050 res="$(__do_curl_to_agent GET $query)"
1051 status=${res:${#res}-3}
1053 if [ $status -ne $1 ]; then
1054 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1056 __check_stop_at_error
1060 if [ $# -gt 2 ]; then
1061 body=${res:0:${#res}-3}
1064 for pid in ${@:3} ; do
1065 if [ "$targetJson" != "[" ]; then
1066 targetJson=$targetJson","
1068 if [ $pid == "EMPTY" ]; then
1071 targetJson=$targetJson"\"$pid\""
1074 targetJson=$targetJson"]"
1075 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1076 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1078 if [ $res -ne 0 ]; then
1079 echo -e $RED" FAIL, returned body not correct"$ERED
1081 __check_stop_at_error
1087 echo -e $GREEN" PASS"$EGREEN
1091 #########################################################
1092 #### Test case functions Health check
1093 #########################################################
1095 # API Test function: GET /status
1096 # args: <response-code>
1097 # (Function for test scripts)
1099 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1100 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1102 if [ $# -ne 1 ]; then
1103 __print_err "<response-code>" $@
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
1113 __check_stop_at_error
1118 echo -e $GREEN" PASS"$EGREEN
1122 #########################################################
1123 #### Test case functions RIC Repository
1124 #########################################################
1126 # API Test function: GET /ric
1127 # args: <reponse-code> <management-element-id> [<ric-id>]
1128 # (Function for test scripts)
1130 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1131 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1133 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1134 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1138 query="/ric?managedElementId="$2
1140 res="$(__do_curl_to_agent GET $query)"
1141 status=${res:${#res}-3}
1143 if [ $status -ne $1 ]; then
1144 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1146 __check_stop_at_error
1150 if [ $# -eq 3 ]; then
1151 body=${res:0:${#res}-3}
1152 if [ "$body" != "$3" ]; then
1153 echo -e $RED" FAIL, returned body not correct"$ERED
1155 __check_stop_at_error
1161 echo -e $GREEN" PASS"$EGREEN
1165 # API test function: GET /rics
1166 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1167 # 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_........."
1168 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1169 # (Function for test scripts)
1171 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1172 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1175 if [ $# -lt 2 ]; then
1176 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1181 if [ $2 != "NOTYPE" ]; then
1182 query="/rics?policyType="$2
1185 res="$(__do_curl_to_agent GET $query)"
1186 status=${res:${#res}-3}
1188 if [ $status -ne $1 ]; then
1189 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1191 __check_stop_at_error
1195 if [ $# -gt 2 ]; then
1196 body=${res:0:${#res}-3}
1197 res=$(python3 ../common/create_rics_json.py ".tmp_rics.json" "$3" )
1198 if [ $res -ne 0 ]; then
1199 echo -e $RED" FAIL, could not create target ric info json"$ERED
1201 __check_stop_at_error
1205 targetJson=$(<.tmp_rics.json)
1206 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1207 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1208 if [ $res -ne 0 ]; then
1209 echo -e $RED" FAIL, returned body not correct"$ERED
1211 __check_stop_at_error
1217 echo -e $GREEN" PASS"$EGREEN
1221 ##################################################################
1222 #### API Test case functions Service registry and supervision ####
1223 ##################################################################
1225 # API test function: PUT /service
1226 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1227 # (Function for test scripts)
1229 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1230 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1232 if [ $# -ne 4 ]; then
1233 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1238 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1240 echo "$json" > $file
1242 res="$(__do_curl_to_agent PUT $query $file)"
1243 status=${res:${#res}-3}
1245 if [ $status -ne $1 ]; then
1246 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1248 __check_stop_at_error
1253 echo -e $GREEN" PASS"$EGREEN
1257 # API test function: GET /services
1258 #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>]* )]
1259 # (Function for test scripts)
1260 api_get_services() {
1261 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1262 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1264 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1266 if [ $# -eq 1 ]; then
1268 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1270 elif [ $# -eq 5 ]; then
1272 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1274 if [ $(($argLen%3)) -eq 0 ]; then
1279 if [ $paramError -ne 0 ]; then
1280 __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>]* )]" $@
1286 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1287 query="/services?name="$2
1290 res="$(__do_curl_to_agent GET $query)"
1291 status=${res:${#res}-3}
1293 if [ $status -ne $1 ]; then
1294 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1296 __check_stop_at_error
1300 if [ $# -gt 2 ]; then
1301 variableArgCount=$(($#-2))
1302 body=${res:0:${#res}-3}
1306 while [ $cntr -lt $variableArgCount ]; do
1307 servicename=$1; shift;
1310 if [ $cntr -gt 0 ]; then
1311 targetJson=$targetJson","
1313 # timeSinceLastActivitySeconds value cannot be checked since value varies
1314 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1317 targetJson=$targetJson"]"
1318 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1319 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1320 if [ $res -ne 0 ]; then
1321 echo -e $RED" FAIL, returned body not correct"$ERED
1323 __check_stop_at_error
1329 echo -e $GREEN" PASS"$EGREEN
1333 # API test function: GET /services (only checking service names)
1334 # args: <response-code> [<service-name>]*"
1335 # (Function for test scripts)
1336 api_get_service_ids() {
1337 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1338 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1341 if [ $# -lt 1 ]; then
1342 __print_err "<response-code> [<service-name>]*" $@
1347 res="$(__do_curl_to_agent GET $query)"
1348 status=${res:${#res}-3}
1350 if [ $status -ne $1 ]; then
1351 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1353 __check_stop_at_error
1357 body=${res:0:${#res}-3}
1359 for rapp in ${@:2} ; do
1360 if [ "$targetJson" != "[" ]; then
1361 targetJson=$targetJson","
1363 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1366 targetJson=$targetJson"]"
1367 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1368 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1370 if [ $res -ne 0 ]; then
1371 echo -e $RED" FAIL, returned body not correct"$ERED
1373 __check_stop_at_error
1378 echo -e $GREEN" PASS"$EGREEN
1382 # API test function: DELETE /services
1383 # args: <response-code> <service-name>
1384 # (Function for test scripts)
1385 api_delete_services() {
1386 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1387 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1390 if [ $# -ne 2 ]; then
1391 __print_err "<response-code> <service-name>" $@
1395 query="/services?name="$2
1396 res="$(__do_curl_to_agent DELETE $query)"
1397 status=${res:${#res}-3}
1399 if [ $status -ne $1 ]; then
1400 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1402 __check_stop_at_error
1407 echo -e $GREEN" PASS"$EGREEN
1411 # API test function: PUT /services/keepalive
1412 # args: <response-code> <service-name>
1413 # (Function for test scripts)
1414 api_put_services_keepalive() {
1415 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1416 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1419 if [ $# -ne 2 ]; then
1420 __print_err "<response-code> <service-name>" $@
1424 query="/services/keepalive?name="$2
1425 res="$(__do_curl_to_agent PUT $query)"
1426 status=${res:${#res}-3}
1428 if [ $status -ne $1 ]; then
1429 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1431 __check_stop_at_error
1436 echo -e $GREEN" PASS"$EGREEN