From: Akihiro MOTOKI Date: Sun, 2 Dec 2012 21:17:20 +0000 (+0900) Subject: Drop duplicated port_id check in remove_router_interface() X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=73161b06b038293dc680e8af5a37d059b67e8a82;p=openstack-build%2Fneutron-build.git Drop duplicated port_id check in remove_router_interface() Fixes bug 1075157 In addition exceptions used in remove_router_intreface are defined and gettextized. Change-Id: I30b1561f3d4be12e485c506e5c3828b41ab226ef --- diff --git a/quantum/api/v2/base.py b/quantum/api/v2/base.py index 37fedf475..1cdaaa06d 100644 --- a/quantum/api/v2/base.py +++ b/quantum/api/v2/base.py @@ -30,6 +30,7 @@ XML_NS_V20 = 'http://openstack.org/quantum/api/v2.0' FAULT_MAP = {exceptions.NotFound: webob.exc.HTTPNotFound, exceptions.InUse: webob.exc.HTTPConflict, + exceptions.Conflict: webob.exc.HTTPConflict, exceptions.BadRequest: webob.exc.HTTPBadRequest, exceptions.ResourceExhausted: webob.exc.HTTPServiceUnavailable, exceptions.MacAddressGenerationFailure: diff --git a/quantum/common/exceptions.py b/quantum/common/exceptions.py index 4d1013c57..ae9c9e3b5 100644 --- a/quantum/common/exceptions.py +++ b/quantum/common/exceptions.py @@ -42,6 +42,10 @@ class NotFound(QuantumException): pass +class Conflict(QuantumException): + pass + + class NotAuthorized(QuantumException): message = _("Not authorized.") @@ -156,6 +160,11 @@ class AlreadyAttached(QuantumException): "already plugged into port %(att_port_id)s") +class SubnetMismatchForPort(Conflict): + message = _("Subnet on port %(port_id)s does not match " + "the requested subnet %(subnet_id)s") + + class MalformedRequestBody(QuantumException): message = _("Malformed request body: %(reason)s") diff --git a/quantum/db/l3_db.py b/quantum/db/l3_db.py index 78ac1cf5e..10a51a4c2 100644 --- a/quantum/db/l3_db.py +++ b/quantum/db/l3_db.py @@ -22,7 +22,6 @@ import sqlalchemy as sa from sqlalchemy import orm from sqlalchemy.orm import exc from sqlalchemy.sql import expression as expr -import webob.exc as w_exc from quantum.api.v2 import attributes from quantum.common import constants as l3_constants @@ -379,19 +378,14 @@ class L3_NAT_db_mixin(l3.RouterPluginBase): port_db = self._get_port(context, port_id) if not (port_db['device_owner'] == DEVICE_OWNER_ROUTER_INTF and port_db['device_id'] == router_id): - raise w_exc.HTTPNotFound("Router %(router_id)s does not have " - " an interface with id %(port_id)s" - % locals()) + raise l3.RouterInterfaceNotFound(router_id=router_id, + port_id=port_id) if 'subnet_id' in interface_info: port_subnet_id = port_db['fixed_ips'][0]['subnet_id'] if port_subnet_id != interface_info['subnet_id']: - raise w_exc.HTTPConflict("subnet_id %s on port does not " - "match requested one (%s)" - % (port_subnet_id, - interface_info['subnet_id'])) - if port_db['device_id'] != router_id: - raise w_exc.HTTPConflict("port_id %s not used by router" % - port_db['id']) + raise q_exc.SubnetMismatchForPort( + port_id=port_id, + subnet_id=interface_info['subnet_id']) self._confirm_router_interface_not_in_use( context, router_id, port_db['fixed_ips'][0]['subnet_id']) @@ -420,9 +414,8 @@ class L3_NAT_db_mixin(l3.RouterPluginBase): pass if not found: - raise w_exc.HTTPNotFound("Router %(router_id)s has no " - "interface on subnet %(subnet_id)s" - % locals()) + raise l3.RouterInterfaceNotFoundForSubnet(router_id=router_id, + subnet_id=subnet_id) routers = self.get_sync_data(context.elevated(), [router_id]) l3_rpc_agent_api.L3AgentNofity.routers_updated(context, routers) diff --git a/quantum/extensions/l3.py b/quantum/extensions/l3.py index 7d6f3a67c..7d110f897 100644 --- a/quantum/extensions/l3.py +++ b/quantum/extensions/l3.py @@ -37,6 +37,16 @@ class RouterInUse(qexception.InUse): message = _("Router %(router_id)s still has active ports") +class RouterInterfaceNotFound(qexception.NotFound): + message = _("Router %(router_id)s does not have " + "an interface with id %(port_id)s") + + +class RouterInterfaceNotFoundForSubnet(qexception.NotFound): + message = _("Router %(router_id)s has no interface " + "on subnet %(subnet_id)s") + + class RouterInterfaceInUseByFloatingIP(qexception.InUse): message = _("Router interface for subnet %(subnet_id)s on router " "%(router_id)s cannot be deleted, as it is required "