Allow function 'yaql' as condition function
Allow 'yaql' in condition definition, like:
parameters:
ServiceNames:
type: comma_delimited_list
default: ['neutron', 'heat']
conditions:
contains_neutron:
yaql:
expression: $.data.service_names.contains('neutron')
data:
service_names:
get_param: ServiceNames
Closes-Bug: #1693093
Change-Id: I83a540336c01a696780621fb2b39486a6abf0917
This commit is contained in:
@@ -321,6 +321,7 @@ for the ``heat_template_version`` key:
|
|||||||
yaql
|
yaql
|
||||||
if
|
if
|
||||||
|
|
||||||
|
We support 'yaql' as condition function in this version.
|
||||||
The complete list of supported condition functions is::
|
The complete list of supported condition functions is::
|
||||||
|
|
||||||
equals
|
equals
|
||||||
@@ -328,6 +329,7 @@ for the ``heat_template_version`` key:
|
|||||||
not
|
not
|
||||||
and
|
and
|
||||||
or
|
or
|
||||||
|
yaql
|
||||||
|
|
||||||
.. _hot_spec_parameter_groups:
|
.. _hot_spec_parameter_groups:
|
||||||
|
|
||||||
@@ -934,10 +936,12 @@ expression
|
|||||||
not
|
not
|
||||||
and
|
and
|
||||||
or
|
or
|
||||||
|
yaql
|
||||||
|
|
||||||
Note: In condition functions, you can reference a value from an input
|
Note: In condition functions, you can reference a value from an input
|
||||||
parameter, but you cannot reference resource or its attribute. We support
|
parameter, but you cannot reference resource or its attribute. We support
|
||||||
referencing other conditions (by condition name) in condition functions.
|
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
|
An example of conditions section definition
|
||||||
|
|
||||||
@@ -979,6 +983,12 @@ An example of conditions section definition
|
|||||||
and:
|
and:
|
||||||
- cd1
|
- cd1
|
||||||
- cd2
|
- cd2
|
||||||
|
cd9:
|
||||||
|
yaql:
|
||||||
|
expression: $.data.services.contains('heat')
|
||||||
|
data:
|
||||||
|
services:
|
||||||
|
get_param: ServiceNames
|
||||||
|
|
||||||
The example below shows how to associate condition with resources
|
The example below shows how to associate condition with resources
|
||||||
|
|
||||||
|
|||||||
@@ -607,3 +607,14 @@ class HOTemplate20170901(HOTemplate20170224):
|
|||||||
'Fn::ResourceFacade': hot_funcs.Removed,
|
'Fn::ResourceFacade': hot_funcs.Removed,
|
||||||
'Ref': 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
|
||||||
|
}
|
||||||
|
|||||||
@@ -1299,6 +1299,36 @@ class HOTemplateTest(common.HeatTestCase):
|
|||||||
|
|
||||||
self.assertEqual({'a': [1, 2, 3]}, resolved)
|
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):
|
def test_equals(self):
|
||||||
hot_tpl = template_format.parse('''
|
hot_tpl = template_format.parse('''
|
||||||
heat_template_version: 2016-10-14
|
heat_template_version: 2016-10-14
|
||||||
|
|||||||
Reference in New Issue
Block a user