Merge "Raise NotFound exception when get a deleted stack"
This commit is contained in:
commit
56b959ec5d
@ -108,6 +108,13 @@ class Stack(resource.Resource):
|
||||
"No stack found for %s" % name_or_id)
|
||||
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):
|
||||
base_path = '/stacks/preview'
|
||||
|
@ -178,3 +178,22 @@ class TestStack(testtools.TestCase):
|
||||
sess, 'fake_name', ignore_missing=False)
|
||||
self.assertEqual('ResourceNotFound: No stack found for fake_name',
|
||||
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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user