Handle NotFound exception in total_nested()

Change-Id: Ia6044539bd78c7202a6cde84bb9567c8df5b8904
Closes-bug: 1424899
This commit is contained in:
Angus Salkeld 2015-02-24 12:36:28 +10:00
parent f604953985
commit 5f37259d9c
2 changed files with 17 additions and 2 deletions

View File

@ -228,7 +228,12 @@ class Stack(collections.Mapping):
def total_nested(res):
get_nested = getattr(res, 'nested', None)
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:
return nested_stack.total_resources()
return 0

View File

@ -1046,7 +1046,7 @@ class StackTest(common.HeatTestCase):
status_reason='blarg')
self.assertEqual(1, stack.total_resources())
def test_total_resources_nested(self):
def test_total_resources_nested_ok(self):
tpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources':
{'A': {'Type': 'GenericResourceType'}}}
@ -1057,6 +1057,16 @@ class StackTest(common.HeatTestCase):
stack['A'].nested.return_value.total_resources.return_value = 3
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):
tpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources':