]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove openstack.common.exception usage
authorJulien Danjou <julien@danjou.info>
Tue, 30 Jul 2013 11:16:51 +0000 (13:16 +0200)
committerJulien Danjou <julien@danjou.info>
Tue, 6 Aug 2013 08:42:02 +0000 (10:42 +0200)
This file is deprecated, stop using it.

Change-Id: I5d79b8c0134bb5f4021487542d4d0a964281b8bf
Fixes-Bug: #1208734

neutron/common/exceptions.py
neutron/neutron_plugin_base_v2.py
neutron/openstack/common/exception.py [deleted file]
neutron/quota.py
neutron/tests/base.py
neutron/tests/unit/test_api_v2.py
openstack-common.conf

index 408d609c58a0732aebb4eb725a6e72df73831c68..68c73f50bb2369fad0bb8c067c8ed41bb3c25af6 100644 (file)
 Neutron base exception handling.
 """
 
-from neutron.openstack.common.exception import Error
-from neutron.openstack.common.exception import InvalidContentType  # noqa
-from neutron.openstack.common.exception import OpenstackException
+_FATAL_EXCEPTION_FORMAT_ERRORS = False
 
 
-class NeutronException(OpenstackException):
+class NeutronException(Exception):
     """Base Neutron Exception.
 
     To correctly use this class, inherit from it and define
@@ -33,6 +31,16 @@ class NeutronException(OpenstackException):
     """
     message = _("An unknown exception occurred.")
 
+    def __init__(self, **kwargs):
+        try:
+            super(NeutronException, self).__init__(self.message % kwargs)
+        except Exception:
+            if _FATAL_EXCEPTION_FORMAT_ERRORS:
+                raise
+            else:
+                # at least get the core message out if something happened
+                super(NeutronException, self).__init__(self.message)
+
 
 class BadRequest(NeutronException):
     message = _('Bad %(resource)s request: %(msg)s')
@@ -185,8 +193,10 @@ class MalformedRequestBody(BadRequest):
     message = _("Malformed request body: %(reason)s")
 
 
-class Invalid(Error):
-    pass
+class Invalid(NeutronException):
+    def __init__(self, message=None):
+        self.message = message
+        super(Invalid, self).__init__()
 
 
 class InvalidInput(BadRequest):
@@ -207,10 +217,6 @@ class OutOfBoundsAllocationPool(BadRequest):
                 "beyond the subnet cidr %(subnet_cidr)s.")
 
 
-class NotImplementedError(Error):
-    pass
-
-
 class MacAddressGenerationFailure(ServiceUnavailable):
     message = _("Unable to generate unique mac on network %(net_id)s.")
 
@@ -257,6 +263,10 @@ class InvalidExtensionEnv(BadRequest):
     message = _("Invalid extension environment: %(reason)s")
 
 
+class InvalidContentType(NeutronException):
+    message = "Invalid content type %(content_type)s"
+
+
 class ExternalIpAddressExhausted(BadRequest):
     message = _("Unable to find any IP address on external "
                 "network %(net_id)s.")
index 9367c29f50ed37dd8986027cadde4b2cb2907219..fb60ffe5995f4084328a445885d68c4ef9952067 100644 (file)
@@ -23,8 +23,6 @@ methods that needs to be implemented by a v2 Neutron Plug-in.
 
 from abc import ABCMeta, abstractmethod
 
-from neutron.common import exceptions
-
 
 class NeutronPluginBaseV2(object):
 
@@ -119,7 +117,7 @@ class NeutronPluginBaseV2(object):
         .. note:: this method is optional, as it was not part of the originally
                   defined plugin API.
         """
-        raise exceptions.NotImplementedError()
+        raise NotImplementedError
 
     @abstractmethod
     def delete_subnet(self, context, id):
@@ -220,7 +218,7 @@ class NeutronPluginBaseV2(object):
         NOTE: this method is optional, as it was not part of the originally
               defined plugin API.
         """
-        raise exceptions.NotImplementedError()
+        raise NotImplementedError
 
     @abstractmethod
     def delete_network(self, context, id):
@@ -316,7 +314,7 @@ class NeutronPluginBaseV2(object):
         .. note:: this method is optional, as it was not part of the originally
                   defined plugin API.
         """
-        raise exceptions.NotImplementedError()
+        raise NotImplementedError
 
     @abstractmethod
     def delete_port(self, context, id):
diff --git a/neutron/openstack/common/exception.py b/neutron/openstack/common/exception.py
deleted file mode 100644 (file)
index a1cf6bb..0000000
+++ /dev/null
@@ -1,141 +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 neutron.openstack.common.gettextutils import _
-
-_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.message = message
-        self.code = code
-        super(ApiError, self).__init__('%s: %s' % (code, message))
-
-
-class NotFound(Error):
-    pass
-
-
-class UnknownScheme(Error):
-
-    msg = "Unknown scheme '%s' found in URI"
-
-    def __init__(self, scheme):
-        msg = self.__class__.msg % scheme
-        super(UnknownScheme, self).__init__(msg)
-
-
-class BadStoreUri(Error):
-
-    msg = "The Store URI %s was malformed. Reason: %s"
-
-    def __init__(self, uri, reason):
-        msg = self.__class__.msg % (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):
-                #exc_type, exc_value, exc_traceback = sys.exc_info()
-                logging.exception(_('Uncaught exception'))
-                #logging.error(traceback.extract_stack(exc_traceback))
-                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 'message' property. That message will get printf'd
-    with the keyword arguments provided to the constructor.
-    """
-    message = "An unknown exception occurred"
-
-    def __init__(self, **kwargs):
-        try:
-            self._error_string = self.message % kwargs
-
-        except Exception as e:
-            if _FATAL_EXCEPTION_FORMAT_ERRORS:
-                raise e
-            else:
-                # at least get the core message out if something happened
-                self._error_string = self.message
-
-    def __str__(self):
-        return self._error_string
-
-
-class MalformedRequestBody(OpenstackException):
-    message = "Malformed message body: %(reason)s"
-
-
-class InvalidContentType(OpenstackException):
-    message = "Invalid content type %(content_type)s"
index fd8c3b3426142a74a3c2e972bf169c0034514a1a..098a1599de11a0bfb30a12eca80874825f1b7f69 100644 (file)
@@ -300,7 +300,7 @@ def _count_resource(context, plugin, resources, tenant_id):
     try:
         obj_count_getter = getattr(plugin, count_getter_name)
         return obj_count_getter(context, filters={'tenant_id': [tenant_id]})
-    except (exceptions.NotImplementedError, AttributeError):
+    except (NotImplementedError, AttributeError):
         obj_getter = getattr(plugin, "get_%s" % resources)
         obj_list = obj_getter(context, filters={'tenant_id': [tenant_id]})
         return len(obj_list) if obj_list else 0
index 3829b551216d3987ea896f9484368157874f34f2..3bb5a2e093bbebb76c6065dc6b05a84a27ff08b5 100644 (file)
@@ -25,7 +25,8 @@ from oslo.config import cfg
 import stubout
 import testtools
 
-from neutron.openstack.common import exception
+from neutron.common import exceptions
+
 
 CONF = cfg.CONF
 TRUE_STRING = ['True', '1']
@@ -62,7 +63,7 @@ class BaseTestCase(testtools.TestCase):
             stderr = self.useFixture(fixtures.StringStream('stderr')).stream
             self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
         self.stubs = stubout.StubOutForTesting()
-        self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True)
+        self.stubs.Set(exceptions, '_FATAL_EXCEPTION_FORMAT_ERRORS', True)
 
     def config(self, **kw):
         """Override some configuration values.
index 200aa2966b9af36ada1ba83a7f573b2d71c19857..7d4d547306676b268e3550399cbfa82fdfb02944 100644 (file)
@@ -1325,7 +1325,7 @@ class QuotaTest(APIv2TestBase):
 
         instance = self.plugin.return_value
         instance.get_networks_count.side_effect = (
-            q_exc.NotImplementedError())
+            NotImplementedError())
         instance.get_networks.return_value = ["foo"]
         res = self.api.post_json(
             _get_path('networks'), initial_input, expect_errors=True)
index ab9ae0d0904134576685b565b76ce718a282227d..7e1c867856f360f67cfadce13d9a1170c74894bc 100644 (file)
@@ -4,7 +4,6 @@ module=context
 module=db
 module=db.sqlalchemy
 module=eventlet_backdoor
-module=exception
 module=excutils
 module=fileutils
 module=gettextutils