tests/unit: clean up notification driver
Some tests doesn't cleanup notification driver. So some tests can run against unintended notification driver depending on execution order Change-Id: I7dbed47153be66684827b2693bbc995dddfb4c1b Related-Bug: #1281481 Partial-Bug: #1284549
This commit is contained in:
parent
0beccf0430
commit
4434882bc4
@ -28,6 +28,8 @@ from oslo.config import cfg
|
|||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from neutron import manager
|
from neutron import manager
|
||||||
|
from neutron.openstack.common.notifier import api as notifier_api
|
||||||
|
from neutron.openstack.common.notifier import test_notifier
|
||||||
from neutron.tests import post_mortem_debug
|
from neutron.tests import post_mortem_debug
|
||||||
|
|
||||||
|
|
||||||
@ -52,6 +54,18 @@ class BaseTestCase(testtools.TestCase):
|
|||||||
if core_plugin is not None:
|
if core_plugin is not None:
|
||||||
cfg.CONF.set_override('core_plugin', core_plugin)
|
cfg.CONF.set_override('core_plugin', core_plugin)
|
||||||
|
|
||||||
|
def _cleanup_test_notifier(self):
|
||||||
|
test_notifier.NOTIFICATIONS = []
|
||||||
|
|
||||||
|
def setup_notification_driver(self, notification_driver=None):
|
||||||
|
# to reload the drivers
|
||||||
|
self.addCleanup(notifier_api._reset_drivers)
|
||||||
|
self.addCleanup(self._cleanup_test_notifier)
|
||||||
|
notifier_api._reset_drivers()
|
||||||
|
if notification_driver is None:
|
||||||
|
notification_driver = [test_notifier.__name__]
|
||||||
|
cfg.CONF.set_override("notification_driver", notification_driver)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BaseTestCase, self).setUp()
|
super(BaseTestCase, self).setUp()
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ import mock
|
|||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from neutron.agent.common import config
|
from neutron.agent.common import config
|
||||||
from neutron.openstack.common.notifier import api as notifier_api
|
|
||||||
from neutron.openstack.common.notifier import test_notifier
|
from neutron.openstack.common.notifier import test_notifier
|
||||||
from neutron.openstack.common import uuidutils
|
from neutron.openstack.common import uuidutils
|
||||||
from neutron.services.metering.agents import metering_agent
|
from neutron.services.metering.agents import metering_agent
|
||||||
@ -52,8 +51,7 @@ class TestMeteringOperations(base.BaseTestCase):
|
|||||||
cfg.CONF.set_override('measure_interval', 0)
|
cfg.CONF.set_override('measure_interval', 0)
|
||||||
cfg.CONF.set_override('report_interval', 0)
|
cfg.CONF.set_override('report_interval', 0)
|
||||||
|
|
||||||
notifier_api._drivers = None
|
self.setup_notification_driver()
|
||||||
cfg.CONF.set_override("notification_driver", [test_notifier.__name__])
|
|
||||||
|
|
||||||
metering_rpc = ('neutron.services.metering.agents.metering_agent.'
|
metering_rpc = ('neutron.services.metering.agents.metering_agent.'
|
||||||
'MeteringPluginRpc._get_sync_data_metering')
|
'MeteringPluginRpc._get_sync_data_metering')
|
||||||
@ -70,10 +68,6 @@ class TestMeteringOperations(base.BaseTestCase):
|
|||||||
self.agent = metering_agent.MeteringAgent('my agent', cfg.CONF)
|
self.agent = metering_agent.MeteringAgent('my agent', cfg.CONF)
|
||||||
self.driver = self.agent.metering_driver
|
self.driver = self.agent.metering_driver
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
test_notifier.NOTIFICATIONS = []
|
|
||||||
super(TestMeteringOperations, self).tearDown()
|
|
||||||
|
|
||||||
def test_add_metering_label(self):
|
def test_add_metering_label(self):
|
||||||
self.agent.add_metering_label(None, ROUTERS)
|
self.agent.add_metering_label(None, ROUTERS)
|
||||||
self.assertEqual(self.driver.add_metering_label.call_count, 1)
|
self.assertEqual(self.driver.add_metering_label.call_count, 1)
|
||||||
|
@ -24,8 +24,6 @@ from neutron.db import extraroute_db
|
|||||||
from neutron.extensions import extraroute
|
from neutron.extensions import extraroute
|
||||||
from neutron.extensions import l3
|
from neutron.extensions import l3
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
from neutron.openstack.common.notifier import api as notifier_api
|
|
||||||
from neutron.openstack.common.notifier import test_notifier
|
|
||||||
from neutron.openstack.common import uuidutils
|
from neutron.openstack.common import uuidutils
|
||||||
from neutron.tests.unit import test_api_v2
|
from neutron.tests.unit import test_api_v2
|
||||||
from neutron.tests.unit import test_l3_plugin as test_l3
|
from neutron.tests.unit import test_l3_plugin as test_l3
|
||||||
@ -470,9 +468,7 @@ class ExtraRouteDBIntTestCase(test_l3.L3NatDBIntTestCase,
|
|||||||
ext_mgr = ExtraRouteTestExtensionManager()
|
ext_mgr = ExtraRouteTestExtensionManager()
|
||||||
super(test_l3.L3BaseForIntTests, self).setUp(plugin=plugin,
|
super(test_l3.L3BaseForIntTests, self).setUp(plugin=plugin,
|
||||||
ext_mgr=ext_mgr)
|
ext_mgr=ext_mgr)
|
||||||
# Set to None to reload the drivers
|
self.setup_notification_driver()
|
||||||
notifier_api._drivers = None
|
|
||||||
cfg.CONF.set_override("notification_driver", [test_notifier.__name__])
|
|
||||||
|
|
||||||
|
|
||||||
class ExtraRouteDBIntTestCaseXML(ExtraRouteDBIntTestCase):
|
class ExtraRouteDBIntTestCaseXML(ExtraRouteDBIntTestCase):
|
||||||
@ -497,9 +493,7 @@ class ExtraRouteDBSepTestCase(test_l3.L3NatDBSepTestCase,
|
|||||||
plugin=plugin, ext_mgr=ext_mgr,
|
plugin=plugin, ext_mgr=ext_mgr,
|
||||||
service_plugins=service_plugins)
|
service_plugins=service_plugins)
|
||||||
|
|
||||||
# Set to None to reload the drivers
|
self.setup_notification_driver()
|
||||||
notifier_api._drivers = None
|
|
||||||
cfg.CONF.set_override("notification_driver", [test_notifier.__name__])
|
|
||||||
|
|
||||||
|
|
||||||
class ExtraRouteDBSepTestCaseXML(ExtraRouteDBSepTestCase):
|
class ExtraRouteDBSepTestCaseXML(ExtraRouteDBSepTestCase):
|
||||||
|
@ -35,7 +35,6 @@ from neutron.extensions import external_net
|
|||||||
from neutron.extensions import l3
|
from neutron.extensions import l3
|
||||||
from neutron.manager import NeutronManager
|
from neutron.manager import NeutronManager
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
from neutron.openstack.common.notifier import api as notifier_api
|
|
||||||
from neutron.openstack.common.notifier import test_notifier
|
from neutron.openstack.common.notifier import test_notifier
|
||||||
from neutron.openstack.common import uuidutils
|
from neutron.openstack.common import uuidutils
|
||||||
from neutron.plugins.common import constants as service_constants
|
from neutron.plugins.common import constants as service_constants
|
||||||
@ -1723,13 +1722,7 @@ class L3BaseForIntTests(test_db_plugin.NeutronDbPluginV2TestCase):
|
|||||||
super(L3BaseForIntTests, self).setUp(plugin=plugin, ext_mgr=ext_mgr,
|
super(L3BaseForIntTests, self).setUp(plugin=plugin, ext_mgr=ext_mgr,
|
||||||
service_plugins=service_plugins)
|
service_plugins=service_plugins)
|
||||||
|
|
||||||
# Set to None to reload the drivers
|
self.setup_notification_driver()
|
||||||
notifier_api._drivers = None
|
|
||||||
cfg.CONF.set_override("notification_driver", [test_notifier.__name__])
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
test_notifier.NOTIFICATIONS = []
|
|
||||||
super(L3BaseForIntTests, self).tearDown()
|
|
||||||
|
|
||||||
|
|
||||||
class L3BaseForSepTests(test_db_plugin.NeutronDbPluginV2TestCase):
|
class L3BaseForSepTests(test_db_plugin.NeutronDbPluginV2TestCase):
|
||||||
@ -1750,13 +1743,7 @@ class L3BaseForSepTests(test_db_plugin.NeutronDbPluginV2TestCase):
|
|||||||
super(L3BaseForSepTests, self).setUp(plugin=plugin, ext_mgr=ext_mgr,
|
super(L3BaseForSepTests, self).setUp(plugin=plugin, ext_mgr=ext_mgr,
|
||||||
service_plugins=service_plugins)
|
service_plugins=service_plugins)
|
||||||
|
|
||||||
# Set to None to reload the drivers
|
self.setup_notification_driver()
|
||||||
notifier_api._drivers = None
|
|
||||||
cfg.CONF.set_override("notification_driver", [test_notifier.__name__])
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
test_notifier.NOTIFICATIONS = []
|
|
||||||
super(L3BaseForSepTests, self).tearDown()
|
|
||||||
|
|
||||||
|
|
||||||
class L3AgentDbIntTestCase(L3BaseForIntTests, L3AgentDbTestCaseBase):
|
class L3AgentDbIntTestCase(L3BaseForIntTests, L3AgentDbTestCaseBase):
|
||||||
|
Loading…
Reference in New Issue
Block a user