Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: bin/cbuildbot.py

Issue 4864001: Change _ArchiveTestResults to upload to Google Storage (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: More code reviews feedback and introduce RunCommandException Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/cros_build_lib.py » ('j') | lib/cros_build_lib.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """CBuildbot is wrapper around the build process used by the pre-flight queue""" 7 """CBuildbot is wrapper around the build process used by the pre-flight queue"""
8 8
9 import errno 9 import errno
10 import heapq 10 import heapq
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 else: 394 else:
395 overlays = [public_overlay, private_overlay] 395 overlays = [public_overlay, private_overlay]
396 RunCommand(['./cros_mark_as_stable', '--srcroot=..', 396 RunCommand(['./cros_mark_as_stable', '--srcroot=..',
397 '--board=%s' % board, 397 '--board=%s' % board,
398 '--overlays=%s' % " ".join(overlays), 398 '--overlays=%s' % " ".join(overlays),
399 '--tracking_branch=%s' % tracking_branch, 399 '--tracking_branch=%s' % tracking_branch,
400 '--push_options=--bypass-hooks -f', 'push'], 400 '--push_options=--bypass-hooks -f', 'push'],
401 cwd=cwd) 401 cwd=cwd)
402 402
403 403
404 def _ArchiveTestResults(buildroot, board, archive_dir, test_results_dir): 404 def _ArchiveTestResults(buildroot, board, test_results_dir,
405 """Archives the test results into the www dir for later use. 405 gsutil, archive_dir, acl):
406 """Archives the test results into Google Storage
406 407
407 Takes the results from the test_results_dir and dumps them into the archive 408 Takes the results from the test_results_dir and the last qemu image and
408 dir specified. This also archives the last qemu image. 409 uploads them to Google Storage.
409 410
410 board: Board to find the qemu image. 411 Arguments:
411 archive_dir: Path from ARCHIVE_BASE to store image. 412 buildroot: Root directory where build occurs
412 test_results_dir: Path from buildroot/chroot to find test results. This must 413 board: Board to find the qemu image.
413 a subdir of /tmp. 414 test_results_dir: Path from buildroot/chroot to find test results.
415 This must a subdir of /tmp.
416 gsutil: Location of gsutil
417 archive_dir: Google Storage path to store the archive
418 acl: ACL to set on archive in Google Storage
414 """ 419 """
420 num_gsutil_retries = 5
415 test_results_dir = test_results_dir.lstrip('/') 421 test_results_dir = test_results_dir.lstrip('/')
416 if not os.path.exists(ARCHIVE_BASE):
417 os.makedirs(ARCHIVE_BASE)
418 else:
419 dir_entries = os.listdir(ARCHIVE_BASE)
420 if len(dir_entries) >= ARCHIVE_COUNT:
421 oldest_dirs = heapq.nsmallest((len(dir_entries) - ARCHIVE_COUNT) + 1,
422 [os.path.join(ARCHIVE_BASE, filename) for filename in dir_entries],
423 key=lambda fn: os.stat(fn).st_mtime)
424 Info('Removing archive dirs %s' % oldest_dirs)
425 for oldest_dir in oldest_dirs:
426 shutil.rmtree(os.path.join(ARCHIVE_BASE, oldest_dir))
427
428 archive_target = os.path.join(ARCHIVE_BASE, str(archive_dir))
429 if os.path.exists(archive_target):
430 shutil.rmtree(archive_target)
431
432 results_path = os.path.join(buildroot, 'chroot', test_results_dir) 422 results_path = os.path.join(buildroot, 'chroot', test_results_dir)
433 RunCommand(['sudo', 'chmod', '-R', '+r', results_path]) 423 RunCommand(['sudo', 'chmod', '-R', '+r', results_path])
434 try: 424 try:
435 shutil.copytree(results_path, archive_target) 425 # gsutil has the ability to resume an upload when the command is retried
436 except: 426 RunCommand([gsutil, 'cp', '-R', results_path, archive_dir],
437 Warning('Some files could not be copied') 427 num_retries=num_gsutil_retries)
428 RunCommand([gsutil, 'setacl', acl, archive_dir])
438 429
439 image_name = 'chromiumos_qemu_image.bin' 430 image_name = 'chromiumos_qemu_image.bin'
440 image_path = os.path.join(buildroot, 'src', 'build', 'images', board, 431 image_path = os.path.join(buildroot, 'src', 'build', 'images', board,
441 'latest', image_name) 432 'latest', image_name)
442 RunCommand(['gzip', '-f', '--fast', image_path]) 433 RunCommand(['gzip', '-f', '--fast', image_path])
443 shutil.copyfile(image_path + '.gz', os.path.join(archive_target, 434 RunCommand([gsutil, 'cp', image_path + '.gz', archive_dir],
444 image_name + '.gz')) 435 num_retries=num_gsutil_retries)
445 436 except Exception, e:
437 Warning('Could not archive test results (error=%s)' % str(e))
446 438
447 439
448 def _GetConfig(config_name): 440 def _GetConfig(config_name):
449 """Gets the configuration for the build""" 441 """Gets the configuration for the build"""
450 default = config['default'] 442 default = config['default']
451 buildconfig = {} 443 buildconfig = {}
452 if not config.has_key(config_name): 444 if not config.has_key(config_name):
453 Warning('Non-existent configuration specified.') 445 Warning('Non-existent configuration specified.')
454 Warning('Please specify one of:') 446 Warning('Please specify one of:')
455 config_names = config.keys() 447 config_names = config.keys()
(...skipping 25 matching lines...) Expand all
481 default=False, 473 default=False,
482 help='Clobbers an old checkout before syncing') 474 help='Clobbers an old checkout before syncing')
483 parser.add_option('--debug', action='store_true', dest='debug', 475 parser.add_option('--debug', action='store_true', dest='debug',
484 default=False, 476 default=False,
485 help='Override some options to run as a developer.') 477 help='Override some options to run as a developer.')
486 parser.add_option('-t', '--tracking-branch', dest='tracking_branch', 478 parser.add_option('-t', '--tracking-branch', dest='tracking_branch',
487 default='cros/master', help='Run the buildbot on a branch') 479 default='cros/master', help='Run the buildbot on a branch')
488 parser.add_option('-u', '--url', dest='url', 480 parser.add_option('-u', '--url', dest='url',
489 default='http://git.chromium.org/git/manifest', 481 default='http://git.chromium.org/git/manifest',
490 help='Run the buildbot on internal manifest') 482 help='Run the buildbot on internal manifest')
483 parser.add_option('-g', '--gsutil', default='', help='Location of gsutil')
484 parser.add_option('-c', '--gsutil_archive', default='',
485 help='Datastore archive location')
486 parser.add_option('-a', '--acl', default='private',
487 help='ACL to set on GSD archives')
491 488
492 (options, args) = parser.parse_args() 489 (options, args) = parser.parse_args()
493 490
494 buildroot = options.buildroot 491 buildroot = options.buildroot
495 revisionfile = options.revisionfile 492 revisionfile = options.revisionfile
496 tracking_branch = options.tracking_branch 493 tracking_branch = options.tracking_branch
497 494
498 if len(args) >= 1: 495 if len(args) >= 1:
499 buildconfig = _GetConfig(args[-1]) 496 buildconfig = _GetConfig(args[-1])
500 else: 497 else:
(...skipping 26 matching lines...) Expand all
527 _RunUnitTests(buildroot) 524 _RunUnitTests(buildroot)
528 525
529 _BuildImage(buildroot) 526 _BuildImage(buildroot)
530 527
531 if buildconfig['smoke_bvt']: 528 if buildconfig['smoke_bvt']:
532 _BuildVMImageForTesting(buildroot) 529 _BuildVMImageForTesting(buildroot)
533 test_results_dir = '/tmp/run_remote_tests.%s' % options.buildnumber 530 test_results_dir = '/tmp/run_remote_tests.%s' % options.buildnumber
534 try: 531 try:
535 _RunSmokeSuite(buildroot, test_results_dir) 532 _RunSmokeSuite(buildroot, test_results_dir)
536 finally: 533 finally:
537 _ArchiveTestResults(buildroot, buildconfig['board'], 534 if not options.debug:
538 archive_dir=options.buildnumber, 535 archive_full_path=os.path.join(options.gsutil_archive,
539 test_results_dir=test_results_dir) 536 str(options.buildnumber))
537 _ArchiveTestResults(buildroot, buildconfig['board'],
538 test_results_dir=test_results_dir,
539 gsutil=options.gsutil,
540 archive_dir=archive_full_path,
541 acl=options.acl)
540 542
541 if buildconfig['uprev']: 543 if buildconfig['uprev']:
542 # Don't push changes for developers. 544 # Don't push changes for developers.
543 if not options.debug: 545 if not options.debug:
544 if buildconfig['master']: 546 if buildconfig['master']:
545 # Master bot needs to check if the other slaves completed. 547 # Master bot needs to check if the other slaves completed.
546 if cbuildbot_comm.HaveSlavesCompleted(config): 548 if cbuildbot_comm.HaveSlavesCompleted(config):
547 _UprevPush(buildroot, tracking_branch, buildconfig['board'], 549 _UprevPush(buildroot, tracking_branch, buildconfig['board'],
548 buildconfig['overlays']) 550 buildconfig['overlays'])
549 else: 551 else:
550 Die('CBUILDBOT - One of the slaves has failed!!!') 552 Die('CBUILDBOT - One of the slaves has failed!!!')
551 553
552 else: 554 else:
553 # Publish my status to the master if its expecting it. 555 # Publish my status to the master if its expecting it.
554 if buildconfig['important']: 556 if buildconfig['important']:
555 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) 557 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE)
556 558
557 except: 559 except:
558 # Send failure to master bot. 560 # Send failure to master bot.
559 if not buildconfig['master'] and buildconfig['important']: 561 if not buildconfig['master'] and buildconfig['important']:
560 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) 562 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED)
561 563
562 raise 564 raise
563 565
564 566
565 if __name__ == '__main__': 567 if __name__ == '__main__':
566 main() 568 main()
OLDNEW
« no previous file with comments | « no previous file | lib/cros_build_lib.py » ('j') | lib/cros_build_lib.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698