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):
node = node_by_uuid or node_by_addr
log_args = (node_type, dump(uuid), addr, state)
if state == NodeStates.DOWN:
# drop down nodes
logging.debug('drop node %s %s %s %s' % log_args)
self.remove(node)
elif node_by_uuid is not None:
if node.getAddress() != addr:
# address changed, update it
node.setAddress(addr)
logging.debug('update node %s %s %s %s' % log_args)
node.setState(state)
if node is None:
if state == NodeStates.DOWN:
logging.debug('NOT creating node %s %s %s %s', *log_args)
else:
logging.debug('creating node %s %s %s %s', *log_args)
self._createNode(klass, address=addr, uuid=uuid, state=state)
else:
if node_by_addr is not None:
# exists only by address,
assert isinstance(node, klass), 'node %r is not ' \
'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)
# don't exists, add it
node = klass(self, address=addr, uuid=uuid)
node.setState(state)
logging.debug('create node %s %s %s %s' % log_args)
else:
logging.debug('updating node %r to %s %s %s %s',
node, *log_args)
node.setUUID(uuid)
node.setAddress(addr)
node.setState(state)
self.log()
def log(self):
......
......@@ -257,6 +257,7 @@ class NodeManagerTests(NeoTestBase):
# build changes
old_address = self.master.getAddress()
new_address = ('127.0.0.1', 2001)
old_uuid = self.storage.getUUID()
new_uuid = self.getNewUUID()
node_list = (
(NodeTypes.CLIENT, None, self.client.getUUID(), NodeStates.DOWN),
......@@ -276,11 +277,11 @@ class NodeManagerTests(NeoTestBase):
self.master.setAddress(new_address)
self.checkByServer(self.master)
# a new storage replaced the old one
self.assertNotEqual(manager.getStorageList(), [self.storage])
self.assertTrue(len(manager.getStorageList()), 1)
new_storage = manager.getStorageList()[0]
storage_list = manager.getStorageList()
self.assertTrue(len(storage_list), 1)
new_storage = storage_list[0]
self.assertNotEqual(new_storage.getUUID(), old_uuid)
self.assertEqual(new_storage.getState(), NodeStates.RUNNING)
self.assertNotEqual(new_storage, self.storage)
# admin is still here but in UNKNOWN state
self.checkNodes([self.master, self.admin, new_storage])
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