From 1e8e0fcc468f63be8414f856006bc840757ce54b Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Thu, 26 Jun 2014 16:55:32 +1200 Subject: [PATCH] HOT intrinisic function list_join like Fn::Join We have an increasing number of attributes which are a list of strings. In HOT there is no way to join a list into a string as with the CFN function Fn::Join. This change implements HOT intrinsic function list_join using an identical implementation as Fn::Join. Tripleo will benefit from this function since the lack of a join function in HOT is one of the barriers to transitioning to the HOT template format. Change-Id: I29e0b744271213429fff6922397b925eb9ccc204 --- doc/source/template_guide/hot_spec.rst | 20 ++++++++++++++++++++ heat/engine/hot/functions.py | 15 +++++++++++++++ heat/tests/test_hot.py | 6 +++--- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/doc/source/template_guide/hot_spec.rst b/doc/source/template_guide/hot_spec.rst index 15a6249eaf..a5ce5acbc6 100644 --- a/doc/source/template_guide/hot_spec.rst +++ b/doc/source/template_guide/hot_spec.rst @@ -726,6 +726,26 @@ The *resource ID* of the referenced resources as used in the current template is given as single parameter to the get_resource function. +list_join +-------- +The *list_join* function joins a list of strings with the given delimiter. +The syntax of the list_join function is as follows: + +:: + + list_join: + - + - + +A sample use of this function with a simple list is shown below. + +:: + + list_join: [', ', ['one', 'two', 'and three']] + +This would resolve to "one, two, and three". + + resource_facade --------------- The *resource_facade* function allows a provider template to retrieve data diff --git a/heat/engine/hot/functions.py b/heat/engine/hot/functions.py index abd7b42aad..1a26f0ae79 100644 --- a/heat/engine/hot/functions.py +++ b/heat/engine/hot/functions.py @@ -202,6 +202,20 @@ class GetFile(function.Function): return f +class Join(cfn_funcs.Join): + ''' + A function for joining strings. + + Takes the form:: + + { "list_join" : [ "", [ "", "", ... ] } + + And resolves to:: + + "..." + ''' + + class ResourceFacade(cfn_funcs.ResourceFacade): ''' A function for obtaining data from the facade resource from within the @@ -235,6 +249,7 @@ def function_mapping(version_key, version): 'get_attr': GetAtt, 'Fn::Select': cfn_funcs.Select, 'Fn::Join': cfn_funcs.Join, + 'list_join': Join, 'Fn::Split': cfn_funcs.Split, 'str_replace': Replace, 'Fn::Replace': cfn_funcs.Replace, diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py index 88c41afae3..6e572ed341 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -17,10 +17,10 @@ import six from heat.common import exception from heat.common import identifier from heat.common import template_format -from heat.engine.cfn import functions as cfn_funcs from heat.engine import constraints from heat.engine import environment from heat.engine import function +from heat.engine.hot import functions as hot_functions from heat.engine.hot import parameters as hot_param from heat.engine.hot import template as hot_template from heat.engine import parameters @@ -585,8 +585,8 @@ class HOTemplateTest(HeatTestCase): parent_resource.stack = parser.Stack(utils.dummy_context(), 'toplevel_stack', parser.Template(hot_tpl_empty)) - del_policy = cfn_funcs.Join(parent_resource.stack, - 'Fn::Join', ['eta', ['R', 'in']]) + del_policy = hot_functions.Join(parent_resource.stack, + 'list_join', ['eta', ['R', 'in']]) parent_resource.t = rsrc_defn.ResourceDefinition( 'parent', 'SomeType', deletion_policy=del_policy)