From bb3ddcf5738a52867debb9c870548f5a67530e16 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Thu, 18 Oct 2018 13:08:50 -0400 Subject: [PATCH] Ensure Functions can be created without stack definition In a number of places we parse templates passing None as the stack definition, in order to be able to extract information from the template in cases where we don't actually need to resolve functions. However, the GetParam and GetFile HOT functions require an actual stack definition to be passed in order to initialise them. So far we haven't encountered any cases where those functions appear where we pass None for the stack definition. Ensure that all Functions can always be created even with no stack definition. Note that the cfn ParamRef class is not affected, as the Ref function always selects the GetResource implementation when the stack definition is None. Change-Id: Ic947dcdc17e9dbc58459a92ba970c292d70578cd --- heat/engine/hot/functions.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/heat/engine/hot/functions.py b/heat/engine/hot/functions.py index 9edcfa6f32..7bba5af5f5 100644 --- a/heat/engine/hot/functions.py +++ b/heat/engine/hot/functions.py @@ -62,9 +62,14 @@ class GetParam(function.Function): def __init__(self, stack, fn_name, args): super(GetParam, self).__init__(stack, fn_name, args) - self.parameters = self.stack.parameters + if self.stack is not None: + self.parameters = self.stack.parameters + else: + self.parameters = None def result(self): + assert self.parameters is not None, "No stack definition in Function" + args = function.resolve(self.args) if not args: @@ -542,9 +547,11 @@ class GetFile(function.Function): def __init__(self, stack, fn_name, args): super(GetFile, self).__init__(stack, fn_name, args) - self.files = self.stack.t.files + self.files = self.stack.t.files if self.stack is not None else None def result(self): + assert self.files is not None, "No stack definition in Function" + args = function.resolve(self.args) if not (isinstance(args, six.string_types)): raise TypeError(_('Argument to "%s" must be a string') %