Raise NotFound exception when get a deleted stack
Heat will always return a stack record if query with an id, so if a stack is deleted, we can still get it from heat, it will break wait_for_delete function. Change-Id: I44367fd053201dd2a20dc14dd9067e29a3a7d2a6 Closes-Bug: #1528996
This commit is contained in:
@@ -108,6 +108,13 @@ class Stack(resource.Resource):
|
|||||||
"No stack found for %s" % name_or_id)
|
"No stack found for %s" % name_or_id)
|
||||||
return stk
|
return stk
|
||||||
|
|
||||||
|
def get(self, session, include_headers=False, args=None):
|
||||||
|
stk = super(Stack, self).get(session, include_headers, args)
|
||||||
|
if stk and stk.status in ['DELETE_COMPLETE', 'ADOPT_COMPLETE']:
|
||||||
|
raise exceptions.NotFoundException(
|
||||||
|
"No stack found for %s" % stk.id)
|
||||||
|
return stk
|
||||||
|
|
||||||
|
|
||||||
class StackPreview(Stack):
|
class StackPreview(Stack):
|
||||||
base_path = '/stacks/preview'
|
base_path = '/stacks/preview'
|
||||||
|
|||||||
@@ -178,3 +178,22 @@ class TestStack(testtools.TestCase):
|
|||||||
sess, 'fake_name', ignore_missing=False)
|
sess, 'fake_name', ignore_missing=False)
|
||||||
self.assertEqual('ResourceNotFound: No stack found for fake_name',
|
self.assertEqual('ResourceNotFound: No stack found for fake_name',
|
||||||
six.text_type(ex))
|
six.text_type(ex))
|
||||||
|
|
||||||
|
@mock.patch.object(resource.Resource, 'get')
|
||||||
|
def test_get(self, mock_get):
|
||||||
|
sess = mock.Mock()
|
||||||
|
sot = stack.Stack(FAKE)
|
||||||
|
deleted_stack = mock.Mock(id=FAKE_ID, status='DELETE_COMPLETE')
|
||||||
|
normal_stack = mock.Mock(status='CREATE_COMPLETE')
|
||||||
|
mock_get.side_effect = [
|
||||||
|
normal_stack,
|
||||||
|
exceptions.NotFoundException(message='oops'),
|
||||||
|
deleted_stack,
|
||||||
|
]
|
||||||
|
|
||||||
|
self.assertEqual(normal_stack, sot.get(sess))
|
||||||
|
ex = self.assertRaises(exceptions.NotFoundException, sot.get, sess)
|
||||||
|
self.assertEqual('NotFoundException: oops', six.text_type(ex))
|
||||||
|
ex = self.assertRaises(exceptions.NotFoundException, sot.get, sess)
|
||||||
|
self.assertEqual('NotFoundException: No stack found for %s' % FAKE_ID,
|
||||||
|
six.text_type(ex))
|
||||||
|
|||||||
Reference in New Issue
Block a user