Do not attempt deletion of a DELETE_COMPLETE stack in service api

A stack may be in transient state where it is DELETE_COMPLETE, but has
has not actually been soft-deleted yet. For the purposes of
delete_stack in, consider a DELETE_COMPLETE stack as
equivalent to a soft-deleted one (it soon will be), thereby avoiding a
race where we would have attempted to update the stack, running into a
foreign-key constraint issue for a non-existing user_cred.

Change-Id: Iec021e6a0df262d447fdf9ee1789603c7a1c55f8
Closes-Bug: #1626173
Closes-Bug: #1626107
Crag Wolfe 2016-09-21 19:06:36 -04:00
parent 5ecb4026ae
commit e1f161a19a
2 changed files with 15 additions and 0 deletions

View File

@ -1358,6 +1358,10 @@ class EngineService(service.Service):
st = self._get_stack(cnxt, stack_identity)
if (st.status == parser.Stack.COMPLETE and
st.action == parser.Stack.DELETE):
raise exception.EntityNotFound(entity='Stack','Deleting stack %s'),
stack = parser.Stack.load(cnxt, stack=st)

View File

@ -975,6 +975,17 @@ class StackServiceTest(common.HeatTestCase):
outputs = self.eng.list_outputs(self.ctx, mock.ANY)
self.assertEqual([], outputs)
def test_stack_delete_complete_is_not_found(self):
mock_get_stack = self.patchobject(self.eng, '_get_stack')
mock_get_stack.return_value = mock.MagicMock()
mock_get_stack.return_value.status = parser.Stack.COMPLETE
mock_get_stack.return_value.action = parser.Stack.DELETE
ex = self.assertRaises(dispatcher.ExpectedException,
self.assertEqual(exception.EntityNotFound, ex.exc_info[0])
def test_get_environment(self):
# Setup
t = template_format.parse(tools.wp_template)