From d73107bd35cadcad0b4933aec43ef0313b961a45 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Mon, 17 Nov 2014 17:38:32 +0000 Subject: [PATCH] ResourceGroup don't special-case zero count Currently, when you specify an initial count of zero, we don't create the nested stack. Unfortunately this then means you can never update it, which makes the group forever broken.. Instead, always create the stack on create, even if it's an empty stack containing zero resources. This allows subsequent updates which move to a non-zero count to work as expected. Change-Id: I494229fcf85a1c28428fa2925c060fc1f40f4f36 Closes-Bug: #1392796 --- heat/engine/resources/resource_group.py | 7 ++----- heat/tests/test_resource_group.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/heat/engine/resources/resource_group.py b/heat/engine/resources/resource_group.py index 9f4a74faa6..24c76f8ca5 100644 --- a/heat/engine/resources/resource_group.py +++ b/heat/engine/resources/resource_group.py @@ -237,11 +237,8 @@ class ResourceGroup(stack_resource.StackResource): def handle_create(self): names = self._resource_names() - if names: - return self.create_with_template( - self._assemble_nested(names), - {}, - self.stack.timeout_mins) + return self.create_with_template(self._assemble_nested(names), + {}, self.stack.timeout_mins) def handle_update(self, json_snippet, tmpl_diff, prop_diff): if prop_diff: diff --git a/heat/tests/test_resource_group.py b/heat/tests/test_resource_group.py index 58dc03286d..ae410810cf 100644 --- a/heat/tests/test_resource_group.py +++ b/heat/tests/test_resource_group.py @@ -252,6 +252,18 @@ class ResourceGroupTest(common.HeatTestCase): self.assertEqual( expect, resg._assemble_nested(['0'], include_all=True)) + def test_assemble_nested_zero(self): + templ = copy.deepcopy(template) + templ['resources']['group1']['properties']['count'] = 0 + stack = utils.parse_stack(templ) + snip = stack.t.resource_definitions(stack)['group1'] + resg = resource_group.ResourceGroup('test', snip, stack) + expect = { + "heat_template_version": "2013-05-23", + "resources": {} + } + self.assertEqual(expect, resg._assemble_nested([])) + def test_index_var(self): stack = utils.parse_stack(template_repl) snip = stack.t.resource_definitions(stack)['group1'] @@ -662,10 +674,7 @@ class ResourceGroupTest(common.HeatTestCase): resg = stack['group1'] scheduler.TaskRunner(resg.create)() self.stack = resg.nested() - if expect_count > 0: - self.assertEqual(expect_count, len(resg.nested())) - else: - self.assertIsNone(resg.nested()) + self.assertEqual(expect_count, len(resg.nested())) self.assertEqual((resg.CREATE, resg.COMPLETE), resg.state) return resg