Add workaround for functions in translation
Currently if translation data is function and translation path runs over unresolved function's value (i.e. intermediate data is function), translation works incorrectly and raises AttributeError. This workaround makes translation skip rules, where translation values contains inside functions. NOTE: This patch is not solve issues, described by Zane Bitter in [1], just add workaround for current mechanism. Also, it doesn't affect destination values, just intermediate, which currently cannot be safely resolved. [1] https://bugs.launchpad.net/heat/+bug/1620859 Change-Id: I5d7f8d3a615590325d38702b21f224ff3de33315 Closes-bug: #1630214
This commit is contained in:
parent
f2881d4071
commit
6396d7c617
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue