typo fix on odl
[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=$(keystone catalog --service 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=$(keystone catalog --service 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 ODL_CONTROLLER | cut -f2 -d'=')
67         neutron_ip=$(keystone catalog --service 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 ""
80     echo "----------------------------------------------"
81     echo "  Running test cases: $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             cinder type-create volume-test #provisional
129             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_rally-cert.py \
130                 --debug all ${report}
131             cinder type-delete $(cinder type-list|grep test|awk '{print $2}')
132             clean_openstack
133
134         ;;
135         "bgpvpn")
136             info "Running BGPVPN Tempest test case..."
137             tempest_dir=$(ls -t /home/opnfv/.rally/tempest/ |grep for-deploy |tail -1)
138             if [[ $tempest_dir == "" ]]; then
139                 echo "Make sure tempest was running before"
140                 exit 1
141             fi
142             tempest_dir=/home/opnfv/.rally/tempest/$tempest_dir
143             pushd $tempest_dir
144               . .venv/bin/activate
145               pip install --no-deps -e ~/repos/bgpvpn/.
146               cp tempest.conf /etc/tempest/
147               echo "[service_available]
148 bgpvpn = True" >> /etc/tempest/tempest.conf
149               ./run_tempest.sh -- networking_bgpvpn_tempest
150               rm -rf /etc/tempest/tempest.conf
151             popd
152         ;;
153         "odl-vpnservice")
154             info "Running VPNSERVICE Robot test case..."
155             odl_tests
156             cp ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt \
157                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt.bak
158             echo "
159 test/csit/suites/vpnservice
160 " > ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt
161             ODL_PORT=$odl_port ODL_IP=$odl_ip NEUTRON_IP=$neutron_ip USR_NAME=$usr_name PASS=$password \
162                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
163             cp ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt.bak \
164                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/test_list.txt
165             # TODO: copy logs
166        ;;
167         "onos")
168             info "Running ONOS test case..."
169             python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
170       ;;
171         "promise")
172             info "Running PROMISE test case..."
173             python ${FUNCTEST_REPO_DIR}/testcases/features/promise.py --debug ${report}
174             clean_openstack
175         ;;
176         "doctor")
177             info "Running Doctor test..."
178             python ${FUNCTEST_REPO_DIR}/testcases/features/doctor.py
179         ;;
180         "ovno")
181             info "Running OpenContrail test..."
182             # TODO
183         ;;
184     esac
185 }
186
187
188 # Parse parameters
189 while [[ $# > 0 ]]
190     do
191     key="$1"
192     case $key in
193         -h|--help)
194             echo "$usage"
195             exit 0
196             shift
197         ;;
198         -o|--offline)
199             offline=true
200         ;;
201         -r|--report)
202             report="-r"
203         ;;
204         -n|--no-clean)
205             clean=false
206         ;;
207         -t|--test|--tests)
208             TEST="$2"
209             shift
210         ;;
211         *)
212             echo "unknown option $1 $2"
213             exit 1
214         ;;
215     esac
216     shift # past argument or value
217 done
218
219
220 tests_file="/home/opnfv/functest/conf/testcase-list.txt"
221 if [[ -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" ]] &&\
222    [[ -f $tests_file ]]; then
223     arr_test=($(cat $tests_file))
224 else
225     arr_test=(vping tempest vims rally)
226 fi
227 echo "arr_test: "${arr_test[@]}
228
229 BASEDIR=`dirname $0`
230 source ${BASEDIR}/common.sh
231
232
233 # Check that the given tests are correct
234 if [ "${TEST}" != "" ]; then
235     arr_test_exec=(${TEST//,/ })
236     for i in "${arr_test_exec[@]}"; do
237         if [[ " ${arr_test[*]} " != *" $i "* ]]; then
238             error "Unknown test: $i. Available tests are: ${arr_test[@]}"
239         fi
240     done
241     info "Tests to execute: ${TEST}."
242 fi
243
244 if [ $offline == false ]; then
245     info "MODE: online"
246 else
247     info "MODE: offline"
248 fi
249
250 # Check that the functest environment has been installed
251 if [ ! -f ${FUNCTEST_CONF_DIR}/env_active ]; then
252     error "The Functest environment is not installed. \
253         Please run prepare_env.sh before running this script...."
254 fi
255
256
257 # Source credentials
258 info "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the tests.."
259 source ${FUNCTEST_CONF_DIR}/openstack.creds
260
261 # Run tests
262 if [ "${TEST}" != "" ]; then
263     for i in "${arr_test_exec[@]}"; do
264         run_test $i
265     done
266 else
267     info "Executing tests..."
268     for i in "${arr_test[@]}"; do
269         run_test $i
270     done
271 fi