X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?p=bottlenecks.git;a=blobdiff_plain;f=run_tests.sh;h=9901269b54d87bd41ca1eb6ad9005ab61e2efd44;hp=c03b19880d48f16cec43eae16dd28ba4135819ec;hb=refs%2Fheads%2Fstable%2Feuphrates;hpb=655a917b161a458d3c4446e4e5e4b208a04f3ade diff --git a/run_tests.sh b/run_tests.sh index c03b1988..ec237a59 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -8,125 +8,112 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -usage="Script to run the tests in bottlenecks auto. +usage="Script to run the tests in Bottlenecks. usage: - bash $(basename "$0") [-h|--help] [-s ] + bash $(basename "$0") [-h|--help] [-s ] [-c ] [--report] [--cleanup] where: -h|--help show the help text - -r|--report push results to DB(true by default) - -s|--suite run specific test suite - one of the following: - rubbos, vstf + -s|--teststory run specific test story + one of the following: + (rubbos, vstf, posca_factor_test) + user can also define their own test story and pass as var to this file, + please refer to testsuites/posca/testsuite_story/ for details + -c|--testcase run specific test case + one of the following: + (posca_factor_system_bandwidth, posca_factor_ping) + --cleanup cleanup test dockers runing when test is done (false by default) + --report push results to DB (false by default) examples: - $(basename "$0") - $(basename "$0") -s rubbos" + $(basename "$0") -s posca_factor_test" -report=true +# Define global variables +Bottlenecks_key_dir="/home/opnfv/bottlenecks/utils/infra_setup" +POSCA_SUITE="/home/opnfv/bottlenecks/testsuites/posca" +POSCA_TESTCASE="/home/opnfv/bottlenecks/testsuites/posca/testcase_cfg" +POSCA_TESTSTORY="/home/opnfv/bottlenecks/testsuites/posca/testsuite_story" +BASEDIR=`dirname $0` -arr_test_suite=(rubbos vstf posca) +REPORT="False" +cleanup=false -Bottlenecks_key_dir="/home/opnfv/bottlenecks/utils/infra_setup" +# Define alias for log printing +info () { + logger -s -t "BOTTLENECKS INFO" "$*" +} -function check_testcase(){ - - check_suite="$1" - case $check_suite in - "-rubbos") - SUITE_PREFIX=$SUITE_PREFIX_CONFIG/rubbos/testcase_cfg - ;; - "-vstf") - SUITE_PREFIX=$SUITE_PREFIX_CONFIG/vstf/testcase_cfg - ;; - "-posca") - SUITE_PREFIX=$SUITE_PREFIX_CONFIG/posca/testcase_cfg - ;; - esac +error () { + logger -s -t "BOTTLENECKS ERROR" "$*" + exit 1 +} - TEST_CASE=$2 +# Define check_test function for test case/story list check +function check_test(){ - #find all the test case yaml files first - find $SUITE_PREFIX -name "*yaml" > /tmp/all_testcases.yaml - all_testcases_insuite=`cat /tmp/all_testcases.yaml | awk -F '/' '{print $NF}' | awk -F '.' '{print $1}'` - all_testcases=(${all_testcases_insuite}) + TEST_LEVEL="$1" + TEST_NAME="$2" - if [ "${TEST_CASE}" != "" ]; then - testcase_exec=(${TEST_CASE// /}) - for i in "${testcase_exec[@]}"; do - if [[ " ${all_testcases[*]} " != *" $i "* ]]; then - error "unknown test case: $i. available test cases are: ${all_test_cases[@]}" + if [[ "${TEST_LEVEL}" == "testcase" ]]; then + TEST_CONFIG="${POSCA_TESTCASE}" + else + if [[ "${TEST_LEVEL}" == "teststory" ]]; then + TEST_CONFIG="${POSCA_TESTSTORY}" + else + info "Invalid name for test level: testcase or teststory" + fi + fi + + # Find all the test case yaml files first + find $TEST_CONFIG -name "*yaml" > /tmp/all_tests.yaml + all_tests_insuite=`cat /tmp/all_tests.yaml | awk -F '/' '{print $NF}' | awk -F '.' '{print $1}'` + all_tests=(${all_tests_insuite}) + + if [ "${TEST_NAME}" != "" ]; then + TEST_EXEC=(${TEST_NAME// /}) + for i in "${TEST_EXEC[@]}"; do + if [[ " ${all_tests[*]} " != *" $i "* ]]; then + error "Unknown $TEST_LEVEL: $i. Available $TEST_LEVEL are: ${all_tests[@]}" fi done - info "tests to execute: ${TEST_CASE}." + info "Tests to execute: ${TEST_NAME}." else - error "lack of testcase name" + error "Lack of $TEST_LEVEL name" fi } + +# Define run test function function run_test(){ - test_suite=$1 - echo "Running test suite $test_suite" + test_exec=$1 - case $test_suite in + case $test_exec in "rubbos") - info "Running rubbos test suite" - test_file="/home/opnfv/bottlenecks/testsuites/rubbos/testsuite_story/rubbos_story1" - if [[ -f $test_file ]]; then - testcases=($(cat $test_file)) - else - error "no rubbos test suite file" - fi - - for i in "${testcases[@]}"; do - #check if the testcase is legal or not - check_testcase -rubbos $i - #adjust config parameters, different test suite has different methods, take rubbos as an example - #run test case, different test suite has different methods - file=${BASEDIR}/testsuites/rubbos/testcase_cfg/${i}.yaml - python /home/opnfv/bottlenecks/testsuites/rubbos/run_rubbos.py -c $file - done + info "After OPNFV Colorado release, Rubbos testsuite is not updating anymore. + This entrance for running Rubbos within Bottlenecks is no longer supported. + This testsuite is also not in the release plan with Bottlenecks since then. + If you want to run Rubbos, please refer to earlier releases." ;; "vstf") - info "Running vstf test suite" - test_file="/home/opnfv/bottlenecks/testsuites/vstf/testsuite_story/vstf_story1" - if [[ -f $test_file ]]; then - testcases=($(cat $test_file)) - else - error "no vstf test suite file " - fi - - for i in "${testcases[@]}"; do - #check if the testcase is legal or not - check_testcase -vstf $i - #adjust config parameters - #run test case - file=${BASEDIR}/testsuites/vstf/testcase_cfg/${i}.yaml - python /home/opnfv/bottlenecks/testsuites/vstf/run_vstf.py -c $file - done + info "After OPNFV Colorado release, VSTF testsuite is not updating anymore. + This entrance for running VSTF within Bottlenecks is no longer supported. + This testsuite is also not in the release plan with Bottlenecks since then. + If you want to run VSTF, please refer to earlier releases." ;; - "posca") - info "Running posca test suite" - test_file="/home/opnfv/bottlenecks/testsuites/posca/testsuite_story/posca_factor_test" - if [[ -f $test_file ]]; then - testcases=($(cat $test_file)) - else - error "no posca test suite file " - fi - - for i in "${testcases[@]}"; do - #check if the testcase is legal or not - check_testcase -posca $i - #adjust config parameters - #run test case - file=${BASEDIR}/testsuites/posca/testcase_cfg/${i}.yaml - python /home/opnfv/bottlenecks/testsuites/posca/run_posca.py -c ${i} - done + *) + info "Running posca $test_level: $test_exec" + opts="--privileged=true -id" + docker_volume="-v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp" + docker run $opts --name bottlenecks-load-master $docker_volume opnfv/bottlenecks:latest /bin/bash + sleep 5 + POSCA_SCRIPT="/home/opnfv/bottlenecks/testsuites/posca" + docker exec bottlenecks-load-master python ${POSCA_SCRIPT}/../run_testsuite.py ${test_level} ${test_exec} ${REPORT} ;; esac } +# Process input variables while [[ $# > 0 ]] do key="$1" @@ -136,13 +123,20 @@ while [[ $# > 0 ]] exit 0 shift ;; - -r|--report) - report="-r" + -s|--teststory) + teststory="$2" + shift ;; - -s|--suite) - SUITE="$2" + -c|--testcase) + testcase="$2" shift ;; + --report) + REPORT="True" + ;; + --cleanup) + cleanup=true + ;; *) echo "unkown option $1 $2" exit 1 @@ -151,39 +145,38 @@ while [[ $# > 0 ]] shift done -BASEDIR=`dirname $0` -source ${BASEDIR}/common.sh - -#Add random key generation -if [ ! -d $Bottlenecks_key_dir/bottlenecks_key ]; then - mkdir $Bottlenecks_key_dir/bottlenecks_key -else - rm -rf $Bottlenecks_key_dir/bottlenecks_key - mkdir $Bottlenecks_key_dir/bottlenecks_key -fi -chmod 700 $Bottlenecks_key_dir/bottlenecks_key - -ssh-keygen -t rsa -f $Bottlenecks_key_dir/bottlenecks_key/bottlenecks_key -q -N "" -chmod 600 $Bottlenecks_key_dir/bottlenecks_key/* - -#check the test suite name is correct -if [ "${SUITE}" != "" ]; then - suite_exec=(${SUITE//,/ }) - for i in "${suite_exec[@]}"; do - if [[ " ${arr_test_suite[*]} " != *" $i "* ]]; then - error "unkown test suite: $i" - fi +# Clean up related docker images +#bash ${BASEDIR}/docker/docker_cleanup.sh -d bottlenecks --debug +#bash ${BASEDIR}/docker/docker_cleanup.sh -d yardstick --debug +#bash ${BASEDIR}/docker/docker_cleanup.sh -d kibana --debug +#bash ${BASEDIR}/docker/docker_cleanup.sh -d elasticsearch --debug +#bash ${BASEDIR}/docker/docker_cleanup.sh -d influxdb --debug + +# Run tests +if [ "${teststory}" != "" ]; then + test_level="teststory" + teststory_exec=(${teststory//,/ }) + check_test $test_level $teststory + for i in "${teststory_exec[@]}"; do + info "Start to run test story $i" + run_test $i done - info "Tests to execute: ${SUITE}" fi -# Source credentials -info "Sourcing Credentials openstack.creds to run the tests.." -source /home/opnfv/bottlenecks/config/openstack.creds - -#run tests -if [ "${SUITE}" != "" ]; then - for i in "${suite_exec[@]}"; do +if [ "${testcase}" != "" ]; then + test_level="testcase" + testcase_exec=(${testcase//,/ }) + check_test $test_level $testcase + for i in "${testcase_exec[@]}"; do + info "Start to run test case $i" run_test $i done fi + +# Clean up testing dockers +if [[ ${cleanup} == true ]]; then + info "Cleaning up docker-compose images and dockers" + bash ${BASEDIR}/docker/docker_cleanup.sh -d influxdb --debug + bash ${BASEDIR}/docker/docker_cleanup.sh -d bottlenecks --debug + bash ${BASEDIR}/docker/docker_cleanup.sh -d yardstick --debug +fi