Skip to content

Commit 56b959e

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Raise NotFound exception when get a deleted stack"
2 parents 9faf4cc + 464731b commit 56b959e

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

openstack/orchestration/v1/stack.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ def find(cls, session, name_or_id, path_args=None, ignore_missing=True):
108108
"No stack found for %s" % name_or_id)
109109
return stk
110110

111+
def get(self, session, include_headers=False, args=None):
112+
stk = super(Stack, self).get(session, include_headers, args)
113+
if stk and stk.status in ['DELETE_COMPLETE', 'ADOPT_COMPLETE']:
114+
raise exceptions.NotFoundException(
115+
"No stack found for %s" % stk.id)
116+
return stk
117+
111118

112119
class StackPreview(Stack):
113120
base_path = '/stacks/preview'

openstack/tests/unit/orchestration/v1/test_stack.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,22 @@ def test_find(self, mock_find):
178178
sess, 'fake_name', ignore_missing=False)
179179
self.assertEqual('ResourceNotFound: No stack found for fake_name',
180180
six.text_type(ex))
181+
182+
@mock.patch.object(resource.Resource, 'get')
183+
def test_get(self, mock_get):
184+
sess = mock.Mock()
185+
sot = stack.Stack(FAKE)
186+
deleted_stack = mock.Mock(id=FAKE_ID, status='DELETE_COMPLETE')
187+
normal_stack = mock.Mock(status='CREATE_COMPLETE')
188+
mock_get.side_effect = [
189+
normal_stack,
190+
exceptions.NotFoundException(message='oops'),
191+
deleted_stack,
192+
]
193+
194+
self.assertEqual(normal_stack, sot.get(sess))
195+
ex = self.assertRaises(exceptions.NotFoundException, sot.get, sess)
196+
self.assertEqual('NotFoundException: oops', six.text_type(ex))
197+
ex = self.assertRaises(exceptions.NotFoundException, sot.get, sess)
198+
self.assertEqual('NotFoundException: No stack found for %s' % FAKE_ID,
199+
six.text_type(ex))

0 commit comments

Comments
 (0)