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