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