def test_12_getRow(self): num_partitions = 5 num_replicas = 2 pt = PartitionTable(num_partitions, num_replicas) # add nodes uuid1 = self.getStorageUUID() server1 = ("127.0.0.1", 19001) sn1 = StorageNode(Mock(), server1, uuid1) pt.setCell(0, sn1, CellStates.UP_TO_DATE) pt.setCell(1, sn1, CellStates.UP_TO_DATE) pt.setCell(2, sn1, CellStates.UP_TO_DATE) uuid2 = self.getStorageUUID() server2 = ("127.0.0.2", 19001) sn2 = StorageNode(Mock(), server2, uuid2) pt.setCell(0, sn2, CellStates.UP_TO_DATE) pt.setCell(1, sn2, CellStates.UP_TO_DATE) uuid3 = self.getStorageUUID() server3 = ("127.0.0.3", 19001) sn3 = StorageNode(Mock(), server3, uuid3) pt.setCell(0, sn3, CellStates.UP_TO_DATE) # test row_0 = pt.getRow(0) self.assertEqual(len(row_0), 3) for uuid, state in row_0: self.assertTrue(uuid in (sn1.getUUID(), sn2.getUUID(), sn3.getUUID())) self.assertEqual(state, CellStates.UP_TO_DATE) row_1 = pt.getRow(1) self.assertEqual(len(row_1), 2) for uuid, state in row_1: self.assertTrue(uuid in (sn1.getUUID(), sn2.getUUID())) self.assertEqual(state, CellStates.UP_TO_DATE) row_2 = pt.getRow(2) self.assertEqual(len(row_2), 1) for uuid, state in row_2: self.assertEqual(uuid, sn1.getUUID()) self.assertEqual(state, CellStates.UP_TO_DATE) row_3 = pt.getRow(3) self.assertEqual(len(row_3), 0) row_4 = pt.getRow(4) self.assertEqual(len(row_4), 0) # unknwon row self.assertRaises(IndexError, pt.getRow, 5)
class NodeManagerTests(NeoUnitTestBase): def setUp(self): NeoUnitTestBase.setUp(self) self.manager = NodeManager() def _addStorage(self): self.storage = StorageNode(self.manager, ('127.0.0.1', 1000), self.getStorageUUID()) def _addMaster(self): self.master = MasterNode(self.manager, ('127.0.0.1', 2000), self.getMasterUUID()) def _addClient(self): self.client = ClientNode(self.manager, None, self.getClientUUID()) def _addAdmin(self): self.admin = AdminNode(self.manager, ('127.0.0.1', 4000), self.getAdminUUID()) def checkNodes(self, node_list): manager = self.manager self.assertEqual(sorted(manager.getList()), sorted(node_list)) def checkMasters(self, master_list): manager = self.manager self.assertEqual(manager.getMasterList(), master_list) def checkStorages(self, storage_list): manager = self.manager self.assertEqual(manager.getStorageList(), storage_list) def checkClients(self, client_list): manager = self.manager self.assertEqual(manager.getClientList(), client_list) def checkByServer(self, node): node_found = self.manager.getByAddress(node.getAddress()) self.assertEqual(node_found, node) def checkByUUID(self, node): node_found = self.manager.getByUUID(node.getUUID()) self.assertEqual(node_found, node) def checkIdentified(self, node_list, pool_set=None): identified_node_list = self.manager.getIdentifiedList(pool_set) self.assertEqual(set(identified_node_list), set(node_list)) def testInit(self): """ Check the manager is empty when started """ manager = self.manager self.checkNodes([]) self.checkMasters([]) self.checkStorages([]) self.checkClients([]) address = ('127.0.0.1', 10000) self.assertEqual(manager.getByAddress(address), None) self.assertEqual(manager.getByAddress(None), None) uuid = self.getNewUUID(None) self.assertEqual(manager.getByUUID(uuid), None) self.assertEqual(manager.getByUUID(None), None) def testAdd(self): """ Check if new nodes are registered in the manager """ manager = self.manager self.checkNodes([]) # storage self._addStorage() self.checkNodes([self.storage]) self.checkStorages([self.storage]) self.checkMasters([]) self.checkClients([]) self.checkByServer(self.storage) self.checkByUUID(self.storage) # master self._addMaster() self.checkNodes([self.storage, self.master]) self.checkStorages([self.storage]) self.checkMasters([self.master]) self.checkClients([]) self.checkByServer(self.master) self.checkByUUID(self.master) # client self._addClient() self.checkNodes([self.storage, self.master, self.client]) self.checkStorages([self.storage]) self.checkMasters([self.master]) self.checkClients([self.client]) # client node has no address self.assertEqual(manager.getByAddress(self.client.getAddress()), None) self.checkByUUID(self.client) # admin self._addAdmin() self.checkNodes([self.storage, self.master, self.client, self.admin]) self.checkStorages([self.storage]) self.checkMasters([self.master]) self.checkClients([self.client]) self.checkByServer(self.admin) self.checkByUUID(self.admin) def testUpdate(self): """ Check manager content update """ # set up four nodes manager = self.manager self._addMaster() self._addStorage() self._addClient() self._addAdmin() self.checkNodes([self.master, self.storage, self.client, self.admin]) self.checkMasters([self.master]) self.checkStorages([self.storage]) self.checkClients([self.client]) # build changes old_address = self.master.getAddress() new_address = ('127.0.0.1', 2001) old_uuid = self.storage.getUUID() new_uuid = self.getStorageUUID() node_list = ( (NodeTypes.CLIENT, None, self.client.getUUID(), NodeStates.DOWN), (NodeTypes.MASTER, new_address, self.master.getUUID(), NodeStates.RUNNING), (NodeTypes.STORAGE, self.storage.getAddress(), new_uuid, NodeStates.RUNNING), (NodeTypes.ADMIN, self.admin.getAddress(), self.admin.getUUID(), NodeStates.UNKNOWN), ) # update manager content manager.update(node_list) # - the client gets down self.checkClients([]) # - master change it's address self.checkMasters([self.master]) self.assertEqual(manager.getByAddress(old_address), None) self.master.setAddress(new_address) self.checkByServer(self.master) # - storage change it's UUID 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) # admin is still here but in UNKNOWN state self.checkNodes([self.master, self.admin, new_storage]) self.assertEqual(self.admin.getState(), NodeStates.UNKNOWN) def testIdentified(self): # set up four nodes manager = self.manager self._addMaster() self._addStorage() self._addClient() self._addAdmin() # switch node to connected self.checkIdentified([]) self.master.setConnection(Mock()) self.checkIdentified([self.master]) self.storage.setConnection(Mock()) self.checkIdentified([self.master, self.storage]) self.client.setConnection(Mock()) self.checkIdentified([self.master, self.storage, self.client]) self.admin.setConnection(Mock()) self.checkIdentified([self.master, self.storage, self.client, self.admin]) # check the pool_set attribute self.checkIdentified([self.master], pool_set=[self.master.getUUID()]) self.checkIdentified([self.storage], pool_set=[self.storage.getUUID()]) self.checkIdentified([self.client], pool_set=[self.client.getUUID()]) self.checkIdentified([self.admin], pool_set=[self.admin.getUUID()]) self.checkIdentified([self.master, self.storage], pool_set=[ self.master.getUUID(), self.storage.getUUID()])
class NodeManagerTests(NeoUnitTestBase): def setUp(self): NeoUnitTestBase.setUp(self) self.manager = NodeManager() def _addStorage(self): self.storage = StorageNode(self.manager, ('127.0.0.1', 1000), self.getStorageUUID()) def _addMaster(self): self.master = MasterNode(self.manager, ('127.0.0.1', 2000), self.getMasterUUID()) def _addClient(self): self.client = ClientNode(self.manager, None, self.getClientUUID()) def _addAdmin(self): self.admin = AdminNode(self.manager, ('127.0.0.1', 4000), self.getAdminUUID()) def checkNodes(self, node_list): manager = self.manager self.assertEqual(sorted(manager.getList()), sorted(node_list)) def checkMasters(self, master_list): manager = self.manager self.assertEqual(manager.getMasterList(), master_list) def checkStorages(self, storage_list): manager = self.manager self.assertEqual(manager.getStorageList(), storage_list) def checkClients(self, client_list): manager = self.manager self.assertEqual(manager.getClientList(), client_list) def checkByServer(self, node): node_found = self.manager.getByAddress(node.getAddress()) self.assertEqual(node_found, node) def checkByUUID(self, node): node_found = self.manager.getByUUID(node.getUUID()) self.assertEqual(node_found, node) def checkIdentified(self, node_list, pool_set=None): identified_node_list = self.manager.getIdentifiedList(pool_set) self.assertEqual(set(identified_node_list), set(node_list)) def testInit(self): """ Check the manager is empty when started """ manager = self.manager self.checkNodes([]) self.checkMasters([]) self.checkStorages([]) self.checkClients([]) address = ('127.0.0.1', 10000) self.assertEqual(manager.getByAddress(address), None) self.assertEqual(manager.getByAddress(None), None) uuid = self.getNewUUID(None) self.assertEqual(manager.getByUUID(uuid), None) self.assertEqual(manager.getByUUID(None), None) def testAdd(self): """ Check if new nodes are registered in the manager """ manager = self.manager self.checkNodes([]) # storage self._addStorage() self.checkNodes([self.storage]) self.checkStorages([self.storage]) self.checkMasters([]) self.checkClients([]) self.checkByServer(self.storage) self.checkByUUID(self.storage) # master self._addMaster() self.checkNodes([self.storage, self.master]) self.checkStorages([self.storage]) self.checkMasters([self.master]) self.checkClients([]) self.checkByServer(self.master) self.checkByUUID(self.master) # client self._addClient() self.checkNodes([self.storage, self.master, self.client]) self.checkStorages([self.storage]) self.checkMasters([self.master]) self.checkClients([self.client]) # client node has no address self.assertEqual(manager.getByAddress(self.client.getAddress()), None) self.checkByUUID(self.client) # admin self._addAdmin() self.checkNodes([self.storage, self.master, self.client, self.admin]) self.checkStorages([self.storage]) self.checkMasters([self.master]) self.checkClients([self.client]) self.checkByServer(self.admin) self.checkByUUID(self.admin) def testUpdate(self): """ Check manager content update """ # set up four nodes manager = self.manager self._addMaster() self._addStorage() self._addClient() self._addAdmin() self.checkNodes([self.master, self.storage, self.client, self.admin]) self.checkMasters([self.master]) self.checkStorages([self.storage]) self.checkClients([self.client]) # build changes old_address = self.master.getAddress() new_address = ('127.0.0.1', 2001) old_uuid = self.storage.getUUID() new_uuid = self.getStorageUUID() node_list = ( (NodeTypes.CLIENT, None, self.client.getUUID(), NodeStates.DOWN), (NodeTypes.MASTER, new_address, self.master.getUUID(), NodeStates.RUNNING), (NodeTypes.STORAGE, self.storage.getAddress(), new_uuid, NodeStates.RUNNING), (NodeTypes.ADMIN, self.admin.getAddress(), self.admin.getUUID(), NodeStates.UNKNOWN), ) # update manager content manager.update(node_list) # - the client gets down self.checkClients([]) # - master change it's address self.checkMasters([self.master]) self.assertEqual(manager.getByAddress(old_address), None) self.master.setAddress(new_address) self.checkByServer(self.master) # - storage change it's UUID 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) # admin is still here but in UNKNOWN state self.checkNodes([self.master, self.admin, new_storage]) self.assertEqual(self.admin.getState(), NodeStates.UNKNOWN) def testIdentified(self): # set up four nodes manager = self.manager self._addMaster() self._addStorage() self._addClient() self._addAdmin() # switch node to connected self.checkIdentified([]) self.master.setConnection(Mock()) self.checkIdentified([self.master]) self.storage.setConnection(Mock()) self.checkIdentified([self.master, self.storage]) self.client.setConnection(Mock()) self.checkIdentified([self.master, self.storage, self.client]) self.admin.setConnection(Mock()) self.checkIdentified( [self.master, self.storage, self.client, self.admin]) # check the pool_set attribute self.checkIdentified([self.master], pool_set=[self.master.getUUID()]) self.checkIdentified([self.storage], pool_set=[self.storage.getUUID()]) self.checkIdentified([self.client], pool_set=[self.client.getUUID()]) self.checkIdentified([self.admin], pool_set=[self.admin.getUUID()]) self.checkIdentified( [self.master, self.storage], pool_set=[self.master.getUUID(), self.storage.getUUID()])