git cl upload --retry-failed: search back up to 5 patchsets.

Make it work the same way as "git cl try --retry-failed".

R=ehmaldonado

Change-Id: Id3a709dc40b6b6d068acbba0c610da254ced8ff3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1845478
Commit-Queue: Andrii Shyshkalov <tandrii@google.com>
Auto-Submit: Andrii Shyshkalov <tandrii@google.com>
Reviewed-by: Vadim Shtayura <vadimsh@chromium.org>
changes/78/1845478/3
Andrii Shyshkalov 6 years ago committed by Commit Bot
parent e7ae514a47
commit 1ad5811acc

@ -568,7 +568,8 @@ def fetch_try_jobs(auth_config, changelist, buildbucket_host,
return builds return builds
def _fetch_latest_builds(auth_config, changelist, buildbucket_host): def _fetch_latest_builds(
auth_config, changelist, buildbucket_host, latest_patchset=None):
"""Fetches builds from the latest patchset that has builds (within """Fetches builds from the latest patchset that has builds (within
the last few patchsets). the last few patchsets).
@ -576,7 +577,8 @@ def _fetch_latest_builds(auth_config, changelist, buildbucket_host):
auth_config (auth.AuthConfig): Auth info for Buildbucket auth_config (auth.AuthConfig): Auth info for Buildbucket
changelist (Changelist): The CL to fetch builds for changelist (Changelist): The CL to fetch builds for
buildbucket_host (str): Buildbucket host, e.g. "cr-buildbucket.appspot.com" buildbucket_host (str): Buildbucket host, e.g. "cr-buildbucket.appspot.com"
lastest_patchset(int|NoneType): the patchset to start fetching builds from.
If None (default), starts with the latest available patchset.
Returns: Returns:
A tuple (builds, patchset) where builds is a dict mapping from build ID to A tuple (builds, patchset) where builds is a dict mapping from build ID to
build info from Buildbucket, and patchset is the patchset number where build info from Buildbucket, and patchset is the patchset number where
@ -585,8 +587,13 @@ def _fetch_latest_builds(auth_config, changelist, buildbucket_host):
assert buildbucket_host assert buildbucket_host
assert changelist.GetIssue(), 'CL must be uploaded first' assert changelist.GetIssue(), 'CL must be uploaded first'
assert changelist.GetCodereviewServer(), 'CL must be uploaded first' assert changelist.GetCodereviewServer(), 'CL must be uploaded first'
if latest_patchset is None:
assert changelist.GetMostRecentPatchset() assert changelist.GetMostRecentPatchset()
ps = changelist.GetMostRecentPatchset() ps = changelist.GetMostRecentPatchset()
else:
assert latest_patchset > 0, latest_patchset
ps = latest_patchset
min_ps = max(1, ps - 5) min_ps = max(1, ps - 5)
while ps >= min_ps: while ps >= min_ps:
builds = fetch_try_jobs( builds = fetch_try_jobs(
@ -4520,8 +4527,9 @@ def CMDupload(parser, args):
print('Upload failed, so --retry-failed has no effect.') print('Upload failed, so --retry-failed has no effect.')
return ret return ret
auth_config = auth.extract_auth_config_from_options(options) auth_config = auth.extract_auth_config_from_options(options)
builds = fetch_try_jobs( builds, _ = _fetch_latest_builds(
auth_config, cl, options.buildbucket_host, patchset) auth_config, cl, options.buildbucket_host,
latest_patchset=patchset)
buckets = _filter_failed(builds) buckets = _filter_failed(builds)
if len(buckets) == 0: if len(buckets) == 0:
print('No failed tryjobs, so --retry-failed has no effect.') print('No failed tryjobs, so --retry-failed has no effect.')

@ -3354,7 +3354,11 @@ class CMDUploadTestCase(unittest.TestCase):
}, },
}, },
} }
mockFetchTryJobs.return_value = { mockFetchTryJobs.side_effect = [
# Prior patchset - no builds.
{},
# Prior to prior patchset -- some builds.
{
'9000': { '9000': {
'id': '9000', 'id': '9000',
'project': 'infra', 'project': 'infra',
@ -3385,10 +3389,13 @@ class CMDUploadTestCase(unittest.TestCase):
'result': 'SUCCESS', 'result': 'SUCCESS',
'tags': ['user_agent:cq'], 'tags': ['user_agent:cq'],
}, },
} },
]
self.assertEqual(0, git_cl.main(['upload', '--retry-failed'])) self.assertEqual(0, git_cl.main(['upload', '--retry-failed']))
mockFetchTryJobs.assert_called_with( mockFetchTryJobs.assert_has_calls([
mock.ANY, mock.ANY, 'cr-buildbucket.appspot.com', 7) mock.call(mock.ANY, mock.ANY, 'cr-buildbucket.appspot.com', patchset=7),
mock.call(mock.ANY, mock.ANY, 'cr-buildbucket.appspot.com', patchset=6),
])
buckets = {'infra/try': {'red-bot': []}} buckets = {'infra/try': {'red-bot': []}}
mockTriggerTryJobs.assert_called_once_with( mockTriggerTryJobs.assert_called_once_with(
mock.ANY, mock.ANY, buckets, mock.ANY, 8) mock.ANY, mock.ANY, buckets, mock.ANY, 8)

Loading…
Cancel
Save