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.config import Config
|
||||||
from tiramisu.setting import groups, owners
|
from tiramisu.setting import groups, owners
|
||||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||||
StrOption, OptionDescription, SymLinkOption
|
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption
|
||||||
from tiramisu.error import PropertiesOptionError, ConflictError, SlaveError, ConfigError
|
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)) == []
|
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():
|
def test_callback_master_and_slaves_master_list():
|
||||||
val1 = StrOption('val1', "", multi=True, callback=return_list)
|
val1 = StrOption('val1', "", multi=True, callback=return_list)
|
||||||
val2 = StrOption('val2', "", multi=True)
|
val2 = StrOption('val2', "", multi=True)
|
||||||
|
|
|
@ -387,6 +387,7 @@ class Option(OnlyOption):
|
||||||
descr = context.cfgimpl_get_description()
|
descr = context.cfgimpl_get_description()
|
||||||
|
|
||||||
all_cons_vals = []
|
all_cons_vals = []
|
||||||
|
val_consistencies = True
|
||||||
for opt in all_cons_opts:
|
for opt in all_cons_opts:
|
||||||
#get value
|
#get value
|
||||||
if (isinstance(opt, DynSymLinkOption) and option._dyn == opt._dyn) or \
|
if (isinstance(opt, DynSymLinkOption) and option._dyn == opt._dyn) or \
|
||||||
|
@ -406,11 +407,11 @@ class Option(OnlyOption):
|
||||||
if isinstance(opt_value, PropertiesOptionError):
|
if isinstance(opt_value, PropertiesOptionError):
|
||||||
log.debug('propertyerror in _launch_consistency: {0}'.format(opt_value))
|
log.debug('propertyerror in _launch_consistency: {0}'.format(opt_value))
|
||||||
if transitive:
|
if transitive:
|
||||||
raise opt_value
|
return opt_value
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
raise opt_value
|
return opt_value
|
||||||
else:
|
else:
|
||||||
opt_value = opt.impl_getdefault()
|
opt_value = opt.impl_getdefault()
|
||||||
|
|
||||||
|
@ -419,12 +420,14 @@ class Option(OnlyOption):
|
||||||
and option._dyn == opt._dyn) or \
|
and option._dyn == opt._dyn) or \
|
||||||
option == opt:
|
option == opt:
|
||||||
all_cons_vals.append(opt_value)
|
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:
|
else:
|
||||||
all_cons_vals.append(opt_value[index])
|
if index is not None:
|
||||||
return getattr(self, func)(all_cons_opts, all_cons_vals, warnings_only)
|
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,
|
def impl_validate(self, value, context=undefined, validate=True,
|
||||||
force_index=None, force_submulti_index=None,
|
force_index=None, force_submulti_index=None,
|
||||||
|
@ -502,6 +505,8 @@ class Option(OnlyOption):
|
||||||
warning = ret
|
warning = ret
|
||||||
elif isinstance(ret, ValueError):
|
elif isinstance(ret, ValueError):
|
||||||
error = ret
|
error = ret
|
||||||
|
else:
|
||||||
|
return ret
|
||||||
if warning:
|
if warning:
|
||||||
msg = _("warning on the value of the option {0}: {1}").format(
|
msg = _("warning on the value of the option {0}: {1}").format(
|
||||||
self.impl_getname(), warning)
|
self.impl_getname(), warning)
|
||||||
|
@ -554,6 +559,9 @@ class Option(OnlyOption):
|
||||||
err = do_validation(val, idx, force_submulti_index)
|
err = do_validation(val, idx, force_submulti_index)
|
||||||
if err:
|
if err:
|
||||||
return err
|
return err
|
||||||
|
else:
|
||||||
|
return self._valid_consistency(current_opt, None, context,
|
||||||
|
None, None)
|
||||||
|
|
||||||
def impl_is_master_slaves(self, type_='both'):
|
def impl_is_master_slaves(self, type_='both'):
|
||||||
"""FIXME
|
"""FIXME
|
||||||
|
|
Loading…
Reference in New Issue