bug fiw syntax when calling push to db from vIMS
[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,rally,tempest,vims,onos,promise,ovno
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               cp tempest.conf /etc/tempest/
158               echo "[service_available]
159 bgpvpn = True" >> /etc/tempest/tempest.conf
160               ./run_tempest.sh -- networking_bgpvpn_tempest
161               rm -rf /etc/tempest/tempest.conf
162             popd
163         ;;
164         "odl-vpnservice")
165             info "Running VPNSERVICE Robot test case..."
166             odl_tests
167             cp ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt \
168                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt.bak
169             echo "
170 test/csit/suites/vpnservice
171 " > ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt
172             ODL_PORT=$odl_port ODL_IP=$odl_ip NEUTRON_IP=$neutron_ip USR_NAME=$usr_name PASS=$password \
173                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
174             cp ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt.bak \
175                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt
176             # TODO: copy logs
177        ;;
178         "onos")
179             info "Running ONOS test case..."
180             if [ $INSTALLER_TYPE == "joid" ]; then
181                 python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py -i joid
182             else
183                 python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
184             fi
185       ;;
186         "promise")
187             info "Running PROMISE test case..."
188             python ${FUNCTEST_REPO_DIR}/testcases/features/promise.py --debug ${report}
189             sleep 10 #to let the instances terminate
190             clean_openstack
191         ;;
192         "doctor")
193             info "Running Doctor test..."
194             python ${FUNCTEST_REPO_DIR}/testcases/features/doctor.py
195         ;;
196         "ovno")
197             info "Running OpenContrail test..."
198             ${repos_dir}/ovno/Testcases/RunTests.sh
199         ;;
200     esac
201 }
202
203
204 # Parse parameters
205 while [[ $# > 0 ]]
206     do
207     key="$1"
208     case $key in
209         -h|--help)
210             echo "$usage"
211             exit 0
212             shift
213         ;;
214         -o|--offline)
215             offline=true
216         ;;
217         -r|--report)
218             report="-r"
219         ;;
220         -n|--no-clean)
221             clean=false
222         ;;
223         -s|--serial)
224             serial=true
225         ;;
226         -t|--test|--tests)
227             TEST="$2"
228             shift
229         ;;
230         *)
231             echo "unknown option $1 $2"
232             exit 1
233         ;;
234     esac
235     shift # past argument or value
236 done
237
238
239 tests_file="/home/opnfv/functest/conf/testcase-list.txt"
240 if [[ -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" ]] &&\
241    [[ -f $tests_file ]]; then
242     arr_test=($(cat $tests_file))
243 else
244     arr_test=(vping_ssh tempest vims rally)
245 fi
246
247 BASEDIR=`dirname $0`
248 source ${BASEDIR}/common.sh
249
250 info "Tests to be executed: ${arr_test[@]}"
251
252 # Check that the given tests are correct
253 if [ "${TEST}" != "" ]; then
254     arr_test_exec=(${TEST//,/ })
255     for i in "${arr_test_exec[@]}"; do
256         if [[ " ${arr_test[*]} " != *" $i "* ]]; then
257             error "Unknown test: $i. Available tests are: ${arr_test[@]}"
258         fi
259     done
260     info "Tests to execute: ${TEST}."
261 fi
262
263 # Check that the functest environment has been installed
264 if [ ! -f ${FUNCTEST_CONF_DIR}/env_active ]; then
265     error "The Functest environment is not installed. \
266         Please run prepare_env.sh before running this script...."
267 fi
268
269
270 # Source credentials
271 info "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the tests.."
272 source ${FUNCTEST_CONF_DIR}/openstack.creds
273
274 # Run tests
275 if [ "${TEST}" != "" ]; then
276     for i in "${arr_test_exec[@]}"; do
277         run_test $i
278     done
279 else
280     info "Executing tests..."
281     for i in "${arr_test[@]}"; do
282         run_test $i
283     done
284 fi