コード例 #1
0
    def test_AllocationPersistence(self):
        self.launchDeviceManager("/nodes/test_multiDomain_exec/DeviceManager.dcd.xml", domainManager=self._domainManager_1)
        self.launchDeviceManager("/nodes/test_multiDomain_uses/DeviceManager.dcd.xml", domainManager=self._domainManager_2)
        self._domainManager_1.registerRemoteDomainManager(self._domainManager_2)

        allocMgr_1 = 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 = dict((r.requestID, r) for r in allocMgr_1.allocate(requests))
        self.assertEqual(len(requests), len(results))
        usesId = results['uses'].allocationID
        execId = results['exec'].allocationID

        # Save the current allocation state
        pre = dict((al.allocationID, al) for al in allocMgr_1.allocations([]))

        # Kill the DomainManager
        os.kill(self._domainBooter_1.pid, signal.SIGTERM)
        if not self.waitTermination(self._domainBooter_1):
            self.fail("Domain Manager Failed to Die")

        # Re-launch and check that the allocation state remains the same
        self.launchDomainManager(endpoint='giop:tcp::5679', dbURI=self._dbfile)
        post = dict((al.allocationID, al) for al in allocMgr_1.allocations([]))
        self.assertEqual(len(pre), len(post))
        self.assertEqual(pre.keys(), post.keys())
        for allocId, status in pre.iteritems():
            self.assert_(allocMgrHelpers.compareAllocationStatus(status, post[allocId]))
コード例 #2
0
    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))
コード例 #3
0
    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))
コード例 #4
0
    def test_allocationsMethod(self):
        nb, devMgr = self.launchDeviceManager(
            '/nodes/test_SADUsesDevice/DeviceManager.dcd.xml')

        # Check that there are no allocations reported
        allocs = self._allocMgr.allocations([])
        self.assertEqual(len(allocs), 0)

        # Make a single allocation request and check that it looks right
        props = properties.props_from_dict({'simple_alloc': 1})
        request = [allocMgrHelpers.createRequest('test1', props)]
        response = self._allocMgr.allocate(request)
        self.assertEqual(len(request), len(response))
        self.assertEqual(request[0].requestID, response[0].requestID)

        # Save allocation IDs for later checks
        allocIDs = [resp.allocationID for resp in response]

        # Check that the reported allocations match expectations
        allocs = self._allocMgr.allocations([])
        self.assertEqual(len(allocs), 1)
        self.assertEqual(allocs[0].allocationID, allocIDs[0])

        # Make two more allocation requests
        request = [('external', {
            'simple_alloc': 1
        }),
                   ('matching', {
                       'DCE:ac73446e-f935-40b6-8b8d-4d9adb6b403f':
                       2,
                       'DCE:7f36cdfb-f828-4e4f-b84f-446e17f1a85b':
                       'BasicTestDevice'
                   })]
        request = [
            allocMgrHelpers.createRequest(k, properties.props_from_dict(v))
            for k, v in request
        ]
        response = self._allocMgr.allocate(request)
        self.assertEqual(len(request), len(response))
        allocIDs.extend(resp.allocationID for resp in response)

        allocs = self._allocMgr.allocations([])
        self.assertEqual(len(allocs), 3)

        # Try to retrieve an invalid allocation ID, making sure it throws an
        # exception
        self.assertRaises(CF.AllocationManager.InvalidAllocationId,
                          self._allocMgr.allocations, ['missing'])

        # Check that we can retrieve a specific allocation
        allocs = self._allocMgr.allocations(allocIDs[-1:])
        self.assertEqual(len(allocs), 1)
