summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Danjou <julien@danjou.info>2013-07-30 12:51:54 +0200
committerZhongyue Luo <zhongyue.nah@intel.com>2013-08-16 12:04:18 +0800
commit9721129f2c0c331e3b0428554d421ae670039f81 (patch)
treef3b03508fedfcf045ceff812babe262592bd75da
parent507f69919e78e74b1385ea359dab3a9454017008 (diff)
downloadoslo-9721129f2c0c331e3b0428554d421ae670039f81.tar.gz
oslo-9721129f2c0c331e3b0428554d421ae670039f81.tar.xz
oslo-9721129f2c0c331e3b0428554d421ae670039f81.zip
exception: remove
This patch drops the obsolete openstack.common.exception module. Most project should define their own exception based on their API and the context they evolve in. Many projects don't use this, only neutron, cinder and heat used it. I've copy pasted the few exceptions that they were using, but that's still by far less code than this whole file. Ultimately that will let them a chance to remove or shring their own exception.py. I don't think most projects should have one anyway. Change-Id: Ia8b2b29bd443233def324e97de7342c2634bccff Closes-Bug: #1208734
-rw-r--r--MAINTAINERS6
-rw-r--r--openstack/common/db/sqlalchemy/utils.py12
-rw-r--r--openstack/common/deprecated/wsgi.py31
-rw-r--r--openstack/common/exception.py139
-rw-r--r--openstack/common/rpc/__init__.py3
-rw-r--r--tests/unit/db/sqlalchemy/test_utils.py9
-rw-r--r--tests/unit/deprecated/test_wsgi.py9
-rw-r--r--tests/unit/rpc/common.py10
-rw-r--r--tests/unit/rpc/test_common.py48
-rw-r--r--tests/unit/rpc/test_kombu.py9
-rw-r--r--tests/unit/test_exception.py99
-rw-r--r--tests/utils.py2
12 files changed, 61 insertions, 316 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index 100b364..a611a5c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -115,12 +115,6 @@ M:
S: Orphan
F: eventlet_backdoor.py
-== exception ==
-
-M:
-S: Obsolete
-F: exception.py
-
== excutils ==
M:
diff --git a/openstack/common/db/sqlalchemy/utils.py b/openstack/common/db/sqlalchemy/utils.py
index 64edec2..102f0e5 100644
--- a/openstack/common/db/sqlalchemy/utils.py
+++ b/openstack/common/db/sqlalchemy/utils.py
@@ -40,7 +40,6 @@ from sqlalchemy.types import NullType
from openstack.common.gettextutils import _ # noqa
-from openstack.common import exception
from openstack.common import log as logging
from openstack.common import timeutils
@@ -186,6 +185,10 @@ def visit_insert_from_select(element, compiler, **kw):
compiler.process(element.select))
+class ColumnError(Exception):
+ """Error raised when no column or an invalid column is found."""
+
+
def _get_not_supported_column(col_name_col_instance, column_name):
try:
column = col_name_col_instance[column_name]
@@ -193,13 +196,13 @@ def _get_not_supported_column(col_name_col_instance, column_name):
msg = _("Please specify column %s in col_name_col_instance "
"param. It is required because column has unsupported "
"type by sqlite).")
- raise exception.OpenstackException(message=msg % column_name)
+ raise ColumnError(msg % column_name)
if not isinstance(column, Column):
msg = _("col_name_col_instance param has wrong type of "
"column instance for column %s It should be instance "
"of sqlalchemy.Column.")
- raise exception.OpenstackException(message=msg % column_name)
+ raise ColumnError(msg % column_name)
return column
@@ -297,8 +300,7 @@ def _get_default_deleted_value(table):
return 0
if isinstance(table.c.id.type, String):
return ""
- raise exception.OpenstackException(
- message=_("Unsupported id columns type"))
+ raise ColumnError(_("Unsupported id columns type"))
def _restore_indexes_on_deleted_columns(migrate_engine, table_name, indexes):
diff --git a/openstack/common/deprecated/wsgi.py b/openstack/common/deprecated/wsgi.py
index a9530b3..aff4b92 100644
--- a/openstack/common/deprecated/wsgi.py
+++ b/openstack/common/deprecated/wsgi.py
@@ -35,7 +35,6 @@ import webob.exc
from xml.dom import minidom
from xml.parsers import expat
-from openstack.common import exception
from openstack.common.gettextutils import _ # noqa
from openstack.common import jsonutils
from openstack.common import log as logging
@@ -59,6 +58,18 @@ CONF.register_opts(socket_opts)
LOG = logging.getLogger(__name__)
+class MalformedRequestBody(Exception):
+ def __init__(self, reason):
+ super(MalformedRequestBody, self).__init__(
+ "Malformed message body: %s", reason)
+
+
+class InvalidContentType(Exception):
+ def __init__(self, content_type):
+ super(InvalidContentType, self).__init__(
+ "Invalid content type %s", content_type)
+
+
def run_server(application, port, **kwargs):
"""Run a WSGI server with the given application."""
sock = eventlet.listen(('0.0.0.0', port))
@@ -255,7 +266,7 @@ class Request(webob.Request):
self.default_request_content_types)
if content_type not in allowed_content_types:
- raise exception.InvalidContentType(content_type=content_type)
+ raise InvalidContentType(content_type=content_type)
return content_type
@@ -294,10 +305,10 @@ class Resource(object):
try:
action, action_args, accept = self.deserialize_request(request)
- except exception.InvalidContentType:
+ except InvalidContentType:
msg = _("Unsupported Content-Type")
return webob.exc.HTTPUnsupportedMediaType(explanation=msg)
- except exception.MalformedRequestBody:
+ except MalformedRequestBody:
msg = _("Malformed request body")
return webob.exc.HTTPBadRequest(explanation=msg)
@@ -530,7 +541,7 @@ class ResponseSerializer(object):
try:
return self.body_serializers[content_type]
except (KeyError, TypeError):
- raise exception.InvalidContentType(content_type=content_type)
+ raise InvalidContentType(content_type=content_type)
class RequestHeadersDeserializer(ActionDispatcher):
@@ -589,7 +600,7 @@ class RequestDeserializer(object):
try:
content_type = request.get_content_type()
- except exception.InvalidContentType:
+ except InvalidContentType:
LOG.debug(_("Unrecognized Content-Type provided in request"))
raise
@@ -599,7 +610,7 @@ class RequestDeserializer(object):
try:
deserializer = self.get_body_deserializer(content_type)
- except exception.InvalidContentType:
+ except InvalidContentType:
LOG.debug(_("Unable to deserialize body as provided Content-Type"))
raise
@@ -609,7 +620,7 @@ class RequestDeserializer(object):
try:
return self.body_deserializers[content_type]
except (KeyError, TypeError):
- raise exception.InvalidContentType(content_type=content_type)
+ raise InvalidContentType(content_type=content_type)
def get_expected_content_type(self, request):
return request.best_match_content_type(self.supported_content_types)
@@ -651,7 +662,7 @@ class JSONDeserializer(TextDeserializer):
return jsonutils.loads(datastring)
except ValueError:
msg = _("cannot understand JSON")
- raise exception.MalformedRequestBody(reason=msg)
+ raise MalformedRequestBody(reason=msg)
def default(self, datastring):
return {'body': self._from_json(datastring)}
@@ -676,7 +687,7 @@ class XMLDeserializer(TextDeserializer):
return {node.nodeName: self._from_xml_node(node, plurals)}
except expat.ExpatError:
msg = _("cannot understand XML")
- raise exception.MalformedRequestBody(reason=msg)
+ raise MalformedRequestBody(reason=msg)
def _from_xml_node(self, node, listnames):
"""Convert a minidom node to a simple Python type.
diff --git a/openstack/common/exception.py b/openstack/common/exception.py
deleted file mode 100644
index 13c3bff..0000000
--- a/openstack/common/exception.py
+++ /dev/null
@@ -1,139 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2011 OpenStack Foundation.
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-"""
-Exceptions common to OpenStack projects
-"""
-
-import logging
-
-from openstack.common.gettextutils import _ # noqa
-
-_FATAL_EXCEPTION_FORMAT_ERRORS = False
-
-
-class Error(Exception):
- def __init__(self, message=None):
- super(Error, self).__init__(message)
-
-
-class ApiError(Error):
- def __init__(self, message='Unknown', code='Unknown'):
- self.api_message = message
- self.code = code
- super(ApiError, self).__init__('%s: %s' % (code, message))
-
-
-class NotFound(Error):
- pass
-
-
-class UnknownScheme(Error):
-
- msg_fmt = "Unknown scheme '%s' found in URI"
-
- def __init__(self, scheme):
- msg = self.msg_fmt % scheme
- super(UnknownScheme, self).__init__(msg)
-
-
-class BadStoreUri(Error):
-
- msg_fmt = "The Store URI %s was malformed. Reason: %s"
-
- def __init__(self, uri, reason):
- msg = self.msg_fmt % (uri, reason)
- super(BadStoreUri, self).__init__(msg)
-
-
-class Duplicate(Error):
- pass
-
-
-class NotAuthorized(Error):
- pass
-
-
-class NotEmpty(Error):
- pass
-
-
-class Invalid(Error):
- pass
-
-
-class BadInputError(Exception):
- """Error resulting from a client sending bad input to a server"""
- pass
-
-
-class MissingArgumentError(Error):
- pass
-
-
-class DatabaseMigrationError(Error):
- pass
-
-
-class ClientConnectionError(Exception):
- """Error resulting from a client connecting to a server"""
- pass
-
-
-def wrap_exception(f):
- def _wrap(*args, **kw):
- try:
- return f(*args, **kw)
- except Exception as e:
- if not isinstance(e, Error):
- logging.exception(_('Uncaught exception'))
- raise Error(str(e))
- raise
- _wrap.func_name = f.func_name
- return _wrap
-
-
-class OpenstackException(Exception):
- """Base Exception class.
-
- To correctly use this class, inherit from it and define
- a 'msg_fmt' property. That message will get printf'd
- with the keyword arguments provided to the constructor.
- """
- msg_fmt = "An unknown exception occurred"
-
- def __init__(self, **kwargs):
- try:
- self._error_string = self.msg_fmt % kwargs
-
- except Exception:
- if _FATAL_EXCEPTION_FORMAT_ERRORS:
- raise
- else:
- # at least get the core message out if something happened
- self._error_string = self.msg_fmt
-
- def __str__(self):
- return self._error_string
-
-
-class MalformedRequestBody(OpenstackException):
- msg_fmt = "Malformed message body: %(reason)s"
-
-
-class InvalidContentType(OpenstackException):
- msg_fmt = "Invalid content type %(content_type)s"
diff --git a/openstack/common/rpc/__init__.py b/openstack/common/rpc/__init__.py
index e39f294..104b059 100644
--- a/openstack/common/rpc/__init__.py
+++ b/openstack/common/rpc/__init__.py
@@ -56,8 +56,7 @@ rpc_opts = [
help='Seconds to wait before a cast expires (TTL). '
'Only supported by impl_zmq.'),
cfg.ListOpt('allowed_rpc_exception_modules',
- default=['openstack.common.exception',
- 'nova.exception',
+ default=['nova.exception',
'cinder.exception',
'exceptions',
],
diff --git a/tests/unit/db/sqlalchemy/test_utils.py b/tests/unit/db/sqlalchemy/test_utils.py
index 5f46f3f..0d8d87c 100644
--- a/tests/unit/db/sqlalchemy/test_utils.py
+++ b/tests/unit/db/sqlalchemy/test_utils.py
@@ -28,7 +28,6 @@ from sqlalchemy.sql import select
from sqlalchemy.types import UserDefinedType, NullType
from openstack.common.db.sqlalchemy import utils
-from openstack.common import exception
from tests.unit.db.sqlalchemy import test_migrations
from tests import utils as testutils
@@ -335,7 +334,7 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
Column('deleted', Boolean))
table.create()
- self.assertRaises(exception.OpenstackException,
+ self.assertRaises(utils.ColumnError,
utils.change_deleted_column_type_to_id_type,
engine, table_name)
@@ -376,7 +375,7 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
Column('deleted', Integer))
table.create()
- self.assertRaises(exception.OpenstackException,
+ self.assertRaises(utils.ColumnError,
utils.change_deleted_column_type_to_boolean,
engine, table_name)
@@ -459,13 +458,13 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
warnings.simplefilter("ignore", SAWarning)
# NOTE(boris-42): Missing info about column `foo` that has
# unsupported type CustomType.
- self.assertRaises(exception.OpenstackException,
+ self.assertRaises(utils.ColumnError,
utils.drop_unique_constraint,
engine, table_name, uc_name, 'foo')
# NOTE(boris-42): Wrong type of foo instance. it should be
# instance of sqlalchemy.Column.
- self.assertRaises(exception.OpenstackException,
+ self.assertRaises(utils.ColumnError,
utils.drop_unique_constraint,
engine, table_name, uc_name, 'foo', foo=Integer())
diff --git a/tests/unit/deprecated/test_wsgi.py b/tests/unit/deprecated/test_wsgi.py
index 72aeae7..abc883d 100644
--- a/tests/unit/deprecated/test_wsgi.py
+++ b/tests/unit/deprecated/test_wsgi.py
@@ -25,7 +25,6 @@ import six
import webob
from openstack.common.deprecated import wsgi
-from openstack.common import exception
from tests import utils
@@ -44,7 +43,7 @@ class RequestTest(utils.BaseTestCase):
request = wsgi.Request.blank('/tests/123', method='POST')
request.headers["Content-Type"] = "text/html"
request.body = "asdf<br />"
- self.assertRaises(exception.InvalidContentType,
+ self.assertRaises(wsgi.InvalidContentType,
request.get_content_type)
def test_content_type_with_charset(self):
@@ -311,7 +310,7 @@ class ResponseSerializerTest(utils.BaseTestCase):
self.body_serializers[ctype])
def test_get_serializer_unknown_content_type(self):
- self.assertRaises(exception.InvalidContentType,
+ self.assertRaises(wsgi.InvalidContentType,
self.serializer.get_body_serializer,
'application/unknown')
@@ -335,7 +334,7 @@ class ResponseSerializerTest(utils.BaseTestCase):
self.assertEqual(response.status_int, 404)
def test_serialize_response_dict_to_unknown_content_type(self):
- self.assertRaises(exception.InvalidContentType,
+ self.assertRaises(wsgi.InvalidContentType,
self.serializer.serialize,
{}, 'application/unknown')
@@ -371,7 +370,7 @@ class RequestDeserializerTest(utils.BaseTestCase):
self.body_deserializers['application/xml'])
def test_get_deserializer_unknown_content_type(self):
- self.assertRaises(exception.InvalidContentType,
+ self.assertRaises(wsgi.InvalidContentType,
self.deserializer.get_body_deserializer,
'application/unknown')
diff --git a/tests/unit/rpc/common.py b/tests/unit/rpc/common.py
index 2c343fe..4cc279c 100644
--- a/tests/unit/rpc/common.py
+++ b/tests/unit/rpc/common.py
@@ -26,7 +26,6 @@ import time
import eventlet
from oslo.config import cfg
-from openstack.common import exception
from openstack.common.gettextutils import _ # noqa
from openstack.common.rpc import common as rpc_common
from openstack.common.rpc import dispatcher as rpc_dispatcher
@@ -37,6 +36,13 @@ FLAGS = cfg.CONF
LOG = logging.getLogger(__name__)
+class ApiError(Exception):
+ def __init__(self, message='Unknown', code='Unknown'):
+ self.api_message = message
+ self.code = code
+ super(ApiError, self).__init__('%s: %s' % (code, message))
+
+
class BaseRpcTestCase(test_utils.BaseTestCase):
def setUp(self, supports_timeouts=True, topic='test',
@@ -424,7 +430,7 @@ class TestReceiver(object):
@staticmethod
def fail_converted(context, value):
"""Raises an exception with the value sent in."""
- raise exception.ApiError(message=value, code='500')
+ raise ApiError(message=value, code='500')
@staticmethod
def block(context, value):
diff --git a/tests/unit/rpc/test_common.py b/tests/unit/rpc/test_common.py
index 291f823..a6a2188 100644
--- a/tests/unit/rpc/test_common.py
+++ b/tests/unit/rpc/test_common.py
@@ -23,7 +23,6 @@ import sys
from oslo.config import cfg
import six
-from openstack.common import exception
from openstack.common import importutils
from openstack.common import jsonutils
from openstack.common import rpc
@@ -35,10 +34,6 @@ FLAGS = cfg.CONF
LOG = logging.getLogger(__name__)
-def raise_exception():
- raise Exception("test")
-
-
class FakeUserDefinedException(Exception):
def __init__(self, *args, **kwargs):
super(FakeUserDefinedException, self).__init__(*args)
@@ -54,7 +49,7 @@ class RpcCommonTestCase(test_utils.BaseTestCase):
}
try:
- raise_exception()
+ raise Exception("test")
except Exception:
failure = rpc_common.serialize_remote_exception(sys.exc_info())
@@ -64,17 +59,14 @@ class RpcCommonTestCase(test_utils.BaseTestCase):
self.assertEqual(expected['message'], failure['message'])
def test_serialize_remote_custom_exception(self):
- def raise_custom_exception():
- raise exception.MalformedRequestBody(reason='test')
-
expected = {
- 'class': 'MalformedRequestBody',
- 'module': 'openstack.common.exception',
- 'message': str(exception.MalformedRequestBody(reason='test')),
+ 'class': 'FakeUserDefinedException',
+ 'module': self.__class__.__module__,
+ 'message': 'test',
}
try:
- raise_custom_exception()
+ raise FakeUserDefinedException('test')
except Exception:
failure = rpc_common.serialize_remote_exception(sys.exc_info())
@@ -88,14 +80,14 @@ class RpcCommonTestCase(test_utils.BaseTestCase):
# module, when being re-serialized, so that through any amount of cell
# hops up, it can pop out with the right type
expected = {
- 'class': 'OpenstackException',
- 'module': 'openstack.common.exception',
- 'message': exception.OpenstackException.msg_fmt,
+ 'class': 'FakeUserDefinedException',
+ 'module': self.__class__.__module__,
+ 'message': 'foobar',
}
def raise_remote_exception():
try:
- raise exception.OpenstackException()
+ raise FakeUserDefinedException('foobar')
except Exception as e:
ex_type = type(e)
message = str(e)
@@ -132,26 +124,6 @@ class RpcCommonTestCase(test_utils.BaseTestCase):
self.assertTrue('raise NotImplementedError' in
six.text_type(after_exc))
- def test_deserialize_remote_custom_exception(self):
- failure = {
- 'class': 'OpenstackException',
- 'module': 'openstack.common.exception',
- 'message': exception.OpenstackException.msg_fmt,
- 'tb': ['raise OpenstackException'],
- }
- serialized = jsonutils.dumps(failure)
-
- after_exc = rpc_common.deserialize_remote_exception(FLAGS, serialized)
- self.assertTrue(isinstance(after_exc, exception.OpenstackException))
- self.assertTrue('An unknown' in six.text_type(after_exc))
- #assure the traceback was added
- self.assertTrue('raise OpenstackException' in six.text_type(after_exc))
- self.assertEqual('OpenstackException_Remote',
- after_exc.__class__.__name__)
- self.assertEqual('openstack.common.exception_Remote',
- after_exc.__class__.__module__)
- self.assertTrue(isinstance(after_exc, exception.OpenstackException))
-
def test_deserialize_remote_exception_bad_module(self):
failure = {
'class': 'popen2',
@@ -169,6 +141,7 @@ class RpcCommonTestCase(test_utils.BaseTestCase):
self.config(allowed_rpc_exception_modules=[self.__class__.__module__])
failure = {
'class': 'FakeUserDefinedException',
+ 'message': 'foobar',
'module': self.__class__.__module__,
'tb': ['raise FakeUserDefinedException'],
}
@@ -176,6 +149,7 @@ class RpcCommonTestCase(test_utils.BaseTestCase):
after_exc = rpc_common.deserialize_remote_exception(FLAGS, serialized)
self.assertTrue(isinstance(after_exc, FakeUserDefinedException))
+ self.assertTrue('foobar' in six.text_type(after_exc))
#assure the traceback was added
self.assertTrue('raise FakeUserDefinedException' in
six.text_type(after_exc))
diff --git a/tests/unit/rpc/test_kombu.py b/tests/unit/rpc/test_kombu.py
index cbe948d..695e701 100644
--- a/tests/unit/rpc/test_kombu.py
+++ b/tests/unit/rpc/test_kombu.py
@@ -33,10 +33,10 @@ from oslo.config import cfg
import six
import time
-from openstack.common import exception
from openstack.common.rpc import amqp as rpc_amqp
from openstack.common.rpc import common as rpc_common
from tests.unit.rpc import amqp
+from tests.unit.rpc import common
from tests import utils
try:
@@ -596,7 +596,8 @@ class RpcKombuTestCase(amqp.BaseRpcAMQPTestCase):
"""
value = "This is the exception message"
# The use of ApiError is an arbitrary choice here ...
- self.assertRaises(exception.ApiError,
+ self.config(allowed_rpc_exception_modules=[common.__name__])
+ self.assertRaises(common.ApiError,
self.rpc.call,
FLAGS,
self.context,
@@ -609,10 +610,10 @@ class RpcKombuTestCase(amqp.BaseRpcAMQPTestCase):
{"method": "fail_converted",
"args": {"value": value}})
self.fail("should have thrown Exception")
- except exception.ApiError as exc:
+ except common.ApiError as exc:
self.assertTrue(value in six.text_type(exc))
#Traceback should be included in exception message
- self.assertTrue('exception.ApiError' in six.text_type(exc))
+ self.assertTrue('ApiError' in six.text_type(exc))
def test_create_worker(self):
meth = 'declare_topic_consumer'
diff --git a/tests/unit/test_exception.py b/tests/unit/test_exception.py
deleted file mode 100644
index 407e68d..0000000
--- a/tests/unit/test_exception.py
+++ /dev/null
@@ -1,99 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2011 OpenStack Foundation.
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-from openstack.common import exception
-from tests import utils
-
-
-def good_function():
- return "Is Bueno!"
-
-
-def bad_function_error():
- raise exception.Error()
-
-
-def bad_function_exception():
- raise Exception()
-
-
-class WrapExceptionTest(utils.BaseTestCase):
-
- def test_wrap_exception_good_return(self):
- wrapped = exception.wrap_exception
- self.assertEquals(good_function(), wrapped(good_function)())
-
- def test_wrap_exception_throws_error(self):
- wrapped = exception.wrap_exception
- self.assertRaises(exception.Error, wrapped(bad_function_error))
-
- def test_wrap_exception_throws_exception(self):
- wrapped = exception.wrap_exception
- self.assertRaises(Exception, wrapped(bad_function_exception))
-
-
-class ApiErrorTest(utils.BaseTestCase):
-
- def test_without_code(self):
- err = exception.ApiError('fake error')
- self.assertEqual(str(err), 'Unknown: fake error')
- self.assertEqual(err.code, 'Unknown')
- self.assertEqual(err.api_message, 'fake error')
-
- def test_with_code(self):
- err = exception.ApiError('fake error', 'blah code')
- self.assertEqual(str(err), 'blah code: fake error')
- self.assertEqual(err.code, 'blah code')
- self.assertEqual(err.api_message, 'fake error')
-
-
-class BadStoreUriTest(utils.BaseTestCase):
-
- def test(self):
- uri = 'http:///etc/passwd'
- reason = 'Permission DENIED!'
- err = exception.BadStoreUri(uri, reason)
- self.assertTrue(uri in str(err))
- self.assertTrue(reason in str(err))
-
-
-class UnknownSchemeTest(utils.BaseTestCase):
-
- def test(self):
- scheme = 'http'
- err = exception.UnknownScheme(scheme)
- self.assertTrue(scheme in str(err))
-
-
-class OpenstackExceptionTest(utils.BaseTestCase):
- class TestException(exception.OpenstackException):
- msg_fmt = '%(test)s'
-
- def test_format_error_string(self):
- test_message = 'Know Your Meme'
- err = self.TestException(test=test_message)
- self.assertEqual(err._error_string, test_message)
-
- def test_error_formating_error_string(self):
- self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', False)
- err = self.TestException(lol='U mad brah')
- self.assertEqual(err._error_string, self.TestException.msg_fmt)
-
- def test_str(self):
- message = 'Y u no fail'
- err = self.TestException(test=message)
- self.assertEqual(str(err), message)
diff --git a/tests/utils.py b/tests/utils.py
index f49e0af..b0770a9 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -24,7 +24,6 @@ import fixtures
from oslo.config import cfg
import testtools
-from openstack.common import exception
from openstack.common.fixture import moxstubout
@@ -56,7 +55,6 @@ class BaseTestCase(testtools.TestCase):
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
- self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True)
self.useFixture(fixtures.NestedTempfile())
self.tempdirs = []