forked from dave-tucker/odl-openstack-ci
-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions
executable file
·364 lines (303 loc) · 9.69 KB
/
functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#!/bin/bash
function echo-step {
printf "\n"
echo "-----> $1"
printf "\n"
}
function die() {
echo >&2 -e "\nERROR: $@\n"
exit 1
}
function run() {
$*
code=$?
[ $code -ne 0 ] && die "command [$*] failed with error code $code"
}
function cleanup {
run sudo rm -r $DEVSTACKDIR
#run sudo rm -r /opt/stack/tempest
run sudo rm -rf /usr/lib/python2.7/site-packages/*client*
}
function check-env {
echo-step "Environment Variables are..."
run env
}
function prepare-environment {
echo-step "Creating Devstack Directory"
run mkdir -p $DEVSTACKDIR
run ln -sf $DEVSTACKDIR/devstack $WORKSPACE
run sudo mkdir -p /opt/stack
run sudo chown $(whoami) /opt/stack
run sudo chmod 755 /opt/stack
}
function configure-firewall {
echo-step "Configuring Firewall"
cat <<EOL > $WORKSPACE/firewall.sh
sudo iptables -I INPUT -p tcp --dport 5672 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 9292 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 9696 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 35357 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 6080 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 8773 -j ACCEPT
sudo iptables -I INPUT -p udp --dport 8472 -j ACCEPT
sudo iptables -I INPUT -p udp --dport 4789 -j ACCEPT
# For the client
sudo iptables -I INPUT -p tcp --dport 5000 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 8774 -j ACCEPT
# For ODL/Swift
sudo iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 8087 -j ACCEPT
EOL
echo "Firewall Configuration is..."
run chmod +x $WORKSPACE/firewall.sh
run cat $WORKSPACE/firewall.sh
run $WORKSPACE/firewall.sh
}
function install-packages {
echo-step "Installing Prerequisite Packages"
if [ "$IS_FEDORA" == "1" ]; then
run sudo yum -q -y install qemu libvirt-daemon
else
run sudo apt-get -y update
run sudo apt-get -y install qemu libvirt0
fi
}
function install-pip {
if [ "$IS_UBUNTU" == "1" ]; then
echo-step "Installing setuptools"
run sudo apt-get -y install python-setuptools
fi
echo-step "Installing python-pip"
cd $WORKSPACE
run curl -O https://pypi.python.org/packages/source/p/pip/pip-6.0.8.tar.gz -s
run tar xzvf pip-6.0.8.tar.gz > /dev/null
cd $WORKSPACE/pip-6.0.8
run sudo -E python setup.py -q install
echo-step "Installing testools"
run sudo pip install -q testtools
}
function install-tempest {
echo-step "Cloning and Installing Tempest"
cd /opt/stack
run git clone -q git://git.openstack.org/openstack/tempest.git
cd /opt/stack/tempest
run sudo python ./setup.py -q install > /dev/null
}
function install-workarounds {
echo-step "Work arounds"
# Workaround for bug:
# https://bugs.launchpad.net/devstack/+bug/1276297
run sudo rm -rf /usr/lib/python2.7/site-packages/oslo*
# Workaround for "keystone not found" issues
run sudo rm -rf /usr/lib/python2.7/site-packages/*client*
# Make sure keystonemiddleware is up to date
run sudo pip install --upgrade keystonemiddleware
# # Workaround: Pull neutron first
# cd /opt/stack
# git clone -q git://git.openstack.org/openstack/neutron.git
# cd neutron
# run sudo python ./setup.py -q install
}
function install-devstack {
echo-step "Cloning Devstack"
cd $DEVSTACKDIR
if [ "$GERRIT_PROJECT" == "openstack-dev/devstack" ]; then
echo-step "This is a Devstack patch - cloning into $GERRIT_REFSPEC"
run git fetch https://$GERRIT_HOST/$GERRIT_PROJECT $GERRIT_REFSPEC
run git checkout FETCH_HEAD
else
run git clone -q https://github.com/openstack-dev/devstack.git
fi
cd $DEVSTACKDIR/devstack
echo-step "Writing local.conf"
####
# Specify changeset being worked on if it's networking-odl
####
if [ "$GERRIT_PROJECT" == "stackforge/networking-odl" ]; then
cat <<EOLLC > local.conf
[[local|localrc]]
enable_plugin networking-odl https://$GERRIT_HOST/$GERRIT_PROJECT $GERRIT_REFSPEC
EOLLC
else
cat <<EOLLC > local.conf
[[local|localrc]]
enable_plugin networking-odl https://github.com/stackforge/networking-odl
EOLLC
fi
cat <<EOLLC >> local.conf
LOGFILE=stack.sh.log
SCREEN_LOGDIR=/opt/stack/data/log
VERBOSE=True
LOG_COLOR=False
#OFFLINE=True
RECLONE=yes
GIT_TIMEOUT=0
GIT_BASE=https://git.openstack.org
EOLLC
if [ "$IS_FEDORA" == "1" ]; then
cat <<EOLLC >> local.conf
HOST_IP=$(ip addr | grep inet | grep enp0s8 | awk -F" " '{print $2}'| sed -e 's/\/.*$//')
EOLLC
else
cat <<EOLLC >> local.conf
HOST_IP=$(ip addr | grep inet | grep eth1 | awk -F" " '{print $2}'| sed -e 's/\/.*$//')
EOLLC
fi
cat <<EOLLC >> local.conf
HOST_NAME=$(hostname)
SERVICE_HOST=\$HOST_IP
SERVICE_HOST_NAME=\$HOST_NAME
Q_HOST=\$SERVICE_HOST
MYSQL_HOST=\$SERVICE_HOST
RABBIT_HOST=\$SERVICE_HOST
GLANCE_HOSTPORT=\$SERVICE_HOST:9292
KEYSTONE_AUTH_HOST=\$SERVICE_HOST
KEYSTONE_SERVICE_HOST=\$SERVICE_HOST
MYSQL_PASSWORD=mysql
RABBIT_PASSWORD=rabbit
QPID_PASSWORD=rabbit
SERVICE_TOKEN=service
SERVICE_PASSWORD=admin
ADMIN_PASSWORD=admin
EOLLC
# Use qpid instead of rabbit in fedora, excluding centos
if [ "$IS_FEDORA" == "1" ] && [ "$IS_CENTOS" != "1" ]; then
cat <<EOLLC >> local.conf
disable_service rabbit
enable_service qpid
EOLLC
fi
cat <<EOLLC >> local.conf
disable_service swift
disable_service cinder
disable_service c-sch
disable_service c-api
disable_service c-vol
enable_service n-cond
enable_service n-cpu
disable_service n-net
enable_service q-svc
# enable_service q-agt
enable_service q-dhcp
enable_service q-l3
enable_service q-meta
enable_service quantum
enable_service tempest
API_RATE_LIMIT=False
Q_PLUGIN=ml2
Q_ML2_PLUGIN_MECHANISM_DRIVERS=logger,opendaylight
ODL_MODE=allinone
ODL_NETVIRT_DEBUG_LOGS=True
ODL_MGR_IP=\$SERVICE_HOST
ODL_ARGS="-Xmx1024m -XX:MaxPermSize=512m"
ODL_BOOT_WAIT=15
ENABLE_TENANT_TUNNELS=True
EOLLC
if [ "$ODL_URL" != "" ]; then
cat <<EOLLC >> local.conf
ODL_URL=$ODL_URL
ODL_PKG=$ODL_PKG
ODL_NAME=$ODL_NAME
EOLLC
fi
if [ "$GERRIT_PROJECT" == "openstack/neutron" ]; then
cat <<EOLLC >> local.conf
NEUTRON_REPO=https://$GERRIT_HOST/$GERRIT_PROJECT
NEUTRON_BRANCH=$GERRIT_REFSPEC
EOLLC
fi
echo-step "Local.conf is..."
cat local.conf
}
function stack {
cd $DEVSTACKDIR/devstack
echo-step "Stacking"
./stack.sh > /dev/null
if [ "$?" != "0" ]; then
echo "stack.sh failed"
echo "The last 20 lines of stack.sh.log were..."
printf "\n"
tail -n 20 $DEVSTACKDIR/devstack/stack.sh.log
printf "\n"
echo "Please see the Jenkins for the full logs"
exit 1
fi
}
function unstack {
cd $DEVSTACKDIR/devstack
echo-step "Unstacking"
./unstack.sh > /dev/null
}
function run-tempest {
# Run a Tempest test and log results
echo-step "Running Tempest"
if [[ -n ${BUILD_ID} ]]; then
cd /opt/stack/tempest
echo "Running tempest tests:" > $TEMPEST_RUN_LOG
echo "" >> $TEMPEST_RUN_LOG
testr init > /dev/null 2>&1 || true
cmd_api="tempest.api.network.test_networks tempest.api.network.test_networks_negative tempest.api.network.test_ports tempest.api.network.test_routers"
cmd_net_basic="tempest.scenario.test_network_basic_ops"
cmd_net_adv="tempest.scenario.test_network_advanced_server_ops"
cmd="testr run $cmd_api $cmd_net_basic"
echo "opendaylight-test:$ "${cmd} >> $TEMPEST_RUN_LOG
${cmd} >> $TEMPEST_RUN_LOG
echo "" >> $TEMPEST_RUN_LOG
echo "" >> $TEMPEST_RUN_LOG
x=$(grep "(id=" $TEMPEST_RUN_LOG)
y="${x//[()=]/ }"
z=$(echo ${y} | awk '{print $3}' | sed 's/\,//g')
#echo "x ($x) y ($y) z ($z)"
echo "List of tempest tests ran (id="${z}"):" >> $TEMPEST_RUN_LOG
echo "" >> $TEMPEST_RUN_LOG
grep -ri successful: .testrepository/${z} | awk '{ gsub(/\[/, "\ "); print $1 " " $2}' >> $TEMPEST_RUN_LOG
fi
}
function archive-logs {
echo-step "Archiving Logs"
mkdir -p $WORKSPACE/logs/devstack
mkdir -p $WORKSPACE/logs/tempest
mkdir -p $WORKSPACE/logs/opendaylight
if [ -f /opt/stack/tempest/tempest.log ]; then
cp -r /opt/stack/tempest/tempest.log* $WORKSPACE/logs/tempest
fi
if [ -d /opt/stack/data/log ]; then
cp -a /opt/stack/data/log/* $WORKSPACE/logs/devstack
fi
if [ -d /opt/stack/opendaylight ]; then
cp -r /opt/stack/opendaylight/*/logs $WORKSPACE/logs/opendaylight
cp -r /opt/stack/opendaylight/*/data/log $WORKSPACE/logs/opendaylight
fi
if [ -f $TEMPEST_RUN_LOG ]; then
cp -r $TEMPEST_RUN_LOG $WORKSPACE/logs
cp -r $TEMPEST_RUN_LOG $WORKSPACE
fi
if [ -f $DEVSTACKDIR/devstack/stack.sh.log ]; then
cp -r $DEVSTACKDIR/devstack/stack.sh.log* $WORKSPACE/logs
fi
if [ -f $DEVSTACKDIR/devstack/local.conf ]; then
cp -r $DEVSTACKDIR/devstack/local.conf $WORKSPACE/logs
fi
tar cvzf $WORKSPACE/opendaylight-full-logs.tgz $WORKSPACE/logs
cleanup
}
function test-branch {
echo-step "Looking to install custom Neutron repository"
if [ "$GERRIT_PROJECT" != "" ]; then
export GERRIT_HOST=review.openstack.org
export GERRIT_PROJECT=openstack/neutron
# Read in NEUTRON_BRANCH if it's not set
if [ "$GERRIT_REFSPEC" == "" ]; then
echo "Please enter the branch you want to test: "
read GERRIT_REFSPEC
fi
echo "Variables set:"
echo "GERRIT_PROJECT: $GERRIT_PROJECT"
echo "GERRIT_HOST: $GERRIT_HOST"
echo "GERRIT_PROJECT: $GERRIT_PROJECT"
echo "GERRIT_REFSPEC: $GERRIT_REFSPEC"
else
echo "Not testing specific branch, working with origin/master."
fi
}