bugfix: right cols to get available pods
[bottlenecks.git] / run_tests.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 usage="Script to run the tests in Bottlenecks.
12
13 usage:
14     bash $(basename "$0") [-h|--help] [-s <test suite>] [-c <test case>] [--report] [--cleanup]
15
16 where:
17     -h|--help         show the help text
18     -s|--teststory    run specific test story
19       <test story>        one of the following:
20                               (posca_factor_test)
21                       user can also define their own test story and pass as var to this file,
22                       please refer to testsuites/posca/testsuite_story/ for details
23     -c|--testcase     run specific test case
24       <test case>         one of the following:
25                               (posca_factor_ping, posca_factor_soak_throughputs, ...)
26     --cleanup         cleanup test dockers runing when test is done (false by default)
27     --report          push results to DB (false by default)
28
29 examples:
30     $(basename "$0") -s posca_factor_test"
31
32 # Define global variables
33 Bottlenecks_key_dir="/home/opnfv/bottlenecks/utils/infra_setup"
34 POSCA_SUITE="/home/opnfv/bottlenecks/testsuites/posca"
35 POSCA_TESTCASE="/home/opnfv/bottlenecks/testsuites/posca/testcase_cfg"
36 POSCA_TESTSTORY="/home/opnfv/bottlenecks/testsuites/posca/testsuite_story"
37 BASEDIR=`dirname $0`
38
39 REPORT="False"
40 cleanup=false
41
42 # Define alias for log printing
43 info () {
44     logger -s -t "BOTTLENECKS INFO" "$*"
45 }
46
47 error () {
48     logger -s -t "BOTTLENECKS ERROR" "$*"
49     exit 1
50 }
51
52 # Define check_test function for test case/story list check
53 function check_test(){
54
55     TEST_LEVEL="$1"
56     TEST_NAME="$2"
57
58     if [[ "${TEST_LEVEL}" == "testcase" ]]; then
59         TEST_CONFIG="${POSCA_TESTCASE}"
60     else
61         if [[ "${TEST_LEVEL}" == "teststory" ]]; then
62             TEST_CONFIG="${POSCA_TESTSTORY}"
63         else
64             info "Invalid name for test level: testcase or teststory"
65         fi
66     fi
67
68     # Find all the test case yaml files first
69     find $TEST_CONFIG -name "*yaml" > /tmp/all_tests.yaml
70     all_tests_insuite=`cat /tmp/all_tests.yaml | awk -F '/' '{print $NF}' | awk -F '.' '{print $1}'`
71     all_tests=(${all_tests_insuite})
72
73     if [ "${TEST_NAME}" != "" ]; then
74        TEST_EXEC=(${TEST_NAME// /})
75        for i in "${TEST_EXEC[@]}"; do
76            if [[ " ${all_tests[*]} " != *" $i "* ]]; then
77                error "Unknown $TEST_LEVEL: $i. Available $TEST_LEVEL are: ${all_tests[@]}"
78            fi
79        done
80        info "Tests to execute: ${TEST_NAME}."
81     else
82        error "Lack of $TEST_LEVEL name"
83     fi
84 }
85
86 # Define run test function
87 function run_test(){
88
89     test_exec=$1
90
91     case $test_exec in
92         "rubbos")
93             info "After OPNFV Colorado release, Rubbos testsuite is not updating anymore.
94                   This entrance for running Rubbos within Bottlenecks is no longer supported.
95                   This testsuite is also not in the release plan with Bottlenecks since then.
96                   If you want to run Rubbos, please refer to earlier releases."
97         ;;
98         "vstf")
99             info "After OPNFV Colorado release, VSTF testsuite is not updating anymore.
100                   This entrance for running VSTF within Bottlenecks is no longer supported.
101                   This testsuite is also not in the release plan with Bottlenecks since then.
102                   If you want to run VSTF, please refer to earlier releases."
103         ;;
104         *)
105             info "Running posca $test_level: $test_exec"
106             opts="--privileged=true -id"
107             docker_volume="-v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp"
108             docker run $opts --name bottlenecks-load-master $docker_volume opnfv/bottlenecks:latest /bin/bash
109             sleep 5
110             POSCA_SCRIPT="/home/opnfv/bottlenecks/testsuites/posca"
111             docker exec bottlenecks-load-master python ${POSCA_SCRIPT}/../run_testsuite.py ${test_level} ${test_exec} ${REPORT}
112         ;;
113     esac
114 }
115
116 # Process input variables
117 while [[ $# > 0 ]]
118     do
119     key="$1"
120     case $key in
121         -h|--help)
122             echo "$usage"
123             exit 0
124             shift
125         ;;
126         -s|--teststory)
127             teststory="$2"
128             shift
129         ;;
130         -c|--testcase)
131             testcase="$2"
132             shift
133         ;;
134         --report)
135             REPORT="True"
136         ;;
137         --cleanup)
138             cleanup=true
139         ;;
140         *)
141             echo "unkown option $1 $2"
142             exit 1
143         ;;
144      esac
145      shift
146 done
147
148 # Clean up related docker images
149 #bash ${BASEDIR}/docker/docker_cleanup.sh -d bottlenecks --debug
150 #bash ${BASEDIR}/docker/docker_cleanup.sh -d yardstick --debug
151 #bash ${BASEDIR}/docker/docker_cleanup.sh -d kibana --debug
152 #bash ${BASEDIR}/docker/docker_cleanup.sh -d elasticsearch --debug
153 #bash ${BASEDIR}/docker/docker_cleanup.sh -d influxdb --debug
154
155 # Run tests
156 if [ "${teststory}" != "" ]; then
157     test_level="teststory"
158     teststory_exec=(${teststory//,/ })
159     check_test $test_level $teststory
160     for i in "${teststory_exec[@]}"; do
161         info "Start to run test story $i"
162         run_test $i
163     done
164 fi
165
166 if [ "${testcase}" != "" ]; then
167     test_level="testcase"
168     testcase_exec=(${testcase//,/ })
169     check_test $test_level $testcase
170     for i in "${testcase_exec[@]}"; do
171         info "Start to run test case $i"
172         run_test $i
173     done
174 fi
175
176 # Clean up testing dockers
177 if [[ ${cleanup} == true ]]; then
178     info "Cleaning up docker-compose images and dockers"
179     bash ${BASEDIR}/docker/docker_cleanup.sh -d influxdb --debug
180     bash ${BASEDIR}/docker/docker_cleanup.sh -d bottlenecks --debug
181     bash ${BASEDIR}/docker/docker_cleanup.sh -d yardstick --debug
182     bash ${BASEDIR}/docker/docker_cleanup.sh -d elk --debug
183 fi