Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index d4486e5b10abd24e0667f0b6509695950029660d..b3a0423e21bdb706f25dcd1af06605ba1690ffa7 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -11,6 +11,7 @@ from distutils.version import LooseVersion |
| from multiprocessing.pool import ThreadPool |
| import base64 |
| import glob |
| +import httplib |
| import json |
| import logging |
| import optparse |
| @@ -21,6 +22,8 @@ import stat |
| import sys |
| import tempfile |
| import textwrap |
| +import time |
| +import traceback |
| import urllib2 |
| import urlparse |
| import webbrowser |
| @@ -31,8 +34,8 @@ try: |
| except ImportError: |
| pass |
| - |
| from third_party import colorama |
| +from third_party import httplib2 |
| from third_party import upload |
| import auth |
| import breakpad # pylint: disable=W0611 |
| @@ -62,6 +65,11 @@ REFS_THAT_ALIAS_TO_OTHER_REFS = { |
| 'refs/remotes/origin/lkcr': 'refs/remotes/origin/master', |
| } |
| +# Buildbucket-related constants |
| +BUILDBUCKET_PUT_URL = ( |
| + 'https://cr-buildbucket.appspot.com/_ah/api/buildbucket/v1/builds/batch') |
| +BUILDSET_STR = 'patch/rietveld/{hostname}/{issue}/{patch}' |
| + |
| # Valid extensions for files we want to lint. |
| DEFAULT_LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)" |
| DEFAULT_LINT_IGNORE_REGEX = r"$^" |
| @@ -202,6 +210,105 @@ def add_git_similarity(parser): |
| parser.parse_args = Parse |
| +def _prefix_master(master): |
| + prefix = 'master.' |
| + if master.startswith(prefix): |
| + return master |
| + else: |
| + return '%s%s' % (prefix, master) |
| + |
| + |
| +def trigger_distributed_try_jobs( |
|
nodir
2015/04/18 05:17:56
I'd call something like "trigger_buildbucket_build
|
| + auth_config, changelist, options, masters, category): |
| + rietveld_url = settings.GetDefaultServerUrl() |
| + rietveld_host = urlparse.urlparse(rietveld_url).hostname |
| + authenticator = auth.get_authenticator_for_host(rietveld_host, auth_config) |
| + http = authenticator.authorize(httplib2.Http()) |
| + http.force_exception_to_status_code = True |
| + issue_props = changelist.GetIssueProperties() |
| + issue = changelist.GetIssue() |
| + patchset = changelist.GetMostRecentPatchset() |
| + buildset = BUILDSET_STR.format( |
| + hostname=rietveld_host, |
| + issue=issue, |
| + patch=patchset) |
| + |
| + batch_req_body = {'builds': []} |
| + print_text = [] |
| + print_text.append('Trying jobs on:') |
| + for master, builders_and_tests in masters.iteritems(): |
| + print_text.append('Master: %s' % master) |
| + bucket = _prefix_master(master) |
| + for builder, tests in builders_and_tests.iteritems(): |
| + print_text.append(' %s: %s' % (builder, tests)) |
| + batch_req_body['builds'].append( |
| + { |
|
nodir
2015/04/18 05:17:56
nit: I think it is fine to merge lines 244 and 245
|
| + 'bucket': bucket, |
| + 'parameters_json': json.dumps({ |
| + 'builder_name': builder, |
| + 'changes':[ |
| + {'author': {'email': issue_props['owner_email']}}, |
| + ], |
| + 'properties': { |
| + 'category': category, |
| + 'clobber': options.clobber, |
|
nodir
2015/04/18 05:17:56
As smut said in https://code.google.com/p/chromium
|
| + 'issue': issue, |
| + 'master': master, |
| + 'patch_project': issue_props['project'], |
| + 'patch_storage': 'rietveld', |
| + 'patchset': patchset, |
| + 'reason': options.name, |
| + 'revision': options.revision, |
| + 'rietveld': rietveld_url, |
| + 'testfilter': tests, |
| + }, |
| + }), |
| + 'tags': ['buildset:%s' % buildset, |
| + 'master:%s' % master, |
| + 'builder:%s' % builder, |
| + 'user_agent:git-cl-try'] |
|
nodir
2015/04/18 06:46:17
please sort
|
| + } |
| + ) |
| + |
| + wait = 1 |
| + try_count = 3 |
| + while try_count > 0: |
| + try_count -= 1 |
| + response, content = http.request( |
| + BUILDBUCKET_PUT_URL, |
| + "PUT", |
|
nodir
2015/04/18 05:17:56
use '
|
| + body=json.dumps(batch_req_body), |
| + headers={'Content-type': 'application/json'}, |
|
nodir
2015/04/18 05:17:56
nit: capital t: Content-Type
|
| + ) |
| + content_json = None |
| + try: |
| + content_json = json.loads(content) |
| + except ValueError: |
| + pass |
| + |
| + # Buildbbucket could return an error even status==200. |
|
nodir
2015/04/18 05:17:56
"even if"
nodir
2015/04/18 05:17:56
typo: double b
|
| + if content_json and content_json.get('error'): |
| + msg = 'Error in response. Code: %d. Reason: %s. Message: %s.' % ( |
| + content_json['error'].get('code', ''), |
| + content_json['error'].get('reason', ''), |
| + content_json['error'].get('message', '')) |
| + raise BuildbucketResponseException(msg) |
| + |
| + if response.status == 200: |
| + break |
| + |
| + if response.status < 500 or try_count <= 0: |
| + raise httplib2.HttpLib2Error(content) |
| + |
| + # status >= 500 means transient failures. |
| + logging.debug('Transient errors when triggering tryjobs. ' |
| + 'Will retry in %d seconds.', wait) |
| + time.sleep(wait) |
| + wait *= 2 |
| + |
| + print '\n'.join(print_text) |
|
nodir
2015/04/18 05:17:56
Move this before the loop. Otherwise it says "tryi
|
| + |
| + |
| def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): |
| """Return the corresponding git ref if |base_url| together with |glob_spec| |
| matches the full |url|. |
| @@ -269,6 +376,10 @@ def print_stats(similarity, find_copies, args): |
| stdout=stdout, env=env) |
| +class BuildbucketResponseException(Exception): |
| + pass |
| + |
| + |
| class Settings(object): |
| def __init__(self): |
| self.default_server = None |
| @@ -2860,22 +2971,16 @@ def CMDtry(parser, args): |
| 'upload fail?\ngit-cl try always uses latest patchset from rietveld. ' |
| 'Continuing using\npatchset %s.\n' % patchset) |
| try: |
| - cl.RpcServer().trigger_distributed_try_jobs( |
| - cl.GetIssue(), patchset, options.name, options.clobber, |
| - options.revision, masters) |
| - except urllib2.HTTPError, e: |
| - if e.code == 404: |
| - print('404 from rietveld; ' |
| - 'did you mean to use "git try" instead of "git cl try"?') |
| - return 1 |
| - print('Tried jobs on:') |
| - |
| - for (master, builders) in masters.iteritems(): |
| - if master: |
| - print 'Master: %s' % master |
| - length = max(len(builder) for builder in builders) |
| - for builder in sorted(builders): |
| - print ' %*s: %s' % (length, builder, ','.join(builders[builder])) |
| + trigger_distributed_try_jobs( |
| + auth_config, cl, options, masters, 'git cl try') |
| + except BuildbucketResponseException as ex: |
| + print 'ERROR: %s' % ex |
| + return 1 |
| + except Exception as e: |
| + stacktrace = (''.join(traceback.format_stack()) + traceback.format_exc()) |
| + print 'ERROR: Exception when trying to trigger tryjobs: %s\n%s' % ( |
| + e, stacktrace) |
|
nodir
2015/04/18 05:17:56
I think logging.exception('ERROR: Exception when t
|
| + return 1 |
| return 0 |