]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
tests/unit: clean up notification driver
authorIsaku Yamahata <isaku.yamahata@intel.com>
Tue, 25 Feb 2014 06:34:53 +0000 (15:34 +0900)
committerIsaku Yamahata <isaku.yamahata@intel.com>
Thu, 20 Mar 2014 02:42:59 +0000 (11:42 +0900)
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

neutron/tests/base.py
neutron/tests/unit/services/metering/test_metering_agent.py
neutron/tests/unit/test_extension_extraroute.py
neutron/tests/unit/test_l3_plugin.py

index 71b3427e67f6ffc19e00ac17bfc6a108cde70e6f..26c166e16c77562d440206f7dd57a8f31789df00 100644 (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()
 
index 0c3a410ea6454b1109912dbfbbf74473babe9cdc..3e1d0db299eb84fbf714f2a01e8f25c80e41a685 100644 (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)
index 48ce3f782b9f93480712038c3b58040313eb9f13..826ca80a2c0b46976dc0623a80dd62d2a0294934 100644 (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):
index a29ade31e28c3fd793c9d84ae833302b69f7c766..bcaf7cefc30943e013ce7f2a00978c8f41ee0a15 100644 (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):