X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Ftestcase_common.sh;h=dd9e57ace4f78d401eed5812c8767a12a9c2dc1f;hb=7b36db6ef1b31daa41e115b7f199bb04f1cd0725;hp=ed02c7b10b4245a7fe4aa2608c0db3d335470110;hpb=b5cb68ea0e77d0a1421b4f17cc58b981628c29f7;p=nonrtric.git diff --git a/test/common/testcase_common.sh b/test/common/testcase_common.sh index ed02c7b1..dd9e57ac 100755 --- a/test/common/testcase_common.sh +++ b/test/common/testcase_common.sh @@ -61,7 +61,7 @@ fi echo -ne $EBOLD # default test environment variables -TEST_ENV_VAR_FILE="../common/test_env.sh" +TEST_ENV_VAR_FILE="" echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@ @@ -128,6 +128,17 @@ echo "" > $HTTPLOG # Create a log dir for the test case mkdir -p $TESTLOGS/$ATC +# Save create for current logs +mkdir -p $TESTLOGS/$ATC/previous + +rm $TESTLOGS/$ATC/previous/*.log &> /dev/null +rm $TESTLOGS/$ATC/previous/*.txt &> /dev/null +rm $TESTLOGS/$ATC/previous/*.json &> /dev/null + +mv $TESTLOGS/$ATC/*.log $TESTLOGS/$ATC/previous &> /dev/null +mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null +mv $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null + # Clear the log dir for the test case rm $TESTLOGS/$ATC/*.log &> /dev/null rm $TESTLOGS/$ATC/*.txt &> /dev/null @@ -148,6 +159,94 @@ RES_DEVIATION=0 DEVIATION_FILE=".tmp_deviations" rm $DEVIATION_FILE &> /dev/null + +# Trap "command not found" and make the script fail +trap_fnc() { + + if [ $? -eq 127 ]; then + echo -e $RED"Function not found, set script to FAIL"$ERED + ((RES_CONF_FAIL++)) + fi +} +trap trap_fnc ERR + +# Counter for tests +TEST_SEQUENCE_NR=1 + +__log_test_start() { + TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") + echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ $EBOLD + echo "TEST $TEST_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ >> $HTTPLOG + ((RES_TEST++)) + ((TEST_SEQUENCE_NR++)) +} + +__log_test_fail_general() { + echo -e $RED" FAIL."$1 $ERED + ((RES_FAIL++)) + __check_stop_at_error +} + +__log_test_fail_status_code() { + echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED + ((RES_FAIL++)) + __check_stop_at_error +} + +__log_test_fail_body() { + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error +} + +__log_test_fail_not_supported() { + echo -e $RED" FAIL, function not supported"$ERED + ((RES_FAIL++)) + __check_stop_at_error +} + +__log_test_pass() { + if [ $# -gt 0 ]; then + echo $@ + fi + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN +} + +#Counter for configurations +CONF_SEQUENCE_NR=1 +__log_conf_start() { + TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") + echo -e $BOLD"CONF $CONF_SEQUENCE_NR (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ $EBOLD + echo "CONF $CONF_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ >> $HTTPLOG + ((CONF_SEQUENCE_NR++)) +} + +__log_conf_fail_general() { + echo -e $RED" FAIL."$1 $ERED + ((RES_CONF_FAIL++)) + __check_stop_at_error +} + +__log_conf_fail_status_code() { + echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED + ((RES_CONF_FAIL++)) + __check_stop_at_error +} + +__log_conf_fail_body() { + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_CONF_FAIL++)) + __check_stop_at_error +} + +__log_conf_ok() { + if [ $# -gt 0 ]; then + echo $@ + fi + echo -e $GREEN" OK"$EGREEN +} + #Var for measuring execution time TCTEST_START=$SECONDS @@ -215,7 +314,7 @@ while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do if [ -z "$1" ]; then paramerror=1 else - echo "Option set - Overriding test_env.sh with: "$1 + echo "Option set - Reading test env from: "$1 shift; foundparm=0 fi @@ -257,8 +356,23 @@ fi if [ -f "$TEST_ENV_VAR_FILE" ]; then echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD . $TEST_ENV_VAR_FILE + + if [ -z "$TEST_ENV_PROFILE" ] || [ -z "$SUPPORTED_PROFILES" ]; then + echo -e $YELLOW"This test case may no work with selected test env file. TEST_ENV_PROFILE is missing in test_env file or SUPPORTED_PROFILES is missing in test case file"$EYELLOW + else + if [[ "$SUPPORTED_PROFILES" == *"$TEST_ENV_PROFILE"* ]]; then + echo -e $GREEN"Test case support the selected test env file"$EGREEN + else + echo -e $RED"Test case does not support the selected test env file"$ERED + echo -e $RED"Exiting...."$ERED + exit 1 + fi + fi else echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED + echo " Select one of following env var file matching the intended target of the test" + echo " Restart the test using the flag '--env-file " + ls ../common/test_env* | indent1 exit 1 fi @@ -266,9 +380,13 @@ fi G1_A1_VERSION="" G2_A1_VERSION="" G3_A1_VERSION="" +G4_A1_VERSION="" +G5_A1_VERSION="" G1_COUNT=0 G2_COUNT=0 G3_COUNT=0 +G4_COUNT=0 +G5_COUNT=0 # Vars to switch between http and https. Extra curl flag needed for https export RIC_SIM_HTTPX="http" @@ -283,6 +401,7 @@ export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker export CR_HTTPX="http" export CR_PORT=$CR_INTERNAL_PORT export CR_LOCAL_PORT=$CR_EXTERNAL_PORT #When CR is running outside the docker net +export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK" export PROD_STUB_HTTPX="http" export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT @@ -321,7 +440,7 @@ __check_image_var() { tag="${!5}" if [ -z $image ]; then - echo -e $RED"\$"$4" not set in test_env"$ERED + echo -e $RED"\$"$4" not set in $TEST_ENV_VAR_FILE"$ERED ((IMAGE_ERR++)) echo "" tmp=$tmp"\t" @@ -329,7 +448,7 @@ __check_image_var() { tmp=$tmp$image"\t" fi if [ -z $tag ]; then - echo -e $RED"\$"$5" not set in test_env"$ERED + echo -e $RED"\$"$5" not set in $TEST_ENV_VAR_FILE"$ERED ((IMAGE_ERR++)) echo "" tmp=$tmp"\t" @@ -464,13 +583,13 @@ if [ -z "$SIM_GROUP" ]; then SIM_GROUP=$PWD/../simulator-group if [ ! -d $SIM_GROUP ]; then echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed." - echo -e $RED"Please set the SIM_GROUP manually in the test_env.sh"$ERED + echo -e $RED"Please set the SIM_GROUP manually in the applicable $TEST_ENV_VAR_FILE"$ERED exit 1 else echo " SIM_GROUP auto set to: " $SIM_GROUP fi elif [ $SIM_GROUP = *simulator_group ]; then - echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check common/test_env.sh"$ERED + echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check $TEST_ENV_VAR_FILE"$ERED exit 1 else echo " SIM_GROUP env var already set to: " $SIM_GROUP @@ -660,13 +779,15 @@ if [ $? -eq 0 ]; then cd $curdir cd ../mrstub echo " Building mrstub image: $MRSTUB_LOCAL_IMAGE:$MRSTUB_LOCAL_IMAGE_TAG" - docker build -t $MRSTUB_LOCAL_IMAGE . &> .dockererr + docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $MRSTUB_LOCAL_IMAGE . &> .dockererr if [ $? -eq 0 ]; then echo -e $GREEN" Build Ok"$EGREEN else echo -e $RED" Build Failed"$ERED ((RES_CONF_FAIL++)) cat .dockererr + echo -e $RED"Exiting...."$ERED + exit 1 fi cd $curdir else @@ -677,13 +798,15 @@ __check_included_image 'CR' if [ $? -eq 0 ]; then cd ../cr echo " Building Callback Receiver image: $CR_LOCAL_IMAGE:$CR_IMAGE_TAG" - docker build -t $CR_LOCAL_IMAGE . &> .dockererr + docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $CR_LOCAL_IMAGE . &> .dockererr if [ $? -eq 0 ]; then echo -e $GREEN" Build Ok"$EGREEN else echo -e $RED" Build Failed"$ERED ((RES_CONF_FAIL++)) cat .dockererr + echo -e $RED"Exiting...."$ERED + exit 1 fi cd $curdir else @@ -694,13 +817,15 @@ __check_included_image 'PRODSTUB' if [ $? -eq 0 ]; then cd ../prodstub echo " Building Producer stub image: $PROD_STUB_LOCAL_IMAGE:$PROD_STUB_LOCAL_IMAGE_TAG" - docker build -t $PROD_STUB_LOCAL_IMAGE . &> .dockererr + docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $PROD_STUB_LOCAL_IMAGE . &> .dockererr if [ $? -eq 0 ]; then echo -e $GREEN" Build Ok"$EGREEN else echo -e $RED" Build Failed"$ERED ((RES_CONF_FAIL++)) cat .dockererr + echo -e $RED"Exiting...."$ERED + exit 1 fi cd $curdir else @@ -780,6 +905,7 @@ print_result() { echo "-------------------------------------------------------------------------------------------------" echo "-- Description: "$TC_ONELINE_DESCR echo "-- Execution time: " $duration " seconds" + echo "-- Used env file: "$TEST_ENV_VAR_FILE echo "-------------------------------------------------------------------------------------------------" echo "------------------------------------- RESULTS" echo "" @@ -1028,7 +1154,8 @@ clean_containers() { if [ $? -eq 0 ]; then if [ $CONTRS -ne 0 ]; then echo -e $RED"Containers running, may cause distubance to the test case"$ERED - docker ps -a + docker ps -a | indent1 + echo "" fi fi } @@ -1074,6 +1201,7 @@ __print_err() { if [ $# -gt 1 ]; then echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED fi + ((RES_CONF_FAIL++)) } @@ -1147,7 +1275,8 @@ __check_container_start() { ((RES_CONF_FAIL++)) echo "" echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED - return 1 + echo -e $RED" Stopping script..."$ERED + exit 1 fi if [ $localport -eq 0 ]; then while [ $localport -eq 0 ]; do @@ -1182,7 +1311,7 @@ __check_container_start() { else TS_TMP=$SECONDS while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do - echo -ne " Waiting for container ${appname} service status...retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}" + echo -ne " Waiting for container ${appname} service status...$(($SECONDS-$TSTART)) seconds, retrying in $(($TS_TMP+$i-$SECONDS)) seconds ${SAMELINE}" sleep 1 done fi @@ -1190,7 +1319,7 @@ __check_container_start() { if [ "$pa_st" = "false" ]; then ((RES_CONF_FAIL++)) - echo -e $RED" Container ${appname} did not respond to service status"$ERED + echo -e $RED" Container ${appname} did not respond to service status in $(($SECONDS-$TSTART)) seconds"$ERED return 0 fi @@ -1221,6 +1350,8 @@ __start_container() { if [ $? -ne 0 ]; then echo -e $RED"Problem to launch container(s) with docker-compose"$ERED cat .dockererr + echo -e $RED"Stopping script...."$ERED + exit 1 fi elif [ "$2" == "STANDALONE" ]; then echo "Skipping docker-compose" @@ -1229,6 +1360,8 @@ __start_container() { if [ $? -ne 0 ]; then echo -e $RED"Problem to launch container(s) with docker-compose"$ERED cat .dockererr + echo -e $RED"Stopping script...."$ERED + exit 1 fi fi app_prefix="" @@ -1439,7 +1572,8 @@ start_consul_cbs() { ########################### use_simulator_http() { - echo -e "Using $BOLD http $EBOLD towards the simulators" + echo -e $BOLD"RICSIM protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD towards the simulators" export RIC_SIM_HTTPX="http" export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:" export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT @@ -1447,16 +1581,17 @@ use_simulator_http() { } use_simulator_https() { - echo -e "Using $BOLD https $EBOLD towards the simulators" + echo -e $BOLD"RICSIM protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD towards the simulators" export RIC_SIM_HTTPX="https" export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:" export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT echo "" } -# Start one group (ricsim_g1, ricsim_g2 or ricsim_g3) with a number of RIC Simulators using a given A interface +# Start one group (ricsim_g1, ricsim_g2 .. ricsim_g5) with a number of RIC Simulators using a given A interface # 'ricsim' may be set on command line to other prefix -# args: ricsim_g1|ricsim_g2|ricsim_g3 +# args: ricsim_g1|ricsim_g2|ricsim_g3|ricsim_g4|ricsim_g5 # (Function for test scripts) start_ric_simulators() { @@ -1472,10 +1607,12 @@ start_ric_simulators() { RIC1=$RIC_SIM_PREFIX"_g1" RIC2=$RIC_SIM_PREFIX"_g2" RIC3=$RIC_SIM_PREFIX"_g3" + RIC4=$RIC_SIM_PREFIX"_g4" + RIC5=$RIC_SIM_PREFIX"_g5" if [ $# != 3 ]; then ((RES_CONF_FAIL++)) - __print_err "need three args, $RIC1|$RIC2|$RIC3 " $@ + __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 " $@ exit 1 fi echo " $2 simulators using basename: $1 on interface: $3" @@ -1489,9 +1626,15 @@ start_ric_simulators() { elif [ $1 == "$RIC3" ]; then G3_COUNT=$2 G3_A1_VERSION=$3 + elif [ $1 == "$RIC4" ]; then + G4_COUNT=$2 + G4_A1_VERSION=$3 + elif [ $1 == "$RIC5" ]; then + G5_COUNT=$2 + G5_A1_VERSION=$3 else ((RES_CONF_FAIL++)) - __print_err "need three args, $RIC1|$RIC2|$RIC3 " $@ + __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 " $@ exit 1 fi @@ -1501,8 +1644,10 @@ start_ric_simulators() { export G1_A1_VERSION export G2_A1_VERSION export G3_A1_VERSION + export G4_A1_VERSION + export G5_A1_VERSION - docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT" + docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT --scale g4=$G4_COUNT --scale g5=$G5_COUNT" app_data="" cntr=1 while [ $cntr -le $2 ]; do @@ -1558,7 +1703,8 @@ start_sdnc() { } use_sdnc_http() { - echo -e "Using $BOLD http $EBOLD towards SDNC" + echo -e $BOLD"SDNC protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD towards SDNC" export SDNC_HTTPX="http" export SDNC_PORT=$SDNC_INTERNAL_PORT export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT @@ -1566,7 +1712,8 @@ use_sdnc_http() { } use_sdnc_https() { - echo -e "Using $BOLD https $EBOLD towards SDNC" + echo -e $BOLD"SDNC protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD towards SDNC" export SDNC_HTTPX="https" export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT @@ -1594,7 +1741,8 @@ start_mr() { } use_mr_http() { - echo -e "Using $BOLD http $EBOLD towards MR" + echo -e $BOLD"MR protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD towards MR" export MR_HTTPX="http" export MR_PORT=$MR_INTERNAL_PORT export MR_LOCAL_PORT=$MR_EXTERNAL_PORT @@ -1602,7 +1750,8 @@ use_mr_http() { } use_mr_https() { - echo -e "Using $BOLD https $EBOLD towards MR" + echo -e $BOLD"MR protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD towards MR" export MR_HTTPX="https" export MR_PORT=$MR_INTERNAL_SECURE_PORT export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT @@ -1631,18 +1780,22 @@ start_cr() { } use_cr_http() { - echo -e "Using $BOLD http $EBOLD towards CR" + echo -e $BOLD"CR protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD towards CR" export CR_HTTPX="http" export CR_PORT=$CR_INTERNAL_PORT export CR_LOCAL_PORT=$CR_EXTERNAL_PORT + export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK" echo "" } use_cr_https() { - echo -e "Using $BOLD https $EBOLD towards CR" + echo -e $BOLD"CR protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD towards CR" export CR_HTTPX="https" export CR_PORT=$CR_INTERNAL_SECURE_PORT export CR_LOCAL_PORT=$CR_EXTERNAL_SECURE_PORT + export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK" echo "" } @@ -1667,7 +1820,8 @@ start_prod_stub() { } use_prod_stub_http() { - echo -e "Using $BOLD http $EBOLD towards Producer stub" + echo -e $BOLD"Producer stub protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD towards Producer stub" export PROD_STUB_HTTPX="http" export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT @@ -1676,7 +1830,8 @@ use_prod_stub_http() { } use_prod_stub_https() { - echo -e "Using $BOLD https $EBOLD towards Producer stub" + echo -e $BOLD"Producer stub protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD towards Producer stub" export PROD_STUB_HTTPX="https" export PROD_STUB_PORT=$PROD_STUB_INTERNAL_SECURE_PORT export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_SECURE_PORT @@ -1725,7 +1880,8 @@ start_policy_agent() { # args: - # (Function for test scripts) use_agent_rest_http() { - echo -e "Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent" + echo -e $BOLD"Agent protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent" export ADAPTER=$RESTBASE echo "" } @@ -1734,7 +1890,8 @@ use_agent_rest_http() { # args: - # (Function for test scripts) use_agent_rest_https() { - echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent" + echo -e $BOLD"Agent protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent" export ADAPTER=$RESTBASE_SECURE echo "" return 0 @@ -1744,7 +1901,8 @@ use_agent_rest_https() { # args: - # (Function for test scripts) use_agent_dmaap_http() { - echo -e "Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent" + echo -e $BOLD"Agent dmaap protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent" export ADAPTER=$DMAAPBASE echo "" return 0 @@ -1754,7 +1912,8 @@ use_agent_dmaap_http() { # args: - # (Function for test scripts) use_agent_dmaap_https() { - echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent" + echo -e $BOLD"Agent dmaap protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent" export ADAPTER=$DMAAPBASE_SECURE echo "" return 0 @@ -1764,8 +1923,12 @@ use_agent_dmaap_https() { # args: - # (Function for test scripts) set_agent_debug() { - echo -e $BOLD"Setting agent debug"$EBOLD - curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}" + echo -e $BOLD"Setting agent debug logging"$EBOLD + actuator="/actuator/loggers/org.oransc.policyagent" + if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then + actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice" + fi + curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}" result=$(__do_curl "$curlString") if [ $? -ne 0 ]; then __print_err "could not set debug mode" $@ @@ -1780,8 +1943,12 @@ set_agent_debug() { # args: - # (Function for test scripts) set_agent_trace() { - echo -e $BOLD"Setting agent trace"$EBOLD - curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}" + echo -e $BOLD"Setting agent trace logging"$EBOLD + actuator="/actuator/loggers/org.oransc.policyagent" + if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then + actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice" + fi + curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}" result=$(__do_curl "$curlString") if [ $? -ne 0 ]; then __print_err "could not set trace mode" $@ @@ -1812,6 +1979,25 @@ use_agent_retries() { start_ecs() { echo -e $BOLD"Starting ECS"$EBOLD + + curdir=$PWD + cd $SIM_GROUP + cd ecs + cd $ECS_HOST_MNT_DIR + if [ -d database ]; then + if [ "$(ls -A $DIR)" ]; then + echo -e $BOLD" Cleaning files in mounted dir: $PWD/database"$EBOLD + rm -rf database/* &> /dev/null + if [ $? -ne 0 ]; then + echo -e $RED" Cannot remove database files in: $PWD"$ERED + exit 1 + fi + fi + else + echo " No files in mounted dir or dir does not exists" + fi + cd $curdir + __check_included_image 'ECS' if [ $? -eq 1 ]; then echo -e $RED"The ECS image has not been checked for this test run due to arg to the test script"$ERED @@ -1822,11 +2008,30 @@ start_ecs() { __start_container ecs NODOCKERARGS $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http" } +# Restart ECS +# args: - +# (Function for test scripts) +restart_ecs() { + echo -e $BOLD"Re-starting ECS"$EBOLD + docker restart $ECS_APP_NAME &> ./tmp/.dockererr + if [ $? -ne 0 ]; then + __print_err "Could restart $ECS_APP_NAME" $@ + cat ./tmp/.dockererr + ((RES_CONF_FAIL++)) + return 1 + fi + + __check_container_start $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http" + echo "" + return 0 +} + # All calls to ECS will be directed to the ECS REST interface from now on # args: - # (Function for test scripts) use_ecs_rest_http() { - echo -e "Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS" + echo -e $BOLD"ECS protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS" export ECS_ADAPTER=$ECS_RESTBASE echo "" } @@ -1835,7 +2040,8 @@ use_ecs_rest_http() { # args: - # (Function for test scripts) use_ecs_rest_https() { - echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS" + echo -e $BOLD"ECS protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS" export ECS_ADAPTER=$ECS_RESTBASE_SECURE echo "" return 0 @@ -1845,7 +2051,9 @@ use_ecs_rest_https() { # args: - # (Function for test scripts) use_ecs_dmaap_http() { - echo -e "Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS" + echo -e $BOLD"ECS dmaap protocol setting"$EBOLD + echo -e $RED" - NOT SUPPORTED - "$ERED + echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS" export ECS_ADAPTER=$ECS_DMAAPBASE echo "" return 0 @@ -1855,7 +2063,9 @@ use_ecs_dmaap_http() { # args: - # (Function for test scripts) use_ecs_dmaap_https() { - echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS" + echo -e $BOLD"RICSIM protocol setting"$EBOLD + echo -e $RED" - NOT SUPPORTED - "$ERED + echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS" export ECS_ADAPTER=$ECS_DMAAPBASE_SECURE echo "" return 0 @@ -1865,7 +2075,7 @@ use_ecs_dmaap_https() { # args: - # (Function for test scripts) set_ecs_debug() { - echo -e $BOLD"Setting ecs debug"$EBOLD + echo -e $BOLD"Setting ecs debug logging"$EBOLD curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}" result=$(__do_curl "$curlString") if [ $? -ne 0 ]; then @@ -1881,7 +2091,7 @@ set_ecs_debug() { # args: - # (Function for test scripts) set_ecs_trace() { - echo -e $BOLD"Setting ecs trace"$EBOLD + echo -e $BOLD"Setting ecs trace logging"$EBOLD curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}" result=$(__do_curl "$curlString") if [ $? -ne 0 ]; then @@ -1975,7 +2185,7 @@ store_logs() { __print_err "need one arg, " $@ exit 1 fi - echo -e $BOLD"Storing all container logs using prefix: "$1$EBOLD + echo -e $BOLD"Storing all container logs in $TESTLOGS/$ATC using prefix: "$1$EBOLD docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1 @@ -2031,6 +2241,11 @@ store_logs() { done fi + __check_included_image 'PRODSTUB' + if [ $? -eq 0 ]; then + docker logs $PROD_STUB_APP_NAME > $TESTLOGS/$ATC/$1_prodstub.log 2>&1 + fi + echo "" } @@ -2053,7 +2268,6 @@ __do_curl() { echo "" return 1 else - echo "X2" >> $HTTPLOG return 0 fi else @@ -2091,8 +2305,9 @@ __var_test() { checkjsonarraycount=1 fi - echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD + echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD ((RES_TEST++)) + ((TEST_SEQUENCE_NR++)) start=$SECONDS ctr=0 for (( ; ; )); do @@ -2152,8 +2367,9 @@ __var_test() { checkjsonarraycount=1 fi - echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD + echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD ((RES_TEST++)) + ((TEST_SEQUENCE_NR++)) if [ $checkjsonarraycount -eq 0 ]; then result="$(__do_curl $2$3)" retcode=$? @@ -2196,22 +2412,6 @@ __var_test() { ### Generic test cases for varaible checking -# Tests if a variable value in the CR is equal to a target value and and optional timeout. -# Arg: - This test set pass or fail depending on if the variable is -# equal to the target or not. -# Arg: - This test waits up to the timeout seconds -# before setting pass or fail depending on if the variable value becomes equal to the target -# value or not. -# (Function for test scripts) -cr_equal() { - if [ $# -eq 2 ] || [ $# -eq 3 ]; then - __var_test "CR" "$LOCALHOST$CR_EXTERNAL_PORT/counter/" $1 "=" $2 $3 - else - ((RES_CONF_FAIL++)) - __print_err "Wrong args to cr_equal, needs two or three args: [ timeout ]" $@ - fi -} - # Tests if a variable value in the MR stub is equal to a target value and and optional timeout. # Arg: - This test set pass or fail depending on if the variable is # equal to the target or not.