X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Fagent_api_functions.sh;h=507e011d24f5f489b25215aea76e53854312e929;hb=4207b8389320d90274b12be78732304034bbc116;hp=29e1bf1afad48e2390cb57b5e51a417d17e506f1;hpb=b7311fbcbd77f615266a039613516adb9cea24f1;p=nonrtric.git diff --git a/test/common/agent_api_functions.sh b/test/common/agent_api_functions.sh index 29e1bf1a..507e011d 100644 --- a/test/common/agent_api_functions.sh +++ b/test/common/agent_api_functions.sh @@ -35,7 +35,11 @@ api_equal() { echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG if [ $# -eq 2 ] || [ $# -eq 3 ]; then if [[ $1 == "json:"* ]]; then - __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/" $1 "=" $2 $3 + if [ "$PMS_VERSION" == "V2" ]; then + __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/v2/" $1 "=" $2 $3 + else + __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/" $1 "=" $2 $3 + fi return 0 fi fi @@ -45,92 +49,184 @@ api_equal() { return 1 } -# API Test function: GET /policies -# args: |NORIC |NOSERVICE |NOTYPE [ NOID | [ EMPTY| ]*] +# API Test function: GET /policies and V2 GET /v2/policy_instances +# args: |NORIC |NOSERVICE |NOTYPE [ NOID | [ EMPTY| ]*] +# args(V2): |NORIC |NOSERVICE |NOTYPE [ NOID | [ EMPTY| ]*] # (Function for test scripts) api_get_policies() { echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG ((RES_TEST++)) - paramError=0 - if [ $# -lt 4 ]; then - paramError=1 - elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then - paramError=1 - elif [ $# -gt 4 ] && [ $(($#%5)) -ne 4 ]; then - paramError=1 + + if [ "$PMS_VERSION" == "V2" ]; then + paramError=0 + variableParams=$(($#-4)) + if [ $# -lt 4 ]; then + paramError=1 + elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then + paramError=1 + elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then + paramError=1 + fi + + if [ $paramError -ne 0 ]; then + __print_err " |NORIC |NOSERVICE |NOTYPE [ NOID | [ EMPTY| ]*]" $@ + return 1 + fi + else + paramError=0 + variableParams=$(($#-4)) + if [ $# -lt 4 ]; then + paramError=1 + elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then + paramError=1 + elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then + paramError=1 + fi + + if [ $paramError -ne 0 ]; then + __print_err " |NORIC |NOSERVICE |NOTYPE [ NOID | [ EMPTY| ]*]" $@ + return 1 + fi fi - if [ $paramError -ne 0 ]; then - __print_err " |NORIC |NOSERVICE |NOTYPE [ NOID | [ EMPTY| ]*]" $@ - return 1 - fi queryparams="" - if [ $2 != "NORIC" ]; then - queryparams="?ric="$2 - fi - if [ $3 != "NOSERVICE" ]; then - if [ -z $queryparams ]; then - queryparams="?service="$3 - else - queryparams=$queryparams"&service="$3 + if [ "$PMS_VERSION" == "V2" ]; then + if [ $2 != "NORIC" ]; then + queryparams="?ric_id="$2 fi - fi - if [ $4 != "NOTYPE" ]; then - if [ -z $queryparams ]; then - queryparams="?type="$4 - else - queryparams=$queryparams"&type="$4 + if [ $3 != "NOSERVICE" ]; then + if [ -z $queryparams ]; then + queryparams="?service_id="$3 + else + queryparams=$queryparams"&service_id="$3 + fi + fi + if [ $4 != "NOTYPE" ]; then + if [ -z $queryparams ]; then + queryparams="?policytype_id="$4 + else + queryparams=$queryparams"&policytype_id="$4 + fi fi - fi - query="/policies"$queryparams - res="$(__do_curl_to_api PA GET $query)" - status=${res:${#res}-3} + query="/v2/policy_instances"$queryparams + res="$(__do_curl_to_api PA GET $query)" + status=${res:${#res}-3} - if [ $status -ne $1 ]; then - echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED - ((RES_FAIL++)) - __check_stop_at_error - return 1 - fi + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi - if [ $# -gt 4 ]; then - if [ $# -eq 5 ] && [ $5 == "NOID" ]; then - targetJson="[" - else + if [ $# -gt 4 ]; then body=${res:0:${#res}-3} - targetJson="[" - arr=(${@:5}) - - for ((i=0; i<$(($#-4)); i=i+5)); do - - if [ "$targetJson" != "[" ]; then - targetJson=$targetJson"," - fi - targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":" - if [ "${arr[$i+3]}" == "EMPTY" ]; then - targetJson=$targetJson"\"\"," - else - targetJson=$targetJson"\"${arr[$i+3]}\"," - fi - file="./tmp/.p.json" - sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file - json=$(cat $file) - targetJson=$targetJson"\"json\":"$json"}" - done + if [ $# -eq 5 ] && [ $5 == "NOID" ]; then + targetJson="[" + else + targetJson="[" + arr=(${@:5}) + + for ((i=0; i<$(($#-4)); i=i+7)); do + + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policy_type_id\":" + if [ "${arr[$i+3]}" == "EMPTY" ]; then + targetJson=$targetJson"\"\"," + else + targetJson=$targetJson"\"${arr[$i+3]}\"," + fi + targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\"," + file="./tmp/.p.json" + sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file + json=$(cat $file) + targetJson=$targetJson"\"policy_data\":"$json"}" + done + fi + + targetJson=$targetJson"]" + targetJson="{\"policies\": $targetJson}" + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + else + if [ $2 != "NORIC" ]; then + queryparams="?ric="$2 + fi + if [ $3 != "NOSERVICE" ]; then + if [ -z $queryparams ]; then + queryparams="?service="$3 + else + queryparams=$queryparams"&service="$3 + fi + fi + if [ $4 != "NOTYPE" ]; then + if [ -z $queryparams ]; then + queryparams="?type="$4 + else + queryparams=$queryparams"&type="$4 + fi fi - targetJson=$targetJson"]" - echo "TARGET JSON: $targetJson" >> $HTTPLOG - res=$(python3 ../common/compare_json.py "$targetJson" "$body") + query="/policies"$queryparams + res="$(__do_curl_to_api PA GET $query)" + status=${res:${#res}-3} - if [ $res -ne 0 ]; then - echo -e $RED" FAIL, returned body not correct"$ERED + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED ((RES_FAIL++)) __check_stop_at_error return 1 fi + + if [ $# -gt 4 ]; then + if [ $# -eq 5 ] && [ $5 == "NOID" ]; then + targetJson="[" + else + body=${res:0:${#res}-3} + targetJson="[" + arr=(${@:5}) + + for ((i=0; i<$(($#-4)); i=i+5)); do + + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":" + if [ "${arr[$i+3]}" == "EMPTY" ]; then + targetJson=$targetJson"\"\"," + else + targetJson=$targetJson"\"${arr[$i+3]}\"," + fi + file="./tmp/.p.json" + sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file + json=$(cat $file) + targetJson=$targetJson"\"json\":"$json"}" + done + fi + + targetJson=$targetJson"]" + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi fi ((RES_PASS++)) @@ -139,20 +235,31 @@ api_get_policies() { } -# API Test function: GET /policy -#args: [] + +# API Test function: GET /policy and V2 GET /v2/policies/{policy_id} +# args: [] +# args(V2): [ |NOTYPE |NOURL ] + # (Function for test scripts) api_get_policy() { echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG ((RES_TEST++)) - if [ $# -lt 2 ] || [ $# -gt 3 ]; then - __print_err " [] " $@ - return 1 - fi - query="/policy?id=$UUID$2" + if [ "$PMS_VERSION" == "V2" ]; then + if [ $# -ne 2 ] && [ $# -ne 8 ]; then + __print_err " [ |NOTYPE |NOURL ]" $@ + return 1 + fi + query="/v2/policies/$UUID$2" + else + if [ $# -lt 2 ] || [ $# -gt 3 ]; then + __print_err " [] " $@ + return 1 + fi + query="/policy?id=$UUID$2" + fi res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} @@ -163,19 +270,54 @@ api_get_policy() { return 1 fi - if [ $# -eq 3 ]; then - #Create a policy json to compare with - body=${res:0:${#res}-3} - file="./tmp/.p.json" - sed 's/XXX/'${2}'/g' $3 > $file - targetJson=$(< $file) - echo "TARGET JSON: $targetJson" >> $HTTPLOG - res=$(python3 ../common/compare_json.py "$targetJson" "$body") - if [ $res -ne 0 ]; then - echo -e $RED" FAIL, returned body not correct"$ERED - ((RES_FAIL++)) - __check_stop_at_error - return 1 + if [ "$PMS_VERSION" == "V2" ]; then + if [ $# -eq 8 ]; then + + #Create a policy json to compare with + body=${res:0:${#res}-3} + file="./tmp/.p.json" + + targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\"" + if [ $7 != "NOTRANSIENT" ]; then + targetJson=$targetJson", \"transient\":$7" + fi + if [ $6 != "NOTYPE" ]; then + targetJson=$targetJson", \"policy_type_id\":\"$6\"" + else + targetJson=$targetJson", \"policy_type_id\":\"\"" + fi + if [ $8 != "NOURL" ]; then + targetJson=$targetJson", \"status_notification_uri\":\"$8\"" + fi + + data=$(sed 's/XXX/'${2}'/g' $temp) + targetJson=$targetJson", \"policy_data\":$data" + targetJson="{$targetJson}" + + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + else + if [ $# -eq 3 ]; then + #Create a policy json to compare with + body=${res:0:${#res}-3} + file="./tmp/.p.json" + sed 's/XXX/'${2}'/g' $3 > $file + targetJson=$(< $file) + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi fi fi @@ -184,43 +326,84 @@ api_get_policy() { return 0 } -# API Test function: PUT /policy -# args: [] +# API Test function: PUT /policy and V2 PUT /policies +# args: |NOTYPE |NOTRANSIENT [] +# args(V2): |NOTYPE |NOTRANSIENT |NOURL [] # (Function for test scripts) api_put_policy() { echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG ((RES_TEST++)) - if [ $# -lt 7 ] || [ $# -gt 8 ]; then - __print_err " |NOTRANSIENT []" $@ - return 1 - fi + if [ "$PMS_VERSION" == "V2" ]; then + if [ $# -lt 8 ] || [ $# -gt 9 ]; then + __print_err " |NOTYPE |NOTRANSIENT |NOURL []" $@ + return 1 + fi + else + if [ $# -lt 7 ] || [ $# -gt 8 ]; then + __print_err " |NOTYPE |NOTRANSIENT []" $@ + return 1 + fi + fi - ric=$3 count=0 max=1 + serv=$2 + ric=$3 + pt=$4 + pid=$5 + trans=$6 - if [ $# -eq 8 ]; then - max=$8 + if [ "$PMS_VERSION" == "V2" ]; then + noti=$7 + temp=$8 + if [ $# -eq 9 ]; then + max=$9 + fi + else + temp=$7 + if [ $# -eq 8 ]; then + max=$8 + fi fi - pid=$5 - file=$7 - while [ $count -lt $max ]; do - query="/policy?id=$UUID$pid&ric=$ric&service=$2" + if [ "$PMS_VERSION" == "V2" ]; then - if [ $4 != "NOTYPE" ]; then - query=$query"&type=$4" - fi + query="/v2/policies" - if [ $6 != NOTRANSIENT ]; then - query=$query"&transient=$6" - fi + inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\"" + if [ $trans != "NOTRANSIENT" ]; then + inputJson=$inputJson", \"transient\":$trans" + fi + if [ $pt != "NOTYPE" ]; then + inputJson=$inputJson", \"policy_type_id\":$pt" + else + inputJson=$inputJson", \"policy_type_id\":\"\"" + fi + if [ $noti != "NOURL" ]; then + inputJson=$inputJson", \"status_notification_uri\":\"$noti\"" + fi + file="./tmp/.p.json" + data=$(sed 's/XXX/'${pid}'/g' $temp) + inputJson=$inputJson", \"policy_data\":$data" + inputJson="{$inputJson}" + echo $inputJson > $file + else + query="/policy?id=$UUID$pid&ric=$ric&service=$serv" - file="./tmp/.p.json" - sed 's/XXX/'${pid}'/g' $7 > $file + if [ $pt != "NOTYPE" ]; then + query=$query"&type=$pt" + fi + + if [ $trans != NOTRANSIENT ]; then + query=$query"&transient=$trans" + fi + + file="./tmp/.p.json" + sed 's/XXX/'${pid}'/g' $temp > $file + fi res="$(__do_curl_to_api PA PUT $query $file)" status=${res:${#res}-3} echo -ne " Executing "$count"("$max")${SAMELINE}" @@ -243,43 +426,83 @@ api_put_policy() { return 0 } -# API Test function: PUT /policy to run in batch -# args: [] +# API Test function: PUT /policy and V2 PUT /policies, to run in batch +# args: |NOTYPE [] +# args(V2): |NOTYPE |NOURL [] # (Function for test scripts) + api_put_policy_batch() { echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG ((RES_TEST++)) - if [ $# -lt 7 ] || [ $# -gt 8 ]; then - __print_err " []" $@ - return 1 - fi + if [ "$PMS_VERSION" == "V2" ]; then + if [ $# -lt 8 ] || [ $# -gt 9 ]; then + __print_err " |NOTYPE |NOURL []" $@ + return 1 + fi + else + if [ $# -lt 7 ] || [ $# -gt 8 ]; then + __print_err " |NOTYPE []" $@ + return 1 + fi + fi - ric=$3 count=0 max=1 - - if [ $# -eq 8 ]; then - max=$8 + serv=$2 + ric=$3 + pt=$4 + pid=$5 + trans=$6 + if [ "$PMS_VERSION" == "V2" ]; then + noti=$7 + temp=$8 + if [ $# -eq 9 ]; then + max=$9 + fi + else + temp=$7 + if [ $# -eq 8 ]; then + max=$8 + fi fi - pid=$5 - file=$7 ARR="" while [ $count -lt $max ]; do - query="/policy?id=$UUID$pid&ric=$ric&service=$2" + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/policies" - if [ $4 != "NOTYPE" ]; then - query=$query"&type=$4" - fi + inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\"" + if [ $trans != "NOTRANSIENT" ]; then + inputJson=$inputJson", \"transient\":$trans" + fi + if [ $pt != "NOTYPE" ]; then + inputJson=$inputJson", \"policy_type_id\":$pt" + else + inputJson=$inputJson", \"policy_type_id\":\"\"" + fi + if [ $noti != "NOURL" ]; then + inputJson=$inputJson", \"status_notification_uri\":\"$noti\"" + fi + file="./tmp/.p.json" + data=$(sed 's/XXX/'${pid}'/g' $temp) + inputJson=$inputJson", \"policy_data\":$data" + inputJson="{$inputJson}" + echo $inputJson > $file + else + query="/policy?id=$UUID$pid&ric=$ric&service=$serv" - if [ $6 != NOTRANSIENT ]; then - query=$query"&transient=$6" - fi + if [ $pt != "NOTYPE" ]; then + query=$query"&type=$pt" + fi - file="./tmp/.p.json" - sed 's/XXX/'${pid}'/g' $7 > $file + if [ $trans != NOTRANSIENT ]; then + query=$query"&transient=$trans" + fi + file="./tmp/.p.json" + sed 's/XXX/'${pid}'/g' $temp > $file + fi res="$(__do_curl_to_api PA PUT_BATCH $query $file)" status=${res:${#res}-3} echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}" @@ -304,10 +527,10 @@ api_put_policy_batch() { res="$(__do_curl_to_api PA RESPONSE $cid)" status=${res:${#res}-3} - echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}" + echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}" if [ $status -ne $1 ]; then - echo " Requested(batch) "$count"?("$max")" + echo " Accepted(batch) "$count"?("$max")" echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED ((RES_FAIL++)) __check_stop_at_error @@ -315,7 +538,7 @@ api_put_policy_batch() { fi let count=$count+1 - echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" + echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}" done echo "" @@ -325,18 +548,26 @@ api_put_policy_batch() { return 0 } -# API Test function: PUT /policy to run in i parallel for a number of rics +# API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics # args: +# args(V2): |NOURL # (Function for test scripts) api_put_policy_parallel() { echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG ((RES_TEST++)) - if [ $# -ne 10 ]; then - __print_err " " $@ - return 1 - fi + if [ "$PMS_VERSION" == "V2" ]; then + if [ $# -ne 11 ]; then + __print_err " |NOURL " $@ + return 1 + fi + else + if [ $# -ne 10 ]; then + __print_err " " $@ + return 1 + fi + fi resp_code=$1; shift; serv=$1; shift ric_base=$1; shift; @@ -344,6 +575,11 @@ api_put_policy_parallel() { type=$1; shift; start_id=$1; shift; transient=$1; shift; + if [ "$PMS_VERSION" == "V2" ]; then + noti=$1; shift; + else + noti="" + fi template=$1; shift; count=$1; shift; pids=$1; shift; @@ -352,18 +588,24 @@ api_put_policy_parallel() { echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported" echo " Info - will execute over agent REST" fi + if [ "$PMS_VERSION" == "V2" ]; then + if [ $serv == "NOSERVICE" ]; then + serv="" + fi + query="/v2/policies" + else + if [ $serv == "NOSERVICE" ]; then + serv="" + fi + query="/policy?service=$serv" - if [ $serv == "NOSERVICE" ]; then - serv="" - fi - query="/policy?service=$serv" - - if [ $type != "NOTYPE" ]; then - query=$query"&type=$type" - fi + if [ $type != "NOTYPE" ]; then + query=$query"&type=$type" + fi - if [ $transient != NOTRANSIENT ]; then - query=$query"&transient=$transient" + if [ $transient != NOTRANSIENT ]; then + query=$query"&transient=$transient" + fi fi urlbase=${ADAPTER}${query} @@ -375,7 +617,11 @@ api_put_policy_parallel() { uuid="NOUUID" fi echo "" > "./tmp/.pid${i}.res.txt" - echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt" + if [ "$PMS_VERSION" == "V2" ]; then + echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i > "./tmp/.pid${i}.txt" + else + echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt" + fi echo $i done | xargs -n 1 -I{} -P $pids bash -c '{ arg=$(echo {}) @@ -414,7 +660,7 @@ api_put_policy_parallel() { return 1 } -# API Test function: DELETE /policy +# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id} # args: [count] # (Function for test scripts) api_delete_policy() { @@ -437,7 +683,11 @@ api_delete_policy() { pid=$2 while [ $count -lt $max ]; do - query="/policy?id="$UUID$pid + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/policies/"$UUID$pid + else + query="/policy?id="$UUID$pid + fi res="$(__do_curl_to_api PA DELETE $query)" status=${res:${#res}-3} echo -ne " Executing "$count"("$max")${SAMELINE}" @@ -460,7 +710,7 @@ api_delete_policy() { return 0 } -# API Test function: DELETE /policy to run in batch +# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch # args: [count] # (Function for test scripts) api_delete_policy_batch() { @@ -483,7 +733,11 @@ api_delete_policy_batch() { pid=$2 ARR="" while [ $count -lt $max ]; do - query="/policy?id="$UUID$pid + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/policies/"$UUID$pid + else + query="/policy?id="$UUID$pid + fi res="$(__do_curl_to_api PA DELETE_BATCH $query)" status=${res:${#res}-3} echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}" @@ -509,7 +763,7 @@ api_delete_policy_batch() { res="$(__do_curl_to_api PA RESPONSE $cid)" status=${res:${#res}-3} - echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}" + echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}" if [ $status -ne $1 ]; then echo " Deleted(batch) "$count"?("$max")" @@ -523,12 +777,14 @@ api_delete_policy_batch() { echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}" done + echo "" + ((RES_PASS++)) echo -e $GREEN" PASS"$EGREEN return 0 } -# API Test function: DELETE /policy to run in i parallel for a number of rics +# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics # args: # (Function for test scripts) api_delete_policy_parallel() { @@ -551,7 +807,11 @@ api_delete_policy_parallel() { echo " Info - will execute over agent REST" fi - query="/policy" + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/policies/" + else + query="/policy" + fi urlbase=${ADAPTER}${query} @@ -567,8 +827,8 @@ api_delete_policy_parallel() { done | xargs -n 1 -I{} -P $pids bash -c '{ arg=$(echo {}) echo " Parallel process $arg started" - tmp=$(< "./tmp/pid${arg}.del.txt") - python3 ../common/delete_policies_process.py $tmp > ./tmp/pid${arg}.del.res.txt + tmp=$(< "./tmp/.pid${arg}.del.txt") + python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt }' msg="" for ((i=1; i<=$pids; i++)) @@ -601,7 +861,7 @@ api_delete_policy_parallel() { return 1 } -# API Test function: GET /policy_ids +# API Test function: GET /policy_ids and V2 GET /v2/policies # args: |NORIC |NOSERVICE |NOTYPE ([> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: V2 GET /v2/policy-types/{policyTypeId} +# args(V2): [] +# (Function for test scripts) +api_get_policy_type() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ "$PMS_VERSION" != "V2" ]; then + echo -e $RED" FAIL, function not supported"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + if [ $# -lt 2 ] || [ $# -gt 3 ]; then + __print_err " []" $@ + return 1 + fi + query="/v2/policy-types/$2" + + res="$(__do_curl_to_api PA GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + if [ $# -eq 3 ]; then + + body=${res:0:${#res}-3} + + targetJson=$(< $3) + targetJson="{\"policy_schema\":$targetJson}" echo "TARGET JSON: $targetJson" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$targetJson" "$body") @@ -684,11 +1024,17 @@ api_get_policy_schema() { echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG ((RES_TEST++)) + if [ "$PMS_VERSION" == "V2" ]; then + echo -e $RED" FAIL, function not supported"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + if [ $# -lt 2 ] || [ $# -gt 3 ]; then __print_err " []" $@ return 1 fi - query="/policy_schema?id=$2" res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} @@ -705,6 +1051,7 @@ api_get_policy_schema() { body=${res:0:${#res}-3} targetJson=$(< $3) + echo "TARGET JSON: $targetJson" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$targetJson" "$body") @@ -723,20 +1070,31 @@ api_get_policy_schema() { # API Test function: GET /policy_schemas # args: |NORIC [|NOFILE]* +# args(V2): # (Function for test scripts) api_get_policy_schemas() { echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG ((RES_TEST++)) - if [ $# -lt 2 ]; then - __print_err " |NORIC [|NOFILE]*" $@ - return 1 - fi - - query="/policy_schemas" - if [ $2 != "NORIC" ]; then - query=$query"?ric="$2 + if [ "$PMS_VERSION" == "V2" ]; then + if [ $# -ne 1 ]; then + __print_err "" $@ + return 1 + fi + else + if [ $# -lt 2 ]; then + __print_err " |NORIC [|NOFILE]*" $@ + return 1 + fi + fi + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/policy-schemas" + else + query="/policy_schemas" + if [ $2 != "NORIC" ]; then + query=$query"?ric="$2 + fi fi res="$(__do_curl_to_api PA GET $query)" @@ -765,6 +1123,9 @@ api_get_policy_schemas() { done targetJson=$targetJson"]" + if [ "$PMS_VERSION" == "V2" ]; then + targetJson="{\"policy_schemas\": $targetJson }" + fi echo "TARGET JSON: $targetJson" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$targetJson" "$body") @@ -781,13 +1142,14 @@ api_get_policy_schemas() { return 0 } -# API Test function: GET /policy_status +# API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status # arg: (STD [])|(OSC ) # (Function for test scripts) api_get_policy_status() { echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG ((RES_TEST++)) + if [ $# -lt 4 ] || [ $# -gt 5 ]; then __print_err " (STD [])|(OSC )" $@ return 1 @@ -812,7 +1174,12 @@ api_get_policy_status() { return 1 fi - query="/policy_status?id="$UUID$2 + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/policies/$UUID$2/status" + targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}" + else + query="/policy_status?id="$UUID$2 + fi res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} @@ -840,7 +1207,7 @@ api_get_policy_status() { return 0 } -# API Test function: GET /policy_types +# API Test function: GET /policy_types and V2 GET /v2/policy-types # args: [|NORIC [|EMPTY []*]] # (Function for test scripts) api_get_policy_types() { @@ -853,12 +1220,22 @@ api_get_policy_types() { return 1 fi - if [ $# -eq 1 ]; then - query="/policy_types" - elif [ $2 == "NORIC" ]; then - query="/policy_types" + if [ "$PMS_VERSION" == "V2" ]; then + if [ $# -eq 1 ]; then + query="/v2/policy-types" + elif [ $2 == "NORIC" ]; then + query="/v2/policy-types" + else + query="/v2/policy-types?ric_id=$2" + fi else - query="/policy_types?ric=$2" + if [ $# -eq 1 ]; then + query="/policy_types" + elif [ $2 == "NORIC" ]; then + query="/policy_types" + else + query="/policy_types?ric=$2" + fi fi res="$(__do_curl_to_api PA GET $query)" @@ -886,6 +1263,9 @@ api_get_policy_types() { done targetJson=$targetJson"]" + if [ "$PMS_VERSION" == "V2" ]; then + targetJson="{\"policy_type_ids\": $targetJson }" + fi echo "TARGET JSON: $targetJson" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$targetJson" "$body") @@ -906,7 +1286,7 @@ api_get_policy_types() { #### Test case functions Health check ######################################################### -# API Test function: GET /status +# API Test function: GET /status and V2 GET /status # args: # (Function for test scripts) api_get_status() { @@ -917,7 +1297,11 @@ api_get_status() { __print_err "" $@ return 1 fi - query="/status" + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/status" + else + query="/status" + fi res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} @@ -937,46 +1321,102 @@ api_get_status() { #### Test case functions RIC Repository ######################################################### -# API Test function: GET /ric +# API Test function: GET /ric and V2 GET /v2/rics/ric # args: [] +# (V2) args: |NOME | [] +# (V2) example of = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4" +# (V2) format of ric-info: :: + + # (Function for test scripts) api_get_ric() { echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG ((RES_TEST++)) - if [ $# -lt 2 ] || [ $# -gt 3 ]; then - __print_err " []" $@ - return 1 - fi - query="/ric?managedElementId="$2 + if [ "$PMS_VERSION" == "V2" ]; then + if [ $# -lt 3 ]; then + __print_err " |NOME | [string-of-ricinfo>]" $@ + return 1 + fi + search="" + if [ $2 != "NOME" ]; then + search="?managed_element_id="$2 + fi + if [ $3 != "NORIC" ]; then + if [ -z $search ]; then + search="?ric_id="$3 + else + search=$search"&ric_id="$3 + fi + fi + query="/v2/rics/ric"$search - res="$(__do_curl_to_api PA GET $query)" - status=${res:${#res}-3} + res="$(__do_curl_to_api PA GET $query)" + status=${res:${#res}-3} - if [ $status -ne $1 ]; then - echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED - ((RES_FAIL++)) - __check_stop_at_error - return 1 - fi + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi - if [ $# -eq 3 ]; then - body=${res:0:${#res}-3} - if [ "$body" != "$3" ]; then - echo -e $RED" FAIL, returned body not correct"$ERED + if [ $# -gt 3 ]; then + body=${res:0:${#res}-3} + res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" ) + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, could not create target ric info json"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + targetJson=$(<./tmp/.tmp_rics.json) + targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + else + if [ $# -lt 2 ] || [ $# -gt 3 ]; then + __print_err " []" $@ + return 1 + fi + + query="/ric?managedElementId="$2 + + res="$(__do_curl_to_api PA GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED ((RES_FAIL++)) __check_stop_at_error return 1 fi - fi + if [ $# -eq 3 ]; then + body=${res:0:${#res}-3} + if [ "$body" != "$3" ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + fi ((RES_PASS++)) echo -e $GREEN" PASS"$EGREEN return 0 } -# API test function: GET /rics +# API test function: GET /rics and V2 GET /v2/rics # args: |NOTYPE [] # example of = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4 ricsim_g1_1:me2_........." # format of ric-info: :: @@ -991,9 +1431,16 @@ api_get_rics() { return 1 fi - query="/rics" - if [ $2 != "NOTYPE" ]; then - query="/rics?policyType="$2 + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/rics" + if [ $2 != "NOTYPE" ]; then + query="/v2/rics?policytype_id="$2 + fi + else + query="/rics" + if [ $2 != "NOTYPE" ]; then + query="/rics?policyType="$2 + fi fi res="$(__do_curl_to_api PA GET $query)" @@ -1008,7 +1455,11 @@ api_get_rics() { if [ $# -gt 2 ]; then body=${res:0:${#res}-3} - res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "$3" ) + if [ "$PMS_VERSION" == "V2" ]; then + res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" ) + else + res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" ) + fi if [ $res -ne 0 ]; then echo -e $RED" FAIL, could not create target ric info json"$ERED ((RES_FAIL++)) @@ -1017,6 +1468,9 @@ api_get_rics() { fi targetJson=$(<./tmp/.tmp_rics.json) + if [ "$PMS_VERSION" == "V2" ]; then + targetJson="{\"rics\": $targetJson }" + fi echo "TARGET JSON: $targetJson" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$targetJson" "$body") if [ $res -ne 0 ]; then @@ -1036,7 +1490,7 @@ api_get_rics() { #### API Test case functions Service registry and supervision #### ################################################################## -# API test function: PUT /service +# API test function: PUT /service and V2 PUT /service # args: # (Function for test scripts) api_put_service() { @@ -1048,8 +1502,13 @@ api_put_service() { return 1 fi - query="/service" - json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}" + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/services" + json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}" + else + query="/service" + json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}" + fi file="./tmp/.tmp.json" echo "$json" > $file @@ -1068,7 +1527,7 @@ api_put_service() { return 0 } -# API test function: GET /services +# API test function: GET /services and V2 GET /v2/services #args: [ ( ) | (NOSERVICE [ ]* )] # (Function for test scripts) api_get_services() { @@ -1095,12 +1554,19 @@ api_get_services() { return 1 fi - query="/services" + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/services" - if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then - query="/services?name="$2 - fi + if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then + query="/v2/services?service_id="$2 + fi + else + query="/services" + if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then + query="/services?name="$2 + fi + fi res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} @@ -1125,10 +1591,17 @@ api_get_services() { targetJson=$targetJson"," fi # timeSinceLastActivitySeconds value cannot be checked since value varies - targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}" + if [ "$PMS_VERSION" == "V2" ]; then + targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}" + else + targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}" + fi let cntr=cntr+3 done targetJson=$targetJson"]" + if [ "$PMS_VERSION" == "V2" ]; then + targetJson="{\"service_list\": $targetJson }" + fi echo "TARGET JSON: $targetJson" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$targetJson" "$body") if [ $res -ne 0 ]; then @@ -1144,7 +1617,7 @@ api_get_services() { return 0 } -# API test function: GET /services (only checking service names) +# API test function: GET /services V2 GET /v2/services - (only checking service names) # args: []*" # (Function for test scripts) api_get_service_ids() { @@ -1157,7 +1630,11 @@ api_get_service_ids() { return 1 fi - query="/services" + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/services" + else + query="/services" + fi res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} @@ -1174,10 +1651,17 @@ api_get_service_ids() { if [ "$targetJson" != "[" ]; then targetJson=$targetJson"," fi - targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}" + if [ "$PMS_VERSION" == "V2" ]; then + targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}" + else + targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}" + fi done targetJson=$targetJson"]" + if [ "$PMS_VERSION" == "V2" ]; then + targetJson="{\"service_list\": $targetJson }" + fi echo "TARGET JSON: $targetJson" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$targetJson" "$body") @@ -1193,7 +1677,7 @@ api_get_service_ids() { return 0 } -# API test function: DELETE /services +# API test function: DELETE /services and V2 DELETE /v2/services/{serviceId} # args: # (Function for test scripts) api_delete_services() { @@ -1205,8 +1689,11 @@ api_delete_services() { __print_err " " $@ return 1 fi - - query="/services?name="$2 + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/services/"$2 + else + query="/services?name="$2 + fi res="$(__do_curl_to_api PA DELETE $query)" status=${res:${#res}-3} @@ -1222,7 +1709,7 @@ api_delete_services() { return 0 } -# API test function: PUT /services/keepalive +# API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive # args: # (Function for test scripts) api_put_services_keepalive() { @@ -1234,8 +1721,12 @@ api_put_services_keepalive() { __print_err " " $@ return 1 fi + if [ "$PMS_VERSION" == "V2" ]; then + query="/v2/services/$2/keepalive" + else + query="/services/keepalive?name="$2 + fi - query="/services/keepalive?name="$2 res="$(__do_curl_to_api PA PUT $query)" status=${res:${#res}-3}