Add frame support of elk one docker support
[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                               (rubbos, vstf, 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_system_bandwidth, posca_factor_ping)
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")
31     $(basename "$0") -s posca_factor_test"
32
33 # Define global variables
34 Bottlenecks_key_dir="/home/opnfv/bottlenecks/utils/infra_setup"
35 POSCA_SUITE="/home/opnfv/bottlenecks/testsuites/posca"
36 POSCA_TESTCASE="/home/opnfv/bottlenecks/testsuites/posca/testcase_cfg"
37 POSCA_TESTSTORY="/home/opnfv/bottlenecks/testsuites/posca/testsuite_story"
38 BASEDIR=`dirname $0`
39
40 REPORT="False"
41 cleanup=false
42
43 # Define alias for log printing
44 info () {
45     logger -s -t "bottlenecks.info" "$*"
46 }
47
48 error () {
49     logger -s -t "bottlenecks.error" "$*"
50     exit 1
51 }
52
53 # Define check_test function for test case/story list check
54 function check_test(){
55
56     TEST_LEVEL="$1"
57     TEST_NAME="$2"
58
59     if [[ "${TEST_LEVEL}" == "testcase" ]]; then
60         TEST_CONFIG="${POSCA_TESTCASE}"
61     else
62         if [[ "${TEST_LEVEL}" == "teststory" ]]; then
63             TEST_CONFIG="${POSCA_TESTSTORY}"
64         else
65             info "Invalid name for test level: testcase or teststory"
66         fi
67     fi
68
69     # Find all the test case yaml files first
70     find $TEST_CONFIG -name "*yaml" > /tmp/all_tests.yaml
71     all_tests_insuite=`cat /tmp/all_tests.yaml | awk -F '/' '{print $NF}' | awk -F '.' '{print $1}'`
72     all_tests=(${all_tests_insuite})
73
74     if [ "${TEST_NAME}" != "" ]; then
75        TEST_EXEC=(${TEST_NAME// /})
76        for i in "${TEST_EXEC[@]}"; do
77            if [[ " ${all_tests[*]} " != *" $i "* ]]; then
78                error "Unknown $TEST_LEVEL: $i. Available $TEST_LEVEL are: ${all_tests[@]}"
79            fi
80        done
81        info "Tests to execute: ${TEST_NAME}."
82     else
83        error "Lack of $TEST_LEVEL name"
84     fi
85 }
86
87 # Define run test function
88 function run_test(){
89
90     test_exec=$1
91
92     case $test_exec in
93         "rubbos")
94             info "After OPNFV Colorado release, Rubbos testsuite is not updating anymore.
95                   This entrance for running Rubbos within Bottlenecks is no longer supported.
96                   This testsuite is also not in the release plan with Bottlenecks since then.
97                   If you want to run Rubbos, please refer to earlier releases."
98         ;;
99         "vstf")
100             info "After OPNFV Colorado release, VSTF testsuite is not updating anymore.
101                   This entrance for running VSTF within Bottlenecks is no longer supported.
102                   This testsuite is also not in the release plan with Bottlenecks since then.
103                   If you want to run VSTF, please refer to earlier releases."
104         ;;
105         *)
106             info "Composing up dockers"
107             docker-compose -f /home/opnfv/bottlenecks/docker/bottleneck-compose/docker-compose.yml up -d
108             info "Pulling tutum/influxdb for yardstick"
109             docker pull tutum/influxdb:0.13
110             sleep 5
111             info "Running posca $test_level: $test_exec"
112             docker exec bottleneckcompose_bottlenecks_1 python ${POSCA_SUITE}/../run_testsuite.py $test_level $test_exec $REPORT
113         ;;
114     esac
115 }
116
117 # Process input variables
118 while [[ $# > 0 ]]
119     do
120     key="$1"
121     case $key in
122         -h|--help)
123             echo "$usage"
124             exit 0
125             shift
126         ;;
127         -s|--teststory)
128             teststory="$2"
129             shift
130         ;;
131         -c|--testcase)
132             testcase="$2"
133             shift
134         ;;
135         --report)
136             REPORT="True"
137         ;;
138         --cleanup)
139             cleanup=true
140         ;;
141         *)
142             echo "unkown option $1 $2"
143             exit 1
144         ;;
145      esac
146      shift
147 done
148
149 # Clean up related docker images
150 #bash ${BASEDIR}/docker/docker_cleanup.sh -d bottlenecks --debug
151 #bash ${BASEDIR}/docker/docker_cleanup.sh -d yardstick --debug
152 #bash ${BASEDIR}/docker/docker_cleanup.sh -d kibana --debug
153 #bash ${BASEDIR}/docker/docker_cleanup.sh -d elasticsearch --debug
154 #bash ${BASEDIR}/docker/docker_cleanup.sh -d influxdb --debug
155
156 # Run tests
157 if [ "${teststory}" != "" ]; then
158     test_level="teststory"
159     teststory_exec=(${teststory//,/ })
160     check_test $test_level $teststory
161     for i in "${teststory_exec[@]}"; do
162         info "Start to run test story $i"
163         run_test $i
164     done
165 fi
166
167 if [ "${testcase}" != "" ]; then
168     test_level="testcase"
169     testcase_exec=(${testcase//,/ })
170     check_test $test_level $testcase
171     for i in "${testcase_exec[@]}"; do
172         info "Start to run test case $i"
173         run_test $i
174     done
175 fi
176
177 # Clean up testing dockers
178 if [[ ${cleanup} == true ]]; then
179     info "Cleaning up docker-compose images and dockers"
180     docker-compose -f $BASEDIR/docker/bottleneck-compose/docker-compose.yml down --rmi all
181     bash ${BASEDIR}/docker/docker_cleanup.sh -d influxdb --debug
182     bash ${BASEDIR}/docker/docker_cleanup.sh -d bottlenecks --debug
183 fi