Make AutoScale sub-template a string instead of map

To avoid the InvalidTemplateReference exception when resolving
get_resource functions for resources that are in the sub-template but
not the parent template.

Change-Id: I985b58ff95efbc7926cec708d2b37d8ce95c3390
This commit is contained in:
Jason Dunsmore 2016-02-18 10:38:38 -06:00
parent 834ac4a041
commit c202c4447b
2 changed files with 75 additions and 73 deletions

View File

@ -18,6 +18,7 @@ import six
from heat.common import exception from heat.common import exception
from heat.common.i18n import _ from heat.common.i18n import _
from heat.common import template_format
from heat.engine import attributes from heat.engine import attributes
from heat.engine import constraints from heat.engine import constraints
from heat.engine import properties from heat.engine import properties
@ -243,7 +244,7 @@ class Group(resource.Resource):
'directly passed to Heat when creating a stack.'), 'directly passed to Heat when creating a stack.'),
schema={ schema={
LAUNCH_CONFIG_ARGS_STACK_TEMPLATE: properties.Schema( LAUNCH_CONFIG_ARGS_STACK_TEMPLATE: properties.Schema(
properties.Schema.MAP, properties.Schema.STRING,
_('The template that describes the stack. Either the ' _('The template that describes the stack. Either the '
'template or template_url property must be specified.'), 'template or template_url property must be specified.'),
), ),
@ -533,7 +534,8 @@ class Group(resource.Resource):
if st_tmpl: if st_tmpl:
st_files = st_args.get(self.LAUNCH_CONFIG_ARGS_STACK_FILES) st_files = st_args.get(self.LAUNCH_CONFIG_ARGS_STACK_FILES)
try: try:
templatem.Template(st_tmpl, files=st_files, env=st_env) tmpl = template_format.simple_parse(st_tmpl)
templatem.Template(tmpl, files=st_files, env=st_env)
except Exception as exc: except Exception as exc:
msg = (_('Encountered error while loading template: %s') % msg = (_('Encountered error while loading template: %s') %
six.text_type(exc)) six.text_type(exc))

View File

@ -232,7 +232,7 @@ class ScalingGroupTest(common.HeatTestCase):
type: launch_stack type: launch_stack
args: args:
stack: stack:
template: template: |
heat_template_version: 2015-10-15 heat_template_version: 2015-10-15
description: This is a Heat template description: This is a Heat template
parameters: parameters:
@ -336,20 +336,20 @@ class ScalingGroupTest(common.HeatTestCase):
'group_metadata': {'group': 'metadata'}, 'group_metadata': {'group': 'metadata'},
'name': 'My Group', 'name': 'My Group',
'launch_config_type': u'launch_stack', 'launch_config_type': u'launch_stack',
'template': { 'template': (
'heat_template_version': '2015-10-15', '''heat_template_version: 2015-10-15
'description': 'This is a Heat template', description: This is a Heat template
'parameters': { parameters:
'flavor': { image:
'default': 'm1.tiny', default: cirros-0.3.4-x86_64-uec
'type': 'string'}, type: string
'image': { flavor:
'default': 'cirros-0.3.4-x86_64-uec', default: m1.tiny
'type': 'string'}}, type: string
'resources': { resources:
'rand': {'type': u'OS::Heat::RandomString'} rand:
} type: OS::Heat::RandomString
}, '''),
'template_url': None, 'template_url': None,
'disable_rollback': False, 'disable_rollback': False,
'environment': { 'environment': {
@ -931,20 +931,20 @@ class AutoScaleGroupValidationTests(common.HeatTestCase):
"type": "launch_stack", "type": "launch_stack",
"args": { "args": {
"stack": { "stack": {
'template': { 'template': (
'heat_template_version': '2015-10-15', '''heat_template_version: 2015-10-15
'description': 'This is a Heat template', description: This is a Heat template
'parameters': { parameters:
'flavor': { image:
'default': 'm1.tiny', default: cirros-0.3.4-x86_64-uec
'type': 'string'}, type: string
'image': { flavor:
'default': 'cirros-0.3.4-x86_64-uec', default: m1.tiny
'type': 'string'}}, type: string
'resources': { resources:
'rand': {'type': u'OS::Heat::RandomString'} rand:
} type: OS::Heat::RandomString
}, '''),
'template_url': None, 'template_url': None,
'disable_rollback': False, 'disable_rollback': False,
'environment': { 'environment': {
@ -995,20 +995,20 @@ class AutoScaleGroupValidationTests(common.HeatTestCase):
"imageRef": "image-ref", "imageRef": "image-ref",
}, },
"stack": { "stack": {
'template': { 'template': (
'heat_template_version': '2015-10-15', '''heat_template_version: 2015-10-15
'description': 'This is a Heat template', description: This is a Heat template
'parameters': { parameters:
'flavor': { image:
'default': 'm1.tiny', default: cirros-0.3.4-x86_64-uec
'type': 'string'}, type: string
'image': { flavor:
'default': 'cirros-0.3.4-x86_64-uec', default: m1.tiny
'type': 'string'}}, type: string
'resources': { resources:
'rand': {'type': u'OS::Heat::RandomString'} rand:
} type: OS::Heat::RandomString
}, '''),
'template_url': None, 'template_url': None,
'disable_rollback': False, 'disable_rollback': False,
'environment': { 'environment': {
@ -1086,20 +1086,20 @@ class AutoScaleGroupValidationTests(common.HeatTestCase):
"type": "launch_server", "type": "launch_server",
"args": { "args": {
"stack": { "stack": {
'template': { 'template': (
'heat_template_version': '2015-10-15', '''heat_template_version: 2015-10-15
'description': 'This is a Heat template', description: This is a Heat template
'parameters': { parameters:
'flavor': { image:
'default': 'm1.tiny', default: cirros-0.3.4-x86_64-uec
'type': 'string'}, type: string
'image': { flavor:
'default': 'cirros-0.3.4-x86_64-uec', default: m1.tiny
'type': 'string'}}, type: string
'resources': { resources:
'rand': {'type': 'OS::Heat::RandomString'} rand:
} type: OS::Heat::RandomString
}, '''),
'template_url': 'https://myhost.com/template.yaml', 'template_url': 'https://myhost.com/template.yaml',
} }
} }
@ -1179,20 +1179,20 @@ class AutoScaleGroupValidationTests(common.HeatTestCase):
"type": "launch_stack", "type": "launch_stack",
"args": { "args": {
"stack": { "stack": {
'template': { 'template': (
'SJDADKJAJKLSheat_template_version': '2015-10-15', '''SJDADKJAJKLSheat_template_version: 2015-10-15
'description': 'This is a Heat template', description: This is a Heat template
'parameters': { parameters:
'flavor': { image:
'default': 'm1.tiny', default: cirros-0.3.4-x86_64-uec
'type': 'string'}, type: string
'image': { flavor:
'default': 'cirros-0.3.4-x86_64-uec', default: m1.tiny
'type': 'string'}}, type: string
'resources': { resources:
'rand': {'type': u'OS::Heat::RandomString'} rand:
} type: OS::Heat::RandomString
}, '''),
'template_url': None, 'template_url': None,
'disable_rollback': False, 'disable_rollback': False,
'environment': {'Foo': 'Bar'}, 'environment': {'Foo': 'Bar'},