summaryrefslogtreecommitdiff
path: root/heatclient
diff options
context:
space:
mode:
Diffstat (limited to 'heatclient')
-rw-r--r--heatclient/common/template_format.py23
-rw-r--r--heatclient/tests/test_shell.py2
-rw-r--r--heatclient/tests/test_template_format.py10
-rw-r--r--heatclient/tests/test_template_utils.py16
4 files changed, 26 insertions, 25 deletions
diff --git a/heatclient/common/template_format.py b/heatclient/common/template_format.py
index 0a7432f..2600449 100644
--- a/heatclient/common/template_format.py
+++ b/heatclient/common/template_format.py
@@ -59,22 +59,9 @@ def parse(tmpl_str):
else:
if tpl is None:
tpl = {}
- if u'heat_template_version' not in tpl:
- default_for_missing(tpl, u'HeatTemplateFormatVersion',
- HEAT_VERSIONS)
+ # Looking for supported version keys in the loaded template
+ if not ('HeatTemplateFormatVersion' in tpl
+ or 'heat_template_version' in tpl
+ or 'AWSTemplateFormatVersion' in tpl):
+ raise ValueError("Template format version not found.")
return tpl
-
-
-def default_for_missing(tpl, version_param, versions):
- '''Checks a parsed template for missing version and sections.
-
- This is currently only applied to YAML templates.
- '''
- # if version is missing, implicitly use the lastest one
- if version_param not in tpl:
- tpl[version_param] = versions[-1]
-
- # create empty placeholders for any of the main dict sections
- for param in (u'Parameters', u'Mappings', u'Resources', u'Outputs'):
- if param not in tpl:
- tpl[param] = {}
diff --git a/heatclient/tests/test_shell.py b/heatclient/tests/test_shell.py
index 51864e4..49609ed 100644
--- a/heatclient/tests/test_shell.py
+++ b/heatclient/tests/test_shell.py
@@ -718,7 +718,7 @@ class ShellTestUserPass(ShellBase):
None)
self.m.StubOutWithMock(urlutils, 'urlopen')
urlutils.urlopen('http://no.where/minimal.template').AndReturn(
- six.StringIO('{}'))
+ six.StringIO('{"AWSTemplateFormatVersion" : "2010-09-09"}'))
http.HTTPClient.json_request(
'POST', '/stacks', data=mox.IgnoreArg(),
diff --git a/heatclient/tests/test_template_format.py b/heatclient/tests/test_template_format.py
index 8dd50f9..cc2e605 100644
--- a/heatclient/tests/test_template_format.py
+++ b/heatclient/tests/test_template_format.py
@@ -40,3 +40,13 @@ class YamlParseExceptions(testtools.TestCase):
self.assertRaises(ValueError,
template_format.parse, text)
+
+ def test_parse_no_version_format(self):
+ yaml = ''
+ self.assertRaises(ValueError, template_format.parse, yaml)
+ yaml2 = '''Parameters: {}
+Mappings: {}
+Resources: {}
+Outputs: {}
+'''
+ self.assertRaises(ValueError, template_format.parse, yaml2)
diff --git a/heatclient/tests/test_template_utils.py b/heatclient/tests/test_template_utils.py
index fcd00cc..8d30e8f 100644
--- a/heatclient/tests/test_template_utils.py
+++ b/heatclient/tests/test_template_utils.py
@@ -280,13 +280,15 @@ class TestGetTemplateContents(testtools.TestCase):
def test_get_template_contents_file(self):
with tempfile.NamedTemporaryFile() as tmpl_file:
- tmpl = b'{"foo": "bar"}'
+ tmpl = b'{"AWSTemplateFormatVersion" : "2010-09-09",' \
+ b' "foo": "bar"}'
tmpl_file.write(tmpl)
tmpl_file.flush()
files, tmpl_parsed = template_utils.get_template_contents(
tmpl_file.name)
- self.assertEqual({"foo": "bar"}, tmpl_parsed)
+ self.assertEqual({"AWSTemplateFormatVersion": "2010-09-09",
+ "foo": "bar"}, tmpl_parsed)
self.assertEqual({}, files)
def test_get_template_contents_file_empty(self):
@@ -326,7 +328,7 @@ class TestGetTemplateContents(testtools.TestCase):
'Error parsing template file://%s ' % tmpl_file.name))
def test_get_template_contents_url(self):
- tmpl = '{"foo": "bar"}'
+ tmpl = '{"AWSTemplateFormatVersion" : "2010-09-09", "foo": "bar"}'
url = 'http://no.where/path/to/a.yaml'
self.m.StubOutWithMock(urlutils, 'urlopen')
urlutils.urlopen(url).AndReturn(six.StringIO(tmpl))
@@ -334,11 +336,12 @@ class TestGetTemplateContents(testtools.TestCase):
files, tmpl_parsed = template_utils.get_template_contents(
template_url=url)
- self.assertEqual({"foo": "bar"}, tmpl_parsed)
+ self.assertEqual({"AWSTemplateFormatVersion": "2010-09-09",
+ "foo": "bar"}, tmpl_parsed)
self.assertEqual({}, files)
def test_get_template_contents_object(self):
- tmpl = '{"foo": "bar"}'
+ tmpl = '{"AWSTemplateFormatVersion" : "2010-09-09", "foo": "bar"}'
url = 'http://no.where/path/to/a.yaml'
self.m.ReplayAll()
@@ -354,7 +357,8 @@ class TestGetTemplateContents(testtools.TestCase):
template_object=url,
object_request=object_request)
- self.assertEqual({"foo": "bar"}, tmpl_parsed)
+ self.assertEqual({"AWSTemplateFormatVersion": "2010-09-09",
+ "foo": "bar"}, tmpl_parsed)
self.assertEqual({}, files)
self.assertTrue(self.object_requested)