Add an InvalidTemplateVersion exception

Change-Id: I9dcc9a2d1ee611d0b8d6554c238784ea98a77930
This commit is contained in:
Zane Bitter 2014-02-26 13:28:33 -05:00
parent 4f20c532e3
commit 445e0b9e2f
5 changed files with 11 additions and 8 deletions

View File

@ -276,6 +276,7 @@ def map_remote_error(ex):
'WatchRuleNotFound',
'StackValidationFailed',
'InvalidTemplateReference',
'InvalidTemplateVersion',
'UnknownUserParameter',
'UserParameterMissing',
'InvalidTemplateParameter',

View File

@ -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,

View File

@ -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.")

View File

@ -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

View File

@ -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):
"""