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

Side by Side Diff: buildbot/prebuilt.py

Issue 6677023: Update prebuilt.py to handle private google storage uploads. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/chromite@master
Patch Set: Add print >> sys.stderr for error message Created 9 years, 9 months 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
« no previous file with comments | « no previous file | buildbot/prebuilt_unittest.py » ('j') | no next file with comments »
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 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import datetime 6 import datetime
7 import multiprocessing 7 import multiprocessing
8 import optparse 8 import optparse
9 import os 9 import os
10 import re 10 import re
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 """ 44 """
45 45
46 # as per http://crosbug.com/5855 always filter the below packages 46 # as per http://crosbug.com/5855 always filter the below packages
47 _FILTER_PACKAGES = set() 47 _FILTER_PACKAGES = set()
48 _RETRIES = 3 48 _RETRIES = 3
49 _GSUTIL_BIN = '/b/build/third_party/gsutil/gsutil' 49 _GSUTIL_BIN = '/b/build/third_party/gsutil/gsutil'
50 _HOST_PACKAGES_PATH = 'chroot/var/lib/portage/pkgs' 50 _HOST_PACKAGES_PATH = 'chroot/var/lib/portage/pkgs'
51 _CATEGORIES_PATH = 'chroot/etc/portage/categories' 51 _CATEGORIES_PATH = 'chroot/etc/portage/categories'
52 _HOST_TARGET = 'amd64' 52 _HOST_TARGET = 'amd64'
53 _BOARD_PATH = 'chroot/build/%(board)s' 53 _BOARD_PATH = 'chroot/build/%(board)s'
54 _BOTO_CONFIG = '/home/chrome-bot/external-boto'
55 # board/board-target/version/packages/' 54 # board/board-target/version/packages/'
56 _REL_BOARD_PATH = 'board/%(board)s/%(version)s/packages' 55 _REL_BOARD_PATH = 'board/%(board)s/%(version)s/packages'
57 # host/host-target/version/packages/' 56 # host/host-target/version/packages/'
58 _REL_HOST_PATH = 'host/%(target)s/%(version)s/packages' 57 _REL_HOST_PATH = 'host/%(target)s/%(version)s/packages'
59 # Private overlays to look at for builds to filter 58 # Private overlays to look at for builds to filter
60 # relative to build path 59 # relative to build path
61 _PRIVATE_OVERLAY_DIR = 'src/private-overlays' 60 _PRIVATE_OVERLAY_DIR = 'src/private-overlays'
61 _GOOGLESTORAGE_ACL_FILE = 'googlestorage_acl.xml'
62 _BINHOST_BASE_URL = 'http://commondatastorage.googleapis.com/chromeos-prebuilt' 62 _BINHOST_BASE_URL = 'http://commondatastorage.googleapis.com/chromeos-prebuilt'
63 _PREBUILT_BASE_DIR = 'src/third_party/chromiumos-overlay/chromeos/config/' 63 _PREBUILT_BASE_DIR = 'src/third_party/chromiumos-overlay/chromeos/config/'
64 # Created in the event of new host targets becoming available 64 # Created in the event of new host targets becoming available
65 _PREBUILT_MAKE_CONF = {'amd64': os.path.join(_PREBUILT_BASE_DIR, 65 _PREBUILT_MAKE_CONF = {'amd64': os.path.join(_PREBUILT_BASE_DIR,
66 'make.conf.amd64-host')} 66 'make.conf.amd64-host')}
67 _BINHOST_CONF_DIR = 'src/third_party/chromiumos-overlay/chromeos/binhost' 67 _BINHOST_CONF_DIR = 'src/third_party/chromiumos-overlay/chromeos/binhost'
68 68
69 69
70 class FiltersEmpty(Exception): 70 class FiltersEmpty(Exception):
71 """Raised when filters are used but none are found.""" 71 """Raised when filters are used but none are found."""
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 """Upload to GS bucket. 271 """Upload to GS bucket.
272 272
273 Args: 273 Args:
274 args: a tuple of three arguments that contains local_file, remote_file, and 274 args: a tuple of three arguments that contains local_file, remote_file, and
275 the acl used for uploading the file. 275 the acl used for uploading the file.
276 276
277 Returns: 277 Returns:
278 Return the arg tuple of two if the upload failed 278 Return the arg tuple of two if the upload failed
279 """ 279 """
280 (local_file, remote_file, acl) = args 280 (local_file, remote_file, acl) = args
281 CANNED_ACLS = ['public-read', 'private', 'bucket-owner-read',
282 'authenticated-read', 'bucket-owner-full-control',
283 'public-read-write']
284 acl_cmd = None
285 if acl in CANNED_ACLS:
286 cmd = '%s cp -a %s %s %s' % (_GSUTIL_BIN, acl, local_file, remote_file)
287 else:
288 # For private uploads we assume that the overlay board is set up properly
289 # and a googlestore_acl.xml is present, if not this script errors
290 cmd = '%s cp -a private %s %s' % (_GSUTIL_BIN, local_file, remote_file)
291 if not os.path.exists(acl):
292 print >> sys.stderr, ('You are specifying either a file that does not '
293 'exist or an unknown canned acl: %s. Aborting '
294 'upload') % acl
295 # emulate the failing of an upload since we are not uploading the file
296 return (local_file, remote_file)
281 297
282 cmd = '%s cp -a %s %s %s' % (_GSUTIL_BIN, acl, local_file, remote_file) 298 acl_cmd = '%s setacl %s %s' % (_GSUTIL_BIN, acl, remote_file)
299
283 if not _RetryRun(cmd, print_cmd=False, shell=True): 300 if not _RetryRun(cmd, print_cmd=False, shell=True):
284 return (local_file, remote_file) 301 return (local_file, remote_file)
285 302
303 if acl_cmd:
304 # Apply the passed in ACL xml file to the uploaded object.
305 _RetryRun(acl_cmd, print_cmd=False, shell=True)
306
307
286 def RemoteUpload(acl, files, pool=10): 308 def RemoteUpload(acl, files, pool=10):
287 """Upload to google storage. 309 """Upload to google storage.
288 310
289 Create a pool of process and call _GsUpload with the proper arguments. 311 Create a pool of process and call _GsUpload with the proper arguments.
290 312
291 Args: 313 Args:
292 acl: The canned acl used for uploading. acl can be one of: "public-read", 314 acl: The canned acl used for uploading. acl can be one of: "public-read",
293 "public-read-write", "authenticated-read", "bucket-owner-read", 315 "public-read-write", "authenticated-read", "bucket-owner-read",
294 "bucket-owner-full-control", or "private". 316 "bucket-owner-full-control", or "private".
295 files: dictionary with keys to local files and values to remote path. 317 files: dictionary with keys to local files and values to remote path.
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 default=False, action='store_true', 626 default=False, action='store_true',
605 help='Update binhost.conf') 627 help='Update binhost.conf')
606 parser.add_option('-P', '--private', dest='private', action='store_true', 628 parser.add_option('-P', '--private', dest='private', action='store_true',
607 default=False, help='Mark gs:// uploads as private.') 629 default=False, help='Mark gs:// uploads as private.')
608 630
609 options, args = parser.parse_args() 631 options, args = parser.parse_args()
610 if not options.build_path: 632 if not options.build_path:
611 usage(parser, 'Error: you need provide a chroot path') 633 usage(parser, 'Error: you need provide a chroot path')
612 if not options.upload: 634 if not options.upload:
613 usage(parser, 'Error: you need to provide an upload location using -u') 635 usage(parser, 'Error: you need to provide an upload location using -u')
614 if options.private and not (options.binhost_base_url.startswith('gs://') and 636
615 options.upload.startswith('gs://')): 637 if options.private:
616 usage(parser, 'Error: --private is only valid for gs:// URLs.\n' 638 if options.sync_host:
617 'Both --binhost-base-url and --upload must be gs:// URLs.') 639 usage(parser, 'Error: --private and --sync-host/-s cannot be specified '
640 'together, we do not support private host prebuilts')
641
642 if not options.upload.startswith('gs://'):
643 usage(parser, 'Error: --private is only valid for gs:// URLs.\n'
644 '--upload must be a gs:// URL.')
645
646 if options.binhost_base_url != _BINHOST_BASE_URL:
647 usage(parser, 'Error: when using --private the --binhost-base-url '
648 'is automatically derived.')
618 return options 649 return options
619 650
620 def main(): 651 def main():
621 options = ParseOptions() 652 options = ParseOptions()
622 653
623 # Setup boto environment for gsutil to use
624 os.environ['BOTO_CONFIG'] = _BOTO_CONFIG
625
626 if options.filters: 654 if options.filters:
627 LoadPrivateFilters(options.build_path) 655 LoadPrivateFilters(options.build_path)
628 656
629 acl = 'public-read'
630 if options.private:
631 acl = 'private'
632 657
633 # Calculate a list of Packages index files to compare against. Whenever we 658 # Calculate a list of Packages index files to compare against. Whenever we
634 # upload a package, we check to make sure it's not already stored in one of 659 # upload a package, we check to make sure it's not already stored in one of
635 # the packages files we uploaded. This list of packages files might contain 660 # the packages files we uploaded. This list of packages files might contain
636 # both board and host packages. 661 # both board and host packages.
637 pkg_indexes = _GrabAllRemotePackageIndexes(options.previous_binhost_url) 662 pkg_indexes = _GrabAllRemotePackageIndexes(options.previous_binhost_url)
638 663
639 version = GetVersion() 664 version = GetVersion()
640 if options.prepend_version: 665 if options.prepend_version:
641 version = '%s-%s' % (options.prepend_version, version) 666 version = '%s-%s' % (options.prepend_version, version)
642 667
643 uploader = PrebuiltUploader(options.upload, acl, options.binhost_base_url, 668 acl = 'public-read'
669 binhost_base_url = options.binhost_base_url
670
671 if options.private:
672 binhost_base_url = options.upload
673 board_path = GetBoardPathFromCrosOverlayList(options.build_path,
674 options.board)
675 acl = os.path.join(board_path, _GOOGLESTORAGE_ACL_FILE)
676
677 uploader = PrebuiltUploader(options.upload, acl, binhost_base_url,
644 pkg_indexes) 678 pkg_indexes)
645 679
646 if options.sync_host: 680 if options.sync_host:
647 uploader._SyncHostPrebuilts(options.build_path, version, options.key, 681 uploader._SyncHostPrebuilts(options.build_path, version, options.key,
648 options.git_sync, options.sync_binhost_conf) 682 options.git_sync, options.sync_binhost_conf)
649 683
650 if options.board: 684 if options.board:
651 uploader._SyncBoardPrebuilts(options.board, options.build_path, version, 685 uploader._SyncBoardPrebuilts(options.board, options.build_path, version,
652 options.key, options.git_sync, 686 options.key, options.git_sync,
653 options.sync_binhost_conf) 687 options.sync_binhost_conf)
654 688
655 if __name__ == '__main__': 689 if __name__ == '__main__':
656 main() 690 main()
OLDNEW
« no previous file with comments | « no previous file | buildbot/prebuilt_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698