diff --git a/heat/engine/stack.py b/heat/engine/stack.py index 85524ab8bd..7780e8e4cd 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -435,6 +435,9 @@ class Stack(collections.Mapping): Includes nested stacks below. """ if not stack_id: + if not self.id: + # We're not stored yet, so we don't have anything to count + return 0 stack_id = self.id return stack_object.Stack.count_total_resources(self.context, stack_id) diff --git a/heat/tests/test_stack.py b/heat/tests/test_stack.py index aba859d784..afb09e84b9 100644 --- a/heat/tests/test_stack.py +++ b/heat/tests/test_stack.py @@ -206,6 +206,13 @@ class StackTest(common.HeatTestCase): self.assertEqual(0, self.stack.total_resources(self.stack.id)) self.assertEqual(0, self.stack.total_resources()) + @mock.patch.object(db_api, 'stack_count_total_resources') + def test_total_resources_not_stored(self, sctr): + self.stack = stack.Stack(self.ctx, 'test_stack', self.tmpl, + status_reason='flimflam') + self.assertEqual(0, self.stack.total_resources()) + sctr.assert_not_called() + def test_total_resources_not_found(self): self.stack = stack.Stack(self.ctx, 'test_stack', self.tmpl, status_reason='flimflam')