@@ -26486,11 +26486,11 @@ def test_get_supported_vgpu_types(self, mock_warning):
26486
26486
self.flags(enabled_mdev_types=['nvidia-11'], group='devices')
26487
26487
self.assertEqual(['nvidia-11'], drvr._get_supported_vgpu_types())
26488
26488
# 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.
26490
26490
self.assertEqual({}, drvr.pgpu_type_mapping)
26491
26491
self.assertEqual({}, drvr.mdev_class_mapping)
26492
26492
# 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 .
26494
26494
self.assertEqual({orc.VGPU}, drvr.mdev_classes)
26495
26495
# Since the operator wanted to only support one type, it's fine to not
26496
26496
# provide config groups
@@ -26573,6 +26573,25 @@ def test_get_supported_vgpu_types_registering_dynamic_opts(self, rdo):
26573
26573
# be the second time that register_dynamic_opts() will be called.
26574
26574
rdo.assert_has_calls([mock.call(CONF), mock.call(CONF)])
26575
26575
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
+
26576
26595
def test_get_vgpu_type_per_pgpu(self):
26577
26596
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
26578
26597
device = 'pci_0000_84_00_0'
@@ -26583,7 +26602,17 @@ def test_get_vgpu_type_per_pgpu(self):
26583
26602
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
26584
26603
self.assertEqual('nvidia-11', drvr._get_vgpu_type_per_pgpu(device))
26585
26604
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.
26587
26616
self.flags(enabled_mdev_types=['nvidia-11', 'nvidia-12'],
26588
26617
group='devices')
26589
26618
# we need to call the below again to ensure the updated
0 commit comments