Commit dfa346a6 authored by Julien Muchembled's avatar Julien Muchembled

qa: in threaded tests, nodes can now be reset with a different configuration

parent f2f44cd5
...@@ -268,6 +268,10 @@ class TestSerialized(Serialized): ...@@ -268,6 +268,10 @@ class TestSerialized(Serialized):
class Node(object): class Node(object):
@staticmethod
def convertInitArgs(**kw):
return {'get' + k.capitalize(): v for k, v in kw.iteritems()}
def getConnectionList(self, *peers): def getConnectionList(self, *peers):
addr = lambda c: c and (c.addr if c.is_server else c.getAddress()) addr = lambda c: c and (c.addr if c.is_server else c.getAddress())
addr_set = {addr(c.connector) for peer in peers addr_set = {addr(c.connector) for peer in peers
...@@ -338,11 +342,15 @@ class ServerNode(Node): ...@@ -338,11 +342,15 @@ class ServerNode(Node):
def getVirtualAddress(self): def getVirtualAddress(self):
return self._init_args['address'] return self._init_args['address']
def resetNode(self): def resetNode(self, **kw):
assert not self.is_alive() assert not self.is_alive()
kw = self._init_args kw = self.convertInitArgs(**kw)
init_args = self._init_args
init_args['getReset'] = False
assert set(kw).issubset(init_args), (kw, init_args)
init_args.update(kw)
self.close() self.close()
self.__init__(**kw) self.__init__(**init_args)
def start(self): def start(self):
Serialized(self) Serialized(self)
...@@ -382,10 +390,6 @@ class StorageApplication(ServerNode, neo.storage.app.Application): ...@@ -382,10 +390,6 @@ class StorageApplication(ServerNode, neo.storage.app.Application):
dm = type('', (), {'close': lambda self: None})() dm = type('', (), {'close': lambda self: None})()
def resetNode(self, clear_database=False):
self._init_args['getReset'] = clear_database
super(StorageApplication, self).resetNode()
def _afterRun(self): def _afterRun(self):
super(StorageApplication, self)._afterRun() super(StorageApplication, self)._afterRun()
try: try:
...@@ -651,10 +655,10 @@ class NEOCluster(object): ...@@ -651,10 +655,10 @@ class NEOCluster(object):
master_list = [MasterApplication.newAddress() master_list = [MasterApplication.newAddress()
for _ in xrange(master_count)] for _ in xrange(master_count)]
self.master_nodes = ' '.join('%s:%s' % x for x in master_list) self.master_nodes = ' '.join('%s:%s' % x for x in master_list)
weak_self = weakref.proxy(self) kw = Node.convertInitArgs(replicas=replicas, adapter=adapter,
kw = dict(cluster=weak_self, getReplicas=replicas, getAdapter=adapter, partitions=partitions, reset=clear_databases)
getPartitions=partitions, getReset=clear_databases, kw['cluster'] = weak_self = weakref.proxy(self)
getSSL=self.SSL) kw['getSSL'] = self.SSL
if upstream is not None: if upstream is not None:
self.upstream = weakref.proxy(upstream) self.upstream = weakref.proxy(upstream)
kw.update(getUpstreamCluster=upstream.name, kw.update(getUpstreamCluster=upstream.name,
...@@ -758,7 +762,7 @@ class NEOCluster(object): ...@@ -758,7 +762,7 @@ class NEOCluster(object):
assert state in (ClusterStates.RUNNING, ClusterStates.BACKINGUP), state assert state in (ClusterStates.RUNNING, ClusterStates.BACKINGUP), state
self.enableStorageList(storage_list) self.enableStorageList(storage_list)
def stop(self, clear_database=False, __print_exc=traceback.print_exc): def stop(self, clear_database=False, __print_exc=traceback.print_exc, **kw):
if self.started: if self.started:
del self.started del self.started
logging.debug("stopping %s", self) logging.debug("stopping %s", self)
...@@ -786,11 +790,11 @@ class NEOCluster(object): ...@@ -786,11 +790,11 @@ class NEOCluster(object):
raise raise
else: else:
for node_type in 'master', 'storage', 'admin': for node_type in 'master', 'storage', 'admin':
kw = {} reset_kw = kw.copy()
if node_type == 'storage': if node_type == 'storage':
kw['clear_database'] = clear_database reset_kw['reset'] = clear_database
for node in getattr(self, node_type + '_list'): for node in getattr(self, node_type + '_list'):
node.resetNode(**kw) node.resetNode(**reset_kw)
def _newClient(self): def _newClient(self):
return ClientApplication(name=self.name, master_nodes=self.master_nodes, return ClientApplication(name=self.name, master_nodes=self.master_nodes,
......
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