Make nova.tests.unit.virt pass with CONF.use_neutron=True by default

The main issue here was if you don't stub out the os-vif plugging
in the libvirt driver, the test_virt_drivers tests will try to
actually execute commands on the system.

Part of blueprint use-neutron-by-default

Change-Id: Iabfc1809d302b80cf4674155feaa0abb61ca8dcb
This commit is contained in:
Matt Riedemann 2016-11-13 10:48:42 -05:00
parent 6a5d936429
commit 4caae1cfea
2 changed files with 11 additions and 1 deletions

View File

@ -1493,6 +1493,8 @@ virConnect = Connection
class FakeLibvirtFixture(fixtures.Fixture):
"""Performs global setup/stubbing for all libvirt tests.
"""
def __init__(self, stub_os_vif=True):
self.stub_os_vif = stub_os_vif
def setUp(self):
super(FakeLibvirtFixture, self).setUp()
@ -1504,3 +1506,11 @@ class FakeLibvirtFixture(fixtures.Fixture):
self.useFixture(fixtures.MonkeyPatch(i, sys.modules[__name__]))
disable_event_thread(self)
if self.stub_os_vif:
# Make sure to never try and actually plug VIFs in os-vif unless
# we're explicitly testing that code and the test itself will
# handle the appropriate mocking.
self.useFixture(fixtures.MonkeyPatch(
'nova.virt.libvirt.vif.LibvirtGenericVIFDriver._plug_os_vif',
lambda *a, **kw: None))

View File

@ -435,7 +435,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
def setUp(self):
super(LibvirtVifTestCase, self).setUp()
self.useFixture(fakelibvirt.FakeLibvirtFixture())
self.useFixture(fakelibvirt.FakeLibvirtFixture(stub_os_vif=False))
self.flags(allow_same_net_traffic=True)
# os_vif.initialize is typically done in nova-compute startup
os_vif.initialize()