Allow cancelling create_in_progress stacks with --no-rollback
Related-Bug:
MODIFY
heatclient/osc/v1/stack.py
heatclient/osc/v1/stack.py
@@ -1215,6 +1215,7 @@ class CancelStack(StackActionBase):
Supported tasks for cancellation:
* update
+ * create
"""
log = logging.getLogger(__name__ + '.CancelStack')
@@ -1245,17 +1246,18 @@ class CancelStack(StackActionBase):
heat_client = self.app.client_manager.orchestration
if parsed_args.no_rollback:
action = heat_client.actions.cancel_without_rollback
+ allowed_statuses = ['create_in_progress',
+ 'update_in_progress']
else:
action = heat_client.actions.cancel_update
+ allowed_statuses = ['update_in_progress']
for stack in parsed_args.stack:
try:
data = heat_client.stacks.get(stack_id=stack)
except heat_exc.HTTPNotFound:
raise exc.CommandError('Stack not found: %s' % stack)
-
status = getattr(data, 'stack_status').lower()
- if status == 'update_in_progress':
-
+ if status in allowed_statuses:
data = _stack_action(
stack,
parsed_args,

MODIFY
heatclient/tests/unit/osc/v1/test_stack.py
heatclient/tests/unit/osc/v1/test_stack.py
@@ -1221,18 +1221,21 @@ class TestStackCancel(_TestStackCheckBase, TestStack):
def test_stack_cancel(self):
self._test_stack_action(2)
- def test_stack_cancel_no_rollback(self):
+ def _test_stack_cancel_no_rollback(self, call_count):
self.action = self.mock_client.actions.cancel_without_rollback
arglist = ['my_stack', '--no-rollback']
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, rows = self.cmd.take_action(parsed_args)
self.action.assert_called_once_with('my_stack')
self.mock_client.stacks.get.assert_called_with('my_stack')
- self.assertEqual(2,
+ self.assertEqual(call_count,
self.mock_client.stacks.get.call_count)
self.assertEqual(self.columns, columns)
self.assertEqual(1, len(rows))
+ def test_stack_cancel_no_rollback(self):
+ self._test_stack_cancel_no_rollback(2)
+
def test_stack_cancel_multi(self):
self._test_stack_action_multi(4)
@@ -1246,6 +1249,7 @@ class TestStackCancel(_TestStackCheckBase, TestStack):
self._test_stack_action_exception()
def test_stack_cancel_unsupported_state(self):
+ self.stack.stack_status = "CREATE_COMPLETE"
self.mock_client.stacks.get.return_value = self.stack
error = self.assertRaises(exc.CommandError,
self._test_stack_action,
@@ -1254,6 +1258,17 @@ class TestStackCancel(_TestStackCheckBase, TestStack):
'not in cancelable state',
str(error))
+ def test_stack_cancel_create_in_progress(self):
+ self.stack.stack_status = "CREATE_IN_PROGRESS"
+ self.mock_client.stacks.get.return_value = self.stack
+ error = self.assertRaises(exc.CommandError,
+ self._test_stack_action,
+ 2)
+ self.assertEqual('Stack my_stack with status \'create_in_progress\' '
+ 'not in cancelable state',
+ str(error))
+ self._test_stack_cancel_no_rollback(3)
+
class TestStackCheck(_TestStackCheckBase, TestStack):

Allow cancelling create_in_progress stacks with --no-rollback

Change-Id: Ib107c82f341f4d271859ca7681d65f7ce4c5d0b1
Related-Bug: #1709041