From f0b76cc0f15b8f4f5a589c8f2fadaf3852ceeddb Mon Sep 17 00:00:00 2001 From: Lee Yarwood Date: Wed, 19 Aug 2020 16:31:25 +0100 Subject: [PATCH] libvirt: Add libvirt version mocks in test_private_destroy_* tests These tests would would rely on the version of libvirt reported by FakeLibvirt being older than MIN_LIBVIRT_BETTER_SIGKILL_HANDLING instead of ensuring that was the case to exercise certain destroy behaviours. Change-Id: I3571efde0061d9337d6c544d093976ccdd2762e8 --- nova/tests/unit/virt/libvirt/test_driver.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 22255273d662..744cf0617f44 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -16763,7 +16763,11 @@ class LibvirtConnTestCase(test.NoDBTestCase, self.assertRaises(fakelibvirt.libvirtError, conn._destroy, instance) - def test_private_destroy_ebusy_timeout(self): + @mock.patch.object( + fakelibvirt.Connection, 'getLibVersion', + return_value=versionutils.convert_version_to_int( + libvirt_driver.MIN_LIBVIRT_BETTER_SIGKILL_HANDLING) - 1) + def test_private_destroy_ebusy_timeout(self, mock_get_ver): # Tests that _destroy will retry 6 times to destroy the guest when an # EBUSY is raised, but eventually times out and raises the libvirtError ex = fakelibvirt.make_libvirtError( @@ -16786,7 +16790,11 @@ class LibvirtConnTestCase(test.NoDBTestCase, self.assertEqual(6, mock_guest.poweroff.call_count) - def test_private_destroy_ebusy_multiple_attempt_ok(self): + @mock.patch.object( + fakelibvirt.Connection, 'getLibVersion', + return_value=versionutils.convert_version_to_int( + libvirt_driver.MIN_LIBVIRT_BETTER_SIGKILL_HANDLING) - 1) + def test_private_destroy_ebusy_multiple_attempt_ok(self, mock_get_ver): # Tests that the _destroy attempt loop is broken when EBUSY is no # longer raised. ex = fakelibvirt.make_libvirtError(