update_floatingip_status_while_deleting_the_vm

Change-Id: Id9aae96d8113a5219fa7124f4058e380f39262d9
(cherry picked from commit d3bf50eebd)
(cherry picked from commit a2203367df)
This commit is contained in:
pulkit vajpyee 2022-01-27 13:16:26 +05:30 committed by Thomas Bachman
parent bd020b02ae
commit 952af6bad3
2 changed files with 27 additions and 0 deletions

View File

@ -3186,6 +3186,12 @@ class ApicMechanismDriver(api_plus.MechanismDriver,
self._send_postcommit_notifications(context._plugin_context)
def _update_floatingip_status(self, session, port_id):
query = (sa.update(l3_db.FloatingIP).
where(l3_db.FloatingIP.fixed_port_id == port_id).
values(status=n_constants.FLOATINGIP_STATUS_DOWN))
session.execute(query)
def delete_port_precommit(self, context):
port = context.current
if self._is_port_bound(port):
@ -3201,6 +3207,10 @@ class ApicMechanismDriver(api_plus.MechanismDriver,
self._really_update_sg_rule_with_remote_group_set(
context, port, port['security_groups'], is_delete=True)
# Set status of floating ip DOWN.
self._update_floatingip_status(
context._plugin_context.session, port['id'])
# Handle router gateway port deletion.
if self._is_port_router_gateway(port):
router = self.l3_plugin.get_router(

View File

@ -8400,6 +8400,23 @@ class TestExternalConnectivityBase(object):
self._do_test_multiple_router(use_addr_scope=True,
shared_l3out=True)
def test_delete_port_assoc_with_floatingip(self):
net1 = self._make_network(self.fmt, 'pvt-net1', True)['network']
sub1 = self._make_subnet(
self.fmt, {'network': net1}, '10.10.1.1', '10.10.1.0/24')
with self.port(subnet=sub1) as port:
port = self._bind_port_to_host(port['port']['id'], 'host1')
port['port']['dns_name'] = ''
p = port['port']
with self.floatingip_with_assoc(port_id=p['id']) as fip:
fip = fip['floatingip']
self.assertEqual('ACTIVE', fip['status'])
fip = self._show('floatingips', fip['id'])['floatingip']
self.assertEqual('ACTIVE', fip['status'])
self._delete('ports', p['id'])
fip = self._show('floatingips', fip['id'])['floatingip']
self.assertEqual('DOWN', fip['status'])
def test_floatingip(self):
net1 = self._make_network(self.fmt, 'pvt-net1', True)['network']
sub1 = self._make_subnet(