コード例 #5
0
    def test_AllocationPersistence(self):
        self.launchDeviceManager(
            "/nodes/test_multiDomain_exec/DeviceManager.dcd.xml",
            domainManager=self._domainManager_1)
        self.launchDeviceManager(
            "/nodes/test_multiDomain_uses/DeviceManager.dcd.xml",
            domainManager=self._domainManager_2)
        self._domainManager_1.registerRemoteDomainManager(
            self._domainManager_2)

        allocMgr_1 = 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 = dict((r.requestID, r) for r in allocMgr_1.allocate(requests))
        self.assertEqual(len(requests), len(results))
        usesId = results['uses'].allocationID
        execId = results['exec'].allocationID

        # Save the current allocation state
        pre = dict((al.allocationID, al) for al in allocMgr_1.allocations([]))

        # Kill the DomainManager
        os.kill(self._domainBooter_1.pid, signal.SIGTERM)
        if not self.waitTermination(self._domainBooter_1):
            self.fail("Domain Manager Failed to Die")

        # Re-launch and check that the allocation state remains the same
        self.launchDomainManager(endpoint='giop:tcp::5679', dbURI=self._dbfile)
        post = dict((al.allocationID, al) for al in allocMgr_1.allocations([]))
        self.assertEqual(len(pre), len(post))
        self.assertEqual(pre.keys(), post.keys())
        for allocId, status in pre.iteritems():
            self.assert_(
                allocMgrHelpers.compareAllocationStatus(status, post[allocId]))
コード例 #6
0
 def _tryAllocation(self, props):
     request = [
         allocMgrHelpers.createRequest('test',
                                       properties.props_from_dict(props))
     ]
     response = self.am.allocate(request)
     if response:
         self.am.deallocate([r.allocationID for r in response])
     return len(response) == len(request)
コード例 #7
0
    def test_allocationsMethod(self):
        nb, devMgr = self.launchDeviceManager('/nodes/test_SADUsesDevice/DeviceManager.dcd.xml')

        # Check that there are no allocations reported
        allocs = self._allocMgr.allocations([])
        self.assertEqual(len(allocs), 0)

        # Make a single allocation request and check that it looks right
        props = properties.props_from_dict({'simple_alloc': 1})
        request = [allocMgrHelpers.createRequest('test1', props)]
        response = self._allocMgr.allocate(request)
        self.assertEqual(len(request), len(response))
        self.assertEqual(request[0].requestID, response[0].requestID)
        
        # Save allocation IDs for later checks
        allocIDs = [resp.allocationID for resp in response]

        # Check that the reported allocations match expectations
        allocs = self._allocMgr.allocations([])
        self.assertEqual(len(allocs), 1)
        self.assertEqual(allocs[0].allocationID, allocIDs[0])

        # Make two more allocation requests
        request = [('external', {'simple_alloc': 1}),
                   ('matching', {'DCE:ac73446e-f935-40b6-8b8d-4d9adb6b403f':2,
                                 'DCE:7f36cdfb-f828-4e4f-b84f-446e17f1a85b':'BasicTestDevice'})]
        request = [allocMgrHelpers.createRequest(k, properties.props_from_dict(v)) for k, v in request]
        response = self._allocMgr.allocate(request)
        self.assertEqual(len(request), len(response))
        allocIDs.extend(resp.allocationID for resp in response)

        allocs = self._allocMgr.allocations([])
        self.assertEqual(len(allocs), 3)

        # Try to retrieve an invalid allocation ID, making sure it throws an
        # exception
        self.assertRaises(CF.AllocationManager.InvalidAllocationId, self._allocMgr.allocations, ['missing'])

        # Check that we can retrieve a specific allocation
        allocs = self._allocMgr.allocations(allocIDs[-1:])
        self.assertEqual(len(allocs), 1)
コード例 #8
0
    def test_ExternalProperties(self):
        nb, devMgr = self.launchDeviceManager('/nodes/test_collocation_good_node/DeviceManager.dcd.xml')

        #self._tryAllocation({ExtendedCF.WKP.OS_VERSION:'1'})
        #self._tryAllocation({'os_name':'Linux'})
        #self._tryAllocation({'supported_components': 5})
        #self._tryAllocation({'supported_components': 5, 'os_name':'Linux'})

        props = [('supported_components', 1), ('supported_components', 1)]
        allocProps = [CF.DataType(key, _any.to_any(value)) for key, value in props]
        request = [allocMgrHelpers.createRequest('test', allocProps)]
        response = self._allocMgr.allocate(request)
        if response:
            self._allocMgr.deallocate([r.allocationID for r in response])
        return len(response) == len(request)
