From 2aa4186dde97e580694b88ad22dad4db657cc5ad Mon Sep 17 00:00:00 2001 From: Hui HX Xiang Date: Wed, 9 Oct 2013 03:10:36 -0700 Subject: [PATCH] Fix heat deletion failed if floating ip is not found Novaclient will throw out a Not Found exception if the floating ip not exists. Heat should catch this exception to continue to delete the stack. Closes-Bug: #1234593 Change-Id: Ifd9d34de37cc5dd57804787d8b1455f0321fc86f --- heat/engine/resources/eip.py | 5 ++++- heat/tests/test_eip.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/heat/engine/resources/eip.py b/heat/engine/resources/eip.py index 23e8aa463e3..c18afc2798c 100644 --- a/heat/engine/resources/eip.py +++ b/heat/engine/resources/eip.py @@ -118,7 +118,10 @@ def handle_delete(self): if e.status_code != 404: raise e else: - self.nova().floating_ips.delete(self.resource_id) + try: + self.nova().floating_ips.delete(self.resource_id) + except clients.novaclient.exceptions.NotFound: + pass def FnGetRefId(self): return unicode(self._ipaddress()) diff --git a/heat/tests/test_eip.py b/heat/tests/test_eip.py index 8ded59ccd3e..63f432b7f42 100644 --- a/heat/tests/test_eip.py +++ b/heat/tests/test_eip.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +import mox + from testtools import skipIf from heat.common import exception @@ -223,6 +225,24 @@ def test_eip_with_exception(self): rsrc.handle_create) self.m.VerifyAll() + def test_delete_eip_with_exception(self): + self.m.StubOutWithMock(self.fc.floating_ips, 'delete') + eip.ElasticIp.nova().MultipleTimes().AndReturn(self.fc) + self.fc.floating_ips.delete(mox.IsA(object)).AndRaise( + clients.novaclient.exceptions.NotFound('fake_falure')) + self.fc.servers.get(mox.IsA(object)).AndReturn(False) + self.m.ReplayAll() + + t = template_format.parse(eip_template) + stack = utils.parse_stack(t) + resource_name = 'IPAddress' + rsrc = eip.ElasticIp(resource_name, + t['Resources'][resource_name], + stack) + rsrc.resource_id = 'fake_id' + rsrc.handle_delete() + self.m.VerifyAll() + class AllocTest(HeatTestCase):