Skip to content

Commit 3e108ef

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Use configuration for single enabled mdev type"
2 parents d1309c4 + c28494f commit 3e108ef

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
@@ -26486,11 +26486,11 @@ def test_get_supported_vgpu_types(self, mock_warning):
2648626486
self.flags(enabled_mdev_types=['nvidia-11'], group='devices')
2648726487
self.assertEqual(['nvidia-11'], drvr._get_supported_vgpu_types())
2648826488
# Given we only support one vGPU type, we don't have any map for PCI
26489-
# devices or mdev classes *yet*
26489+
# devices or mdev classes *yet* if we don't have a vgpu type section.
2649026490
self.assertEqual({}, drvr.pgpu_type_mapping)
2649126491
self.assertEqual({}, drvr.mdev_class_mapping)
2649226492
# Remember, we only support the VGPU resource class if we only have
26493-
# one needed vGPU type.
26493+
# one needed vGPU type without a specific vgpu type section.
2649426494
self.assertEqual({orc.VGPU}, drvr.mdev_classes)
2649526495
# Since the operator wanted to only support one type, it's fine to not
2649626496
# provide config groups
@@ -26573,6 +26573,25 @@ def test_get_supported_vgpu_types_registering_dynamic_opts(self, rdo):
2657326573
# be the second time that register_dynamic_opts() will be called.
2657426574
rdo.assert_has_calls([mock.call(CONF), mock.call(CONF)])
2657526575

26576+
@mock.patch.object(libvirt_driver.LOG, 'warning')
26577+
def test_get_supported_vgpu_types_with_a_single_type(self, mock_warning):
26578+
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
26579+
# Just add a single type...
26580+
self.flags(enabled_mdev_types=['nvidia-11'], group='devices')
26581+
# we need to call the below again to ensure the updated
26582+
# 'device_addresses' value is read and the new groups created
26583+
nova.conf.devices.register_dynamic_opts(CONF)
26584+
# ... But then use the type group for telling which pGPU to use.
26585+
self.flags(device_addresses=['0000:84:00.0'], group='mdev_nvidia-11')
26586+
self.flags(mdev_class='CUSTOM_NOTVGPU', group='mdev_nvidia-11')
26587+
26588+
self.assertEqual(['nvidia-11'], drvr._get_supported_vgpu_types())
26589+
self.assertEqual({'0000:84:00.0': 'nvidia-11'}, drvr.pgpu_type_mapping)
26590+
self.assertEqual({'0000:84:00.0': 'CUSTOM_NOTVGPU'},
26591+
drvr.mdev_class_mapping)
26592+
self.assertEqual({'CUSTOM_NOTVGPU'}, drvr.mdev_classes)
26593+
mock_warning.assert_not_called()
26594+
2657626595
def test_get_vgpu_type_per_pgpu(self):
2657726596
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
2657826597
device = 'pci_0000_84_00_0'
@@ -26583,7 +26602,17 @@ def test_get_vgpu_type_per_pgpu(self):
2658326602
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
2658426603
self.assertEqual('nvidia-11', drvr._get_vgpu_type_per_pgpu(device))
2658526604

26586-
# Now, make sure we provide the right vGPU type for the device
26605+
# But this also works if we add a specific type group
26606+
self.flags(enabled_mdev_types=['nvidia-11'], group='devices')
26607+
nova.conf.devices.register_dynamic_opts(CONF)
26608+
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
26609+
# we default to directly provide the type for all devices...
26610+
self.assertEqual('nvidia-11', drvr._get_vgpu_type_per_pgpu(device))
26611+
# ... even the ones we haven't provided yet by device_addresses
26612+
self.assertEqual('nvidia-11',
26613+
drvr._get_vgpu_type_per_pgpu('pci_0000_85_00_0'))
26614+
26615+
# Now, use two types instead of one.
2658726616
self.flags(enabled_mdev_types=['nvidia-11', 'nvidia-12'],
2658826617
group='devices')
2658926618
# 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
@@ -7965,8 +7965,7 @@ def _get_supported_vgpu_types(self):
79657965

79667966
# Make sure we register all the types as the compute service could
79677967
# be calling this method before init_host()
7968-
if len(CONF.devices.enabled_mdev_types) > 1:
7969-
nova.conf.devices.register_dynamic_opts(CONF)
7968+
nova.conf.devices.register_dynamic_opts(CONF)
79707969

79717970
for vgpu_type in CONF.devices.enabled_mdev_types:
79727971
group = getattr(CONF, 'mdev_%s' % vgpu_type, None)
@@ -7990,9 +7989,11 @@ def _get_supported_vgpu_types(self):
79907989
# support only the first type.
79917990
self.pgpu_type_mapping.clear()
79927991
self.mdev_class_mapping.clear()
7993-
# Given we only have one type, we default to only support the
7994-
# VGPU resource class.
7995-
self.mdev_classes = {orc.VGPU}
7992+
first_group = getattr(CONF, 'mdev_%s' % first_type, None)
7993+
if first_group is None:
7994+
self.mdev_classes = {orc.VGPU}
7995+
else:
7996+
self.mdev_classes = {first_group.mdev_class}
79967997
return [first_type]
79977998
mdev_class = group.mdev_class
79987999
for device_address in group.device_addresses:
@@ -8046,9 +8047,11 @@ def _get_vgpu_type_per_pgpu(self, device_address):
80468047
return
80478048

80488049
if len(self.supported_vgpu_types) == 1:
8049-
# The operator wanted to only support one single type so we can
8050-
# blindly return it for every single pGPU
8051-
return self.supported_vgpu_types[0]
8050+
first_type = self.supported_vgpu_types[0]
8051+
group = getattr(CONF, 'mdev_%s' % first_type, None)
8052+
if group is None or not group.device_addresses:
8053+
return first_type
8054+
80528055
device_address = self._get_pci_id_from_libvirt_name(device_address)
80538056
if not device_address:
80548057
return

0 commit comments

Comments
 (0)