コード例 #9
0
    def test_ExternalProperties(self):
        nb, devMgr = self.launchDeviceManager('/nodes/test_collocation_good_node/DeviceManager.dcd.xml')

        #self._tryAllocation({ExtendedCF.WKP.OS_VERSION:'1'})
        #self._tryAllocation({'os_name':'Linux'})
        #self._tryAllocation({'supported_components': 5})
        #self._tryAllocation({'supported_components': 5, 'os_name':'Linux'})

        props = [('supported_components', 1), ('supported_components', 1)]
        allocProps = [CF.DataType(key, _any.to_any(value)) for key, value in props]
        request = [allocMgrHelpers.createRequest('test', allocProps)]
        response = self._allocMgr.allocate(request)
        if response:
            self._allocMgr.deallocate([r.allocationID for r in response])
        return len(response) == len(request)
コード例 #10
0
    def test_AllocationSubsetLocalRemote(self):
        """
        Test that AllocationManager can split usesdevice allocations across
        the local domain and a remote one.
        """
        self.launchDeviceManager(
            "/nodes/MultiDomain1_node/DeviceManager.dcd.xml",
            domainManager=self._domainManager_1)
        self.launchDeviceManager(
            "/nodes/MultiDomain2_node/DeviceManager.dcd.xml",
            domainManager=self._domainManager_2)

        # Register second domain with first (no need to do both directions)
        self._domainManager_1.registerRemoteDomainManager(
            self._domainManager_2)

        allocMgr_1 = self._domainManager_1._get_allocationMgr()
        allocMgr_2 = self._domainManager_2._get_allocationMgr()

        # Check that the initial state of all allocations is empty
        self.assertEqual(allocMgr_1.allocations([]), [])
        self.assertEqual(allocMgr_1.localAllocations([]), [])
        self.assertEqual(allocMgr_2.allocations([]), [])
        self.assertEqual(allocMgr_2.localAllocations([]), [])

        # Make a couple of allocation requests that we know will have to be
        # split across the local and remote domains
        usescap = {'count': 1}
        requests = [
            allocMgrHelpers.createRequest('test_%d' % ii,
                                          properties.props_from_dict(usescap))
            for ii in range(2)
        ]

        # Both requests should be satisfied
        results = allocMgr_1.allocate(requests)
        self.assertEqual(len(requests), len(results))
        expected = set(r.requestID for r in requests)
        actual = set(r.requestID for r in results)
        self.assertEqual(expected, actual)

        # One allocation on the local domain
        allocations = allocMgr_1.localAllocations([])
        self.assertEqual(len(allocations), 1)

        # One allocation on the remote domain
        allocations = allocMgr_2.localAllocations([])
        self.assertEqual(len(allocations), 1)
コード例 #11
0
    def test_MultipleRequests(self):
        nb, devMgr = self.launchDeviceManager('/nodes/test_SADUsesDevice/DeviceManager.dcd.xml')

        # Try two requests that should succeed
        props = properties.props_from_dict({'simple_alloc': 1})
        request = [allocMgrHelpers.createRequest('test1', props), allocMgrHelpers.createRequest('test2', props)]
        response = self._allocMgr.allocate(request)
        self.assertEqual(len(request), len(response))
        self._allocMgr.deallocate([r.allocationID for r in response])

        # The second request should fail
        props = properties.props_from_dict({'simple_alloc': 8})
        request = [allocMgrHelpers.createRequest('test1', props), allocMgrHelpers.createRequest('test2', props)]
        response = self._allocMgr.allocate(request)
        good_requests = [r.requestID for r in response]
        self.assertTrue(len(request) > len(response))
        self.assertTrue('test1' in good_requests)
        self.assertFalse('test2' in good_requests)
        self._allocMgr.deallocate([r.allocationID for r in response])

        # The first and second requests should fail, but the third should succeed
        bad_props = {'simple_alloc': 12}
        good_props = {'simple_alloc': 8}
        request = [('test1', bad_props), ('test2', bad_props), ('test3', good_props)]
        request = [allocMgrHelpers.createRequest(k, properties.props_from_dict(v)) for k, v in request]
        response = self._allocMgr.allocate(request)
        good_requests = [r.requestID for r in response]
        self.assertTrue(len(request) > len(response))
        self.assertEqual(good_requests, ['test3'])
        self._allocMgr.deallocate([r.allocationID for r in response])

        # Ensure that different requests can be allocated to different devices
        request = [('external', {'simple_alloc': 1}),
                   ('matching', {'DCE:ac73446e-f935-40b6-8b8d-4d9adb6b403f':2,
                                 'DCE:7f36cdfb-f828-4e4f-b84f-446e17f1a85b':'BasicTestDevice'})]
        request = [allocMgrHelpers.createRequest(k, properties.props_from_dict(v)) for k, v in request]
        response = dict((r.requestID, r) for r in self._allocMgr.allocate(request))
        self.assertEqual(len(request), len(response))
        self.assertFalse(response['external'].allocatedDevice._is_equivalent(response['matching'].allocatedDevice))
        self._allocMgr.deallocate([r.allocationID for r in response.values()])
