refactor validation
This commit is contained in:
@ -135,6 +135,9 @@ class Base(StorageBase):
|
||||
list(set_forbidden_properties)))
|
||||
StorageBase.__init__(self, name, _multi, warnings_only, doc, extra,
|
||||
calc_properties, requires, properties)
|
||||
if multi is not False and default is None:
|
||||
default = []
|
||||
self.impl_validate(default)
|
||||
self._set_default_values(default, default_multi)
|
||||
if callback is not False:
|
||||
self.impl_set_callback(callback, callback_params)
|
||||
@ -507,7 +510,7 @@ class Option(OnlyOption):
|
||||
if current_opt is undefined:
|
||||
current_opt = self
|
||||
|
||||
def val_validator(val):
|
||||
def calculation_validator(val):
|
||||
validator, validator_params = self.impl_get_validator()
|
||||
if validator is not None:
|
||||
if validator_params != {}:
|
||||
@ -524,7 +527,7 @@ class Option(OnlyOption):
|
||||
else:
|
||||
validator_params_ = {'': (val,)}
|
||||
# Raise ValueError if not valid
|
||||
carry_out_calculation(self, config=context,
|
||||
carry_out_calculation(self, context=context,
|
||||
callback=validator,
|
||||
callback_params=validator_params_)
|
||||
|
||||
@ -545,7 +548,7 @@ class Option(OnlyOption):
|
||||
warning = None
|
||||
try:
|
||||
# valid with self._validator
|
||||
val_validator(_value)
|
||||
calculation_validator(_value)
|
||||
# if not context launch consistency validation
|
||||
if context is not undefined:
|
||||
descr._valid_consistency(current_opt, _value, context,
|
||||
@ -721,6 +724,7 @@ class Option(OnlyOption):
|
||||
None, all_cons_opts, warnings_only,
|
||||
transitive)
|
||||
self._add_consistency(func, all_cons_opts, params)
|
||||
#re validate default value when add consistency
|
||||
self.impl_validate(self.impl_getdefault())
|
||||
|
||||
def _cons_not_equal(self, opts, vals, warnings_only):
|
||||
|
@ -208,7 +208,8 @@ class MasterSlaves(object):
|
||||
index=index,
|
||||
setting_properties=setting_properties),
|
||||
setitem=False,
|
||||
force=True)
|
||||
force=True,
|
||||
validate=validate)
|
||||
if validate_properties:
|
||||
context.cfgimpl_get_settings().validate_properties(opt, False,
|
||||
False,
|
||||
|
@ -74,7 +74,7 @@ class ChoiceOption(Option):
|
||||
values_params = self._choice_values_params
|
||||
if values_params is None:
|
||||
values_params = {}
|
||||
values = carry_out_calculation(self, config=context,
|
||||
values = carry_out_calculation(self, context=context,
|
||||
callback=values,
|
||||
callback_params=values_params)
|
||||
if not isinstance(values, list): # pragma: optional cover
|
||||
@ -290,7 +290,7 @@ class PortOption(Option):
|
||||
except ValueError: # pragma: optional cover
|
||||
raise ValueError(_('invalid port'))
|
||||
if not self._get_extra('_min_value') <= val <= self._get_extra('_max_value'): # pragma: optional cover
|
||||
raise ValueError(_('invalid port, must be an between {0} '
|
||||
raise ValueError(_('invalid port, must be an integer between {0} '
|
||||
'and {1}').format(self._get_extra('_min_value'),
|
||||
self._get_extra('_max_value')))
|
||||
|
||||
|
@ -139,7 +139,7 @@ class OptionDescription(BaseOption, StorageOptionDescription):
|
||||
option.impl_validate_options(cache_option)
|
||||
if init:
|
||||
if len(cache_option) != len(set(cache_option)):
|
||||
for idx in xrange(1, len(cache_option)+1):
|
||||
for idx in xrange(1, len(cache_option) + 1):
|
||||
opt = cache_option.pop(0)
|
||||
if opt in cache_option:
|
||||
raise ConflictError(_('duplicate option: {0}').format(opt))
|
||||
@ -255,7 +255,7 @@ class OptionDescription(BaseOption, StorageOptionDescription):
|
||||
|
||||
def _impl_get_suffixes(self, context):
|
||||
callback, callback_params = self.impl_get_callback()
|
||||
values = carry_out_calculation(self, config=context,
|
||||
values = carry_out_calculation(self, context=context,
|
||||
callback=callback,
|
||||
callback_params=callback_params)
|
||||
if len(values) > len(set(values)):
|
||||
|
Reference in New Issue
Block a user