Commit 7ab14ef7 authored by Vincent Pelletier's avatar Vincent Pelletier

Automatically set UUID on connection when setting it on node.

parent 88d76044
...@@ -43,9 +43,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -43,9 +43,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
app.uuid = your_uuid app.uuid = your_uuid
neo.lib.logging.info('Got an UUID: %s', dump(app.uuid)) neo.lib.logging.info('Got an UUID: %s', dump(app.uuid))
node = app.nm.getByAddress(conn.getAddress()) app.nm.getByAddress(conn.getAddress()).setUUID(uuid)
conn.setUUID(uuid)
node.setUUID(uuid)
# Always create partition table # Always create partition table
app.pt = PartitionTable(num_partitions, num_replicas) app.pt = PartitionTable(num_partitions, num_replicas)
......
...@@ -57,7 +57,6 @@ class StorageBootstrapHandler(AnswerBaseHandler): ...@@ -57,7 +57,6 @@ class StorageBootstrapHandler(AnswerBaseHandler):
node = self.app.nm.getByAddress(conn.getAddress()) node = self.app.nm.getByAddress(conn.getAddress())
assert node is not None, conn.getAddress() assert node is not None, conn.getAddress()
conn.setUUID(uuid)
node.setUUID(uuid) node.setUUID(uuid)
assert node.getConnection() is conn, (node.getConnection(), conn) assert node.getConnection() is conn, (node.getConnection(), conn)
......
...@@ -119,7 +119,6 @@ class BootstrapManager(EventHandler): ...@@ -119,7 +119,6 @@ class BootstrapManager(EventHandler):
# got an uuid from the primary master # got an uuid from the primary master
self.uuid = your_uuid self.uuid = your_uuid
neo.lib.logging.info('Got a new UUID : %s' % dump(self.uuid)) neo.lib.logging.info('Got a new UUID : %s' % dump(self.uuid))
conn.setUUID(uuid)
self.accepted = True self.accepted = True
def getPrimaryConnection(self, connector_handler): def getPrimaryConnection(self, connector_handler):
......
...@@ -86,6 +86,8 @@ class Node(object): ...@@ -86,6 +86,8 @@ class Node(object):
self._uuid = uuid self._uuid = uuid
self._manager._updateUUID(self, old_uuid) self._manager._updateUUID(self, old_uuid)
self._manager._updateIdentified(self) self._manager._updateIdentified(self)
if self._connection is not None:
self._connection.setUUID(uuid)
def getUUID(self): def getUUID(self):
return self._uuid return self._uuid
...@@ -104,6 +106,8 @@ class Node(object): ...@@ -104,6 +106,8 @@ class Node(object):
""" """
assert connection is not None assert connection is not None
assert self._connection is None, attributeTracker.whoSet(self, '_connection') assert self._connection is None, attributeTracker.whoSet(self, '_connection')
assert connection.getUUID() in (None, self._uuid), connection
connection.setUUID(self._uuid)
self._connection = connection self._connection = connection
connection.setOnClose(self.onConnectionClosed) connection.setOnClose(self.onConnectionClosed)
self._manager._updateIdentified(self) self._manager._updateIdentified(self)
......
...@@ -59,7 +59,6 @@ class IdentificationHandler(MasterHandler): ...@@ -59,7 +59,6 @@ class IdentificationHandler(MasterHandler):
node.setState(state) node.setState(state)
node.setConnection(conn) node.setConnection(conn)
# set up the connection # set up the connection
conn.setUUID(uuid)
conn.setHandler(handler) conn.setHandler(handler)
# answer # answer
args = (NodeTypes.MASTER, app.uuid, app.pt.getPartitions(), args = (NodeTypes.MASTER, app.uuid, app.pt.getPartitions(),
......
...@@ -94,8 +94,6 @@ class ReplicationHandler(EventHandler): ...@@ -94,8 +94,6 @@ class ReplicationHandler(EventHandler):
def acceptIdentification(self, conn, node_type, def acceptIdentification(self, conn, node_type,
uuid, num_partitions, num_replicas, your_uuid): uuid, num_partitions, num_replicas, your_uuid):
# set the UUID on the connection
conn.setUUID(uuid)
self.startReplication(conn) self.startReplication(conn)
def startReplication(self, conn): def startReplication(self, conn):
......
...@@ -78,7 +78,6 @@ class MasterBootstrapHandlerTests(MasterHandlerTests): ...@@ -78,7 +78,6 @@ class MasterBootstrapHandlerTests(MasterHandlerTests):
self.handler.acceptIdentification(conn, NodeTypes.MASTER, uuid, self.handler.acceptIdentification(conn, NodeTypes.MASTER, uuid,
partitions, replicas, your_uuid) partitions, replicas, your_uuid)
self.assertEqual(self.app.uuid, your_uuid) self.assertEqual(self.app.uuid, your_uuid)
self.checkUUIDSet(conn, uuid)
self.checkUUIDSet(node, uuid) self.checkUUIDSet(node, uuid)
self.assertTrue(isinstance(self.app.pt, PartitionTable)) self.assertTrue(isinstance(self.app.pt, PartitionTable))
......
...@@ -62,7 +62,6 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase): ...@@ -62,7 +62,6 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase):
self.handler.acceptIdentification(conn, NodeTypes.STORAGE, uuid, self.handler.acceptIdentification(conn, NodeTypes.STORAGE, uuid,
10, 0, None) 10, 0, None)
self.checkUUIDSet(node, uuid) self.checkUUIDSet(node, uuid)
self.checkUUIDSet(conn, uuid)
class StorageAnswerHandlerTests(NeoUnitTestBase): class StorageAnswerHandlerTests(NeoUnitTestBase):
......
...@@ -89,7 +89,6 @@ class StorageIdentificationHandlerTests(NeoUnitTestBase): ...@@ -89,7 +89,6 @@ class StorageIdentificationHandlerTests(NeoUnitTestBase):
self.assertTrue(node.isConnected()) self.assertTrue(node.isConnected())
self.assertEqual(node.getUUID(), uuid) self.assertEqual(node.getUUID(), uuid)
self.assertTrue(node.getConnection() is conn) self.assertTrue(node.getConnection() is conn)
self.checkUUIDSet(conn, uuid)
args = self.checkAcceptIdentification(conn, decode=True) args = self.checkAcceptIdentification(conn, decode=True)
node_type, address, _np, _nr, _uuid = args node_type, address, _np, _nr, _uuid = args
self.assertEqual(node_type, NodeTypes.STORAGE) self.assertEqual(node_type, NodeTypes.STORAGE)
......
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