Make stack suspend and resume convergence aware

Change-Id: I9f525e9d5fad017d005fd0ed7c9761eccef108eb
Task: 37220
This commit is contained in:
Rabi Mishra 2019-11-08 08:30:09 +05:30
parent 698c10fa56
commit 873111caaf
5 changed files with 42 additions and 20 deletions

View File

@ -386,9 +386,9 @@ def check_resource_update(rsrc, template_id, requires, engine_id,
stack, msg_queue):
"""Create or update the Resource if appropriate."""
check_message = functools.partial(_check_for_message, msg_queue)
if stack.action == stack.CHECK:
rsrc.check_convergence(engine_id, stack.time_remaining(),
check_message)
if stack.action in [stack.CHECK, stack.SUSPEND, stack.RESUME]:
do_convergence = getattr(rsrc, stack.action.lower() + "_convergence")
do_convergence(engine_id, stack.time_remaining(), check_message)
elif rsrc.action == resource.Resource.INIT:
rsrc.create_convergence(template_id, requires, engine_id,
stack.time_remaining(), check_message)
@ -401,7 +401,7 @@ def check_resource_update(rsrc, template_id, requires, engine_id,
def check_resource_cleanup(rsrc, template_id, engine_id, stack,
timeout, msg_queue):
"""Delete the Resource if appropriate."""
if stack.action == stack.CHECK:
if stack.action in [stack.CHECK, stack.SUSPEND, stack.RESUME]:
return
check_message = functools.partial(_check_for_message, msg_queue)

View File

@ -1423,6 +1423,18 @@ class Resource(status.ResourceStatus):
runner = scheduler.TaskRunner(self.check)
runner(timeout=timeout, progress_callback=progress_callback)
def suspend_convergence(self, engine_id, timeout, progress_callback=None):
"""suspend the resource synchronously."""
self._calling_engine_id = engine_id
runner = scheduler.TaskRunner(self.suspend)
runner(timeout=timeout, progress_callback=progress_callback)
def resume_convergence(self, engine_id, timeout, progress_callback=None):
"""resume the resource synchronously."""
self._calling_engine_id = engine_id
runner = scheduler.TaskRunner(self.resume)
runner(timeout=timeout, progress_callback=progress_callback)
def update_convergence(self, template_id, new_requires, engine_id,
timeout, new_stack, progress_callback=None):
"""Update the resource synchronously.

View File

@ -2059,27 +2059,37 @@ class EngineService(service.ServiceBase):
def stack_suspend(self, cnxt, stack_identity):
"""Handle request to perform suspend action on a stack."""
s = self._get_stack(cnxt, stack_identity)
stack = parser.Stack.load(cnxt, stack=s)
self.resource_enforcer.enforce_stack(stack, is_registered_policy=True)
stored_event = NotifyEvent()
self.thread_group_mgr.start_with_lock(cnxt, stack, self.engine_id,
stack.suspend,
notify=stored_event)
stored_event.wait()
if stack.convergence:
stack.thread_group_mgr = self.thread_group_mgr
stack.converge_stack(template=stack.t,
action=stack.SUSPEND)
else:
stored_event = NotifyEvent()
self.thread_group_mgr.start_with_lock(
cnxt, stack, self.engine_id,
stack.suspend, notify=stored_event)
stored_event.wait()
@context.request_context
def stack_resume(self, cnxt, stack_identity):
"""Handle request to perform a resume action on a stack."""
s = self._get_stack(cnxt, stack_identity)
stack = parser.Stack.load(cnxt, stack=s)
self.resource_enforcer.enforce_stack(stack, is_registered_policy=True)
stored_event = NotifyEvent()
self.thread_group_mgr.start_with_lock(cnxt, stack, self.engine_id,
stack.resume,
notify=stored_event)
stored_event.wait()
if stack.convergence:
stack.thread_group_mgr = self.thread_group_mgr
stack.converge_stack(template=stack.t,
action=stack.RESUME)
else:
stored_event = NotifyEvent()
self.thread_group_mgr.start_with_lock(
cnxt, stack, self.engine_id,
stack.resume, notify=stored_event)
stored_event.wait()
@context.request_context
def stack_snapshot(self, cnxt, stack_identity, name):

View File

@ -985,7 +985,7 @@ class Stack(collections.Mapping):
if (self.convergence and
self.action in {self.UPDATE, self.DELETE, self.CREATE,
self.ADOPT, self.ROLLBACK, self.RESTORE,
self.CHECK}):
self.CHECK, self.SUSPEND, self.RESUME}):
# These operations do not use the stack lock in convergence, so
# never defer.
return False
@ -1340,7 +1340,7 @@ class Stack(collections.Mapping):
def converge_stack(self, template, action=UPDATE, new_stack=None,
pre_converge=None):
"""Update the stack template and trigger convergence for resources."""
if action != self.CHECK:
if action not in [self.CHECK, self.SUSPEND, self.RESUME]:
if action not in [self.CREATE, self.ADOPT]:
# no back-up template for create action
self.prev_raw_template_id = getattr(self.t, 'id', None)

View File

@ -593,7 +593,7 @@ class TestConvgStackStateSet(common.HeatTestCase):
mock_ps.reset_mock()
self.stack.state_set(self.stack.SUSPEND, self.stack.COMPLETE,
'Suspend complete')
self.assertFalse(mock_ps.called)
self.assertTrue(mock_ps.called)
def test_state_set_stack_resume(self, mock_ps):
self.stack.state_set(self.stack.RESUME, self.stack.IN_PROGRESS,
@ -602,7 +602,7 @@ class TestConvgStackStateSet(common.HeatTestCase):
mock_ps.reset_mock()
self.stack.state_set(self.stack.RESUME, self.stack.COMPLETE,
'Resume complete')
self.assertFalse(mock_ps.called)
self.assertTrue(mock_ps.called)
def test_state_set_stack_snapshot(self, mock_ps):
self.stack.state_set(self.stack.SNAPSHOT, self.stack.IN_PROGRESS,