Delete _normalize_inventory_from_cn_obj

With Ib62ac0b692eb92a2ed364ec9f486ded05def39ad and the
get_inventory method gone nothing uses this so we can
remove it now.

Change-Id: I3f55e09641465279b8b92551a2302219fe6fc5ca
This commit is contained in:
Matt Riedemann 2019-11-07 17:25:11 -05:00
parent c80912866f
commit 112999e1dd
2 changed files with 0 additions and 170 deletions

View File

@ -22,7 +22,6 @@ import collections
import copy
from keystoneauth1 import exceptions as ks_exc
import os_resource_classes as orc
import os_traits
from oslo_log import log as logging
from oslo_serialization import jsonutils
@ -82,52 +81,6 @@ def _instance_is_live_migrating(instance):
return False
# TODO(mriedem): Remove this now that get_inventory isn't being used anymore
def _normalize_inventory_from_cn_obj(inv_data, cn):
"""Helper function that injects various information from a compute node
object into the inventory dict returned from the virt driver's
get_inventory() method. This function allows us to marry information like
*_allocation_ratio and reserved memory amounts that are in the
compute_nodes DB table and that the virt driver doesn't know about with the
information the virt driver *does* know about.
Note that if the supplied inv_data contains allocation_ratio, reserved or
other fields, we DO NOT override the value with that of the compute node.
This is to ensure that the virt driver is the single source of truth
regarding inventory information. For instance, the Ironic virt driver will
always return a very specific inventory with allocation_ratios pinned to
1.0.
:param inv_data: Dict, keyed by resource class, of inventory information
returned from virt driver's get_inventory() method
:param compute_node: `objects.ComputeNode` describing the compute node
"""
if orc.VCPU in inv_data:
cpu_inv = inv_data[orc.VCPU]
if 'allocation_ratio' not in cpu_inv:
cpu_inv['allocation_ratio'] = cn.cpu_allocation_ratio
if 'reserved' not in cpu_inv:
cpu_inv['reserved'] = CONF.reserved_host_cpus
if orc.MEMORY_MB in inv_data:
mem_inv = inv_data[orc.MEMORY_MB]
if 'allocation_ratio' not in mem_inv:
mem_inv['allocation_ratio'] = cn.ram_allocation_ratio
if 'reserved' not in mem_inv:
mem_inv['reserved'] = CONF.reserved_host_memory_mb
if orc.DISK_GB in inv_data:
disk_inv = inv_data[orc.DISK_GB]
if 'allocation_ratio' not in disk_inv:
disk_inv['allocation_ratio'] = cn.disk_allocation_ratio
if 'reserved' not in disk_inv:
# TODO(johngarbutt) We should either move to reserved_host_disk_gb
# or start tracking DISK_MB.
reserved_mb = CONF.reserved_host_disk_mb
reserved_gb = compute_utils.convert_mb_to_ceil_gb(reserved_mb)
disk_inv['reserved'] = reserved_gb
class ResourceTracker(object):
"""Compute helper class for keeping track of resource usage as instances
are built and destroyed.

View File

@ -1893,129 +1893,6 @@ class TestUpdateComputeNode(BaseTestCase):
self.assertEqual(1.0, changes[attr_name])
class TestNormalizatInventoryFromComputeNode(test.NoDBTestCase):
def test_normalize_libvirt(self):
self.flags(reserved_host_disk_mb=100,
reserved_host_memory_mb=10,
reserved_host_cpus=1)
vcpus = 24
memory_mb = 1024
disk_gb = 200
cn = objects.ComputeNode(
mock.sentinel.ctx,
ram_allocation_ratio=1.5,
cpu_allocation_ratio=16.0,
disk_allocation_ratio=1.0,
)
# What we get back from libvirt driver, for instance, doesn't contain
# allocation_ratio or reserved amounts for some resources. Verify that
# the information on the compute node fills in this information...
inv = {
orc.VCPU: {
'total': vcpus,
'min_unit': 1,
'max_unit': vcpus,
'step_size': 1,
},
orc.MEMORY_MB: {
'total': memory_mb,
'min_unit': 1,
'max_unit': memory_mb,
'step_size': 1,
},
orc.DISK_GB: {
'total': disk_gb,
'min_unit': 1,
'max_unit': disk_gb,
'step_size': 1,
},
}
expected = {
orc.VCPU: {
'total': vcpus,
'reserved': 1,
'min_unit': 1,
'max_unit': vcpus,
'step_size': 1,
'allocation_ratio': 16.0,
},
orc.MEMORY_MB: {
'total': memory_mb,
'reserved': 10,
'min_unit': 1,
'max_unit': memory_mb,
'step_size': 1,
'allocation_ratio': 1.5,
},
orc.DISK_GB: {
'total': disk_gb,
'reserved': 1, # Rounded up from CONF.reserved_host_disk_mb
'min_unit': 1,
'max_unit': disk_gb,
'step_size': 1,
'allocation_ratio': 1.0,
},
}
self.assertNotEqual(expected, inv)
resource_tracker._normalize_inventory_from_cn_obj(inv, cn)
self.assertEqual(expected, inv)
def test_normalize_ironic(self):
"""Test that when normalizing the return from Ironic virt driver's
get_inventory() method, we don't overwrite the information that the
virt driver gave us.
"""
self.flags(reserved_host_disk_mb=100,
reserved_host_memory_mb=10,
reserved_host_cpus=1)
vcpus = 24
memory_mb = 1024
disk_gb = 200
# We will make sure that these field values do NOT override what the
# Ironic virt driver sets (which is, for example, that allocation
# ratios are all 1.0 for Ironic baremetal nodes)
cn = objects.ComputeNode(
mock.sentinel.ctx,
ram_allocation_ratio=1.5,
cpu_allocation_ratio=16.0,
disk_allocation_ratio=1.0,
)
# What we get back from Ironic driver contains fully-filled-out info
# blocks for VCPU, MEMORY_MB, DISK_GB and the custom resource class
# inventory items
inv = {
orc.VCPU: {
'total': vcpus,
'reserved': 0,
'min_unit': 1,
'max_unit': vcpus,
'step_size': 1,
'allocation_ratio': 1.0,
},
orc.MEMORY_MB: {
'total': memory_mb,
'reserved': 0,
'min_unit': 1,
'max_unit': memory_mb,
'step_size': 1,
'allocation_ratio': 1.0,
},
orc.DISK_GB: {
'total': disk_gb,
'reserved': 0,
'min_unit': 1,
'max_unit': disk_gb,
'step_size': 1,
'allocation_ratio': 1.0,
},
}
# We are expecting that NOTHING changes after calling the normalization
# function
expected = copy.deepcopy(inv)
resource_tracker._normalize_inventory_from_cn_obj(inv, cn)
self.assertEqual(expected, inv)
class TestInstanceClaim(BaseTestCase):
def setUp(self):