コード例 #12
0
    def test_MultipleRequests(self):
        nb, devMgr = self.launchDeviceManager('/nodes/test_SADUsesDevice/DeviceManager.dcd.xml')

        # Try two requests that should succeed
        props = properties.props_from_dict({'simple_alloc': 1})
        request = [allocMgrHelpers.createRequest('test1', props), allocMgrHelpers.createRequest('test2', props)]
        response = self._allocMgr.allocate(request)
        self.assertEqual(len(request), len(response))
        self._allocMgr.deallocate([r.allocationID for r in response])

        # The second request should fail
        props = properties.props_from_dict({'simple_alloc': 8})
        request = [allocMgrHelpers.createRequest('test1', props), allocMgrHelpers.createRequest('test2', props)]
        response = self._allocMgr.allocate(request)
        good_requests = [r.requestID for r in response]
        self.assertTrue(len(request) > len(response))
        self.assertTrue('test1' in good_requests)
        self.assertFalse('test2' in good_requests)
        self._allocMgr.deallocate([r.allocationID for r in response])

        # The first and second requests should fail, but the third should succeed
        bad_props = {'simple_alloc': 12}
        good_props = {'simple_alloc': 8}
        request = [('test1', bad_props), ('test2', bad_props), ('test3', good_props)]
        request = [allocMgrHelpers.createRequest(k, properties.props_from_dict(v)) for k, v in request]
        response = self._allocMgr.allocate(request)
        good_requests = [r.requestID for r in response]
        self.assertTrue(len(request) > len(response))
        self.assertEqual(good_requests, ['test3'])
        self._allocMgr.deallocate([r.allocationID for r in response])

        # Ensure that different requests can be allocated to different devices
        request = [('external', {'simple_alloc': 1}),
                   ('matching', {'DCE:ac73446e-f935-40b6-8b8d-4d9adb6b403f':2,
                                 'DCE:7f36cdfb-f828-4e4f-b84f-446e17f1a85b':'BasicTestDevice'})]
        request = [allocMgrHelpers.createRequest(k, properties.props_from_dict(v)) for k, v in request]
        response = dict((r.requestID, r) for r in self._allocMgr.allocate(request))
        self.assertEqual(len(request), len(response))
        self.assertFalse(response['external'].allocatedDevice._is_equivalent(response['matching'].allocatedDevice))
        self._allocMgr.deallocate([r.allocationID for r in response.values()])
コード例 #13
0
 def _tryAllocation(self, props):
     request = [allocMgrHelpers.createRequest('test', properties.props_from_dict(props))]
     response = self.am.allocate(request)
     if response:
         self.am.deallocate([r.allocationID for r in response])
     return len(response) == len(request)
