Allow str_replace to reference parameters/attributes
Currently a validation error occurs if you attempt to reference via get_param or get_attr when using str_replace, however if we avoid the explicit validation in the constructor it actually works fine, and we already have a validation to handle any invalid input elsewhere in the function definition. Change-Id: Ib934f443a8b8e4f75335a9d8b992e7f86791aa45 Closes-Bug: #1539737
This commit is contained in:
parent
8b83e14d84
commit
0d109b75d9
|
@ -402,10 +402,6 @@ class Replace(function.Function):
|
|||
|
||||
self._mapping, self._string = self._parse_args()
|
||||
|
||||
if not isinstance(self._mapping, collections.Mapping):
|
||||
raise TypeError(_('"%s" parameters must be a mapping') %
|
||||
self.fn_name)
|
||||
|
||||
def _parse_args(self):
|
||||
|
||||
example = ('{"%s": '
|
||||
|
|
|
@ -613,6 +613,29 @@ class HOTemplateTest(common.HeatTestCase):
|
|||
|
||||
self.assertRaises(TypeError, self.resolve, snippet, tmpl)
|
||||
|
||||
def test_str_replace_ref_get_param(self):
|
||||
"""Test str_replace referencing parameters."""
|
||||
hot_tpl = template_format.parse('''
|
||||
heat_template_version: 2015-04-30
|
||||
parameters:
|
||||
p_template:
|
||||
type: string
|
||||
default: foo-replaceme
|
||||
p_params:
|
||||
type: json
|
||||
default:
|
||||
replaceme: success
|
||||
''')
|
||||
snippet = {'str_replace':
|
||||
{'template': {'get_param': 'p_template'},
|
||||
'params': {'get_param': 'p_params'}}}
|
||||
snippet_resolved = 'foo-success'
|
||||
|
||||
tmpl = template.Template(hot_tpl)
|
||||
stack = parser.Stack(utils.dummy_context(), 'test_stack', tmpl)
|
||||
|
||||
self.assertEqual(snippet_resolved, self.resolve(snippet, tmpl, stack))
|
||||
|
||||
def test_get_file(self):
|
||||
"""Test get_file function."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue