Commit fa63d856 authored by Julien Muchembled's avatar Julien Muchembled

Fix handling of -m/--masters arg

For the master, the purpose of -m/--masters is to specify addresses
of other master nodes, since its own address is already known via
-b/--bind. Therefore, an empty value for -m/--masters is valid.
The user remains free to repeat the -b value in -m.

More generally, a node may choose to only specify master addresses
via -D/--dynamic-master-list, so the check that at least one master
address is specified is moved where the NodeManager is expected to be
initialized.
parent c34d332f
......@@ -138,8 +138,7 @@ class Application(BaseApplication, Monitor):
def __init__(self, config):
BaseApplication.__init__(self,
config.get('ssl'), config.get('dynamic_master_list'))
for address in config['masters']:
self.nm.createMaster(address=address)
self.nm.createMasters(config['masters'])
self.name = config['cluster']
self.server = config['bind']
......
......@@ -57,8 +57,9 @@ class BaseApplication(object):
_('s', 'section', default=section,
help='specify a configuration section')
_('c', 'cluster', required=True, help='the cluster name')
_('m', 'masters', default=masters, parse=util.parseMasterList,
help='master node list')
_('m', 'masters', parse=util.parseMasterList,
help='space-separated list of master node addresses',
**{'default': masters} if masters else {'type': lambda x: x or ''})
_('b', 'bind', default=bind,
parse=lambda x: util.parseNodeAddress(x, 0),
help='the local address to bind to')
......
......@@ -393,6 +393,12 @@ class NodeManager(EventQueue):
raise NotReadyError('unknown by master')
return node
def createMasters(self, master_nodes):
for address in master_nodes:
self.createMaster(address=address)
if not self.getMasterList():
raise ValueError("At least one master must be defined")
def _createNode(self, klass, address=None, uuid=None, **kw):
by_address = self.getByAddress(address)
by_uuid = self.getByUUID(uuid)
......
......@@ -53,10 +53,7 @@ class ThreadedApplication(BaseApplication):
self.name = name
self.dispatcher = Dispatcher()
self.master_conn = None
# load master node list
for address in master_nodes:
self.nm.createMaster(address=address)
self.nm.createMasters(master_nodes)
# Internal attribute distinct between thread
self._thread_container = ThreadContainer()
......
......@@ -158,7 +158,6 @@ def parseNodeAddress(address, port_opt=None):
return socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0][4][:2]
def parseMasterList(masters):
assert masters, 'At least one master must be defined'
return map(parseNodeAddress, masters.split())
......
......@@ -108,7 +108,7 @@ class Application(BaseApplication):
self.storage_ready_dict = {}
self.storage_starting_set = set()
for master_address in config['masters']:
for master_address in config.get('masters', ()):
self.nm.createMaster(address=master_address)
self._node = self.nm.createMaster(address=self.server,
uuid=config.get('nid'))
......
......@@ -72,8 +72,7 @@ class BackupApplication(object):
self.app = weakref.proxy(app)
self.name = name
self.nm = NodeManager()
for master_address in master_addresses:
self.nm.createMaster(address=master_address)
self.nm.createMasters(master_addresses)
em = property(lambda self: self.app.em)
ssl = property(lambda self: self.app.ssl)
......
......@@ -98,10 +98,7 @@ class Application(BaseApplication):
)
self.disable_drop_partitions = config.get('disable_drop_partitions',
False)
# load master nodes
for master_address in config['masters']:
self.nm.createMaster(address=master_address)
self.nm.createMasters(config['masters'])
# set the bind address
self.server = config['bind']
......
......@@ -66,8 +66,7 @@ class StressApplication(AdminApplication):
def __init__(self, ssl, master_nodes):
BaseApplication.__init__(self, ssl)
for address in master_nodes:
self.nm.createMaster(address=address)
self.nm.createMasters(master_nodes)
self.pt = None
self.master_event_handler = Handler(self)
self.reset()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment