Skip to content

Commit

Permalink
cfn - stack ensure present - catch DELETE_FAILED state (#479)
Browse files Browse the repository at this point in the history
* cfn - stack ensure present - catch DELETE_FAILED state

* add test_update_stack_in_delete_failed_state
  • Loading branch information
nehalrp authored Nov 12, 2019
1 parent 4e80a08 commit 37a11eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions kingpin/actors/aws/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,14 @@ def __init__(self, *args, **kwargs):
def _update_stack(self, stack):
self.log.info('Verifying that stack is in desired state')

# First, check that this stack isn't one that may have failed before
# and there was attempted to be deleted but failed. If it is, we have a
# fatal error and we must raise an exception.
if stack['StackStatus'] == 'DELETE_FAILED':
msg = 'Stack found in a deleted failed state: %s' % (
stack['StackStatus'])
raise StackFailed(msg)

# Upon a stack creation, there are two states the stack can be left in
# that are both un-fixable -- CREATE_FAILED and ROLLBACK_COMPLETE. In
# both of these cases, the only possible option is to destroy the stack
Expand Down
7 changes: 7 additions & 0 deletions kingpin/actors/aws/test/test_cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,13 @@ def test_update_stack_in_failed_state(self):
self.actor._create_stack.assert_called_with(
stack='fake')

@testing.gen_test
def test_update_stack_in_delete_failed_state(self):
fake_stack = create_fake_stack('fake', 'DELETE_FAILED')
self.actor._get_stack = mock.MagicMock(name='_get_stack')
with self.assertRaises(cloudformation.StackFailed):
yield self.actor._update_stack(fake_stack)

@testing.gen_test
def test_update_stack_ensure_template(self):
fake_stack = create_fake_stack('fake', 'CREATE_COMPLETE')
Expand Down

0 comments on commit 37a11eb

Please sign in to comment.