OLD | NEW |
---|---|
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 Loading... | |
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 _gsutil_with_retries(command, num_retries): |
sosa
2010/11/12 18:49:09
Name style is wrong
scottz-goog
2010/11/12 19:15:02
This will is just a RunCommandWithRetries and you
scottz-goog
2010/11/12 19:15:02
While I know this file doesn't follow it exactly w
| |
405 """Run the gsutil command and retry in case of failure. | |
406 | |
407 This is helpful when attempting to upload a large file to Google Storage. | |
408 gsutil will resume any broken upload when it is retried. | |
409 | |
410 command: Command to run | |
sosa
2010/11/12 18:49:09
Command should be an array
| |
411 num_retries: Number of times to retry the command | |
412 """ | |
413 for i in range(num_retries): | |
414 try: | |
415 RunCommand(command) | |
416 return | |
sosa
2010/11/12 18:49:09
No explicit return
| |
417 except: | |
418 Warning('Retrying command') | |
sosa
2010/11/12 18:49:09
Print out command you are retrying.
| |
419 | |
420 | |
421 def _ArchiveTestResults(buildroot, board, test_results_dir, | |
422 gsutil, archive_dir, acl): | |
405 """Archives the test results into the www dir for later use. | 423 """Archives the test results into the www dir for later use. |
406 | 424 |
407 Takes the results from the test_results_dir and dumps them into the archive | 425 Takes the results from the test_results_dir and the last qemu image and |
408 dir specified. This also archives the last qemu image. | 426 uploads them to Google Storage. |
409 | 427 |
410 board: Board to find the qemu image. | 428 board: Board to find the qemu image. |
411 archive_dir: Path from ARCHIVE_BASE to store image. | |
412 test_results_dir: Path from buildroot/chroot to find test results. This must | 429 test_results_dir: Path from buildroot/chroot to find test results. This must |
413 a subdir of /tmp. | 430 a subdir of /tmp. |
431 gsutil: Location of gsutil | |
432 archive_dir: Google Storage path to store the archive | |
433 acl: ACL to set on archive in Google Storage | |
414 """ | 434 """ |
435 num_gsutil_retries = 5 | |
415 test_results_dir = test_results_dir.lstrip('/') | 436 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) | 437 results_path = os.path.join(buildroot, 'chroot', test_results_dir) |
433 RunCommand(['sudo', 'chmod', '-R', '+r', results_path]) | 438 RunCommand(['sudo', 'chmod', '-R', '+r', results_path]) |
434 try: | 439 try: |
435 shutil.copytree(results_path, archive_target) | 440 _gsutil_with_retries([gsutil, 'cp', '-R', results_path, archive_dir], |
441 num_gsutil_retries) | |
436 except: | 442 except: |
scottz-goog
2010/11/12 19:15:02
We should never be catching blank exceptions. You
| |
437 Warning('Some files could not be copied') | 443 Warning('Some files could not be uploaded') |
444 | |
445 try: | |
446 RunCommand([gsutil, 'setacl', acl, archive_dir]) | |
sosa
2010/11/12 18:49:09
All these try's should be in the same try clause p
| |
447 except: | |
scottz-goog
2010/11/12 19:15:02
see above
| |
448 Warning('Could not set archive ACL') | |
438 | 449 |
439 image_name = 'chromiumos_qemu_image.bin' | 450 image_name = 'chromiumos_qemu_image.bin' |
440 image_path = os.path.join(buildroot, 'src', 'build', 'images', board, | 451 image_path = os.path.join(buildroot, 'src', 'build', 'images', board, |
441 'latest', image_name) | 452 'latest', image_name) |
442 RunCommand(['gzip', '-f', '--fast', image_path]) | 453 try: |
443 shutil.copyfile(image_path + '.gz', os.path.join(archive_target, | 454 RunCommand(['gzip', '-f', '--fast', image_path]) |
444 image_name + '.gz')) | 455 _gsutil_with_retries([gsutil, 'cp', image_path + '.gz', archive_dir], |
445 | 456 num_gsutil_retries) |
457 except: | |
scottz-goog
2010/11/12 19:15:02
See above.
| |
458 Warning('Could not gzip/upload QEMU image') | |
446 | 459 |
447 | 460 |
448 def _GetConfig(config_name): | 461 def _GetConfig(config_name): |
449 """Gets the configuration for the build""" | 462 """Gets the configuration for the build""" |
450 default = config['default'] | 463 default = config['default'] |
451 buildconfig = {} | 464 buildconfig = {} |
452 if not config.has_key(config_name): | 465 if not config.has_key(config_name): |
453 Warning('Non-existent configuration specified.') | 466 Warning('Non-existent configuration specified.') |
454 Warning('Please specify one of:') | 467 Warning('Please specify one of:') |
455 config_names = config.keys() | 468 config_names = config.keys() |
(...skipping 25 matching lines...) Expand all Loading... | |
481 default=False, | 494 default=False, |
482 help='Clobbers an old checkout before syncing') | 495 help='Clobbers an old checkout before syncing') |
483 parser.add_option('--debug', action='store_true', dest='debug', | 496 parser.add_option('--debug', action='store_true', dest='debug', |
484 default=False, | 497 default=False, |
485 help='Override some options to run as a developer.') | 498 help='Override some options to run as a developer.') |
486 parser.add_option('-t', '--tracking-branch', dest='tracking_branch', | 499 parser.add_option('-t', '--tracking-branch', dest='tracking_branch', |
487 default='cros/master', help='Run the buildbot on a branch') | 500 default='cros/master', help='Run the buildbot on a branch') |
488 parser.add_option('-u', '--url', dest='url', | 501 parser.add_option('-u', '--url', dest='url', |
489 default='http://git.chromium.org/git/manifest', | 502 default='http://git.chromium.org/git/manifest', |
490 help='Run the buildbot on internal manifest') | 503 help='Run the buildbot on internal manifest') |
504 parser.add_option('-g', '--gsutil', default='', help='Location of gsutil') | |
505 parser.add_option('-c', '--gsutil_archive', default='', | |
506 help='Datastore archive location') | |
507 parser.add_option('-a', '--acl', default='', | |
sosa
2010/11/12 18:49:09
Why should this be user specified? SHouldn't we h
| |
508 help='ACL to set on GSD archives') | |
491 | 509 |
492 (options, args) = parser.parse_args() | 510 (options, args) = parser.parse_args() |
493 | 511 |
494 buildroot = options.buildroot | 512 buildroot = options.buildroot |
495 revisionfile = options.revisionfile | 513 revisionfile = options.revisionfile |
496 tracking_branch = options.tracking_branch | 514 tracking_branch = options.tracking_branch |
497 | 515 |
498 if len(args) >= 1: | 516 if len(args) >= 1: |
499 buildconfig = _GetConfig(args[-1]) | 517 buildconfig = _GetConfig(args[-1]) |
500 else: | 518 else: |
(...skipping 27 matching lines...) Expand all Loading... | |
528 | 546 |
529 _BuildImage(buildroot) | 547 _BuildImage(buildroot) |
530 | 548 |
531 if buildconfig['smoke_bvt']: | 549 if buildconfig['smoke_bvt']: |
532 _BuildVMImageForTesting(buildroot) | 550 _BuildVMImageForTesting(buildroot) |
533 test_results_dir = '/tmp/run_remote_tests.%s' % options.buildnumber | 551 test_results_dir = '/tmp/run_remote_tests.%s' % options.buildnumber |
534 try: | 552 try: |
535 _RunSmokeSuite(buildroot, test_results_dir) | 553 _RunSmokeSuite(buildroot, test_results_dir) |
536 finally: | 554 finally: |
537 _ArchiveTestResults(buildroot, buildconfig['board'], | 555 _ArchiveTestResults(buildroot, buildconfig['board'], |
538 archive_dir=options.buildnumber, | 556 test_results_dir=test_results_dir, |
539 test_results_dir=test_results_dir) | 557 gsutil=options.gsutil, |
558 archive_dir=options.gsutil_archive + '/' + | |
sosa
2010/11/12 18:49:09
use os.path.join here
| |
559 str(options.buildnumber), | |
sosa
2010/11/12 18:49:09
is str() needed here?
| |
560 acl=options.acl) | |
540 | 561 |
541 if buildconfig['uprev']: | 562 if buildconfig['uprev']: |
542 # Don't push changes for developers. | 563 # Don't push changes for developers. |
543 if not options.debug: | 564 if not options.debug: |
544 if buildconfig['master']: | 565 if buildconfig['master']: |
545 # Master bot needs to check if the other slaves completed. | 566 # Master bot needs to check if the other slaves completed. |
546 if cbuildbot_comm.HaveSlavesCompleted(config): | 567 if cbuildbot_comm.HaveSlavesCompleted(config): |
547 _UprevPush(buildroot, tracking_branch, buildconfig['board'], | 568 _UprevPush(buildroot, tracking_branch, buildconfig['board'], |
548 buildconfig['overlays']) | 569 buildconfig['overlays']) |
549 else: | 570 else: |
550 Die('CBUILDBOT - One of the slaves has failed!!!') | 571 Die('CBUILDBOT - One of the slaves has failed!!!') |
551 | 572 |
552 else: | 573 else: |
553 # Publish my status to the master if its expecting it. | 574 # Publish my status to the master if its expecting it. |
554 if buildconfig['important']: | 575 if buildconfig['important']: |
555 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) | 576 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) |
556 | 577 |
557 except: | 578 except: |
558 # Send failure to master bot. | 579 # Send failure to master bot. |
559 if not buildconfig['master'] and buildconfig['important']: | 580 if not buildconfig['master'] and buildconfig['important']: |
560 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) | 581 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) |
561 | 582 |
562 raise | 583 raise |
563 | 584 |
564 | 585 |
565 if __name__ == '__main__': | 586 if __name__ == '__main__': |
566 main() | 587 main() |
OLD | NEW |