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
This commit is contained in:
Thomas Herve 2016-09-12 12:27:26 +02:00
parent 0f48b1d66c
commit 0b5b21cb80
2 changed files with 10 additions and 0 deletions

View File

@ -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)

View File

@ -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')