Merge "Allow function 'yaql' as condition function"

This commit is contained in:
Jenkins 2017-05-26 21:18:40 +00:00 committed by Gerrit Code Review
commit 4bc9acca7f
3 changed files with 51 additions and 0 deletions

View File

@ -321,6 +321,7 @@ for the ``heat_template_version`` key:
yaql
if
We support 'yaql' as condition function in this version.
The complete list of supported condition functions is::
equals
@ -328,6 +329,7 @@ for the ``heat_template_version`` key:
not
and
or
yaql
.. _hot_spec_parameter_groups:
@ -934,10 +936,12 @@ expression
not
and
or
yaql
Note: In condition functions, you can reference a value from an input
parameter, but you cannot reference resource or its attribute. We support
referencing other conditions (by condition name) in condition functions.
We support 'yaql' as condition function in the Pike version.
An example of conditions section definition
@ -979,6 +983,12 @@ An example of conditions section definition
and:
- cd1
- cd2
cd9:
yaql:
expression: $.data.services.contains('heat')
data:
services:
get_param: ServiceNames
The example below shows how to associate condition with resources

View File

@ -607,3 +607,14 @@ class HOTemplate20170901(HOTemplate20170224):
'Fn::ResourceFacade': hot_funcs.Removed,
'Ref': hot_funcs.Removed,
}
condition_functions = {
'get_param': hot_funcs.GetParam,
'equals': hot_funcs.Equals,
'not': hot_funcs.Not,
'and': hot_funcs.And,
'or': hot_funcs.Or,
# functions added in 2017-09-01
'yaql': hot_funcs.Yaql
}

View File

@ -1299,6 +1299,36 @@ class HOTemplateTest(common.HeatTestCase):
self.assertEqual({'a': [1, 2, 3]}, resolved)
def test_yaql_as_condition(self):
hot_tpl = template_format.parse('''
heat_template_version: pike
parameters:
ServiceNames:
type: comma_delimited_list
default: ['neutron', 'heat']
''')
snippet = {
'yaql': {
'expression': '$.data.service_names.contains("neutron")',
'data': {'service_names': {'get_param': 'ServiceNames'}}}}
# when param 'ServiceNames' contains 'neutron',
# equals function resolve to true
tmpl = template.Template(hot_tpl)
stack = parser.Stack(utils.dummy_context(),
'test_condition_yaql_true', tmpl)
resolved = self.resolve_condition(snippet, tmpl, stack)
self.assertTrue(resolved)
# when param 'ServiceNames' doesn't contain 'neutron',
# equals function resolve to false
tmpl = template.Template(
hot_tpl,
env=environment.Environment(
{'ServiceNames': ['nova_network', 'heat']}))
stack = parser.Stack(utils.dummy_context(),
'test_condition_yaql_false', tmpl)
resolved = self.resolve_condition(snippet, tmpl, stack)
self.assertFalse(resolved)
def test_equals(self):
hot_tpl = template_format.parse('''
heat_template_version: 2016-10-14