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