Merge "Replace stubout with fixtures"
This commit is contained in:
commit
56710b3545
|
@ -19,8 +19,6 @@
|
||||||
Neutron base exception handling.
|
Neutron base exception handling.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_FATAL_EXCEPTION_FORMAT_ERRORS = False
|
|
||||||
|
|
||||||
|
|
||||||
class NeutronException(Exception):
|
class NeutronException(Exception):
|
||||||
"""Base Neutron Exception.
|
"""Base Neutron Exception.
|
||||||
|
@ -36,7 +34,7 @@ class NeutronException(Exception):
|
||||||
super(NeutronException, self).__init__(self.message % kwargs)
|
super(NeutronException, self).__init__(self.message % kwargs)
|
||||||
self.msg = self.message % kwargs
|
self.msg = self.message % kwargs
|
||||||
except Exception:
|
except Exception:
|
||||||
if _FATAL_EXCEPTION_FORMAT_ERRORS:
|
if self.use_fatal_exceptions():
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
# at least get the core message out if something happened
|
# at least get the core message out if something happened
|
||||||
|
@ -45,6 +43,9 @@ class NeutronException(Exception):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return unicode(self.msg)
|
return unicode(self.msg)
|
||||||
|
|
||||||
|
def use_fatal_exceptions(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class BadRequest(NeutronException):
|
class BadRequest(NeutronException):
|
||||||
message = _('Bad %(resource)s request: %(msg)s')
|
message = _('Bad %(resource)s request: %(msg)s')
|
||||||
|
|
|
@ -24,17 +24,18 @@ import os
|
||||||
import eventlet.timeout
|
import eventlet.timeout
|
||||||
import fixtures
|
import fixtures
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
import stubout
|
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from neutron.common import exceptions
|
|
||||||
|
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
TRUE_STRING = ['True', '1']
|
TRUE_STRING = ['True', '1']
|
||||||
LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s"
|
LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s"
|
||||||
|
|
||||||
|
|
||||||
|
def fake_use_fatal_exceptions(*args):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class BaseTestCase(testtools.TestCase):
|
class BaseTestCase(testtools.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -72,8 +73,9 @@ class BaseTestCase(testtools.TestCase):
|
||||||
if os.environ.get('OS_STDERR_CAPTURE') in TRUE_STRING:
|
if os.environ.get('OS_STDERR_CAPTURE') in TRUE_STRING:
|
||||||
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
|
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
|
||||||
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
|
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
self.stubs.Set(exceptions, '_FATAL_EXCEPTION_FORMAT_ERRORS', True)
|
'neutron.common.exceptions.NeutronException.use_fatal_exceptions',
|
||||||
|
fake_use_fatal_exceptions))
|
||||||
|
|
||||||
def config(self, **kw):
|
def config(self, **kw):
|
||||||
"""Override some configuration values.
|
"""Override some configuration values.
|
||||||
|
|
|
@ -18,13 +18,12 @@
|
||||||
Unit Tests for linuxbridge rpc
|
Unit Tests for linuxbridge rpc
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import fixtures
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
import stubout
|
|
||||||
|
|
||||||
from neutron.agent import rpc as agent_rpc
|
from neutron.agent import rpc as agent_rpc
|
||||||
from neutron.common import topics
|
from neutron.common import topics
|
||||||
from neutron.openstack.common import context
|
from neutron.openstack.common import context
|
||||||
from neutron.openstack.common import rpc
|
|
||||||
from neutron.plugins.linuxbridge import lb_neutron_plugin as plb
|
from neutron.plugins.linuxbridge import lb_neutron_plugin as plb
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
|
|
||||||
|
@ -49,8 +48,8 @@ class rpcApiTestCase(base.BaseTestCase):
|
||||||
if expected_retval:
|
if expected_retval:
|
||||||
return expected_retval
|
return expected_retval
|
||||||
|
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
self.stubs.Set(rpc, rpc_method, _fake_rpc_method)
|
'neutron.openstack.common.rpc.' + rpc_method, _fake_rpc_method))
|
||||||
|
|
||||||
retval = getattr(rpcapi, method)(ctxt, **kwargs)
|
retval = getattr(rpcapi, method)(ctxt, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,12 @@
|
||||||
Unit Tests for Mellanox RPC (major reuse of linuxbridge rpc unit tests)
|
Unit Tests for Mellanox RPC (major reuse of linuxbridge rpc unit tests)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import fixtures
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
import stubout
|
|
||||||
|
|
||||||
from neutron.agent import rpc as agent_rpc
|
from neutron.agent import rpc as agent_rpc
|
||||||
from neutron.common import topics
|
from neutron.common import topics
|
||||||
from neutron.openstack.common import context
|
from neutron.openstack.common import context
|
||||||
from neutron.openstack.common import rpc
|
|
||||||
from neutron.plugins.mlnx import agent_notify_api
|
from neutron.plugins.mlnx import agent_notify_api
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
|
|
||||||
|
@ -51,8 +50,8 @@ class rpcApiTestCase(base.BaseTestCase):
|
||||||
if expected_retval:
|
if expected_retval:
|
||||||
return expected_retval
|
return expected_retval
|
||||||
|
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
self.stubs.Set(rpc, rpc_method, _fake_rpc_method)
|
'neutron.openstack.common.rpc.' + rpc_method, _fake_rpc_method))
|
||||||
|
|
||||||
retval = getattr(rpcapi, method)(ctxt, **kwargs)
|
retval = getattr(rpcapi, method)(ctxt, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,11 @@
|
||||||
Unit Tests for openvswitch rpc
|
Unit Tests for openvswitch rpc
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import stubout
|
import fixtures
|
||||||
|
|
||||||
from neutron.agent import rpc as agent_rpc
|
from neutron.agent import rpc as agent_rpc
|
||||||
from neutron.common import topics
|
from neutron.common import topics
|
||||||
from neutron.openstack.common import context
|
from neutron.openstack.common import context
|
||||||
from neutron.openstack.common import rpc
|
|
||||||
from neutron.plugins.openvswitch.common import constants
|
from neutron.plugins.openvswitch.common import constants
|
||||||
from neutron.plugins.openvswitch import ovs_neutron_plugin as povs
|
from neutron.plugins.openvswitch import ovs_neutron_plugin as povs
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
|
@ -48,8 +47,8 @@ class rpcApiTestCase(base.BaseTestCase):
|
||||||
if expected_retval:
|
if expected_retval:
|
||||||
return expected_retval
|
return expected_retval
|
||||||
|
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
self.stubs.Set(rpc, rpc_method, _fake_rpc_method)
|
'neutron.openstack.common.rpc.' + rpc_method, _fake_rpc_method))
|
||||||
|
|
||||||
retval = getattr(rpcapi, method)(ctxt, **kwargs)
|
retval = getattr(rpcapi, method)(ctxt, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,6 @@
|
||||||
# @author: Salvatore Orlando, Nicira, Inc
|
# @author: Salvatore Orlando, Nicira, Inc
|
||||||
#
|
#
|
||||||
|
|
||||||
import stubout
|
|
||||||
|
|
||||||
import fixtures
|
|
||||||
import mock
|
import mock
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
from webob import exc
|
from webob import exc
|
||||||
|
@ -49,25 +46,6 @@ FAKE_ROUTER_PORT_ID = _uuid()
|
||||||
FAKE_ROUTER_PORT_MAC = 'bb:bb:bb:bb:bb:bb'
|
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):
|
class TestExtensionManager(object):
|
||||||
|
|
||||||
def get_resources(self):
|
def get_resources(self):
|
||||||
|
@ -104,8 +82,6 @@ class TestL3GwModeMixin(base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestL3GwModeMixin, self).setUp()
|
super(TestL3GwModeMixin, self).setUp()
|
||||||
stubout_fixture = self.useFixture(StuboutFixture())
|
|
||||||
self.stubs = stubout_fixture.stubs
|
|
||||||
self.target_object = TestDbIntPlugin()
|
self.target_object = TestDbIntPlugin()
|
||||||
# Patch the context
|
# Patch the context
|
||||||
ctx_patcher = mock.patch('neutron.context', autospec=True)
|
ctx_patcher = mock.patch('neutron.context', autospec=True)
|
||||||
|
|
|
@ -5,7 +5,6 @@ coverage>=3.6
|
||||||
discover
|
discover
|
||||||
fixtures>=0.3.14
|
fixtures>=0.3.14
|
||||||
mock>=1.0
|
mock>=1.0
|
||||||
mox>=0.5.3
|
|
||||||
python-subunit
|
python-subunit
|
||||||
sphinx>=1.1.2
|
sphinx>=1.1.2
|
||||||
testrepository>=0.0.17
|
testrepository>=0.0.17
|
||||||
|
|
Loading…
Reference in New Issue