Enable service validate-template for hot template

Get `Resources' and `Description' for hot or cfn template instead of
the raw one.

Change-Id: I54ac8a9905634529b641fe322eee4c10e587bac3
Fixes: bug #1204061
This commit is contained in:
JUN JIE NAN 2013-07-24 13:48:02 +08:00 committed by Gerrit Code Review
parent 91f013a003
commit 28c93efda5
2 changed files with 19 additions and 2 deletions

View File

@ -306,7 +306,7 @@ class EngineService(service.Service):
return webob.exc.HTTPBadRequest(explanation=msg) return webob.exc.HTTPBadRequest(explanation=msg)
tmpl = parser.Template(template) tmpl = parser.Template(template)
tmpl_resources = template.get('Resources', []) tmpl_resources = tmpl.get('Resources', [])
if not tmpl_resources: if not tmpl_resources:
return {'Error': 'At least one Resources member must be defined.'} return {'Error': 'At least one Resources member must be defined.'}
@ -330,7 +330,7 @@ class EngineService(service.Service):
params = tmpl_params.map(format_validate_parameter, is_real_param) params = tmpl_params.map(format_validate_parameter, is_real_param)
result = { result = {
'Description': template.get('Description', ''), 'Description': tmpl.get('Description', ''),
'Parameters': params, 'Parameters': params,
} }
return result return result

View File

@ -531,6 +531,23 @@ class validateTest(HeatTestCase):
res = dict(engine.validate_template(None, t)) res = dict(engine.validate_template(None, t))
self.assertEqual(res['Description'], 'test.') self.assertEqual(res['Description'], 'test.')
def test_validate_hot_valid(self):
t = template_format.parse(
"""
heat_template_version: 2013-05-23
description: test.
resources:
my_instance:
type: AWS::EC2::Instance
""")
self.m.StubOutWithMock(instances.Instance, 'nova')
instances.Instance.nova().AndReturn(self.fc)
self.m.ReplayAll()
engine = service.EngineService('a', 't')
res = dict(engine.validate_template(None, t))
self.assertEqual(res['Description'], 'test.')
def test_validate_ref_invalid(self): def test_validate_ref_invalid(self):
t = template_format.parse(test_template_ref % 'WikiDatabasez') t = template_format.parse(test_template_ref % 'WikiDatabasez')