Don't poison Host._init_events if it's already mocked
PoisonFunctions poisons Host._init_events without checking if it's already mocked. This creates a proper headscratcher when you try to use FakeLibvirtFixture with ServersTestBase: if you use FakeLibvirtFixture before calling super.setUp() PoisonFunctions will poison the function we already mocked, if we call it in the other order setUp() will fail when it tries to start nova-compute. Change-Id: I6d8214c75a67c87ec5a7406f3cc2e8b923aa4d84
This commit is contained in:
parent
03ccb1f933
commit
2c9fe11e8d
|
@ -942,19 +942,17 @@ class PoisonFunctions(fixtures.Fixture):
|
|||
# causes trouble in tests. Make sure that if tests don't
|
||||
# properly patch it the test explodes.
|
||||
|
||||
# explicit import because MonkeyPatch doesn't magic import
|
||||
# correctly if we are patching a method on a class in a
|
||||
# module.
|
||||
import nova.virt.libvirt.host # noqa
|
||||
|
||||
def evloop(*args, **kwargs):
|
||||
import sys
|
||||
warnings.warn("Forgot to disable libvirt event thread")
|
||||
sys.exit(1)
|
||||
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'nova.virt.libvirt.host.Host._init_events',
|
||||
evloop))
|
||||
# Don't poison the function if it's already mocked
|
||||
import nova.virt.libvirt.host
|
||||
if not isinstance(nova.virt.libvirt.host.Host._init_events, mock.Mock):
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'nova.virt.libvirt.host.Host._init_events',
|
||||
side_effect=evloop))
|
||||
|
||||
|
||||
class IndirectionAPIFixture(fixtures.Fixture):
|
||||
|
|
|
@ -481,9 +481,9 @@ def disable_event_thread(self):
|
|||
def evloop(*args, **kwargs):
|
||||
pass
|
||||
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'nova.virt.libvirt.host.Host._init_events',
|
||||
evloop))
|
||||
side_effect=evloop))
|
||||
|
||||
|
||||
class libvirtError(Exception):
|
||||
|
|
Loading…
Reference in New Issue