From f05105ec480e6d5e51dc75151fb4cc26ae16b88e Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Mon, 13 Feb 2017 09:25:32 +0800 Subject: [PATCH] Set COMPLETE for failed resource if no update/replace Update the status from FAILED to COMPLETE for resources which do not have to update or replace. Change-Id: I9a632691ec8f0682000d704a30039d99d12d71e3 Closes-Bug: #1663522 --- heat/engine/resource.py | 6 ++++++ heat/tests/test_resource.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 7a83bdec3a..91460d74f2 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -1400,6 +1400,12 @@ class Resource(status.ResourceStatus): prev_resource): if update_templ_func is not None: update_templ_func(persist=True) + if self.status == self.FAILED: + status_reason = _('Update status to COMPLETE for ' + 'FAILED resource neither update ' + 'nor replace.') + self.state_set(self.action, self.COMPLETE, + status_reason) return if not self.stack.convergence: diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 38b5c2828e..adb01e3970 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -500,6 +500,22 @@ class ResourceTest(common.HeatTestCase): self.assertFalse(res.needs_replace_failed.called) self.assertTrue(res.prepare_for_replace.called) + def test_no_update_or_replace_in_failed(self): + res, utmpl = self._setup_resource_for_update( + res_name='test_failed_res_no_update_or_replace') + res.state_set(res.CREATE, res.FAILED) + res.prepare_for_replace = mock.Mock() + res.needs_replace_failed = mock.MagicMock(return_value=False) + + scheduler.TaskRunner(res.update, res.t)() + self.assertTrue(res.needs_replace_failed.called) + self.assertFalse(res.prepare_for_replace.called) + self.assertEqual((res.CREATE, res.COMPLETE), res.state) + status_reason = _('Update status to COMPLETE for ' + 'FAILED resource neither update ' + 'nor replace.') + self.assertEqual(status_reason, res.status_reason) + def test_update_replace_prepare_replace_error(self): # test if any error happened when prepare_for_replace, # whether the resource will go to FAILED