18f4a2733313d8e0d8f0bcabe23c0b22a24a30b7
[functest.git] / docker / run_tests.sh
1 #!/bin/bash
2
3 #
4 # Author: Jose Lausuch (jose.lausuch@ericsson.com)
5 #
6 # Installs the Functest framework within the Docker container
7 # and run the tests automatically
8 #
9
10 usage="Script to trigger the tests automatically.
11
12 usage:
13     bash $(basename "$0") [--offline] [-h|--help] [-t <test_name>]
14
15 where:
16     -o|--offline      optional offline mode (experimental)
17     -h|--help         show this help text
18     -r|--report       push results to database (false by default)
19     -t|--test         run specific set of tests
20       <test_name>     one or more of the following: vping,odl,rally,tempest,vims,onos,promise,ovno. Separated by comma.
21
22
23 examples:
24     $(basename "$0")
25     $(basename "$0") --test vping,odl
26     $(basename "$0") --offline -t tempest,rally"
27
28
29 # Support for Functest offline
30 # NOTE: Still not 100% working when running the tests
31 offline=false
32 report=""
33 # Get the list of runnable tests
34 # Check if we are in CI mode
35 tests_file="/home/opnfv/functest/conf/testcase-list.txt"
36 if [[ -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" ]] &&\
37    [[ -f $tests_file ]]; then
38     arr_test=($(cat $tests_file))
39 else
40     arr_test=(vping tempest vims rally)
41 fi
42
43 function clean_openstack(){
44     echo -e "\n\nCleaning Openstack environment..."
45     python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/clean_openstack.py \
46         --debug
47     echo -e "\n\n"
48 }
49
50 function run_test(){
51     test_name=$1
52     echo ""
53     echo "----------------------------------------------"
54     echo "  Running test cases: $i"
55     echo "----------------------------------------------"
56     echo ""
57     case $test_name in
58         "vping")
59             info "Running vPing test..."
60             python ${FUNCTEST_REPO_DIR}/testcases/vPing/CI/libraries/vPing.py \
61                 --debug ${report}
62         ;;
63         "odl")
64             info "Running ODL test..."
65             neutron_ip=$(keystone catalog --service identity | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
66             odl_ip=$(keystone catalog --service network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
67             usr_name=$(env | grep OS | grep OS_USERNAME | cut -f2 -d'=')
68             password=$(env | grep OS | grep OS_PASSWORD | cut -f2 -d'=')
69             odl_port=8181
70             if [ $INSTALLER_TYPE == "fuel" ]; then
71                 odl_port=8282
72             elif [ $INSTALLER_TYPE == "apex" ]; then
73                 :
74             elif [ $INSTALLER_TYPE == "joid" ]; then
75                 :
76             elif [ $INSTALLER_TYPE == "compass" ]; then
77                 :
78             else
79                 error "INSTALLER_TYPE not valid."
80                 exit 1
81             fi
82             ODL_PORT=$odl_port ODL_IP=$odl_ip NEUTRON_IP=$neutron_ip USR_NAME=$usr_name PASS=$password \
83                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
84
85             # save ODL results
86             odl_logs="${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/logs"
87             if [ -d ${odl_logs} ]; then
88                 cp -Rf  ${odl_logs} ${FUNCTEST_CONF_DIR}/ODL/
89             fi
90         ;;
91         "tempest")
92             info "Running Tempest tests..."
93             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_tempest.py \
94                 --debug -m custom ${report}
95             # save tempest.conf for further troubleshooting
96             tempest_conf="${RALLY_VENV_DIR}/tempest/for-deployment-*/tempest.conf"
97             if [ -f ${tempest_conf} ]; then
98                 cp $tempest_conf ${FUNCTEST_CONF_DIR}
99             fi
100             clean_openstack
101         ;;
102         "vims")
103             info "Running vIMS test..."
104             python ${FUNCTEST_REPO_DIR}/testcases/vIMS/CI/vIMS.py \
105                 --debug ${report}
106             clean_openstack
107         ;;
108         "rally")
109             info "Running Rally benchmark suite..."
110             cinder type-create volume-test #provisional
111             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_rally.py \
112                 --debug all ${report}
113             cinder type-delete $(cinder type-list|grep test|awk '{print $2}')
114             clean_openstack
115
116         ;;
117         "bgpvpn_template")
118             info "Running BGPVPN Tempest test case..."
119             tempest_dir=$(find /root/.rally -type d -name for-deploy*)
120             # TODO:
121             # do the call of your test case here.
122             # the bgpvpn repo is cloned in $BGPVPN_REPO_DIR
123             # tempest is installed in $tempest_dir
124             # Suggestion:
125             #   mkdir ${tempest_dir}/tempest/api/bgpvpn/
126             #   cp ${BGPVPN_REPO_DIR}/networking_bgpvpn_tempest/<whatever you need> \
127             #       ${tempest_dir}/tempest/api/bgpvpn/
128             #   ${tempest_dir}/run_tempest.sh tempest.api.bgpvpn.<test_case_name>
129        ;;
130         "onos")
131             info "Running ONOS test case..."
132             python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
133       ;;
134         "promise")
135             info "Running PROMISE test case..."
136             # TODO
137         ;;
138         "doctor")
139             info "Running Doctor test..."
140             python ${FUNCTEST_REPO_DIR}/testcases/features/doctor.py
141         ;;
142         "ovno")
143             info "Running OpenContrail test..."
144             # TODO
145         ;;
146     esac
147 }
148
149
150 # Parse parameters
151 while [[ $# > 0 ]]
152     do
153     key="$1"
154     case $key in
155         -h|--help)
156             echo "$usage"
157             exit 0
158             shift
159         ;;
160         -o|--offline)
161             offline=true
162         ;;
163         -r|--report)
164             report="-r"
165         ;;
166         -t|--test|--tests)
167             TEST="$2"
168             shift
169         ;;
170         *)
171             echo "unknown option $1 $2"
172             exit 1
173         ;;
174     esac
175     shift # past argument or value
176 done
177
178 BASEDIR=`dirname $0`
179 source ${BASEDIR}/common.sh
180
181
182 # Check that the given tests are correct
183 if [ "${TEST}" != "" ]; then
184     arr_test_exec=(${TEST//,/ })
185     for i in "${arr_test_exec[@]}"; do
186         if [[ " ${arr_test[*]} " != *" $i "* ]]; then
187             error "Unknown test: $i. Available tests are: ${arr_test[@]}"
188         fi
189     done
190     info "Tests to execute: ${TEST}."
191 fi
192
193 if [ $offline == false ]; then
194     info "MODE: online"
195 else
196     info "MODE: offline"
197 fi
198
199 # Check that the functest environment has been installed
200 if [ ! -f ${FUNCTEST_CONF_DIR}/env_active ]; then
201     error "The Functest environment is not installed. \
202         Please run prepare_env.sh before running this script...."
203 fi
204
205
206 # Source credentials
207 info "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the tests.."
208 source ${FUNCTEST_CONF_DIR}/openstack.creds
209
210 # Run tests
211 if [ "${TEST}" != "" ]; then
212     for i in "${arr_test_exec[@]}"; do
213         run_test $i
214     done
215 else
216     info "Executing all the tests"
217     for i in "${arr_test[@]}"; do
218         run_test $i
219     done
220 fi