Merge "Add workaround for functions in translation"

This commit is contained in:
Jenkins 2016-10-14 02:16:29 +00:00 committed by Gerrit Code Review
commit cf988a60f2
2 changed files with 43 additions and 0 deletions

View File

@ -230,6 +230,11 @@ class TranslationRule(object):
def translate_property(self, path, data, return_value=False, value=None,
value_data=None, value_key=None,
client_resolve=True):
if isinstance(data, function.Function):
if return_value:
raise AttributeError('No chance to translate value due to '
'value is function. Skip translation.')
return
current_key = path[0]
if len(path) <= 1:
if return_value:

View File

@ -862,6 +862,44 @@ class TestTranslationRule(common.HeatTestCase):
self.assertEqual({'source': param, 'destination': ''},
data)
def test_property_get_attr_translation_successfully_skipped(self):
schema = {
'source': properties.Schema(
properties.Schema.LIST,
schema=properties.Schema(
properties.Schema.MAP,
schema={
'sub-source': properties.Schema(
properties.Schema.STRING
)
}
)
),
'destination': properties.Schema(
properties.Schema.STRING
)}
class DummyStack(dict):
pass
class rsrc(object):
pass
stack = DummyStack(res=rsrc())
attr_func = cfn_funcs.GetAtt(stack, 'Fn::GetAtt',
['res', 'sub-sources'])
data = {'source': attr_func, 'destination': ''}
props = properties.Properties(schema, data)
rule = translation.TranslationRule(
props,
translation.TranslationRule.REPLACE,
['source', 'sub-sources'],
value_path=['destination'])
rule.execute_rule()
self.assertEqual({'source': attr_func, 'destination': ''}, props.data)
def test_list_list_add_translation_rule(self):
schema = {
'far': properties.Schema(