diff options
author | Sylvain Bauza <sbauza@redhat.com> | 2020-10-15 19:19:38 +0200 |
---|---|---|
committer | Christian Rohmann <christian.rohmann@inovex.de> | 2022-03-02 14:20:24 +0100 |
commit | 2ddc2e6ab0259fdc1437998542fb5fd020dfef31 (patch) | |
tree | 9a45f8e258379572ef856410771321c17345d012 | |
parent | 184a3c976faed38907af148a533bc6e9faa410f5 (diff) | |
download | nova-2ddc2e6ab0259fdc1437998542fb5fd020dfef31.tar.gz |
Fix the vGPU dynamic options race
As we lookup the existing dynamic options *before* creating them as
_get_supported_vgpu_types() is called *before* compute init_host(),
we need to make sure we call again the dynamic options registration
within it.
Change-Id: Ib9387c381d39fac389374c731b210815c6d4af03
Closes-Bug: #1900006
(cherry picked from commit 2bd8900d9b2600fba74341e249701051fb78eb37)
(cherry picked from commit c7d9d6d9dd25e21ec76ceea294cdf1690686a086)
-rw-r--r-- | nova/tests/unit/virt/libvirt/test_driver.py | 14 | ||||
-rw-r--r-- | nova/virt/libvirt/driver.py | 5 |
2 files changed, 19 insertions, 0 deletions
diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 8b22cf4be3..cea2521893 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -24190,6 +24190,20 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin): libvirt_driver.LibvirtDriver, fake.FakeVirtAPI(), False) + @mock.patch.object(nova.conf.devices, 'register_dynamic_opts') + def test_get_supported_vgpu_types_registering_dynamic_opts(self, rdo): + self.flags(enabled_vgpu_types=['nvidia-11', 'nvidia-12'], + group='devices') + + drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) + drvr._get_supported_vgpu_types() + + # Okay below is confusing, but remember, ._get_supported_vgpu_types() + # is first called by the LibvirtDriver object creation, so when + # calling the above drvr._get_supported_vgpu_types() method, it will + # be the second time that register_dynamic_opts() will be called. + rdo.assert_has_calls([mock.call(CONF), mock.call(CONF)]) + def test_get_vgpu_type_per_pgpu(self): drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) device = 'pci_0000_84_00_0' diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index e51ad5ef7e..08251516e3 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -6760,6 +6760,11 @@ class LibvirtDriver(driver.ComputeDriver): if not CONF.devices.enabled_vgpu_types: return [] + # Make sure we register all the types as the compute service could + # be calling this method before init_host() + if len(CONF.devices.enabled_vgpu_types) > 1: + nova.conf.devices.register_dynamic_opts(CONF) + for vgpu_type in CONF.devices.enabled_vgpu_types: group = getattr(CONF, 'vgpu_%s' % vgpu_type, None) if group is None or not group.device_addresses: |