Fix 'if' function with only 2 arguments
This had a similar problem as when null values were passed explicitly before the fix for bug 1709620. Change-Id: I02fb4c8815bc24d4c0c339022aa857dc344d58e9 Story: 2011108 Task: 49921
This commit is contained in:
parent
80eea85194
commit
f7eddbef83
@ -243,7 +243,9 @@ class Macro(Function, metaclass=abc.ABCMeta):
|
|||||||
if isinstance(self.parsed, Function):
|
if isinstance(self.parsed, Function):
|
||||||
return self.parsed.__reduce__()
|
return self.parsed.__reduce__()
|
||||||
if self.parsed is None:
|
if self.parsed is None:
|
||||||
return lambda x: None, (None,)
|
return type(None), tuple()
|
||||||
|
if self.parsed is Ellipsis:
|
||||||
|
return type(Ellipsis), tuple()
|
||||||
return type(self.parsed), (self.parsed,)
|
return type(self.parsed), (self.parsed,)
|
||||||
|
|
||||||
def _repr_result(self):
|
def _repr_result(self):
|
||||||
|
@ -165,8 +165,9 @@ class HOTemplateTest(common.HeatTestCase):
|
|||||||
"""Test processing of HOT templates."""
|
"""Test processing of HOT templates."""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def resolve(snippet, template, stack=None):
|
def resolve(snippet, template, stack=None, nullable=False):
|
||||||
return function.resolve(template.parse(stack and stack.defn, snippet))
|
return function.resolve(template.parse(stack and stack.defn, snippet),
|
||||||
|
nullable=nullable)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def resolve_condition(snippet, template, stack=None):
|
def resolve_condition(snippet, template, stack=None):
|
||||||
@ -1445,6 +1446,15 @@ class HOTemplateTest(common.HeatTestCase):
|
|||||||
resolved = self.resolve(snippet, tmpl, stack)
|
resolved = self.resolve(snippet, tmpl, stack)
|
||||||
self.assertIsNone(resolved)
|
self.assertIsNone(resolved)
|
||||||
|
|
||||||
|
def test_if_empty_return(self):
|
||||||
|
snippet = {'if': [False, 'value_if_true']}
|
||||||
|
# when condition is true, if function resolve to value_if_true
|
||||||
|
tmpl = template.Template(hot_wallaby_tpl_empty)
|
||||||
|
stack = parser.Stack(utils.dummy_context(),
|
||||||
|
'test_if_empty_return', tmpl)
|
||||||
|
resolved = self.resolve(snippet, tmpl, stack, nullable=True)
|
||||||
|
self.assertIs(Ellipsis, resolved)
|
||||||
|
|
||||||
def test_if_using_condition_function(self):
|
def test_if_using_condition_function(self):
|
||||||
tmpl_with_conditions = template_format.parse('''
|
tmpl_with_conditions = template_format.parse('''
|
||||||
heat_template_version: 2016-10-14
|
heat_template_version: 2016-10-14
|
||||||
@ -1509,6 +1519,29 @@ resources:
|
|||||||
self.stack.state)
|
self.stack.state)
|
||||||
self.assertEqual('', self.stack['AResource'].properties['Foo'])
|
self.assertEqual('', self.stack['AResource'].properties['Foo'])
|
||||||
|
|
||||||
|
def test_if_referenced_by_resource_empty(self):
|
||||||
|
tmpl_with_conditions = template_format.parse('''
|
||||||
|
heat_template_version: wallaby
|
||||||
|
conditions:
|
||||||
|
create_prod: False
|
||||||
|
resources:
|
||||||
|
AResource:
|
||||||
|
type: ResourceWithPropsType
|
||||||
|
properties:
|
||||||
|
Foo:
|
||||||
|
if:
|
||||||
|
- create_prod
|
||||||
|
- "prod"
|
||||||
|
''')
|
||||||
|
tmpl = template.Template(tmpl_with_conditions)
|
||||||
|
self.stack = parser.Stack(utils.dummy_context(),
|
||||||
|
'test_if_referenced_by_resource_null', tmpl)
|
||||||
|
self.stack.store()
|
||||||
|
self.stack.create()
|
||||||
|
self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE),
|
||||||
|
self.stack.state)
|
||||||
|
self.assertIsNone(self.stack['AResource'].properties['Foo'])
|
||||||
|
|
||||||
def test_if_invalid_args(self):
|
def test_if_invalid_args(self):
|
||||||
snippets = [
|
snippets = [
|
||||||
{'if': ['create_prod', 'one_value']},
|
{'if': ['create_prod', 'one_value']},
|
||||||
|
Loading…
Reference in New Issue
Block a user