+ if [ "$PMS_VERSION" == "V2" ]; then
+ if [ $# -lt 8 ] || [ $# -gt 9 ]; then
+ __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
+ return 1
+ fi
+ else
+ if [ $# -lt 7 ] || [ $# -gt 8 ]; then
+ __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
+ return 1
+ fi
+ fi
+
+ count=0
+ max=1
+ 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
+
+ while [ $count -lt $max ]; do
+ if [ "$PMS_VERSION" == "V2" ]; then
+
+ query="/v2/policies"
+
+ 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", \"policytype_id\":\"$pt\""
+ else
+ inputJson=$inputJson", \"policytype_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 [ $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}"
+ if [ $status -ne $1 ]; then
+ echo " Executed "$count"?("$max")"
+ __log_test_fail_status_code $1 $status
+ return 1
+ fi
+
+ let pid=$pid+1
+ let count=$count+1
+ echo -ne " Executed "$count"("$max")${SAMELINE}"
+ done
+ echo ""
+
+ __log_test_pass
+ return 0
+}
+
+# API Test function: PUT /policy and V2 PUT /policies, to run in batch
+# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
+# args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
+# (Function for test scripts)
+
+api_put_policy_batch() {
+ __log_test_start $@
+
+ if [ "$PMS_VERSION" == "V2" ]; then
+ if [ $# -lt 8 ] || [ $# -gt 9 ]; then
+ __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
+ return 1
+ fi
+ else
+ if [ $# -lt 7 ] || [ $# -gt 8 ]; then
+ __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
+ return 1
+ fi
+ fi
+
+ count=0
+ max=1
+ 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
+
+ ARR=""
+ while [ $count -lt $max ]; do
+ if [ "$PMS_VERSION" == "V2" ]; then
+ query="/v2/policies"
+
+ 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", \"policytype_id\":\"$pt\""
+ else
+ inputJson=$inputJson", \"policytype_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 [ $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_BATCH $query $file)"
+ status=${res:${#res}-3}
+ echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
+
+ if [ $status -ne 200 ]; then
+ echo " Requested(batch) "$count"?("$max")"
+ __log_test_fail_status_code 200 $status
+ return 1
+ fi
+ cid=${res:0:${#res}-3}
+ ARR=$ARR" "$cid
+ let pid=$pid+1
+ let count=$count+1
+ echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
+ done
+
+ echo ""
+ count=0
+ for cid in $ARR; do
+
+ res="$(__do_curl_to_api PA RESPONSE $cid)"
+ status=${res:${#res}-3}
+ echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
+
+ if [ $status -ne $1 ]; then
+ echo " Accepted(batch) "$count"?("$max")"
+ __log_test_fail_status_code $1 $status
+ return 1
+ fi
+
+ let count=$count+1
+ echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
+ done
+
+ echo ""
+
+ __log_test_pass
+ return 0
+}
+
+# API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
+# 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>
+# args(V2): <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>
+# (Function for test scripts)
+api_put_policy_parallel() {
+ __log_test_start $@
+
+ if [ "$PMS_VERSION" == "V2" ]; then
+ if [ $# -ne 11 ]; then
+ __print_err "<response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>" $@
+ return 1
+ fi
+ else
+ if [ $# -ne 10 ]; then
+ __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>" $@
+ return 1
+ fi
+ fi
+ resp_code=$1; shift;
+ serv=$1; shift
+ ric_base=$1; shift;
+ num_rics=$1; shift;
+ 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;
+
+ if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
+ 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 [ $type != "NOTYPE" ]; then
+ query=$query"&type=$type"
+ fi
+
+ if [ $transient != NOTRANSIENT ]; then
+ query=$query"&transient=$transient"
+ fi
+ fi
+
+ urlbase=${ADAPTER}${query}
+
+ for ((i=1; i<=$pids; i++))
+ do
+ uuid=$UUID
+ if [ -z "$uuid" ]; then
+ uuid="NOUUID"
+ fi
+ echo "" > "./tmp/.pid${i}.res.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 {})
+ echo " Parallel process $arg started"
+ tmp=$(< "./tmp/.pid${arg}.txt")
+ python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
+ }'
+ msg=""
+ for ((i=1; i<=$pids; i++))
+ do
+ file="./tmp/.pid${i}.res.txt"
+ tmp=$(< $file)
+ if [ -z "$tmp" ]; then
+ echo " Process $i : unknown result (result file empty"
+ msg="failed"
+ else
+ res=${tmp:0:1}
+ if [ $res == "0" ]; then
+ echo " Process $i : OK - "${tmp:1}
+ else
+ echo " Process $i : failed - "${tmp:1}
+ msg="failed"
+ fi
+ fi
+ done
+ if [ -z $msg ]; then
+ __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
+ return 0
+ fi
+
+ __log_test_fail_general "One of more processes failed to execute"
+ return 1
+}
+
+# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
+# args: <response-code> <policy-id> [count]
+# (Function for test scripts)
+api_delete_policy() {
+ __log_test_start $@
+
+ if [ $# -lt 2 ] || [ $# -gt 3 ]; then
+ __print_err "<response-code> <policy-id> [count]" $@