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