diff --git a/heat/api/aws/exception.py b/heat/api/aws/exception.py index 7f5140875f..bf3a069263 100644 --- a/heat/api/aws/exception.py +++ b/heat/api/aws/exception.py @@ -276,6 +276,7 @@ def map_remote_error(ex): 'WatchRuleNotFound', 'StackValidationFailed', 'InvalidTemplateReference', + 'InvalidTemplateVersion', 'UnknownUserParameter', 'UserParameterMissing', 'InvalidTemplateParameter', diff --git a/heat/api/middleware/fault.py b/heat/api/middleware/fault.py index 06769acfaa..8e4399ebe4 100644 --- a/heat/api/middleware/fault.py +++ b/heat/api/middleware/fault.py @@ -71,6 +71,7 @@ class FaultWrapper(wsgi.Middleware): 'StackExists': webob.exc.HTTPConflict, 'StackValidationFailed': webob.exc.HTTPBadRequest, 'InvalidTemplateReference': webob.exc.HTTPBadRequest, + 'InvalidTemplateVersion': webob.exc.HTTPBadRequest, 'UnknownUserParameter': webob.exc.HTTPBadRequest, 'RevertFailed': webob.exc.HTTPInternalServerError, 'StopActionFailed': webob.exc.HTTPInternalServerError, diff --git a/heat/common/exception.py b/heat/common/exception.py index 5ede75bd8b..d4d463383d 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -192,6 +192,10 @@ class UnknownUserParameter(HeatException): msg_fmt = _("The Parameter (%(key)s) was not defined in template.") +class InvalidTemplateVersion(HeatException): + msg_fmt = _("The template version is invalid: %(explanation)s") + + class InvalidTemplateParameter(HeatException): msg_fmt = _("The Parameter (%(key)s) has no attributes.") diff --git a/heat/engine/hot/template.py b/heat/engine/hot/template.py index a9228d19c2..ceaaaa8eae 100644 --- a/heat/engine/hot/template.py +++ b/heat/engine/hot/template.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +from heat.common import exception from heat.engine import template from heat.engine.cfn import template as cfn_template from heat.engine.hot import parameters @@ -47,11 +48,8 @@ class HOTemplate(template.Template): version = template.get(self.VERSION, '2013-05-23') if version not in self.VERSIONS: - msg = _('"%(version)s" is not a valid ' - 'heat_template_version. Should be one of: ' - '%(valid)s') - raise ValueError(msg % {'version': version, - 'valid': str(self.VERSIONS)}) + msg = _('Should be one of: %s') % str(self.VERSIONS) + raise exception.InvalidTemplateVersion(explanation=msg) super(HOTemplate, self).__init__(template, *args, **kwargs) self.version = self.VERSION, version diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py index 94c8661e93..67f1566f6c 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -310,9 +310,8 @@ class HOTemplateTest(HeatTestCase): tmpl_str = "heat_template_version: this-ain't-valid" hot_tmpl = template_format.parse(tmpl_str) - exc = self.assertRaises(ValueError, template.Template, hot_tmpl) - self.assertIn('"this-ain\'t-valid" is not a valid ' - 'heat_template_version', str(exc)) + self.assertRaises(exception.InvalidTemplateVersion, + template.Template, hot_tmpl) def test_valid_hot_version(self): """