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 |
11 import re | 11 import re |
12 import optparse | 12 import optparse |
13 import os | 13 import os |
14 import shutil | 14 import shutil |
15 import sys | 15 import sys |
16 | 16 |
17 import cbuildbot_comm | 17 import cbuildbot_comm |
18 from cbuildbot_config import config | 18 from cbuildbot_config import config |
19 | 19 |
20 sys.path.append(os.path.join(os.path.dirname(__file__), '../lib')) | 20 sys.path.append(os.path.join(os.path.dirname(__file__), '../lib')) |
21 from cros_build_lib import Die, Info, RunCommand, Warning | 21 from cros_build_lib import Die, Info, RunCommand, RunCommandWithRetries, Warning |
22 | 22 |
23 _DEFAULT_RETRIES = 3 | 23 _DEFAULT_RETRIES = 3 |
24 ARCHIVE_BASE = '/var/www/archive' | 24 ARCHIVE_BASE = '/var/www/archive' |
25 ARCHIVE_COUNT = 10 | 25 ARCHIVE_COUNT = 10 |
26 | 26 |
27 # ======================== Utility functions ================================ | 27 # ======================== Utility functions ================================ |
28 | 28 |
29 def MakeDir(path, parents=False): | 29 def MakeDir(path, parents=False): |
30 """Basic wrapper around os.mkdirs. | 30 """Basic wrapper around os.mkdirs. |
31 | 31 |
(...skipping 362 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 _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: |
sosa
2010/11/12 21:41:45
buildroot?
| |
411 archive_dir: Path from ARCHIVE_BASE to store image. | 412 board: Board to find the qemu image. |
412 test_results_dir: Path from buildroot/chroot to find test results. This must | 413 test_results_dir: Path from buildroot/chroot to find test results. |
413 a subdir of /tmp. | 414 This must a subdir of /tmp. |
415 gsutil: Location of gsutil | |
416 archive_dir: Google Storage path to store the archive | |
417 acl: ACL to set on archive in Google Storage | |
414 """ | 418 """ |
419 num_gsutil_retries = 5 | |
415 test_results_dir = test_results_dir.lstrip('/') | 420 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) | 421 results_path = os.path.join(buildroot, 'chroot', test_results_dir) |
433 RunCommand(['sudo', 'chmod', '-R', '+r', results_path]) | 422 RunCommand(['sudo', 'chmod', '-R', '+r', results_path]) |
434 try: | 423 try: |
435 shutil.copytree(results_path, archive_target) | 424 # gsutil has the ability to resume an upload when the command is retried |
436 except: | 425 RunCommandWithRetries([gsutil, 'cp', '-R', results_path, archive_dir], |
437 Warning('Some files could not be copied') | 426 num_gsutil_retries) |
427 RunCommand([gsutil, 'setacl', acl, archive_dir]) | |
438 | 428 |
439 image_name = 'chromiumos_qemu_image.bin' | 429 image_name = 'chromiumos_qemu_image.bin' |
440 image_path = os.path.join(buildroot, 'src', 'build', 'images', board, | 430 image_path = os.path.join(buildroot, 'src', 'build', 'images', board, |
441 'latest', image_name) | 431 'latest', image_name) |
442 RunCommand(['gzip', '-f', '--fast', image_path]) | 432 RunCommand(['gzip', '-f', '--fast', image_path]) |
443 shutil.copyfile(image_path + '.gz', os.path.join(archive_target, | 433 RunCommandWithRetries([gsutil, 'cp', image_path + '.gz', archive_dir], |
444 image_name + '.gz')) | 434 num_gsutil_retries) |
445 | 435 except Exception, e: |
436 Warning('Could not archive test results (error=%s)' % str(e)) | |
446 | 437 |
447 | 438 |
448 def _GetConfig(config_name): | 439 def _GetConfig(config_name): |
449 """Gets the configuration for the build""" | 440 """Gets the configuration for the build""" |
450 default = config['default'] | 441 default = config['default'] |
451 buildconfig = {} | 442 buildconfig = {} |
452 if not config.has_key(config_name): | 443 if not config.has_key(config_name): |
453 Warning('Non-existent configuration specified.') | 444 Warning('Non-existent configuration specified.') |
454 Warning('Please specify one of:') | 445 Warning('Please specify one of:') |
455 config_names = config.keys() | 446 config_names = config.keys() |
(...skipping 25 matching lines...) Expand all Loading... | |
481 default=False, | 472 default=False, |
482 help='Clobbers an old checkout before syncing') | 473 help='Clobbers an old checkout before syncing') |
483 parser.add_option('--debug', action='store_true', dest='debug', | 474 parser.add_option('--debug', action='store_true', dest='debug', |
484 default=False, | 475 default=False, |
485 help='Override some options to run as a developer.') | 476 help='Override some options to run as a developer.') |
486 parser.add_option('-t', '--tracking-branch', dest='tracking_branch', | 477 parser.add_option('-t', '--tracking-branch', dest='tracking_branch', |
487 default='cros/master', help='Run the buildbot on a branch') | 478 default='cros/master', help='Run the buildbot on a branch') |
488 parser.add_option('-u', '--url', dest='url', | 479 parser.add_option('-u', '--url', dest='url', |
489 default='http://git.chromium.org/git/manifest', | 480 default='http://git.chromium.org/git/manifest', |
490 help='Run the buildbot on internal manifest') | 481 help='Run the buildbot on internal manifest') |
482 parser.add_option('-g', '--gsutil', default='', help='Location of gsutil') | |
483 parser.add_option('-c', '--gsutil_archive', default='', | |
484 help='Datastore archive location') | |
485 parser.add_option('-a', '--acl', default='private', | |
486 help='ACL to set on GSD archives') | |
491 | 487 |
492 (options, args) = parser.parse_args() | 488 (options, args) = parser.parse_args() |
493 | 489 |
494 buildroot = options.buildroot | 490 buildroot = options.buildroot |
495 revisionfile = options.revisionfile | 491 revisionfile = options.revisionfile |
496 tracking_branch = options.tracking_branch | 492 tracking_branch = options.tracking_branch |
497 | 493 |
498 if len(args) >= 1: | 494 if len(args) >= 1: |
499 buildconfig = _GetConfig(args[-1]) | 495 buildconfig = _GetConfig(args[-1]) |
500 else: | 496 else: |
(...skipping 26 matching lines...) Expand all Loading... | |
527 _RunUnitTests(buildroot) | 523 _RunUnitTests(buildroot) |
528 | 524 |
529 _BuildImage(buildroot) | 525 _BuildImage(buildroot) |
530 | 526 |
531 if buildconfig['smoke_bvt']: | 527 if buildconfig['smoke_bvt']: |
532 _BuildVMImageForTesting(buildroot) | 528 _BuildVMImageForTesting(buildroot) |
533 test_results_dir = '/tmp/run_remote_tests.%s' % options.buildnumber | 529 test_results_dir = '/tmp/run_remote_tests.%s' % options.buildnumber |
534 try: | 530 try: |
535 _RunSmokeSuite(buildroot, test_results_dir) | 531 _RunSmokeSuite(buildroot, test_results_dir) |
536 finally: | 532 finally: |
533 archive_full_path=os.path.join(options.gsutil_archive, | |
534 str(options.buildnumber)) | |
537 _ArchiveTestResults(buildroot, buildconfig['board'], | 535 _ArchiveTestResults(buildroot, buildconfig['board'], |
538 archive_dir=options.buildnumber, | 536 test_results_dir=test_results_dir, |
539 test_results_dir=test_results_dir) | 537 gsutil=options.gsutil, |
538 » » » archive_dir=archive_full_path, | |
sosa
2010/11/12 21:41:45
You have tabs here. This is bad.
| |
539 acl=options.acl) | |
540 | 540 |
541 if buildconfig['uprev']: | 541 if buildconfig['uprev']: |
542 # Don't push changes for developers. | 542 # Don't push changes for developers. |
543 if not options.debug: | 543 if not options.debug: |
544 if buildconfig['master']: | 544 if buildconfig['master']: |
545 # Master bot needs to check if the other slaves completed. | 545 # Master bot needs to check if the other slaves completed. |
546 if cbuildbot_comm.HaveSlavesCompleted(config): | 546 if cbuildbot_comm.HaveSlavesCompleted(config): |
547 _UprevPush(buildroot, tracking_branch, buildconfig['board'], | 547 _UprevPush(buildroot, tracking_branch, buildconfig['board'], |
548 buildconfig['overlays']) | 548 buildconfig['overlays']) |
549 else: | 549 else: |
550 Die('CBUILDBOT - One of the slaves has failed!!!') | 550 Die('CBUILDBOT - One of the slaves has failed!!!') |
551 | 551 |
552 else: | 552 else: |
553 # Publish my status to the master if its expecting it. | 553 # Publish my status to the master if its expecting it. |
554 if buildconfig['important']: | 554 if buildconfig['important']: |
555 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) | 555 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) |
556 | 556 |
557 except: | 557 except: |
558 # Send failure to master bot. | 558 # Send failure to master bot. |
559 if not buildconfig['master'] and buildconfig['important']: | 559 if not buildconfig['master'] and buildconfig['important']: |
560 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) | 560 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) |
561 | 561 |
562 raise | 562 raise |
563 | 563 |
564 | 564 |
565 if __name__ == '__main__': | 565 if __name__ == '__main__': |
566 main() | 566 main() |
OLD | NEW |