def test_AllocationManagerAllocationIterators(self): """ Verifiers that the AllocationManager's allocation iterators return the same sets of allocations as the corresponding attributes. """ nb1, execDevNode1 = self.launchDeviceManager("/nodes/test_multiDomain_exec/DeviceManager.dcd.xml", domainManager=self._domainManager_1) self.assertNotEqual(execDevNode1, None) nb2, basicDevNode1 = self.launchDeviceManager("/nodes/test_multiDomain_uses/DeviceManager.dcd.xml", domainManager=self._domainManager_2) self.assertNotEqual(basicDevNode1, None) # Connect the domains to each other self._domainManager_1.registerRemoteDomainManager(self._domainManager_2) allocMgr = self._domainManager_1._get_allocationMgr() # Make a couple of allocation requests that we know will have to be # split across the two domains execcap = {'DCE:8dcef419-b440-4bcf-b893-cab79b6024fb':1000, 'DCE:4f9a57fc-8fb3-47f6-b779-3c2692f52cf9':50.0} usescap = {'DCE:8cad8ca5-c155-4d1d-ae40-e194aa1d855f':1} requests = [allocMgrHelpers.createRequest('exec', properties.props_from_dict(execcap)), allocMgrHelpers.createRequest('uses', properties.props_from_dict(usescap))] results = allocMgr.allocate(requests) self.assertEqual(len(requests), len(results)) # Check local allocations local_iter = _iteratorFetch(allocMgr.listAllocations(CF.AllocationManager.LOCAL_ALLOCATIONS, 1)) local_list = allocMgr.localAllocations([]) self.assertTrue(allocMgrHelpers.compareAllocationStatusSequence(local_iter, local_list)) # Check all allocations all_iter = _iteratorFetch(allocMgr.listAllocations(CF.AllocationManager.ALL_ALLOCATIONS, 1)) all_list = allocMgr.allocations([]) self.assertTrue(allocMgrHelpers.compareAllocationStatusSequence(all_iter, all_list))
def test_AllocationManagerAllocationIterators(self): """ Verifiers that the AllocationManager's allocation iterators return the same sets of allocations as the corresponding attributes. """ nb1, execDevNode1 = self.launchDeviceManager( "/nodes/test_multiDomain_exec/DeviceManager.dcd.xml", domainManager=self._domainManager_1) self.assertNotEqual(execDevNode1, None) nb2, basicDevNode1 = self.launchDeviceManager( "/nodes/test_multiDomain_uses/DeviceManager.dcd.xml", domainManager=self._domainManager_2) self.assertNotEqual(basicDevNode1, None) # Connect the domains to each other self._domainManager_1.registerRemoteDomainManager( self._domainManager_2) allocMgr = self._domainManager_1._get_allocationMgr() # Make a couple of allocation requests that we know will have to be # split across the two domains execcap = { 'DCE:8dcef419-b440-4bcf-b893-cab79b6024fb': 1000, 'DCE:4f9a57fc-8fb3-47f6-b779-3c2692f52cf9': 50.0 } usescap = {'DCE:8cad8ca5-c155-4d1d-ae40-e194aa1d855f': 1} requests = [ allocMgrHelpers.createRequest('exec', properties.props_from_dict(execcap)), allocMgrHelpers.createRequest('uses', properties.props_from_dict(usescap)) ] results = allocMgr.allocate(requests) self.assertEqual(len(requests), len(results)) # Check local allocations local_iter = _iteratorFetch( allocMgr.listAllocations(CF.AllocationManager.LOCAL_ALLOCATIONS, 1)) local_list = allocMgr.localAllocations([]) self.assertTrue( allocMgrHelpers.compareAllocationStatusSequence( local_iter, local_list)) # Check all allocations all_iter = _iteratorFetch( allocMgr.listAllocations(CF.AllocationManager.ALL_ALLOCATIONS, 1)) all_list = allocMgr.allocations([]) self.assertTrue( allocMgrHelpers.compareAllocationStatusSequence( all_iter, all_list))
def test_redhawkutils_AllocationIterators(self): nb, devMgr = self.launchDeviceManager('/nodes/test_SADUsesDevice/DeviceManager.dcd.xml') # Set initial state to 4 allocations request = [('test1', {'simple_alloc': 1}), ('test2', {'simple_alloc': 1}), ('external', {'simple_alloc': 1}), ('matching', {'DCE:ac73446e-f935-40b6-8b8d-4d9adb6b403f':2, 'DCE:7f36cdfb-f828-4e4f-b84f-446e17f1a85b':'BasicTestDevice'})] request = [ self.am.createRequest(k, properties.props_from_dict(v)) for k, v in request] response = self.am.allocate(request) self.assertEqual(len(request), len(response)) localAllocs = self.am.allocations([], True) # First, try to list more allocations than have been made, to make sure # no iterator is returned allocs, allociter = self.am.listAllocations( self.am.LOCAL_ALLOCATIONS, 10) self.assertTrue(allocMgrHelpers.compareAllocationStatusSequence(allocs, localAllocs)) self.assertEqual(allociter, None) # Next, start with fewer allocations and fetch one-by-one via the iterator allocs, allociter = self.am.listAllocations( self.am.LOCAL_ALLOCATIONS, 1) self.assertEqual(len(allocs), 1) self.assertNotEqual(allociter, None) try: # There has to be at least one more allocation item = allociter.next_one() self.assertNotEqual(item, None) allocs.append(item) # Fetch the remainder while item: item = allociter.next_one() if item: allocs.append(item) finally: pass # Check the resulting list self.assertTrue(allocMgrHelpers.compareAllocationStatusSequence(allocs, localAllocs)) # Then try fetching by a higher count allocs, allociter = self.am.listAllocations( self.am.LOCAL_ALLOCATIONS, 1) self.assertEqual(len(allocs), 1) self.assertNotEqual(allociter, None) try: # Try to fetch 2 more, which ought to succeed in full items = allociter.next_n(2) self.assertEqual(len(items), 2) allocs.extend(items) # Try 2 more, which should return only 1 items = allociter.next_n(2) self.assertEqual(len(items), 1) allocs.extend(items) # Finally, the next fetch should fail items = allociter.next_n(2) self.assertEqual(items, None) finally: pass # Check the resulting list self.assertTrue(allocMgrHelpers.compareAllocationStatusSequence(allocs, localAllocs))
def test_redhawkutils_AllocationIterators(self): nb, devMgr = self.launchDeviceManager( '/nodes/test_SADUsesDevice/DeviceManager.dcd.xml') # Set initial state to 4 allocations request = [('test1', { 'simple_alloc': 1 }), ('test2', { 'simple_alloc': 1 }), ('external', { 'simple_alloc': 1 }), ('matching', { 'DCE:ac73446e-f935-40b6-8b8d-4d9adb6b403f': 2, 'DCE:7f36cdfb-f828-4e4f-b84f-446e17f1a85b': 'BasicTestDevice' })] request = [ self.am.createRequest(k, properties.props_from_dict(v)) for k, v in request ] response = self.am.allocate(request) self.assertEqual(len(request), len(response)) localAllocs = self.am.allocations([], True) # First, try to list more allocations than have been made, to make sure # no iterator is returned allocs, allociter = self.am.listAllocations(self.am.LOCAL_ALLOCATIONS, 10) self.assertTrue( allocMgrHelpers.compareAllocationStatusSequence( allocs, localAllocs)) self.assertEqual(allociter, None) # Next, start with fewer allocations and fetch one-by-one via the iterator allocs, allociter = self.am.listAllocations(self.am.LOCAL_ALLOCATIONS, 1) self.assertEqual(len(allocs), 1) self.assertNotEqual(allociter, None) try: # There has to be at least one more allocation item = allociter.next_one() self.assertNotEqual(item, None) allocs.append(item) # Fetch the remainder while item: item = allociter.next_one() if item: allocs.append(item) finally: pass # Check the resulting list self.assertTrue( allocMgrHelpers.compareAllocationStatusSequence( allocs, localAllocs)) # Then try fetching by a higher count allocs, allociter = self.am.listAllocations(self.am.LOCAL_ALLOCATIONS, 1) self.assertEqual(len(allocs), 1) self.assertNotEqual(allociter, None) try: # Try to fetch 2 more, which ought to succeed in full items = allociter.next_n(2) self.assertEqual(len(items), 2) allocs.extend(items) # Try 2 more, which should return only 1 items = allociter.next_n(2) self.assertEqual(len(items), 1) allocs.extend(items) # Finally, the next fetch should fail items = allociter.next_n(2) self.assertEqual(items, None) finally: pass # Check the resulting list self.assertTrue( allocMgrHelpers.compareAllocationStatusSequence( allocs, localAllocs))