From c0538c94cf02d4bd2c8f1194d29eabcffcbea895 Mon Sep 17 00:00:00 2001 From: Szymon Wroblewski Date: Wed, 29 Sep 2021 12:32:11 +0200 Subject: Fix broken test_discovery_with_libvirt_error Mock only small parts of libvirt not the whole library, when testing libvirt discovery. Closes-Bug: #1774292 Change-Id: Ifbcf3fa0602d805b1e493f1ee6c3385edb87a277 (cherry picked from commit 0940d4f2318e7216486ad2d6ad11837c8f54797a) (cherry picked from commit 274e51555f0b939efc228efe1ec34e0253742a8e) (cherry picked from commit b80d48afea9ab934e380f277ab92aaf4d45e1297) (cherry picked from commit bcada72c3aaeeb2a86de3368b1787a9253c9d55b) --- ceilometer/tests/unit/compute/test_discovery.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ceilometer/tests/unit/compute/test_discovery.py b/ceilometer/tests/unit/compute/test_discovery.py index 33fe9aaf..5a4d4029 100644 --- a/ceilometer/tests/unit/compute/test_discovery.py +++ b/ceilometer/tests/unit/compute/test_discovery.py @@ -128,6 +128,9 @@ class FakeManualInstanceConn(object): def listAllDomains(self): return [FakeManualInstanceDomain()] + def isAlive(self): + return False + class TestDiscovery(base.BaseTestCase): @@ -286,14 +289,13 @@ class TestDiscovery(base.BaseTestCase): self.client.instance_get_all_by_host.call_args_list) @testtools.skipUnless(libvirt, "libvirt not available") - @mock.patch.object(utils, "libvirt") - @mock.patch.object(discovery, "libvirt") - def test_discovery_with_libvirt_error(self, libvirt, libvirt2): + @mock.patch.object(libvirt, "VIR_DOMAIN_METADATA_ELEMENT", 2) + @mock.patch.object(libvirt, "openReadOnly") + def test_discovery_with_libvirt_error(self, openReadOnly): self.CONF.set_override("instance_discovery_method", "libvirt_metadata", group="compute") - libvirt.VIR_DOMAIN_METADATA_ELEMENT = 2 - libvirt2.openReadOnly.return_value = FakeManualInstanceConn() + openReadOnly.return_value = FakeManualInstanceConn() dsc = discovery.InstanceDiscovery(self.CONF) resources = dsc.discover(mock.MagicMock()) self.assertEqual(0, len(resources)) -- cgit v1.2.1