Convergence: Set traversal to empty string on failure

When a stack fails, update the current traversal and set it to empty
string so that the resource workers bail out. This is effectively
implementing cancel-on-failure.

Change-Id: Ifab89e5dc69bab53faa6b82db624024214830d77
Closes-Bug: #1491186
changes/08/261208/11
Anant Patil 7 years ago committed by Anant Patil
parent 2219a32995
commit 2ec5d949cf
  1. 32
      heat/engine/stack.py
  2. 10
      heat/tests/test_convg_stack.py

@ -1944,23 +1944,33 @@ class Stack(collections.Mapping):
def purge_db(self):
"""Cleanup database after stack has completed/failed.
1. Delete previous raw template if stack completes successfully.
2. Deletes all sync points. They are no longer needed after stack
1. If the stack failed, update the current_traversal to empty string
so that the resource workers bail out.
2. Delete previous raw template if stack completes successfully.
3. Deletes all sync points. They are no longer needed after stack
has completed/failed.
3. Delete the stack if the action is DELETE.
4. Delete the stack if the action is DELETE.
"""
exp_trvsl = self.current_traversal
if self.status == self.FAILED:
self.current_traversal = ''
prev_tmpl_id = None
if (self.prev_raw_template_id is not None and
self.status != self.FAILED):
prev_tmpl_id = self.prev_raw_template_id
self.prev_raw_template_id = None
stack_id = self.store()
if stack_id is None:
# Failed concurrent update
LOG.warning(_LW("Failed to store stack %(name)s with traversal"
" ID %(trvsl_id)s, aborting stack purge"),
{'name': self.name,
'trvsl_id': self.current_traversal})
return
stack_id = self.store(exp_trvsl=exp_trvsl)
if stack_id is None:
# Failed concurrent update
LOG.warning(_LW("Failed to store stack %(name)s with traversal ID "
"%(trvsl_id)s, aborting stack purge"),
{'name': self.name,
'trvsl_id': self.current_traversal})
return
if prev_tmpl_id is not None:
raw_template_object.RawTemplate.delete(self.context, prev_tmpl_id)
sync_point.delete_all(self.context, self.id, self.current_traversal)

@ -369,6 +369,16 @@ class StackConvergenceCreateUpdateDeleteTest(common.HeatTestCase):
stack.mark_complete()
self.assertTrue(stack.purge_db.called)
def test_purge_db_sets_curr_trvsl_to_none_for_failed_stack(
self, mock_cr):
stack = tools.get_stack('test_stack', utils.dummy_context(),
template=tools.string_template_five,
convergence=True)
stack.status = stack.FAILED
stack.store()
stack.purge_db()
self.assertEqual('', stack.current_traversal)
@mock.patch.object(raw_template_object.RawTemplate, 'delete')
def test_purge_db_deletes_previous_template(self, mock_tmpl_delete,
mock_cr):

Loading…
Cancel
Save