Reusable empty template
Refactored the empty template and added it to template module so that it can be re-used else where. In convergence it is needed for rolling back when create fails. Also needed for deleting stack, that is, update the stack with empty template. The empty_template method can be passed a template header (version) in order to get an empty template of that version, otherwise by default, an empty HOT template is returned. Change-Id: Ic59bd2d4b9cfed1efd1973af0c4ec9274bcc204a
This commit is contained in:
parent
910d40ba7b
commit
f71811a770
|
@ -36,7 +36,6 @@ from heat.common.i18n import _LW
|
|||
from heat.common import identifier
|
||||
from heat.common import messaging as rpc_messaging
|
||||
from heat.common import service_utils
|
||||
from heat.common import template_format
|
||||
from heat.engine import api
|
||||
from heat.engine import attributes
|
||||
from heat.engine import clients
|
||||
|
@ -950,12 +949,7 @@ class EngineService(service.Service):
|
|||
stack = parser.Stack.load(cnxt, stack=st)
|
||||
|
||||
if stack.convergence:
|
||||
empty_template = '''
|
||||
heat_template_version: 2013-05-23
|
||||
description: Empty Template
|
||||
'''
|
||||
tmpl = template_format.parse(empty_template)
|
||||
template = templatem.Template(tmpl)
|
||||
template = templatem.Template.create_empty_template()
|
||||
stack.converge_stack(template=template, action=stack.DELETE)
|
||||
return
|
||||
|
||||
|
|
|
@ -244,6 +244,23 @@ class Template(collections.Mapping):
|
|||
'Found a [%s] instead') % type(res)
|
||||
raise exception.StackValidationFailed(message=message)
|
||||
|
||||
@classmethod
|
||||
def create_empty_template(cls,
|
||||
version=('heat_template_version', '2015-04-30')):
|
||||
'''Creates an empty template.
|
||||
|
||||
Creates a new empty template with given version. If version is
|
||||
not provided, a new empty HOT template of version "2015-04-30"
|
||||
is returned.
|
||||
|
||||
:param version: A tuple containing version header of the
|
||||
template: version key and value. E.g. ("heat_template_version",
|
||||
"2015-04-30")
|
||||
:returns: A new empty template.
|
||||
'''
|
||||
tmpl = {version[0]: version[1]}
|
||||
return cls(tmpl)
|
||||
|
||||
|
||||
def parse(functions, stack, snippet):
|
||||
recurse = functools.partial(parse, functions, stack)
|
||||
|
|
|
@ -94,11 +94,6 @@ resources:
|
|||
salt: {get_param: salt}
|
||||
'''
|
||||
|
||||
empty_template = '''
|
||||
heat_template_version: 2013-05-23
|
||||
description: Empty Template
|
||||
'''
|
||||
|
||||
wp_template_no_default = '''
|
||||
{
|
||||
"AWSTemplateFormatVersion" : "2010-09-09",
|
||||
|
@ -400,9 +395,8 @@ class StackConvergenceCreateUpdateDeleteTest(common.HeatTestCase):
|
|||
stack.converge_stack(template=stack.t, action=stack.CREATE)
|
||||
|
||||
# update stack with new template
|
||||
t2 = template_format.parse(empty_template)
|
||||
template2 = templatem.Template(
|
||||
t2, env=environment.Environment({'KeyName2': 'test2'}))
|
||||
template2 = templatem.Template.create_empty_template(
|
||||
version=stack.t.version)
|
||||
|
||||
curr_stack_db = stack_object.Stack.get_by_id(stack.context, stack.id)
|
||||
curr_stack = parser.Stack.load(curr_stack_db._context,
|
||||
|
|
|
@ -872,6 +872,56 @@ Mappings:
|
|||
|
||||
self.assertEqual(cfn_tpl['Resources'], empty.t['Resources'])
|
||||
|
||||
def test_create_empty_template_default_version(self):
|
||||
empty_template = template.Template.create_empty_template()
|
||||
self.assertEqual(hot_t.HOTemplate20150430, empty_template.__class__)
|
||||
self.assertEqual({}, empty_template['parameter_groups'])
|
||||
self.assertEqual({}, empty_template['resources'])
|
||||
self.assertEqual({}, empty_template['outputs'])
|
||||
|
||||
def test_create_empty_template_returns_correct_version(self):
|
||||
t = template_format.parse('''
|
||||
AWSTemplateFormatVersion: 2010-09-09
|
||||
Parameters:
|
||||
Resources:
|
||||
Outputs:
|
||||
''')
|
||||
aws_tmpl = template.Template(t)
|
||||
empty_template = template.Template.create_empty_template(
|
||||
version=aws_tmpl.version)
|
||||
self.assertEqual(aws_tmpl.__class__, empty_template.__class__)
|
||||
self.assertEqual({}, empty_template['Mappings'])
|
||||
self.assertEqual({}, empty_template['Resources'])
|
||||
self.assertEqual({}, empty_template['Outputs'])
|
||||
|
||||
t = template_format.parse('''
|
||||
HeatTemplateFormatVersion: 2012-12-12
|
||||
Parameters:
|
||||
Resources:
|
||||
Outputs:
|
||||
''')
|
||||
heat_tmpl = template.Template(t)
|
||||
empty_template = template.Template.create_empty_template(
|
||||
version=heat_tmpl.version)
|
||||
self.assertEqual(heat_tmpl.__class__, empty_template.__class__)
|
||||
self.assertEqual({}, empty_template['Mappings'])
|
||||
self.assertEqual({}, empty_template['Resources'])
|
||||
self.assertEqual({}, empty_template['Outputs'])
|
||||
|
||||
t = template_format.parse('''
|
||||
heat_template_version: 2015-04-30
|
||||
parameter_groups:
|
||||
resources:
|
||||
outputs:
|
||||
''')
|
||||
hot_tmpl = template.Template(t)
|
||||
empty_template = template.Template.create_empty_template(
|
||||
version=hot_tmpl.version)
|
||||
self.assertEqual(hot_tmpl.__class__, empty_template.__class__)
|
||||
self.assertEqual({}, empty_template['parameter_groups'])
|
||||
self.assertEqual({}, empty_template['resources'])
|
||||
self.assertEqual({}, empty_template['outputs'])
|
||||
|
||||
|
||||
class TemplateFnErrorTest(common.HeatTestCase):
|
||||
scenarios = [
|
||||
|
|
Loading…
Reference in New Issue