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