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