Add cancel_with_rollback flag to stack cancel update

Add cancel_with_rollback flag to deside rollback or not  when stack update
cancelled.

Change-Id: I351a46c2e9add3f26fc42f09678c6c3a3c97475d
Partial-Bug: #1475057
This commit is contained in:
ricolin 2015-07-31 10:38:54 +08:00
parent c6c1cc9e8a
commit 6536588272
8 changed files with 38 additions and 14 deletions

View File

@ -269,7 +269,7 @@ class EngineService(service.Service):
by the RPC caller.
"""
RPC_API_VERSION = '1.13'
RPC_API_VERSION = '1.14'
def __init__(self, host, topic, manager=None):
super(EngineService, self).__init__()
@ -799,11 +799,13 @@ class EngineService(service.Service):
return dict(current_stack.identifier())
@context.request_context
def stack_cancel_update(self, cnxt, stack_identity):
def stack_cancel_update(self, cnxt, stack_identity,
cancel_with_rollback=True):
"""Cancel currently running stack update.
:param cnxt: RPC context.
:param stack_identity: Name of the stack for which to cancel update.
:param cancel_with_rollback: Force rollback when cancel update.
"""
# Get the database representation of the existing stack
db_stack = self._get_stack(cnxt, stack_identity)
@ -821,19 +823,25 @@ class EngineService(service.Service):
lock = stack_lock.StackLock(cnxt, current_stack.id,
self.engine_id)
engine_id = lock.try_acquire()
if cancel_with_rollback:
cancel_message = rpc_api.THREAD_CANCEL_WITH_ROLLBACK
else:
cancel_message = rpc_api.THREAD_CANCEL
# Current engine has the lock
if engine_id == self.engine_id:
self.thread_group_mgr.send(current_stack.id, 'cancel')
self.thread_group_mgr.send(current_stack.id, cancel_message)
# Another active engine has the lock
elif stack_lock.StackLock.engine_alive(cnxt, engine_id):
cancel_result = self._remote_call(
cnxt, engine_id, self.listener.SEND,
stack_identity=stack_identity, message=rpc_api.THREAD_CANCEL)
stack_identity=stack_identity, message=cancel_message)
if cancel_result is None:
LOG.debug("Successfully sent %(msg)s message "
"to remote task on engine %(eng)s" % {
'eng': engine_id, 'msg': 'cancel'})
'eng': engine_id, 'msg': cancel_message})
else:
raise exception.EventSendFailed(stack_name=current_stack.name,
engine_id=engine_id)

View File

@ -279,4 +279,6 @@ SNAPSHOT_KEYS = (
'creation_time'
)
THREAD_MESSAGES = (THREAD_CANCEL,) = ('cancel',)
THREAD_MESSAGES = (THREAD_CANCEL,
THREAD_CANCEL_WITH_ROLLBACK
) = ('cancel', 'cancel_with_rollback')

View File

@ -34,6 +34,7 @@ class EngineClient(object):
1.11 - Add support for template versions list
1.12 - Add with_detail option for stack resources list
1.13 - Add support for template functions list
1.14 - Add cancel_with_rollback option to stack_cancel_update
'''
BASE_RPC_API_VERSION = '1.0'
@ -463,9 +464,14 @@ class EngineClient(object):
return self.call(ctxt, self.make_msg('stack_check',
stack_identity=stack_identity))
def stack_cancel_update(self, ctxt, stack_identity):
return self.call(ctxt, self.make_msg('stack_cancel_update',
stack_identity=stack_identity))
def stack_cancel_update(self, ctxt, stack_identity,
cancel_with_rollback=True):
return self.call(ctxt,
self.make_msg(
'stack_cancel_update',
stack_identity=stack_identity,
cancel_with_rollback=cancel_with_rollback),
version='1.14')
def resource_signal(self, ctxt, stack_identity, resource_name, details,
sync_call=False):

View File

@ -886,7 +886,9 @@ class CfnStackControllerTest(common.HeatTestCase):
rpc_client.EngineClient.call(
dummy_req.context,
('stack_cancel_update',
{'stack_identity': identity})
{'stack_identity': identity,
'cancel_with_rollback': True}),
version='1.14'
).AndReturn(identity)
self.m.ReplayAll()

View File

@ -4206,7 +4206,10 @@ class ActionControllerTest(ControllerTest, common.HeatTestCase):
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
('stack_cancel_update', {'stack_identity': stack_identity})
('stack_cancel_update',
{'stack_identity': stack_identity,
'cancel_with_rollback': True}),
version='1.14'
).AndReturn(None)
self.m.ReplayAll()

View File

@ -39,7 +39,7 @@ class ServiceEngineTest(common.HeatTestCase):
def test_make_sure_rpc_version(self):
self.assertEqual(
'1.13',
'1.14',
service.EngineService.RPC_API_VERSION,
('RPC version is changed, please update this test to new version '
'and make sure additional test cases are added for RPC APIs '

View File

@ -956,7 +956,8 @@ class StackServiceAdoptUpdateTest(common.HeatTestCase):
lock_mock = self.patchobject(stack_lock.StackLock, 'try_acquire')
lock_mock.return_value = self.man.engine_id
self.patchobject(self.man.thread_group_mgr, 'send')
self.man.stack_cancel_update(self.ctx, old_stack.identifier())
self.man.stack_cancel_update(self.ctx, old_stack.identifier(),
cancel_with_rollback=False)
self.man.thread_group_mgr.send.assert_called_once_with(old_stack.id,
'cancel')

View File

@ -243,7 +243,9 @@ class EngineRpcAPITestCase(common.HeatTestCase):
def test_stack_cancel_update(self):
self._test_engine_api('stack_cancel_update', 'call',
stack_identity=self.identity)
stack_identity=self.identity,
cancel_with_rollback=False,
version='1.14')
def test_resource_signal(self):
self._test_engine_api('resource_signal', 'call',