コード例 #14
0
    def test_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 = [allocMgrHelpers.createRequest(k, properties.props_from_dict(v)) for k, v in request]
        response = self._allocMgr.allocate(request)
        self.assertEqual(len(request), len(response))

        localAllocs = self._allocMgr.localAllocations([])

        # First, try to list more allocations than have been made, to make sure
        # no iterator is returned
        allocs, allociter = self._allocMgr.listAllocations(CF.AllocationManager.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._allocMgr.listAllocations(CF.AllocationManager.LOCAL_ALLOCATIONS, 1)
        self.assertEqual(len(allocs), 1)
        self.assertNotEqual(allociter, None)
        try:
            # There has to be at least one more allocation
            status, item = allociter.next_one()
            self.assertTrue(status)
            self.assertNotEqual(item, None)
            allocs.append(item)

            # Fetch the remainder
            while status:
                status, item = allociter.next_one()
                if status:
                    allocs.append(item)
        finally:
            allociter.destroy()
        # Check the resulting list
        self.assertTrue(allocMgrHelpers.compareAllocationStatusSequence(allocs, localAllocs))

        # Then try fetching by a higher count
        allocs, allociter = self._allocMgr.listAllocations(CF.AllocationManager.LOCAL_ALLOCATIONS, 1)
        self.assertEqual(len(allocs), 1)
        self.assertNotEqual(allociter, None)
        try:
            # Try to fetch 2 more, which ought to succeed in full
            status, items = allociter.next_n(2)
            self.assertTrue(status)
            self.assertEqual(len(items), 2)
            allocs.extend(items)

            # Try 2 more, which should return only 1
            status, items = allociter.next_n(2)
            self.assertTrue(status)
            self.assertEqual(len(items), 1)
            allocs.extend(items)

            # Finally, the next fetch should fail
            status, items = allociter.next_n(2)
            self.assertFalse(status)
            self.assertEqual(len(items), 0)
        finally:
            allociter.destroy()
        # Check the resulting list
        self.assertTrue(allocMgrHelpers.compareAllocationStatusSequence(allocs, localAllocs))
コード例 #15
0
    def test_AllocationSubsetRemoteRemote(self):
        """
        Test that AllocationManager can split usesdevice allocations across
        the two remote domains.
        """
        # Launch a third domain; need to specify a different DMD so that it has
        # a unique ID for the DomainManager
        nb3, domainManager_3 = launchDomain(3, self._root,
                                            '/domain/DomainManager2.dmd.xml')
        self.__nodeBooters.append(nb3)

        # Launch device nodes on the two remote domains
        self.launchDeviceManager(
            "/nodes/MultiDomain1_node/DeviceManager.dcd.xml",
            domainManager=self._domainManager_2)
        self.launchDeviceManager(
            "/nodes/MultiDomain2_node/DeviceManager.dcd.xml",
            domainManager=domainManager_3)

        # Register second and third domains with first
        self._domainManager_1.registerRemoteDomainManager(
            self._domainManager_2)
        self._domainManager_1.registerRemoteDomainManager(domainManager_3)

        allocMgr_1 = self._domainManager_1._get_allocationMgr()
        allocMgr_2 = self._domainManager_2._get_allocationMgr()
        allocMgr_3 = domainManager_3._get_allocationMgr()

        # Check that the initial state of all allocations is empty
        self.assertEqual(allocMgr_1.allocations([]), [])
        self.assertEqual(allocMgr_1.localAllocations([]), [])
        self.assertEqual(allocMgr_2.allocations([]), [])
        self.assertEqual(allocMgr_2.localAllocations([]), [])
        self.assertEqual(allocMgr_3.allocations([]), [])
        self.assertEqual(allocMgr_3.localAllocations([]), [])

        # Make a couple of allocation requests that we know will have to be
        # split across the local and remote domains
        usescap = {'count': 1}
        requests = [
            allocMgrHelpers.createRequest('test_%d' % ii,
                                          properties.props_from_dict(usescap))
            for ii in range(2)
        ]

        # Both requests should be satisfied
        results = allocMgr_1.allocate(requests)
        self.assertEqual(len(requests), len(results))
        expected = set(r.requestID for r in requests)
        actual = set(r.requestID for r in results)
        self.assertEqual(expected, actual)

        # No allocation on the local domain
        allocations = allocMgr_1.localAllocations([])
        self.assertEqual(len(allocations), 0)

        # One allocation on the 1st remote domain
        allocations = allocMgr_2.localAllocations([])
        self.assertEqual(len(allocations), 1)

        # One allocation on the 2nd remote domain
        allocations = allocMgr_3.localAllocations([])
        self.assertEqual(len(allocations), 1)
コード例 #16
0
    def test_RemoteAllocations(self):
        nb1, execDevNode1 = self.launchDeviceManager(
            "/nodes/test_multiDomain_exec/DeviceManager.dcd.xml",
            domainManager=self._domainManager_1)
        nb2, basicDevNode1 = self.launchDeviceManager(
            "/nodes/test_multiDomain_uses/DeviceManager.dcd.xml",
            domainManager=self._domainManager_2)

        # Register second domain with first (no need to do both directions)
        self._domainManager_1.registerRemoteDomainManager(
            self._domainManager_2)

        allocMgr_1 = self._domainManager_1._get_allocationMgr()
        allocMgr_2 = self._domainManager_2._get_allocationMgr()

        # Check that the initial state of all allocations is empty
        self.assertEqual(allocMgr_1.allocations([]), [])
        self.assertEqual(allocMgr_1.localAllocations([]), [])
        self.assertEqual(allocMgr_2.allocations([]), [])
        self.assertEqual(allocMgr_2.localAllocations([]), [])

        # 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),
                                          sourceId='TestId'),
            allocMgrHelpers.createRequest('uses',
                                          properties.props_from_dict(usescap))
        ]
        results = dict((r.requestID, r) for r in allocMgr_1.allocate(requests))
        self.assertEqual(len(requests), len(results))
        usesId = results['uses'].allocationID
        execId = results['exec'].allocationID
        allocations = allocMgr_1.listAllocations(
            CF.AllocationManager.ALL_ALLOCATIONS, 100)[0]
        number_checks = 0
        for allocation in allocations:
            if allocation.allocationID == results['uses'].allocationID:
                self.assertEqual(allocation.sourceID, '')
                number_checks += 1
            else:
                self.assertEqual(allocation.sourceID, 'TestId')
                number_checks += 1
        self.assertEqual(number_checks, 2)

        # The first domain should report the full set of allocations, with only
        # the "exec" allocation showing up in the local allocations
        allocs = allocMgr_1.allocations([])
        self.assertEqual(len(allocs), len(requests))
        for status in allocs:
            if status.allocationID == usesId:
                resId = 'uses'
            elif status.allocationID == execId:
                resId = 'exec'
            else:
                self.fail('Unexpected allocation in results')
            self.assert_(
                allocMgrHelpers.compareAllocationStatus(
                    status, results[resId]))

        # Try to retrieve a local and remote allocation via allocations
        allocs = allocMgr_1.allocations([execId])
        self.assertEqual(len(allocs), 1)
        self.assert_(
            allocMgrHelpers.compareAllocationStatus(allocs[0],
                                                    results['exec']))
        allocs = allocMgr_1.allocations([usesId])
        self.assertEqual(len(allocs), 1)
        self.assert_(
            allocMgrHelpers.compareAllocationStatus(allocs[0],
                                                    results['uses']))

        # Make sure we can retrieve the local allocation via localAllocations
        allocs = allocMgr_1.localAllocations([execId])
        self.assertEqual(len(allocs), 1)
        self.assert_(
            allocMgrHelpers.compareAllocationStatus(allocs[0],
                                                    results['exec']))

        # Try to retrieve a remote allocation via localAllocations, and make
        # sure that the invalid ID causes an exception
        self.assertRaises(CF.AllocationManager.InvalidAllocationId,
                          allocMgr_1.localAllocations, [usesId])

        # Check the second domain, which should report just the 'uses'
        # allocation, but via both allocations and localAllocations
        allocs = allocMgr_2.allocations([])
        self.assertEqual(len(allocs), 1)
        self.assert_(
            allocMgrHelpers.compareAllocationStatus(allocs[0],
                                                    results['uses']))
        allocs = allocMgr_2.localAllocations([])
        self.assertEqual(len(allocs), 1)
        self.assert_(
            allocMgrHelpers.compareAllocationStatus(allocs[0],
                                                    results['uses']))

        # The second domain shouldn't know about the local 'exec' allocation
        self.assertRaises(CF.AllocationManager.InvalidAllocationId,
                          allocMgr_2.allocations, [execId])
        self.assertRaises(CF.AllocationManager.InvalidAllocationId,
                          allocMgr_2.localAllocations, [execId])

        # Deallocate the remote allocation and check that only the local 'exec'
        # allocation remains
        allocMgr_1.deallocate([usesId])
        allocs = allocMgr_1.allocations([])
        self.assertEqual(len(allocs), 1)
        self.assert_(
            allocMgrHelpers.compareAllocationStatus(allocs[0],
                                                    results['exec']))
        self.assertRaises(CF.AllocationManager.InvalidAllocationId,
                          allocMgr_1.allocations, [usesId])
        allocs = allocMgr_1.localAllocations([])
        self.assertEqual(len(allocs), 1)
        self.assert_(
            allocMgrHelpers.compareAllocationStatus(allocs[0],
                                                    results['exec']))

        # The remote domain should have nothing left
        self.assertEqual(allocMgr_2.allocations([]), [])
        self.assertEqual(allocMgr_2.localAllocations([]), [])
