X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Fricsimulator_api_functions.sh;h=2a68aa0ef05e9dec643535ca4a2db475cc46a426;hb=32157220c43100bd0ab49da4f6232348ee2e99fe;hp=049e43db502aca047ae0ae80731d508a7f33e567;hpb=34882342628629b55c19e7f6a5369de045ab9102;p=nonrtric.git diff --git a/test/common/ricsimulator_api_functions.sh b/test/common/ricsimulator_api_functions.sh index 049e43db..2a68aa0e 100644 --- a/test/common/ricsimulator_api_functions.sh +++ b/test/common/ricsimulator_api_functions.sh @@ -22,19 +22,17 @@ # 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 + ((RES_CONF_FAIL++)) 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 +40,8 @@ __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 + ((RES_CONF_FAIL++)) return 1 } @@ -56,12 +55,10 @@ __execute_curl_to_sim() { sim_equal() { if [ $# -eq 3 ] || [ $# -eq 4 ]; then - app=$1 - port=$(__find_sim_port $app) - __var_test $app "$LOCALHOST$port/counter/" $2 "=" $3 $4 + port=$(__find_sim_port $1) + __var_test $1 "$RIC_SIM_LOCALHOST$port/counter/" $2 "=" $3 $4 return 0 else - ((RES_CONF_FAIL++)) __print_err "needs three or four args: [ timeout ]" return 1 fi @@ -73,49 +70,58 @@ sim_equal() { sim_print() { if [ $# != 2 ]; then - ((RES_CONF_FAIL++)) __print_err "need two args, " $@ exit 1 fi - app=$1 - port=$(__find_sim_port $app) - echo -e $BOLD"INFO(${BASH_LINENO[0]}): $app, $2 = $(__do_curl $LOCALHOST$port/counter/$2)"$EBOLD + port=$(__find_sim_port $1) + echo -e $BOLD"INFO(${BASH_LINENO[0]}): $1, $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 + port=$(__find_sim_port $1) + __var_test $1 "$RIC_SIM_LOCALHOST$port/counter/" $2 "contain_str" $3 $4 + return 0 + else + __print_err "needs three or four args: [ timeout ]" + return 1 + fi } # Simulator API: Put a policy type in a ric # args: # (Function for test scripts) sim_put_policy_type() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + __log_conf_start $@ if [ $# -ne 4 ]; then - ((RES_CONF_FAIL++)) __print_err " " $@ return 1 fi - 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 - - __execute_curl_to_sim $1 "$curlString" $4 + res=$(__find_sim_port $2) + 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" return $? } -# DSimulator API: Delete a policy type in a ric +# Simulator API: Delete a policy type in a ric # # (Function for test scripts) sim_delete_policy_type() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + __log_conf_start $@ if [ $# -ne 3 ]; then - ((RES_CONF_FAIL++)) __print_err " " $@ return 1 fi - app=$2 - res=$(__find_sim_port $app) - - curlString="curl -X DELETE -sw %{http_code} $LOCALHOST"$res"/policytype?id="$3 - + res=$(__find_sim_port $2) + curlString="curl -X DELETE -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/policytype?id="$3 __execute_curl_to_sim $1 "$curlString" return $? } @@ -124,17 +130,13 @@ sim_delete_policy_type() { # # (Function for test scripts) sim_post_delete_instances() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + __log_conf_start $@ if [ $# -ne 2 ]; then - ((RES_CONF_FAIL++)) __print_err " " $@ return 1 fi - app=$2 - res=$(__find_sim_port $app) - - curlString="curl -X POST -sw %{http_code} $LOCALHOST"$res"/deleteinstances" - + res=$(__find_sim_port $2) + curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/deleteinstances" __execute_curl_to_sim $1 "$curlString" return $? } @@ -143,17 +145,13 @@ sim_post_delete_instances() { # # (Function for test scripts) sim_post_delete_all() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + __log_conf_start $@ if [ $# -ne 3 ]; then - ((RES_CONF_FAIL++)) __print_err " " $@ return 1 fi - app=$2 - res=$(__find_sim_port $app) - - curlString="curl -X POST -sw %{http_code} $LOCALHOST"$res"/deleteall" - + res=$(__find_sim_port $2) + curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/deleteall" __execute_curl_to_sim $1 "$curlString" return $? } @@ -162,20 +160,16 @@ sim_post_delete_all() { # [] # (Function for test scripts) sim_post_forcedresponse() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + __log_conf_start $@ if [ $# -ne 3 ]; then - ((RES_CONF_FAIL++)) __print_err " " $@ return 1 fi - app=$2 - res=$(__find_sim_port $app) - - curlString="curl -X POST -sw %{http_code} $LOCALHOST"$res"/forceresponse" + res=$(__find_sim_port $2) + curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/forceresponse" if [ $# -eq 3 ]; then curlString=$curlString"?code="$3 fi - __execute_curl_to_sim $1 "$curlString" return $? } @@ -184,20 +178,16 @@ sim_post_forcedresponse() { # [] # (Function for test scripts) sim_post_forcedelay() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + __log_conf_start $@ if [ $# -ne 3 ]; then - ((RES_CONF_FAIL++)) __print_err " []" $@ return 1 fi - app=$2 - res=$(__find_sim_port $app) - - curlString="curl -X POST -sw %{http_code} $LOCALHOST$res/delay" + res=$(__find_sim_port $2) + curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST$res/forcedelay" if [ $# -eq 3 ]; then curlString=$curlString"?delay="$3 fi - __execute_curl_to_sim $1 "$curlString" return $? } \ No newline at end of file