@@ -26374,11 +26374,11 @@ def test_get_supported_vgpu_types(self, mock_warning):
26374
26374
self.flags(enabled_mdev_types=['nvidia-11'], group='devices')
26375
26375
self.assertEqual(['nvidia-11'], drvr._get_supported_vgpu_types())
26376
26376
# 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.
26378
26378
self.assertEqual({}, drvr.pgpu_type_mapping)
26379
26379
self.assertEqual({}, drvr.mdev_class_mapping)
26380
26380
# 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 .
26382
26382
self.assertEqual({orc.VGPU}, drvr.mdev_classes)
26383
26383
# Since the operator wanted to only support one type, it's fine to not
26384
26384
# provide config groups
@@ -26461,6 +26461,25 @@ def test_get_supported_vgpu_types_registering_dynamic_opts(self, rdo):
26461
26461
# be the second time that register_dynamic_opts() will be called.
26462
26462
rdo.assert_has_calls([mock.call(CONF), mock.call(CONF)])
26463
26463
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
+
26464
26483
def test_get_vgpu_type_per_pgpu(self):
26465
26484
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
26466
26485
device = 'pci_0000_84_00_0'
@@ -26471,7 +26490,17 @@ def test_get_vgpu_type_per_pgpu(self):
26471
26490
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
26472
26491
self.assertEqual('nvidia-11', drvr._get_vgpu_type_per_pgpu(device))
26473
26492
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.
26475
26504
self.flags(enabled_mdev_types=['nvidia-11', 'nvidia-12'],
26476
26505
group='devices')
26477
26506
# we need to call the below again to ensure the updated
0 commit comments