class MasterAppTests(NeoUnitTestBase): def setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration() self.app = Application(config) self.app.pt.clear() def _tearDown(self, success): self.app.close() NeoUnitTestBase._tearDown(self, success) def checkNotifyNodeInformation(self, conn): return self.checkNotifyPacket(conn, Packets.NotifyNodeInformation) def test_06_broadcastNodeInformation(self): # defined some nodes to which data will be send master_uuid = self.getMasterUUID() master = self.app.nm.createMaster(uuid=master_uuid) storage_uuid = self.getStorageUUID() storage = self.app.nm.createStorage(uuid=storage_uuid) client_uuid = self.getClientUUID() client = self.app.nm.createClient(uuid=client_uuid) # create conn and patch em master_conn = self.getFakeConnection() storage_conn = self.getFakeConnection(is_server=True) client_conn = self.getFakeConnection(is_server=True) master.setConnection(master_conn) storage.setConnection(storage_conn) client.setConnection(client_conn) self.app.nm.add(storage) self.app.nm.add(client) # no address defined, not send to client node c_node = self.app.nm.createClient(uuid=self.getClientUUID()) self.app.broadcastNodesInformation([c_node]) # check conn self.checkNoPacketSent(client_conn) self.checkNoPacketSent(master_conn) self.checkNotifyNodeInformation(storage_conn) # address defined and client type s_node = self.app.nm.createClient(uuid=self.getClientUUID(), address=("127.1.0.1", 3361)) self.app.broadcastNodesInformation([c_node]) # check conn self.checkNoPacketSent(client_conn) self.checkNoPacketSent(master_conn) self.checkNotifyNodeInformation(storage_conn) # address defined and storage type s_node = self.app.nm.createStorage(uuid=self.getStorageUUID(), address=("127.0.0.1", 1351)) self.app.broadcastNodesInformation([s_node]) # check conn self.checkNotifyNodeInformation(client_conn) self.checkNoPacketSent(master_conn) self.checkNotifyNodeInformation(storage_conn)
class MasterAppTests(NeoUnitTestBase): def setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration() self.app = Application(config) self.app.pt.clear() def _tearDown(self, success): self.app.close() NeoUnitTestBase._tearDown(self, success) def test_06_broadcastNodeInformation(self): # defined some nodes to which data will be send master_uuid = self.getMasterUUID() master = self.app.nm.createMaster(uuid=master_uuid) storage_uuid = self.getStorageUUID() storage = self.app.nm.createStorage(uuid=storage_uuid) client_uuid = self.getClientUUID() client = self.app.nm.createClient(uuid=client_uuid) # create conn and patch em master_conn = self.getFakeConnection() storage_conn = self.getFakeConnection() client_conn = self.getFakeConnection() master.setConnection(master_conn) storage.setConnection(storage_conn) client.setConnection(client_conn) master.setRunning() client.setRunning() storage.setRunning() self.app.nm.add(storage) self.app.nm.add(client) # no address defined, not send to client node c_node = self.app.nm.createClient(uuid=self.getClientUUID()) self.app.broadcastNodesInformation([c_node]) # check conn self.checkNoPacketSent(client_conn) self.checkNoPacketSent(master_conn) self.checkNotifyNodeInformation(storage_conn) # address defined and client type s_node = self.app.nm.createClient(uuid=self.getClientUUID(), address=("127.1.0.1", 3361)) self.app.broadcastNodesInformation([c_node]) # check conn self.checkNoPacketSent(client_conn) self.checkNoPacketSent(master_conn) self.checkNotifyNodeInformation(storage_conn) # address defined and storage type s_node = self.app.nm.createStorage(uuid=self.getStorageUUID(), address=("127.0.0.1", 1351)) self.app.broadcastNodesInformation([s_node]) # check conn self.checkNotifyNodeInformation(client_conn) self.checkNoPacketSent(master_conn) self.checkNotifyNodeInformation(storage_conn) # node not running, don't send informations client.setPending() self.app.broadcastNodesInformation([s_node]) # check conn self.assertFalse(client_conn.mockGetNamedCalls('notify')) self.checkNoPacketSent(master_conn) self.checkNotifyNodeInformation(storage_conn) def test_storageReadinessAPI(self): uuid_1 = self.getStorageUUID() uuid_2 = self.getStorageUUID() self.assertFalse(self.app.isStorageReady(uuid_1)) self.assertFalse(self.app.isStorageReady(uuid_2)) # Must not raise, nor change readiness self.app.setStorageNotReady(uuid_1) self.assertFalse(self.app.isStorageReady(uuid_1)) self.assertFalse(self.app.isStorageReady(uuid_2)) # Mark as ready, only one must change self.app.setStorageReady(uuid_1) self.assertTrue(self.app.isStorageReady(uuid_1)) self.assertFalse(self.app.isStorageReady(uuid_2)) self.app.setStorageReady(uuid_2) # Mark not ready, only one must change self.app.setStorageNotReady(uuid_1) self.assertFalse(self.app.isStorageReady(uuid_1)) self.assertTrue(self.app.isStorageReady(uuid_2))
class MasterRecoveryTests(NeoUnitTestBase): def setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration() self.app = Application(config) self.app.pt.clear() self.recovery = RecoveryManager(self.app) self.app.unconnected_master_node_set = set() self.app.negotiating_master_node_set = set() for node in self.app.nm.getMasterList(): self.app.unconnected_master_node_set.add(node.getAddress()) node.setState(NodeStates.RUNNING) # define some variable to simulate client and storage node self.client_port = 11022 self.storage_port = 10021 self.master_port = 10011 self.master_address = ('127.0.0.1', self.master_port) self.storage_address = ('127.0.0.1', self.storage_port) def _tearDown(self, success): self.app.close() NeoUnitTestBase._tearDown(self, success) # Common methods def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1", port=10021): """Do first step of identification to MN """ address = (ip, port) uuid = self.getNewUUID(node_type) self.app.nm.createFromNodeType(node_type, address=address, uuid=uuid, state=NodeStates.RUNNING) return uuid # Tests def test_01_connectionClosed(self): uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port) conn = self.getFakeConnection(uuid, self.master_address) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), NodeStates.RUNNING) self.recovery.connectionClosed(conn) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), NodeStates.TEMPORARILY_DOWN) def test_10_answerPartitionTable(self): recovery = self.recovery uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port) # not from target node, ignore uuid = self.identifyToMasterNode(NodeTypes.STORAGE, port=self.storage_port) conn = self.getFakeConnection(uuid, self.storage_port) node = self.app.nm.getByUUID(conn.getUUID()) offset = 1 cell_list = [(offset, uuid, CellStates.UP_TO_DATE)] cells = self.app.pt.getRow(offset) for cell, state in cells: self.assertEqual(state, CellStates.OUT_OF_DATE) recovery.target_ptid = 2 node.setPending() recovery.answerPartitionTable(conn, 1, cell_list) cells = self.app.pt.getRow(offset) for cell, state in cells: self.assertEqual(state, CellStates.OUT_OF_DATE) # from target node, taken into account conn = self.getFakeConnection(uuid, self.storage_port) offset = 1 cell_list = [(offset, ((uuid, CellStates.UP_TO_DATE,),),)] cells = self.app.pt.getRow(offset) for cell, state in cells: self.assertEqual(state, CellStates.OUT_OF_DATE) node.setPending() recovery.answerPartitionTable(conn, None, cell_list) cells = self.app.pt.getRow(offset) for cell, state in cells: self.assertEqual(state, CellStates.UP_TO_DATE) # give a bad offset, must send error self.recovery.target_uuid = uuid conn = self.getFakeConnection(uuid, self.storage_port) offset = 1000000 self.assertFalse(self.app.pt.hasOffset(offset)) cell_list = [(offset, ((uuid, NodeStates.DOWN,),),)] node.setPending() self.checkProtocolErrorRaised(recovery.answerPartitionTable, conn, 2, cell_list)
class MasterRecoveryTests(NeoUnitTestBase): def setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration() self.app = Application(config) self.app.pt.clear() self.recovery = RecoveryManager(self.app) self.app.unconnected_master_node_set = set() self.app.negotiating_master_node_set = set() for node in self.app.nm.getMasterList(): self.app.unconnected_master_node_set.add(node.getAddress()) node.setState(NodeStates.RUNNING) # define some variable to simulate client and storage node self.client_port = 11022 self.storage_port = 10021 self.master_port = 10011 self.master_address = ('127.0.0.1', self.master_port) self.storage_address = ('127.0.0.1', self.storage_port) def _tearDown(self, success): self.app.close() NeoUnitTestBase._tearDown(self, success) # Common methods def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1", port=10021): """Do first step of identification to MN """ address = (ip, port) uuid = self.getNewUUID(node_type) self.app.nm.createFromNodeType(node_type, address=address, uuid=uuid, state=NodeStates.RUNNING) return uuid # Tests def test_01_connectionClosed(self): uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port) conn = self.getFakeConnection(uuid, self.master_address) self.assertEqual( self.app.nm.getByAddress(conn.getAddress()).getState(), NodeStates.RUNNING) self.recovery.connectionClosed(conn) self.assertEqual( self.app.nm.getByAddress(conn.getAddress()).getState(), NodeStates.TEMPORARILY_DOWN) def test_10_answerPartitionTable(self): recovery = self.recovery uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port) # not from target node, ignore uuid = self.identifyToMasterNode(NodeTypes.STORAGE, port=self.storage_port) conn = self.getFakeConnection(uuid, self.storage_port) node = self.app.nm.getByUUID(conn.getUUID()) offset = 1 cell_list = [(offset, uuid, CellStates.UP_TO_DATE)] cells = self.app.pt.getRow(offset) for cell, state in cells: self.assertEqual(state, CellStates.OUT_OF_DATE) recovery.target_ptid = 2 node.setPending() recovery.answerPartitionTable(conn, 1, cell_list) cells = self.app.pt.getRow(offset) for cell, state in cells: self.assertEqual(state, CellStates.OUT_OF_DATE) # from target node, taken into account conn = self.getFakeConnection(uuid, self.storage_port) offset = 1 cell_list = [( offset, (( uuid, CellStates.UP_TO_DATE, ), ), )] cells = self.app.pt.getRow(offset) for cell, state in cells: self.assertEqual(state, CellStates.OUT_OF_DATE) node.setPending() recovery.answerPartitionTable(conn, None, cell_list) cells = self.app.pt.getRow(offset) for cell, state in cells: self.assertEqual(state, CellStates.UP_TO_DATE) # give a bad offset, must send error self.recovery.target_uuid = uuid conn = self.getFakeConnection(uuid, self.storage_port) offset = 1000000 self.assertFalse(self.app.pt.hasOffset(offset)) cell_list = [( offset, (( uuid, NodeStates.DOWN, ), ), )] node.setPending() self.checkProtocolErrorRaised(recovery.answerPartitionTable, conn, 2, cell_list)
class MasterAppTests(NeoUnitTestBase): def setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration() self.app = Application(config) self.app.pt.clear() def _tearDown(self, success): self.app.close() NeoUnitTestBase._tearDown(self, success) def test_06_broadcastNodeInformation(self): # defined some nodes to which data will be send master_uuid = self.getMasterUUID() master = self.app.nm.createMaster(uuid=master_uuid) storage_uuid = self.getStorageUUID() storage = self.app.nm.createStorage(uuid=storage_uuid) client_uuid = self.getClientUUID() client = self.app.nm.createClient(uuid=client_uuid) # create conn and patch em master_conn = self.getFakeConnection() storage_conn = self.getFakeConnection() client_conn = self.getFakeConnection() master.setConnection(master_conn) storage.setConnection(storage_conn) client.setConnection(client_conn) master.setRunning() client.setRunning() storage.setRunning() self.app.nm.add(storage) self.app.nm.add(client) # no address defined, not send to client node c_node = self.app.nm.createClient(uuid=self.getClientUUID()) self.app.broadcastNodesInformation([c_node]) # check conn self.checkNoPacketSent(client_conn) self.checkNoPacketSent(master_conn) self.checkNotifyNodeInformation(storage_conn) # address defined and client type s_node = self.app.nm.createClient( uuid=self.getClientUUID(), address=("127.1.0.1", 3361) ) self.app.broadcastNodesInformation([c_node]) # check conn self.checkNoPacketSent(client_conn) self.checkNoPacketSent(master_conn) self.checkNotifyNodeInformation(storage_conn) # address defined and storage type s_node = self.app.nm.createStorage( uuid=self.getStorageUUID(), address=("127.0.0.1", 1351) ) self.app.broadcastNodesInformation([s_node]) # check conn self.checkNotifyNodeInformation(client_conn) self.checkNoPacketSent(master_conn) self.checkNotifyNodeInformation(storage_conn) # node not running, don't send informations client.setPending() self.app.broadcastNodesInformation([s_node]) # check conn self.assertFalse(client_conn.mockGetNamedCalls('notify')) self.checkNoPacketSent(master_conn) self.checkNotifyNodeInformation(storage_conn) def test_storageReadinessAPI(self): uuid_1 = self.getStorageUUID() uuid_2 = self.getStorageUUID() self.assertFalse(self.app.isStorageReady(uuid_1)) self.assertFalse(self.app.isStorageReady(uuid_2)) # Must not raise, nor change readiness self.app.setStorageNotReady(uuid_1) self.assertFalse(self.app.isStorageReady(uuid_1)) self.assertFalse(self.app.isStorageReady(uuid_2)) # Mark as ready, only one must change self.app.setStorageReady(uuid_1) self.assertTrue(self.app.isStorageReady(uuid_1)) self.assertFalse(self.app.isStorageReady(uuid_2)) self.app.setStorageReady(uuid_2) # Mark not ready, only one must change self.app.setStorageNotReady(uuid_1) self.assertFalse(self.app.isStorageReady(uuid_1)) self.assertTrue(self.app.isStorageReady(uuid_2))
class MasterRecoveryTests(NeoUnitTestBase): def setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration() self.app = Application(config) self.app.pt.clear() self.recovery = RecoveryManager(self.app) self.app.unconnected_master_node_set = set() self.app.negotiating_master_node_set = set() for node in self.app.nm.getMasterList(): self.app.unconnected_master_node_set.add(node.getAddress()) node.setState(NodeStates.RUNNING) # define some variable to simulate client and storage node self.storage_port = 10021 self.master_port = 10011 def _tearDown(self, success): self.app.close() NeoUnitTestBase._tearDown(self, success) # Common methods def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1", port=10021): """Do first step of identification to MN """ address = (ip, port) uuid = self.getNewUUID(node_type) self.app.nm.createFromNodeType(node_type, address=address, uuid=uuid, state=NodeStates.RUNNING) return uuid # Tests def test_10_answerPartitionTable(self): # XXX: This test does much less that it seems, because all 'for' loops # iterate over empty lists. Currently, only testRecovery covers # some paths in NodeManager._createNode: apart from that, we could # delete it entirely. recovery = self.recovery uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port) # not from target node, ignore uuid = self.identifyToMasterNode(NodeTypes.STORAGE, port=self.storage_port) conn = self.getFakeConnection(uuid, self.storage_port) node = self.app.nm.getByUUID(conn.getUUID()) offset = 1 cell_list = [(offset, uuid, CellStates.UP_TO_DATE)] cells = self.app.pt.getRow(offset) for cell, state in cells: self.assertEqual(state, CellStates.OUT_OF_DATE) recovery.target_ptid = 2 node.setPending() recovery.answerPartitionTable(conn, 1, cell_list) cells = self.app.pt.getRow(offset) for cell, state in cells: self.assertEqual(state, CellStates.OUT_OF_DATE) # from target node, taken into account conn = self.getFakeConnection(uuid, self.storage_port) offset = 1 cell_list = [( offset, (( uuid, CellStates.UP_TO_DATE, ), ), )] cells = self.app.pt.getRow(offset) for cell, state in cells: self.assertEqual(state, CellStates.OUT_OF_DATE) node.setPending() recovery.answerPartitionTable(conn, None, cell_list) cells = self.app.pt.getRow(offset) for cell, state in cells: self.assertEqual(state, CellStates.UP_TO_DATE) # give a bad offset, must send error self.recovery.target_uuid = uuid conn = self.getFakeConnection(uuid, self.storage_port) offset = 1000000 self.assertFalse(self.app.pt.hasOffset(offset)) cell_list = [( offset, (( uuid, NodeStates.UNKNOWN, ), ), )] node.setPending() self.checkProtocolErrorRaised(recovery.answerPartitionTable, conn, 2, cell_list)