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

Side by Side Diff: build/android/test_wrapper/logdog_wrapper.py

Issue 2451273005: [android] Pass SIGTERM from logdog_wrapper to its wrapped test command. (Closed)
Patch Set: bpastene comment Created 4 years, 1 month 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 | no next file » | 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 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
11 import signal
11 import subprocess 12 import subprocess
12 import sys 13 import sys
13 import urllib 14 import urllib
14 15
15 16
16 def CommandParser(): 17 def CommandParser():
17 # Parses the command line arguments being passed in 18 # Parses the command line arguments being passed in
18 parser = argparse.ArgumentParser() 19 parser = argparse.ArgumentParser()
19 parser.add_argument('--logdog-bin-cmd', required=True, 20 parser.add_argument('--logdog-bin-cmd', required=True,
20 help='Command for running logdog butler binary') 21 help='Command for running logdog butler binary')
(...skipping 11 matching lines...) Expand all
32 parser.add_argument('--name', required=True, 33 parser.add_argument('--name', required=True,
33 help='Name to be used for logdog stream') 34 help='Name to be used for logdog stream')
34 return parser 35 return parser
35 36
36 37
37 def CreateUrl(server, project, prefix, name): 38 def CreateUrl(server, project, prefix, name):
38 stream_name = '%s/%s/+/%s' % (project, prefix, name) 39 stream_name = '%s/%s/+/%s' % (project, prefix, name)
39 return 'https://%s/v/?s=%s' % (server, urllib.quote_plus(stream_name)) 40 return 'https://%s/v/?s=%s' % (server, urllib.quote_plus(stream_name))
40 41
41 42
43 def CreateSignalForwarder(proc):
44 def handler(signum, _frame):
45 logging.error('Forwarding signal %s to test process', str(signum))
46 proc.send_signal(signum)
47
48 return handler
49
50
42 def main(): 51 def main():
43 parser = CommandParser() 52 parser = CommandParser()
44 args, test_cmd = parser.parse_known_args(sys.argv[1:]) 53 args, test_cmd = parser.parse_known_args(sys.argv[1:])
45 logging.basicConfig(level=logging.INFO) 54 logging.basicConfig(level=logging.INFO)
46 if not test_cmd: 55 if not test_cmd:
47 parser.error('Must specify command to run after the logdog flags') 56 parser.error('Must specify command to run after the logdog flags')
48 result = subprocess.call(test_cmd) 57 test_proc = subprocess.Popen(test_cmd)
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)
49 if '${SWARMING_TASK_ID}' in args.prefix: 64 if '${SWARMING_TASK_ID}' in args.prefix:
50 args.prefix = args.prefix.replace('${SWARMING_TASK_ID}', 65 args.prefix = args.prefix.replace('${SWARMING_TASK_ID}',
51 os.environ.get('SWARMING_TASK_ID')) 66 os.environ.get('SWARMING_TASK_ID'))
52 url = CreateUrl('luci-logdog.appspot.com', args.project, args.prefix, 67 url = CreateUrl('luci-logdog.appspot.com', args.project, args.prefix,
53 args.name) 68 args.name)
54 logdog_cmd = [args.logdog_bin_cmd, '-project', args.project, 69 logdog_cmd = [args.logdog_bin_cmd, '-project', args.project,
55 '-output', 'logdog,host=%s' % args.logdog_server, 70 '-output', 'logdog,host=%s' % args.logdog_server,
56 '-prefix', args.prefix, 71 '-prefix', args.prefix,
57 '-service-account-json', args.service_account_json, 72 '-service-account-json', args.service_account_json,
58 'stream', '-source', args.source, 73 'stream', '-source', args.source,
59 '-stream', '-name=%s' % args.name] 74 '-stream', '-name=%s' % args.name]
60 if os.path.exists(args.logdog_bin_cmd): 75 if os.path.exists(args.logdog_bin_cmd):
61 subprocess.call(logdog_cmd) 76 subprocess.call(logdog_cmd)
62 logging.info('Logcats are located at: %s', url) 77 logging.info('Logcats are located at: %s', url)
63 return result 78 return result
64 79
65 80
66 if __name__ == '__main__': 81 if __name__ == '__main__':
67 sys.exit(main()) 82 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698