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