Skip to content

Commit 83b7e0a

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Omit resource inventories from placement update if zero" into stable/victoria
2 parents cb4963b + c3a0969 commit 83b7e0a

File tree

2 files changed

+72
-13
lines changed

2 files changed

+72
-13
lines changed

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21177,6 +21177,54 @@ def test_update_provider_tree(self):
2117721177
for trait in ['HW_CPU_X86_AVX512F', 'HW_CPU_X86_BMI']:
2117821178
self.assertIn(trait, self.pt.data(self.cn_rp['uuid']).traits)
2117921179

21180+
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_gpu_inventories')
21181+
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
21182+
'_get_cpu_feature_traits',
21183+
new=mock.Mock(return_value=cpu_traits))
21184+
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_local_gb_info',
21185+
new=mock.Mock(return_value={'total': 0}))
21186+
@mock.patch('nova.virt.libvirt.host.Host.get_memory_mb_total',
21187+
new=mock.Mock(return_value=0))
21188+
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_pcpu_available',
21189+
new=mock.Mock(return_value=range(0)))
21190+
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_vcpu_available',
21191+
new=mock.Mock(return_value=range(0)))
21192+
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
21193+
'_update_provider_tree_for_pcpu',
21194+
new=mock.Mock())
21195+
def test_update_provider_tree_zero_total(self, mock_gpu_invs):
21196+
# Verify that we omit various resources from inventory when there are
21197+
# zero total quantity of those resources. Placement does not allow
21198+
# inventory updates with total=0 as they fail API schema validation.
21199+
21200+
# Use total=0 for vgpus.
21201+
gpu_inventory_dicts = {
21202+
'pci_0000_06_00_0': {'total': 0,
21203+
'max_unit': 16,
21204+
'min_unit': 1,
21205+
'step_size': 1,
21206+
'reserved': 0,
21207+
'allocation_ratio': 1.0,
21208+
},
21209+
}
21210+
mock_gpu_invs.return_value = gpu_inventory_dicts
21211+
# Use an empty list for vpmems.
21212+
self.driver._vpmems_by_rc = {'CUSTOM_PMEM_NAMESPACE_4GB': []}
21213+
# Before we update_provider_tree, we have 2 providers from setUp():
21214+
# self.cn_rp and self.shared_rp and they are both empty {}.
21215+
self.assertEqual(2, len(self.pt.get_provider_uuids()))
21216+
# Update the provider tree.
21217+
self.driver.update_provider_tree(self.pt, self.cn_rp['name'])
21218+
# After we update_provider_tree, we should still have 2 providers
21219+
# because VGPU has total=0 and we would skip adding a child provider
21220+
# for it.
21221+
self.assertEqual(2, len(self.pt.get_provider_uuids()))
21222+
# All providers should have an empty dict because (1) we never updated
21223+
# the self.shared_rp provider and (2) the other 2 providers have zero
21224+
# for resource totals.
21225+
for uuid in self.pt.get_provider_uuids():
21226+
self.assertEqual({}, self.pt.data(uuid).inventory)
21227+
2118021228
def test_update_provider_tree_with_vgpus(self):
2118121229
pci_devices = ['pci_0000_06_00_0', 'pci_0000_07_00_0']
2118221230
gpu_inventory_dicts = {

nova/virt/libvirt/driver.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7786,16 +7786,17 @@ def update_provider_tree(self, provider_tree, nodename, allocations=None):
77867786
resources: ty.Dict[str, ty.Set['objects.Resource']] = (
77877787
collections.defaultdict(set)
77887788
)
7789-
result = {
7790-
orc.MEMORY_MB: {
7789+
7790+
result = {}
7791+
if memory_mb:
7792+
result[orc.MEMORY_MB] = {
77917793
'total': memory_mb,
77927794
'min_unit': 1,
77937795
'max_unit': memory_mb,
77947796
'step_size': 1,
77957797
'allocation_ratio': ratios[orc.MEMORY_MB],
77967798
'reserved': CONF.reserved_host_memory_mb,
7797-
},
7798-
}
7799+
}
77997800

78007801
# NOTE(stephenfin): We have to optionally report these since placement
78017802
# forbids reporting inventory with total=0
@@ -7836,15 +7837,17 @@ def update_provider_tree(self, provider_tree, nodename, allocations=None):
78367837
# compute RP once the issues from bug #1784020 have been resolved.
78377838
if provider_tree.has_sharing_provider(orc.DISK_GB):
78387839
LOG.debug('Ignoring sharing provider - see bug #1784020')
7839-
result[orc.DISK_GB] = {
7840-
'total': disk_gb,
7841-
'min_unit': 1,
7842-
'max_unit': disk_gb,
7843-
'step_size': 1,
7844-
'allocation_ratio': ratios[orc.DISK_GB],
7845-
'reserved': (self._get_reserved_host_disk_gb_from_config() +
7846-
self._get_disk_size_reserved_for_image_cache()),
7847-
}
7840+
7841+
if disk_gb:
7842+
result[orc.DISK_GB] = {
7843+
'total': disk_gb,
7844+
'min_unit': 1,
7845+
'max_unit': disk_gb,
7846+
'step_size': 1,
7847+
'allocation_ratio': ratios[orc.DISK_GB],
7848+
'reserved': (self._get_reserved_host_disk_gb_from_config() +
7849+
self._get_disk_size_reserved_for_image_cache()),
7850+
}
78487851

78497852
# TODO(sbauza): Use traits to providing vGPU types. For the moment,
78507853
# it will be only documentation support by explaining to use
@@ -7879,6 +7882,10 @@ def _update_provider_tree_for_vpmems(self, provider_tree, nodename,
78797882
"""Update resources and inventory for vpmems in provider tree."""
78807883
prov_data = provider_tree.data(nodename)
78817884
for rc, vpmems in self._vpmems_by_rc.items():
7885+
# Skip (and omit) inventories with total=0 because placement does
7886+
# not allow setting total=0 for inventory.
7887+
if not len(vpmems):
7888+
continue
78827889
inventory[rc] = {
78837890
'total': len(vpmems),
78847891
'max_unit': len(vpmems),
@@ -7991,6 +7998,10 @@ def _ensure_pgpu_providers(inventories_dict, provider_tree, nodename):
79917998
# Dict of PGPU RPs keyed by their libvirt PCI name
79927999
pgpu_rps = {}
79938000
for pgpu_dev_id, inventory in inventories_dict.items():
8001+
# Skip (and omit) inventories with total=0 because placement does
8002+
# not allow setting total=0 for inventory.
8003+
if not inventory['total']:
8004+
continue
79948005
# For each physical GPU, we make sure to have a child provider
79958006
pgpu_rp_name = '%s_%s' % (nodename, pgpu_dev_id)
79968007
if not provider_tree.exists(pgpu_rp_name):

0 commit comments

Comments
 (0)