Don't validate parameters when loading a stack

All kinds of Frankentemplates can now be stored in the database. We don't
want to refuse to load them again. Only validate the parameters when we
actually validate the stack.

Change-Id: I8bff116f1a9c16be2bd10a8da685ef9571e1101f
Closes-bug: #1354962
This commit is contained in:
Zane Bitter 2014-08-11 17:26:14 -04:00
parent f1220c3774
commit acf39978ad
3 changed files with 21 additions and 17 deletions

View File

@ -63,7 +63,7 @@ class Stack(collections.Mapping):
disable_rollback=True, parent_resource=None, owner_id=None,
adopt_stack_data=None, stack_user_project_id=None,
created_time=None, updated_time=None,
user_creds_id=None, tenant_id=None, validate_parameters=True,
user_creds_id=None, tenant_id=None,
use_stored_context=False):
'''
Initialise from a context, name, Template object and (optionally)
@ -113,8 +113,6 @@ class Stack(collections.Mapping):
self.env = env or environment.Environment({})
self.parameters = self.t.parameters(self.identifier(),
user_params=self.env.params)
self.parameters.validate(validate_value=validate_parameters,
context=self.context)
self._set_param_stackid()
if resolve_data:
@ -268,7 +266,6 @@ class Stack(collections.Mapping):
created_time=stack.created_at,
updated_time=stack.updated_at,
user_creds_id=stack.user_creds_id, tenant_id=stack.tenant,
validate_parameters=False,
use_stored_context=use_stored_context)
def store(self, backup=False):
@ -423,6 +420,9 @@ class Stack(collections.Mapping):
# validate overall template (top-level structure)
self.t.validate()
# Validate parameters
self.parameters.validate(context=self.context)
# Validate Parameter Groups
parameter_groups = ParameterGroups(self.t)
parameter_groups.validate()

View File

@ -1107,7 +1107,6 @@ class StackTest(HeatTestCase):
updated_time=None,
user_creds_id=stack.user_creds_id,
tenant_id='test_tenant_id',
validate_parameters=False,
use_stored_context=False)
self.m.ReplayAll()
@ -3532,6 +3531,7 @@ class StackTest(HeatTestCase):
template.Template(tmpl),
environment.Environment({'flavor': 'dummy'}))
self.stack.validate()
self.stack.store()
self.stack.create()
stack_id = self.stack.id

View File

@ -1377,16 +1377,18 @@ class validateTest(HeatTestCase):
template = parser.Template(t)
# test with size parameter provided as string
err = self.assertRaises(exception.StackValidationFailed, parser.Stack,
self.ctx, 'test_stack', template,
environment.Environment({'size': '3'}))
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'size': '3'}))
err = self.assertRaises(exception.StackValidationFailed,
stack.validate)
self.assertIn('"3" is not an allowed value [1, 4, 8]',
six.text_type(err))
# test with size parameter provided as number
err = self.assertRaises(exception.StackValidationFailed, parser.Stack,
self.ctx, 'test_stack', template,
environment.Environment({'size': 3}))
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'size': 3}))
err = self.assertRaises(exception.StackValidationFailed,
stack.validate)
self.assertIn('"3" is not an allowed value [1, 4, 8]',
six.text_type(err))
@ -1395,15 +1397,17 @@ class validateTest(HeatTestCase):
template = parser.Template(t)
# test with size parameter provided as string
err = self.assertRaises(exception.StackValidationFailed, parser.Stack,
self.ctx, 'test_stack', template,
environment.Environment({'size': '3'}))
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'size': '3'}))
err = self.assertRaises(exception.StackValidationFailed,
stack.validate)
self.assertIn('"3" is not an allowed value [1, 4, 8]',
six.text_type(err))
# test with size parameter provided as number
err = self.assertRaises(exception.StackValidationFailed, parser.Stack,
self.ctx, 'test_stack', template,
environment.Environment({'size': 3}))
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'size': 3}))
err = self.assertRaises(exception.StackValidationFailed,
stack.validate)
self.assertIn('"3" is not an allowed value [1, 4, 8]',
six.text_type(err))