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 <gibi@redhat.com>
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user