Commit bbaa9a63 authored by Vincent Pelletier's avatar Vincent Pelletier

Make node register itself to node manager.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2046 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent ca861ad6
...@@ -34,6 +34,7 @@ class Node(object): ...@@ -34,6 +34,7 @@ class Node(object):
self._manager = manager self._manager = manager
self._last_state_change = time() self._last_state_change = time()
self._connection = None self._connection = None
manager.add(self)
def notify(self, packet): def notify(self, packet):
assert self.isConnected(), 'Not connected' assert self.isConnected(), 'Not connected'
...@@ -388,9 +389,7 @@ class NodeManager(object): ...@@ -388,9 +389,7 @@ class NodeManager(object):
return uuid in self._uuid_dict return uuid in self._uuid_dict
def _createNode(self, klass, **kw): def _createNode(self, klass, **kw):
node = klass(self, **kw) return klass(self, **kw)
self.add(node)
return node
def createMaster(self, **kw): def createMaster(self, **kw):
""" Create and register a new master """ """ Create and register a new master """
...@@ -452,7 +451,6 @@ class NodeManager(object): ...@@ -452,7 +451,6 @@ class NodeManager(object):
raise RuntimeError('Unknown node type') raise RuntimeError('Unknown node type')
node = klass(self, address=addr, uuid=uuid) node = klass(self, address=addr, uuid=uuid)
node.setState(state) node.setState(state)
self.add(node)
logging.debug('create node %s %s %s %s' % log_args) logging.debug('create node %s %s %s %s' % log_args)
self.log() self.log()
......
...@@ -125,11 +125,19 @@ class NodesTests(NeoTestBase): ...@@ -125,11 +125,19 @@ class NodesTests(NeoTestBase):
class NodeManagerTests(NeoTestBase): class NodeManagerTests(NeoTestBase):
def setUp(self): def setUp(self):
self.manager = nm = NodeManager() self.manager = NodeManager()
self.storage = StorageNode(nm, ('127.0.0.1', 1000), self.getNewUUID())
self.master = MasterNode(nm, ('127.0.0.1', 2000), self.getNewUUID()) def _addStorage(self):
self.client = ClientNode(nm, None, self.getNewUUID()) self.storage = StorageNode(self.manager, ('127.0.0.1', 1000), self.getNewUUID())
self.admin = AdminNode(nm, ('127.0.0.1', 4000), self.getNewUUID())
def _addMaster(self):
self.master = MasterNode(self.manager, ('127.0.0.1', 2000), self.getNewUUID())
def _addClient(self):
self.client = ClientNode(self.manager, None, self.getNewUUID())
def _addAdmin(self):
self.admin = AdminNode(self.manager, ('127.0.0.1', 4000), self.getNewUUID())
def checkNodes(self, node_list): def checkNodes(self, node_list):
manager = self.manager manager = self.manager
...@@ -178,7 +186,7 @@ class NodeManagerTests(NeoTestBase): ...@@ -178,7 +186,7 @@ class NodeManagerTests(NeoTestBase):
manager = self.manager manager = self.manager
self.checkNodes([]) self.checkNodes([])
# storage # storage
manager.add(self.storage) self._addStorage()
self.checkNodes([self.storage]) self.checkNodes([self.storage])
self.checkStorages([self.storage]) self.checkStorages([self.storage])
self.checkMasters([]) self.checkMasters([])
...@@ -186,7 +194,7 @@ class NodeManagerTests(NeoTestBase): ...@@ -186,7 +194,7 @@ class NodeManagerTests(NeoTestBase):
self.checkByServer(self.storage) self.checkByServer(self.storage)
self.checkByUUID(self.storage) self.checkByUUID(self.storage)
# master # master
manager.add(self.master) self._addMaster()
self.checkNodes([self.storage, self.master]) self.checkNodes([self.storage, self.master])
self.checkStorages([self.storage]) self.checkStorages([self.storage])
self.checkMasters([self.master]) self.checkMasters([self.master])
...@@ -194,7 +202,7 @@ class NodeManagerTests(NeoTestBase): ...@@ -194,7 +202,7 @@ class NodeManagerTests(NeoTestBase):
self.checkByServer(self.master) self.checkByServer(self.master)
self.checkByUUID(self.master) self.checkByUUID(self.master)
# client # client
manager.add(self.client) self._addClient()
self.checkNodes([self.storage, self.master, self.client]) self.checkNodes([self.storage, self.master, self.client])
self.checkStorages([self.storage]) self.checkStorages([self.storage])
self.checkMasters([self.master]) self.checkMasters([self.master])
...@@ -203,7 +211,7 @@ class NodeManagerTests(NeoTestBase): ...@@ -203,7 +211,7 @@ class NodeManagerTests(NeoTestBase):
self.assertEqual(manager.getByAddress(self.client.getAddress()), None) self.assertEqual(manager.getByAddress(self.client.getAddress()), None)
self.checkByUUID(self.client) self.checkByUUID(self.client)
# admin # admin
manager.add(self.admin) self._addAdmin()
self.checkNodes([self.storage, self.master, self.client, self.admin]) self.checkNodes([self.storage, self.master, self.client, self.admin])
self.checkStorages([self.storage]) self.checkStorages([self.storage])
self.checkMasters([self.master]) self.checkMasters([self.master])
...@@ -218,17 +226,17 @@ class NodeManagerTests(NeoTestBase): ...@@ -218,17 +226,17 @@ class NodeManagerTests(NeoTestBase):
self.checkStorages([]) self.checkStorages([])
self.checkMasters([]) self.checkMasters([])
self.checkClients([]) self.checkClients([])
manager.add(self.master) self._addMaster()
self.checkMasters([self.master]) self.checkMasters([self.master])
manager.init() manager.init()
self.checkNodes([]) self.checkNodes([])
self.checkMasters([]) self.checkMasters([])
manager.add(self.storage) self._addStorage()
self.checkStorages([self.storage]) self.checkStorages([self.storage])
manager.init() manager.init()
self.checkNodes([]) self.checkNodes([])
self.checkStorages([]) self.checkStorages([])
manager.add(self.client) self._addClient()
self.checkClients([self.client]) self.checkClients([self.client])
manager.init() manager.init()
self.checkNodes([]) self.checkNodes([])
...@@ -238,10 +246,10 @@ class NodeManagerTests(NeoTestBase): ...@@ -238,10 +246,10 @@ class NodeManagerTests(NeoTestBase):
""" Check manager content update """ """ Check manager content update """
# set up four nodes # set up four nodes
manager = self.manager manager = self.manager
manager.add(self.master) self._addMaster()
manager.add(self.storage) self._addStorage()
manager.add(self.client) self._addClient()
manager.add(self.admin) self._addAdmin()
self.checkNodes([self.master, self.storage, self.client, self.admin]) self.checkNodes([self.master, self.storage, self.client, self.admin])
self.checkMasters([self.master]) self.checkMasters([self.master])
self.checkStorages([self.storage]) self.checkStorages([self.storage])
...@@ -280,10 +288,10 @@ class NodeManagerTests(NeoTestBase): ...@@ -280,10 +288,10 @@ class NodeManagerTests(NeoTestBase):
def testIdentified(self): def testIdentified(self):
# set up four nodes # set up four nodes
manager = self.manager manager = self.manager
manager.add(self.master) self._addMaster()
manager.add(self.storage) self._addStorage()
manager.add(self.client) self._addClient()
manager.add(self.admin) self._addAdmin()
# switch node to connected # switch node to connected
self.checkIdentified([]) self.checkIdentified([])
self.master.setConnection(Mock()) self.master.setConnection(Mock())
......
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