Commit 1ad5811a authored by Andrii Shyshkalov's avatar Andrii Shyshkalov Committed by Commit Bot

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: 's avatarVadim Shtayura <vadimsh@chromium.org>
parent e7ae514a
......@@ -568,7 +568,8 @@ def fetch_try_jobs(auth_config, changelist, buildbucket_host,
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
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
changelist (Changelist): The CL to fetch builds for
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:
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
......@@ -585,8 +587,13 @@ def _fetch_latest_builds(auth_config, changelist, buildbucket_host):
assert buildbucket_host
assert changelist.GetIssue(), 'CL must be uploaded first'
assert changelist.GetCodereviewServer(), 'CL must be uploaded first'
assert changelist.GetMostRecentPatchset()
ps = changelist.GetMostRecentPatchset()
if latest_patchset is None:
assert changelist.GetMostRecentPatchset()
ps = changelist.GetMostRecentPatchset()
else:
assert latest_patchset > 0, latest_patchset
ps = latest_patchset
min_ps = max(1, ps - 5)
while ps >= min_ps:
builds = fetch_try_jobs(
......@@ -4520,8 +4527,9 @@ def CMDupload(parser, args):
print('Upload failed, so --retry-failed has no effect.')
return ret
auth_config = auth.extract_auth_config_from_options(options)
builds = fetch_try_jobs(
auth_config, cl, options.buildbucket_host, patchset)
builds, _ = _fetch_latest_builds(
auth_config, cl, options.buildbucket_host,
latest_patchset=patchset)
buckets = _filter_failed(builds)
if len(buckets) == 0:
print('No failed tryjobs, so --retry-failed has no effect.')
......
......@@ -3354,41 +3354,48 @@ class CMDUploadTestCase(unittest.TestCase):
},
},
}
mockFetchTryJobs.return_value = {
'9000': {
'id': '9000',
'project': 'infra',
'bucket': 'luci.infra.try',
'created_by': 'user:someone@chromium.org',
'created_ts': '147200002222000',
'experimental': False,
'parameters_json': json.dumps({
'builder_name': 'red-bot',
'properties': {'category': 'cq'},
}),
'status': 'COMPLETED',
'result': 'FAILURE',
'tags': ['user_agent:cq'],
},
8000: {
'id': '8000',
'project': 'infra',
'bucket': 'luci.infra.try',
'created_by': 'user:someone@chromium.org',
'created_ts': '147200002222020',
'experimental': False,
'parameters_json': json.dumps({
'builder_name': 'green-bot',
'properties': {'category': 'cq'},
}),
'status': 'COMPLETED',
'result': 'SUCCESS',
'tags': ['user_agent:cq'],
},
}
mockFetchTryJobs.side_effect = [
# Prior patchset - no builds.
{},
# Prior to prior patchset -- some builds.
{
'9000': {
'id': '9000',
'project': 'infra',
'bucket': 'luci.infra.try',
'created_by': 'user:someone@chromium.org',
'created_ts': '147200002222000',
'experimental': False,
'parameters_json': json.dumps({
'builder_name': 'red-bot',
'properties': {'category': 'cq'},
}),
'status': 'COMPLETED',
'result': 'FAILURE',
'tags': ['user_agent:cq'],
},
8000: {
'id': '8000',
'project': 'infra',
'bucket': 'luci.infra.try',
'created_by': 'user:someone@chromium.org',
'created_ts': '147200002222020',
'experimental': False,
'parameters_json': json.dumps({
'builder_name': 'green-bot',
'properties': {'category': 'cq'},
}),
'status': 'COMPLETED',
'result': 'SUCCESS',
'tags': ['user_agent:cq'],
},
},
]
self.assertEqual(0, git_cl.main(['upload', '--retry-failed']))
mockFetchTryJobs.assert_called_with(
mock.ANY, mock.ANY, 'cr-buildbucket.appspot.com', 7)
mockFetchTryJobs.assert_has_calls([
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': []}}
mockTriggerTryJobs.assert_called_once_with(
mock.ANY, mock.ANY, buckets, mock.ANY, 8)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment