Refresh info_cache after deleting floating IP

When deleting a floating IP associated with Neutron's info_cache we don't
refresh the info_cache after it is deleted.
This patch makes it so the info_cache is refreshed when an associated
floating IP is deleted. If there is no info_cache associated with the
floating IP then info_cache is not refreshed.

Change-Id: I8a8ae8cdbe2d9d77e7f1ae94ebdf6e4ad46eaf00
Closes-Bug:  #1614538
(cherry picked from commit cdb9b6820d)
This commit is contained in:
Michael Wurtz 2016-08-18 14:53:33 -05:00 committed by Matt Riedemann
parent c8b8365d31
commit a832e6b2a0
2 changed files with 27 additions and 2 deletions

View File

@ -1553,8 +1553,18 @@ class API(base_api.NetworkAPI):
This api call was added to allow this to be done in one operation This api call was added to allow this to be done in one operation
if using neutron. if using neutron.
""" """
self._release_floating_ip(context, floating_ip['address'],
raise_if_associated=False) @base_api.refresh_cache
def _release_floating_ip_and_refresh_cache(self, context, instance,
floating_ip):
self._release_floating_ip(context, floating_ip['address'],
raise_if_associated=False)
if instance:
_release_floating_ip_and_refresh_cache(self, context, instance,
floating_ip)
else:
self._release_floating_ip(context, floating_ip['address'],
raise_if_associated=False)
def _release_floating_ip(self, context, address, def _release_floating_ip(self, context, address,
raise_if_associated=True): raise_if_associated=True):

View File

@ -2275,6 +2275,21 @@ class TestNeutronv2(TestNeutronv2Base):
api.disassociate_and_release_floating_ip(self.context, None, api.disassociate_and_release_floating_ip(self.context, None,
floating_ip) floating_ip)
def test_disassociate_and_release_floating_ip_with_instance(self):
api = neutronapi.API()
address = self.fip_unassociated['floating_ip_address']
fip_id = self.fip_unassociated['id']
floating_ip = {'address': address}
instance = self._fake_instance_object(self.instance)
self.moxed_client.list_floatingips(floating_ip_address=address).\
AndReturn({'floatingips': [self.fip_unassociated]})
self.moxed_client.delete_floatingip(fip_id)
self._setup_mock_for_refresh_cache(api, [instance])
self.mox.ReplayAll()
api.disassociate_and_release_floating_ip(self.context, instance,
floating_ip)
def test_release_floating_ip_associated(self): def test_release_floating_ip_associated(self):
api = neutronapi.API() api = neutronapi.API()
address = self.fip_associated['floating_ip_address'] address = self.fip_associated['floating_ip_address']