From a832e6b2a019323fdf00e30302ad5c3c809baa21 Mon Sep 17 00:00:00 2001 From: Michael Wurtz Date: Thu, 18 Aug 2016 14:53:33 -0500 Subject: [PATCH] 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 cdb9b6820dc17971bca24adfc0b56f030f0ae827) --- nova/network/neutronv2/api.py | 14 ++++++++++++-- nova/tests/unit/network/test_neutronv2.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/nova/network/neutronv2/api.py b/nova/network/neutronv2/api.py index 06c4f49249e1..7050f9721118 100644 --- a/nova/network/neutronv2/api.py +++ b/nova/network/neutronv2/api.py @@ -1553,8 +1553,18 @@ class API(base_api.NetworkAPI): This api call was added to allow this to be done in one operation 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, raise_if_associated=True): diff --git a/nova/tests/unit/network/test_neutronv2.py b/nova/tests/unit/network/test_neutronv2.py index 8619fae946ac..fa4ace059137 100644 --- a/nova/tests/unit/network/test_neutronv2.py +++ b/nova/tests/unit/network/test_neutronv2.py @@ -2275,6 +2275,21 @@ class TestNeutronv2(TestNeutronv2Base): api.disassociate_and_release_floating_ip(self.context, None, 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): api = neutronapi.API() address = self.fip_associated['floating_ip_address']