Merge "Drop duplicated port_id check in remove_router_interface()"

This commit is contained in:
Jenkins 2012-12-06 14:22:37 +00:00 committed by Gerrit Code Review
commit 81bdebb520
4 changed files with 27 additions and 14 deletions

View File

@ -30,6 +30,7 @@ XML_NS_V20 = 'http://openstack.org/quantum/api/v2.0'
FAULT_MAP = {exceptions.NotFound: webob.exc.HTTPNotFound, FAULT_MAP = {exceptions.NotFound: webob.exc.HTTPNotFound,
exceptions.InUse: webob.exc.HTTPConflict, exceptions.InUse: webob.exc.HTTPConflict,
exceptions.Conflict: webob.exc.HTTPConflict,
exceptions.BadRequest: webob.exc.HTTPBadRequest, exceptions.BadRequest: webob.exc.HTTPBadRequest,
exceptions.ResourceExhausted: webob.exc.HTTPServiceUnavailable, exceptions.ResourceExhausted: webob.exc.HTTPServiceUnavailable,
exceptions.MacAddressGenerationFailure: exceptions.MacAddressGenerationFailure:

View File

@ -42,6 +42,10 @@ class NotFound(QuantumException):
pass pass
class Conflict(QuantumException):
pass
class NotAuthorized(QuantumException): class NotAuthorized(QuantumException):
message = _("Not authorized.") message = _("Not authorized.")
@ -156,6 +160,11 @@ class AlreadyAttached(QuantumException):
"already plugged into port %(att_port_id)s") "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): class MalformedRequestBody(QuantumException):
message = _("Malformed request body: %(reason)s") message = _("Malformed request body: %(reason)s")

View File

@ -22,7 +22,6 @@ import sqlalchemy as sa
from sqlalchemy import orm from sqlalchemy import orm
from sqlalchemy.orm import exc from sqlalchemy.orm import exc
from sqlalchemy.sql import expression as expr from sqlalchemy.sql import expression as expr
import webob.exc as w_exc
from quantum.api.v2 import attributes from quantum.api.v2 import attributes
from quantum.common import constants as l3_constants 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) port_db = self._get_port(context, port_id)
if not (port_db['device_owner'] == DEVICE_OWNER_ROUTER_INTF and if not (port_db['device_owner'] == DEVICE_OWNER_ROUTER_INTF and
port_db['device_id'] == router_id): port_db['device_id'] == router_id):
raise w_exc.HTTPNotFound("Router %(router_id)s does not have " raise l3.RouterInterfaceNotFound(router_id=router_id,
" an interface with id %(port_id)s" port_id=port_id)
% locals())
if 'subnet_id' in interface_info: if 'subnet_id' in interface_info:
port_subnet_id = port_db['fixed_ips'][0]['subnet_id'] port_subnet_id = port_db['fixed_ips'][0]['subnet_id']
if port_subnet_id != interface_info['subnet_id']: if port_subnet_id != interface_info['subnet_id']:
raise w_exc.HTTPConflict("subnet_id %s on port does not " raise q_exc.SubnetMismatchForPort(
"match requested one (%s)" port_id=port_id,
% (port_subnet_id, subnet_id=interface_info['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'])
self._confirm_router_interface_not_in_use( self._confirm_router_interface_not_in_use(
context, router_id, context, router_id,
port_db['fixed_ips'][0]['subnet_id']) port_db['fixed_ips'][0]['subnet_id'])
@ -420,9 +414,8 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
pass pass
if not found: if not found:
raise w_exc.HTTPNotFound("Router %(router_id)s has no " raise l3.RouterInterfaceNotFoundForSubnet(router_id=router_id,
"interface on subnet %(subnet_id)s" subnet_id=subnet_id)
% locals())
routers = self.get_sync_data(context.elevated(), [router_id]) routers = self.get_sync_data(context.elevated(), [router_id])
l3_rpc_agent_api.L3AgentNofity.routers_updated(context, routers) l3_rpc_agent_api.L3AgentNofity.routers_updated(context, routers)

View File

@ -37,6 +37,16 @@ class RouterInUse(qexception.InUse):
message = _("Router %(router_id)s still has active ports") 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): class RouterInterfaceInUseByFloatingIP(qexception.InUse):
message = _("Router interface for subnet %(subnet_id)s on router " message = _("Router interface for subnet %(subnet_id)s on router "
"%(router_id)s cannot be deleted, as it is required " "%(router_id)s cannot be deleted, as it is required "