diff --git a/heat/engine/resources/resource_group.py b/heat/engine/resources/resource_group.py index 1584abf60f..add88c2d17 100644 --- a/heat/engine/resources/resource_group.py +++ b/heat/engine/resources/resource_group.py @@ -150,9 +150,8 @@ class ResourceGroup(stack_resource.StackResource): self.stack) res_inst.validate() - def _resource_names(self, properties=None): - p = properties or self.properties - return [str(n) for n in range(p.get(self.COUNT, 0))] + def _resource_names(self): + return [str(n) for n in range(self.properties.get(self.COUNT))] def handle_create(self): names = self._resource_names() @@ -162,14 +161,18 @@ class ResourceGroup(stack_resource.StackResource): {}, self.stack.timeout_mins) - def handle_update(self, new_snippet, tmpl_diff, prop_diff): - old_names = self._resource_names() - new_names = self._resource_names(prop_diff) - if old_names != new_names: - return self.update_with_template( - self._assemble_nested(new_names), - {}, - self.stack.timeout_mins) + def handle_update(self, json_snippet, tmpl_diff, prop_diff): + if prop_diff: + old_names = self._resource_names() + self.properties = json_snippet.properties(self.properties_schema, + self.context) + + new_names = self._resource_names() + if old_names != new_names: + return self.update_with_template( + self._assemble_nested(new_names), + {}, + self.stack.timeout_mins) def handle_delete(self): return self.delete_nested() diff --git a/heat/engine/resources/software_config/software_deployment.py b/heat/engine/resources/software_config/software_deployment.py index 59d388fbf6..0b3f1279e2 100644 --- a/heat/engine/resources/software_config/software_deployment.py +++ b/heat/engine/resources/software_config/software_deployment.py @@ -565,9 +565,8 @@ class SoftwareDeployments(resource_group.ResourceGroup): ), } - def _resource_names(self, properties=None): - p = properties or self.properties - return p.get(self.SERVERS, {}).keys() + def _resource_names(self): + return self.properties.get(self.SERVERS, {}).keys() def _do_prop_replace(self, res_name, res_def_template): res_def = copy.deepcopy(res_def_template) diff --git a/heat/tests/test_resource_group.py b/heat/tests/test_resource_group.py index 10454cfa50..c25b2460d4 100644 --- a/heat/tests/test_resource_group.py +++ b/heat/tests/test_resource_group.py @@ -359,6 +359,10 @@ class ResourceGroupTest(common.HeatTestCase): def test_update(self): """Test basic update.""" resg = self._create_dummy_stack() + self.assertEqual(2, len(resg.nested())) + resource_names = [r.name for r in resg.nested().iter_resources()] + self.assertEqual(['0', '1'], sorted(resource_names)) + old_snip = copy.deepcopy(resg.t) new_snip = copy.deepcopy(resg.t) new_snip['Properties']['count'] = 3 scheduler.TaskRunner(resg.update, new_snip)() @@ -366,6 +370,14 @@ class ResourceGroupTest(common.HeatTestCase): self.assertEqual((resg.UPDATE, resg.COMPLETE), resg.state) self.assertEqual((resg.UPDATE, resg.COMPLETE), resg.nested().state) self.assertEqual(3, len(resg.nested())) + resource_names = [r.name for r in resg.nested().iter_resources()] + self.assertEqual(['0', '1', '2'], sorted(resource_names)) + scheduler.TaskRunner(resg.update, old_snip)() + self.assertEqual((resg.UPDATE, resg.COMPLETE), resg.state) + self.assertEqual((resg.UPDATE, resg.COMPLETE), resg.nested().state) + self.assertEqual(2, len(resg.nested())) + resource_names = [r.name for r in resg.nested().iter_resources()] + self.assertEqual(['0', '1'], sorted(resource_names)) def test_aggregate_attribs(self): """ diff --git a/heat/tests/test_software_deployment.py b/heat/tests/test_software_deployment.py index 2da3943a6a..acd60ba965 100644 --- a/heat/tests/test_software_deployment.py +++ b/heat/tests/test_software_deployment.py @@ -835,11 +835,10 @@ class SoftwareDeploymentsTest(HeatTestCase): set(resg._resource_names()) ) + resg.properties = {'servers': {'s1': 'u1', 's2': 'u2', 's3': 'u3'}} self.assertEqual( set(('s1', 's2', 's3')), - set(resg._resource_names({ - 'servers': {'s1': 'u1', 's2': 'u2', 's3': 'u3'}})) - ) + set(resg._resource_names())) def test_assemble_nested(self): """ diff --git a/heat/tests/test_structured_config.py b/heat/tests/test_structured_config.py index 06af1ad4ef..bccb452a0f 100644 --- a/heat/tests/test_structured_config.py +++ b/heat/tests/test_structured_config.py @@ -246,11 +246,10 @@ class StructuredDeploymentsTest(HeatTestCase): set(resg._resource_names()) ) + resg.properties = {'servers': {'s1': 'u1', 's2': 'u2', 's3': 'u3'}} self.assertEqual( set(('s1', 's2', 's3')), - set(resg._resource_names({ - 'servers': {'s1': 'u1', 's2': 'u2', 's3': 'u3'}})) - ) + set(resg._resource_names())) def test_assemble_nested(self): """