unit: consolidate mocking start_odl_sync_thread

Introduce fixture to mock start_odl_sync_thread.
and mock _start_sync_timer. It's also needs to be mocked
to avoid running timer unintentionally.

Change-Id: I8298189fcbe56028fa08b96cb50f50d5163a58f0
This commit is contained in:
Isaku Yamahata 2017-06-23 17:38:28 -07:00
parent 42a69fc193
commit 2d34f2b493
5 changed files with 19 additions and 12 deletions

View File

@ -22,6 +22,8 @@ from oslo_config import cfg
from networking_odl.common import odl_features
from neutron.tests import base
from networking_odl.journal import journal
class DietTestCase(base.DietTestCase):
@ -75,3 +77,10 @@ class OpenDaylightFeaturesFixture(fixtures.Fixture):
@staticmethod
def fake_init():
odl_features.feature_set = set()
class OpenDaylightJournalThreadFixture(fixtures.Fixture):
def _setUp(self):
super(OpenDaylightJournalThreadFixture, self)._setUp()
mock.patch.object(journal.OpenDaylightJournalThread,
'start_odl_sync_thread').start()

View File

@ -35,8 +35,7 @@ class OpenDaylightConfigBase(test_plugin.Ml2PluginV2TestCase,
['logger', 'opendaylight_v2'], 'ml2')
cfg.CONF.set_override('extension_drivers',
['port_security', 'qos'], 'ml2')
self.mock_sync_thread = mock.patch.object(
journal.OpenDaylightJournalThread, 'start_odl_sync_thread').start()
self.useFixture(base.OpenDaylightJournalThreadFixture())
self.mock_mt_thread = mock.patch.object(
maintenance.MaintenanceThread, 'start').start()
self.thread = journal.OpenDaylightJournalThread()

View File

@ -111,8 +111,7 @@ class OpenDaylightL3TestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase,
cfg.CONF.set_override("service_plugins", ['odl-router_v2'])
core_plugin = cfg.CONF.core_plugin
service_plugins = {'l3_plugin_name': 'odl-router_v2'}
mock.patch.object(journal.OpenDaylightJournalThread,
'start_odl_sync_thread').start()
self.useFixture(odl_base.OpenDaylightJournalThreadFixture())
self.mock_mt_thread = mock.patch.object(
maintenance.MaintenanceThread, 'start').start()
mock.patch.object(mech_driver_v2.OpenDaylightMechanismDriver,

View File

@ -43,7 +43,7 @@ from networking_odl.journal import cleanup
from networking_odl.journal import journal
from networking_odl.journal import maintenance
from networking_odl.ml2 import mech_driver_v2
from networking_odl.tests import base as odl_base
from networking_odl.tests import base
from networking_odl.tests.unit import base_v2
@ -60,15 +60,14 @@ SG_RULE_FAKE_ID = uuidutils.generate_uuid()
class OpenDayLightMechanismConfigTests(testlib_api.SqlTestCase):
def setUp(self):
super(OpenDayLightMechanismConfigTests, self).setUp()
self.mock_sync_thread = mock.patch.object(
journal.OpenDaylightJournalThread, 'start_odl_sync_thread').start()
self.useFixture(base.OpenDaylightJournalThreadFixture())
self.mock_mt_thread = mock.patch.object(
maintenance.MaintenanceThread, 'start').start()
cfg.CONF.set_override('mechanism_drivers',
['logger', 'opendaylight_v2'], 'ml2')
cfg.CONF.set_override('port_binding_controller',
'legacy-port-binding', 'ml2_odl')
self.useFixture(odl_base.OpenDaylightFeaturesFixture())
self.useFixture(base.OpenDaylightFeaturesFixture())
def _set_config(self, url='http://127.0.0.1:9999', username='someuser',
password='somepass'):
@ -156,7 +155,9 @@ class AttributeDict(dict):
class OpenDaylightMechanismDriverTestCase(base_v2.OpenDaylightConfigBase):
def setUp(self):
super(OpenDaylightMechanismDriverTestCase, self).setUp()
self.useFixture(odl_base.OpenDaylightFeaturesFixture())
self.useFixture(base.OpenDaylightFeaturesFixture())
self.mock_sync_thread = mock.patch.object(
journal.OpenDaylightJournalThread, 'start_odl_sync_thread').start()
self.db_session = neutron_db_api.get_writer_session()
self.mech = mech_driver_v2.OpenDaylightMechanismDriver()
self.mech.initialize()

View File

@ -18,8 +18,8 @@ from neutron.db import api as neutron_db_api
from networking_odl.common import constants as odl_const
from networking_odl.db import db
from networking_odl.journal import journal
from networking_odl.qos import qos_driver_v2 as qos_driver
from networking_odl.tests import base
from networking_odl.tests.unit import base_v2
@ -29,8 +29,7 @@ class OpenDaylightQosDriverTestCase(base_v2.OpenDaylightConfigBase):
super(OpenDaylightQosDriverTestCase, self).setUp()
self.db_session = neutron_db_api.get_writer_session()
self.qos_driver = qos_driver.OpenDaylightQosDriver()
self.mock_sync_thread = mock.patch.object(
journal.OpenDaylightJournalThread, 'start_odl_sync_thread').start()
self.useFixture(base.OpenDaylightJournalThreadFixture())
def _get_mock_context(self):
current = {'tenant_id': 'tenant_id'}