add doctor test case
[functest.git] / docker / run_tests.sh
1 #!/bin/bash
2
3 #
4 # Author: Jose Lausuch (jose.lausuch@ericsson.com)
5 #
6 # Installs the Functest framework within the Docker container
7 # and run the tests automatically
8 #
9
10 usage="Script to trigger the tests automatically.
11
12 usage:
13     bash $(basename "$0") [--offline] [-h|--help] [-t <test_name>]
14
15 where:
16     -o|--offline      optional offline mode (experimental)
17     -h|--help         show this help text
18     -r|--report       push results to database (false by default)
19     -t|--test         run specific set of tests
20       <test_name>     one or more of the following: vping,odl,rally,tempest,vims,onos, promise. Separated by comma.
21
22
23 examples:
24     $(basename "$0")
25     $(basename "$0") --test vping,odl
26     $(basename "$0") --offline -t tempest,rally"
27
28
29 # Support for Functest offline
30 # NOTE: Still not 100% working when running the tests
31 offline=false
32 report=""
33 # Get the list of runnable tests
34 # Check if we are in CI mode
35 if [[ -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" ]]; then
36      testcase=`cat /home/opnfv/functest/conf/testcase-list.txt`
37      arr_test=("$testcase")
38 else
39     arr_test=(vping odl tempest vims rally onos)
40 fi
41
42 function clean_openstack(){
43     python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/clean_openstack.py \
44         --debug
45 }
46
47 function run_test(){
48     test_name=$1
49     echo "----------------------------------------------"
50     echo "------------- Running $i test case  "
51     echo "----------------------------------------------"
52     case $test_name in
53         "vping")
54             info "Running vPing test..."
55             python ${FUNCTEST_REPO_DIR}/testcases/vPing/CI/libraries/vPing.py \
56                 --debug ${report}
57         ;;
58         "odl")
59             info "Running ODL test..."
60             neutron_ip=$(keystone catalog --service identity | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
61             odl_ip=$(keystone catalog --service network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
62             usr_name=$(env | grep OS | grep OS_USERNAME | cut -f2 -d'=')
63             password=$(env | grep OS | grep OS_PASSWORD | cut -f2 -d'=')
64             odl_port=8181
65             if [ $INSTALLER_TYPE == "fuel" ]; then
66                 odl_port=8282
67             elif [ $INSTALLER_TYPE == "apex" ]; then
68                 pass
69             elif [ $INSTALLER_TYPE == "joid" ]; then
70                 pass
71             elif [ $INSTALLER_TYPE == "compass" ]; then
72                 pass
73             else
74                 error "INSTALLER_TYPE not valid."
75                 exit 1
76             fi
77             ODL_PORT=$odl_port ODL_IP=$odl_ip NEUTRON_IP=$neutron_ip USR_NAME=$usr_name PASS=$password \
78                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
79
80             # save ODL results
81             odl_logs="${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/logs"
82             if [ -d ${odl_logs} ]; then
83                 cp -Rf  ${odl_logs} ${FUNCTEST_CONF_DIR}/ODL/
84             fi
85         ;;
86         "tempest")
87             info "Running Tempest tests..."
88             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_tempest.py \
89                 --debug -m custom ${report}
90             # save tempest.conf for further troubleshooting
91             tempest_conf="${RALLY_VENV_DIR}/tempest/for-deployment-*/tempest.conf"
92             if [ -f ${tempest_conf} ]; then
93                 cp $tempest_conf ${FUNCTEST_CONF_DIR}
94             fi
95             clean_openstack
96         ;;
97         "vims")
98             info "Running vIMS test..."
99             python ${FUNCTEST_REPO_DIR}/testcases/vIMS/CI/vIMS.py \
100                 --debug ${report}
101             clean_openstack
102         ;;
103         "rally")
104             info "Running Rally benchmark suite..."
105             cinder type-create volume-test #provisional
106             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_rally.py \
107                 --debug all ${report}
108             cinder type-delete $(cinder type-list|grep test|awk '{print $2}')
109             clean_openstack
110
111         ;;
112         "bgpvpn_template")
113             info "Running BGPVPN Tempest test case..."
114             tempest_dir=$(find /root/.rally -type d -name for-deploy*)
115             # TODO:
116             # do the call of your test case here.
117             # the bgpvpn repo is cloned in $BGPVPN_REPO_DIR
118             # tempest is installed in $tempest_dir
119             # Suggestion:
120             #   mkdir ${tempest_dir}/tempest/api/bgpvpn/
121             #   cp ${BGPVPN_REPO_DIR}/networking_bgpvpn_tempest/<whatever you need> \
122             #       ${tempest_dir}/tempest/api/bgpvpn/
123             #   ${tempest_dir}/run_tempest.sh tempest.api.bgpvpn.<test_case_name>
124        ;;
125         "onos")
126             info "Running ONOS test case..."
127             python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
128       ;;
129         "promise")
130             info "Running PROMISE test case..."
131             # TODO
132         ;;
133         "doctor")
134             info "Running Doctor test..."
135             python ${FUNCTEST_REPO_DIR}/testcases/features/doctor.py
136         ;;
137     esac
138 }
139
140
141 # Parse parameters
142 while [[ $# > 0 ]]
143     do
144     key="$1"
145     case $key in
146         -h|--help)
147             echo "$usage"
148             exit 0
149             shift
150         ;;
151         -o|--offline)
152             offline=true
153         ;;
154         -r|--report)
155             report="-r"
156         ;;
157         -t|--test|--tests)
158             TEST="$2"
159             shift
160         ;;
161         *)
162             echo "unknown option $1 $2"
163             exit 1
164         ;;
165     esac
166     shift # past argument or value
167 done
168
169 BASEDIR=`dirname $0`
170 source ${BASEDIR}/common.sh
171
172
173 # Check that the given tests are correct
174 if [ "${TEST}" != "" ]; then
175     arr_test_exec=(${TEST//,/ })
176     for i in "${arr_test_exec[@]}"; do
177         if [[ " ${arr_test[*]} " != *" $i "* ]]; then
178             error "Unknown test: $i. Available tests are: ${arr_test[@]}"
179         fi
180     done
181     info "Tests to execute: ${TEST}."
182 fi
183
184 if [ $offline == false ]; then
185     info "MODE: online"
186 else
187     info "MODE: offline"
188 fi
189
190 # Check that the functest environment has been installed
191 if [ ! -f ${FUNCTEST_CONF_DIR}/env_active ]; then
192     error "The Functest environment is not installed. \
193         Please run prepare_env.sh before running this script...."
194 fi
195
196
197 # Source credentials
198 info "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the tests.."
199 source ${FUNCTEST_CONF_DIR}/openstack.creds
200
201 # Run tests
202 if [ "${TEST}" != "" ]; then
203     for i in "${arr_test_exec[@]}"; do
204         run_test $i
205     done
206 else
207     info "Executing all the tests"
208     for i in "${arr_test[@]}"; do
209         run_test $i
210     done
211 fi