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