]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Drop duplicated port_id check in remove_router_interface()
authorAkihiro MOTOKI <motoki@da.jp.nec.com>
Sun, 2 Dec 2012 21:17:20 +0000 (06:17 +0900)
committerAkihiro MOTOKI <motoki@da.jp.nec.com>
Thu, 6 Dec 2012 03:40:16 +0000 (12:40 +0900)
Fixes bug 1075157

In addition exceptions used in remove_router_intreface are defined
and gettextized.

Change-Id: I30b1561f3d4be12e485c506e5c3828b41ab226ef

quantum/api/v2/base.py
quantum/common/exceptions.py
quantum/db/l3_db.py
quantum/extensions/l3.py

index 37fedf475b3966022a08bad436789de1fad33c02..1cdaaa06d164d0729d3acdace9faba2e997deefa 100644 (file)
@@ -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:
index 4d1013c57451edb18ac3d8133c6ecee89123740c..ae9c9e3b56541a2abc0624d58566c57932046908 100644 (file)
@@ -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")
 
index 78ac1cf5ee614f68028d243cfda21404684c809d..10a51a4c27d570e0e70676dcb1a6ce70c5657ad5 100644 (file)
@@ -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)
 
index 7d6f3a67c1272a19ad1ab28515db16bc29d63a67..7d110f897396b80e05208e23784b29ca18745008 100644 (file)
@@ -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 "