コード例 #17
0
    def test_RemoteAllocations(self):
        nb1, execDevNode1 = self.launchDeviceManager("/nodes/test_multiDomain_exec/DeviceManager.dcd.xml", domainManager=self._domainManager_1)
        nb2, basicDevNode1 = self.launchDeviceManager("/nodes/test_multiDomain_uses/DeviceManager.dcd.xml", domainManager=self._domainManager_2)

        # Register second domain with first (no need to do both directions)
        self._domainManager_1.registerRemoteDomainManager(self._domainManager_2)

        allocMgr_1 = self._domainManager_1._get_allocationMgr()
        allocMgr_2 = self._domainManager_2._get_allocationMgr()

        # Check that the initial state of all allocations is empty
        self.assertEqual(allocMgr_1.allocations([]), [])
        self.assertEqual(allocMgr_1.localAllocations([]), [])
        self.assertEqual(allocMgr_2.allocations([]), [])
        self.assertEqual(allocMgr_2.localAllocations([]), [])

        # 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),sourceId='TestId'),
                    allocMgrHelpers.createRequest('uses', properties.props_from_dict(usescap))]
        results = dict((r.requestID, r) for r in allocMgr_1.allocate(requests))
        self.assertEqual(len(requests), len(results))
        usesId = results['uses'].allocationID
        execId = results['exec'].allocationID
        allocations = allocMgr_1.listAllocations(CF.AllocationManager.ALL_ALLOCATIONS,100)[0]
        number_checks = 0
        for allocation in allocations:
            if allocation.allocationID == results['uses'].allocationID:
                self.assertEqual(allocation.sourceID,'')
                number_checks += 1
            else:
                self.assertEqual(allocation.sourceID,'TestId')
                number_checks += 1
        self.assertEqual(number_checks,2)

        # The first domain should report the full set of allocations, with only
        # the "exec" allocation showing up in the local allocations
        allocs = allocMgr_1.allocations([])
        self.assertEqual(len(allocs), len(requests))
        for status in allocs:
            if status.allocationID == usesId:
                resId = 'uses'
            elif status.allocationID == execId:
                resId = 'exec'
            else:
                self.fail('Unexpected allocation in results')
            self.assert_(allocMgrHelpers.compareAllocationStatus(status, results[resId]))

        # Try to retrieve a local and remote allocation via allocations
        allocs = allocMgr_1.allocations([execId])
        self.assertEqual(len(allocs), 1)
        self.assert_(allocMgrHelpers.compareAllocationStatus(allocs[0], results['exec']))
        allocs = allocMgr_1.allocations([usesId])
        self.assertEqual(len(allocs), 1)
        self.assert_(allocMgrHelpers.compareAllocationStatus(allocs[0], results['uses']))

        # Make sure we can retrieve the local allocation via localAllocations
        allocs = allocMgr_1.localAllocations([execId])
        self.assertEqual(len(allocs), 1)
        self.assert_(allocMgrHelpers.compareAllocationStatus(allocs[0], results['exec']))

        # Try to retrieve a remote allocation via localAllocations, and make
        # sure that the invalid ID causes an exception
        self.assertRaises(CF.AllocationManager.InvalidAllocationId, allocMgr_1.localAllocations, [usesId])

        # Check the second domain, which should report just the 'uses'
        # allocation, but via both allocations and localAllocations
        allocs = allocMgr_2.allocations([])
        self.assertEqual(len(allocs), 1)
        self.assert_(allocMgrHelpers.compareAllocationStatus(allocs[0], results['uses']))
        allocs = allocMgr_2.localAllocations([])
        self.assertEqual(len(allocs), 1)
        self.assert_(allocMgrHelpers.compareAllocationStatus(allocs[0], results['uses']))

        # The second domain shouldn't know about the local 'exec' allocation
        self.assertRaises(CF.AllocationManager.InvalidAllocationId, allocMgr_2.allocations, [execId])
        self.assertRaises(CF.AllocationManager.InvalidAllocationId, allocMgr_2.localAllocations, [execId])

        # Deallocate the remote allocation and check that only the local 'exec'
        # allocation remains
        allocMgr_1.deallocate([usesId])
        allocs = allocMgr_1.allocations([])
        self.assertEqual(len(allocs), 1)
        self.assert_(allocMgrHelpers.compareAllocationStatus(allocs[0], results['exec']))
        self.assertRaises(CF.AllocationManager.InvalidAllocationId, allocMgr_1.allocations, [usesId])
        allocs = allocMgr_1.localAllocations([])
        self.assertEqual(len(allocs), 1)
        self.assert_(allocMgrHelpers.compareAllocationStatus(allocs[0], results['exec']))

        # The remote domain should have nothing left
        self.assertEqual(allocMgr_2.allocations([]), [])
        self.assertEqual(allocMgr_2.localAllocations([]), [])
