Skip to content

Commit c28494f

Browse files
pshchelosbauza
authored andcommitted
Use configuration for single enabled mdev type
Even when having specified a single mdev type, operator still might want to expose only one of available mdev-capable PCI devices to users, or use a custom resource class for it. NOTE(sbauza): That patch isn't changing the current behaviour (you can see the tests) but it just removes a weird limitation (that I wrote, sorry folks !) Co-Authored-By: Sylvain Bauza <[email protected]> Change-Id: I9f42410e407902b2f562adaa506f14cbc69898d4
1 parent 1738b52 commit c28494f

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26374,11 +26374,11 @@ def test_get_supported_vgpu_types(self, mock_warning):
2637426374
self.flags(enabled_mdev_types=['nvidia-11'], group='devices')
2637526375
self.assertEqual(['nvidia-11'], drvr._get_supported_vgpu_types())
2637626376
# Given we only support one vGPU type, we don't have any map for PCI
26377-
# devices or mdev classes *yet*
26377+
# devices or mdev classes *yet* if we don't have a vgpu type section.
2637826378
self.assertEqual({}, drvr.pgpu_type_mapping)
2637926379
self.assertEqual({}, drvr.mdev_class_mapping)
2638026380
# Remember, we only support the VGPU resource class if we only have
26381-
# one needed vGPU type.
26381+
# one needed vGPU type without a specific vgpu type section.
2638226382
self.assertEqual({orc.VGPU}, drvr.mdev_classes)
2638326383
# Since the operator wanted to only support one type, it's fine to not
2638426384
# provide config groups
@@ -26461,6 +26461,25 @@ def test_get_supported_vgpu_types_registering_dynamic_opts(self, rdo):
2646126461
# be the second time that register_dynamic_opts() will be called.
2646226462
rdo.assert_has_calls([mock.call(CONF), mock.call(CONF)])
2646326463

26464+
@mock.patch.object(libvirt_driver.LOG, 'warning')
26465+
def test_get_supported_vgpu_types_with_a_single_type(self, mock_warning):
26466+
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
26467+
# Just add a single type...
26468+
self.flags(enabled_mdev_types=['nvidia-11'], group='devices')
26469+
# we need to call the below again to ensure the updated
26470+
# 'device_addresses' value is read and the new groups created
26471+
nova.conf.devices.register_dynamic_opts(CONF)
26472+
# ... But then use the type group for telling which pGPU to use.
26473+
self.flags(device_addresses=['0000:84:00.0'], group='mdev_nvidia-11')
26474+
self.flags(mdev_class='CUSTOM_NOTVGPU', group='mdev_nvidia-11')
26475+
26476+
self.assertEqual(['nvidia-11'], drvr._get_supported_vgpu_types())
26477+
self.assertEqual({'0000:84:00.0': 'nvidia-11'}, drvr.pgpu_type_mapping)
26478+
self.assertEqual({'0000:84:00.0': 'CUSTOM_NOTVGPU'},
26479+
drvr.mdev_class_mapping)
26480+
self.assertEqual({'CUSTOM_NOTVGPU'}, drvr.mdev_classes)
26481+
mock_warning.assert_not_called()
26482+
2646426483
def test_get_vgpu_type_per_pgpu(self):
2646526484
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
2646626485
device = 'pci_0000_84_00_0'
@@ -26471,7 +26490,17 @@ def test_get_vgpu_type_per_pgpu(self):
2647126490
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
2647226491
self.assertEqual('nvidia-11', drvr._get_vgpu_type_per_pgpu(device))
2647326492

26474-
# Now, make sure we provide the right vGPU type for the device
26493+
# But this also works if we add a specific type group
26494+
self.flags(enabled_mdev_types=['nvidia-11'], group='devices')
26495+
nova.conf.devices.register_dynamic_opts(CONF)
26496+
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
26497+
# we default to directly provide the type for all devices...
26498+
self.assertEqual('nvidia-11', drvr._get_vgpu_type_per_pgpu(device))
26499+
# ... even the ones we haven't provided yet by device_addresses
26500+
self.assertEqual('nvidia-11',
26501+
drvr._get_vgpu_type_per_pgpu('pci_0000_85_00_0'))
26502+
26503+
# Now, use two types instead of one.
2647526504
self.flags(enabled_mdev_types=['nvidia-11', 'nvidia-12'],
2647626505
group='devices')
2647726506
# we need to call the below again to ensure the updated

nova/virt/libvirt/driver.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7930,8 +7930,7 @@ def _get_supported_vgpu_types(self):
79307930

79317931
# Make sure we register all the types as the compute service could
79327932
# be calling this method before init_host()
7933-
if len(CONF.devices.enabled_mdev_types) > 1:
7934-
nova.conf.devices.register_dynamic_opts(CONF)
7933+
nova.conf.devices.register_dynamic_opts(CONF)
79357934

79367935
for vgpu_type in CONF.devices.enabled_mdev_types:
79377936
group = getattr(CONF, 'mdev_%s' % vgpu_type, None)
@@ -7955,9 +7954,11 @@ def _get_supported_vgpu_types(self):
79557954
# support only the first type.
79567955
self.pgpu_type_mapping.clear()
79577956
self.mdev_class_mapping.clear()
7958-
# Given we only have one type, we default to only support the
7959-
# VGPU resource class.
7960-
self.mdev_classes = {orc.VGPU}
7957+
first_group = getattr(CONF, 'mdev_%s' % first_type, None)
7958+
if first_group is None:
7959+
self.mdev_classes = {orc.VGPU}
7960+
else:
7961+
self.mdev_classes = {first_group.mdev_class}
79617962
return [first_type]
79627963
mdev_class = group.mdev_class
79637964
for device_address in group.device_addresses:
@@ -8011,9 +8012,11 @@ def _get_vgpu_type_per_pgpu(self, device_address):
80118012
return
80128013

80138014
if len(self.supported_vgpu_types) == 1:
8014-
# The operator wanted to only support one single type so we can
8015-
# blindly return it for every single pGPU
8016-
return self.supported_vgpu_types[0]
8015+
first_type = self.supported_vgpu_types[0]
8016+
group = getattr(CONF, 'mdev_%s' % first_type, None)
8017+
if group is None or not group.device_addresses:
8018+
return first_type
8019+
80178020
device_address = self._get_pci_id_from_libvirt_name(device_address)
80188021
if not device_address:
80198022
return

0 commit comments

Comments
 (0)