Fix a bug where ports may not be deleted

A loop to delete vip ports had an improperly scoped try block that
could, under the right circumstance lead to ports not getting deleted.
This patch fixes that scoping.

Co-Authored-By: Adam Harwell <flux.adam@gmail.com>
Change-Id: I162eed5e48b361ed9f4c5b10edcf90bd8a7d4818
This commit is contained in:
johnsom 2017-02-08 21:02:21 -08:00 committed by Adam Harwell
parent cb4261444d
commit 412fb302a6
3 changed files with 12 additions and 9 deletions

View File

@ -264,9 +264,9 @@ class AllowedAddressPairsDriver(neutron_base.BaseNeutronDriver):
This can happen if a failover has occurred.
"""
try:
for amphora in six.moves.filter(self._filter_amphora,
vip.load_balancer.amphorae):
try:
self.neutron_client.delete_port(amphora.vrrp_port_id)
except (neutron_client_exceptions.NotFound,
neutron_client_exceptions.PortNotFoundClient):

View File

@ -41,7 +41,6 @@ def generate_load_balancer(vip=None, amphorae=None):
amp.load_balancer = lb
amp.load_balancer_id = lb.id
amp.status = constants.AMPHORA_ALLOCATED
amp.vrrp_port_id = 'vrrp_port-{0}-id'.format(VIP_SEED)
if vip:
vip.load_balancer = lb
vip.load_balancer_id = lb.id
@ -74,6 +73,7 @@ def generate_amphora(load_balancer=None):
status='ACTIVE',
lb_network_ip='99.99.99.{0}'.format(AMP_SEED),
vrrp_ip='55.55.55.{0}'.format(AMP_SEED),
vrrp_port_id='vrrp_port-{0}-id'.format(AMP_SEED),
load_balancer=load_balancer)
if load_balancer:
amp.load_balancer_id = load_balancer.id

View File

@ -120,7 +120,10 @@ class TestAllowedAddressPairsDriver(base.TestCase):
}
list_security_groups.return_value = security_groups
self.driver.deallocate_vip(vip)
delete_port.assert_called_with(vip.port_id)
calls = [mock.call(vip.port_id)]
for amp in lb.amphorae:
calls.append(mock.call(amp.vrrp_port_id))
delete_port.assert_has_calls(calls, any_order=True)
delete_sec_grp.assert_called_once_with(sec_grp_id)
def test_deallocate_vip_no_sec_group(self):