Add task selection to test suite entrance file
[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 auto.
12
13 usage:
14     bash $(basename "$0") [-h|--help] [-s <test suite>] [-c <test case>]
15
16 where:
17     -h|--help         show the help text
18     -r|--report       push results to DB(true by default)
19     -s|--teststory    run specific test story
20       <test story>        one of the following:
21                               (rubbos, vstf, posca_factor_test)
22                       user can also define their own test story and pass as var to this file,
23                       please refer to testsuites/posca/testsuite_story/ for details
24     -c|--testcase     run specific test case
25       <test case>         one of the following:
26                               (posca_factor_system_bandwidth, posca_factor_ping)
27
28 examples:
29     $(basename "$0")
30     $(basename "$0") -s posca_factor_test"
31
32 Bottlenecks_key_dir="/home/opnfv/bottlenecks/utils/infra_setup"
33 POSCA_SCRIPT="/home/opnfv/bottlenecks/testsuites/posca"
34 SUITE_PREFIX="/home/opnfv/bottlenecks/testsuites/posca/testcase_cfg"
35
36 report=true
37
38 #TO-DO add auto-find for test story as for test case
39 all_test_story=(rubbos vstf posca_factor_test)
40
41 find $SUITE_PREFIX -name "*yaml" > /tmp/all_testcases.yaml
42 all_testcases_posca=`cat /tmp/all_testcases.yaml | awk -F '/' '{print $NF}' | awk -F '.' '{print $1}'`
43 all_test_case=(${all_testcases_posca})
44
45 function run_test(){
46
47     test_exec=$1
48
49     case $test_exec in
50         "rubbos")
51             info "After OPNFV Colorado release, Rubbos testsuite is not updating anymore.
52                   This entrance for running Rubbos within Bottlenecks is no longer supported.
53                   This testsuite is also not in the release plan with Bottlenecks since then.
54                   If you want to run Rubbos, please refer to earlier releases."
55         ;;
56         "vstf")
57             info "After OPNFV Colorado release, VSTF testsuite is not updating anymore.
58                   This entrance for running VSTF within Bottlenecks is no longer supported.
59                   This testsuite is also not in the release plan with Bottlenecks since then.
60                   If you want to run VSTF, please refer to earlier releases."
61         ;;
62         *)
63             info "Composing up dockers"
64             docker-compose -f /home/opnfv/bottlenecks/docker/bottleneck-compose/docker-compose.yml up -d
65             info "Pulling tutum/influxdb for yardstick"
66             docker pull tutum/influxdb:0.13
67 #            info "Copying testing scripts to docker"
68 #            docker cp /home/opnfv/bottlenecks/run_posca.sh bottleneckcompose_bottlenecks_1:/home/opnfv/bottlenecks
69             sleep 5
70             info "Running posca test story: $test_exec"
71             docker exec bottleneckcompose_bottlenecks_1 python ${POSCA_SCRIPT}/run_posca.py $test_level $test_exec
72         ;;
73     esac
74 }
75
76 while [[ $# > 0 ]]
77     do
78     key="$1"
79     case $key in
80         -h|--help)
81             echo "$usage"
82             exit 0
83             shift
84         ;;
85         -r|--report)
86             report="-r"
87         ;;
88         -s|--teststory)
89             teststory="$2"
90             shift
91         ;;
92         -c|--testcase)
93             testcase="$2"
94             shift
95         ;;
96         *)
97             echo "unkown option $1 $2"
98             exit 1
99         ;;
100      esac
101      shift
102 done
103
104 BASEDIR=`dirname $0`
105 source ${BASEDIR}/common.sh
106
107 #Add random key generation
108 if [ ! -d $Bottlenecks_key_dir/bottlenecks_key ]; then
109     mkdir $Bottlenecks_key_dir/bottlenecks_key
110 else
111     rm -rf $Bottlenecks_key_dir/bottlenecks_key
112     mkdir $Bottlenecks_key_dir/bottlenecks_key
113 fi
114 chmod 700 $Bottlenecks_key_dir/bottlenecks_key
115
116 ssh-keygen -t rsa -f $Bottlenecks_key_dir/bottlenecks_key/bottlenecks_key -q -N ""
117 chmod 600 $Bottlenecks_key_dir/bottlenecks_key/*
118
119 #check the test suite name is correct
120 if [ "${teststory}" != "" ]; then
121     teststory_exec=(${teststory//,/ })
122     for i in "${teststory_exec[@]}"; do
123         if [[ " ${all_test_story[*]} " != *" $i "* ]]; then
124             error "Unkown test story: $i"
125         fi
126     done
127 fi
128
129 #check the test case name is correct
130 if [ "${testcase}" != "" ]; then
131     testcase_exec=(${testcase//,/ })
132     for i in "${testcase_exec[@]}"; do
133         if [[ " ${all_test_case[*]} " != *" $i "* ]]; then
134             error "Unkown test case: $i"
135         fi
136     done
137 fi
138
139 #run tests
140 if [ "${teststory}" != "" ]; then
141     test_level="teststory"
142     for i in "${teststory_exec[@]}"; do
143         info "Start to run test story $i"
144         run_test $i
145     done
146 fi
147
148 if [ "${testcase}" != "" ]; then
149     test_level="testcase"
150     for i in "${testcase_exec[@]}"; do
151         info "Start to run test case $i"
152         run_test $i
153     done
154 fi