]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Replace stubout with fixtures
authorMonty Taylor <mordred@inaugust.com>
Mon, 11 Nov 2013 09:30:54 +0000 (04:30 -0500)
committerMonty Taylor <mordred@inaugust.com>
Sun, 24 Nov 2013 15:46:08 +0000 (10:46 -0500)
blueprint remove-mox

The last step in removing mox is to remove stubout usage. Lucky for us,
the fixtures library, which we are already using, can take on the
challenge quite well.

Change-Id: Id33cc8988935a1905f9a14351964f0bb24ef82e3

neutron/common/exceptions.py
neutron/tests/base.py
neutron/tests/unit/linuxbridge/test_rpcapi.py
neutron/tests/unit/mlnx/test_rpcapi.py
neutron/tests/unit/openvswitch/test_ovs_rpcapi.py
neutron/tests/unit/test_extension_ext_gw_mode.py
test-requirements.txt

index df49df8580b746836b557f7ce116466b108026bc..35427d23d2180df6e6eaf2a6b068930b307e3c26 100644 (file)
@@ -19,8 +19,6 @@
 Neutron base exception handling.
 """
 
-_FATAL_EXCEPTION_FORMAT_ERRORS = False
-
 
 class NeutronException(Exception):
     """Base Neutron Exception.
@@ -36,7 +34,7 @@ class NeutronException(Exception):
             super(NeutronException, self).__init__(self.message % kwargs)
             self.msg = self.message % kwargs
         except Exception:
-            if _FATAL_EXCEPTION_FORMAT_ERRORS:
+            if self.use_fatal_exceptions():
                 raise
             else:
                 # at least get the core message out if something happened
@@ -45,6 +43,9 @@ class NeutronException(Exception):
     def __unicode__(self):
         return unicode(self.msg)
 
+    def use_fatal_exceptions(self):
+        return False
+
 
 class BadRequest(NeutronException):
     message = _('Bad %(resource)s request: %(msg)s')
index e611a28ecf070c996d39fbcada68654f26aef727..8426d1af8b1322e0014be84e7bf31260de9f52c8 100644 (file)
@@ -24,17 +24,18 @@ import os
 import eventlet.timeout
 import fixtures
 from oslo.config import cfg
-import stubout
 import testtools
 
-from neutron.common import exceptions
-
 
 CONF = cfg.CONF
 TRUE_STRING = ['True', '1']
 LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s"
 
 
+def fake_use_fatal_exceptions(*args):
+    return True
+
+
 class BaseTestCase(testtools.TestCase):
 
     def setUp(self):
@@ -72,8 +73,9 @@ class BaseTestCase(testtools.TestCase):
         if os.environ.get('OS_STDERR_CAPTURE') in TRUE_STRING:
             stderr = self.useFixture(fixtures.StringStream('stderr')).stream
             self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
-        self.stubs = stubout.StubOutForTesting()
-        self.stubs.Set(exceptions, '_FATAL_EXCEPTION_FORMAT_ERRORS', True)
+        self.useFixture(fixtures.MonkeyPatch(
+            'neutron.common.exceptions.NeutronException.use_fatal_exceptions',
+            fake_use_fatal_exceptions))
 
     def config(self, **kw):
         """Override some configuration values.
index e6e8587e0ecbe782709a4ee4734625207f150834..762a65be1d36db6a07de32e696092a6aa8dbbd81 100644 (file)
 Unit Tests for linuxbridge rpc
 """
 
+import fixtures
 from oslo.config import cfg
-import stubout
 
 from neutron.agent import rpc as agent_rpc
 from neutron.common import topics
 from neutron.openstack.common import context
-from neutron.openstack.common import rpc
 from neutron.plugins.linuxbridge import lb_neutron_plugin as plb
 from neutron.tests import base
 
@@ -49,8 +48,8 @@ class rpcApiTestCase(base.BaseTestCase):
             if expected_retval:
                 return expected_retval
 
-        self.stubs = stubout.StubOutForTesting()
-        self.stubs.Set(rpc, rpc_method, _fake_rpc_method)
+        self.useFixture(fixtures.MonkeyPatch(
+            'neutron.openstack.common.rpc.' + rpc_method, _fake_rpc_method))
 
         retval = getattr(rpcapi, method)(ctxt, **kwargs)
 
