From 5553a6f29c9069318f97ba6e1d83bc3f18b59240 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Tue, 10 Jan 2017 15:00:39 -0500 Subject: [PATCH] Correct output values when generating templates Change-Id: Ibb41bec5c6cf4f63a5b8ab1c9a46b7219c3e46fb Closes-Bug: #1655439 --- heat/engine/attributes.py | 6 ++--- heat/tests/test_attributes.py | 49 ++++++++++++++++++++++++++++++++--- heat/tests/test_resource.py | 12 ++++----- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/heat/engine/attributes.py b/heat/engine/attributes.py index 78ba4f787d..e72caf23b5 100644 --- a/heat/engine/attributes.py +++ b/heat/engine/attributes.py @@ -112,14 +112,12 @@ class Attribute(object): """ if template_type == 'hot': return { - "value": '{"get_attr": ["%s", "%s"]}' % (resource_name, - self.name), + "value": {"get_attr": [resource_name, self.name]}, "description": self.schema.description } else: return { - "Value": '{"Fn::GetAtt": ["%s", "%s"]}' % (resource_name, - self.name), + "Value": {"Fn::GetAtt": [resource_name, self.name]}, "Description": self.schema.description } diff --git a/heat/tests/test_attributes.py b/heat/tests/test_attributes.py index 6c7b63fa83..77b6d1b799 100644 --- a/heat/tests/test_attributes.py +++ b/heat/tests/test_attributes.py @@ -83,13 +83,23 @@ class AttributeTest(common.HeatTestCase): def test_as_output(self): """Test that Attribute looks right when viewed as an Output.""" expected = { - "Value": '{"Fn::GetAtt": ["test_resource", "test1"]}', + "Value": {"Fn::GetAtt": ["test_resource", "test1"]}, "Description": "The first test attribute" } attr = attributes.Attribute( "test1", attributes.Schema("The first test attribute")) self.assertEqual(expected, attr.as_output("test_resource")) + def test_as_output_hot(self): + """Test that Attribute looks right when viewed as an Output.""" + expected = { + "value": {"get_attr": ["test_resource", "test1"]}, + "description": "The first test attribute" + } + attr = attributes.Attribute( + "test1", attributes.Schema("The first test attribute")) + self.assertEqual(expected, attr.as_output("test_resource", "hot")) + class AttributesTest(common.HeatTestCase): """Test the Attributes class.""" @@ -152,15 +162,15 @@ class AttributesTest(common.HeatTestCase): """Test that Output format works as expected.""" expected = { "test1": { - "Value": '{"Fn::GetAtt": ["test_resource", "test1"]}', + "Value": {"Fn::GetAtt": ["test_resource", "test1"]}, "Description": "Test attrib 1" }, "test2": { - "Value": '{"Fn::GetAtt": ["test_resource", "test2"]}', + "Value": {"Fn::GetAtt": ["test_resource", "test2"]}, "Description": "Test attrib 2" }, "test3": { - "Value": '{"Fn::GetAtt": ["test_resource", "test3"]}', + "Value": {"Fn::GetAtt": ["test_resource", "test3"]}, "Description": "Test attrib 3" } } @@ -178,6 +188,37 @@ class AttributesTest(common.HeatTestCase): attributes.Attributes.as_outputs("test_resource", MyTestResourceClass)) + def test_as_outputs_hot(self): + """Test that Output format works as expected.""" + expected = { + "test1": { + "value": {"get_attr": ["test_resource", "test1"]}, + "description": "Test attrib 1" + }, + "test2": { + "value": {"get_attr": ["test_resource", "test2"]}, + "description": "Test attrib 2" + }, + "test3": { + "value": {"get_attr": ["test_resource", "test3"]}, + "description": "Test attrib 3" + } + } + MyTestResourceClass = mock.MagicMock() + MyTestResourceClass.attributes_schema = { + "test1": attributes.Schema("Test attrib 1"), + "test2": attributes.Schema("Test attrib 2"), + "test3": attributes.Schema("Test attrib 3"), + "test4": attributes.Schema( + "Test attrib 4", + support_status=support.SupportStatus(status=support.HIDDEN)) + } + self.assertEqual( + expected, + attributes.Attributes.as_outputs("test_resource", + MyTestResourceClass, + "hot")) + def test_caching_local(self): self.resolver.side_effect = ["value1", "value1 changed"] attribs = attributes.Attributes('test resource', diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 6b17f3d647..b7c9442abe 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -1433,15 +1433,15 @@ class ResourceTest(common.HeatTestCase): 'Outputs': { 'output1': { 'Description': 'output1_desc', - 'Value': '{"Fn::GetAtt": ["TestResource", "output1"]}' + 'Value': {"Fn::GetAtt": ["TestResource", "output1"]} }, 'output2': { 'Description': 'output2_desc', - 'Value': '{"Fn::GetAtt": ["TestResource", "output2"]}' + 'Value': {"Fn::GetAtt": ["TestResource", "output2"]} }, 'show': { 'Description': u'Detailed information about resource.', - 'Value': '{"Fn::GetAtt": ["TestResource", "show"]}' + 'Value': {"Fn::GetAtt": ["TestResource", "show"]} } } } @@ -1517,15 +1517,15 @@ class ResourceTest(common.HeatTestCase): 'outputs': { 'output1': { 'description': 'output1_desc', - 'value': '{"get_attr": ["TestResource", "output1"]}' + 'value': {"get_attr": ["TestResource", "output1"]} }, 'output2': { 'description': 'output2_desc', - 'value': '{"get_attr": ["TestResource", "output2"]}' + 'value': {"get_attr": ["TestResource", "output2"]} }, 'show': { 'description': u'Detailed information about resource.', - 'value': '{"get_attr": ["TestResource", "show"]}' + 'value': {"get_attr": ["TestResource", "show"]} } } }