bae75e96187ec67a04cdfa403712c614224c947a
[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             # save ODL results
90             odl_logs="${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/logs"
91             if [ -d ${odl_logs} ]; then
92                 cp -Rf  ${odl_logs} ${FUNCTEST_CONF_DIR}/ODL/
93             fi
94         ;;
95         "tempest")
96             info "Running Tempest tests..."
97             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_tempest.py \
98                 --debug -m custom ${report}
99             # save tempest.conf for further troubleshooting
100             tempest_conf="${RALLY_VENV_DIR}/tempest/for-deployment-*/tempest.conf"
101             if [ -f ${tempest_conf} ]; then
102                 cp $tempest_conf ${FUNCTEST_CONF_DIR}
103             fi
104             clean_openstack
105         ;;
106         "vims")
107             info "Running vIMS test..."
108             python ${FUNCTEST_REPO_DIR}/testcases/vIMS/CI/vIMS.py \
109                 --debug ${report}
110             clean_openstack
111         ;;
112         "rally")
113             info "Running Rally benchmark suite..."
114             cinder type-create volume-test #provisional
115             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_rally.py \
116                 --debug all ${report}
117             cinder type-delete $(cinder type-list|grep test|awk '{print $2}')
118             clean_openstack
119
120         ;;
121         "bgpvpn_template")
122             info "Running BGPVPN Tempest test case..."
123             tempest_dir=$(find /root/.rally -type d -name for-deploy*)
124             # TODO:
125             # do the call of your test case here.
126             # the bgpvpn repo is cloned in $BGPVPN_REPO_DIR
127             # tempest is installed in $tempest_dir
128             # Suggestion:
129             #   mkdir ${tempest_dir}/tempest/api/bgpvpn/
130             #   cp ${BGPVPN_REPO_DIR}/networking_bgpvpn_tempest/<whatever you need> \
131             #       ${tempest_dir}/tempest/api/bgpvpn/
132             #   ${tempest_dir}/run_tempest.sh tempest.api.bgpvpn.<test_case_name>
133        ;;
134         "onos")
135             info "Running ONOS test case..."
136             python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
137       ;;
138         "promise")
139             info "Running PROMISE test case..."
140             python ${FUNCTEST_REPO_DIR}/testcases/features/promise.py --debug all ${report}
141             clean_openstack
142         ;;
143         "doctor")
144             info "Running Doctor test..."
145             python ${FUNCTEST_REPO_DIR}/testcases/features/doctor.py
146         ;;
147         "ovno")
148             info "Running OpenContrail test..."
149             # TODO
150         ;;
151     esac
152 }
153
154
155 # Parse parameters
156 while [[ $# > 0 ]]
157     do
158     key="$1"
159     case $key in
160         -h|--help)
161             echo "$usage"
162             exit 0
163             shift
164         ;;
165         -o|--offline)
166             offline=true
167         ;;
168         -r|--report)
169             report="-r"
170         ;;
171         -t|--test|--tests)
172             TEST="$2"
173             shift
174         ;;
175         *)
176             echo "unknown option $1 $2"
177             exit 1
178         ;;
179     esac
180     shift # past argument or value
181 done
182
183
184 tests_file="/home/opnfv/functest/conf/testcase-list.txt"
185 if [[ -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" ]] &&\
186    [[ -f $tests_file ]]; then
187     echo "testcase-list.txt content:";cat $test_file; echo ""
188     arr_test=($(cat $tests_file))
189 else
190     arr_test=(vping tempest vims rally)
191 fi
192 echo "arr_test: "${arr_test[@]}
193
194 BASEDIR=`dirname $0`
195 source ${BASEDIR}/common.sh
196
197
198 # Check that the given tests are correct
199 if [ "${TEST}" != "" ]; then
200     arr_test_exec=(${TEST//,/ })
201     for i in "${arr_test_exec[@]}"; do
202         if [[ " ${arr_test[*]} " != *" $i "* ]]; then
203             error "Unknown test: $i. Available tests are: ${arr_test[@]}"
204         fi
205     done
206     info "Tests to execute: ${TEST}."
207 fi
208
209 if [ $offline == false ]; then
210     info "MODE: online"
211 else
212     info "MODE: offline"
213 fi
214
215 # Check that the functest environment has been installed
216 if [ ! -f ${FUNCTEST_CONF_DIR}/env_active ]; then
217     error "The Functest environment is not installed. \
218         Please run prepare_env.sh before running this script...."
219 fi
220
221
222 # Source credentials
223 info "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the tests.."
224 source ${FUNCTEST_CONF_DIR}/openstack.creds
225
226 # Run tests
227 if [ "${TEST}" != "" ]; then
228     for i in "${arr_test_exec[@]}"; do
229         run_test $i
230     done
231 else
232     info "Executing tests..."
233     for i in "${arr_test[@]}"; do
234         run_test $i
235     done
236 fi