Exemplo n.º 1
0
def _move_operation_alloc_request(source_allocs, dest_alloc_req):
    """Given existing allocations for a source host and a new allocation
    request for a destination host, return a new allocation request that
    contains resources claimed against both source and destination, accounting
    for shared providers.

    Also accounts for a resize to the same host where the source and dest
    compute node resource providers are going to be the same. In that case
    we sum the resource allocations for the single provider.

    :param source_allocs: Dict, keyed by resource provider UUID, of resources
                          allocated on the source host
    :param dest_alloc_request: The allocation request for resources against the
                               destination host
    """
    LOG.debug("Doubling-up allocation request for move operation.")
    # Remove any allocations against resource providers that are
    # already allocated against on the source host (like shared storage
    # providers)
    cur_rp_uuids = set(source_allocs.keys())
    new_rp_uuids = set(a['resource_provider']['uuid']
                       for a in dest_alloc_req['allocations']) - cur_rp_uuids

    current_allocs = [{
        'resource_provider': {
            'uuid': cur_rp_uuid,
        },
        'resources': alloc['resources'],
    } for cur_rp_uuid, alloc in source_allocs.items()]
    new_alloc_req = {'allocations': current_allocs}
    for alloc in dest_alloc_req['allocations']:
        if alloc['resource_provider']['uuid'] in new_rp_uuids:
            new_alloc_req['allocations'].append(alloc)
        elif not new_rp_uuids:
            # If there are no new_rp_uuids that means we're resizing to
            # the same host so we need to sum the allocations for
            # the compute node (and possibly shared providers) using both
            # the current and new allocations.
            # Note that we sum the allocations rather than take the max per
            # resource class between the current and new allocations because
            # the compute node/resource tracker is going to adjust for
            # decrementing any old allocations as necessary, the scheduler
            # shouldn't make assumptions about that.
            for current_alloc in current_allocs:
                # Find the matching resource provider allocations by UUID.
                if (current_alloc['resource_provider']['uuid'] ==
                        alloc['resource_provider']['uuid']):
                    # Now sum the current allocation resource amounts with
                    # the new allocation resource amounts.
                    scheduler_utils.merge_resources(current_alloc['resources'],
                                                    alloc['resources'])

    LOG.debug(
        "New allocation request containing both source and "
        "destination hosts in move operation: %s", new_alloc_req)
    return new_alloc_req
Exemplo n.º 2
0
 def test_merge_resources_zero(self):
     """Test 0 value resources are ignored."""
     resources = {
         'VCPU': 1, 'MEMORY_MB': 1024,
     }
     new_resources = {
         'VCPU': 2, 'MEMORY_MB': 2048, 'DISK_GB': 0,
     }
     # The result should not include the zero valued resource.
     doubled = {
         'VCPU': 3, 'MEMORY_MB': 3072,
     }
     utils.merge_resources(resources, new_resources)
     self.assertEqual(doubled, resources)
Exemplo n.º 3
0
 def test_merge_resources_zero(self):
     """Test 0 value resources are ignored."""
     resources = {
         'VCPU': 1, 'MEMORY_MB': 1024,
     }
     new_resources = {
         'VCPU': 2, 'MEMORY_MB': 2048, 'DISK_GB': 0,
     }
     # The result should not include the zero valued resource.
     doubled = {
         'VCPU': 3, 'MEMORY_MB': 3072,
     }
     utils.merge_resources(resources, new_resources)
     self.assertEqual(doubled, resources)
Exemplo n.º 4
0
 def test_merge_resources_original_zeroes(self):
     """Confirm that merging that result in a zero in the original
     excludes the zeroed resource class.
     """
     resources = {
         'VCPU': 3, 'MEMORY_MB': 1023, 'DISK_GB': 1,
     }
     new_resources = {
         'VCPU': 1, 'MEMORY_MB': 512, 'DISK_GB': 1,
     }
     merged = {
         'VCPU': 2, 'MEMORY_MB': 511,
     }
     utils.merge_resources(resources, new_resources, -1)
     self.assertEqual(merged, resources)
Exemplo n.º 5
0
 def test_merge_resources_original_zeroes(self):
     """Confirm that merging that result in a zero in the original
     excludes the zeroed resource class.
     """
     resources = {
         'VCPU': 3, 'MEMORY_MB': 1023, 'DISK_GB': 1,
     }
     new_resources = {
         'VCPU': 1, 'MEMORY_MB': 512, 'DISK_GB': 1,
     }
     merged = {
         'VCPU': 2, 'MEMORY_MB': 511,
     }
     utils.merge_resources(resources, new_resources, -1)
     self.assertEqual(merged, resources)
Exemplo n.º 6
0
 def test_merge_resources(self):
     resources = {
         'VCPU': 1, 'MEMORY_MB': 1024,
     }
     new_resources = {
         'VCPU': 2, 'MEMORY_MB': 2048, 'CUSTOM_FOO': 1,
     }
     doubled = {
         'VCPU': 3, 'MEMORY_MB': 3072, 'CUSTOM_FOO': 1,
     }
     saved_orig = dict(resources)
     utils.merge_resources(resources, new_resources)
     # Check to see that we've doubled our resources
     self.assertEqual(doubled, resources)
     # and then removed those doubled resources
     utils.merge_resources(resources, saved_orig, -1)
     self.assertEqual(new_resources, resources)
Exemplo n.º 7
0
 def test_merge_resources(self):
     resources = {
         'VCPU': 1, 'MEMORY_MB': 1024,
     }
     new_resources = {
         'VCPU': 2, 'MEMORY_MB': 2048, 'CUSTOM_FOO': 1,
     }
     doubled = {
         'VCPU': 3, 'MEMORY_MB': 3072, 'CUSTOM_FOO': 1,
     }
     saved_orig = dict(resources)
     utils.merge_resources(resources, new_resources)
     # Check to see that we've doubled our resources
     self.assertEqual(doubled, resources)
     # and then removed those doubled resources
     utils.merge_resources(resources, saved_orig, -1)
     self.assertEqual(new_resources, resources)