diff --git a/heat/engine/function.py b/heat/engine/function.py index 2169e21943..708b8a2c6b 100644 --- a/heat/engine/function.py +++ b/heat/engine/function.py @@ -243,7 +243,9 @@ class Macro(Function, metaclass=abc.ABCMeta): if isinstance(self.parsed, Function): return self.parsed.__reduce__() 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,) def _repr_result(self): diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py index a4f4c3d32a..3c826309fd 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -165,8 +165,9 @@ class HOTemplateTest(common.HeatTestCase): """Test processing of HOT templates.""" @staticmethod - def resolve(snippet, template, stack=None): - return function.resolve(template.parse(stack and stack.defn, snippet)) + def resolve(snippet, template, stack=None, nullable=False): + return function.resolve(template.parse(stack and stack.defn, snippet), + nullable=nullable) @staticmethod def resolve_condition(snippet, template, stack=None): @@ -1445,6 +1446,15 @@ class HOTemplateTest(common.HeatTestCase): resolved = self.resolve(snippet, tmpl, stack) 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): tmpl_with_conditions = template_format.parse(''' heat_template_version: 2016-10-14 @@ -1509,6 +1519,29 @@ resources: self.stack.state) 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): snippets = [ {'if': ['create_prod', 'one_value']},