Remove openstack.common.exception usage
This file is deprecated, stop using it. Change-Id: I5d79b8c0134bb5f4021487542d4d0a964281b8bf Fixes-Bug: #1208734
This commit is contained in:
parent
97ec829d86
commit
65928476dd
@ -19,12 +19,10 @@
|
|||||||
Neutron base exception handling.
|
Neutron base exception handling.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from neutron.openstack.common.exception import Error
|
_FATAL_EXCEPTION_FORMAT_ERRORS = False
|
||||||
from neutron.openstack.common.exception import InvalidContentType # noqa
|
|
||||||
from neutron.openstack.common.exception import OpenstackException
|
|
||||||
|
|
||||||
|
|
||||||
class NeutronException(OpenstackException):
|
class NeutronException(Exception):
|
||||||
"""Base Neutron Exception.
|
"""Base Neutron Exception.
|
||||||
|
|
||||||
To correctly use this class, inherit from it and define
|
To correctly use this class, inherit from it and define
|
||||||
@ -33,6 +31,16 @@ class NeutronException(OpenstackException):
|
|||||||
"""
|
"""
|
||||||
message = _("An unknown exception occurred.")
|
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):
|
class BadRequest(NeutronException):
|
||||||
message = _('Bad %(resource)s request: %(msg)s')
|
message = _('Bad %(resource)s request: %(msg)s')
|
||||||
@ -185,8 +193,10 @@ class MalformedRequestBody(BadRequest):
|
|||||||
message = _("Malformed request body: %(reason)s")
|
message = _("Malformed request body: %(reason)s")
|
||||||
|
|
||||||
|
|
||||||
class Invalid(Error):
|
class Invalid(NeutronException):
|
||||||
pass
|
def __init__(self, message=None):
|
||||||
|
self.message = message
|
||||||
|
super(Invalid, self).__init__()
|
||||||
|
|
||||||
|
|
||||||
class InvalidInput(BadRequest):
|
class InvalidInput(BadRequest):
|
||||||
@ -207,10 +217,6 @@ class OutOfBoundsAllocationPool(BadRequest):
|
|||||||
"beyond the subnet cidr %(subnet_cidr)s.")
|
"beyond the subnet cidr %(subnet_cidr)s.")
|
||||||
|
|
||||||
|
|
||||||
class NotImplementedError(Error):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class MacAddressGenerationFailure(ServiceUnavailable):
|
class MacAddressGenerationFailure(ServiceUnavailable):
|
||||||
message = _("Unable to generate unique mac on network %(net_id)s.")
|
message = _("Unable to generate unique mac on network %(net_id)s.")
|
||||||
|
|
||||||
@ -257,6 +263,10 @@ class InvalidExtensionEnv(BadRequest):
|
|||||||
message = _("Invalid extension environment: %(reason)s")
|
message = _("Invalid extension environment: %(reason)s")
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidContentType(NeutronException):
|
||||||
|
message = "Invalid content type %(content_type)s"
|
||||||
|
|
||||||
|
|
||||||
class ExternalIpAddressExhausted(BadRequest):
|
class ExternalIpAddressExhausted(BadRequest):
|
||||||
message = _("Unable to find any IP address on external "
|
message = _("Unable to find any IP address on external "
|
||||||
"network %(net_id)s.")
|
"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 abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
from neutron.common import exceptions
|
|
||||||
|
|
||||||
|
|
||||||
class NeutronPluginBaseV2(object):
|
class NeutronPluginBaseV2(object):
|
||||||
|
|
||||||
@ -119,7 +117,7 @@ class NeutronPluginBaseV2(object):
|
|||||||
.. note:: this method is optional, as it was not part of the originally
|
.. note:: this method is optional, as it was not part of the originally
|
||||||
defined plugin API.
|
defined plugin API.
|
||||||
"""
|
"""
|
||||||
raise exceptions.NotImplementedError()
|
raise NotImplementedError
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def delete_subnet(self, context, id):
|
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
|
NOTE: this method is optional, as it was not part of the originally
|
||||||
defined plugin API.
|
defined plugin API.
|
||||||
"""
|
"""
|
||||||
raise exceptions.NotImplementedError()
|
raise NotImplementedError
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def delete_network(self, context, id):
|
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
|
.. note:: this method is optional, as it was not part of the originally
|
||||||
defined plugin API.
|
defined plugin API.
|
||||||
"""
|
"""
|
||||||
raise exceptions.NotImplementedError()
|
raise NotImplementedError
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def delete_port(self, context, id):
|
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:
|
try:
|
||||||
obj_count_getter = getattr(plugin, count_getter_name)
|
obj_count_getter = getattr(plugin, count_getter_name)
|
||||||
return obj_count_getter(context, filters={'tenant_id': [tenant_id]})
|
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_getter = getattr(plugin, "get_%s" % resources)
|
||||||
obj_list = obj_getter(context, filters={'tenant_id': [tenant_id]})
|
obj_list = obj_getter(context, filters={'tenant_id': [tenant_id]})
|
||||||
return len(obj_list) if obj_list else 0
|
return len(obj_list) if obj_list else 0
|
||||||
|
@ -25,7 +25,8 @@ from oslo.config import cfg
|
|||||||
import stubout
|
import stubout
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from neutron.openstack.common import exception
|
from neutron.common import exceptions
|
||||||
|
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
TRUE_STRING = ['True', '1']
|
TRUE_STRING = ['True', '1']
|
||||||
@ -62,7 +63,7 @@ class BaseTestCase(testtools.TestCase):
|
|||||||
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.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):
|
def config(self, **kw):
|
||||||
"""Override some configuration values.
|
"""Override some configuration values.
|
||||||
|
@ -1325,7 +1325,7 @@ class QuotaTest(APIv2TestBase):
|
|||||||
|
|
||||||
instance = self.plugin.return_value
|
instance = self.plugin.return_value
|
||||||
instance.get_networks_count.side_effect = (
|
instance.get_networks_count.side_effect = (
|
||||||
q_exc.NotImplementedError())
|
NotImplementedError())
|
||||||
instance.get_networks.return_value = ["foo"]
|
instance.get_networks.return_value = ["foo"]
|
||||||
res = self.api.post_json(
|
res = self.api.post_json(
|
||||||
_get_path('networks'), initial_input, expect_errors=True)
|
_get_path('networks'), initial_input, expect_errors=True)
|
||||||
|
@ -4,7 +4,6 @@ module=context
|
|||||||
module=db
|
module=db
|
||||||
module=db.sqlalchemy
|
module=db.sqlalchemy
|
||||||
module=eventlet_backdoor
|
module=eventlet_backdoor
|
||||||
module=exception
|
|
||||||
module=excutils
|
module=excutils
|
||||||
module=fileutils
|
module=fileutils
|
||||||
module=gettextutils
|
module=gettextutils
|
||||||
|
Loading…
Reference in New Issue
Block a user