Using a number in str_replace causes an exception
When passing in a number as a parameter value to the string replace function, an exception is raised. Cast the value as a string before using it in the string replace function. Change-Id: I38bdc8d97c7d1f9b62f52b0a783bf4d3fde3611a Closes-Bug: #1250251
This commit is contained in:
parent
a1280357db
commit
cc8acd8f12
@ -248,7 +248,7 @@ class HOTemplate(template.Template):
|
||||
_('"params" parameter must be a dictionary'))
|
||||
for key in params.iterkeys():
|
||||
value = params.get(key, '') or ""
|
||||
text = text.replace(key, value)
|
||||
text = text.replace(key, str(value))
|
||||
return text
|
||||
|
||||
match_str_replace = lambda k, v: k in ['str_replace', 'Fn::Replace']
|
||||
|
@ -177,6 +177,18 @@ class HOTemplateTest(HeatTestCase):
|
||||
self.assertEqual(snippet_resolved,
|
||||
tmpl.resolve_replace(snippet))
|
||||
|
||||
def test_str_replace_number(self):
|
||||
"""Test str_replace function with numbers."""
|
||||
|
||||
snippet = {'str_replace': {'template': 'Template number string bar',
|
||||
'params': {'number': 1}}}
|
||||
snippet_resolved = 'Template 1 string bar'
|
||||
|
||||
tmpl = parser.Template(hot_tpl_empty)
|
||||
|
||||
self.assertEqual(snippet_resolved,
|
||||
tmpl.resolve_replace(snippet))
|
||||
|
||||
def test_str_fn_replace(self):
|
||||
"""Test Fn:Replace function."""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user