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