diff options
| author | Julien Danjou <julien@danjou.info> | 2013-07-30 12:51:54 +0200 |
|---|---|---|
| committer | Zhongyue Luo <zhongyue.nah@intel.com> | 2013-08-16 12:04:18 +0800 |
| commit | 9721129f2c0c331e3b0428554d421ae670039f81 (patch) | |
| tree | f3b03508fedfcf045ceff812babe262592bd75da /openstack/common | |
| parent | 507f69919e78e74b1385ea359dab3a9454017008 (diff) | |
| download | oslo-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
Diffstat (limited to 'openstack/common')
| -rw-r--r-- | openstack/common/db/sqlalchemy/utils.py | 12 | ||||
| -rw-r--r-- | openstack/common/deprecated/wsgi.py | 31 | ||||
| -rw-r--r-- | openstack/common/exception.py | 139 | ||||
| -rw-r--r-- | openstack/common/rpc/__init__.py | 3 |
4 files changed, 29 insertions, 156 deletions
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', ], |
