Fix reset_stack_status

Fix reset_stack_status on legacy, by using a different session for each
stack reset, and handling lock duplicate errors.

Closes-Bug: #1735755
Change-Id: I6bcd7448052e86ec3e4eb4c49ef3139c20d4f919
changes/58/524558/4
Thomas Herve 5 years ago
parent 34fe34d8fb
commit e1a26279ce
  1. 7
      heat/db/sqlalchemy/api.py
  2. 6
      heat/engine/service.py
  3. 2
      heat/tests/test_engine_service.py

@ -802,8 +802,13 @@ def stack_delete(context, stack_id):
delete_softly(context, s)
def _is_duplicate_error(exc):
return isinstance(exc, db_exception.DBDuplicateEntry)
@oslo_db_api.wrap_db_retry(max_retries=3, retry_on_deadlock=True,
retry_interval=0.5, inc_retry_interval=True)
retry_interval=0.5, inc_retry_interval=True,
exception_checker=_is_duplicate_error)
def stack_lock_create(context, stack_id, engine_id):
with db_context.writer.independent.using(context) as session:
lock = session.query(models.StackLock).get(stack_id)

@ -2449,15 +2449,17 @@ class EngineService(service.ServiceBase):
service_objects.Service.delete(cnxt, service_ref['id'])
def reset_stack_status(self):
cnxt = context.get_admin_context()
filters = {
'status': parser.Stack.IN_PROGRESS,
'convergence': False
}
stacks = stack_object.Stack.get_all(cnxt,
stacks = stack_object.Stack.get_all(context.get_admin_context(),
filters=filters,
show_nested=True)
for s in stacks:
# Build one context per stack, so that it can safely be passed to
# to thread.
cnxt = context.get_admin_context()
stack_id = s.id
lock = stack_lock.StackLock(cnxt, stack_id, self.engine_id)
engine_id = lock.get_engine_id()

@ -1328,7 +1328,7 @@ class StackServiceTest(common.HeatTestCase):
self.eng.reset_stack_status()
mock_admin_context.assert_called_once_with()
mock_admin_context.assert_called()
filters = {
'status': parser.Stack.IN_PROGRESS,
'convergence': False

Loading…
Cancel
Save