def setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration(master_number=1, replicas=1) self.app = Application(config) self.app.em.close() self.app.pt.clear() self.app.pt.setID(1) self.app.em = Mock() self.app.loid = '\0' * 8 self.app.tm.setLastTID('\0' * 8) self.service = ClientServiceHandler(self.app) # define some variable to simulate client and storage node self.client_port = 11022 self.storage_port = 10021 self.master_port = 10010 self.master_address = ('127.0.0.1', self.master_port) self.client_address = ('127.0.0.1', self.client_port) self.storage_address = ('127.0.0.1', self.storage_port) self.storage_uuid = self.getStorageUUID() # register the storage self.app.nm.createStorage( uuid=self.storage_uuid, address=self.storage_address, )
def main(args=None): from neo.master.app import Application config = Application.option_parser.parse(args) # setup custom logging logging.setup(config.get('logfile')) # and then, load and run the application app = Application(config) app.run()
def main(args=None): # build configuration dict from command line options (options, args) = parser.parse_args(args=args) config = ConfigurationManager(defaults, options, 'master') # setup custom logging logging.setup(config.getLogfile()) # and then, load and run the application from neo.master.app import Application app = Application(config) app.run()
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)
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 setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration(master_number=1, replicas=1) self.app = Application(config) self.app.em.close() self.app.em = Mock() self.service = StorageServiceHandler(self.app)
def setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration(master_number=1, replicas=1) self.app = Application(config) self.app.em.close() self.app.pt.clear() self.app.em = Mock() self.service = StorageServiceHandler(self.app) self.client_handler = ClientServiceHandler(self.app) # define some variable to simulate client and storage node self.client_port = 11022 self.storage_port = 10021 self.master_port = 10010 self.master_address = ('127.0.0.1', self.master_port) self.client_address = ('127.0.0.1', self.client_port) self.storage_address = ('127.0.0.1', self.storage_port)
def setUp(self): super(MasterClientElectionTests, self).setUp() # create an application object config = self.getMasterConfiguration(master_number=1) self.app = Application(config) self.app.em.close() self.app.pt.clear() self.app.em = Mock() self.app.uuid = self.getMasterUUID() self.app.server = (self.local_ip, 10000) self.app.name = 'NEOCLUSTER' self.election = ClientElectionHandler(self.app) self.app.unconnected_master_node_set = set() self.app.negotiating_master_node_set = set() # apply monkey patches ClientConnection._addPacket = _addPacket
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 setUp(self): super(MasterServerElectionTests, self).setUp() # create an application object config = self.getMasterConfiguration(master_number=1) self.app = Application(config) self.app.em.close() self.app.pt.clear() self.app.name = 'NEOCLUSTER' self.app.em = Mock() self.election = ServerElectionHandler(self.app) self.app.unconnected_master_node_set = set() self.app.negotiating_master_node_set = set() for node in self.app.nm.getMasterList(): node.setState(NodeStates.RUNNING) # define some variable to simulate client and storage node self.client_address = (self.local_ip, 1000) self.storage_address = (self.local_ip, 2000) self.master_address = (self.local_ip, 3000) # apply monkey patches ClientConnection._addPacket = _addPacket
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 MasterClientHandlerTests(NeoUnitTestBase): def setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration(master_number=1, replicas=1) self.app = Application(config) self.app.em.close() self.app.pt.clear() self.app.pt.setID(1) self.app.em = Mock() self.app.loid = '\0' * 8 self.app.tm.setLastTID('\0' * 8) self.service = ClientServiceHandler(self.app) # define some variable to simulate client and storage node self.client_port = 11022 self.storage_port = 10021 self.master_port = 10010 self.master_address = ('127.0.0.1', self.master_port) self.client_address = ('127.0.0.1', self.client_port) self.storage_address = ('127.0.0.1', self.storage_port) self.storage_uuid = self.getStorageUUID() # register the storage self.app.nm.createStorage( uuid=self.storage_uuid, address=self.storage_address, ) def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1", port=10021): """Do first step of identification to MN """ # register the master itself uuid = self.getNewUUID(node_type) self.app.nm.createFromNodeType( node_type, address=(ip, port), uuid=uuid, state=NodeStates.RUNNING, ) return uuid # Tests def test_07_askBeginTransaction(self): tid1 = self.getNextTID() tid2 = self.getNextTID() service = self.service tm_org = self.app.tm self.app.tm = tm = Mock({ 'begin': '\x00\x00\x00\x00\x00\x00\x00\x01', }) # client call it client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) client_node = self.app.nm.getByUUID(client_uuid) conn = self.getFakeConnection(client_uuid, self.client_address) service.askBeginTransaction(conn, None) calls = tm.mockGetNamedCalls('begin') self.assertEqual(len(calls), 1) calls[0].checkArgs(client_node, None) self.checkAnswerBeginTransaction(conn) # Client asks for a TID conn = self.getFakeConnection(client_uuid, self.client_address) self.app.tm = tm_org service.askBeginTransaction(conn, tid1) calls = tm.mockGetNamedCalls('begin') self.assertEqual(len(calls), 1) calls[0].checkArgs(client_node, None) args = self.checkAnswerBeginTransaction(conn, decode=True) self.assertEqual(args, (tid1, )) def test_08_askNewOIDs(self): service = self.service oid1, oid2 = self.getOID(1), self.getOID(2) self.app.tm.setLastOID(oid1) # client call it client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) conn = self.getFakeConnection(client_uuid, self.client_address) for node in self.app.nm.getStorageList(): conn = self.getFakeConnection(node.getUUID(), node.getAddress()) node.setConnection(conn) service.askNewOIDs(conn, 1) self.assertTrue(self.app.tm.getLastOID() > oid1) def test_09_askFinishTransaction(self): service = self.service # do the right job client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) storage_uuid = self.storage_uuid storage_conn = self.getFakeConnection(storage_uuid, self.storage_address) storage2_uuid = self.identifyToMasterNode(port=10022) storage2_conn = self.getFakeConnection( storage2_uuid, (self.storage_address[0], self.storage_address[1] + 1)) self.app.setStorageReady(storage2_uuid) conn = self.getFakeConnection(client_uuid, self.client_address) self.app.pt = Mock({ 'getPartition': 0, 'getCellList': [ Mock({'getUUID': storage_uuid}), Mock({'getUUID': storage2_uuid}), ], 'getPartitions': 2, }) ttid = self.getNextTID() service.askBeginTransaction(conn, ttid) conn = self.getFakeConnection(client_uuid, self.client_address) self.app.nm.getByUUID(storage_uuid).setConnection(storage_conn) # No packet sent if storage node is not ready self.assertFalse(self.app.isStorageReady(storage_uuid)) service.askFinishTransaction(conn, ttid, (), ()) self.checkNoPacketSent(storage_conn) # ...but AskLockInformation is sent if it is ready self.app.setStorageReady(storage_uuid) self.assertTrue(self.app.isStorageReady(storage_uuid)) service.askFinishTransaction(conn, ttid, (), ()) self.checkAskLockInformation(storage_conn) self.assertEqual( len(self.app.tm.registerForNotification(storage_uuid)), 1) txn = self.app.tm[ttid] pending_ttid = list( self.app.tm.registerForNotification(storage_uuid))[0] self.assertEqual(ttid, pending_ttid) self.assertEqual(len(txn.getOIDList()), 0) self.assertEqual(len(txn.getUUIDList()), 1) def test_askNodeInformations(self): # check that only informations about master and storages nodes are # send to a client self.app.nm.createClient() conn = self.getFakeConnection() self.service.askNodeInformation(conn) calls = conn.mockGetNamedCalls('notify') self.assertEqual(len(calls), 1) packet = calls[0].getParam(0) (node_list, ) = packet.decode() self.assertEqual(len(node_list), 2) def test_connectionClosed(self): # give a client uuid which have unfinished transactions client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) conn = self.getFakeConnection(client_uuid, self.client_address) self.app.listening_conn = object() # mark as running lptid = self.app.pt.getID() self.assertEqual( self.app.nm.getByUUID(client_uuid).getState(), NodeStates.RUNNING) self.service.connectionClosed(conn) # node must be have been remove, and no more transaction must remains self.assertEqual(self.app.nm.getByUUID(client_uuid), None) self.assertEqual(lptid, self.app.pt.getID()) def test_askPack(self): self.assertEqual(self.app.packing, None) self.app.nm.createClient() tid = self.getNextTID() peer_id = 42 conn = self.getFakeConnection(peer_id=peer_id) storage_uuid = self.storage_uuid storage_conn = self.getFakeConnection(storage_uuid, self.storage_address) self.app.nm.getByUUID(storage_uuid).setConnection(storage_conn) self.service.askPack(conn, tid) self.checkNoPacketSent(conn) ptid = self.checkAskPacket(storage_conn, Packets.AskPack, decode=True)[0] self.assertEqual(ptid, tid) self.assertTrue(self.app.packing[0] is conn) self.assertEqual(self.app.packing[1], peer_id) self.assertEqual(self.app.packing[2], {storage_uuid}) # Asking again to pack will cause an immediate error storage_uuid = self.identifyToMasterNode(port=10022) storage_conn = self.getFakeConnection(storage_uuid, self.storage_address) self.app.nm.getByUUID(storage_uuid).setConnection(storage_conn) self.service.askPack(conn, tid) self.checkNoPacketSent(storage_conn) status = self.checkAnswerPacket(conn, Packets.AnswerPack, decode=True)[0] self.assertFalse(status)
class MasterClientHandlerTests(NeoUnitTestBase): def setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration(master_number=1, replicas=1) self.app = Application(config) self.app.em.close() self.app.pt.clear() self.app.pt.setID(1) self.app.em = Mock() self.app.loid = '\0' * 8 self.app.tm.setLastTID('\0' * 8) self.service = ClientServiceHandler(self.app) # define some variable to simulate client and storage node self.client_port = 11022 self.storage_port = 10021 self.master_port = 10010 self.master_address = ('127.0.0.1', self.master_port) self.client_address = ('127.0.0.1', self.client_port) self.storage_address = ('127.0.0.1', self.storage_port) self.storage_uuid = self.getStorageUUID() # register the storage self.app.nm.createStorage( uuid=self.storage_uuid, address=self.storage_address, ) def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1", port=10021): """Do first step of identification to MN """ # register the master itself uuid = self.getNewUUID(node_type) self.app.nm.createFromNodeType( node_type, address=(ip, port), uuid=uuid, state=NodeStates.RUNNING, ) return uuid # Tests def test_07_askBeginTransaction(self): tid1 = self.getNextTID() tid2 = self.getNextTID() service = self.service tm_org = self.app.tm self.app.tm = tm = Mock({ 'begin': '\x00\x00\x00\x00\x00\x00\x00\x01', }) # client call it client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) client_node = self.app.nm.getByUUID(client_uuid) conn = self.getFakeConnection(client_uuid, self.client_address) service.askBeginTransaction(conn, None) calls = tm.mockGetNamedCalls('begin') self.assertEqual(len(calls), 1) calls[0].checkArgs(client_node, None) self.checkAnswerBeginTransaction(conn) # Client asks for a TID conn = self.getFakeConnection(client_uuid, self.client_address) self.app.tm = tm_org service.askBeginTransaction(conn, tid1) calls = tm.mockGetNamedCalls('begin') self.assertEqual(len(calls), 1) calls[0].checkArgs(client_node, None) args = self.checkAnswerBeginTransaction(conn, decode=True) self.assertEqual(args, (tid1, )) def test_08_askNewOIDs(self): service = self.service oid1, oid2 = self.getOID(1), self.getOID(2) self.app.tm.setLastOID(oid1) # client call it client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) conn = self.getFakeConnection(client_uuid, self.client_address) for node in self.app.nm.getStorageList(): conn = self.getFakeConnection(node.getUUID(), node.getAddress()) node.setConnection(conn) service.askNewOIDs(conn, 1) self.assertTrue(self.app.tm.getLastOID() > oid1) def test_09_askFinishTransaction(self): service = self.service # do the right job client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) storage_uuid = self.storage_uuid storage_conn = self.getFakeConnection(storage_uuid, self.storage_address) storage2_uuid = self.identifyToMasterNode(port=10022) storage2_conn = self.getFakeConnection(storage2_uuid, (self.storage_address[0], self.storage_address[1] + 1)) self.app.setStorageReady(storage2_uuid) conn = self.getFakeConnection(client_uuid, self.client_address) self.app.pt = Mock({ 'getPartition': 0, 'getCellList': [ Mock({'getUUID': storage_uuid}), Mock({'getUUID': storage2_uuid}), ], 'getPartitions': 2, }) ttid = self.getNextTID() service.askBeginTransaction(conn, ttid) conn = self.getFakeConnection(client_uuid, self.client_address) self.app.nm.getByUUID(storage_uuid).setConnection(storage_conn) # No packet sent if storage node is not ready self.assertFalse(self.app.isStorageReady(storage_uuid)) service.askFinishTransaction(conn, ttid, (), ()) self.checkNoPacketSent(storage_conn) # ...but AskLockInformation is sent if it is ready self.app.setStorageReady(storage_uuid) self.assertTrue(self.app.isStorageReady(storage_uuid)) service.askFinishTransaction(conn, ttid, (), ()) self.checkAskLockInformation(storage_conn) self.assertEqual(len(self.app.tm.registerForNotification(storage_uuid)), 1) txn = self.app.tm[ttid] pending_ttid = list(self.app.tm.registerForNotification(storage_uuid))[0] self.assertEqual(ttid, pending_ttid) self.assertEqual(len(txn.getOIDList()), 0) self.assertEqual(len(txn.getUUIDList()), 1) def test_askNodeInformations(self): # check that only informations about master and storages nodes are # send to a client self.app.nm.createClient() conn = self.getFakeConnection() self.service.askNodeInformation(conn) calls = conn.mockGetNamedCalls('notify') self.assertEqual(len(calls), 1) packet = calls[0].getParam(0) (node_list, ) = packet.decode() self.assertEqual(len(node_list), 2) def test_connectionClosed(self): # give a client uuid which have unfinished transactions client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port = self.client_port) conn = self.getFakeConnection(client_uuid, self.client_address) self.app.listening_conn = object() # mark as running lptid = self.app.pt.getID() self.assertEqual(self.app.nm.getByUUID(client_uuid).getState(), NodeStates.RUNNING) self.service.connectionClosed(conn) # node must be have been remove, and no more transaction must remains self.assertEqual(self.app.nm.getByUUID(client_uuid), None) self.assertEqual(lptid, self.app.pt.getID()) def test_askPack(self): self.assertEqual(self.app.packing, None) self.app.nm.createClient() tid = self.getNextTID() peer_id = 42 conn = self.getFakeConnection(peer_id=peer_id) storage_uuid = self.storage_uuid storage_conn = self.getFakeConnection(storage_uuid, self.storage_address) self.app.nm.getByUUID(storage_uuid).setConnection(storage_conn) self.service.askPack(conn, tid) self.checkNoPacketSent(conn) ptid = self.checkAskPacket(storage_conn, Packets.AskPack, decode=True)[0] self.assertEqual(ptid, tid) self.assertTrue(self.app.packing[0] is conn) self.assertEqual(self.app.packing[1], peer_id) self.assertEqual(self.app.packing[2], {storage_uuid}) # Asking again to pack will cause an immediate error storage_uuid = self.identifyToMasterNode(port=10022) storage_conn = self.getFakeConnection(storage_uuid, self.storage_address) self.app.nm.getByUUID(storage_uuid).setConnection(storage_conn) self.service.askPack(conn, tid) self.checkNoPacketSent(storage_conn) status = self.checkAnswerPacket(conn, Packets.AnswerPack, decode=True)[0] self.assertFalse(status)
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 MasterStorageHandlerTests(NeoUnitTestBase): def setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration(master_number=1, replicas=1) self.app = Application(config) self.app.em.close() self.app.pt.clear() self.app.em = Mock() self.service = StorageServiceHandler(self.app) self.client_handler = ClientServiceHandler(self.app) # define some variable to simulate client and storage node self.client_port = 11022 self.storage_port = 10021 self.master_port = 10010 self.master_address = ('127.0.0.1', self.master_port) self.client_address = ('127.0.0.1', self.client_port) self.storage_address = ('127.0.0.1', self.storage_port) def _allocatePort(self): self.port = getattr(self, 'port', 1000) + 1 return self.port def _getClient(self): return self.identifyToMasterNode(node_type=NodeTypes.CLIENT, ip='127.0.0.1', port=self._allocatePort()) def _getStorage(self): return self.identifyToMasterNode(node_type=NodeTypes.STORAGE, ip='127.0.0.1', port=self._allocatePort()) def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1", port=10021): """Do first step of identification to MN """ nm = self.app.nm uuid = self.getNewUUID(node_type) node = nm.createFromNodeType(node_type, address=(ip, port), uuid=uuid) conn = self.getFakeConnection(node.getUUID(), node.getAddress()) node.setConnection(conn) return (node, conn) def test_answerInformationLocked_1(self): """ Master must refuse to lock if the TID is greater than the last TID """ tid1 = self.getNextTID() tid2 = self.getNextTID(tid1) self.app.tm.setLastTID(tid1) self.assertTrue(tid1 < tid2) node, conn = self.identifyToMasterNode() self.checkProtocolErrorRaised(self.service.answerInformationLocked, conn, tid2) self.checkNoPacketSent(conn) def test_answerInformationLocked_2(self): """ Master must: - lock each storage - notify the client - invalidate other clients - unlock storages """ # one client and two storages required client_1, client_conn_1 = self._getClient() client_2, client_conn_2 = self._getClient() storage_1, storage_conn_1 = self._getStorage() storage_2, storage_conn_2 = self._getStorage() uuid_list = storage_1.getUUID(), storage_2.getUUID() oid_list = self.getOID(), self.getOID() msg_id = 1 # register a transaction ttid = self.app.tm.begin(client_1) tid = self.app.tm.prepare(ttid, 1, oid_list, uuid_list, msg_id) self.assertTrue(ttid in self.app.tm) # the first storage acknowledge the lock self.service.answerInformationLocked(storage_conn_1, ttid) self.checkNoPacketSent(client_conn_1) self.checkNoPacketSent(client_conn_2) self.checkNoPacketSent(storage_conn_1) self.checkNoPacketSent(storage_conn_2) # then the second self.service.answerInformationLocked(storage_conn_2, ttid) self.checkAnswerTransactionFinished(client_conn_1) self.checkInvalidateObjects(client_conn_2) self.checkNotifyUnlockInformation(storage_conn_1) self.checkNotifyUnlockInformation(storage_conn_2) def test_13_askUnfinishedTransactions(self): service = self.service node, conn = self.identifyToMasterNode() # give a uuid service.askUnfinishedTransactions(conn) packet = self.checkAnswerUnfinishedTransactions(conn) max_tid, tid_list = packet.decode() self.assertEqual(tid_list, []) # create some transaction node, conn = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) ttid = self.app.tm.begin(node) self.app.tm.prepare(ttid, 1, [self.getOID(1)], [node.getUUID()], 1) conn = self.getFakeConnection(node.getUUID(), self.storage_address) service.askUnfinishedTransactions(conn) max_tid, tid_list = self.checkAnswerUnfinishedTransactions(conn, decode=True) self.assertEqual(len(tid_list), 1) def test_connectionClosed(self): method = self.service.connectionClosed state = NodeStates.TEMPORARILY_DOWN # define two nodes node1, conn1 = self.identifyToMasterNode() node2, conn2 = self.identifyToMasterNode(port=10022) node1.setRunning() node2.setRunning() self.assertEqual(node1.getState(), NodeStates.RUNNING) self.assertEqual(node2.getState(), NodeStates.RUNNING) # filled the pt self.app.pt.make(self.app.nm.getStorageList()) self.assertTrue(self.app.pt.filled()) self.assertTrue(self.app.pt.operational()) # drop one node lptid = self.app.pt.getID() method(conn1) self.assertEqual(node1.getState(), state) self.assertTrue(lptid < self.app.pt.getID()) # drop the second, no storage node left lptid = self.app.pt.getID() self.assertEqual(node2.getState(), NodeStates.RUNNING) self.assertRaises(StoppedOperation, method, conn2) self.assertEqual(node2.getState(), state) self.assertEqual(lptid, self.app.pt.getID()) def test_answerPack(self): # Note: incomming status has no meaning here, so it's left to False. node1, conn1 = self._getStorage() node2, conn2 = self._getStorage() self.app.packing = None # Does nothing self.service.answerPack(None, False) client_conn = Mock({ 'getPeerId': 512, }) client_peer_id = 42 self.app.packing = (client_conn, client_peer_id, {conn1.getUUID(), conn2.getUUID()}) self.service.answerPack(conn1, False) self.checkNoPacketSent(client_conn) self.assertEqual(self.app.packing[2], {conn2.getUUID()}) self.service.answerPack(conn2, False) status = self.checkAnswerPacket(client_conn, Packets.AnswerPack, decode=True)[0] # TODO: verify packet peer id self.assertTrue(status) self.assertEqual(self.app.packing, None) def test_notifyReady(self): node, conn = self._getStorage() uuid = node.getUUID() self.assertFalse(self.app.isStorageReady(uuid)) self.service.notifyReady(conn) self.assertTrue(self.app.isStorageReady(uuid))
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)
def setUp(self): NeoUnitTestBase.setUp(self) # create an application object config = self.getMasterConfiguration() self.app = Application(config) self.app.pt.clear()
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.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)