index 900a50f0fd88f46b5044b8546f2fc8ce59ca7552..80dcf78277fc4625371563134ea6308bd5efc0d2 100644 (file)
 Unit Tests for Mellanox RPC (major reuse of linuxbridge rpc unit tests)
 """
 
+import fixtures
 from oslo.config import cfg
-import stubout
 
 from neutron.agent import rpc as agent_rpc
 from neutron.common import topics
 from neutron.openstack.common import context
-from neutron.openstack.common import rpc
 from neutron.plugins.mlnx import agent_notify_api
 from neutron.tests import base
 
@@ -51,8 +50,8 @@ class rpcApiTestCase(base.BaseTestCase):
             if expected_retval:
                 return expected_retval
 
-        self.stubs = stubout.StubOutForTesting()
-        self.stubs.Set(rpc, rpc_method, _fake_rpc_method)
+        self.useFixture(fixtures.MonkeyPatch(
+            'neutron.openstack.common.rpc.' + rpc_method, _fake_rpc_method))
 
         retval = getattr(rpcapi, method)(ctxt, **kwargs)
 
index 1a480a44a42b8fe21f6c87dec7d0e460a24d7a0c..1b6a7370a7b14075a2ceee5f8fbbf69144e90b74 100644 (file)
 Unit Tests for openvswitch rpc
 """
 
-import stubout
+import fixtures
 
 from neutron.agent import rpc as agent_rpc
 from neutron.common import topics
 from neutron.openstack.common import context
-from neutron.openstack.common import rpc
 from neutron.plugins.openvswitch.common import constants
 from neutron.plugins.openvswitch import ovs_neutron_plugin as povs
 from neutron.tests import base
@@ -48,8 +47,8 @@ class rpcApiTestCase(base.BaseTestCase):
             if expected_retval:
                 return expected_retval
 
-        self.stubs = stubout.StubOutForTesting()
-        self.stubs.Set(rpc, rpc_method, _fake_rpc_method)
+        self.useFixture(fixtures.MonkeyPatch(
+            'neutron.openstack.common.rpc.' + rpc_method, _fake_rpc_method))
 
         retval = getattr(rpcapi, method)(ctxt, **kwargs)
 
index 585a4700f0da3f7017a661d6b61cb69910a5341a..ac2fd5171e0d2cec743bbcc46fe93018602bf5e0 100644 (file)
@@ -18,9 +18,6 @@
 # @author: Salvatore Orlando, Nicira, Inc
 #
 
-import stubout
-
-import fixtures
 import mock
 from oslo.config import cfg
 from webob import exc
@@ -49,25 +46,6 @@ FAKE_ROUTER_PORT_ID = _uuid()
 FAKE_ROUTER_PORT_MAC = 'bb:bb:bb:bb:bb:bb'
 
 
-class StuboutFixture(fixtures.Fixture):
-    """Setup stubout and add unsetAll to cleanup."""
-
-    def setUp(self):
-        super(StuboutFixture, self).setUp()
-        self.stubs = stubout.StubOutForTesting()
-        self.addCleanup(self.stubs.UnsetAll)
-        self.addCleanup(self.stubs.SmartUnsetAll)
-
-
-def stubout_floating_ip_calls(stubs, fake_count=0):
-
-    def get_floatingips_count(_1, _2, filters):
-        return fake_count
-
-    stubs.Set(l3_db.L3_NAT_db_mixin, 'get_floatingips_count',
-              get_floatingips_count)
-
-
 class TestExtensionManager(object):
 
     def get_resources(self):
@@ -104,8 +82,6 @@ class TestL3GwModeMixin(base.BaseTestCase):
 
     def setUp(self):
         super(TestL3GwModeMixin, self).setUp()
-        stubout_fixture = self.useFixture(StuboutFixture())
-        self.stubs = stubout_fixture.stubs
         self.target_object = TestDbIntPlugin()
         # Patch the context
         ctx_patcher = mock.patch('neutron.context', autospec=True)
index e4276a2042e437283423484aaacdef9fc7231e31..fca3a97bac826412b4010a3431083ad59303cd8a 100644 (file)
@@ -5,7 +5,6 @@ coverage>=3.6
 discover
 fixtures>=0.3.14
 mock>=1.0
-mox>=0.5.3
 python-subunit
 sphinx>=1.1.2
 testrepository>=0.0.17