valid correctly consistencies for master/slaves
This commit is contained in:
parent
5a5231c2d8
commit
924692d3ab
|
@ -6,7 +6,7 @@ from py.test import raises
|
|||
from tiramisu.config import Config
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption
|
||||
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption
|
||||
from tiramisu.error import PropertiesOptionError, ConflictError, SlaveError, ConfigError
|
||||
|
||||
|
||||
|
@ -480,6 +480,46 @@ def test_callback_master_and_slaves_master4():
|
|||
assert list(cfg.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == []
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_master_mandatory_transitive():
|
||||
#default value
|
||||
val1 = IPOption('val1', "", ['192.168.0.1'], multi=True, properties=('mandatory',))
|
||||
val2 = NetmaskOption('val2', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
|
||||
val2.impl_add_consistency('ip_netmask', val1)
|
||||
#no value
|
||||
val3 = IPOption('val3', "", multi=True, properties=('mandatory',))
|
||||
val4 = NetmaskOption('val4', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
|
||||
val4.impl_add_consistency('ip_netmask', val3)
|
||||
interface1 = OptionDescription('val1', '', [val1, val2])
|
||||
interface2 = OptionDescription('val3', '', [val3, val4])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
interface2.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
raises(PropertiesOptionError, "cfg.val1.val1")
|
||||
raises(PropertiesOptionError, "cfg.val3.val3")
|
||||
assert list(cfg.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == []
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_master_mandatory_non_transitive():
|
||||
#no value
|
||||
val1 = IPOption('val1', "", multi=True, properties=('mandatory',))
|
||||
val2 = NetmaskOption('val2', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
|
||||
val2.impl_add_consistency('ip_netmask', val1, transitive=False)
|
||||
#default value
|
||||
val3 = IPOption('val3', "", ['192.168.0.1'], multi=True, properties=('mandatory',))
|
||||
val4 = NetmaskOption('val4', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
|
||||
val4.impl_add_consistency('ip_netmask', val3, transitive=False)
|
||||
interface1 = OptionDescription('val1', '', [val1, val2])
|
||||
interface2 = OptionDescription('val3', '', [val3, val4])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
interface2.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
assert list(cfg.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == ["val1.val1"]
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_master_list():
|
||||
val1 = StrOption('val1', "", multi=True, callback=return_list)
|
||||
val2 = StrOption('val2', "", multi=True)
|
||||
|
|
|
@ -387,6 +387,7 @@ class Option(OnlyOption):
|
|||
descr = context.cfgimpl_get_description()
|
||||
|
||||
all_cons_vals = []
|
||||
val_consistencies = True
|
||||
for opt in all_cons_opts:
|
||||
#get value
|
||||
if (isinstance(opt, DynSymLinkOption) and option._dyn == opt._dyn) or \
|
||||
|
@ -406,11 +407,11 @@ class Option(OnlyOption):
|
|||
if isinstance(opt_value, PropertiesOptionError):
|
||||
log.debug('propertyerror in _launch_consistency: {0}'.format(opt_value))
|
||||
if transitive:
|
||||
raise opt_value
|
||||
return opt_value
|
||||
else:
|
||||
return
|
||||
else:
|
||||
raise opt_value
|
||||
return opt_value
|
||||
else:
|
||||
opt_value = opt.impl_getdefault()
|
||||
|
||||
|
@ -419,11 +420,13 @@ class Option(OnlyOption):
|
|||
and option._dyn == opt._dyn) or \
|
||||
option == opt:
|
||||
all_cons_vals.append(opt_value)
|
||||
#consistency with submulti is now forbidden
|
||||
#elif self.impl_is_submulti():
|
||||
# all_cons_vals.append(opt_value[index][submulti_index])
|
||||
else:
|
||||
if index is not None:
|
||||
all_cons_vals.append(opt_value[index])
|
||||
else:
|
||||
#only check properties for slaves
|
||||
val_consistencies = False
|
||||
if val_consistencies:
|
||||
return getattr(self, func)(all_cons_opts, all_cons_vals, warnings_only)
|
||||
|
||||
def impl_validate(self, value, context=undefined, validate=True,
|
||||
|
@ -502,6 +505,8 @@ class Option(OnlyOption):
|
|||
warning = ret
|
||||
elif isinstance(ret, ValueError):
|
||||
error = ret
|
||||
else:
|
||||
return ret
|
||||
if warning:
|
||||
msg = _("warning on the value of the option {0}: {1}").format(
|
||||
self.impl_getname(), warning)
|
||||
|
@ -554,6 +559,9 @@ class Option(OnlyOption):
|
|||
err = do_validation(val, idx, force_submulti_index)
|
||||
if err:
|
||||
return err
|
||||
else:
|
||||
return self._valid_consistency(current_opt, None, context,
|
||||
None, None)
|
||||
|
||||
def impl_is_master_slaves(self, type_='both'):
|
||||
"""FIXME
|
||||
|
|
Loading…
Reference in New Issue