def _remove_host_allocations(self, host, node): """Removes instance allocations against the given host from Placement :param host: The name of the host. :param node: The name of the node. """ # Get the compute node object since we need the UUID. # TODO(mriedem): If the result of select_destinations eventually # returns the compute node uuid, we wouldn't need to look it # up via host/node and we can save some time. try: compute_node = objects.ComputeNode.get_by_host_and_nodename( self.context, host, node) except exception.ComputeHostNotFound: # This shouldn't happen, but we're being careful. LOG.info('Unable to remove instance allocations from host %s ' 'and node %s since it was not found.', host, node, instance=self.instance) return # Calculate the resource class amounts to subtract from the allocations # on the node based on the instance flavor. resources = scheduler_utils.resources_from_flavor( self.instance, self.instance.flavor) # Now remove the allocations for our instance against that node. # Note that this does not remove allocations against any other node # or shared resource provider, it's just undoing what the scheduler # allocated for the given (destination) node. self.scheduler_client.reportclient.\ remove_provider_from_instance_allocation( self.context, self.instance.uuid, compute_node.uuid, self.instance.user_id, self.instance.project_id, resources)
def test_resources_from_flavor_with_override(self, mock_is_bfv): flavor = objects.Flavor( vcpus=1, memory_mb=1024, root_gb=10, ephemeral_gb=5, swap=1024, extra_specs={ # Replace 'resources:VCPU': '2', # Sum up 'resources42:SRIOV_NET_VF': '1', 'resources24:SRIOV_NET_VF': '2', # Ignore 'some:bogus': 'value', # Custom 'resources:CUSTOM_THING': '123', # Ignore 'trait:CUSTOM_GOLD': 'required', # Delete standard 'resources86:MEMORY_MB': 0, # Standard and custom zeroes don't make it through 'resources:IPV4_ADDRESS': 0, 'resources:CUSTOM_FOO': 0 }) instance = objects.Instance() expected = { 'VCPU': 2, 'DISK_GB': 16, 'CUSTOM_THING': 123, 'SRIOV_NET_VF': 3, } actual = utils.resources_from_flavor(instance, flavor) self.assertEqual(expected, actual)
def _remove_host_allocations(self, host, node): """Removes instance allocations against the given host from Placement :param host: The name of the host. :param node: The name of the node. """ # Get the compute node object since we need the UUID. # TODO(mriedem): If the result of select_destinations eventually # returns the compute node uuid, we wouldn't need to look it # up via host/node and we can save some time. try: compute_node = objects.ComputeNode.get_by_host_and_nodename( self.context, host, node) except exception.ComputeHostNotFound: # This shouldn't happen, but we're being careful. LOG.info('Unable to remove instance allocations from host %s ' 'and node %s since it was not found.', host, node, instance=self.instance) return # Calculate the resource class amounts to subtract from the allocations # on the node based on the instance flavor. resources = scheduler_utils.resources_from_flavor( self.instance, self.instance.flavor) # Now remove the allocations for our instance against that node. # Note that this does not remove allocations against any other node # or shared resource provider, it's just undoing what the scheduler # allocated for the given (destination) node. self.scheduler_client.reportclient.\ remove_provider_from_instance_allocation( self.context, self.instance.uuid, compute_node.uuid, self.instance.user_id, self.instance.project_id, resources)
def test_resources_from_flavor_with_override(self): flavor = objects.Flavor( vcpus=1, memory_mb=1024, root_gb=10, ephemeral_gb=5, swap=1024, extra_specs={ # Replace 'resources:VCPU': '2', # Sum up 'resources42:SRIOV_NET_VF': '1', 'resources24:SRIOV_NET_VF': '2', # Ignore 'some:bogus': 'value', # Custom 'resources:CUSTOM_THING': '123', # Ignore 'trait:CUSTOM_GOLD': 'required', # Delete standard 'resources86:MEMORY_MB': 0, # Standard and custom zeroes don't make it through 'resources:IPV4_ADDRESS': 0, 'resources:CUSTOM_FOO': 0, 'group_policy': 'none'}) instance = objects.Instance() expected = { 'VCPU': 2, 'DISK_GB': 16, 'CUSTOM_THING': 123, 'SRIOV_NET_VF': 3, } actual = utils.resources_from_flavor(instance, flavor) self.assertEqual(expected, actual)
def _instance_to_allocations_dict(instance): """Given an `objects.Instance` object, return a dict, keyed by resource class of the amount used by the instance. :param instance: `objects.Instance` object to translate """ alloc_dict = scheduler_utils.resources_from_flavor(instance, instance.flavor) # Remove any zero allocations. return {key: val for key, val in alloc_dict.items() if val}
def test_resources_from_flavor_bfv(self, mock_is_bfv): flavor = objects.Flavor(vcpus=1, memory_mb=1024, root_gb=10, ephemeral_gb=5, swap=1024, extra_specs={}) instance = objects.Instance() expected = { 'VCPU': 1, 'MEMORY_MB': 1024, 'DISK_GB': 6, # No root disk... } actual = utils.resources_from_flavor(instance, flavor) self.assertEqual(expected, actual)
def test_resources_from_flavor_bfv(self, mock_is_bfv): flavor = objects.Flavor(vcpus=1, memory_mb=1024, root_gb=10, ephemeral_gb=5, swap=1024, extra_specs={}) instance = objects.Instance() expected = { 'VCPU': 1, 'MEMORY_MB': 1024, 'DISK_GB': 6, # No root disk... } actual = utils.resources_from_flavor(instance, flavor) self.assertEqual(expected, actual)
def test_resources_from_flavor_with_override(self, mock_is_bfv): flavor = objects.Flavor(vcpus=1, memory_mb=1024, root_gb=10, ephemeral_gb=5, swap=1024, extra_specs={'resources:VCPU': '2'}) instance = objects.Instance() expected = { 'VCPU': 2, 'MEMORY_MB': 1024, 'DISK_GB': 16, } actual = utils.resources_from_flavor(instance, flavor) self.assertEqual(expected, actual)
def test_resources_from_flavor_with_override(self, mock_is_bfv): flavor = objects.Flavor(vcpus=1, memory_mb=1024, root_gb=10, ephemeral_gb=5, swap=1024, extra_specs={'resources:VCPU': '2'}) instance = objects.Instance() expected = { 'VCPU': 2, 'MEMORY_MB': 1024, 'DISK_GB': 16, } actual = utils.resources_from_flavor(instance, flavor) self.assertEqual(expected, actual)