Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 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 """Wrapper for adding logdog streaming support to swarming tasks.""" | 6 """Wrapper for adding logdog streaming support to swarming tasks.""" |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 | 47 |
| 48 return handler | 48 return handler |
| 49 | 49 |
| 50 | 50 |
| 51 def main(): | 51 def main(): |
| 52 parser = CommandParser() | 52 parser = CommandParser() |
| 53 args, test_cmd = parser.parse_known_args(sys.argv[1:]) | 53 args, test_cmd = parser.parse_known_args(sys.argv[1:]) |
| 54 logging.basicConfig(level=logging.INFO) | 54 logging.basicConfig(level=logging.INFO) |
| 55 if not test_cmd: | 55 if not test_cmd: |
| 56 parser.error('Must specify command to run after the logdog flags') | 56 parser.error('Must specify command to run after the logdog flags') |
| 57 test_proc = subprocess.Popen(test_cmd) | 57 |
| 58 original_sigterm_handler = signal.signal( | |
| 59 signal.SIGTERM, CreateSignalForwarder(test_proc)) | |
| 60 try: | |
| 61 result = test_proc.wait() | |
| 62 finally: | |
| 63 signal.signal(signal.SIGTERM, original_sigterm_handler) | |
| 64 if '${SWARMING_TASK_ID}' in args.prefix: | 58 if '${SWARMING_TASK_ID}' in args.prefix: |
| 65 args.prefix = args.prefix.replace('${SWARMING_TASK_ID}', | 59 args.prefix = args.prefix.replace('${SWARMING_TASK_ID}', |
| 66 os.environ.get('SWARMING_TASK_ID')) | 60 os.environ.get('SWARMING_TASK_ID')) |
| 67 url = CreateUrl('luci-logdog.appspot.com', args.project, args.prefix, | 61 url = CreateUrl('luci-logdog.appspot.com', args.project, args.prefix, |
| 68 args.name) | 62 args.name) |
| 63 | |
| 69 logdog_cmd = [args.logdog_bin_cmd, '-project', args.project, | 64 logdog_cmd = [args.logdog_bin_cmd, '-project', args.project, |
| 70 '-output', 'logdog,host=%s' % args.logdog_server, | 65 '-output', 'logdog,host=%s' % args.logdog_server, |
| 71 '-prefix', args.prefix, | 66 '-prefix', args.prefix, |
| 72 '-service-account-json', args.service_account_json, | 67 '-service-account-json', args.service_account_json, |
| 73 'stream', '-source', args.source, | 68 'stream', '-source', args.source, |
| 74 '-stream', '-name=%s' % args.name] | 69 '-stream', '-name=%s' % args.name] |
| 75 | 70 |
| 76 if not os.path.exists(args.logdog_bin_cmd): | 71 if not os.path.exists(args.logdog_bin_cmd): |
| 72 test_proc = subprocess.Popen(test_cmd) | |
|
jbudorick
2017/02/14 23:50:27
Why is this moving? We still need to pass signals
| |
| 73 original_sigterm_handler = signal.signal( | |
| 74 signal.SIGTERM, CreateSignalForwarder(test_proc)) | |
| 75 try: | |
| 76 result = test_proc.wait() | |
| 77 finally: | |
| 78 signal.signal(signal.SIGTERM, original_sigterm_handler) | |
| 79 | |
| 77 logging.error( | 80 logging.error( |
| 78 'Logdog binary %s unavailable. Unable to upload logcats.', | 81 'Logdog binary %s unavailable. Unable to upload logcats.', |
| 79 args.logdog_bin_cmd) | 82 args.logdog_bin_cmd) |
| 80 elif not os.path.exists(args.source): | 83 return result |
| 84 | |
| 85 test_cmd = [args.logdog_bin_cmd, '-project', args.project, | |
| 86 '-output', 'logdog,host=%s' % args.logdog_server, | |
| 87 '-prefix', args.prefix, | |
| 88 '-service-account-json', args.service_account_json, | |
| 89 'run', '--'] + test_cmd | |
| 90 result = subprocess.call(test_cmd) | |
| 91 | |
| 92 if not os.path.exists(args.source): | |
| 81 logging.error( | 93 logging.error( |
| 82 'Logcat sources not found at %s. Unable to upload logcats.', | 94 'Logcat sources not found at %s. Unable to upload logcats.', |
| 83 args.source) | 95 args.source) |
| 84 else: | 96 else: |
| 85 subprocess.call(logdog_cmd) | 97 subprocess.call(logdog_cmd) |
| 86 logging.info('Logcats are located at: %s', url) | 98 logging.info('Logcats are located at: %s', url) |
| 87 return result | 99 return result |
| 88 | 100 |
| 89 | 101 |
| 90 if __name__ == '__main__': | 102 if __name__ == '__main__': |
| 91 sys.exit(main()) | 103 sys.exit(main()) |
| OLD | NEW |