OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Wrapper that does auto-retry and stats logging for command invocation. | 7 """Wrapper that does auto-retry and stats logging for command invocation. |
8 | 8 |
9 Various command line tools in use: gsutil, curl have spurious failure. | 9 Various command line tools in use: gsutil, curl have spurious failure. |
10 This wrapper will track stats to an AppEngine based service to | 10 This wrapper will track stats to an AppEngine based service to |
11 help track down the cause of failures, as well as add retry logic. | 11 help track down the cause of failures, as well as add retry logic. |
12 """ | 12 """ |
13 | 13 |
14 | 14 |
15 import optparse | 15 import optparse |
16 import os | 16 import os |
| 17 import platform |
17 import subprocess | 18 import subprocess |
18 import sys | 19 import sys |
19 import time | 20 import time |
20 import urllib | 21 import urllib |
21 import uuid | 22 import uuid |
22 | 23 |
23 | 24 |
24 def LogCommand(options, command_id, | 25 def LogCommand(options, command_id, |
25 attempt, cmd, returncode, stdout, stderr, runtime): | 26 attempt, cmd, returncode, stdout, stderr, runtime): |
26 """Log a command invocation and result to a central location. | 27 """Log a command invocation and result to a central location. |
27 | 28 |
28 Arguments: | 29 Arguments: |
29 options: parsed options | 30 options: parsed options |
30 command_id: unique id for this command (shared by all retries) | 31 command_id: unique id for this command (shared by all retries) |
31 attempt: which try numbered from 0 | 32 attempt: which try numbered from 0 |
32 cmd: command run | 33 cmd: command run |
33 returncode: return code from running command | 34 returncode: return code from running command |
34 stdout: text of stdout | 35 stdout: text of stdout |
35 stderr: text of stderr | 36 stderr: text of stderr |
36 runtime: command runtime in seconds | 37 runtime: command runtime in seconds |
37 """ | 38 """ |
38 uname = os.uname() | 39 uname = platform.uname() |
39 params = urllib.urlencode({ | 40 params = urllib.urlencode({ |
40 'attempt': str(attempt), | 41 'attempt': str(attempt), |
41 'cwd': os.getcwd(), | 42 'cwd': os.getcwd(), |
42 'command_id': command_id, | 43 'command_id': command_id, |
43 'command': cmd, | 44 'command': cmd, |
44 'returncode': str(returncode), | 45 'returncode': str(returncode), |
45 'stdout': stdout[:400], | 46 'stdout': stdout[:400], |
46 'stderr': stderr[:400], | 47 'stderr': stderr[:400], |
47 'runtime': str(runtime), | 48 'runtime': str(runtime), |
48 'retries': str(options.retries), | 49 'retries': str(options.retries), |
49 'uname_sysname': uname[0], | 50 'uname_sysname': uname[0], |
50 'uname_nodename': uname[1], | 51 'uname_nodename': uname[1], |
51 'uname_release': uname[2], | 52 'uname_release': uname[2], |
52 'uname_version': uname[3], | 53 'uname_version': uname[3], |
53 'uname_machine': uname[4], | 54 'uname_machine': uname[4], |
| 55 'uname_processor': uname[5], |
54 }) | 56 }) |
55 f = urllib.urlopen(options.logurl, params) | 57 f = urllib.urlopen(options.logurl, params) |
56 f.read() | 58 f.read() |
57 f.close() | 59 f.close() |
58 | 60 |
59 | 61 |
60 def main(argv): | 62 def main(argv): |
61 parser = optparse.OptionParser() | 63 parser = optparse.OptionParser() |
62 parser.add_option('-r', '--retries', dest='retries', | 64 parser.add_option('-r', '--retries', dest='retries', |
63 type='int', default=10, | 65 type='int', default=10, |
(...skipping 21 matching lines...) Expand all Loading... |
85 print 'Command %s failed with retcode %d, try %d.' % ( | 87 print 'Command %s failed with retcode %d, try %d.' % ( |
86 ' '.join(args), p.returncode, r + 1) | 88 ' '.join(args), p.returncode, r + 1) |
87 print 'Command %s failed %d retries, giving up.' % ( | 89 print 'Command %s failed %d retries, giving up.' % ( |
88 ' '.join(args), options.retries) | 90 ' '.join(args), options.retries) |
89 | 91 |
90 return p.returncode | 92 return p.returncode |
91 | 93 |
92 | 94 |
93 if __name__ == '__main__': | 95 if __name__ == '__main__': |
94 sys.exit(main(sys.argv)) | 96 sys.exit(main(sys.argv)) |
OLD | NEW |