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

Side by Side Diff: scripts/tools/slave_alloc_update.py

Issue 1393893004: Add `slave_alloc_update` tool. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Command-line tool to update slave allocation JSON for slave pools that are
7 managed by `<build>/scripts/common/slave_alloc.py`.
8
9 This script is directed at a master, and will:
10 1) Load the master's `slaves.cfg` and process it.
11 2) For each identified SlaveAllocator instance, regenerate the slave pool JSON
12 file.
13 """
14
15 import argparse
16 import logging
17 import os
18 import sys
19
20 import common.chromium_utils
21 import common.env
22 import common.slave_alloc
23
24
25 def _UpdateSlaveAlloc(master_dir, sa):
26 logging.info('Updating slaves for master "%s": [%s]',
27 os.path.basename(master_dir), sa.state_path)
28 with common.chromium_utils.MasterEnvironment(master_dir):
29 sa.SaveState()
30
31
32 def _UpdateMaster(master_name):
33 master_dir = common.chromium_utils.MasterPath(master_name)
34 slaves_cfg_path = os.path.join(os.path.abspath(master_dir), 'slaves.cfg')
35 if not os.path.isfile(slaves_cfg_path):
36 raise ValueError('Master directory does not contain "slaves.cfg": %s' % (
37 master_dir,))
38
39 logging.debug('Loading "slaves.cfg" from: [%s]', slaves_cfg_path)
40 cfg = common.chromium_utils.ParsePythonCfg(slaves_cfg_path, fail_hard=False)
41
42 updated = False
43 for name, sa in (cfg or {}).iteritems():
44 if isinstance(sa, common.slave_alloc.SlaveAllocator):
45 logging.debug('Identified slave allocator variable [%s]', name)
46 _UpdateSlaveAlloc(master_dir, sa)
47 updated = True
48 return updated
49
50
51 def main(argv):
52 parser = argparse.ArgumentParser()
53 parser.add_argument('-v', '--verbose',
54 action='count', default=0,
55 help='Increase verbosity. This can be specified multiple times.')
56 parser.add_argument('masters', metavar='NAME', nargs='+',
57 help='Name of the master to update.')
58 args = parser.parse_args(argv)
59
60 # Configure logging verbosity.
61 if args.verbose == 0:
62 level = logging.WARNING
63 elif args.verbose == 1:
64 level = logging.INFO
65 else:
66 level = logging.DEBUG
67 logging.getLogger().setLevel(level)
68
69 # Update each master directory.
70 for name in args.masters:
71 if not _UpdateMaster(name):
72 raise ValueError('No slave allocators identified for [%s]' % (name,))
73
74
75 if __name__ == '__main__':
76 logging.basicConfig()
77 try:
78 sys.exit(main(sys.argv[1:]))
79 except Exception as e:
80 logging.exception('Uncaught exception encountered during execution: %s', e)
81 sys.exit(2)
OLDNEW
« scripts/common/chromium_utils.py ('K') | « scripts/common/slave_alloc.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698