Handle NotFound exception in total_nested()
Change-Id: Ia6044539bd78c7202a6cde84bb9567c8df5b8904 Closes-bug: 1424899
This commit is contained in:
parent
f604953985
commit
5f37259d9c
@ -228,7 +228,12 @@ class Stack(collections.Mapping):
|
|||||||
def total_nested(res):
|
def total_nested(res):
|
||||||
get_nested = getattr(res, 'nested', None)
|
get_nested = getattr(res, 'nested', None)
|
||||||
if callable(get_nested):
|
if callable(get_nested):
|
||||||
nested_stack = get_nested()
|
try:
|
||||||
|
nested_stack = get_nested()
|
||||||
|
except exception.NotFound:
|
||||||
|
# when an delete is underway, a nested stack can
|
||||||
|
# disapear at any moment.
|
||||||
|
return 0
|
||||||
if nested_stack is not None:
|
if nested_stack is not None:
|
||||||
return nested_stack.total_resources()
|
return nested_stack.total_resources()
|
||||||
return 0
|
return 0
|
||||||
|
@ -1046,7 +1046,7 @@ class StackTest(common.HeatTestCase):
|
|||||||
status_reason='blarg')
|
status_reason='blarg')
|
||||||
self.assertEqual(1, stack.total_resources())
|
self.assertEqual(1, stack.total_resources())
|
||||||
|
|
||||||
def test_total_resources_nested(self):
|
def test_total_resources_nested_ok(self):
|
||||||
tpl = {'HeatTemplateFormatVersion': '2012-12-12',
|
tpl = {'HeatTemplateFormatVersion': '2012-12-12',
|
||||||
'Resources':
|
'Resources':
|
||||||
{'A': {'Type': 'GenericResourceType'}}}
|
{'A': {'Type': 'GenericResourceType'}}}
|
||||||
@ -1057,6 +1057,16 @@ class StackTest(common.HeatTestCase):
|
|||||||
stack['A'].nested.return_value.total_resources.return_value = 3
|
stack['A'].nested.return_value.total_resources.return_value = 3
|
||||||
self.assertEqual(4, stack.total_resources())
|
self.assertEqual(4, stack.total_resources())
|
||||||
|
|
||||||
|
def test_total_resources_nested_not_found(self):
|
||||||
|
tpl = {'HeatTemplateFormatVersion': '2012-12-12',
|
||||||
|
'Resources':
|
||||||
|
{'A': {'Type': 'GenericResourceType'}}}
|
||||||
|
stack = parser.Stack(self.ctx, 'test_stack', parser.Template(tpl),
|
||||||
|
status_reason='blarg')
|
||||||
|
|
||||||
|
stack['A'].nested = mock.Mock(side_effect=exception.NotFound('gone'))
|
||||||
|
self.assertEqual(1, stack.total_resources())
|
||||||
|
|
||||||
def test_iter_resources(self):
|
def test_iter_resources(self):
|
||||||
tpl = {'HeatTemplateFormatVersion': '2012-12-12',
|
tpl = {'HeatTemplateFormatVersion': '2012-12-12',
|
||||||
'Resources':
|
'Resources':
|
||||||
|
Loading…
Reference in New Issue
Block a user