Add --no-rollback option for stack cancel

This adds a new --no-rollback option for stack cancel.

Usage: openstack stack cancel --no-rollback <stack_name>

Change-Id: I46252823701779e3a3c6867bc470d5532cf9d7a7
Related-Bug: #1709041
This commit is contained in:
rabi 2017-08-08 13:25:20 +05:30
parent f73c2a4177
commit 187fc54249
4 changed files with 40 additions and 4 deletions

View File

@ -1220,11 +1220,17 @@ class CancelStack(StackActionBase):
log = logging.getLogger(__name__ + '.CancelStack') log = logging.getLogger(__name__ + '.CancelStack')
def get_parser(self, prog_name): def get_parser(self, prog_name):
return self._get_parser( parser = self._get_parser(
prog_name, prog_name,
_('Stack(s) to cancel (name or ID)'), _('Stack(s) to cancel (name or ID)'),
_('Wait for check to complete') _('Wait for cancel to complete')
) )
parser.add_argument(
'--no-rollback',
action='store_true',
help=_('Cancel without rollback')
)
return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args) self.log.debug("take_action(%s)", parsed_args)
@ -1237,7 +1243,10 @@ class CancelStack(StackActionBase):
'Updated Time' 'Updated Time'
] ]
heat_client = self.app.client_manager.orchestration heat_client = self.app.client_manager.orchestration
if parsed_args.no_rollback:
action = heat_client.actions.cancel_without_rollback
else:
action = heat_client.actions.cancel_update
for stack in parsed_args.stack: for stack in parsed_args.stack:
try: try:
data = heat_client.stacks.get(stack_id=stack) data = heat_client.stacks.get(stack_id=stack)
@ -1246,11 +1255,12 @@ class CancelStack(StackActionBase):
status = getattr(data, 'stack_status').lower() status = getattr(data, 'stack_status').lower()
if status == 'update_in_progress': if status == 'update_in_progress':
data = _stack_action( data = _stack_action(
stack, stack,
parsed_args, parsed_args,
heat_client, heat_client,
heat_client.actions.cancel_update action
) )
rows += [utils.get_dict_properties(data.to_dict(), columns)] rows += [utils.get_dict_properties(data.to_dict(), columns)]
else: else:

View File

@ -1221,6 +1221,18 @@ class TestStackCancel(_TestStackCheckBase, TestStack):
def test_stack_cancel(self): def test_stack_cancel(self):
self._test_stack_action(2) self._test_stack_action(2)
def test_stack_cancel_no_rollback(self):
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.mock_client.stacks.get.call_count)
self.assertEqual(self.columns, columns)
self.assertEqual(1, len(rows))
def test_stack_cancel_multi(self): def test_stack_cancel_multi(self):
self._test_stack_action_multi(4) self._test_stack_action_multi(4)

View File

@ -98,6 +98,15 @@ class ActionManagerTest(testtools.TestCase):
manager = self._base_test(expect_args, expect_kwargs) manager = self._base_test(expect_args, expect_kwargs)
manager.cancel_update(**fields) manager.cancel_update(**fields)
def test_cancel_without_rollback(self):
fields = {'stack_id': 'teststack%2Fabcd1234'}
expect_args = ('POST',
'/stacks/teststack%2Fabcd1234/actions')
expect_kwargs = {'data': {'cancel_without_rollback': None}}
manager = self._base_test(expect_args, expect_kwargs)
manager.cancel_without_rollback(**fields)
def test_check(self): def test_check(self):
fields = {'stack_id': 'teststack%2Fabcd1234'} fields = {'stack_id': 'teststack%2Fabcd1234'}
expect_args = ('POST', expect_args = ('POST',

View File

@ -48,6 +48,11 @@ class ActionManager(stacks.StackChildManager):
body = {'cancel_update': None} body = {'cancel_update': None}
self.client.post('/stacks/%s/actions' % stack_id, data=body) self.client.post('/stacks/%s/actions' % stack_id, data=body)
def cancel_without_rollback(self, stack_id):
"""Cancel running update of a stack."""
body = {'cancel_without_rollback': None}
self.client.post('/stacks/%s/actions' % stack_id, data=body)
def check(self, stack_id): def check(self, stack_id):
"""Check a stack.""" """Check a stack."""
body = {'check': None} body = {'check': None}