1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2024-10-06 19:01:15 +01:00

core: changing the time of constraint validation for params

Constraints and allowed values of Extension Parameters will now be check
when the Parameter value is set, rather than when validating the
extension. Mandatory status of a Parameter is still checked during
valudation.
This commit is contained in:
Sergei Trofimov 2016-09-13 10:20:52 +01:00
parent 3711f7316d
commit 20996e9a58

View File

@ -224,18 +224,11 @@ class Param(object):
else:
new_value = current_value + [value]
setattr(obj, self.name, new_value)
def validate(self, obj):
value = getattr(obj, self.name, None)
if value is not None:
if self.allowed_values:
self._validate_allowed_values(obj, value)
if self.constraint:
self._validate_constraint(obj, value)
else:
if self.mandatory:
msg = 'No value specified for mandatory parameter {} in {}.'
raise ConfigError(msg.format(self.name, obj.name))
def get_type_name(self):
typename = str(self.kind)
@ -567,7 +560,9 @@ class Extension(object):
if self.name is None:
raise ValidationError('Name not set for {}'.format(self._classname))
for param in self.parameters:
param.validate(self)
if param.mandatory and getattr(self, param.name, None) is None:
msg = 'No value specified for mandatory parameter {} in {}.'
raise ConfigError(msg.format(param.name, self.name))
def initialize(self, context):
pass