OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Utilities to enable slaves to determine their master without importing any | 5 """Utilities to enable slaves to determine their master without importing any |
6 buildbot or twisted code. | 6 buildbot or twisted code. |
7 """ | 7 """ |
8 | 8 |
9 import inspect | 9 import inspect |
10 import os | 10 import os |
(...skipping 28 matching lines...) Expand all Loading... |
39 print >> sys.stderr, e | 39 print >> sys.stderr, e |
40 for (symbol_name, symbol) in local_vars.iteritems(): | 40 for (symbol_name, symbol) in local_vars.iteritems(): |
41 if inspect.isclass(local_vars[symbol_name]): | 41 if inspect.isclass(local_vars[symbol_name]): |
42 setattr(config_bootstrap.Master, symbol_name, symbol) | 42 setattr(config_bootstrap.Master, symbol_name, symbol) |
43 # If we have a master_name and it matches, set | 43 # If we have a master_name and it matches, set |
44 # config_bootstrap.Master.active_master. | 44 # config_bootstrap.Master.active_master. |
45 if master_name and master_name == symbol_name: | 45 if master_name and master_name == symbol_name: |
46 setattr(config_bootstrap.Master, 'active_master', symbol) | 46 setattr(config_bootstrap.Master, 'active_master', symbol) |
47 | 47 |
48 | 48 |
49 def GetActiveMaster(slavename=None): | 49 def GetActiveMaster(slavename=None, default=None): |
50 """Parses all the slaves.cfg and returns the name of the active master | 50 """Parses all the slaves.cfg and returns the name of the active master |
51 determined by the host name. Returns None otherwise. | 51 determined by the host name. Returns None otherwise. |
52 | 52 |
53 If a slavename is given, it will be matched against *both* the 'slavename' | 53 If a slavename is given, it will be matched against *both* the 'slavename' |
54 and 'hostname' fields in slave.cfg. Otherwise, the machine's hostname will be | 54 and 'hostname' fields in slave.cfg. Otherwise, the machine's hostname will be |
55 matched against only the 'hostname' field. | 55 matched against only the 'hostname' field. |
56 """ | 56 """ |
57 if slavename is None: | 57 if slavename is None: |
58 config_keys = ['hostname'] | 58 config_keys = ['hostname'] |
59 config_val = socket.getfqdn().split('.', 1)[0].lower() | 59 config_val = socket.getfqdn().split('.', 1)[0].lower() |
60 else: | 60 else: |
61 config_keys = ['slavename', 'hostname'] | 61 config_keys = ['slavename', 'hostname'] |
62 config_val = slavename | 62 config_val = slavename |
63 for master in chromium_utils.ListMasters(): | 63 for master in chromium_utils.ListMasters(): |
64 path = os.path.join(master, 'slaves.cfg') | 64 path = os.path.join(master, 'slaves.cfg') |
65 if os.path.exists(path): | 65 if os.path.exists(path): |
66 for slave in chromium_utils.RunSlavesCfg(path): | 66 for slave in chromium_utils.RunSlavesCfg(path): |
67 for key in config_keys: | 67 for key in config_keys: |
68 if slave.get(key, None) == config_val: | 68 if slave.get(key, None) == config_val: |
69 return slave['master'] | 69 return slave['master'] |
| 70 return default |
OLD | NEW |