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

Side by Side Diff: infra/services/master_manager_launcher/__main__.py

Issue 1130063003: Convert master_manager_launcher to use multiprocessing. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master-kickoff
Patch Set: Rebase onto latest master. Created 5 years, 7 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 | « infra/libs/process_invocation/test/multiprocess_test.py ('k') | 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/python 1 #!/usr/bin/python
2 # Copyright 2015 Google Inc. All Rights Reserved. 2 # Copyright 2015 Google Inc. All Rights Reserved.
3 # pylint: disable=F0401 3 # pylint: disable=F0401
4 4
5 """Launch a master_manager script for every master on a host.""" 5 """Launch a master_manager script for every master on a host."""
6 6
7 # pragma: no cover 7 # pragma: no cover
8 8
9 import argparse 9 import argparse
10 import json 10 import json
11 import logging 11 import logging
12 import operator 12 import operator
13 import os 13 import os
14 import socket 14 import socket
15 import subprocess 15 import subprocess
16 import sys 16 import sys
17 17
18 from infra.libs import logs 18 from infra.libs import logs
19 from infra.libs.process_invocation import multiprocess
19 from infra.libs.service_utils import daemon 20 from infra.libs.service_utils import daemon
20 from infra.services.master_lifecycle import buildbot_state 21 from infra.services.master_lifecycle import buildbot_state
21 from infra.services.master_manager_launcher import desired_state_parser 22 from infra.services.master_manager_launcher import desired_state_parser
22 23
23 24
24 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) 25 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
25 RUNPY = os.path.abspath(os.path.join( 26 RUNPY = os.path.abspath(os.path.join(
26 SCRIPT_DIR, os.pardir, os.pardir, os.pardir, 'run.py')) 27 SCRIPT_DIR, os.pardir, os.pardir, os.pardir, 'run.py'))
27 28
28 29
29 def parse_args(): 30 def parse_args():
30 parser = argparse.ArgumentParser( 31 parser = argparse.ArgumentParser(
31 description='Launches master_manager for every master on a host. NOTE: ' 32 description='Launches master_manager for every master on a host. NOTE: '
32 'does not perform any action unless --prod is set.') 33 'does not perform any action unless --prod is set.')
33 parser.add_argument('build_dir', nargs='?', 34 parser.add_argument('build_dir', nargs='?',
34 help='location of the tools/build directory') 35 help='location of the tools/build directory')
35 parser.add_argument('--hostname', 36 parser.add_argument('--hostname',
36 default=socket.getfqdn(), 37 default=socket.getfqdn(),
37 help='override local hostname (currently %(default)s)') 38 help='override local hostname (currently %(default)s)')
38 parser.add_argument('--json-location', 39 parser.add_argument('--json-location',
39 default='desired_master_state.json', 40 default='desired_master_state.json',
40 help='desired master state configuration (default: %(default)s)') 41 help='desired master state configuration (default: %(default)s)')
41 parser.add_argument('--command-timeout', 42 parser.add_argument('--command-timeout',
42 help='apply a timeout in seconds to each master_manager process') 43 help='apply a timeout in seconds to each master_manager process')
43 parser.add_argument('--verify', action='store_true', 44 parser.add_argument('--verify', action='store_true',
44 help='verify the desired master state JSON is valid, then exit') 45 help='verify the desired master state JSON is valid, then exit')
45 parser.add_argument('--prod', action='store_true', 46 parser.add_argument('--prod', action='store_true',
46 help='actually perform actions instead of doing a dry run') 47 help='actually perform actions instead of doing a dry run')
48 parser.add_argument('--processes',
49 default=16, type=int,
50 help='maximum number of master_manager processes to run simultaneously '
51 '(default %(default)d)')
47 logs.add_argparse_options(parser) 52 logs.add_argparse_options(parser)
48 53
49 args = parser.parse_args() 54 args = parser.parse_args()
50 logs.process_argparse_options(args) 55 logs.process_argparse_options(args)
51 56
52 if not args.verify: 57 if not args.verify:
53 if not args.build_dir: 58 if not args.build_dir:
54 parser.error('A build/ directory must be specified.') 59 parser.error('A build/ directory must be specified.')
55 60
56 return args 61 return args
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 log_triggered_ignored(triggered, ignored, args.hostname) 111 log_triggered_ignored(triggered, ignored, args.hostname)
107 112
108 commands = [ 113 commands = [
109 synthesize_master_manager_cmd(m, args.hostname, prod=args.prod) 114 synthesize_master_manager_cmd(m, args.hostname, prod=args.prod)
110 for m in triggered 115 for m in triggered
111 ] 116 ]
112 117
113 if args.command_timeout: 118 if args.command_timeout:
114 commands = [daemon.add_timeout(c, args.command_timeout) for c in commands] 119 commands = [daemon.add_timeout(c, args.command_timeout) for c in commands]
115 120
116 for command in commands: 121 multiprocess.safe_map(subprocess.call, commands, args.processes)
117 logging.info('running %s' % command)
118 subprocess.call(command)
119 122
120 123
121 if __name__ == '__main__': 124 if __name__ == '__main__':
122 sys.exit(main()) 125 sys.exit(main())
OLDNEW
« no previous file with comments | « infra/libs/process_invocation/test/multiprocess_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698