Allow get_attr: [res_name] format to get all attribute

Don't check None attribute name if want to get all
attributes of resource, and this only works in template
'2015-10-15' or higher version.

Change-Id: I6699bfc8bc8096e5dc313d01b3a829694c105fea
Closes-Bug: #1505560
This commit is contained in:
huangtianhua 2015-10-14 10:41:50 +08:00
parent 20b5e05be7
commit 1240c33a3f
4 changed files with 35 additions and 0 deletions

View File

@ -176,9 +176,19 @@ class GetAtt(function.Function):
return itertools.chain(super(GetAtt, self).dependencies(path),
[self._resource(path)])
def _allow_without_attribute_name(self):
return False
def validate(self):
super(GetAtt, self).validate()
res = self._resource()
if self._allow_without_attribute_name():
# if allow without attribute_name, then don't check
# when attribute_name is None
if self._attribute is None:
return
attr = function.resolve(self._attribute)
from heat.engine import resource
if (type(res).FnGetAtt == resource.Resource.FnGetAtt and

View File

@ -218,6 +218,9 @@ class GetAttAllAttributes(GetAtt):
else:
return super(GetAttAllAttributes, self).result()
def _allow_without_attribute_name(self):
return True
class Replace(cfn_funcs.Replace):
"""A function for performing string substitutions.

View File

@ -280,3 +280,10 @@ class ValidateGetAttTest(common.HeatTestCase):
func = functions.GetAtt(self.stack, 'Fn::GetAtt',
[self.rsrc.name, 'Foo'])
self.assertIsNone(func.validate())
def test_get_attr_without_attribute_name(self):
ex = self.assertRaises(ValueError, functions.GetAtt,
self.stack, 'Fn::GetAtt', [self.rsrc.name])
self.assertEqual('Arguments to "Fn::GetAtt" must be '
'of the form [resource_name, attribute]',
six.text_type(ex))

View File

@ -2096,3 +2096,18 @@ class TestGetAttAllAttributes(common.HeatTestCase):
else:
self.assertEqual(self.expected,
self.resolve(self.snippet, tmpl, stack))
def test_stack_validate_outputs_get_all_attribute(self):
hot_liberty_tpl = template_format.parse('''
heat_template_version: 2015-10-15
resources:
resource1:
type: GenericResourceType
outputs:
all_attr:
value: {get_attr: [resource1]}
''')
stack = parser.Stack(utils.dummy_context(), 'test_outputs_get_all',
template.Template(hot_liberty_tpl))
stack.validate()