Commit b180ded3 authored by dsansome@chromium.org's avatar dsansome@chromium.org
parent 305b8b57
...@@ -55,6 +55,11 @@ def GetNormalizedPlatform(): ...@@ -55,6 +55,11 @@ def GetNormalizedPlatform():
class Gsutil(object): class Gsutil(object):
"""Call gsutil with some predefined settings. This is a convenience object, """Call gsutil with some predefined settings. This is a convenience object,
and is also immutable.""" and is also immutable."""
MAX_TRIES = 5
RETRY_BASE_DELAY = 5.0
RETRY_DELAY_MULTIPLE = 1.3
def __init__(self, path, boto_path=None, timeout=None, version='4.15'): def __init__(self, path, boto_path=None, timeout=None, version='4.15'):
if not os.path.exists(path): if not os.path.exists(path):
raise FileNotFoundError('GSUtil not found in %s' % path) raise FileNotFoundError('GSUtil not found in %s' % path)
...@@ -100,6 +105,18 @@ class Gsutil(object): ...@@ -100,6 +105,18 @@ class Gsutil(object):
return (404, out, err) return (404, out, err)
return (code, out, err) return (code, out, err)
def check_call_with_retries(self, *args):
delay = self.RETRY_BASE_DELAY
for i in xrange(self.MAX_TRIES):
code, out, err = self.check_call(*args)
if not code or i == self.MAX_TRIES - 1:
break
time.sleep(delay)
delay *= self.RETRY_DELAY_MULTIPLE
return code, out, err
def check_platform(target): def check_platform(target):
"""Checks if any parent directory of target matches (win|mac|linux).""" """Checks if any parent directory of target matches (win|mac|linux)."""
......
...@@ -76,7 +76,7 @@ def _upload_worker( ...@@ -76,7 +76,7 @@ def _upload_worker(
file_url = '%s/%s' % (base_url, sha1_sum) file_url = '%s/%s' % (base_url, sha1_sum)
if gsutil.check_call('ls', file_url)[0] == 0 and not force: if gsutil.check_call('ls', file_url)[0] == 0 and not force:
# File exists, check MD5 hash. # File exists, check MD5 hash.
_, out, _ = gsutil.check_call('ls', '-L', file_url) _, out, _ = gsutil.check_call_with_retries('ls', '-L', file_url)
etag_match = re.search('ETag:\s+([a-z0-9]{32})', out) etag_match = re.search('ETag:\s+([a-z0-9]{32})', out)
if etag_match: if etag_match:
remote_md5 = etag_match.group(1) remote_md5 = etag_match.group(1)
...@@ -97,7 +97,7 @@ def _upload_worker( ...@@ -97,7 +97,7 @@ def _upload_worker(
if gzip: if gzip:
gsutil_args.extend(['-z', gzip]) gsutil_args.extend(['-z', gzip])
gsutil_args.extend([filename, file_url]) gsutil_args.extend([filename, file_url])
code, _, err = gsutil.check_call(*gsutil_args) code, _, err = gsutil.check_call_with_retries(*gsutil_args)
if code != 0: if code != 0:
ret_codes.put( ret_codes.put(
(code, (code,
...@@ -109,9 +109,9 @@ def _upload_worker( ...@@ -109,9 +109,9 @@ def _upload_worker(
# the download script will check for to preserve the executable bit. # the download script will check for to preserve the executable bit.
if not sys.platform.startswith('win'): if not sys.platform.startswith('win'):
if os.stat(filename).st_mode & stat.S_IEXEC: if os.stat(filename).st_mode & stat.S_IEXEC:
code, _, err = gsutil.check_call('setmeta', '-h', code, _, err = gsutil.check_call_with_retries(
'x-goog-meta-executable:1', file_url) 'setmeta', '-h', 'x-goog-meta-executable:1', file_url)
if code: if not code:
ret_codes.put( ret_codes.put(
(code, (code,
'Encountered error on setting metadata on %s\n%s' % 'Encountered error on setting metadata on %s\n%s' %
......
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