Skip to content

Commit

Permalink
Remove openstack.common.exception usage
Browse files Browse the repository at this point in the history
This file is deprecated, stop using it.

Change-Id: I5d79b8c0134bb5f4021487542d4d0a964281b8bf
Fixes-Bug: #1208734
  • Loading branch information
jd committed Aug 6, 2013
1 parent 537674c commit 9b50a25
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 161 deletions.
30 changes: 20 additions & 10 deletions neutron/common/exceptions.py
Expand Up @@ -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
Expand All @@ -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')
Expand Down Expand Up @@ -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):
Expand All @@ -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.")

Expand Down Expand Up @@ -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.")
Expand Down
8 changes: 3 additions & 5 deletions neutron/neutron_plugin_base_v2.py
Expand Up @@ -23,8 +23,6 @@

from abc import ABCMeta, abstractmethod

from neutron.common import exceptions


class NeutronPluginBaseV2(object):

Expand Down Expand Up @@ -119,7 +117,7 @@ def get_subnets_count(self, context, filters=None):
.. 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):
Expand Down Expand Up @@ -220,7 +218,7 @@ def get_networks_count(self, context, filters=None):
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):
Expand Down Expand Up @@ -316,7 +314,7 @@ def get_ports_count(self, context, filters=None):
.. 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):
Expand Down
141 changes: 0 additions & 141 deletions neutron/openstack/common/exception.py

This file was deleted.

2 changes: 1 addition & 1 deletion neutron/quota.py
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions neutron/tests/base.py
Expand Up @@ -25,7 +25,8 @@
import stubout
import testtools

from neutron.openstack.common import exception
from neutron.common import exceptions


CONF = cfg.CONF
TRUE_STRING = ['True', '1']
Expand Down Expand Up @@ -62,7 +63,7 @@ def setUp(self):
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.
Expand Down
2 changes: 1 addition & 1 deletion neutron/tests/unit/test_api_v2.py
Expand Up @@ -1325,7 +1325,7 @@ def test_create_network_quota_no_counts(self):

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)
Expand Down
1 change: 0 additions & 1 deletion openstack-common.conf
Expand Up @@ -4,7 +4,6 @@ module=context
module=db
module=db.sqlalchemy
module=eventlet_backdoor
module=exception
module=excutils
module=fileutils
module=gettextutils
Expand Down

0 comments on commit 9b50a25

Please sign in to comment.