forked from citrix-openstack/qa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-devstack-xen.sh
executable file
·563 lines (474 loc) · 16.7 KB
/
install-devstack-xen.sh
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
#!/bin/bash
set -eu
function print_usage_and_die
{
cat >&2 << EOF
usage: $0 XENSERVER XENSERVER_PASS PRIVKEY <optional arguments>
A simple script to use devstack to setup an OpenStack, and optionally
run tests on it. This script should be executed on an operator machine, and
it will execute commands through ssh on the remote XenServer specified.
positional arguments:
XENSERVER The address of the XenServer
XENSERVER_PASS The root password for the XenServer
PRIVKEY A passwordless private key to be used for installation.
This key will be copied over to the xenserver host, and will
be used for migration/resize tasks if multiple XenServers
used. If '-' is passed, assume the key is provided by an agent
optional arguments:
-t TEST_TYPE Type of the tests to run. One of [none, exercise, smoke, full]
defaults to none
-d DEVSTACK_SRC An URL pointing to a tar.gz snapshot of devstack. This
defaults to the official devstack repository. Can also be a local
file location.
-l LOG_FILE_DIRECTORY The directory in which to store the devstack logs on failure.
-j JEOS_URL An URL for an xva containing an exported minimal OS template
with the name jeos_template_for_devstack, to be used
as a starting point.
-e JEOS_FILENAME Save a JeOS xva to the given filename and quit. If this
parameter is specified, no private key setup or devstack
installation will be done. The exported file could be
re-used later by putting it to a webserver, and specifying
JEOS_URL.
-s SUPP_PACK_URL URL to a supplemental pack that will be installed on the host
before running any tests. The host will not be rebooted after
installing the supplemental pack, so new kernels will not be
picked up.
flags:
-f Force SR replacement. If your XenServer has an LVM type SR,
it will be destroyed and replaced with an ext SR.
WARNING: This will destroy your actual default SR !
-n No devstack, just create the JEOS template that could be
exported to an xva using the -e option.
An example run:
# Create a passwordless ssh key
ssh-keygen -t rsa -N "" -f devstack_key.priv
# Cache the XenServer's host key:
ssh-keyscan XENSERVER >> ~/.ssh/known_hosts
# Install devstack
$0 XENSERVER mypassword devstack_key.priv
$@
EOF
exit 1
}
# Defaults for optional arguments
DEVSTACK_SRC="https://github.com/openstack-dev/devstack/archive/master.tar.gz"
TEST_TYPE="none"
FORCE_SR_REPLACEMENT="false"
EXIT_AFTER_JEOS_INSTALLATION=""
LOG_FILE_DIRECTORY=""
JEOS_URL=""
JEOS_FILENAME=""
SUPP_PACK_URL=""
SCREEN_LOGDIR="/opt/stack/devstack_logs"
# Get Positional arguments
set +u
XENSERVER="$1"
shift || print_usage_and_die "ERROR: XENSERVER not specified!"
XENSERVER_PASS="$1"
shift || print_usage_and_die "ERROR: XENSERVER_PASS not specified!"
PRIVKEY="$1"
shift || print_usage_and_die "ERROR: PRIVKEY not specified!"
set -u
# Number of options passed to this script
REMAINING_OPTIONS="$#"
# Get optional parameters
set +e
while getopts ":t:d:fnl:j:e:s:" flag; do
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
case "$flag" in
t)
TEST_TYPE="$OPTARG"
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
if ! [ "$TEST_TYPE" = "none" -o "$TEST_TYPE" = "smoke" -o "$TEST_TYPE" = "full" -o "$TEST_TYPE" = "exercise" ]; then
print_usage_and_die "$TEST_TYPE - Invalid value for TEST_TYPE"
fi
;;
d)
DEVSTACK_SRC="$OPTARG"
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
;;
f)
FORCE_SR_REPLACEMENT="true"
;;
n)
EXIT_AFTER_JEOS_INSTALLATION="true"
;;
l)
LOG_FILE_DIRECTORY="$OPTARG"
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
;;
j)
JEOS_URL="$OPTARG"
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
;;
e)
JEOS_FILENAME="$OPTARG"
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
;;
s)
SUPP_PACK_URL="$OPTARG"
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
;;
\?)
print_usage_and_die "Invalid option -$OPTARG"
;;
esac
done
set -e
# Make sure that all options processed
if [ "0" != "$REMAINING_OPTIONS" ]; then
print_usage_and_die "ERROR: some arguments were not recognised!"
fi
# Set up internal variables
_SSH_OPTIONS="\
-q \
-o BatchMode=yes \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null"
if [ "$PRIVKEY" != "-" ]; then
_SSH_OPTIONS="$_SSH_OPTIONS -i $PRIVKEY"
fi
# Print out summary
cat << EOF
XENSERVER: $XENSERVER
XENSERVER_PASS: $XENSERVER_PASS
PRIVKEY: $PRIVKEY
TEST_TYPE: $TEST_TYPE
DEVSTACK_SRC: $DEVSTACK_SRC
FORCE_SR_REPLACEMENT: $FORCE_SR_REPLACEMENT
JEOS_URL: ${JEOS_URL:-template will not be imported}
JEOS_FILENAME: ${JEOS_FILENAME:-not exporting JeOS}
SUPP_PACK_URL: ${SUPP_PACK_URL:-no supplemental pack}
EOF
# Helper function
function on_xenserver() {
ssh $_SSH_OPTIONS "root@$XENSERVER" bash -s --
}
function assert_tool_exists() {
local tool_name
tool_name="$1"
if ! which "$tool_name" >/dev/null; then
echo "ERROR: $tool_name is required for this script, please install it on your system! " >&2
exit 1
fi
}
if [ -z "$JEOS_FILENAME" ]; then
echo -n "Setup ssh keys on XenServer..."
tmp_dir="$(mktemp -d)"
COPY_KEY=""
if [ "$PRIVKEY" != "-" ]; then
cp $PRIVKEY "$tmp_dir/devstack"
ssh-keygen -y -f $PRIVKEY > "$tmp_dir/devstack.pub"
COPY_KEY="$tmp_dir/devstack.pub"
fi
assert_tool_exists sshpass
sshpass -p "$XENSERVER_PASS" \
ssh-copy-id \
-i $COPY_KEY \
root@$XENSERVER > /dev/null 2>&1
if [ "$PRIVKEY" != "-" ]; then
scp $_SSH_OPTIONS $PRIVKEY "root@$XENSERVER:.ssh/id_rsa"
scp $_SSH_OPTIONS $tmp_dir/devstack.pub "root@$XENSERVER:.ssh/id_rsa.pub"
fi
rm -rf "$tmp_dir"
unset tmp_dir
echo "OK"
else
echo -n "Exporting JeOS template..."
on_xenserver << END_OF_EXPORT_COMMANDS
set -eu
JEOS_TEMPLATE="\$(xe template-list name-label="jeos_template_for_devstack" --minimal)"
if [ -z "\$JEOS_TEMPLATE" ]; then
echo "FATAL: jeos_template_for_devstack not found"
exit 1
fi
rm -f /root/jeos-for-devstack.xva
xe template-export template-uuid="\$JEOS_TEMPLATE" filename="/root/jeos-for-devstack.xva" compress=true
END_OF_EXPORT_COMMANDS
echo "OK"
echo -n "Copy exported template to local file..."
if scp -3 $_SSH_OPTIONS "root@$XENSERVER:/root/jeos-for-devstack.xva" "$JEOS_FILENAME"; then
echo "OK"
RETURN_CODE=0
else
echo "FAILED"
RETURN_CODE=1
fi
echo "Cleanup: delete exported template from XenServer"
on_xenserver << END_OF_CLEANUP
set -eu
rm -f /root/jeos-for-devstack.xva
END_OF_CLEANUP
echo "JeOS export done, exiting."
exit $RETURN_CODE
fi
TMPDIR=$(echo "mktemp -d" | on_xenserver)
function copy_logs_on_failure() {
set +e
$@
EXIT_CODE=$?
set -e
if [ $EXIT_CODE -ne 0 ]; then
copy_logs
exit $EXIT_CODE
fi
}
function copy_logs() {
if [ -n "$LOG_FILE_DIRECTORY" ]; then
on_xenserver << END_OF_XENSERVER_COMMANDS
set -xu
cd $TMPDIR
cd devstack*
mkdir -p /root/artifacts
GUEST_IP=\$(. "tools/xen/functions" && find_ip_by_name DevStackOSDomU 0)
if [ -n \$GUEST_IP ]; then
ssh -q \
-o Batchmode=yes \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
stack@\$GUEST_IP "tar --ignore-failed-read -czf - ${SCREEN_LOGDIR}/* /opt/stack/tempest/*.xml" > \
/root/artifacts/domU.tgz < /dev/null || true
fi
tar --ignore-failed-read -czf /root/artifacts/dom0.tgz /var/log/messages* /var/log/xensource* /var/log/SM* || true
END_OF_XENSERVER_COMMANDS
mkdir -p $LOG_FILE_DIRECTORY
scp $_SSH_OPTIONS $XENSERVER:artifacts/* $LOG_FILE_DIRECTORY
tar -xzf $LOG_FILE_DIRECTORY/domU.tgz opt/stack/tempest/tempest-full.xml -O \
> $LOG_FILE_DIRECTORY/tempest-full.xml || true
fi
}
echo -n "Generate id_rsa.pub..."
echo "ssh-keygen -y -f .ssh/id_rsa > .ssh/id_rsa.pub" | on_xenserver
echo "OK"
echo -n "Verify that XenServer can log in to itself..."
if echo "ssh -o StrictHostKeyChecking=no $XENSERVER true" | on_xenserver; then
echo "OK"
else
echo ""
echo ""
echo "ERROR: XenServer couldn't authenticate to itself. This might"
echo "be caused by having a key originally installed on XenServer"
echo "consider using the -w parameter to wipe all your ssh settings"
echo "on XenServer."
exit 1
fi
echo -n "Verify XenServer has an ext type default SR..."
copy_logs_on_failure on_xenserver << END_OF_SR_OPERATIONS
set -eu
# Verify the host is suitable for devstack
defaultSR=\$(xe pool-list params=default-SR minimal=true)
currentSrType=\$(xe sr-param-get uuid=\$defaultSR param-name=type)
if [ "\$currentSrType" != "ext" -a "\$currentSrType" != "nfs" -a "\$currentSrType" != "ffs" -a "\$currentSrType" != "file" ]; then
if [ "true" == "$FORCE_SR_REPLACEMENT" ]; then
echo ""
echo ""
echo "Trying to replace the default SR with an EXT SR"
pbd_uuid=\`xe pbd-list sr-uuid=\$defaultSR minimal=true\`
host_uuid=\`xe pbd-param-get uuid=\$pbd_uuid param-name=host-uuid\`
use_device=\`xe pbd-param-get uuid=\$pbd_uuid param-name=device-config param-key=device\`
# Destroy the existing SR
xe pbd-unplug uuid=\$pbd_uuid
xe sr-destroy uuid=\$defaultSR
sr_uuid=\`xe sr-create content-type=user host-uuid=\$host_uuid type=ext device-config:device=\$use_device shared=false name-label="Local storage"\`
pool_uuid=\`xe pool-list minimal=true\`
xe pool-param-set default-SR=\$sr_uuid uuid=\$pool_uuid
xe pool-param-set suspend-image-SR=\$sr_uuid uuid=\$pool_uuid
xe sr-param-add uuid=\$sr_uuid param-name=other-config i18n-key=local-storage
exit 0
fi
echo ""
echo ""
echo "ERROR: The xenserver host must have an EXT3/NFS/FFS/File SR as the default SR"
echo "Use the -f flag to destroy the current default SR and create a new"
echo "ext type default SR."
echo ""
echo "WARNING: This will destroy your actual default SR !"
echo ""
exit 1
fi
END_OF_SR_OPERATIONS
echo "OK"
echo -n "Get the IP address of XenServer..."
XENSERVER_IP=$(on_xenserver << GET_XENSERVER_IP
xe host-list params=address minimal=true
GET_XENSERVER_IP
)
if [ -z "$XENSERVER_IP" ]; then
echo "Failed to detect the IP address of XenServer"
exit 1
fi
echo "OK"
if [ -n "$SUPP_PACK_URL" ]; then
echo -n "Applying supplemental pack"
on_xenserver <<SUPP_PACK
set -eu
wget -qO /root/supp_pack_for_devstack.iso $SUPP_PACK_URL
xe-install-supplemental-pack /root/supp_pack_for_devstack.iso
reboot
SUPP_PACK
echo -n "Rebooted host; waiting 10 minutes"
sleep 10m
fi
echo -n "Hack ISCSISR.py on XenServer (original saved to /root/ISCSISR.py.orig)..."
on_xenserver << HACK_ISCSI_SR
set -eu
iscsi_target_file=""
for candidate_file in "/opt/xensource/sm/ISCSISR.py" "/usr/lib64/xcp-sm/ISCSISR.py"; do
if [ -e "\$candidate_file" ]; then
iscsi_target_file=\$candidate_file
fi
done
if [ -n "\$iscsi_target_file" ]; then
if ! [ -e "/root/ISCSISR.py.orig" ]; then
cp \$iscsi_target_file /root/ISCSISR.py.orig
fi
sed -e "s/'phy'/'aio'/g" /root/ISCSISR.py.orig > \$iscsi_target_file
fi
HACK_ISCSI_SR
echo "OK"
if [ -n "$JEOS_URL" ]; then
echo "(re-)importing JeOS template"
on_xenserver << END_OF_JEOS_IMPORT
set -eu
JEOS_TEMPLATE="\$(xe template-list name-label="jeos_template_for_devstack" --minimal)"
if [ -n "\$JEOS_TEMPLATE" ]; then
echo " jeos_template_for_devstack already exist, uninstalling"
xe template-uninstall template-uuid="\$JEOS_TEMPLATE" force=true > /dev/null
fi
rm -f /root/jeos-for-devstack.xva
echo " downloading $JEOS_URL to /root/jeos-for-devstack.xva"
wget -qO /root/jeos-for-devstack.xva "$JEOS_URL"
echo " importing /root/jeos-for-devstack.xva"
xe vm-import filename=/root/jeos-for-devstack.xva
rm -f /root/jeos-for-devstack.xva
echo " verify template imported"
JEOS_TEMPLATE="\$(xe template-list name-label="jeos_template_for_devstack" --minimal)"
if [ -z "\$JEOS_TEMPLATE" ]; then
echo "FATAL: template jeos_template_for_devstack does not exist after import."
exit 1
fi
END_OF_JEOS_IMPORT
echo "OK"
fi
if [ -e $DEVSTACK_SRC ]; then
copy_logs_on_failure on_xenserver << END_OF_XENSERVER_COMMANDS
set -eu
mkdir -p $TMPDIR/devstack-local
END_OF_XENSERVER_COMMANDS
scp $_SSH_OPTIONS -r $DEVSTACK_SRC/* "root@$XENSERVER:$TMPDIR/devstack-local"
else
copy_logs_on_failure on_xenserver << END_OF_XENSERVER_COMMANDS
set -exu
cd $TMPDIR
wget -qO - "$DEVSTACK_SRC" |
tar -xzf -
cd devstack*
END_OF_XENSERVER_COMMANDS
fi
copy_logs_on_failure on_xenserver << END_OF_XENSERVER_COMMANDS
set -exu
cd $TMPDIR
cd devstack*
cat << LOCALRC_CONTENT_ENDS_HERE > localrc
# Passwords
MYSQL_PASSWORD=citrix
SERVICE_TOKEN=citrix
ADMIN_PASSWORD=citrix
SERVICE_PASSWORD=citrix
RABBIT_PASSWORD=citrix
GUEST_PASSWORD=citrix
XENAPI_PASSWORD="$XENSERVER_PASS"
SWIFT_HASH="66a3d6b56c1f479c8b4e70ab5c2000f5"
# Use xvdb for backing cinder volumes
XEN_XVDB_SIZE_GB=20
VOLUME_BACKING_DEVICE=/dev/xvdb
# Nice short names, so we could export an XVA
VM_BRIDGE_OR_NET_NAME="osvmnet"
PUB_BRIDGE_OR_NET_NAME="ospubnet"
XEN_INT_BRIDGE_OR_NET_NAME="osintnet"
# As we have nice names, specify FLAT_NETWORK_BRIDGE
# This requires https://review.openstack.org/48296 to land
# FLAT_NETWORK_BRIDGE="osvmnet"
# Do not use secure delete
CINDER_SECURE_DELETE=False
# Compute settings
EXTRA_OPTS=("xenapi_disable_agent=True")
API_RATE_LIMIT=False
VIRT_DRIVER=xenserver
# Use a XenServer Image
IMAGE_URLS="\
https://github.com/downloads/citrix-openstack/warehouse/cirros-0.3.0-x86_64-disk.vhd.tgz"
DEFAULT_IMAGE_NAME="cirros-0.3.0-x86_64-disk"
# OpenStack VM settings
OSDOMU_VDI_GB=40
# Exercise settings
ACTIVE_TIMEOUT=500
TERMINATE_TIMEOUT=500
# Increase boot timeout for neutron tests:
BOOT_TIMEOUT=500
# DevStack settings
LOGFILE=${SCREEN_LOGDIR}/stack.log
SCREEN_LOGDIR=${SCREEN_LOGDIR}
# Turn on verbosity (password input does not work otherwise)
VERBOSE=True
# XenAPI specific
XENAPI_CONNECTION_URL="http://$XENSERVER_IP"
VNCSERVER_PROXYCLIENT_ADDRESS="$XENSERVER_IP"
MULTI_HOST=1
# Skip boot from volume exercise
# See https://bugs.launchpad.net/openstack-ci/+bug/1263824 for euca and bundle
SKIP_EXERCISES="boot_from_volume,bundle,euca"
ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-sch,horizon,mysql,rabbit,sysstat,tempest,s-proxy,s-account,s-container,s-object,cinder,c-api,c-vol,c-sch,n-cond,heat,h-api,h-api-cfn,h-api-cw,h-eng,n-net
# XEN_FIREWALL_DRIVER=nova.virt.xenapi.firewall.Dom0IptablesFirewallDriver
XEN_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
# 9 Gigabyte for object store
SWIFT_LOOPBACK_DISK_SIZE=9663676416
# Additional Localrc parameters here
INSTALL_TESTONLY_PACKAGES=True
UBUNTU_INST_HTTP_HOSTNAME=mirror.cc.columbia.edu
UBUNTU_INST_HTTP_DIRECTORY=/pub/linux/ubuntu/archive
LOCALRC_CONTENT_ENDS_HERE
# XenServer doesn't have nproc by default - but it's used by stackrc.
# Fake it up if one doesn't exist
set +e
which nproc > /dev/null 2>&1
if [ \$? -ne 0 ]; then
cat >> /usr/local/bin/nproc << END_OF_NPROC
#!/bin/bash
cat /proc/cpuinfo | grep -c processor
END_OF_NPROC
chmod +x /usr/local/bin/nproc
fi
cd tools/xen
EXIT_AFTER_JEOS_INSTALLATION="$EXIT_AFTER_JEOS_INSTALLATION" ./install_os_domU.sh
END_OF_XENSERVER_COMMANDS
if [ "$TEST_TYPE" == "none" ]; then
exit 0
fi
# Run tests
copy_logs_on_failure on_xenserver << END_OF_XENSERVER_COMMANDS
set -exu
cd $TMPDIR
cd devstack*
GUEST_IP=\$(. "tools/xen/functions" && find_ip_by_name DevStackOSDomU 0)
ssh -q \
-o Batchmode=yes \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
"stack@\$GUEST_IP" bash -s -- << END_OF_DEVSTACK_COMMANDS
set -exu
# Pin to 1.6.1 due to https://bugs.launchpad.net/openstack-ci/+bug/1274135
sudo pip install tox==1.6.1
cd /opt/stack/tempest
if [ "$TEST_TYPE" == "exercise" ]; then
tox -eall tempest.scenario.test_server_basic_ops
elif [ "$TEST_TYPE" == "smoke" ]; then
#./run_tests.sh -s -N
tox -esmoke
elif [ "$TEST_TYPE" == "full" ]; then
#nosetests -sv --with-xunit --xunit-file=tempest-full.xml tempest/api tempest/scenario tempest/thirdparty tempest/cli
tox -efull
fi
END_OF_DEVSTACK_COMMANDS
END_OF_XENSERVER_COMMANDS
copy_logs