From 0b5b21cb80618c4694a784ff78ec94ee26b5e701 Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Mon, 12 Sep 2016 12:27:26 +0200 Subject: [PATCH] Skip resource counting during validation When validate a nested stack, we try to query the db to count resources, but there is nothing to count. Let's skip it and push to creation time. Change-Id: Ia4249340b022fd182b28f0944c750a4e47c20473 Closes-Bug: #1621982 --- heat/engine/stack.py | 3 +++ heat/tests/test_stack.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/heat/engine/stack.py b/heat/engine/stack.py index 218f001130..1e1df439ac 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -437,6 +437,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 da83120146..ad68719176 100644 --- a/heat/tests/test_stack.py +++ b/heat/tests/test_stack.py @@ -205,6 +205,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')