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): ...@@ -138,8 +138,7 @@ class Application(BaseApplication, Monitor):
def __init__(self, config): def __init__(self, config):
BaseApplication.__init__(self, BaseApplication.__init__(self,
config.get('ssl'), config.get('dynamic_master_list')) config.get('ssl'), config.get('dynamic_master_list'))
for address in config['masters']: self.nm.createMasters(config['masters'])
self.nm.createMaster(address=address)
self.name = config['cluster'] self.name = config['cluster']
self.server = config['bind'] self.server = config['bind']
......
...@@ -57,8 +57,9 @@ class BaseApplication(object): ...@@ -57,8 +57,9 @@ class BaseApplication(object):
_('s', 'section', default=section, _('s', 'section', default=section,
help='specify a configuration section') help='specify a configuration section')
_('c', 'cluster', required=True, help='the cluster name') _('c', 'cluster', required=True, help='the cluster name')
_('m', 'masters', default=masters, parse=util.parseMasterList, _('m', 'masters', parse=util.parseMasterList,
help='master node list') help='space-separated list of master node addresses',
**{'default': masters} if masters else {'type': lambda x: x or ''})
_('b', 'bind', default=bind, _('b', 'bind', default=bind,
parse=lambda x: util.parseNodeAddress(x, 0), parse=lambda x: util.parseNodeAddress(x, 0),
help='the local address to bind to') help='the local address to bind to')
......
...@@ -393,6 +393,12 @@ class NodeManager(EventQueue): ...@@ -393,6 +393,12 @@ class NodeManager(EventQueue):
raise NotReadyError('unknown by master') raise NotReadyError('unknown by master')
return node 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): def _createNode(self, klass, address=None, uuid=None, **kw):
by_address = self.getByAddress(address) by_address = self.getByAddress(address)
by_uuid = self.getByUUID(uuid) by_uuid = self.getByUUID(uuid)
......
...@@ -53,10 +53,7 @@ class ThreadedApplication(BaseApplication): ...@@ -53,10 +53,7 @@ class ThreadedApplication(BaseApplication):
self.name = name self.name = name
self.dispatcher = Dispatcher() self.dispatcher = Dispatcher()
self.master_conn = None self.master_conn = None
self.nm.createMasters(master_nodes)
# load master node list
for address in master_nodes:
self.nm.createMaster(address=address)
# Internal attribute distinct between thread # Internal attribute distinct between thread
self._thread_container = ThreadContainer() self._thread_container = ThreadContainer()
......
...@@ -158,7 +158,6 @@ def parseNodeAddress(address, port_opt=None): ...@@ -158,7 +158,6 @@ def parseNodeAddress(address, port_opt=None):
return socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0][4][:2] return socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0][4][:2]
def parseMasterList(masters): def parseMasterList(masters):
assert masters, 'At least one master must be defined'
return map(parseNodeAddress, masters.split()) return map(parseNodeAddress, masters.split())
......
...@@ -108,7 +108,7 @@ class Application(BaseApplication): ...@@ -108,7 +108,7 @@ class Application(BaseApplication):
self.storage_ready_dict = {} self.storage_ready_dict = {}
self.storage_starting_set = set() 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.nm.createMaster(address=master_address)
self._node = self.nm.createMaster(address=self.server, self._node = self.nm.createMaster(address=self.server,
uuid=config.get('nid')) uuid=config.get('nid'))
......
...@@ -72,8 +72,7 @@ class BackupApplication(object): ...@@ -72,8 +72,7 @@ class BackupApplication(object):
self.app = weakref.proxy(app) self.app = weakref.proxy(app)
self.name = name self.name = name
self.nm = NodeManager() self.nm = NodeManager()
for master_address in master_addresses: self.nm.createMasters(master_addresses)
self.nm.createMaster(address=master_address)
em = property(lambda self: self.app.em) em = property(lambda self: self.app.em)
ssl = property(lambda self: self.app.ssl) ssl = property(lambda self: self.app.ssl)
......
...@@ -98,10 +98,7 @@ class Application(BaseApplication): ...@@ -98,10 +98,7 @@ class Application(BaseApplication):
) )
self.disable_drop_partitions = config.get('disable_drop_partitions', self.disable_drop_partitions = config.get('disable_drop_partitions',
False) False)
self.nm.createMasters(config['masters'])
# load master nodes
for master_address in config['masters']:
self.nm.createMaster(address=master_address)
# set the bind address # set the bind address
self.server = config['bind'] self.server = config['bind']
......
...@@ -66,8 +66,7 @@ class StressApplication(AdminApplication): ...@@ -66,8 +66,7 @@ class StressApplication(AdminApplication):
def __init__(self, ssl, master_nodes): def __init__(self, ssl, master_nodes):
BaseApplication.__init__(self, ssl) BaseApplication.__init__(self, ssl)
for address in master_nodes: self.nm.createMasters(master_nodes)
self.nm.createMaster(address=address)
self.pt = None self.pt = None
self.master_event_handler = Handler(self) self.master_event_handler = Handler(self)
self.reset() 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