Merge "Fix success status parsing of rally results"
[functest.git] / docker / run_tests.sh
1 #!/bin/bash
2
3 #
4 # Author: Jose Lausuch (jose.lausuch@ericsson.com)
5 #         Morgan Richomme (morgan.richomme@orange.com)
6 # Installs the Functest framework within the Docker container
7 # and run the tests automatically
8 #
9 #
10 # All rights reserved. This program and the accompanying materials
11 # are made available under the terms of the Apache License, Version 2.0
12 # which accompanies this distribution, and is available at
13 # http://www.apache.org/licenses/LICENSE-2.0
14 #
15
16 usage="Script to trigger the tests automatically.
17
18 usage:
19     bash $(basename "$0") [-h|--help] [-t <test_name>]
20
21 where:
22     -h|--help         show this help text
23     -r|--report       push results to database (false by default)
24     -n|--no-clean     do not clean OpenStack resources after test run
25     -t|--test         run specific set of tests
26       <test_name>     one or more of the following: vping,odl,rally,tempest,vims,onos,promise,ovno. Separated by comma.
27
28
29 examples:
30     $(basename "$0")
31     $(basename "$0") --test vping,odl
32     $(basename "$0") -t tempest,rally"
33
34
35 # Support for Functest offline
36 # NOTE: Still not 100% working when running the tests
37 offline=false
38 report=""
39 clean=true
40 # Get the list of runnable tests
41 # Check if we are in CI mode
42
43
44 function clean_openstack(){
45     if [ $clean == true ]; then
46         echo -e "\n\nCleaning Openstack environment..."
47         python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/clean_openstack.py \
48             --debug
49         echo -e "\n\n"
50     fi
51 }
52
53 function odl_tests(){
54     keystone_ip=$(openstack catalog show identity |grep publicURL| cut -f3 -d"/" | cut -f1 -d":")
55     # historically most of the installers use the same IP for neutron and keystone API
56     neutron_ip=$keystone_ip
57     odl_ip=$(openstack catalog show network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
58     usr_name=$(env | grep OS | grep OS_USERNAME | cut -f2 -d'=')
59     password=$(env | grep OS | grep OS_PASSWORD | cut -f2 -d'=')
60     odl_port=8181
61     if [ $INSTALLER_TYPE == "fuel" ]; then
62         odl_port=8282
63     elif [ $INSTALLER_TYPE == "apex" ]; then
64         :
65     elif [ $INSTALLER_TYPE == "joid" ]; then
66         odl_ip=$(env | grep SDN_CONTROLLER | cut -f2 -d'=')
67         neutron_ip=$(openstack catalog show network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
68         odl_port=8080
69         :
70     elif [ $INSTALLER_TYPE == "compass" ]; then
71         :
72     else
73         error "INSTALLER_TYPE not valid."
74         exit 1
75     fi
76 }
77 function run_test(){
78     test_name=$1
79     echo -e "\n\n\n\n"
80     echo "----------------------------------------------"
81     echo "  Running test case: $i"
82     echo "----------------------------------------------"
83     echo ""
84     case $test_name in
85         "vping")
86             info "Running vPing test..."
87             python ${FUNCTEST_REPO_DIR}/testcases/vPing/CI/libraries/vPing2.py \
88                 --debug ${report}
89         ;;
90         "vping_userdata")
91             info "Running vPing test using userdata/cloudinit.... "
92             python ${FUNCTEST_REPO_DIR}/testcases/vPing/CI/libraries/vPing.py \
93                 --debug ${report}
94         ;;
95         "odl")
96             info "Running ODL test..."
97             odl_tests
98             ODL_PORT=$odl_port ODL_IP=$odl_ip KEYSTONE_IP=$keystone_ip NEUTRON_IP=$neutron_ip USR_NAME=$usr_name PASS=$password \
99                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
100
101             # push results to the DB in case of CI
102             if [[ -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" ]]; then
103                 odl_logs="/home/opnfv/functest/results/odl/logs/2"
104                 odl_path="${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI"
105                 node_name=$(env | grep NODE_NAME | cut -f2 -d'=')
106                 python ${odl_path}/odlreport2db.py -x ${odl_logs}/output.xml -i ${INSTALLER_TYPE} -p ${node_name} -s ${DEPLOY_SCENARIO}
107             fi
108         ;;
109         "tempest")
110             info "Running Tempest tests..."
111             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_tempest.py \
112                 --debug -m custom ${report}
113             # save tempest.conf for further troubleshooting
114             tempest_conf="${RALLY_VENV_DIR}/tempest/for-deployment-*/tempest.conf"
115             if [ -f ${tempest_conf} ]; then
116                 cp $tempest_conf ${FUNCTEST_CONF_DIR}
117             fi
118             clean_openstack
119         ;;
120         "vims")
121             info "Running vIMS test..."
122             python ${FUNCTEST_REPO_DIR}/testcases/vIMS/CI/vIMS.py \
123                 --debug ${report}
124             clean_openstack
125         ;;
126         "rally")
127             info "Running Rally benchmark suite..."
128             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_rally-cert.py \
129                 --debug all ${report}
130             clean_openstack
131
132         ;;
133         "bgpvpn")
134             info "Running BGPVPN Tempest test case..."
135             tempest_dir=$(ls -t /home/opnfv/.rally/tempest/ |grep for-deploy |tail -1)
136             if [[ $tempest_dir == "" ]]; then
137                 echo "Make sure tempest was running before"
138                 exit 1
139             fi
140             tempest_dir=/home/opnfv/.rally/tempest/$tempest_dir
141             pushd $tempest_dir
142               . .venv/bin/activate
143               pip install --no-deps -e ~/repos/bgpvpn/.
144               cp tempest.conf /etc/tempest/
145               echo "[service_available]
146 bgpvpn = True" >> /etc/tempest/tempest.conf
147               ./run_tempest.sh -- networking_bgpvpn_tempest
148               rm -rf /etc/tempest/tempest.conf
149             popd
150         ;;
151         "odl-vpnservice")
152             info "Running VPNSERVICE Robot test case..."
153             odl_tests
154             cp ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt \
155                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt.bak
156             echo "
157 test/csit/suites/vpnservice
158 " > ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt
159             ODL_PORT=$odl_port ODL_IP=$odl_ip NEUTRON_IP=$neutron_ip USR_NAME=$usr_name PASS=$password \
160                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
161             cp ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt.bak \
162                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt
163             # TODO: copy logs
164        ;;
165         "onos")
166             info "Running ONOS test case..."
167             if [ $INSTALLER_TYPE == "joid" ]; then
168                 python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py -i joid
169             else
170                 python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
171             fi
172       ;;
173         "promise")
174             info "Running PROMISE test case..."
175             python ${FUNCTEST_REPO_DIR}/testcases/features/promise.py --debug ${report}
176             sleep 10 #to let the instances terminate
177             clean_openstack
178         ;;
179         "doctor")
180             info "Running Doctor test..."
181             python ${FUNCTEST_REPO_DIR}/testcases/features/doctor.py
182         ;;
183         "ovno")
184             info "Running OpenContrail test..."
185             ${repos_dir}/ovno/Testcases/RunTests.sh
186         ;;
187     esac
188 }
189
190
191 # Parse parameters
192 while [[ $# > 0 ]]
193     do
194     key="$1"
195     case $key in
196         -h|--help)
197             echo "$usage"
198             exit 0
199             shift
200         ;;
201         -o|--offline)
202             offline=true
203         ;;
204         -r|--report)
205             report="-r"
206         ;;
207         -n|--no-clean)
208             clean=false
209         ;;
210         -t|--test|--tests)
211             TEST="$2"
212             shift
213         ;;
214         *)
215             echo "unknown option $1 $2"
216             exit 1
217         ;;
218     esac
219     shift # past argument or value
220 done
221
222
223 tests_file="/home/opnfv/functest/conf/testcase-list.txt"
224 if [[ -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" ]] &&\
225    [[ -f $tests_file ]]; then
226     arr_test=($(cat $tests_file))
227 else
228     arr_test=(vping tempest vims rally)
229 fi
230
231 BASEDIR=`dirname $0`
232 source ${BASEDIR}/common.sh
233
234 info "Tests to be executed: ${arr_test[@]}"
235
236 # Check that the given tests are correct
237 if [ "${TEST}" != "" ]; then
238     arr_test_exec=(${TEST//,/ })
239     for i in "${arr_test_exec[@]}"; do
240         if [[ " ${arr_test[*]} " != *" $i "* ]]; then
241             error "Unknown test: $i. Available tests are: ${arr_test[@]}"
242         fi
243     done
244     info "Tests to execute: ${TEST}."
245 fi
246
247 # Check that the functest environment has been installed
248 if [ ! -f ${FUNCTEST_CONF_DIR}/env_active ]; then
249     error "The Functest environment is not installed. \
250         Please run prepare_env.sh before running this script...."
251 fi
252
253
254 # Source credentials
255 info "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the tests.."
256 source ${FUNCTEST_CONF_DIR}/openstack.creds
257
258 # Run tests
259 if [ "${TEST}" != "" ]; then
260     for i in "${arr_test_exec[@]}"; do
261         run_test $i
262     done
263 else
264     info "Executing tests..."
265     for i in "${arr_test[@]}"; do
266         run_test $i
267     done
268 fi