Merge "Convergence: Resolve attribute with path using cache data"

This commit is contained in:
Jenkins 2015-09-15 12:24:17 +00:00 committed by Gerrit Code Review
commit e37e1cf4f3
2 changed files with 60 additions and 1 deletions

View File

@ -1494,6 +1494,7 @@ class Resource(object):
complex_key = tuple([key] + list(path))
attribute = self.stack.cache_data_resource_attribute(
self.name, complex_key)
return attribute
else:
try:
attribute = self.attributes[key]
@ -1501,7 +1502,7 @@ class Resource(object):
raise exception.InvalidTemplateAttribute(resource=self.name,
key=key)
return attributes.select_from_attribute(attribute, path)
return attributes.select_from_attribute(attribute, path)
def FnGetAtts(self):
"""For the intrinsic function get_attr which returns all attributes.

View File

@ -1428,6 +1428,64 @@ class ResourceTest(common.HeatTestCase):
res.FnGetAtt('attr2')
self.assertIn("Attribute attr2 is not of type Map", self.LOG.output)
def test_getatt_with_path(self):
tmpl = template.Template({
'heat_template_version': '2013-05-23',
'resources': {
'res': {
'type': 'ResourceWithComplexAttributesType'
}
}
})
stack = parser.Stack(utils.dummy_context(), 'test', tmpl)
res = stack['res']
self.assertEqual('abc', res.FnGetAtt('nested_dict', 'string'))
def test_getatt_with_cache_data(self):
tmpl = template.Template({
'heat_template_version': '2013-05-23',
'resources': {
'res': {
'type': 'ResourceWithAttributeType'
}
}
})
stack = parser.Stack(utils.dummy_context(), 'test', tmpl,
cache_data={
'res': {'attrs': {'Foo': 'Res',
'foo': 'res'},
'uuid': mock.ANY,
'id': mock.ANY,
'action': 'CREATE',
'status': 'COMPLETE'}})
res = stack['res']
self.assertEqual('Res', res.FnGetAtt('Foo'))
def test_getatt_with_path_cache_data(self):
tmpl = template.Template({
'heat_template_version': '2013-05-23',
'resources': {
'res': {
'type': 'ResourceWithComplexAttributesType'
}
}
})
stack = parser.Stack(utils.dummy_context(), 'test', tmpl,
cache_data={
'res': {
'attrs': {('nested', 'string'): 'abc'},
'uuid': mock.ANY,
'id': mock.ANY,
'action': 'CREATE',
'status': 'COMPLETE'}})
res = stack['res']
self.assertEqual('abc', res.FnGetAtt('nested', 'string'))
def test_getatts(self):
tmpl = template.Template({
'heat_template_version': '2013-05-23',