Commit 03ae3309 authored by Vincent Pelletier's avatar Vincent Pelletier

Add safeguards around --reset parameter.

Do not actually start storage node when told to reset database content.
Refuse to reset database content when non-required parameters are provided.
parent 6e2124a3
...@@ -65,6 +65,19 @@ def main(args=None): ...@@ -65,6 +65,19 @@ def main(args=None):
adapter = options.adapter, adapter = options.adapter,
wait = options.wait, wait = options.wait,
) )
if arguments['reset']:
# Forbid using "reset" along with any unneeded argument.
# "reset" is too dangerous to let user a chance of accidentally
# letting it slip through in a long option list.
forbidden = set(x for x, y in arguments.iteritems()
if y).difference((
'reset',
'adapter',
'database',
))
if forbidden:
raise ValueError('Cannot reset database when the following '
'parameters are also provided: ' + ' '.join(forbidden))
config = ConfigurationManager( config = ConfigurationManager(
defaults, defaults,
options.file, options.file,
......
...@@ -41,6 +41,19 @@ class Application(object): ...@@ -41,6 +41,19 @@ class Application(object):
"""The storage node application.""" """The storage node application."""
def __init__(self, config): def __init__(self, config):
self.dm = buildDatabaseManager(config.getAdapter(),
(config.getDatabase(), config.getWait())
)
reset = config.getReset()
self.dm.setup(reset=reset)
if reset:
# Abort ctor and prevent instance from running.
# This is done to prevent mistakes where user would use a storage
# started with reset option, and restart that storage later without
# dropping that option.
self.run = lambda: None
return
# set the cluster name # set the cluster name
self.name = config.getCluster() self.name = config.getCluster()
...@@ -48,10 +61,6 @@ class Application(object): ...@@ -48,10 +61,6 @@ class Application(object):
self.em = EventManager() self.em = EventManager()
self.nm = NodeManager(config.getDynamicMasterList()) self.nm = NodeManager(config.getDynamicMasterList())
self.tm = TransactionManager(self) self.tm = TransactionManager(self)
self.dm = buildDatabaseManager(config.getAdapter(),
(config.getDatabase(), config.getWait())
)
# load master nodes # load master nodes
master_addresses, connector_name = config.getMasters() master_addresses, connector_name = config.getMasters()
self.connector_handler = getConnectorHandler(connector_name) self.connector_handler = getConnectorHandler(connector_name)
...@@ -79,7 +88,6 @@ class Application(object): ...@@ -79,7 +88,6 @@ class Application(object):
# ready is True when operational and got all informations # ready is True when operational and got all informations
self.ready = False self.ready = False
self.dm.setup(reset=config.getReset())
self.loadConfiguration() self.loadConfiguration()
# force node uuid from command line argument, for testing purpose only # force node uuid from command line argument, for testing purpose only
......
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