c0bf06a2a31506c5d38005f60461c73255549ba8
[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 run_test(){
54     test_name=$1
55     echo ""
56     echo "----------------------------------------------"
57     echo "  Running test cases: $i"
58     echo "----------------------------------------------"
59     echo ""
60     case $test_name in
61         "vping")
62             info "Running vPing test..."
63             python ${FUNCTEST_REPO_DIR}/testcases/vPing/CI/libraries/vPing2.py \
64                 --debug ${report}
65         ;;
66         "vping_userdata")
67             info "Running vPing test using userdata/cloudinit.... "
68             python ${FUNCTEST_REPO_DIR}/testcases/vPing/CI/libraries/vPing.py \
69                 --debug ${report}
70         ;;
71         "odl")
72             info "Running ODL test..."
73             neutron_ip=$(keystone catalog --service identity | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
74             odl_ip=$(keystone catalog --service network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
75             usr_name=$(env | grep OS | grep OS_USERNAME | cut -f2 -d'=')
76             password=$(env | grep OS | grep OS_PASSWORD | cut -f2 -d'=')
77             odl_port=8181
78             if [ $INSTALLER_TYPE == "fuel" ]; then
79                 odl_port=8282
80             elif [ $INSTALLER_TYPE == "apex" ]; then
81                 :
82             elif [ $INSTALLER_TYPE == "joid" ]; then
83                 :
84             elif [ $INSTALLER_TYPE == "compass" ]; then
85                 :
86             else
87                 error "INSTALLER_TYPE not valid."
88                 exit 1
89             fi
90             ODL_PORT=$odl_port ODL_IP=$odl_ip NEUTRON_IP=$neutron_ip USR_NAME=$usr_name PASS=$password \
91                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
92
93             # push results to the DB in case of CI
94             if [[ -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" ]]; then
95                 odl_logs="/home/opnfv/functest/results/odl/logs/2"
96                 odl_path="${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI"
97                 node_name=$(env | grep NODE_NAME | cut -f2 -d'=')
98                 python ${odl_path}/odlreport2db.py -x ${odl_logs}/output.xml -i ${INSTALLER_TYPE} -p ${node_name} -s ${DEPLOY_SCENARIO}
99             fi
100         ;;
101         "tempest")
102             info "Running Tempest tests..."
103             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_tempest.py \
104                 --debug -m custom ${report}
105             # save tempest.conf for further troubleshooting
106             tempest_conf="${RALLY_VENV_DIR}/tempest/for-deployment-*/tempest.conf"
107             if [ -f ${tempest_conf} ]; then
108                 cp $tempest_conf ${FUNCTEST_CONF_DIR}
109             fi
110             clean_openstack
111         ;;
112         "vims")
113             info "Running vIMS test..."
114             python ${FUNCTEST_REPO_DIR}/testcases/vIMS/CI/vIMS.py \
115                 --debug ${report}
116             clean_openstack
117         ;;
118         "rally")
119             info "Running Rally benchmark suite..."
120             cinder type-create volume-test #provisional
121             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_rally.py \
122                 --debug all ${report}
123             cinder type-delete $(cinder type-list|grep test|awk '{print $2}')
124             clean_openstack
125
126         ;;
127         "bgpvpn_template")
128             info "Running BGPVPN Tempest test case..."
129             tempest_dir=$(find /root/.rally -type d -name for-deploy*)
130             # TODO:
131             # do the call of your test case here.
132             # the bgpvpn repo is cloned in $BGPVPN_REPO_DIR
133             # tempest is installed in $tempest_dir
134             # Suggestion:
135             #   mkdir ${tempest_dir}/tempest/api/bgpvpn/
136             #   cp ${BGPVPN_REPO_DIR}/networking_bgpvpn_tempest/<whatever you need> \
137             #       ${tempest_dir}/tempest/api/bgpvpn/
138             #   ${tempest_dir}/run_tempest.sh tempest.api.bgpvpn.<test_case_name>
139        ;;
140         "onos")
141             info "Running ONOS test case..."
142             python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
143       ;;
144         "promise")
145             info "Running PROMISE test case..."
146             # TODO
147         ;;
148         "doctor")
149             info "Running Doctor test..."
150             python ${FUNCTEST_REPO_DIR}/testcases/features/doctor.py
151         ;;
152         "ovno")
153             info "Running OpenContrail test..."
154             # TODO
155         ;;
156     esac
157 }
158
159
160 # Parse parameters
161 while [[ $# > 0 ]]
162     do
163     key="$1"
164     case $key in
165         -h|--help)
166             echo "$usage"
167             exit 0
168             shift
169         ;;
170         -o|--offline)
171             offline=true
172         ;;
173         -r|--report)
174             report="-r"
175         ;;
176         -n|--no-clean)
177             clean=false
178         ;;
179         -t|--test|--tests)
180             TEST="$2"
181             shift
182         ;;
183         *)
184             echo "unknown option $1 $2"
185             exit 1
186         ;;
187     esac
188     shift # past argument or value
189 done
190
191
192 tests_file="/home/opnfv/functest/conf/testcase-list.txt"
193 if [[ -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" ]] &&\
194    [[ -f $tests_file ]]; then
195     echo "testcase-list.txt content:";cat $test_file; echo ""
196     arr_test=($(cat $tests_file))
197 else
198     arr_test=(vping tempest vims rally)
199 fi
200 echo "arr_test: "${arr_test[@]}
201
202 BASEDIR=`dirname $0`
203 source ${BASEDIR}/common.sh
204
205
206 # Check that the given tests are correct
207 if [ "${TEST}" != "" ]; then
208     arr_test_exec=(${TEST//,/ })
209     for i in "${arr_test_exec[@]}"; do
210         if [[ " ${arr_test[*]} " != *" $i "* ]]; then
211             error "Unknown test: $i. Available tests are: ${arr_test[@]}"
212         fi
213     done
214     info "Tests to execute: ${TEST}."
215 fi
216
217 if [ $offline == false ]; then
218     info "MODE: online"
219 else
220     info "MODE: offline"
221 fi
222
223 # Check that the functest environment has been installed
224 if [ ! -f ${FUNCTEST_CONF_DIR}/env_active ]; then
225     error "The Functest environment is not installed. \
226         Please run prepare_env.sh before running this script...."
227 fi
228
229
230 # Source credentials
231 info "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the tests.."
232 source ${FUNCTEST_CONF_DIR}/openstack.creds
233
234 # Run tests
235 if [ "${TEST}" != "" ]; then
236     for i in "${arr_test_exec[@]}"; do
237         run_test $i
238     done
239 else
240     info "Executing tests..."
241     for i in "${arr_test[@]}"; do
242         run_test $i
243     done
244 fi