X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Fricsimulator_api_functions.sh;h=67a398e16adedfc386c33dc363f42c00f653f53b;hb=dddded37b9b321d041a1dc66a3a86112e37b918e;hp=049e43db502aca047ae0ae80731d508a7f33e567;hpb=acdd3f361ff7af58b0276789cc5148180a06e552;p=nonrtric.git diff --git a/test/common/ricsimulator_api_functions.sh b/test/common/ricsimulator_api_functions.sh index 049e43db..67a398e1 100644 --- a/test/common/ricsimulator_api_functions.sh +++ b/test/common/ricsimulator_api_functions.sh @@ -22,19 +22,16 @@ # Excute a curl cmd towards a ricsimulator and check the response code. -# args: [] +# args: __execute_curl_to_sim() { echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG echo " CMD: $2" >> $HTTPLOG - if [ $# -eq 3 ]; then - echo " FILE: $(<$3)" >> $HTTPLOG - fi res="$($2)" echo " RESP: $res" >> $HTTPLOG retcode=$? if [ $retcode -ne 0 ]; then echo " RETCODE: "$retcode - echo -e $RED" ERROR - fatal error when executing curl."$ERED + echo -e $RED" FAIL - fatal error when executing curl."$ERED return 1 fi status=${res:${#res}-3} @@ -42,7 +39,7 @@ __execute_curl_to_sim() { echo -e $GREEN" OK"$EGREEN return 0 fi - echo -e $RED" ERROR - expected http response: "$1" but got http response: "$status $ERED + echo -e $RED" FAIL - expected http response: "$1" but got http response: "$status $ERED return 1 } @@ -58,7 +55,7 @@ sim_equal() { if [ $# -eq 3 ] || [ $# -eq 4 ]; then app=$1 port=$(__find_sim_port $app) - __var_test $app "$LOCALHOST$port/counter/" $2 "=" $3 $4 + __var_test $app "$RIC_SIM_LOCALHOST$port/counter/" $2 "=" $3 $4 return 0 else ((RES_CONF_FAIL++)) @@ -79,7 +76,28 @@ sim_print() { fi app=$1 port=$(__find_sim_port $app) - echo -e $BOLD"INFO(${BASH_LINENO[0]}): $app, $2 = $(__do_curl $LOCALHOST$port/counter/$2)"$EBOLD + echo -e $BOLD"INFO(${BASH_LINENO[0]}): $app, $2 = $(__do_curl $RIC_SIM_LOCALHOST$port/counter/$2)"$EBOLD +} + +# Tests if a variable value in the RIC simulator contains the target string and and optional timeout +# Arg: - This test set pass or fail depending on if the variable contains +# the target or not. +# Arg: - This test waits up to the timeout seconds +# before setting pass or fail depending on if the variable value contains the target +# value or not. +# (Function for test scripts) +sim_contains_str() { + + if [ $# -eq 3 ] || [ $# -eq 4 ]; then + app=$1 + port=$(__find_sim_port $app) + __var_test $app "$RIC_SIM_LOCALHOST$port/counter/" $2 "contain_str" $3 $4 + return 0 + else + ((RES_CONF_FAIL++)) + __print_err "needs three or four args: [ timeout ]" + return 1 + fi } # Simulator API: Put a policy type in a ric @@ -95,9 +113,9 @@ sim_put_policy_type() { app=$2 res=$(__find_sim_port $app) - curlString="curl -X PUT -sw %{http_code} $LOCALHOST"$res"/policytype?id="$3" -H Content-Type:application/json --data-binary @"$4 + curlString="curl -X PUT -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/policytype?id="$3" -H Content-Type:application/json --data-binary @"$4 - __execute_curl_to_sim $1 "$curlString" $4 + __execute_curl_to_sim $1 "$curlString" return $? } @@ -114,7 +132,7 @@ sim_delete_policy_type() { app=$2 res=$(__find_sim_port $app) - curlString="curl -X DELETE -sw %{http_code} $LOCALHOST"$res"/policytype?id="$3 + curlString="curl -X DELETE -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/policytype?id="$3 __execute_curl_to_sim $1 "$curlString" return $? @@ -133,7 +151,7 @@ sim_post_delete_instances() { app=$2 res=$(__find_sim_port $app) - curlString="curl -X POST -sw %{http_code} $LOCALHOST"$res"/deleteinstances" + curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/deleteinstances" __execute_curl_to_sim $1 "$curlString" return $? @@ -152,7 +170,7 @@ sim_post_delete_all() { app=$2 res=$(__find_sim_port $app) - curlString="curl -X POST -sw %{http_code} $LOCALHOST"$res"/deleteall" + curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/deleteall" __execute_curl_to_sim $1 "$curlString" return $? @@ -171,7 +189,7 @@ sim_post_forcedresponse() { app=$2 res=$(__find_sim_port $app) - curlString="curl -X POST -sw %{http_code} $LOCALHOST"$res"/forceresponse" + curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/forceresponse" if [ $# -eq 3 ]; then curlString=$curlString"?code="$3 fi @@ -193,7 +211,7 @@ sim_post_forcedelay() { app=$2 res=$(__find_sim_port $app) - curlString="curl -X POST -sw %{http_code} $LOCALHOST$res/delay" + curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST$res/forcedelay" if [ $# -eq 3 ]; then curlString=$curlString"?delay="$3 fi