diff options
author | Sahdev Zala <spzala@us.ibm.com> | 2013-10-12 22:32:45 -0500 |
---|---|---|
committer | Steve Baker <sbaker@redhat.com> | 2014-01-27 16:34:15 +1300 |
commit | 35cfa39fb1f05ea94a2d244d231b2381783795d7 (patch) | |
tree | a49af5bf8ce487a5834dda5541f8c187c8266822 | |
parent | 50dc14af4f78f0d4050f82545aae6910a92aa8cf (diff) | |
download | heat-35cfa39fb1f05ea94a2d244d231b2381783795d7.tar.gz |
Validate template parameter attributes
Validate that template parameter is provided with at least one attribute.
Closes-Bug: #1227061
Change-Id: I5e245556c21a1ea800eb9e0346f3b2414ad56183
-rw-r--r-- | heat/api/aws/exception.py | 1 | ||||
-rw-r--r-- | heat/api/middleware/fault.py | 1 | ||||
-rw-r--r-- | heat/common/exception.py | 4 | ||||
-rw-r--r-- | heat/engine/parameters.py | 13 | ||||
-rw-r--r-- | heat/tests/test_parameters.py | 9 |
5 files changed, 28 insertions, 0 deletions
diff --git a/heat/api/aws/exception.py b/heat/api/aws/exception.py index 1a6fbe31f..c55a8343b 100644 --- a/heat/api/aws/exception.py +++ b/heat/api/aws/exception.py @@ -267,6 +267,7 @@ def map_remote_error(ex): 'InvalidTemplateReference', 'UnknownUserParameter', 'UserParameterMissing', + 'InvalidTemplateParameter', ) denied_errors = ('Forbidden', 'NotAuthorized') already_exists_errors = ('StackExists') diff --git a/heat/api/middleware/fault.py b/heat/api/middleware/fault.py index 466ef92e4..a4778344a 100644 --- a/heat/api/middleware/fault.py +++ b/heat/api/middleware/fault.py @@ -75,6 +75,7 @@ class FaultWrapper(wsgi.Middleware): 'MissingCredentialError': webob.exc.HTTPBadRequest, 'UserParameterMissing': webob.exc.HTTPBadRequest, 'RequestLimitExceeded': webob.exc.HTTPBadRequest, + 'InvalidTemplateParameter': webob.exc.HTTPBadRequest, } def _error(self, ex): diff --git a/heat/common/exception.py b/heat/common/exception.py index 278fb719a..65c3013d5 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -205,6 +205,10 @@ class UnknownUserParameter(HeatException): message = _("The Parameter (%(key)s) was not defined in template.") +class InvalidTemplateParameter(HeatException): + message = _("The Parameter (%(key)s) has no attributes.") + + class InvalidTemplateAttribute(HeatException): message = _("The Referenced Attribute (%(resource)s %(key)s)" " is incorrect.") diff --git a/heat/engine/parameters.py b/heat/engine/parameters.py index 7088cb1f2..6bc8a7cc9 100644 --- a/heat/engine/parameters.py +++ b/heat/engine/parameters.py @@ -355,6 +355,7 @@ class Parameters(collections.Mapping): yield Parameter(name, schema, value, validate_value) self.tmpl = tmpl + self._validate_tmpl_parameters() self._validate(user_params) self.params = dict((p.name, p) for p in parameters()) @@ -393,3 +394,15 @@ class Parameters(collections.Mapping): for param in user_params: if param not in schemata: raise exception.UnknownUserParameter(key=param) + + def _validate_tmpl_parameters(self): + param = None + for key in self.tmpl.t.keys(): + if key == 'Parameters' or key == 'parameters': + param = key + break + if param is not None: + template_params = self.tmpl.t[key] + for name, attrs in template_params.iteritems(): + if not isinstance(attrs, dict): + raise exception.InvalidTemplateParameter(key=name) diff --git a/heat/tests/test_parameters.py b/heat/tests/test_parameters.py index 8f44a28d3..c21d47d7e 100644 --- a/heat/tests/test_parameters.py +++ b/heat/tests/test_parameters.py @@ -469,3 +469,12 @@ class ParametersTest(testtools.TestCase): 'test', params_schema, user_params) + + def test_missing_attribute_params(self): + params = {'Parameters': {'Foo': {'Type': 'String'}, + 'NoAttr': 'No attribute.', + 'Bar': {'Type': 'Number', 'Default': '1'}}} + self.assertRaises(exception.InvalidTemplateParameter, + self.new_parameters, + 'test', + params) |