Add test name check function and cleanup 19/35119/4
authoryuyang <Gabriel.yuyang@huawei.com>
Mon, 22 May 2017 02:23:55 +0000 (10:23 +0800)
committeryuyang <Gabriel.yuyang@huawei.com>
Tue, 23 May 2017 03:39:37 +0000 (11:39 +0800)
JIRA: BOTTLENECK-158

Add test case/story name check and cleanup environment option.

Change-Id: I07609c089ca78b0d2760c09c0312d7d1106c815a
Signed-off-by: yuyang <Gabriel.yuyang@huawei.com>
common.sh [deleted file]
config/__init__.py [deleted file]
config/bottlenecks_cfg.yaml [deleted file]
run_tests.sh
testsuites/posca/testsuite_story/posca_factor_test.yaml [moved from testsuites/posca/testsuite_story/posca_factor_test with 100% similarity]

diff --git a/common.sh b/common.sh
deleted file mode 100755 (executable)
index 15cf2ec..0000000
--- a/common.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/bash
-##############################################################################
-# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-mkdir -p /home/opnfv/bottlenecks/config
-config_file=/home/opnfv/bottlenecks/config/bottlenecks_cfg.yaml
-
-if [ ! -f ${config_file} ]; then
-    default_config_file=$(find /home/opnfv -name bottlenecks_cfg.yaml)
-    cp $default_config_file $config_file
-    echo "bottlenecks_cfg.yaml not provided. Using default one"
-fi
-
-SUITE_PREFIX_CONFIG=$(cat $config_file | grep -w suite_prefix_config | awk 'END {print $NF}')
-
-info () {
-    logger -s -t "bottlenecks.info" "$*"
-}
-
-error () {
-    logger -s -t "bottlenecks.error" "$*"
-    exit 1
-}
diff --git a/config/__init__.py b/config/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/config/bottlenecks_cfg.yaml b/config/bottlenecks_cfg.yaml
deleted file mode 100644 (file)
index 32624d1..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-suite_prefix_config: /home/opnfv/bottlenecks/testsuites
index eb78824..7e4be37 100755 (executable)
@@ -8,14 +8,13 @@
 # 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 <test suite>] [-c <test case>]
+    bash $(basename "$0") [-h|--help] [-s <test suite>] [-c <test case>] [--report] [--cleanup]
 
 where:
     -h|--help         show the help text
-    -r|--report       push results to DB(true by default)
     -s|--teststory    run specific test story
       <test story>        one of the following:
                               (rubbos, vstf, posca_factor_test)
@@ -24,24 +23,69 @@ where:
     -c|--testcase     run specific test case
       <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_factor_test"
 
+# Define global variables
 Bottlenecks_key_dir="/home/opnfv/bottlenecks/utils/infra_setup"
-POSCA_SCRIPT="/home/opnfv/bottlenecks/testsuites/posca"
-SUITE_PREFIX="/home/opnfv/bottlenecks/testsuites/posca/testcase_cfg"
+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`
+
+report=false
+cleanup=false
 
-report=true
 
-#TO-DO add auto-find for test story as for test case
-all_test_story=(rubbos vstf posca_factor_test)
+# Define alias for log printing
+info () {
+    logger -s -t "bottlenecks.info" "$*"
+}
+
+error () {
+    logger -s -t "bottlenecks.error" "$*"
+    exit 1
+}
 
-find $SUITE_PREFIX -name "*yaml" > /tmp/all_testcases.yaml
-all_testcases_posca=`cat /tmp/all_testcases.yaml | awk -F '/' '{print $NF}' | awk -F '.' '{print $1}'`
-all_test_case=(${all_testcases_posca})
+# 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_exec=$1
@@ -64,15 +108,14 @@ function run_test(){
             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
             sleep 5
             info "Running posca test story: $test_exec"
-            docker exec bottleneckcompose_bottlenecks_1 python ${POSCA_SCRIPT}/run_posca.py $test_level $test_exec
+            docker exec bottleneckcompose_bottlenecks_1 python ${POSCA_SUITE}/run_posca.py $test_level $test_exec
         ;;
     esac
 }
 
+# Process input variables
 while [[ $# > 0 ]]
     do
     key="$1"
@@ -82,9 +125,6 @@ while [[ $# > 0 ]]
             exit 0
             shift
         ;;
-        -r|--report)
-            report="-r"
-        ;;
         -s|--teststory)
             teststory="$2"
             shift
@@ -93,6 +133,12 @@ while [[ $# > 0 ]]
             testcase="$2"
             shift
         ;;
+        --report)
+            report=true
+        ;;
+        --cleanup)
+            cleanup=true
+        ;;
         *)
             echo "unkown option $1 $2"
             exit 1
@@ -101,51 +147,18 @@ 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 [ "${teststory}" != "" ]; then
-    teststory_exec=(${teststory//,/ })
-    for i in "${teststory_exec[@]}"; do
-        if [[ " ${all_test_story[*]} " != *" $i "* ]]; then
-            error "Unkown test story: $i"
-        fi
-    done
-fi
-
-#check the test case name is correct
-if [ "${testcase}" != "" ]; then
-    testcase_exec=(${testcase//,/ })
-    for i in "${testcase_exec[@]}"; do
-        if [[ " ${all_test_case[*]} " != *" $i "* ]]; then
-            error "Unkown test case: $i"
-        fi
-    done
-fi
-
-#clean up correlated docker images
+# 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
+# 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
@@ -154,11 +167,18 @@ fi
 
 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
 
-# echo "Bottlenecks: cleaning up docker-compose images and dockers"
-# docker-compose -f $BASEDIR/docker/bottleneck-compose/docker-compose.yml down --rmi all
\ No newline at end of file
+# Clean up testing dockers
+if [[ ${cleanup} == true ]]; then
+    info "Cleaning up docker-compose images and dockers"
+    docker-compose -f $BASEDIR/docker/bottleneck-compose/docker-compose.yml down --rmi all
+    bash ${BASEDIR}/docker/docker_cleanup.sh -d influxdb --debug
+    bash ${BASEDIR}/docker/docker_cleanup.sh -d bottlenecks --debug
+fi