1
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
1
# Copyright 2009 Canonical Ltd. This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
4
"""Code to actually run the tests in an EC2 instance."""
19
19
from bzrlib.config import GlobalConfig
20
20
from bzrlib.errors import UncommittedChanges
21
21
from bzrlib.plugins.pqm.pqm_submit import (
22
NoPQMSubmissionAddress,
22
NoPQMSubmissionAddress, PQMSubmission)
27
25
TRUNK_BRANCH = 'bzr+ssh://bazaar.launchpad.net/~launchpad-pqm/launchpad/devel'
201
199
pqm_submit_location = trunk_branch
202
200
elif pqm_submit_location is None and trunk_specified:
203
201
pqm_submit_location = trunk_branch
204
# Modified from pqm_submit.py.
202
# modified from pqm_submit.py
205
203
submission = PQMSubmission(
206
204
source_branch=bzrbranch,
207
205
public_location=pqm_public_location,
209
207
submit_location=pqm_submit_location,
211
209
if tree is not None:
212
# This is the part we want to do whether we're
214
submission.check_tree() # Any working changes.
215
submission.check_public_branch() # Everything public.
210
# this is the part we want to do whether or not we're
212
submission.check_tree() # any working changes
213
submission.check_public_branch() # everything public
216
214
branch = submission.public_location
217
215
if (include_download_cache_changes is None or
218
216
include_download_cache_changes):
219
# We need to get the download cache settings.
217
# We need to get the download cache settings
220
218
cache_tree, cache_bzrbranch, cache_relpath = (
221
219
BzrDir.open_containing_tree_or_branch(
241
239
if pqm_message is not None:
242
240
if self.download_cache_additions:
243
241
raise UncommittedChanges(cache_tree)
244
# Get the submission message.
242
# get the submission message
245
243
mail_from = config.get_user_option('pqm_user_email')
246
244
if not mail_from:
247
245
mail_from = config.username()
246
# Make sure this isn't unicode
248
247
mail_from = mail_from.encode('utf8')
249
248
if pqm_email is None:
254
253
pqm_email = config.get_user_option('pqm_email')
255
254
if not pqm_email:
256
255
raise NoPQMSubmissionAddress(bzrbranch)
257
mail_to = pqm_email.encode('utf8')
256
mail_to = pqm_email.encode('utf8') # same here
258
257
self.message = submission.to_email(mail_from, mail_to)
259
258
elif (self.download_cache_additions and
260
259
self.include_download_cache_changes is None):
321
320
if self.timeout is not None:
322
321
# Activate a fail-safe shutdown just in case something goes
323
322
# really wrong with the server or suite.
324
user_connection.perform("sudo shutdown -P +%d &" % self.timeout)
324
# We need to use a call to /usr/bin/at here instead of a call to
325
# /sbin/shutdown because the test suite already uses the shutdown
326
# command after the suite finishes. If we called shutdown
327
# here, it would prevent the end-of-suite shutdown from executing,
328
# leaving the server running until the failsafe finally activates.
329
# See bug 617598 for the details.
330
user_connection.perform(
331
"echo sudo shutdown -h now | at today + %d minutes"
325
333
as_user = user_connection.perform
328
"-o remount,data=writeback,commit=3600,async,relatime /")
329
for d in ['/tmp', '/var/tmp']:
331
"sudo mkdir -p %s && sudo mount -t tmpfs none %s" % (d, d))
333
"sudo service postgresql-8.4 stop"
334
"; sudo mv /var/lib/postgresql /tmp/postgresql-tmp"
335
"&& sudo mkdir /var/lib/postgresql"
336
"&& sudo mount -t tmpfs none /var/lib/postgresql"
337
"&& sudo mv /tmp/postgresql-tmp/* /var/lib/postgresql"
338
"&& sudo service postgresql-8.4 start")
339
as_user("sudo add-apt-repository ppa:bzr")
340
as_user("sudo add-apt-repository ppa:launchpad")
341
as_user("sudo aptitude update")
343
"sudo DEBIAN_FRONTEND=noninteractive aptitude -y full-upgrade")
344
334
# Set up bazaar.conf with smtp information if necessary
345
335
if self.email or self.message:
346
336
as_user('[ -d .bazaar ] || mkdir .bazaar')
371
361
user_connection = self._instance.connect()
372
362
# Clean up the test branch left in the instance image.
373
363
user_connection.perform('rm -rf /var/launchpad/test')
374
user_connection.perform(
375
'sudo mkdir /var/launchpad/test && '
376
'sudo mount -t tmpfs none /var/launchpad/test')
378
365
user_connection.run_with_ssh_agent(
379
'bzr branch --use-existing-dir %s /var/launchpad/test'
380
% (self._trunk_branch,))
366
'bzr branch %s /var/launchpad/test' % (self._trunk_branch,))
381
367
# Merge the branch in.
382
368
if self._branch is not None:
383
369
user_connection.run_with_ssh_agent(
395
381
'bzr branch --standalone %s %s' % (src, fulldest))
396
382
# prepare fresh copy of sourcecode and buildout sources for building
397
383
p = user_connection.perform
398
p('rm -rf /var/launchpad/tmp'
399
'&& mkdir /var/launchpad/tmp '
400
'&& sudo mount -t tmpfs none /var/launchpad/tmp')
384
p('rm -rf /var/launchpad/tmp')
385
p('mkdir /var/launchpad/tmp')
401
386
p('mv /var/launchpad/sourcecode /var/launchpad/tmp/sourcecode')
402
387
p('mkdir /var/launchpad/tmp/eggs')
403
p('mkdir /var/launchpad/tmp/yui')
404
388
user_connection.run_with_ssh_agent(
405
389
'bzr pull lp:lp-source-dependencies '
406
390
'-d /var/launchpad/download-cache')
408
'mv /var/launchpad/download-cache '
409
'/var/launchpad/tmp/download-cache')
391
p('mv /var/launchpad/download-cache /var/launchpad/tmp/download-cache')
410
392
if (self.include_download_cache_changes and
411
393
self.download_cache_additions):
412
394
root = os.path.realpath(
416
398
self.log('Copying %s to remote machine.\n' % (src,))
417
399
user_connection.sftp.put(
420
'/var/launchpad/tmp/download-cache', info[0]))
401
os.path.join('/var/launchpad/tmp/download-cache', info[0]))
421
402
p('/var/launchpad/test/utilities/link-external-sourcecode '
422
403
'-p/var/launchpad/tmp -t/var/launchpad/test'),
423
404
# set up database