X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Ftestcase_common.sh;h=3ed51c911b9268f2590b53a1f9c49118fa23e2d5;hb=refs%2Fchanges%2F23%2F9023%2F2;hp=57344fb25cf6ba97f2b2cad62012f39a7955d88c;hpb=99a769b52cf20bca4803320df819af0133330baa;p=nonrtric.git diff --git a/test/common/testcase_common.sh b/test/common/testcase_common.sh index 57344fb2..194a3072 100755 --- a/test/common/testcase_common.sh +++ b/test/common/testcase_common.sh @@ -17,9 +17,73 @@ # ============LICENSE_END================================================= # -# This is a script that contains all the functions needed for auto test -# Arg: local|remote|remote-remove [auto-clean] +# This is a script that contains all the common functions needed for auto test. +# Specific test function are defined in scripts XXXX_functions.sh + +. ../common/api_curl.sh +. ../common/testengine_config.sh + +__print_args() { + echo "Args: remote|remote-remove docker|kube --env-file [release] [auto-clean] [--stop-at-error] " + echo " [--ricsim-prefix ] [--use-local-image +] [--use-snapshot-image +]" + echo " [--use-staging-image +] [--use-release-image +] [--use-external-image +] [--image-repo ]" + echo " [--repo-policy local|remote] [--cluster-timeout ] [--print-stats]" + echo " [--override ] [--pre-clean] [--gen-stats] [--delete-namespaces]" + echo " [--delete-containers] [--endpoint-stats] [--kubeconfig ] [--host-path-dir ]" + echo " [--kubecontext ] [--docker-host ] [--docker-proxy ]" +} + +if [ $# -eq 1 ] && [ "$1" == "help" ]; then + + if [ ! -z "$TC_ONELINE_DESCR" ]; then + echo "Test script description:" + echo $TC_ONELINE_DESCR + echo "" + fi + __print_args + echo "" + echo "remote - Use images from remote repositories. Can be overridden for individual images using the '--use_xxx' flags" + echo "remote-remove - Same as 'remote' but will also try to pull fresh images from remote repositories" + echo "docker - Test executed in docker environment" + echo "kube - Test executed in kubernetes environment - requires an already started kubernetes environment" + echo "--env-file - The script will use the supplied file to read environment variables from" + echo "release - If this flag is given the script will use release version of the images" + echo "auto-clean - If the function 'auto_clean_containers' is present in the end of the test script then all containers will be stopped and removed. If 'auto-clean' is not given then the function has no effect." + echo "--stop-at-error - The script will stop when the first failed test or configuration" + echo "--ricsim-prefix - The a1 simulator will use the supplied string as container prefix instead of 'ricsim'" + echo "--use-local-image - The script will use local images for the supplied apps, space separated list of app short names" + echo "--use-snapshot-image - The script will use images from the nexus snapshot repo for the supplied apps, space separated list of app short names" + echo "--use-staging-image - The script will use images from the nexus staging repo for the supplied apps, space separated list of app short names" + echo "--use-release-image - The script will use images from the nexus release repo for the supplied apps, space separated list of app short names" + echo "--use-external-image - The script will use images from the external (non oran/onap) repo for the supplied apps, space separated list of app short names" + echo "--image-repo - Url to optional image repo. Only locally built images will be re-tagged and pushed to this repo" + echo "--repo-policy - Policy controlling which images to re-tag and push if param --image-repo is set. Default is 'local'" + echo "--cluster-timeout - Optional timeout for cluster where it takes time to obtain external ip/host-name. Timeout in seconds. " + echo "--print-stats - Print current test stats after each test." + echo "--override - Override setting from the file supplied by --env-file" + echo "--pre-clean - Will clean kube resouces when running docker and vice versa" + echo "--gen-stats - Collect container/pod runtime statistics" + echo "--delete-namespaces - Delete kubernetes namespaces before starting tests - but only those created by the test scripts. Kube mode only. Ignored if running with prestarted apps." + echo "--delete-containers - Delete docker containers before starting tests - but only those created by the test scripts. Docker mode only." + echo "--endpoint-stats - Collect endpoint statistics" + echo "--kubeconfig - Configure kubectl to use cluster specific cluster config file" + echo "--host-path-dir - (Base-)path on local-hostmounted to all VMs (nodes), for hostpath volumes in kube" + echo "--kubecontext - Configure kubectl to use a certain context, e.g 'minikube'" + echo "--docker-host - Configure docker to use docker in e.g. a VM" + echo "--docker-proxy - Configure ip/host to docker when docker is running in a VM" + echo "" + echo "List of app short names supported: "$APP_SHORT_NAMES + exit 0 +fi +AUTOTEST_HOME=$PWD +# 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" @@ -32,58 +96,55 @@ YELLOW="\033[33m\033[1m" EYELLOW="\033[0m" SAMELINE="\033[0K\r" -tmp=$(which python3) -if [ $? -ne 0 ] || [ -z tmp ]; then - echo -e $RED"python3 is required to run the test environment, pls install"$ERED - exit 1 -fi -tmp=$(which docker) -if [ $? -ne 0 ] || [ -z tmp ]; then - echo -e $RED"docker is required to run the test environment, pls install"$ERED - exit 1 -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="" +#Override env file, will be added on top of the above file +TEST_ENV_VAR_FILE_OVERRIDE="" 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 +# Var to hold 'auto' in case containers shall be stopped when test case ends +AUTO_CLEAN="" -# 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" +# Var to indicate pre clean, if flag --pre-clean is set the script will clean kube resouces when running docker and vice versa +PRE_CLEAN="0" -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 +# Var to hold the app names to use local images for +USE_LOCAL_IMAGES="" -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 +# Var to hold the app names to use remote snapshot images for +USE_SNAPSHOT_IMAGES="" -#Localhost constant -LOCALHOST="http://localhost:" +# Var to hold the app names to use remote staging images for +USE_STAGING_IMAGES="" -# Make curl retries for http response codes set in this env var, space separated list of codes -AGENT_RETRY_CODES="" +# Var to hold the app names to use remote release images for +USE_RELEASE_IMAGES="" -# Var to contol if the agent runs in a container (normal = 0) or as application on the local machine ( = 1) -AGENT_STAND_ALONE=0 +# Var to hold the app names to use external release images for +USE_EXTERNAL_IMAGES="" -# Var to hold 'auto' in case containers shall be stopped when test case ends -AUTO_CLEAN="" +# 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 + +# The default value "DEV" indicate that development image tags (SNAPSHOT) and nexus repos (nexus port 10002) are used. +# The value "RELEASE" indicate that relase image tag and nexus repos (nexus port) are used +# Applies only to images defined in the test-env files with image names and tags defined as XXXX_RELEASE +IMAGE_CATEGORY="DEV" + +#Var to indicate docker-compose version, V1 or V2 +#V1 names replicated containers __ +#V2 names replicated containers -- +DOCKER_COMPOSE_VERSION="V1" + +# 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 @@ -98,16 +159,64 @@ 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 +# files in the ./tmp is moved to ./tmp/prev when a new test is started +if [ ! -d "tmp" ]; then + mkdir tmp + if [ $? -ne 0 ]; then + echo "Cannot create dir for temp files, $PWD/tmp" + echo "Exiting...." + exit 1 + fi +fi +curdir=$PWD +cd tmp +if [ $? -ne 0 ]; then + echo "Cannot cd to $PWD/tmp" + echo "Exiting...." + exit 1 +fi + +TESTENV_TEMP_FILES=$PWD + +if [ ! -d "prev" ]; then + mkdir prev + if [ $? -ne 0 ]; then + echo "Cannot create dir for previous temp files, $PWD/prev" + echo "Exiting...." + exit 1 + fi +fi + +TMPFILES=$(ls -A | grep -vw prev) +if [ ! -z "$TMPFILES" ]; then + cp -r $TMPFILES prev #Move all temp files to prev dir + if [ $? -ne 0 ]; then + echo "Cannot move temp files in $PWD to previous temp files in, $PWD/prev" + echo "Exiting...." + exit 1 + fi + if [ $(pwd | xargs basename) == "tmp" ]; then #Check that current dir is tmp...for safety + + rm -rf $TMPFILES # Remove all temp files + fi +fi + +cd $curdir +if [ $? -ne 0 ]; then + echo "Cannot cd to $curdir" + echo "Exiting...." + exit 1 +fi + + # Create a http message log for this testcase HTTPLOG=$PWD"/.httplog_"$ATC".txt" echo "" > $HTTPLOG @@ -115,11 +224,25 @@ 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 rm $TESTLOGS/$ATC/*.json &> /dev/null +#Create result file in the log dir +echo "1" > "$TESTLOGS/$ATC/.result$ATC.txt" + # Log all output from the test case to a TC log TCLOG=$TESTLOGS/$ATC/TC.log exec &> >(tee ${TCLOG}) @@ -131,330 +254,1659 @@ RES_FAIL=0 RES_CONF_FAIL=0 RES_DEVIATION=0 -#File to keep deviation messages -DEVIATION_FILE=".tmp_deviations" -rm $DEVIATION_FILE &> /dev/null +#Var to control if current stats shall be printed +PRINT_CURRENT_STATS=0 -#Var for measuring execution time -TCTEST_START=$SECONDS +#Var to control if container/pod runtim statistics shall be collected +COLLECT_RUNTIME_STATS=0 +COLLECT_RUNTIME_STATS_PID=0 -#File to save timer measurement results -TIMER_MEASUREMENTS=".timer_measurement.txt" -echo -e "Activity \t Duration" > $TIMER_MEASUREMENTS +#Var to control if endpoint statistics shall be collected +COLLECT_ENDPOINT_STATS=0 +#Var to control if namespaces shall be delete before test setup +DELETE_KUBE_NAMESPACES=0 -echo "-------------------------------------------------------------------------------------------------" -echo "----------------------------------- Test case: "$ATC -echo "----------------------------------- Started: "$(date) -echo "-------------------------------------------------------------------------------------------------" -echo "-- Description: "$TC_ONELINE_DESCR -echo "-------------------------------------------------------------------------------------------------" -echo "----------------------------------- Test case setup -----------------------------------" +#Var to control if containers shall be delete before test setup +DELETE_CONTAINERS=0 -echo -e $BOLD"Checking configured image setting for this test case"$EBOLD +#Var to configure kubectl from a config file or context +KUBECONF="" -#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" -echo -e " Container\tImage\ttag" > $image_list_file +#Localhost, may be set to another host/ip by cmd parameter +LOCALHOST_NAME="localhost" -# Check if image env var is set and if so export the env var with image to use (used by docker compose files) -# arg: