Reduce the number of iterations to ten in rally scenarios
[functest.git] / docker / prepare_env.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 # 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 prepare the Functest environment.
17
18 usage:
19     bash $(basename "$0") [--offline] [-h|--help] [-t <test_name>]
20
21 where:
22     -o|--offline      optional offline mode (experimental)
23     -h|--help         show this help text
24
25 examples:
26     $(basename "$0")
27     $(basename "$0") --offline"
28
29 offline=false
30
31 # Parse parameters
32 while [[ $# > 0 ]]
33     do
34     key="$1"
35     case $key in
36         -h|--help)
37             echo "$usage"
38             exit 0
39             shift
40         ;;
41         -o|--offline)
42             offline=true
43         ;;
44         *)
45             error "unknown option $1"
46             exit 1
47         ;;
48     esac
49     shift # past argument or value
50 done
51
52 BASEDIR=`dirname $0`
53 source ${BASEDIR}/common.sh
54
55 # Support for Functest offline
56 # NOTE: Still not 100% working when running the tests
57
58 info "######### Preparing Functest environment #########"
59 if [ $offline == false ]; then
60     info "MODE: online"
61 else
62     info "MODE: offline"
63 fi
64
65 # definition of available installer names
66 INSTALLERS=(fuel compass apex joid)
67
68 if [ ! -f ${FUNCTEST_CONF_DIR}/openstack.creds ]; then
69     # If credentials file is not given, check if environment variables are set
70     # to get the creds using fetch_os_creds.sh later on
71     info "Checking environment variables INSTALLER_TYPE and INSTALLER_IP"
72     if [ -z ${INSTALLER_TYPE} ]; then
73         error "Environment variable 'INSTALLER_TYPE' is not defined."
74     elif [[ ${INSTALLERS[@]} =~ ${INSTALLER_TYPE} ]]; then
75         info "INSTALLER_TYPE env variable found: ${INSTALLER_TYPE}"
76     else
77         error "Invalid environment variable INSTALLER_TYPE=${INSTALLER_TYPE}"
78     fi
79
80     if [ -z ${INSTALLER_IP} ]; then
81         error "Environment variable 'INSTALLER_IP' is not defined."
82     fi
83     info "INSTALLER_IP env variable found: ${INSTALLER_IP}"
84 fi
85
86
87 if [ $offline == false ]; then
88     # Update repos
89     info "Updating Releng repository...."
90     cd ${RELENG_REPO_DIR}
91     if [ ${RELENG_BRANCH} != "master" ]; then
92         info "Releng repo: checkout ${RELENG_BRANCH} branch..."
93         git checkout ${RELENG_BRANCH}
94     fi
95     info "Releng repo: pulling to latest..."
96     git pull
97     if [ ${RELENG_COMMIT} != "latest" ]; then
98         info "Releng repo: given commit is ${RELENG_COMMIT}. Reseting..."
99         git reset --hard ${RELENG_COMMIT}
100     fi
101
102     info "Updating Rally repository...."
103     cd ${RALLY_REPO_DIR}
104     if [ ${RALLY_BRANCH} != "master" ]; then
105         info "Rally repo: checkout ${RALLY_BRANCH} branch..."
106         git checkout ${RALLY_BRANCH}
107     fi
108     info "Rally repo: pulling to latest..."
109     git pull
110     # We leave the reset command for later.
111
112     info "Updating vIMS test repository...."
113     cd ${VIMS_REPO_DIR}
114     if [ ${VIMS_BRANCH} != "stable" ]; then
115         info "Releng repo: checkout ${VIMS_TEST_BRANCH} branch..."
116         git checkout ${VIMS_BRANCH}
117     fi
118     info "vIMS test repo: pulling to latest..."
119     git pull
120     if [ ${VIMS_COMMIT} != "latest" ]; then
121         info "vIMS test repo: given commit is ${VIMS_TEST_COMMIT}. Reseting..."
122         git reset --hard ${VIMS_COMMIT}
123     fi
124
125     info "Updating BGPVPN repository...."
126     cd ${BGPVPN_REPO_DIR}
127     if [ ${BGPVPN_BRANCH} != "master" ]; then
128         info "BGPVPN repo: checkout ${BGPVPN_BRANCH} branch..."
129         git checkout ${BGPVPN_BRANCH}
130     fi
131     info "BGPVPN repo: pulling to latest..."
132     git pull
133     if [ ${BGPVPN_COMMIT} != "latest" ]; then
134         info "BGPVPN repo: given commit is ${BGPVPN_COMMIT}. Reseting..."
135         git reset --hard ${BGPVPN_COMMIT}
136     fi
137
138     info "Updating ONOS repository...."
139     cd ${ONOS_REPO_DIR}
140     if [ ${ONOS_BRANCH} != "master" ]; then
141         info "ONOS repo: checkout ${ONOS} branch..."
142         git checkout ${ONOS_BRANCH}
143     fi
144     info "ONOS repo: pulling to latest..."
145     git pull
146     if [ ${ONOS_COMMIT} != "latest" ]; then
147         info "ONOS repo: given commit is ${ONOS_COMMIT}. Reseting..."
148         git reset --hard ${ONOS_COMMIT}
149     fi
150
151     info "Updating PROMISE repository...."
152     cd ${PROMISE_REPO_DIR}
153     if [ ${PROMISE_BRANCH} != "master" ]; then
154         info "PROMISE repo: checkout ${PROMISE} branch..."
155         git checkout ${PROMISE_BRANCH}
156     fi
157     info "PROMISE repo: pulling to latest..."
158     git pull
159     if [ ${PROMISE_COMMIT} != "latest" ]; then
160         info "PROMISE repo: given commit is ${PROMISE_COMMIT}. Reseting..."
161         git reset --hard ${PROMISE_COMMIT}
162     fi
163
164     info "Updating OVNO repository...."
165     cd ${OVNO_REPO_DIR}
166     if [ ${OVNO_BRANCH} != "master" ]; then
167         info "OVNO repo: checkout ${OVNO} branch..."
168         git checkout ${OVNO_BRANCH}
169     fi
170     info "OVNO repo: pulling to latest..."
171     git pull
172     if [ ${OVNO_COMMIT} != "latest" ]; then
173         info "OVNO repo: given commit is ${OVNO_COMMIT}. Reseting..."
174         git reset --hard ${OVNO_COMMIT}
175     fi
176
177 fi
178
179 # We do this regardless if its online or offline mode.
180 # Assumption: the docker image contains a newer rally repo than the given commit.
181 if [ ${RALLY_COMMIT} != "latest" ]; then
182     cd ${RALLY_REPO_DIR}
183     info "Rally repo: given commit is ${RALLY_COMMIT}. Reseting..."
184     git reset --hard ${RALLY_COMMIT}
185 fi
186
187 # IMPORTANT: To be removed when version 0.2.1 is out
188 git config --global user.email "functest@opnfv.com"
189 git config --global user.name "opnfv/functest"
190 git fetch https://review.openstack.org/openstack/rally refs/changes/06/270506/9 && git cherry-pick FETCH_HEAD
191
192
193 # Create directories
194 mkdir -p ${FUNCTEST_CONF_DIR}
195 mkdir -p ${FUNCTEST_DATA_DIR}
196 mkdir -p ${FUNCTEST_RESULTS_DIR}/ODL
197
198
199
200 # Create Openstack credentials file
201 if [ ! -f ${FUNCTEST_CONF_DIR}/openstack.creds ]; then
202     ${REPOS_DIR}/releng/utils/fetch_os_creds.sh -d ${FUNCTEST_CONF_DIR}/openstack.creds \
203         -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}
204     retval=$?
205     if [ $retval != 0 ]; then
206         error "Cannot retrieve credentials file from installation. Check logs."
207         exit $retval
208     fi
209 else
210     info "OpenStack credentials file given to the docker and stored in ${FUNCTEST_CONF_DIR}/openstack.creds."
211 fi
212 # Source credentials
213 source ${FUNCTEST_CONF_DIR}/openstack.creds
214
215 # Check OpenStack
216 info "Checking that the basic OpenStack services are functional..."
217 ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/check_os.sh
218 RETVAL=$?
219 if [ $RETVAL -ne 0 ]; then
220     exit 1
221 fi
222
223 # Prepare Functest Environment
224 info "Preparing Functest environment..."
225 python ${FUNCTEST_REPO_DIR}/testcases/config_functest.py --debug start
226 retval=$?
227 if [ $retval != 0 ]; then
228     error "Error when configuring Functest environment"
229     exit $retval
230 fi
231
232
233 # Generate OpenStack defaults
234 info "Generating OpenStack defaults..."
235 python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/generate_defaults.py -d
236
237
238 ifconfig eth0 mtu 1450
239
240 echo "1" > ${FUNCTEST_CONF_DIR}/env_active