]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Handle YAML parser error as well
authorJianing YANG <jianingy@unitedstack.com>
Tue, 25 Jun 2013 15:55:40 +0000 (23:55 +0800)
committerJianing YANG <jianingy@unitedstack.com>
Tue, 25 Jun 2013 15:55:40 +0000 (23:55 +0800)
Fixes bug: #1185590
Change-Id: Id561e2769d1f0192dd831450f10e05e8213bffa8

heat/common/template_format.py
heat/tests/test_parser.py

index 0cdae3749208797dd30504f970c646a8aa15cad4..ac897e02094af069d8c6201fd05b4c1611d2b470 100644 (file)
@@ -40,7 +40,7 @@ def parse(tmpl_str, add_template_sections=True):
     else:
         try:
             tpl = yaml.safe_load(tmpl_str)
-        except yaml.scanner.ScannerError as e:
+        except (yaml.scanner.ScannerError, yaml.parser.ParserError) as e:
             raise ValueError(e)
         else:
             if tpl is None:
index 13788fe2b5d7198a2fe49d3fb3a650adac196aad..ed008dc72078a1f2eeecc864a995ef3259b633f6 100644 (file)
@@ -135,6 +135,22 @@ class TemplateTest(HeatTestCase):
         self.assertEqual(empty[template.RESOURCES], {})
         self.assertEqual(empty[template.OUTPUTS], {})
 
+    def test_invalid_template(self):
+        scanner_error = '''
+1
+Mappings:
+  ValidMapping:
+    TestKey: TestValue
+'''
+        parser_error = '''
+Mappings:
+  ValidMapping:
+    TestKey: {TestKey1: "Value1" TestKey2: "Value2"}
+'''
+
+        self.assertRaises(ValueError, template_format.parse, scanner_error)
+        self.assertRaises(ValueError, template_format.parse, parser_error)
+
     def test_invalid_section(self):
         tmpl = parser.Template({'Foo': ['Bar']})
         try: