Remove openstack.common.exception usage
This file is deprecated, stop using it. Change-Id: I5d79b8c0134bb5f4021487542d4d0a964281b8bf Fixes-Bug: #1208734
This commit is contained in:
parent
537674c33e
commit
9b50a25c28
@ -19,12 +19,10 @@
|
||||
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.")
|
||||
|
@ -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):
|
||||
|
@ -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"
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -4,7 +4,6 @@ module=context
|
||||
module=db
|
||||
module=db.sqlalchemy
|
||||
module=eventlet_backdoor
|
||||
module=exception
|
||||
module=excutils
|
||||
module=fileutils
|
||||
module=gettextutils
|
||||
|
Loading…
Reference in New Issue
Block a user