X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Ftestcase_common.sh;h=ea940a18c38036804ca884a2a717ceef47ba1412;hb=647744d8ab625d28ea0ecda3e6741e23ba9b0bc7;hp=d694ef10c487742430293dd98cbeb8c37d822e18;hpb=e704d116cf5d97ca5faad93c536901f3351df93f;p=nonrtric.git diff --git a/test/common/testcase_common.sh b/test/common/testcase_common.sh index d694ef10..ea940a18 100755 --- a/test/common/testcase_common.sh +++ b/test/common/testcase_common.sh @@ -18,9 +18,17 @@ # # This is a script that contains all the functions needed for auto test -# Arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--ricsim-prefix ] [--use-local-image []*] +# Arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--ricsim-prefix ] [ --env-file ] [--use-local-image []*] +# Create a test case id, ATC (Auto Test Case), from the name of the test case script. +# FTC1.sh -> ATC == FTC1 +ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh) + +#Create result file (containing '1' for error) for this test case +#Will be replaced with a file containing '0' if all test cases pass +echo "1" > "$PWD/.result$ATC.txt" + #Formatting for 'echo' cmd BOLD="\033[1m" EBOLD="\033[0m" @@ -52,37 +60,18 @@ fi # Just resetting any previous echo formatting... echo -ne $EBOLD -# source test environment variables -. ../common/test_env.sh +# default test environment variables +TEST_ENV_VAR_FILE="" echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@ -#Vars for A1 interface version and container count -G1_A1_VERSION="" -G2_A1_VERSION="" -G3_A1_VERSION="" -G1_COUNT=0 -G2_COUNT=0 -G3_COUNT=0 - -# Vars to switch between http and https. Extra curl flag needed for https -export RIC_SIM_HTTPX="http" -export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:" -export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT -export RIC_SIM_CERT_MOUNT_DIR="./cert" - -export MR_HTTPX="http" -export MR_PORT=$MR_INTERNAL_PORT -export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker net - -export SDNC_HTTPX="http" -export SDNC_PORT=$SDNC_INTERNAL_PORT -export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net - #Localhost constant LOCALHOST="http://localhost:" -# Make curl retries for http response codes set in this env var, space separated list of codes +# Make curl retries towards ECS for http response codes set in this env var, space separated list of codes +ECS_RETRY_CODES="" + +# Make curl retries towards the agent for http response codes set in this env var, space separated list of codes AGENT_RETRY_CODES="" # Var to contol if the agent runs in a container (normal = 0) or as application on the local machine ( = 1) @@ -95,11 +84,17 @@ AUTO_CLEAN="" USE_LOCAL_IMAGES="" # List of available apps to override with local image -AVAILABLE_LOCAL_IMAGES_OVERRIDE="PA CP SDNC RICSIM" +AVAILABLE_LOCAL_IMAGES_OVERRIDE="PA ECS CP SDNC RICSIM" # Use this var (STOP_AT_ERROR=1 in the test script) for debugging/trouble shooting to take all logs and exit at first FAIL test case STOP_AT_ERROR=0 +# Function to indent cmd output with one space +indent1() { sed 's/^/ /'; } + +# Function to indent cmd output with two spaces +indent2() { sed 's/^/ /'; } + # Set a description string for the test case if [ -z "$TC_ONELINE_DESCR" ]; then TC_ONELINE_DESCR="" @@ -113,24 +108,22 @@ if [ -f .tmp_tcsuite_ctr ]; then echo $tmpval > .tmp_tcsuite_ctr fi -# Create a test case id, ATC (Auto Test Case), from the name of the test case script. -# FTC1.sh -> ATC == FTC1 -ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh) - # Create the logs dir if not already created in the current dir if [ ! -d "logs" ]; then mkdir logs fi TESTLOGS=$PWD/logs +# Create the tmp dir for temporary files that is not needed after the test +# hidden files for the test env is still stored in the current dir +if [ ! -d "tmp" ]; then + mkdir tmp +fi + # Create a http message log for this testcase HTTPLOG=$PWD"/.httplog_"$ATC".txt" echo "" > $HTTPLOG -#Create result file (containing '1' for error) for this test case -#Will be replaced with a file containing '0' if script is ok - -echo "1" > "$PWD/.result$ATC.txt" # Create a log dir for the test case mkdir -p $TESTLOGS/$ATC @@ -215,6 +208,19 @@ while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do fi fi fi + if [ $paramerror -eq 0 ]; then + if [ "$1" == "--env-file" ]; then + shift; + TEST_ENV_VAR_FILE=$1 + if [ -z "$1" ]; then + paramerror=1 + else + echo "Option set - Reading test env from: "$1 + shift; + foundparm=0 + fi + fi + fi if [ $paramerror -eq 0 ]; then if [ "$1" == "--use-local-image" ]; then USE_LOCAL_IMAGES="" @@ -243,33 +249,86 @@ if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then fi if [ $paramerror -eq 1 ]; then - echo -e $RED"Expected arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--ricsim-prefix ] [--use-local-image []*]"$ERED + echo -e $RED"Expected arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--ricsim-prefix ] [ --env-file ] [--use-local-image []*]"$ERED + exit 1 +fi + +# sourcing the selected env variables for the test case +if [ -f "$TEST_ENV_VAR_FILE" ]; then + echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD + . $TEST_ENV_VAR_FILE +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 +#Vars for A1 interface version and container count +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" +export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:" +export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT +export RIC_SIM_CERT_MOUNT_DIR="./cert" + +export MR_HTTPX="http" +export MR_PORT=$MR_INTERNAL_PORT +export MR_LOCAL_PORT=$MR_EXTERNAL_PORT #When agent is running outside the docker net + +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 PROD_STUB_HTTPX="http" +export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT +export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT #When CR is running outside the docker net +export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT + +export SDNC_HTTPX="http" +export SDNC_PORT=$SDNC_INTERNAL_PORT +export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net + echo -e $BOLD"Checking configured image setting for this test case"$EBOLD #Temp var to check for image variable name errors IMAGE_ERR=0 #Create a file with image info for later printing as a table -image_list_file=".image-list" +image_list_file="./tmp/.image-list" echo -e " Container\tImage\ttag" > $image_list_file # Check if image env var is set and if so export the env var with image to use (used by docker compose files) -# arg: