From a7e473bcc89da0f3191d542fadf8328a48c78b88 Mon Sep 17 00:00:00 2001 From: Rabi Mishra Date: Thu, 13 Aug 2015 11:04:17 +0530 Subject: [PATCH] Add option to specify metadata for RG resources Provides an optional property to specify metadata for the resources. Change-Id: I6cd19f759a907bf913e53aa0ca26a12ee157a86e --- .../openstack/heat/resource_group.py | 12 +++++++-- heat/tests/test_resource_group.py | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/heat/engine/resources/openstack/heat/resource_group.py b/heat/engine/resources/openstack/heat/resource_group.py index 12d570c209..673dc32f63 100644 --- a/heat/engine/resources/openstack/heat/resource_group.py +++ b/heat/engine/resources/openstack/heat/resource_group.py @@ -83,9 +83,9 @@ class ResourceGroup(stack_resource.StackResource): ) _RESOURCE_DEF_KEYS = ( - RESOURCE_DEF_TYPE, RESOURCE_DEF_PROPERTIES, + RESOURCE_DEF_TYPE, RESOURCE_DEF_PROPERTIES, RESOURCE_DEF_METADATA, ) = ( - 'type', 'properties', + 'type', 'properties', 'metadata', ) _REMOVAL_POLICIES_KEYS = ( @@ -146,6 +146,12 @@ class ResourceGroup(stack_resource.StackResource): properties.Schema.MAP, _('Property values for the resources in the group') ), + RESOURCE_DEF_METADATA: properties.Schema( + properties.Schema.MAP, + _('Supplied metadata for the resources in the group'), + support_status=support.SupportStatus(version='5.0.0') + ), + }, required=True, update_allowed=True @@ -411,6 +417,8 @@ class ResourceGroup(stack_resource.StackResource): res_def = self.properties[self.RESOURCE_DEF] if res_def[self.RESOURCE_DEF_PROPERTIES] is None: res_def[self.RESOURCE_DEF_PROPERTIES] = {} + if res_def[self.RESOURCE_DEF_METADATA] is None: + del res_def[self.RESOURCE_DEF_METADATA] if not include_all: resource_def_props = res_def[self.RESOURCE_DEF_PROPERTIES] clean = dict((k, v) for k, v in resource_def_props.items() diff --git a/heat/tests/test_resource_group.py b/heat/tests/test_resource_group.py index 52e1c59960..346b44dda1 100644 --- a/heat/tests/test_resource_group.py +++ b/heat/tests/test_resource_group.py @@ -187,6 +187,32 @@ class ResourceGroupTest(common.HeatTestCase): } self.assertEqual(expect, resg._assemble_nested([])) + def test_assemble_nested_with_metadata(self): + templ = copy.deepcopy(template) + res_def = templ["resources"]["group1"]["properties"]['resource_def'] + res_def['properties']['Foo'] = None + res_def['metadata'] = { + 'priority': 'low', + 'role': 'webserver' + } + 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": { + "0": { + "type": "OverwrittenFnGetRefIdType", + "properties": {}, + "metadata": { + 'priority': 'low', + 'role': 'webserver' + } + } + } + } + self.assertEqual(expect, resg._assemble_nested(['0'])) + def test_assemble_nested_rolling_update(self): expect = { "heat_template_version": "2013-05-23",