L3 port delete prevention: do not raise if no IP on port
Bug #1104337 This patch alters the prevent_l3_port_deletion logic. PortInUse is raised only if the port has a device owner in (router_interface, router_gateway, floatingip) and an IP address. If no IP address is found on the port the port itself can be considered stale and therefore deleted as any association with l3 entities would be void. Change-Id: I9d711b2a9d2cbcc8be481f1751f51fe5b9f01327
This commit is contained in:
parent
193dbf6d1c
commit
f9dbd2293d
@ -740,8 +740,17 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
|
|||||||
if port_db['device_owner'] in [DEVICE_OWNER_ROUTER_INTF,
|
if port_db['device_owner'] in [DEVICE_OWNER_ROUTER_INTF,
|
||||||
DEVICE_OWNER_ROUTER_GW,
|
DEVICE_OWNER_ROUTER_GW,
|
||||||
DEVICE_OWNER_FLOATINGIP]:
|
DEVICE_OWNER_FLOATINGIP]:
|
||||||
|
# Raise port in use only if the port has IP addresses
|
||||||
|
# Otherwise it's a stale port that can be removed
|
||||||
|
fixed_ips = port_db['fixed_ips'].all()
|
||||||
|
if fixed_ips:
|
||||||
raise l3.L3PortInUse(port_id=port_id,
|
raise l3.L3PortInUse(port_id=port_id,
|
||||||
device_owner=port_db['device_owner'])
|
device_owner=port_db['device_owner'])
|
||||||
|
else:
|
||||||
|
LOG.debug(_("Port %(port_id)s has owner %(port_owner)s, but "
|
||||||
|
"no IP address, so it can be deleted"),
|
||||||
|
{'port_id': port_db['id'],
|
||||||
|
'port_owner': port_db['device_owner']})
|
||||||
|
|
||||||
def disassociate_floatingips(self, context, port_id):
|
def disassociate_floatingips(self, context, port_id):
|
||||||
with context.session.begin(subtransactions=True):
|
with context.session.begin(subtransactions=True):
|
||||||
|
@ -968,6 +968,23 @@ class L3NatDBTestCase(L3NatTestCaseBase):
|
|||||||
r['router']['id'],
|
r['router']['id'],
|
||||||
n['network']['id'], expected_code=exc.HTTPBadRequest.code)
|
n['network']['id'], expected_code=exc.HTTPBadRequest.code)
|
||||||
|
|
||||||
|
def test_delete_unused_router_interface(self):
|
||||||
|
with self.network() as n:
|
||||||
|
with self.router() as r:
|
||||||
|
with self.subnet(network=n) as s:
|
||||||
|
res = self._create_port(self.fmt,
|
||||||
|
s['subnet']['network_id'])
|
||||||
|
p = self.deserialize(self.fmt, res)
|
||||||
|
self._router_interface_action('add',
|
||||||
|
r['router']['id'],
|
||||||
|
None,
|
||||||
|
p['port']['id'])
|
||||||
|
# The subnet here is deleted, and the port should have no IP
|
||||||
|
self._delete('ports', p['port']['id'])
|
||||||
|
# Verify the port has been deleted
|
||||||
|
self._show('ports', p['port']['id'],
|
||||||
|
expected_code=exc.HTTPNotFound.code)
|
||||||
|
|
||||||
def test_router_remove_interface_inuse_returns_409(self):
|
def test_router_remove_interface_inuse_returns_409(self):
|
||||||
with self.router() as r:
|
with self.router() as r:
|
||||||
with self.subnet() as s:
|
with self.subnet() as s:
|
||||||
|
Loading…
Reference in New Issue
Block a user