diff --git a/openstack/orchestration/v1/stack.py b/openstack/orchestration/v1/stack.py index 211852c6..0c47cc1d 100644 --- a/openstack/orchestration/v1/stack.py +++ b/openstack/orchestration/v1/stack.py @@ -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' diff --git a/openstack/tests/unit/orchestration/v1/test_stack.py b/openstack/tests/unit/orchestration/v1/test_stack.py index e8332ac8..d7f408b8 100644 --- a/openstack/tests/unit/orchestration/v1/test_stack.py +++ b/openstack/tests/unit/orchestration/v1/test_stack.py @@ -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))