Commit 16340bad authored by Vincent Pelletier's avatar Vincent Pelletier

Rewrite NodeManager.update main code.

- Don't trash a node to recreate it right after (it was the case when a
  node was known by address only).
- Check node type consistency between:
  - parameters and node found
  - node known by type and node known by UUID
- Log actions before doing them, consistently
- Log found node in addition to loop variables
- Don't call remove when an unknown node is notified as down, and add a
  log for this case

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2049 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 762da524
...@@ -439,24 +439,29 @@ class NodeManager(object): ...@@ -439,24 +439,29 @@ class NodeManager(object):
node = node_by_uuid or node_by_addr node = node_by_uuid or node_by_addr
log_args = (node_type, dump(uuid), addr, state) log_args = (node_type, dump(uuid), addr, state)
if state == NodeStates.DOWN: if node is None:
# drop down nodes if state == NodeStates.DOWN:
logging.debug('drop node %s %s %s %s' % log_args) logging.debug('NOT creating node %s %s %s %s', *log_args)
self.remove(node) else:
elif node_by_uuid is not None: logging.debug('creating node %s %s %s %s', *log_args)
if node.getAddress() != addr: self._createNode(klass, address=addr, uuid=uuid, state=state)
# address changed, update it
node.setAddress(addr)
logging.debug('update node %s %s %s %s' % log_args)
node.setState(state)
else: else:
if node_by_addr is not None: assert isinstance(node, klass), 'node %r is not ' \
# exists only by address, 'of expected type: %r' % (node, klass)
assert None in (node_by_uuid, node_by_addr) or \
node_by_uuid is node_by_addr, \
'Discrepancy between node_by_uuid (%r) and ' \
'node_by_addr (%r)' % (node_by_uuid, node_by_addr)
if state == NodeStates.DOWN:
logging.debug('droping node %r, found with %s %s %s %s',
node, *log_args)
self.remove(node) self.remove(node)
# don't exists, add it else:
node = klass(self, address=addr, uuid=uuid) logging.debug('updating node %r to %s %s %s %s',
node.setState(state) node, *log_args)
logging.debug('create node %s %s %s %s' % log_args) node.setUUID(uuid)
node.setAddress(addr)
node.setState(state)
self.log() self.log()
def log(self): def log(self):
......
...@@ -257,6 +257,7 @@ class NodeManagerTests(NeoTestBase): ...@@ -257,6 +257,7 @@ class NodeManagerTests(NeoTestBase):
# build changes # build changes
old_address = self.master.getAddress() old_address = self.master.getAddress()
new_address = ('127.0.0.1', 2001) new_address = ('127.0.0.1', 2001)
old_uuid = self.storage.getUUID()
new_uuid = self.getNewUUID() new_uuid = self.getNewUUID()
node_list = ( node_list = (
(NodeTypes.CLIENT, None, self.client.getUUID(), NodeStates.DOWN), (NodeTypes.CLIENT, None, self.client.getUUID(), NodeStates.DOWN),
...@@ -276,11 +277,11 @@ class NodeManagerTests(NeoTestBase): ...@@ -276,11 +277,11 @@ class NodeManagerTests(NeoTestBase):
self.master.setAddress(new_address) self.master.setAddress(new_address)
self.checkByServer(self.master) self.checkByServer(self.master)
# a new storage replaced the old one # a new storage replaced the old one
self.assertNotEqual(manager.getStorageList(), [self.storage]) storage_list = manager.getStorageList()
self.assertTrue(len(manager.getStorageList()), 1) self.assertTrue(len(storage_list), 1)
new_storage = manager.getStorageList()[0] new_storage = storage_list[0]
self.assertNotEqual(new_storage.getUUID(), old_uuid)
self.assertEqual(new_storage.getState(), NodeStates.RUNNING) self.assertEqual(new_storage.getState(), NodeStates.RUNNING)
self.assertNotEqual(new_storage, self.storage)
# admin is still here but in UNKNOWN state # admin is still here but in UNKNOWN state
self.checkNodes([self.master, self.admin, new_storage]) self.checkNodes([self.master, self.admin, new_storage])
self.assertEqual(self.admin.getState(), NodeStates.UNKNOWN) self.assertEqual(self.admin.getState(), NodeStates.UNKNOWN)
......
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