Commit 7adb5845 authored by Dan Jacques's avatar Dan Jacques Committed by Commit Bot

[bot_update] Remove retry logic.

Retries are no longer necessary, since the Git wrapper will retry all
transient Git operations.

BUG=None
TEST=None
R=hinoka@chromium.org, iannucci@chromium.org

Change-Id: I18f066004992c98e54665833360944cc7d6550cc
Reviewed-on: https://chromium-review.googlesource.com/506375
Commit-Queue: Daniel Jacques <dnj@chromium.org>
Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
Reviewed-by: 's avatarRyan Tseng <hinoka@chromium.org>
parent 4a28cac7
...@@ -143,9 +143,7 @@ def call(*args, **kwargs): # pragma: no cover ...@@ -143,9 +143,7 @@ def call(*args, **kwargs): # pragma: no cover
kwargs['stderr'] = subprocess.STDOUT kwargs['stderr'] = subprocess.STDOUT
kwargs.setdefault('bufsize', BUF_SIZE) kwargs.setdefault('bufsize', BUF_SIZE)
cwd = kwargs.get('cwd', os.getcwd()) cwd = kwargs.get('cwd', os.getcwd())
result_fn = kwargs.pop('result_fn', lambda code, out: RETRY if code else OK)
stdin_data = kwargs.pop('stdin_data', None) stdin_data = kwargs.pop('stdin_data', None)
tries = kwargs.pop('tries', ATTEMPTS)
if stdin_data: if stdin_data:
kwargs['stdin'] = subprocess.PIPE kwargs['stdin'] = subprocess.PIPE
out = cStringIO.StringIO() out = cStringIO.StringIO()
...@@ -153,64 +151,53 @@ def call(*args, **kwargs): # pragma: no cover ...@@ -153,64 +151,53 @@ def call(*args, **kwargs): # pragma: no cover
env = copy.copy(os.environ) env = copy.copy(os.environ)
env.update(new_env) env.update(new_env)
kwargs['env'] = env kwargs['env'] = env
attempt = 0
for attempt in range(1, tries + 1): if new_env:
attempt_msg = ' (attempt #%d)' % attempt if attempt else '' print '===Injecting Environment Variables==='
if new_env: for k, v in sorted(new_env.items()):
print '===Injecting Environment Variables===' print '%s: %s' % (k, v)
for k, v in sorted(new_env.items()): print '===Running %s===' % (' '.join(args),)
print '%s: %s' % (k, v) print 'In directory: %s' % cwd
print '===Running %s%s===' % (' '.join(args), attempt_msg) start_time = time.time()
print 'In directory: %s' % cwd proc = subprocess.Popen(args, **kwargs)
start_time = time.time() if stdin_data:
proc = subprocess.Popen(args, **kwargs) proc.stdin.write(stdin_data)
if stdin_data: proc.stdin.close()
proc.stdin.write(stdin_data) psprinter = PsPrinter()
proc.stdin.close() # This is here because passing 'sys.stdout' into stdout for proc will
psprinter = PsPrinter() # produce out of order output.
# This is here because passing 'sys.stdout' into stdout for proc will hanging_cr = False
# produce out of order output. while True:
hanging_cr = False psprinter.poke()
while True: buf = proc.stdout.read(BUF_SIZE)
psprinter.poke() if not buf:
buf = proc.stdout.read(BUF_SIZE)
if not buf:
break
if hanging_cr:
buf = '\r' + buf
hanging_cr = buf.endswith('\r')
if hanging_cr:
buf = buf[:-1]
buf = buf.replace('\r\n', '\n').replace('\r', '\n')
sys.stdout.write(buf)
out.write(buf)
if hanging_cr:
sys.stdout.write('\n')
out.write('\n')
psprinter.cancel()
code = proc.wait()
elapsed_time = ((time.time() - start_time) / 60.0)
outval = out.getvalue()
result = result_fn(code, outval)
if result in (FAIL, RETRY):
print '===Failed in %.1f mins===' % elapsed_time
print
else:
print '===Succeeded in %.1f mins===' % elapsed_time
print
return outval
if result is FAIL:
break break
if result is RETRY and attempt < tries: if hanging_cr:
sleep_backoff = 4 ** attempt buf = '\r' + buf
sleep_time = random.randint(sleep_backoff, int(sleep_backoff * 1.2)) hanging_cr = buf.endswith('\r')
print '===backing off, sleeping for %d secs===' % sleep_time if hanging_cr:
time.sleep(sleep_time) buf = buf[:-1]
buf = buf.replace('\r\n', '\n').replace('\r', '\n')
sys.stdout.write(buf)
out.write(buf)
if hanging_cr:
sys.stdout.write('\n')
out.write('\n')
psprinter.cancel()
code = proc.wait()
elapsed_time = ((time.time() - start_time) / 60.0)
outval = out.getvalue()
if code:
print '===Failed in %.1f mins===' % elapsed_time
print
raise SubprocessFailed('%s failed with code %d in %s.' %
(' '.join(args), code, cwd),
code, outval)
raise SubprocessFailed('%s failed with code %d in %s after %d attempts.' % print '===Succeeded in %.1f mins===' % elapsed_time
(' '.join(args), code, cwd, attempt), print
code, outval) return outval
def git(*args, **kwargs): # pragma: no cover def git(*args, **kwargs): # pragma: no cover
...@@ -363,7 +350,7 @@ def gclient_sync( ...@@ -363,7 +350,7 @@ def gclient_sync(
args.extend(['--revision', '%s@%s' % (name, revision)]) args.extend(['--revision', '%s@%s' % (name, revision)])
try: try:
call_gclient(*args, tries=1) call_gclient(*args)
except SubprocessFailed as e: except SubprocessFailed as e:
# Throw a GclientSyncFailed exception so we can catch this independently. # Throw a GclientSyncFailed exception so we can catch this independently.
raise GclientSyncFailed(e.message, e.code, e.output) raise GclientSyncFailed(e.message, e.code, e.output)
...@@ -467,10 +454,10 @@ def force_revision(folder_name, revision): ...@@ -467,10 +454,10 @@ def force_revision(folder_name, revision):
branch, revision = split_revision branch, revision = split_revision
if revision and revision.upper() != 'HEAD': if revision and revision.upper() != 'HEAD':
git('checkout', '--force', revision, cwd=folder_name, tries=1) git('checkout', '--force', revision, cwd=folder_name)
else: else:
ref = branch if branch.startswith('refs/') else 'origin/%s' % branch ref = branch if branch.startswith('refs/') else 'origin/%s' % branch
git('checkout', '--force', ref, cwd=folder_name, tries=1) git('checkout', '--force', ref, cwd=folder_name)
def is_broken_repo_dir(repo_dir): def is_broken_repo_dir(repo_dir):
...@@ -543,13 +530,13 @@ def git_checkout(solutions, revisions, shallow, refs, git_cache_dir): ...@@ -543,13 +530,13 @@ def git_checkout(solutions, revisions, shallow, refs, git_cache_dir):
# Use "tries=1", since we retry manually in this loop. # Use "tries=1", since we retry manually in this loop.
if not path.isdir(sln_dir): if not path.isdir(sln_dir):
git(*clone_cmd, tries=1) git(*clone_cmd)
else: else:
git('remote', 'set-url', 'origin', mirror_dir, cwd=sln_dir, tries=1) git('remote', 'set-url', 'origin', mirror_dir, cwd=sln_dir)
git('fetch', 'origin', cwd=sln_dir, tries=1) git('fetch', 'origin', cwd=sln_dir)
for ref in refs: for ref in refs:
refspec = '%s:%s' % (ref, ref.lstrip('+')) refspec = '%s:%s' % (ref, ref.lstrip('+'))
git('fetch', 'origin', refspec, cwd=sln_dir, tries=1) git('fetch', 'origin', refspec, cwd=sln_dir)
# Windows sometimes has trouble deleting files. # Windows sometimes has trouble deleting files.
# This can make git commands that rely on locks fail. # This can make git commands that rely on locks fail.
...@@ -641,7 +628,7 @@ def apply_rietveld_issue(issue, patchset, root, server, _rev_map, _revision, ...@@ -641,7 +628,7 @@ def apply_rietveld_issue(issue, patchset, root, server, _rev_map, _revision,
# Only try once, since subsequent failures hide the real failure. # Only try once, since subsequent failures hide the real failure.
try: try:
call(*cmd, tries=1) call(*cmd)
except SubprocessFailed as e: except SubprocessFailed as e:
raise PatchFailed(e.message, e.code, e.output) raise PatchFailed(e.message, e.code, e.output)
...@@ -661,7 +648,7 @@ def apply_gerrit_ref(gerrit_repo, gerrit_ref, root, gerrit_reset, ...@@ -661,7 +648,7 @@ def apply_gerrit_ref(gerrit_repo, gerrit_ref, root, gerrit_reset,
# command will do so. See http://crbug.com/692067. # command will do so. See http://crbug.com/692067.
git('reset', '--hard', cwd=root) git('reset', '--hard', cwd=root)
try: try:
git('fetch', gerrit_repo, gerrit_ref, cwd=root, tries=1) git('fetch', gerrit_repo, gerrit_ref, cwd=root)
git('checkout', 'FETCH_HEAD', cwd=root) git('checkout', 'FETCH_HEAD', cwd=root)
if gerrit_rebase_patch_ref: if gerrit_rebase_patch_ref:
...@@ -674,7 +661,7 @@ def apply_gerrit_ref(gerrit_repo, gerrit_ref, root, gerrit_reset, ...@@ -674,7 +661,7 @@ def apply_gerrit_ref(gerrit_repo, gerrit_ref, root, gerrit_reset,
try: try:
git('-c', 'user.name=chrome-bot', git('-c', 'user.name=chrome-bot',
'-c', 'user.email=chrome-bot@chromium.org', '-c', 'user.email=chrome-bot@chromium.org',
'rebase', base_rev, cwd=root, tries=1) 'rebase', base_rev, cwd=root)
except SubprocessFailed: except SubprocessFailed:
# Abort the rebase since there were failures. # Abort the rebase since there were failures.
git('rebase', '--abort', cwd=root) git('rebase', '--abort', cwd=root)
......
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