From 5f37259d9c2f9397f4aa9e110eb91331b3d2e478 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Tue, 24 Feb 2015 12:36:28 +1000 Subject: [PATCH] Handle NotFound exception in total_nested() Change-Id: Ia6044539bd78c7202a6cde84bb9567c8df5b8904 Closes-bug: 1424899 --- heat/engine/stack.py | 7 ++++++- heat/tests/test_parser.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/heat/engine/stack.py b/heat/engine/stack.py index f47aff09f9..5f4dd4406f 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -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 diff --git a/heat/tests/test_parser.py b/heat/tests/test_parser.py index cfce642b94..f53e089102 100644 --- a/heat/tests/test_parser.py +++ b/heat/tests/test_parser.py @@ -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':