From 081130d329f2c7386ddbada8c0e5ac47188f5c12 Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Thu, 18 Dec 2025 16:33:09 +0100 Subject: [PATCH] Do not mock threading.Event.wait There were libvirt disk attach / detach unit test cases that mocked threading.Event.wait to speed up the test execution as the libvirt event based device detach has a 20 seconds timeout. However this mock is very wide. It effects all the threading.Event usage during the test case. As we are switched to the native threaded backed of oslo.service we got an LoopingCall implementation that relies on threading.Event to signal when the call is finished. In these test cases the wide mock broke this logic and the LoopingCall signalled "done" while the actual call in the background was still running making that call leaking out from the test case and therefore under the fixtures the test case tore down after the test case finished. This caused that later the call hit non mocked code paths like importing the real libvirt lib instead of using our libvirt fixture causing late failures. The fix is to remove the wide mock and instead change the detach timeout in these test cases. Later follow ups will check put protection in place to avoid re-introducing this wide mock. Closes-Bug: #2136815 Change-Id: I3f40d9dad6ef87e6fa4db0ea4065a77421e8c271 Signed-off-by: Balazs Gibizer --- nova/tests/unit/virt/test_virt_drivers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/unit/virt/test_virt_drivers.py b/nova/tests/unit/virt/test_virt_drivers.py index e6a2c8a324..47182f2197 100644 --- a/nova/tests/unit/virt/test_virt_drivers.py +++ b/nova/tests/unit/virt/test_virt_drivers.py @@ -421,10 +421,10 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase): self.assertEqual(storage_ip, result['ip']) @catch_notimplementederror - @mock.patch('threading.Event.wait', new=mock.Mock()) @mock.patch.object(libvirt.driver.LibvirtDriver, '_build_device_metadata', return_value=objects.InstanceDeviceMetadata()) def test_attach_detach_volume(self, _): + self.flags(device_detach_timeout="1", group="libvirt") instance_ref, network_info = self._get_running_instance() connection_info = { "driver_volume_type": "fake", @@ -458,10 +458,10 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase): '/dev/sda', 2)) @catch_notimplementederror - @mock.patch('threading.Event.wait', new=mock.Mock()) @mock.patch.object(libvirt.driver.LibvirtDriver, '_build_device_metadata', return_value=objects.InstanceDeviceMetadata()) def test_attach_detach_different_power_states(self, _): + self.flags(device_detach_timeout="1", group="libvirt") instance_ref, network_info = self._get_running_instance() connection_info = { "driver_volume_type": "fake",