Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(647)

Side by Side Diff: recipe_modules/bot_update/resources/bot_update.py

Issue 2382653005: Remove git lockfile flakiness on win (bot_update) (Closed)
Patch Set: Remove git lockfile flakiness on win (bot_update) Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/bot_update_coverage_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # TODO(hinoka): Use logging. 6 # TODO(hinoka): Use logging.
7 7
8 import cStringIO 8 import cStringIO
9 import codecs 9 import codecs
10 import copy 10 import copy
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 if result is RETRY and attempt < tries: 203 if result is RETRY and attempt < tries:
204 sleep_backoff = 4 ** attempt 204 sleep_backoff = 4 ** attempt
205 sleep_time = random.randint(sleep_backoff, int(sleep_backoff * 1.2)) 205 sleep_time = random.randint(sleep_backoff, int(sleep_backoff * 1.2))
206 print '===backing off, sleeping for %d secs===' % sleep_time 206 print '===backing off, sleeping for %d secs===' % sleep_time
207 time.sleep(sleep_time) 207 time.sleep(sleep_time)
208 208
209 raise SubprocessFailed('%s failed with code %d in %s after %d attempts.' % 209 raise SubprocessFailed('%s failed with code %d in %s after %d attempts.' %
210 (' '.join(args), code, cwd, attempt), 210 (' '.join(args), code, cwd, attempt),
211 code, outval) 211 code, outval)
212 212
213
214 def git(*args, **kwargs): # pragma: no cover 213 def git(*args, **kwargs): # pragma: no cover
215 """Wrapper around call specifically for Git commands.""" 214 """Wrapper around call specifically for Git commands."""
216 if args and args[0] == 'cache': 215 if args and args[0] == 'cache':
217 # Rewrite "git cache" calls into "python git_cache.py". 216 # Rewrite "git cache" calls into "python git_cache.py".
218 cmd = (sys.executable, '-u', GIT_CACHE_PATH) + args[1:] 217 cmd = (sys.executable, '-u', GIT_CACHE_PATH) + args[1:]
219 else: 218 else:
220 git_executable = 'git' 219 git_executable = 'git'
221 # On windows, subprocess doesn't fuzzy-match 'git' to 'git.bat', so we 220 # On windows, subprocess doesn't fuzzy-match 'git' to 'git.bat', so we
222 # have to do it explicitly. This is better than passing shell=True. 221 # have to do it explicitly. This is better than passing shell=True.
223 if sys.platform.startswith('win'): 222 if sys.platform.startswith('win'):
224 git_executable += '.bat' 223 git_executable += '.bat'
224 # Windows sometimes has trouble deleting files. This can make git commands
225 # that rely on locks fail.
226 remove_git_lockfiles(sys.platform, os.getcwd())
Paweł Hajdan Jr. 2016/10/07 13:47:43 Well this still runs before _each_ git command rat
katthomas 2016/10/07 18:49:16 Right, I was thinking that any git command could c
Paweł Hajdan Jr. 2016/10/10 14:58:04 That'd sound good to me.
agable 2016/10/10 23:01:34 Yep, I'm in agreement with Pawel here: breaking lo
katthomas 2016/10/11 17:29:18 Makes sense, done.
225 cmd = (git_executable,) + args 227 cmd = (git_executable,) + args
226 return call(*cmd, **kwargs) 228 return call(*cmd, **kwargs)
227 229
230 def remove_git_lockfiles(platform, cwd, retries=3):
231 if not platform.startswith('win'):
agable 2016/10/10 23:01:34 nit: It's a matter of opinion whether it is better
katthomas 2016/10/11 17:29:18 Thanks!
232 return
233 git_dir = cwd + '/.git'
agable 2016/10/10 23:01:34 Can you guarantee that all callers of this functio
katthomas 2016/10/11 17:29:18 Done.
234 try:
235 lockfiles = [git_dir + '/' + f for f in os.listdir(git_dir)
236 if f.endswith('.lock')]
237 except Exception as e:
238 print 'Could not remove git lockfiles: %s' % str(e)
239 return
240 if lockfiles:
241 for filename in lockfiles:
242 print '===Attempting to remove lockfile %s===' % filename
agable 2016/10/10 23:01:34 super duper tiny nit: I'd print these big header/f
katthomas 2016/10/11 17:29:18 Done.
243 for _ in xrange(retries):
244 exitcode = call('cmd.exe', '/c', 'del',
245 '/f', '/q', os.path.normcase(filename))
246 if exitcode == 0:
247 return
248 time.sleep(3)
249 print '===Failed to remove lockfile %s====' % filename
228 250
229 def get_gclient_spec(solutions, target_os, target_os_only, git_cache_dir): 251 def get_gclient_spec(solutions, target_os, target_os_only, git_cache_dir):
230 return GCLIENT_TEMPLATE % { 252 return GCLIENT_TEMPLATE % {
231 'solutions': pprint.pformat(solutions, indent=4), 253 'solutions': pprint.pformat(solutions, indent=4),
232 'cache_dir': '"%s"' % git_cache_dir, 254 'cache_dir': '"%s"' % git_cache_dir,
233 'target_os': ('\ntarget_os=%s' % target_os) if target_os else '', 255 'target_os': ('\ntarget_os=%s' % target_os) if target_os else '',
234 'target_os_only': '\ntarget_os_only=%s' % target_os_only 256 'target_os_only': '\ntarget_os_only=%s' % target_os_only
235 } 257 }
236 258
237 259
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 # download patch failure is still an infra problem. 1112 # download patch failure is still an infra problem.
1091 if e.code == 3: 1113 if e.code == 3:
1092 # Patch download problem. 1114 # Patch download problem.
1093 return 87 1115 return 87
1094 # Genuine patch problem. 1116 # Genuine patch problem.
1095 return 88 1117 return 88
1096 1118
1097 1119
1098 if __name__ == '__main__': 1120 if __name__ == '__main__':
1099 sys.exit(main()) 1121 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | tests/bot_update_coverage_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698