Merge "Validate template parameter attributes"
This commit is contained in:
commit
6d67fd83c7
@ -267,6 +267,7 @@ def map_remote_error(ex):
|
||||
'InvalidTemplateReference',
|
||||
'UnknownUserParameter',
|
||||
'UserParameterMissing',
|
||||
'InvalidTemplateParameter',
|
||||
)
|
||||
denied_errors = ('Forbidden', 'NotAuthorized')
|
||||
already_exists_errors = ('StackExists')
|
||||
|
@ -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):
|
||||
|
@ -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.")
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user