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