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 commit0940d4f231
) (cherry picked from commit274e51555f
) (cherry picked from commitb80d48afea
)
This commit is contained in:
parent
16dbe38ff1
commit
d2a545adda
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue