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:
Isaku Yamahata 2014-02-25 15:34:53 +09:00
parent 0beccf0430
commit 4434882bc4
4 changed files with 19 additions and 30 deletions

View File

@ -28,6 +28,8 @@ from oslo.config import cfg
import testtools
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
@ -52,6 +54,18 @@ class BaseTestCase(testtools.TestCase):
if core_plugin is not None:
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):
super(BaseTestCase, self).setUp()

View File

@ -18,7 +18,6 @@ import mock
from oslo.config import cfg
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 import uuidutils
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('report_interval', 0)
notifier_api._drivers = None
cfg.CONF.set_override("notification_driver", [test_notifier.__name__])
self.setup_notification_driver()
metering_rpc = ('neutron.services.metering.agents.metering_agent.'
'MeteringPluginRpc._get_sync_data_metering')
@ -70,10 +68,6 @@ class TestMeteringOperations(base.BaseTestCase):
self.agent = metering_agent.MeteringAgent('my agent', cfg.CONF)
self.driver = self.agent.metering_driver
def tearDown(self):
test_notifier.NOTIFICATIONS = []
super(TestMeteringOperations, self).tearDown()
def test_add_metering_label(self):
self.agent.add_metering_label(None, ROUTERS)
self.assertEqual(self.driver.add_metering_label.call_count, 1)

View File

@ -24,8 +24,6 @@ from neutron.db import extraroute_db
from neutron.extensions import extraroute
from neutron.extensions import l3
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.tests.unit import test_api_v2
from neutron.tests.unit import test_l3_plugin as test_l3
@ -470,9 +468,7 @@ class ExtraRouteDBIntTestCase(test_l3.L3NatDBIntTestCase,
ext_mgr = ExtraRouteTestExtensionManager()
super(test_l3.L3BaseForIntTests, self).setUp(plugin=plugin,
ext_mgr=ext_mgr)
# Set to None to reload the drivers
notifier_api._drivers = None
cfg.CONF.set_override("notification_driver", [test_notifier.__name__])
self.setup_notification_driver()
class ExtraRouteDBIntTestCaseXML(ExtraRouteDBIntTestCase):
@ -497,9 +493,7 @@ class ExtraRouteDBSepTestCase(test_l3.L3NatDBSepTestCase,
plugin=plugin, ext_mgr=ext_mgr,
service_plugins=service_plugins)
# Set to None to reload the drivers
notifier_api._drivers = None
cfg.CONF.set_override("notification_driver", [test_notifier.__name__])
self.setup_notification_driver()
class ExtraRouteDBSepTestCaseXML(ExtraRouteDBSepTestCase):

View File

@ -35,7 +35,6 @@ from neutron.extensions import external_net
from neutron.extensions import l3
from neutron.manager import NeutronManager
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.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,
service_plugins=service_plugins)
# Set to None to reload the drivers
notifier_api._drivers = None
cfg.CONF.set_override("notification_driver", [test_notifier.__name__])
def tearDown(self):
test_notifier.NOTIFICATIONS = []
super(L3BaseForIntTests, self).tearDown()
self.setup_notification_driver()
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,
service_plugins=service_plugins)
# Set to None to reload the drivers
notifier_api._drivers = None
cfg.CONF.set_override("notification_driver", [test_notifier.__name__])
def tearDown(self):
test_notifier.NOTIFICATIONS = []
super(L3BaseForSepTests, self).tearDown()
self.setup_notification_driver()
class L3AgentDbIntTestCase(L3BaseForIntTests, L3AgentDbTestCaseBase):