Commit b1ae481f authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

git-cl: Remove hack to ask for random mirrors when querying Gerrit.

Bug: 881860
Change-Id: I4d37c8fd7cf5804dbc69fa4f87b0f55160afdaf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1874893
Commit-Queue: Andrii Shyshkalov <tandrii@google.com>
Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@google.com>
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
parent 401b25c8
......@@ -47,8 +47,7 @@ else:
LOGGER = logging.getLogger()
# With a starting sleep time of 1.5 seconds, 2^n exponential backoff, and seven
# total tries, the sleep time between the first and last tries will be 94.5 sec.
# TODO(crbug.com/881860): Lower this when crbug.com/877717 is fixed.
TRY_LIMIT = 7
TRY_LIMIT = 3
# Controls the transport protocol used to communicate with Gerrit.
......@@ -453,16 +452,6 @@ def ReadHttpResponse(conn, accept_statuses=frozenset([200])):
conn.req_host, conn.req_params['method'],
conn.req_params['uri'],
http_version, http_version, response.status, response.reason)
if response.status == 404:
# TODO(crbug/881860): remove this hack.
# HACK: try different Gerrit mirror as a workaround for potentially
# out-of-date mirror hit through default routing.
if conn.req_host == 'chromium-review.googlesource.com':
conn.req_params['uri'] = _UseGerritMirror(
conn.req_params['uri'], 'chromium-review.googlesource.com')
# And don't increase sleep_time in this case, since we suspect we've
# just asked wrong git mirror before.
sleep_time /= 2.0
if TRY_LIMIT - idx > 1:
LOGGER.info('Will retry in %d seconds (%d more times)...',
......@@ -1007,31 +996,3 @@ def ChangeIdentifier(project, change_number):
"""
assert int(change_number)
return '%s~%s' % (urllib.quote(project, safe=''), change_number)
# TODO(crbug/881860): remove this hack.
_GERRIT_MIRROR_PREFIXES = ['us1', 'us2', 'us3', 'eu1']
assert all(3 == len(p) for p in _GERRIT_MIRROR_PREFIXES)
def _UseGerritMirror(url, host):
"""Returns a new URL which uses randomly selected mirror for a Gerrit host.
The URL's host should be for a given host or a result of prior call to this
function.
Assumes that the URL has a single occurence of the host substring.
"""
assert host in url
suffix = '-mirror-' + host
prefixes = set(_GERRIT_MIRROR_PREFIXES)
prefix_len = len(_GERRIT_MIRROR_PREFIXES[0])
st = url.find(suffix)
if st == -1:
actual_host = host
else:
# Already uses some mirror.
assert st >= prefix_len, (url, host, st, prefix_len)
prefixes.remove(url[st-prefix_len:st])
actual_host = url[st-prefix_len:st+len(suffix)]
return url.replace(actual_host, random.choice(list(prefixes)) + suffix)
......@@ -421,24 +421,6 @@ class TestGitClBasic(unittest.TestCase):
'Cr-Commit-Position: refs/heads/branch@{#2}\n'
'Cr-Branched-From: somehash-refs/heads/master@{#12}')
def test_gerrit_mirror_hack(self):
cr = 'chromium-review.googlesource.com'
url0 = 'https://%s/a/changes/x?a=b' % cr
origMirrors = git_cl.gerrit_util._GERRIT_MIRROR_PREFIXES
try:
git_cl.gerrit_util._GERRIT_MIRROR_PREFIXES = ['us1', 'us2']
url1 = git_cl.gerrit_util._UseGerritMirror(url0, cr)
url2 = git_cl.gerrit_util._UseGerritMirror(url1, cr)
url3 = git_cl.gerrit_util._UseGerritMirror(url2, cr)
self.assertNotEqual(url1, url2)
self.assertEqual(sorted((url1, url2)), [
'https://us1-mirror-chromium-review.googlesource.com/a/changes/x?a=b',
'https://us2-mirror-chromium-review.googlesource.com/a/changes/x?a=b'])
self.assertEqual(url1, url3)
finally:
git_cl.gerrit_util._GERRIT_MIRROR_PREFIXES = origMirrors
def test_valid_accounts(self):
mock_per_account = {
'u1': None, # 404, doesn't exist.
......
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