diff --git a/heat/engine/resources/eip.py b/heat/engine/resources/eip.py index 23e8aa463e..c18afc2798 100644 --- a/heat/engine/resources/eip.py +++ b/heat/engine/resources/eip.py @@ -118,7 +118,10 @@ class ElasticIp(resource.Resource): 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 8ded59ccd3..63f432b7f4 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 @@ class EIPTest(HeatTestCase): 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):