コード例 #18
0
    def test_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 = [
            allocMgrHelpers.createRequest(k, properties.props_from_dict(v))
            for k, v in request
        ]
        response = self._allocMgr.allocate(request)
        self.assertEqual(len(request), len(response))

        localAllocs = self._allocMgr.localAllocations([])

        # First, try to list more allocations than have been made, to make sure
        # no iterator is returned
        allocs, allociter = self._allocMgr.listAllocations(
            CF.AllocationManager.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._allocMgr.listAllocations(
            CF.AllocationManager.LOCAL_ALLOCATIONS, 1)
        self.assertEqual(len(allocs), 1)
        self.assertNotEqual(allociter, None)
        try:
            # There has to be at least one more allocation
            status, item = allociter.next_one()
            self.assertTrue(status)
            self.assertNotEqual(item, None)
            allocs.append(item)

            # Fetch the remainder
            while status:
                status, item = allociter.next_one()
                if status:
                    allocs.append(item)
        finally:
            allociter.destroy()
        # Check the resulting list
        self.assertTrue(
            allocMgrHelpers.compareAllocationStatusSequence(
                allocs, localAllocs))

        # Then try fetching by a higher count
        allocs, allociter = self._allocMgr.listAllocations(
            CF.AllocationManager.LOCAL_ALLOCATIONS, 1)
        self.assertEqual(len(allocs), 1)
        self.assertNotEqual(allociter, None)
        try:
            # Try to fetch 2 more, which ought to succeed in full
            status, items = allociter.next_n(2)
            self.assertTrue(status)
            self.assertEqual(len(items), 2)
            allocs.extend(items)

            # Try 2 more, which should return only 1
            status, items = allociter.next_n(2)
            self.assertTrue(status)
            self.assertEqual(len(items), 1)
            allocs.extend(items)

            # Finally, the next fetch should fail
            status, items = allociter.next_n(2)
            self.assertFalse(status)
            self.assertEqual(len(items), 0)
        finally:
            allociter.destroy()
        # Check the resulting list
        self.assertTrue(
            allocMgrHelpers.compareAllocationStatusSequence(
                allocs, localAllocs))