X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?p=bottlenecks.git;a=blobdiff_plain;f=run_tests.sh;h=9901269b54d87bd41ca1eb6ad9005ab61e2efd44;hp=798a5bac6b379e804aaeac9e7b46fa1a8b266243;hb=refs%2Fheads%2Fstable%2Feuphrates;hpb=fc9a89857e121c2015a34e49c441cb234fa10c13 diff --git a/run_tests.sh b/run_tests.sh index 798a5bac..ec237a59 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -8,62 +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, posca + -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 posca" + $(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" "$*" +} + +error () { + logger -s -t "BOTTLENECKS ERROR" "$*" + exit 1 +} +# Define check_test function for test case/story list check +function check_test(){ + + TEST_LEVEL="$1" + TEST_NAME="$2" + + 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_NAME}." + else + 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 "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.\n" + 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 "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.\n" + 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") - POSCA_SCRIPT=/home/opnfv/bottlenecks/testsuites/posca - TEST_CASE=posca_factor_system_bandwidth - info "Composing up dockers" - docker-compose -f /home/opnfv/bottlenecks/docker/bottleneck-compose/docker-compose.yml up -d - info "Pulling tutum/influxdb for yardstick" - docker pull tutum/influxdb:0.13 - info "Copying testing scripts to docker" - docker cp /home/opnfv/bottlenecks/run_posca.sh bottleneckcompose_bottlenecks_1:/home/opnfv/bottlenecks + *) + 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 - info "Running posca test suite with default testcase posca_stress_traffic" - docker exec bottleneckcompose_bottlenecks_1 python ${POSCA_SCRIPT}/run_posca.py testcase $TEST_CASE + 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" @@ -73,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 @@ -88,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