better hidden/display support

This commit is contained in:
Emmanuel Garette 2019-07-04 20:43:47 +02:00
parent 83f05197fb
commit fb1286e50e
14 changed files with 1489 additions and 1195 deletions

View File

@ -370,7 +370,6 @@ def test_callback_value_tuple(config_type):
def test_callback_value_force_permissive2(config_type): def test_callback_value_force_permissive2(config_type):
config_type = 'tiramisu-api'
val1 = StrOption('val1', "", 'val', properties=('disabled',)) val1 = StrOption('val1', "", 'val', properties=('disabled',))
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val1, True))) val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val1, True)))
@ -578,7 +577,7 @@ def test_callback_leader_and_followers_leader2(config_type):
assert cfg.option('val1.val2', 0).value.get() == 'val2' assert cfg.option('val1.val2', 0).value.get() == 'val2'
def test_callback_leader_and_followers_leader_mandatory(config_type): def test_callback_leader_and_followers_leader_mandatory1(config_type):
val = StrOption('val', "", default='val') val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',)) val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',))
val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',)) val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
@ -591,9 +590,13 @@ def test_callback_leader_and_followers_leader_mandatory(config_type):
assert cfg.option('val1.val3', 0).value.get() == 'val' assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val4', 0).value.get() == 'val' assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val1').value.get() == ['val'] assert cfg.option('val1.val1').value.get() == ['val']
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_write() cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type) cfg = get_config(cfg_ori, config_type)
cfg.option('val1.val1').value.set([undefined, 'val3']) cfg.option('val1.val1').value.set([undefined, 'val3'])
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_only() cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type) cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val1').value.get() == ['val', 'val3'] assert cfg.option('val1.val1').value.get() == ['val', 'val3']

View File

@ -162,7 +162,6 @@ def test_consistency_not_equal(config_type):
def test_consistency_not_equal_many_opts(config_type): def test_consistency_not_equal_many_opts(config_type):
config_type='tiramisu-api'
a = IntOption('a', '') a = IntOption('a', '')
b = IntOption('b', '') b = IntOption('b', '')
c = IntOption('c', '') c = IntOption('c', '')
@ -584,7 +583,6 @@ def test_consistency_ip_netmask_invalid():
def test_consistency_network_netmask(config_type): def test_consistency_network_netmask(config_type):
config_type = 'tiramisu-api'
a = NetworkOption('a', '') a = NetworkOption('a', '')
b = NetmaskOption('b', '') b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])

View File

@ -2,6 +2,7 @@
"frozen and hidden values" "frozen and hidden values"
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from py.test import raises from py.test import raises
@ -45,95 +46,122 @@ def make_description():
# ____________________________________________________________ # ____________________________________________________________
def test_is_hidden(): def test_is_hidden(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert not 'frozen' in api.forcepermissive.option('gc.dummy').property.get() assert not 'frozen' in cfg.forcepermissive.option('gc.dummy').property.get()
cfg = get_config(cfg, config_type)
# setattr # setattr
raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False") raises(PropertiesOptionError, "cfg.option('gc.dummy').value.get() == False")
# getattr # getattr
raises(PropertiesOptionError, "api.option('gc.dummy').value.get()") raises(PropertiesOptionError, "cfg.option('gc.dummy').value.get()")
def test_group_is_hidden(): def test_group_is_hidden(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
api.option('gc').property.add('hidden') cfg_ori.option('gc').property.add('hidden')
raises(PropertiesOptionError, "api.option('gc.dummy').value.get()") cfg = get_config(cfg_ori, config_type)
assert 'hidden' in api.forcepermissive.option('gc').property.get() raises(PropertiesOptionError, "cfg.option('gc.dummy').value.get()")
raises(PropertiesOptionError, "api.option('gc.float').value.get()") if config_type == 'tiramisu-api':
cfg.send()
assert 'hidden' in cfg_ori.forcepermissive.option('gc').property.get()
cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('gc.float').value.get()")
# manually set the subconfigs to "show" # manually set the subconfigs to "show"
api.forcepermissive.option('gc').property.pop('hidden') if config_type == 'tiramisu-api':
assert not 'hidden' in api.option('gc').property.get() cfg.send()
assert api.option('gc.float').value.get() == 2.3 cfg_ori.forcepermissive.option('gc').property.pop('hidden')
cfg = get_config(cfg_ori, config_type)
assert not 'hidden' in cfg.option('gc').property.get()
assert cfg.option('gc.float').value.get() == 2.3
#dummy est en hide #dummy est en hide
prop = [] prop = []
try: try:
api.option('gc.dummy').value.set(False) cfg.option('gc.dummy').value.set(False)
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
if config_type == 'tiramisu-api':
assert 'disabled' in prop
else:
assert 'hidden' in prop assert 'hidden' in prop
def test_group_is_hidden_multi(): def test_group_is_hidden_multi(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
api.option('objspace').property.add('hidden') cfg_ori.option('objspace').property.add('hidden')
raises(PropertiesOptionError, "api.option('objspace').value.get()") cfg = get_config(cfg_ori, config_type)
assert 'hidden' in api.forcepermissive.option('objspace').property.get() raises(PropertiesOptionError, "cfg.option('objspace').value.get()")
if config_type == 'tiramisu-api':
cfg.send()
assert 'hidden' in cfg_ori.forcepermissive.option('objspace').property.get()
cfg = get_config(cfg_ori, config_type)
prop = [] prop = []
try: try:
api.option('objspace').value.set(['std']) cfg.option('objspace').value.set(['std'])
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
if config_type == 'tiramisu-api':
assert 'disabled' in prop
else:
assert 'hidden' in prop assert 'hidden' in prop
api.forcepermissive.option('objspace').property.pop('hidden') if config_type == 'tiramisu-api':
assert not 'hidden' in api.option('objspace').property.get() cfg.send()
api.option('objspace').value.set(['std', 'std']) cfg_ori.forcepermissive.option('objspace').property.pop('hidden')
cfg = get_config(cfg_ori, config_type)
assert not 'hidden' in cfg.option('objspace').property.get()
cfg.option('objspace').value.set(['std', 'std'])
def test_global_show(): def test_global_show(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.forcepermissive.option('gc.dummy').property.add('hidden') cfg.forcepermissive.option('gc.dummy').property.add('hidden')
assert 'hidden' in api.forcepermissive.option('gc.dummy').property.get() assert 'hidden' in cfg.forcepermissive.option('gc.dummy').property.get()
raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False") cfg = get_config(cfg, config_type)
raises(PropertiesOptionError, "cfg.option('gc.dummy').value.get() == False")
def test_with_many_subgroups(): def test_with_many_subgroups(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg_ori = Config(descr)
#booltwo = config.unwrap_from_path('gc.subgroup.booltwo') #booltwo = config.unwrap_from_path('gc.subgroup.booltwo')
#setting = config.cfgimpl_get_settings() #setting = config.cfgimpl_get_settings()
assert not 'hidden' in api.option('gc.subgroup.booltwo').property.get() cfg = get_config(cfg_ori, config_type)
assert api.option('gc.subgroup.booltwo').value.get() is False assert not 'hidden' in cfg.option('gc.subgroup.booltwo').property.get()
api.option('gc.subgroup.booltwo').property.add('hidden') assert cfg.option('gc.subgroup.booltwo').value.get() is False
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('gc.subgroup.booltwo').property.add('hidden')
def test_password_option(): def test_password_option(config_type):
o = PasswordOption('o', '') o = PasswordOption('o', '')
d = OptionDescription('d', '', [o]) d = OptionDescription('d', '', [o])
api = Config(d) cfg = Config(d)
cfg = get_config(cfg, config_type)
api.option('o').value.set('a_valid_password') cfg.option('o').value.set('a_valid_password')
raises(ValueError, "api.option('o').value.set(1)") raises(ValueError, "cfg.option('o').value.set(1)")
def test_date_option(): def test_date_option(config_type):
o = DateOption('o', '') o = DateOption('o', '')
d = OptionDescription('d', '', [o]) d = OptionDescription('d', '', [o])
api = Config(d) cfg = Config(d)
cfg = get_config(cfg, config_type)
api.option('o').value.set('2017-02-04') cfg.option('o').value.set('2017-02-04')
api.option('o').value.set('2017-2-4') cfg.option('o').value.set('2017-2-4')
raises(ValueError, "api.option('o').value.set(1)") raises(ValueError, "cfg.option('o').value.set(1)")
raises(ValueError, "api.option('o').value.set('2017-13-20')") raises(ValueError, "cfg.option('o').value.set('2017-13-20')")
raises(ValueError, "api.option('o').value.set('2017-11-31')") raises(ValueError, "cfg.option('o').value.set('2017-11-31')")
raises(ValueError, "api.option('o').value.set('2017-12-32')") raises(ValueError, "cfg.option('o').value.set('2017-12-32')")
raises(ValueError, "api.option('o').value.set('2017-2-29')") raises(ValueError, "cfg.option('o').value.set('2017-2-29')")
raises(ValueError, "api.option('o').value.set('2-2-2017')") raises(ValueError, "cfg.option('o').value.set('2-2-2017')")
raises(ValueError, "api.option('o').value.set('2017/2/2')") raises(ValueError, "cfg.option('o').value.set('2017/2/2')")

View File

@ -1,5 +1,6 @@
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
import warnings import warnings
from py.test import raises from py.test import raises
@ -39,9 +40,9 @@ def return_if_val(value):
def is_context(value, context): def is_context(value, context):
api = Config(context) cfg = Config(context)
api.property.pop('validator') cfg.property.pop('validator')
if not isinstance(api, Config): if not isinstance(cfg, Config):
raise ValueError('not context') raise ValueError('not context')
@ -96,114 +97,130 @@ def value_empty(value, empty, values):
def valid_from_config(value, config): def valid_from_config(value, config):
api = Config(config) cfg = Config(config)
if api.option('opt1').value.get() != u'yes': if cfg.option('opt1').value.get() != u'yes':
raise ValueError("c'est une erreur") raise ValueError("c'est une erreur")
def test_validator(): def test_validator(config_type):
opt1 = StrOption('opt1', '', validator=return_true, default='val') opt1 = StrOption('opt1', '', validator=return_true, default='val')
raises(ValueError, "StrOption('opt2', '', validator=return_false, default='val')") raises(ValueError, "StrOption('opt2', '', validator=return_false, default='val')")
opt2 = StrOption('opt2', '', validator=return_false) opt2 = StrOption('opt2', '', validator=return_false)
root = OptionDescription('root', '', [opt1, opt2]) root = OptionDescription('root', '', [opt1, opt2])
api = Config(root) cfg_ori = Config(root)
assert api.option('opt1').value.get() == 'val' cfg = get_config(cfg_ori, config_type)
raises(ValueError, "api.option('opt2').value.set('val')") assert cfg.option('opt1').value.get() == 'val'
raises(ValueError, "cfg.option('opt2').value.set('val')")
try: try:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
except ValueError as err: except ValueError as err:
msg = _('"{0}" is an invalid {1} for "{2}"').format('val', _('string'), 'opt2') + ', ' + _('test error return_false') msg = _('"{0}" is an invalid {1} for "{2}"').format('val', _('string'), 'opt2') + ', ' + _('test error return_false')
assert str(err) == msg assert str(err) == msg
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
msg = _('"{0}" is an invalid {1} for "{2}"').format('val', 'string', 'opt2') + ', ' + _('test error return_false')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
assert len(w) == 1 assert len(w) == 1
assert str(w[0].message) == msg assert str(w[0].message) == msg
def test_validator_params(): def test_validator_params(config_type):
opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamValue('yes')), default='val') opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamValue('yes')), default='val')
raises(ValueError, "StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes')), default='val')") raises(ValueError, "StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes')), default='val')")
opt2 = StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes'))) opt2 = StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes')))
root = OptionDescription('root', '', [opt1, opt2]) root = OptionDescription('root', '', [opt1, opt2])
api = Config(root) cfg_ori = Config(root)
assert api.option('opt1').value.get() == 'val' cfg = get_config(cfg_ori, config_type)
raises(ValueError, "api.option('opt2').value.set('val')") assert cfg.option('opt1').value.get() == 'val'
api.property.add('demoting_error_warning') raises(ValueError, "cfg.option('opt2').value.set('val')")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
assert len(w) == 1 assert len(w) == 1
def test_validator_params_value_values(): def test_validator_params_value_values(config_type):
opt1 = StrOption('opt1', '', validator=value_values, default=['val'], multi=True) opt1 = StrOption('opt1', '', validator=value_values, default=['val'], multi=True)
root = OptionDescription('root', '', [opt1]) root = OptionDescription('root', '', [opt1])
api = Config(root) cfg = Config(root)
assert api.option('opt1').value.get() == ['val'] cfg = get_config(cfg, config_type)
api.option('opt1').value.set(['val1', 'val2']) assert cfg.option('opt1').value.get() == ['val']
cfg.option('opt1').value.set(['val1', 'val2'])
def test_validator_params_value_values_index(): def test_validator_params_value_values_index(config_type):
opt1 = StrOption('opt1', '', validator=value_values_index, default=['val'], multi=True) opt1 = StrOption('opt1', '', validator=value_values_index, default=['val'], multi=True)
root = OptionDescription('root', '', [opt1]) root = OptionDescription('root', '', [opt1])
api = Config(root) cfg = Config(root)
assert api.option('opt1').value.get() == ['val'] cfg = get_config(cfg, config_type)
api.option('opt1').value.set(['val1', 'val2']) assert cfg.option('opt1').value.get() == ['val']
cfg.option('opt1').value.set(['val1', 'val2'])
def test_validator_params_value_values_leader(): def test_validator_params_value_values_leader(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
def test_validator_params_value_values_index_leader(): def test_validator_params_value_values_index_leader(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values_index) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values_index)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
def test_validator_params_value_values_follower(): def test_validator_params_value_values_follower(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
def test_validator_params_value_values_index_follower(): def test_validator_params_value_values_index_follower(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values_index) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values_index)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
def test_validator_params_value_values_notmulti(): def test_validator_params_value_values_notmulti():
raises(ConfigError, "opt1 = StrOption('opt1', '', validator=value_values, default='val')") raises(ConfigError, "opt1 = StrOption('opt1', '', validator=value_values, default='val')")
def test_validator_params_value_values_kwargs_empty(): def test_validator_params_value_values_kwargs_empty(config_type):
v = BoolOption('v', '', default=False) v = BoolOption('v', '', default=False)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, default=["ip"]) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, default=["ip"])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
@ -213,14 +230,15 @@ def test_validator_params_value_values_kwargs_empty():
validator_params=Params(ParamOption(v))) validator_params=Params(ParamOption(v)))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [v, interface1]) root = OptionDescription('root', '', [v, interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val'])
#cfg.ip_admin_eth0.ip_admin_eth0.append('val') #cfg.ip_admin_eth0.ip_admin_eth0.append('val')
#cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2' #cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2'
def test_validator_params_value_values_kwargs(): def test_validator_params_value_values_kwargs(config_type):
v = BoolOption('v', '', default=False) v = BoolOption('v', '', default=False)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, default=["ip"]) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, default=["ip"])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
@ -230,14 +248,15 @@ def test_validator_params_value_values_kwargs():
validator_params=Params(kwargs={'auto': ParamOption(v)})) validator_params=Params(kwargs={'auto': ParamOption(v)}))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [v, interface1]) root = OptionDescription('root', '', [v, interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
def test_validator_params_value_values_kwargs_values(): def test_validator_params_value_values_kwargs_values(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
"masque du sous-reseau", "masque du sous-reseau",
@ -246,15 +265,16 @@ def test_validator_params_value_values_kwargs_values():
validator_params=Params(kwargs={'values': ParamOption(ip_admin_eth0)})) validator_params=Params(kwargs={'values': ParamOption(ip_admin_eth0)}))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
def test_validator_params_value_values_kwargs2(): def test_validator_params_value_values_kwargs2(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
"masque du sous-reseau", "masque du sous-reseau",
@ -263,14 +283,15 @@ def test_validator_params_value_values_kwargs2():
validator_params=Params(ParamValue(['val1']), {'index': ParamOption(ip_admin_eth0)})) validator_params=Params(ParamValue(['val1']), {'index': ParamOption(ip_admin_eth0)}))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
def test_validator_params_value_values_kwargs_index(): def test_validator_params_value_values_kwargs_index(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
"masque du sous-reseau", "masque du sous-reseau",
@ -279,158 +300,181 @@ def test_validator_params_value_values_kwargs_index():
validator_params=Params(kwargs={'index': ParamOption(ip_admin_eth0)})) validator_params=Params(kwargs={'index': ParamOption(ip_admin_eth0)}))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
def test_validator_params_context(): def test_validator_params_context():
opt1 = StrOption('opt1', '', validator=is_context, validator_params=Params(ParamContext()), default='val') opt1 = StrOption('opt1', '', validator=is_context, validator_params=Params(ParamContext()), default='val')
root = OptionDescription('root', '', [opt1]) root = OptionDescription('root', '', [opt1])
api = Config(root) cfg = Config(root)
assert 'validator' in api.property.get() # cfg = get_config(cfg, config_type) # ParamContext not supported
assert api.option('opt1').value.get() == 'val' assert 'validator' in cfg.property.get()
assert 'validator' in api.property.get() assert cfg.option('opt1').value.get() == 'val'
assert 'validator' in cfg.property.get()
def test_validator_params_context_value(): def test_validator_params_context_value():
opt1 = StrOption('opt1', '', 'yes') opt1 = StrOption('opt1', '', 'yes')
opt2 = StrOption('opt2', '', validator=valid_from_config, validator_params=Params(ParamContext()), default='val') opt2 = StrOption('opt2', '', validator=valid_from_config, validator_params=Params(ParamContext()), default='val')
root = OptionDescription('root', '', [opt1, opt2]) root = OptionDescription('root', '', [opt1, opt2])
api = Config(root) cfg = Config(root)
assert api.option('opt1').value.get() == 'yes' # cfg = get_config(cfg_ori, config_type) # ParamContext not supported
assert api.option('opt2').value.get() == 'val' assert cfg.option('opt1').value.get() == 'yes'
api.option('opt1').value.set('no') assert cfg.option('opt2').value.get() == 'val'
raises(ValueError, "assert api.option('opt2').value.get()") cfg.option('opt1').value.set('no')
api.property.add('demoting_error_warning') raises(ValueError, "assert cfg.option('opt2').value.get()")
if config_type == 'tiramisu-api':
cfg.send()
cfg.property.add('demoting_error_warning')
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.get() cfg.option('opt2').value.get()
assert len(w) == 1 assert len(w) == 1
def test_validator_params_key(): def test_validator_params_key(config_type):
opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(kwargs={'param': ParamValue('yes')}), default='val') opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(kwargs={'param': ParamValue('yes')}), default='val')
raises(ConfigError, "StrOption('opt2', '', validator=return_true, validator_params=Params(kwargs={'param_unknown': ParamValue('yes')}), default='val')") raises(ConfigError, "StrOption('opt2', '', validator=return_true, validator_params=Params(kwargs={'param_unknown': ParamValue('yes')}), default='val')")
root = OptionDescription('root', '', [opt1]) root = OptionDescription('root', '', [opt1])
api = Config(root) cfg = Config(root)
assert api.option('opt1').value.get() == 'val' cfg = get_config(cfg, config_type)
assert cfg.option('opt1').value.get() == 'val'
def test_validator_params_option(): def test_validator_params_option(config_type):
opt0 = StrOption('opt0', '', default='yes') opt0 = StrOption('opt0', '', default='yes')
opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamOption(opt0)), default='val') opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamOption(opt0)), default='val')
r = OptionDescription('root', '', [opt0, opt1]) r = OptionDescription('root', '', [opt0, opt1])
api = Config(r) cfg_ori = Config(r)
assert api.option('opt1').value.get() == 'val' cfg = get_config(cfg_ori, config_type)
api.option('opt0').value.set('val') assert cfg.option('opt1').value.get() == 'val'
raises(ValueError, "api.option('opt1').value.get()") cfg.option('opt0').value.set('val')
api.property.add('demoting_error_warning') raises(ValueError, "cfg.option('opt1').value.get()")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt1').value.get() cfg.option('opt1').value.get()
assert len(w) == 1 assert len(w) == 1
def test_validator_multi(): def test_validator_multi(config_type):
opt1 = StrOption('opt1', '', validator=return_if_val, multi=True) opt1 = StrOption('opt1', '', validator=return_if_val, multi=True)
root = OptionDescription('root', '', [opt1]) root = OptionDescription('root', '', [opt1])
api = Config(root) cfg_ori = Config(root)
assert api.option('opt1').value.get() == [] cfg = get_config(cfg_ori, config_type)
api.option('opt1').value.set(['val']) assert cfg.option('opt1').value.get() == []
assert api.option('opt1').value.get() == ['val'] cfg.option('opt1').value.set(['val'])
raises(ValueError, "api.option('opt1').value.set(['val', 'val1'])") assert cfg.option('opt1').value.get() == ['val']
api.property.add('demoting_error_warning') raises(ValueError, "cfg.option('opt1').value.set(['val', 'val1'])")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt1').value.set(['val', 'val1']) cfg.option('opt1').value.set(['val', 'val1'])
assert len(w) == 1 assert len(w) == 1
def test_validator_warning(): def test_validator_warning(config_type):
opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True) opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True)
opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True) opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True)
opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True) opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True)
root = OptionDescription('root', '', [opt1, opt2, opt3]) root = OptionDescription('root', '', [opt1, opt2, opt3])
api = Config(root) cfg = Config(root)
assert api.option('opt1').value.get() == 'val' cfg = get_config(cfg, config_type)
assert cfg.option('opt1').value.get() == 'val'
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt1').value.set('val') cfg.option('opt1').value.set('val')
assert w == [] assert w == []
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
assert len(w) == 1 assert len(w) == 1
if config_type != 'tiramisu-api':
assert w[0].message.opt() == opt2 assert w[0].message.opt() == opt2
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false' assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false'
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt3').value.set(['val']) cfg.option('opt3').value.set(['val'])
assert w == [] assert w == []
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt3').value.set(['val', 'val1']) cfg.option('opt3').value.set(['val', 'val1'])
assert len(w) == 1 assert len(w) == 1
if config_type != 'tiramisu-api':
assert w[0].message.opt() == opt3 assert w[0].message.opt() == opt3
assert str(w[0].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error' assert str(w[0].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error'
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
raises(ValueError, "api.option('opt2').value.set(1)") raises(ValueError, "cfg.option('opt2').value.set(1)")
assert len(w) == 0 assert len(w) == 0
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
api.option('opt3').value.set(['val', 'val1', 'val']) cfg.option('opt3').value.set(['val', 'val1', 'val'])
assert len(w) == 2 assert len(w) == 2
if config_type != 'tiramisu-api':
assert w[0].message.opt() == opt2 assert w[0].message.opt() == opt2
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false' assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false'
assert w[1].message.opt() == opt3 assert w[1].message.opt() == opt3
assert str(w[1].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error' assert str(w[1].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error'
def test_validator_warning_disabled(): def test_validator_warning_disabled(config_type):
opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True) opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True)
opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True) opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True)
opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True) opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True)
root = OptionDescription('root', '', [opt1, opt2, opt3]) root = OptionDescription('root', '', [opt1, opt2, opt3])
api = Config(root) cfg_ori = Config(root)
api.property.pop('warnings') cfg_ori.property.pop('warnings')
assert api.option('opt1').value.get() == 'val' cfg = get_config(cfg_ori, config_type)
assert cfg.option('opt1').value.get() == 'val'
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt1').value.set('val') cfg.option('opt1').value.set('val')
assert w == [] assert w == []
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
assert w == [] assert w == []
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt3').value.set(['val']) cfg.option('opt3').value.set(['val'])
assert w == [] assert w == []
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt3').value.set(['val', 'val1']) cfg.option('opt3').value.set(['val', 'val1'])
assert w == [] assert w == []
raises(ValueError, "api.option('opt2').value.set(1)") raises(ValueError, "cfg.option('opt2').value.set(1)")
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
api.option('opt3').value.set(['val', 'val1', 'val']) cfg.option('opt3').value.set(['val', 'val1', 'val'])
assert w == [] assert w == []
# #
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
if config_type != 'tiramisu-api':
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set(1) cfg.option('opt2').value.set(1)
assert len(w) == 1 assert len(w) == 1
def test_validator_warning_leadership(): def test_validator_warning_leadership(config_type):
display_name_ip = "ip reseau autorise" display_name_ip = "ip reseau autorise"
display_name_netmask = "masque du sous-reseau" display_name_netmask = "masque du sous-reseau"
ip_admin_eth0 = StrOption('ip_admin_eth0', display_name_ip, multi=True, validator=return_false, warnings_only=True) ip_admin_eth0 = StrOption('ip_admin_eth0', display_name_ip, multi=True, validator=return_false, warnings_only=True)
@ -438,48 +482,55 @@ def test_validator_warning_leadership():
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
assert interface1.impl_get_group_type() == groups.leadership assert interface1.impl_get_group_type() == groups.leadership
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
cfg = get_config(cfg, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set([None]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([None])
assert w == [] assert w == []
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
assert len(w) == 1 assert len(w) == 1
if config_type != 'tiramisu-api':
assert w[0].message.opt() == netmask_admin_eth0 assert w[0].message.opt() == netmask_admin_eth0
assert str(w[0].message) == msg_err.format('val1', netmask_admin_eth0._display_name, display_name_netmask) + ', test error' assert str(w[0].message) == msg_err.format('val1', netmask_admin_eth0._display_name, display_name_netmask) + ', test error'
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
assert len(w) == 1 if config_type != 'tiramisu-api':
assert w[0].message.opt() == ip_admin_eth0 assert w[0].message.opt() == ip_admin_eth0
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false' assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
else:
assert len(w) == 2
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val1', 'val1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val1', 'val1'])
#FIXME if config_type != 'tiramisu-api':
#assert len(w) == 1
assert w[0].message.opt() == ip_admin_eth0 assert w[0].message.opt() == ip_admin_eth0
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false' assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
else:
assert len(w) == 3
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val', 'val1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val', 'val1'])
#FIXME if config_type != 'tiramisu-api':
#assert len(w) == 1
assert w[0].message.opt() == ip_admin_eth0 assert w[0].message.opt() == ip_admin_eth0
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false' assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
else:
assert len(w) == 3
# #
warnings.resetwarnings() warnings.resetwarnings()
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val1', 'val']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val1', 'val'])
#FIXME if config_type != 'tiramisu-api':
#assert len(w) == 1
assert w[0].message.opt() == ip_admin_eth0 assert w[0].message.opt() == ip_admin_eth0
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false' assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
else:
assert len(w) == 3
def test_validator_follower_param(): def test_validator_follower_param(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
"masque du sous-reseau", "masque du sous-reseau",
@ -488,12 +539,13 @@ def test_validator_follower_param():
validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)})) validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)}))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes', 'yes']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes', 'yes'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val')
def test_validator_dependencies(): def test_validator_dependencies():
@ -504,11 +556,11 @@ def test_validator_dependencies():
validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)})) validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)}))
opt2 = StrOption('opt2', '', validator=return_false) opt2 = StrOption('opt2', '', validator=return_false)
root = OptionDescription('root', '', [ip_admin_eth0, netmask_admin_eth0, opt2]) root = OptionDescription('root', '', [ip_admin_eth0, netmask_admin_eth0, opt2])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0').option.has_dependency() is False assert cfg.option('ip_admin_eth0').option.has_dependency() is False
assert api.option('netmask_admin_eth0').option.has_dependency() is True assert cfg.option('netmask_admin_eth0').option.has_dependency() is True
assert api.option('opt2').option.has_dependency() is False assert cfg.option('opt2').option.has_dependency() is False
# #
assert api.option('ip_admin_eth0').option.has_dependency(False) is True assert cfg.option('ip_admin_eth0').option.has_dependency(False) is True
assert api.option('netmask_admin_eth0').option.has_dependency(False) is False assert cfg.option('netmask_admin_eth0').option.has_dependency(False) is False
assert api.option('opt2').option.has_dependency(False) is False assert cfg.option('opt2').option.has_dependency(False) is False

View File

@ -1,6 +1,7 @@
#this test is much more to test that **it's there** and answers attribute access #this test is much more to test that **it's there** and answers attribute access
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from py.test import raises from py.test import raises
@ -36,17 +37,18 @@ def make_description():
return descr return descr
def test_root_config_answers_ok(): def test_root_config_answers_ok(config_type):
"if you hide the root config, the options in this namespace behave normally" "if you hide the root config, the options in this namespace behave normally"
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
boolop = BoolOption('boolop', 'Test boolean option op', default=True) boolop = BoolOption('boolop', 'Test boolean option op', default=True)
descr = OptionDescription('tiramisu', '', [gcdummy, boolop]) descr = OptionDescription('tiramisu', '', [gcdummy, boolop])
api = Config(descr) cfg = Config(descr)
cfg = get_config(cfg, config_type)
#settings = cfg.cfgimpl_get_settings() #settings = cfg.cfgimpl_get_settings()
#settings.append('hidden') #settings.append('hidden')
assert api.option('dummy').value.get() is False assert cfg.option('dummy').value.get() is False
assert api.option('boolop').value.get() is True assert cfg.option('boolop').value.get() is True
#def test_optname_shall_not_start_with_numbers(): #def test_optname_shall_not_start_with_numbers():
@ -54,9 +56,10 @@ def test_root_config_answers_ok():
# raises(ValueError, "descr = OptionDescription('123tiramisu', '', [])") # raises(ValueError, "descr = OptionDescription('123tiramisu', '', [])")
# #
# #
def test_option_has_an_api_name(): def test_option_has_an_api_name(config_type):
b = BoolOption('impl_has_dependency', 'dummy', default=True) b = BoolOption('impl_has_dependency', 'dummy', default=True)
descr = OptionDescription('tiramisu', '', [b]) descr = OptionDescription('tiramisu', '', [b])
api = Config(descr) cfg = Config(descr)
assert api.option('impl_has_dependency').value.get() is True cfg = get_config(cfg, config_type)
assert cfg.option('impl_has_dependency').value.get() is True
assert b.impl_has_dependency() is False assert b.impl_has_dependency() is False

View File

@ -1,12 +1,12 @@
# coding: utf-8 # coding: utf-8
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from py.test import raises from py.test import raises
from tiramisu import IntOption, UnicodeOption, OptionDescription, Config from tiramisu import IntOption, UnicodeOption, OptionDescription, Config
from tiramisu.error import PropertiesOptionError, ConfigError from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.api import TIRAMISU_VERSION
from tiramisu.storage import list_sessions, delete_session from tiramisu.storage import list_sessions, delete_session
@ -20,61 +20,81 @@ def make_description():
return OptionDescription('od1', '', [u1, u2]) return OptionDescription('od1', '', [u1, u2])
def test_permissive(): def test_permissive(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
api.property.read_write() cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.unrestraint.permissive.set(frozenset(['disabled'])) if config_type == 'tiramisu-api':
assert api.unrestraint.permissive.get() == frozenset(['disabled']) cfg.send()
cfg_ori.unrestraint.permissive.set(frozenset(['disabled']))
assert cfg_ori.unrestraint.permissive.get() == frozenset(['disabled'])
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.property.add('permissive') if config_type == 'tiramisu-api':
api.option('u1').value.get() cfg.send()
api.property.pop('permissive') cfg_ori.property.add('permissive')
cfg = get_config(cfg_ori, config_type)
cfg.option('u1').value.get()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('permissive')
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
def test_permissive_add(): def test_permissive_add(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
api.property.read_write() cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.unrestraint.permissive.add('disabled') if config_type == 'tiramisu-api':
assert api.unrestraint.permissive.get() == frozenset(['hidden', 'disabled']) cfg.send()
cfg_ori.unrestraint.permissive.add('disabled')
assert cfg_ori.unrestraint.permissive.get() == frozenset(['hidden', 'disabled'])
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.property.add('permissive') if config_type == 'tiramisu-api':
api.option('u1').value.get() cfg.send()
api.property.pop('permissive') cfg_ori.property.add('permissive')
cfg = get_config(cfg_ori, config_type)
cfg.option('u1').value.get()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('permissive')
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
@ -82,22 +102,22 @@ def test_permissive_add():
def test_permissive_pop(): def test_permissive_pop():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.property.read_write() cfg.property.read_write()
props = frozenset() props = frozenset()
try: try:
api.forcepermissive.option('u1').value.get() cfg.forcepermissive.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.unrestraint.permissive.add('disabled') cfg.unrestraint.permissive.add('disabled')
assert api.unrestraint.permissive.get() == frozenset(['hidden', 'disabled']) assert cfg.unrestraint.permissive.get() == frozenset(['hidden', 'disabled'])
api.forcepermissive.option('u1').value.get() cfg.forcepermissive.option('u1').value.get()
api.unrestraint.permissive.pop('disabled') cfg.unrestraint.permissive.pop('disabled')
props = frozenset() props = frozenset()
try: try:
api.forcepermissive.option('u1').value.get() cfg.forcepermissive.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
@ -105,140 +125,138 @@ def test_permissive_pop():
def test_permissive_reset(): def test_permissive_reset():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert api.unrestraint.permissive.get() == frozenset(['hidden']) assert cfg.unrestraint.permissive.get() == frozenset(['hidden'])
# #
api.unrestraint.permissive.set(frozenset(['disabled'])) cfg.unrestraint.permissive.set(frozenset(['disabled']))
assert api.unrestraint.permissive.get() == frozenset(['disabled']) assert cfg.unrestraint.permissive.get() == frozenset(['disabled'])
# #
api.unrestraint.permissive.reset() cfg.unrestraint.permissive.reset()
assert api.unrestraint.permissive.get() == frozenset() assert cfg.unrestraint.permissive.get() == frozenset()
def test_permissive_mandatory(): def test_permissive_mandatory():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_only() cfg.property.read_only()
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2:
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
else:
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.unrestraint.permissive.set(frozenset(['mandatory', 'disabled'])) cfg.unrestraint.permissive.set(frozenset(['mandatory', 'disabled']))
assert api.unrestraint.permissive.get() == frozenset(['mandatory', 'disabled']) assert cfg.unrestraint.permissive.get() == frozenset(['mandatory', 'disabled'])
api.property.add('permissive') cfg.property.add('permissive')
api.option('u1').value.get() cfg.option('u1').value.get()
api.property.pop('permissive') cfg.property.pop('permissive')
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2:
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
else:
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_permissive_frozen(): def test_permissive_frozen():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.unrestraint.permissive.set(frozenset(['frozen', 'disabled'])) cfg.unrestraint.permissive.set(frozenset(['frozen', 'disabled']))
assert api.unrestraint.permissive.get() == frozenset(['frozen', 'disabled']) assert cfg.unrestraint.permissive.get() == frozenset(['frozen', 'disabled'])
assert api.permissive.get() == frozenset(['frozen', 'disabled']) assert cfg.permissive.get() == frozenset(['frozen', 'disabled'])
try: try:
api.option('u1').value.set(1) cfg.option('u1').value.set(1)
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2:
assert frozenset(props) == frozenset(['disabled', 'frozen'])
else:
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.property.add('permissive') cfg.property.add('permissive')
api.option('u1').value.set(1) cfg.option('u1').value.set(1)
assert api.option('u1').value.get() == 1 assert cfg.option('u1').value.get() == 1
api.property.pop('permissive') cfg.property.pop('permissive')
try: try:
api.option('u1').value.set(1) cfg.option('u1').value.set(1)
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2:
assert frozenset(props) == frozenset(['disabled', 'frozen'])
else:
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_invalid_permissive(): def test_invalid_permissive():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
raises(TypeError, "api.unrestraint.permissive.set(['frozen', 'disabled'])") raises(TypeError, "cfg.unrestraint.permissive.set(['frozen', 'disabled'])")
def test_forbidden_permissive(): def test_forbidden_permissive():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
raises(ConfigError, "api.permissive.set(frozenset(['force_default_on_freeze']))") raises(ConfigError, "cfg.permissive.set(frozenset(['force_default_on_freeze']))")
raises(ConfigError, "api.permissive.set(frozenset(['force_metaconfig_on_freeze']))") raises(ConfigError, "cfg.permissive.set(frozenset(['force_metaconfig_on_freeze']))")
def test_permissive_option(): def test_permissive_option(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.unrestraint.option('u1').permissive.set(frozenset(['disabled'])) if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset() assert frozenset(props) == frozenset()
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.property.add('permissive') if config_type == 'tiramisu-api':
api.option('u1').value.get() cfg.send()
cfg_ori.property.add('permissive')
cfg = get_config(cfg_ori, config_type)
cfg.option('u1').value.get()
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.property.pop('permissive') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('permissive')
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset() assert frozenset(props) == frozenset()
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
@ -246,55 +264,55 @@ def test_permissive_option():
def test_permissive_option_cache(): def test_permissive_option_cache():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.unrestraint.option('u1').permissive.set(frozenset(['disabled'])) cfg.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset() assert frozenset(props) == frozenset()
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.property.add('permissive') cfg.property.add('permissive')
api.option('u1').value.get() cfg.option('u1').value.get()
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.property.pop('permissive') cfg.property.pop('permissive')
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset() assert frozenset(props) == frozenset()
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
@ -302,78 +320,85 @@ def test_permissive_option_cache():
def test_permissive_option_mandatory(): def test_permissive_option_mandatory():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_only() cfg.property.read_only()
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2:
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
else:
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.unrestraint.option('u1').permissive.set(frozenset(['mandatory', 'disabled'])) cfg.unrestraint.option('u1').permissive.set(frozenset(['mandatory', 'disabled']))
assert api.unrestraint.option('u1').permissive.get() == frozenset(['mandatory', 'disabled']) assert cfg.unrestraint.option('u1').permissive.get() == frozenset(['mandatory', 'disabled'])
api.property.add('permissive') cfg.property.add('permissive')
api.option('u1').value.get() cfg.option('u1').value.get()
api.property.pop('permissive') cfg.property.pop('permissive')
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2:
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
else:
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_permissive_option_frozen(): def test_permissive_option_frozen():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.unrestraint.option('u1').permissive.set(frozenset(['frozen', 'disabled'])) cfg.unrestraint.option('u1').permissive.set(frozenset(['frozen', 'disabled']))
api.option('u1').value.set(1) cfg.option('u1').value.set(1)
assert api.option('u1').value.get() == 1 assert cfg.option('u1').value.get() == 1
api.property.add('permissive') cfg.property.add('permissive')
assert api.option('u1').value.get() == 1 assert cfg.option('u1').value.get() == 1
api.property.pop('permissive') cfg.property.pop('permissive')
assert api.option('u1').value.get() == 1 assert cfg.option('u1').value.get() == 1
if TIRAMISU_VERSION == 3: def test_invalid_option_permissive():
def test_invalid_option_permissive():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
raises(TypeError, "api.unrestraint.option('u1').permissive.set(['frozen', 'disabled'])") raises(TypeError, "cfg.unrestraint.option('u1').permissive.set(['frozen', 'disabled'])")
def test_remove_option_permissive(): def test_remove_option_permissive(config_type):
var1 = UnicodeOption('var1', '', u'value', properties=('hidden',)) var1 = UnicodeOption('var1', '', u'value', properties=('hidden',))
od1 = OptionDescription('od1', '', [var1]) od1 = OptionDescription('od1', '', [var1])
rootod = OptionDescription('rootod', '', [od1]) rootod = OptionDescription('rootod', '', [od1])
api = Config(rootod) cfg_ori = Config(rootod)
api.property.read_write() cfg_ori.property.read_write()
raises(PropertiesOptionError, "api.option('od1.var1').value.get()") cfg = get_config(cfg_ori, config_type)
api.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden'])) raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
assert api.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden']) if config_type == 'tiramisu-api':
assert api.option('od1.var1').value.get() == 'value' cfg.send()
api.forcepermissive.option('od1.var1').permissive.set(frozenset()) cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('od1.var1').permissive.get() == frozenset() assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden'])
raises(PropertiesOptionError, "api.option('od1.var1').value.get()") cfg = get_config(cfg_ori, config_type)
assert cfg.option('od1.var1').value.get() == 'value'
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset())
assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset()
cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
def test_reset_option_permissive(): def test_reset_option_permissive(config_type):
var1 = UnicodeOption('var1', '', u'value', properties=('hidden',)) var1 = UnicodeOption('var1', '', u'value', properties=('hidden',))
od1 = OptionDescription('od1', '', [var1]) od1 = OptionDescription('od1', '', [var1])
rootod = OptionDescription('rootod', '', [od1]) rootod = OptionDescription('rootod', '', [od1])
api = Config(rootod) cfg_ori = Config(rootod)
api.property.read_write() cfg_ori.property.read_write()
raises(PropertiesOptionError, "api.option('od1.var1').value.get()") cfg = get_config(cfg_ori, config_type)
api.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden'])) raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
assert api.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden']) if config_type == 'tiramisu-api':
assert api.option('od1.var1').value.get() == 'value' cfg.send()
api.forcepermissive.option('od1.var1').permissive.reset() cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('od1.var1').permissive.get() == frozenset() assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden'])
raises(PropertiesOptionError, "api.option('od1.var1').value.get()") cfg = get_config(cfg_ori, config_type)
assert cfg.option('od1.var1').value.get() == 'value'
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.forcepermissive.option('od1.var1').permissive.reset()
assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset()
cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")

View File

@ -1,6 +1,7 @@
# coding: utf-8 # coding: utf-8
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from copy import copy from copy import copy
from tiramisu.i18n import _ from tiramisu.i18n import _
@ -9,7 +10,7 @@ from tiramisu import setting
setting.expires_time = 1 setting.expires_time = 1
from tiramisu import IPOption, OptionDescription, BoolOption, IntOption, StrOption, \ from tiramisu import IPOption, OptionDescription, BoolOption, IntOption, StrOption, \
Leadership, Config, calc_value, Params, ParamOption Leadership, Config, calc_value, Params, ParamOption
from tiramisu.error import PropertiesOptionError, RequirementError from tiramisu.error import PropertiesOptionError, RequirementError, ConfigError
from py.test import raises from py.test import raises
from tiramisu.storage import list_sessions, delete_session from tiramisu.storage import list_sessions, delete_session
@ -18,133 +19,147 @@ def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__) assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def test_properties(): def test_properties(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', properties=('disabled',)) b = IPOption('ip_address_service', '', properties=('disabled',))
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg_ori = Config(od)
api.property.read_write() cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.unrestraint.option('ip_address_service').property.pop('disabled') if config_type == 'tiramisu-api':
api.option('ip_address_service').value.get() cfg.send()
api.unrestraint.option('ip_address_service').property.add('disabled') cfg_ori.unrestraint.option('ip_address_service').property.pop('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_address_service').value.get()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_address_service').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
# pop twice # pop twice
api.unrestraint.option('ip_address_service').property.pop('disabled') if config_type == 'tiramisu-api':
api.unrestraint.option('ip_address_service').property.pop('disabled') cfg.send()
cfg_ori.unrestraint.option('ip_address_service').property.pop('disabled')
cfg_ori.unrestraint.option('ip_address_service').property.pop('disabled')
def test_requires(): def test_requires(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert not api.option('activate_service').option.requires() assert not cfg.option('activate_service').option.requires()
assert api.option('ip_address_service').option.requires() assert cfg.option('ip_address_service').option.requires()
api.option('ip_address_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service').value.set(False) cfg.option('ip_address_service').value.get()
cfg.option('activate_service').value.set(False)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_requires_callback(): def test_requires_callback(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': False, 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert not api.option('activate_service').option.requires() assert not cfg.option('activate_service').option.requires()
assert api.option('ip_address_service').option.requires() assert cfg.option('ip_address_service').option.requires()
api.option('ip_address_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service').value.set(False) cfg.option('ip_address_service').value.get()
cfg.option('activate_service').value.set(False)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_requires_inverse(): def test_requires_inverse(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled', 'inverse': True}]) requires=[{'option': a, 'expected': False, 'action': 'disabled', 'inverse': True}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_self(): def test_requires_self(config_type):
a = StrOption('ip_address_service', '', a = StrOption('ip_address_service', '',
requires=[{'option': 'self', 'expected': 'b', 'action': 'disabled'}]) requires=[{'option': 'self', 'expected': 'b', 'action': 'disabled'}])
od = OptionDescription('service', '', [a]) od = OptionDescription('service', '', [a])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_address_service').value.get() == None cfg = get_config(cfg, config_type)
api.option('ip_address_service').value.set('a') assert cfg.option('ip_address_service').value.get() == None
assert api.option('ip_address_service').value.get() == 'a' cfg.option('ip_address_service').value.set('a')
api.option('ip_address_service').value.set('b') assert cfg.option('ip_address_service').value.get() == 'a'
cfg.option('ip_address_service').value.set('b')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_with_requires(): def test_requires_with_requires(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('ip_address_service').property.add('test') cfg.option('ip_address_service').property.add('test')
api.option('ip_address_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service').value.set(False) cfg.option('ip_address_service').value.get()
cfg.option('activate_service').value.set(False)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_requires_invalid(): def test_requires_invalid():
@ -162,7 +177,7 @@ def test_requires_invalid():
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': 'string', 'action': 'disabled'}])") raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': 'string', 'action': 'disabled'}])")
def test_requires_same_action(): def test_requires_same_action(config_type):
activate_service = BoolOption('activate_service', '', True) activate_service = BoolOption('activate_service', '', True)
activate_service_web = BoolOption('activate_service_web', '', True, activate_service_web = BoolOption('activate_service_web', '', True,
requires=[{'option': activate_service, 'expected': False, requires=[{'option': activate_service, 'expected': False,
@ -173,34 +188,42 @@ def test_requires_same_action():
'action': 'disabled', 'inverse': False, 'action': 'disabled', 'inverse': False,
'transitive': True, 'same_action': False}]) 'transitive': True, 'same_action': False}])
od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web]) od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web])
api = Config(od1) cfg = Config(od1)
api.property.read_write() cfg.property.read_write()
api.property.add('new') cfg.property.add('new')
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if config_type == 'tiramisu':
assert frozenset(props) == frozenset(['new']) assert frozenset(props) == frozenset(['new'])
else:
assert frozenset(props) == frozenset(['disabled'])
# #
props = [] props = []
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
submsg = '"disabled" (' + _('the value of "{0}" is {1}').format('activate_service', '"False"') + ')' submsg = '"disabled" (' + _('the value of "{0}" is {1}').format('activate_service', '"False"') + ')'
if config_type == 'tiramisu':
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg)) assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
#access to cache #access to cache
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg)) assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
else:
# FIXME
assert str(err) == 'error'
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_same_action_callback(): def test_requires_same_action_callback(config_type):
activate_service = BoolOption('activate_service', '', True) activate_service = BoolOption('activate_service', '', True)
activate_service_web = BoolOption('activate_service_web', '', True, activate_service_web = BoolOption('activate_service_web', '', True,
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate_service)), 'expected': False, requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate_service)), 'expected': False,
@ -211,151 +234,175 @@ def test_requires_same_action_callback():
'action': 'disabled', 'inverse': False, 'action': 'disabled', 'inverse': False,
'transitive': True, 'same_action': False}]) 'transitive': True, 'same_action': False}])
od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web]) od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web])
api = Config(od1) cfg = Config(od1)
api.property.read_write() cfg.property.read_write()
api.property.add('new') cfg.property.add('new')
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if config_type == 'tiramisu':
assert frozenset(props) == frozenset(['new']) assert frozenset(props) == frozenset(['new'])
else:
assert frozenset(props) == frozenset(['disabled'])
# #
props = [] props = []
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
submsg = '"disabled" (' + _('the calculated value is {0}').format('"False"') + ')' submsg = '"disabled" (' + _('the calculated value is {0}').format('"False"') + ')'
if config_type == 'tiramisu':
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg)) assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
#access to cache #access to cache
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg)) assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
else:
# FIXME
assert str(err) == 'error'
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_multiple_requires(): def test_multiple_requires(config_type):
a = StrOption('activate_service', '') a = StrOption('activate_service', '')
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'}, requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
{'option': a, 'expected': 'ok', 'action': 'disabled'}]) {'option': a, 'expected': 'ok', 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('ip_address_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service').value.set('yes') cfg.option('ip_address_service').value.get()
cfg.option('activate_service').value.set('yes')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set('ok') cfg.option('activate_service').value.set('ok')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set('no') cfg.option('activate_service').value.set('no')
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_multiple_requires_cumulative(): def test_multiple_requires_cumulative(config_type):
a = StrOption('activate_service', '') a = StrOption('activate_service', '')
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'}, requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
{'option': a, 'expected': 'yes', 'action': 'hidden'}]) {'option': a, 'expected': 'yes', 'action': 'hidden'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('ip_address_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service').value.set('yes') cfg.option('ip_address_service').value.get()
cfg.option('activate_service').value.set('yes')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == set(['hidden', 'disabled']) if config_type == 'tiramisu':
assert set(props) == {'hidden', 'disabled'}
else:
assert set(props) == {'disabled'}
api.option('activate_service').value.set('ok') cfg.option('activate_service').value.set('ok')
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set('no') cfg.option('activate_service').value.set('no')
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_multiple_requires_cumulative_inverse(): def test_multiple_requires_cumulative_inverse(config_type):
a = StrOption('activate_service', '') a = StrOption('activate_service', '')
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True}, requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
{'option': a, 'expected': 'yes', 'action': 'hidden', 'inverse': True}]) {'option': a, 'expected': 'yes', 'action': 'hidden', 'inverse': True}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == set(['hidden', 'disabled']) if config_type == 'tiramisu':
api.option('activate_service').value.set('yes') assert set(props) == {'hidden', 'disabled'}
api.option('ip_address_service').value.get() else:
assert set(props) == {'disabled'}
cfg.option('activate_service').value.set('yes')
cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set('ok') cfg.option('activate_service').value.set('ok')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == set(['hidden', 'disabled']) if config_type == 'tiramisu':
assert set(props) == {'hidden', 'disabled'}
else:
assert set(props) == {'disabled'}
api.option('activate_service').value.set('no') cfg.option('activate_service').value.set('no')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == set(['hidden', 'disabled']) if config_type == 'tiramisu':
assert set(props) == {'hidden', 'disabled'}
else:
assert set(props) == {'disabled'}
def test_multiple_requires_inverse(): def test_multiple_requires_inverse(config_type):
a = StrOption('activate_service', '') a = StrOption('activate_service', '')
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True}, requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
{'option': a, 'expected': 'ok', 'action': 'disabled', 'inverse': True}]) {'option': a, 'expected': 'ok', 'action': 'disabled', 'inverse': True}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set('yes') cfg.option('activate_service').value.set('yes')
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set('ok') cfg.option('activate_service').value.set('ok')
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set('no') cfg.option('activate_service').value.set('no')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_transitive(): def test_requires_transitive(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
@ -363,29 +410,30 @@ def test_requires_transitive():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
# #
props = [] props = []
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_transitive_callback(): def test_requires_transitive_callback(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': False, 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': False, 'action': 'disabled'}])
@ -393,29 +441,30 @@ def test_requires_transitive_callback():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(b)), 'expected': False, 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(b)), 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
# #
props = [] props = []
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_transitive_unrestraint(): def test_requires_transitive_unrestraint(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
@ -423,18 +472,21 @@ def test_requires_transitive_unrestraint():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg_ori = Config(od)
api.property.read_write() cfg_ori.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg_ori, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
assert api.unrestraint.option('activate_service_web').property.get() == {'disabled'} if config_type == 'tiramisu-api':
assert api.unrestraint.option('ip_address_service_web').property.get() == {'disabled'} cfg.send()
assert cfg_ori.unrestraint.option('activate_service_web').property.get() == {'disabled'}
assert cfg_ori.unrestraint.option('ip_address_service_web').property.get() == {'disabled'}
def test_requires_transitive_owner(): def test_requires_transitive_owner(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
@ -442,23 +494,24 @@ def test_requires_transitive_owner():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
cfg.option('ip_address_service_web').value.get()
#no more default value #no more default value
api.option('ip_address_service_web').value.set('1.1.1.1') cfg.option('ip_address_service_web').value.set('1.1.1.1')
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
props = [] props = []
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_transitive_bis(): def test_requires_transitive_bis(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
abis = BoolOption('activate_service_bis', '', True) abis = BoolOption('activate_service_bis', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
@ -467,23 +520,24 @@ def test_requires_transitive_bis():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}]) requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
od = OptionDescription('service', '', [a, abis, b, d]) od = OptionDescription('service', '', [a, abis, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
# #
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
# #
props = [] props = []
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
@ -496,40 +550,45 @@ def test_requires_transitive_hidden_permissive():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() # FIXME permissive cfg = get_config(cfg, config_type)
api.option('ip_address_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
def test_requires_transitive_hidden_disabled(): def test_requires_transitive_hidden_disabled(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'hidden'}]) requires=[{'option': a, 'expected': False, 'action': 'hidden'}])
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if config_type == 'tiramisu-api':
assert frozenset(props) == frozenset(['disabled'])
else:
assert frozenset(props) == frozenset(['hidden']) assert frozenset(props) == frozenset(['hidden'])
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
def test_requires_transitive_hidden_disabled_multiple(): def test_requires_transitive_hidden_disabled_multiple(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'hidden'}, requires=[{'option': a, 'expected': False, 'action': 'hidden'},
@ -537,41 +596,62 @@ def test_requires_transitive_hidden_disabled_multiple():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False, 'action': 'mandatory'}]) requires=[{'option': b, 'expected': False, 'action': 'mandatory'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg_ori = Config(od)
api.property.read_write() cfg_ori.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg_ori, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
req = None
if config_type == 'tiramisu-api':
try:
cfg.option('activate_service').value.set(False)
except ConfigError as err:
req = err
error_msg = str(_('unable to transform tiramisu object to dict: {}').format(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('property'), '"disabled"')))
else:
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if config_type == 'tiramisu-api':
assert set(props) == {'disabled',}
else:
assert set(props) == {'disabled', 'hidden'} assert set(props) == {'disabled', 'hidden'}
del props del props
# #
req = None
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except RequirementError as err: except RequirementError as err:
req = err req = err
error_msg = str(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('property'), '"disabled"'))
assert req, "ip_address_service_web should raise RequirementError" assert req, "ip_address_service_web should raise RequirementError"
assert str(req) == str(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('property'), '"disabled"')) assert str(req) == error_msg
del req del req
# #
api.permissive.set(frozenset()) cfg_ori.permissive.set(frozenset())
if config_type == 'tiramisu-api':
try: try:
api.option('ip_address_service_web').value.get() cfg = get_config(cfg_ori, config_type)
except ConfigError as err:
req = err
error_msg = str(_('unable to transform tiramisu object to dict: {}').format(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('properties'), '"disabled" {} "hidden"'.format(_('and')))))
else:
cfg = get_config(cfg_ori, config_type)
try:
cfg.option('ip_address_service_web').value.get()
except RequirementError as err: except RequirementError as err:
req = err req = err
error_msg = str(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('properties'), '"disabled" {} "hidden"'.format(_('and'))))
assert req, "ip_address_service_web should raise RequirementError" assert req, "ip_address_service_web should raise RequirementError"
assert str(req) == str(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('properties'), '"disabled" {} "hidden"'.format(_('and')))) assert str(req) == error_msg
del req del req
def test_requires_not_transitive(): def test_requires_not_transitive(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
@ -579,24 +659,25 @@ def test_requires_not_transitive():
requires=[{'option': b, 'expected': False, requires=[{'option': b, 'expected': False,
'action': 'disabled', 'transitive': False}]) 'action': 'disabled', 'transitive': False}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
# #
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
def test_requires_not_transitive_not_same_action(): def test_requires_not_transitive_not_same_action(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
@ -604,154 +685,162 @@ def test_requires_not_transitive_not_same_action():
requires=[{'option': b, 'expected': False, requires=[{'option': b, 'expected': False,
'action': 'hidden', 'transitive': False}]) 'action': 'hidden', 'transitive': False}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
if config_type == 'tiramisu-api':
raises(ConfigError, "cfg.option('activate_service').value.set(False)")
else:
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
# #
raises(RequirementError, "api.option('ip_address_service_web').value.get()") raises(RequirementError, "cfg.option('ip_address_service_web').value.get()")
def test_requires_None(): def test_requires_None(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': None, 'action': 'disabled'}]) requires=[{'option': a, 'expected': None, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_requires_multi_disabled(): def test_requires_multi_disabled(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': True, 'action': 'disabled'}, requires=[{'option': a, 'expected': True, 'action': 'disabled'},
{'option': b, 'expected': 1, 'action': 'disabled'}]) {'option': b, 'expected': 1, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('num_service').value.set(1) cfg.option('num_service').value.set(1)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_multi_disabled_callback(): def test_requires_multi_disabled_callback(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': True, 'action': 'disabled'}, requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': True, 'action': 'disabled'},
{'callback': calc_value, 'callback_params': Params(ParamOption(b)), 'expected': 1, 'action': 'disabled'}]) {'callback': calc_value, 'callback_params': Params(ParamOption(b)), 'expected': 1, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('num_service').value.set(1) cfg.option('num_service').value.set(1)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_multi_disabled_new_format(): def test_requires_multi_disabled_new_format(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled'}]) requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('num_service').value.set(1) cfg.option('num_service').value.set(1)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
@ -781,84 +870,92 @@ def test_requires_unvalid():
'action': 'disabled', 'operator': 'and'}])""") 'action': 'disabled', 'operator': 'and'}])""")
def test_requires_multi_disabled_new_format_and(): def test_requires_multi_disabled_new_format_and(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'}]) requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert props == [] assert props == []
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('num_service').value.set(1) cfg.option('num_service').value.set(1)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert props == [] assert props == []
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_multi_disabled_new_format_and_2(): def test_requires_multi_disabled_new_format_and_2(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'}, requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'},
{'expected': [{'option': a, 'value': False}, {'option': b, 'value': 1}], 'action': 'expert'}]) {'expected': [{'option': a, 'value': False}, {'option': b, 'value': 1}], 'action': 'expert'}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
api = Config(od) cfg = Config(od)
api.property.add('expert') cfg.property.add('expert')
api.property.read_write() cfg.property.read_write()
api.option('ip_address_service').value.get() cfg = get_config(cfg, config_type)
cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert props == [] assert props == []
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('num_service').value.set(1) cfg.option('num_service').value.set(1)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if config_type == 'tiramisu-api':
assert frozenset(props) == frozenset(['disabled'])
else:
assert frozenset(props) == frozenset(['expert']) assert frozenset(props) == frozenset(['expert'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if config_type == 'tiramisu-api':
assert frozenset(props) == frozenset(['disabled'])
else:
assert frozenset(props) == frozenset(['disabled', 'expert']) assert frozenset(props) == frozenset(['disabled', 'expert'])
def test_requires_multi_disabled_inverse(): def test_requires_multi_disabled_inverse(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
@ -867,45 +964,46 @@ def test_requires_multi_disabled_inverse():
{'option': b, 'expected': 1, {'option': b, 'expected': 1,
'action': 'disabled', 'inverse': True}]) 'action': 'disabled', 'inverse': True}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('num_service').value.set(1) cfg.option('num_service').value.set(1)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_requires_multi_disabled_2(): def test_requires_multi_disabled_2(config_type):
a = BoolOption('a', '') a = BoolOption('a', '')
b = BoolOption('b', '') b = BoolOption('b', '')
c = BoolOption('c', '') c = BoolOption('c', '')
@ -927,32 +1025,33 @@ def test_requires_multi_disabled_2():
y = copy(list_bools) y = copy(list_bools)
y.append(z) y.append(z)
od = OptionDescription('service', '', y) od = OptionDescription('service', '', y)
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
api.option('z').value.get() cfg.option('z').value.get()
for boo in list_bools: for boo in list_bools:
api.option(boo.impl_getname()).value.set(True) cfg.option(boo.impl_getname()).value.set(True)
props = [] props = []
try: try:
api.option('z').value.get() cfg.option('z').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
for boo in list_bools: for boo in list_bools:
api.option(boo.impl_getname()).value.set(False) cfg.option(boo.impl_getname()).value.set(False)
if boo == m: if boo == m:
api.option('z').value.get() cfg.option('z').value.get()
else: else:
props = [] props = []
try: try:
api.option('z').value.get() cfg.option('z').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_multi_disabled_inverse_2(): def test_requires_multi_disabled_inverse_2(config_type):
a = BoolOption('a', '') a = BoolOption('a', '')
b = BoolOption('b', '') b = BoolOption('b', '')
c = BoolOption('c', '') c = BoolOption('c', '')
@ -975,93 +1074,106 @@ def test_requires_multi_disabled_inverse_2():
y = copy(list_bools) y = copy(list_bools)
y.append(z) y.append(z)
od = OptionDescription('service', '', y) od = OptionDescription('service', '', y)
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
props = [] props = []
try: try:
api.option('z').value.get() cfg.option('z').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
for boo in list_bools: for boo in list_bools:
api.option(boo.impl_getname()).value.set(True) cfg.option(boo.impl_getname()).value.set(True)
if boo == m: if boo == m:
api.option('z').value.get() cfg.option('z').value.get()
else: else:
props = [] props = []
try: try:
api.option('z').value.get() cfg.option('z').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
for boo in list_bools: for boo in list_bools:
api.option(boo.impl_getname()).value.set(False) cfg.option(boo.impl_getname()).value.set(False)
props = [] props = []
try: try:
api.option('z').value.get() cfg.option('z').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_requirement_append(): def test_requires_requirement_append(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg_ori = Config(od)
api.property.read_write() cfg_ori.property.read_write()
api.property.get() cfg = get_config(cfg_ori, config_type)
api.option('ip_address_service').property.get() cfg.property.get()
raises(ValueError, "api.option('ip_address_service').property.add('disabled')") cfg.option('ip_address_service').property.get()
api.option('activate_service').value.set(False) if config_type == 'tiramisu-api':
cfg.send()
raises(ValueError, "cfg_ori.option('ip_address_service').property.add('disabled')")
cfg = get_config(cfg_ori, config_type)
cfg.option('activate_service').value.set(False)
# disabled is now set, test to remove disabled before store in storage # disabled is now set, test to remove disabled before store in storage
api.unrestraint.option('ip_address_service').property.add("test") if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_address_service').property.add("test")
def test_requires_different_inverse(): def test_requires_different_inverse(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', requires=[ b = IPOption('ip_address_service', '', requires=[
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}, {'option': a, 'expected': True, 'action': 'disabled', 'inverse': True},
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': False}]) {'option': a, 'expected': True, 'action': 'disabled', 'inverse': False}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()") cfg = get_config(cfg, config_type)
api.option('activate_service').value.set(False) raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()") cfg.option('activate_service').value.set(False)
raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
def test_requires_different_inverse_unicode(): def test_requires_different_inverse_unicode(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
d = StrOption('activate_other_service', '', 'val2') d = StrOption('activate_other_service', '', 'val2')
b = IPOption('ip_address_service', '', requires=[ b = IPOption('ip_address_service', '', requires=[
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}, {'option': a, 'expected': True, 'action': 'disabled', 'inverse': True},
{'option': d, 'expected': 'val1', 'action': 'disabled', 'inverse': False}]) {'option': d, 'expected': 'val1', 'action': 'disabled', 'inverse': False}])
od = OptionDescription('service', '', [a, d, b]) od = OptionDescription('service', '', [a, d, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_address_service').value.get() == None cfg = get_config(cfg, config_type)
api.option('activate_service').value.set(False) assert cfg.option('ip_address_service').value.get() == None
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()") cfg.option('activate_service').value.set(False)
api.option('activate_service').value.set(True) raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
assert api.option('ip_address_service').value.get() == None cfg.option('activate_service').value.set(True)
api.option('activate_other_service').value.set('val1') assert cfg.option('ip_address_service').value.get() == None
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()") cfg.option('activate_other_service').value.set('val1')
api.option('activate_service').value.set(False) raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()") cfg.option('activate_service').value.set(False)
raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
def test_requires_recursive_path(): def test_requires_recursive_path(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od1 = OptionDescription('service', '', [a, b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) od1 = OptionDescription('service', '', [a, b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('base', '', [od1]) od = OptionDescription('base', '', [od1])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
raises(RequirementError, "api.option('service.a').value.get()") if config_type == 'tiramisu-api':
raises(ConfigError, "get_config(cfg, config_type)")
else:
cfg = get_config(cfg, config_type)
raises(RequirementError, "cfg.option('service.a').value.get()")
def test_optiondescription_requires(): def test_optiondescription_requires():
@ -1085,35 +1197,36 @@ def test_properties_conflict():
raises(ValueError, "od1 = OptionDescription('service', '', [a], properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])") raises(ValueError, "od1 = OptionDescription('service', '', [a], properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
def test_leadership_requires(): def test_leadership_requires(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}]) requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) od = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'], assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'],
'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']} 'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']}
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
ret = api.value.dict() ret = cfg.value.dict()
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1'] assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2 assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
@ -1123,8 +1236,8 @@ def test_leadership_requires():
del ret['ip_admin_eth0.netmask_admin_eth0'][0] del ret['ip_admin_eth0.netmask_admin_eth0'][0]
del ret['ip_admin_eth0.netmask_admin_eth0'] del ret['ip_admin_eth0.netmask_admin_eth0']
# #
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
ret = api.value.dict() ret = cfg.value.dict()
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1'] assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2 assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
@ -1135,35 +1248,36 @@ def test_leadership_requires():
del ret['ip_admin_eth0.netmask_admin_eth0'] del ret['ip_admin_eth0.netmask_admin_eth0']
def test_leadership_requires_callback(): def test_leadership_requires_callback(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(ip_admin_eth0)), 'expected': '192.168.1.1', 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(ip_admin_eth0)), 'expected': '192.168.1.1', 'action': 'disabled'}])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) od = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'], assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'],
'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']} 'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']}
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
ret = api.value.dict() ret = cfg.value.dict()
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1'] assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2 assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
@ -1173,8 +1287,8 @@ def test_leadership_requires_callback():
del ret['ip_admin_eth0.netmask_admin_eth0'][0] del ret['ip_admin_eth0.netmask_admin_eth0'][0]
del ret['ip_admin_eth0.netmask_admin_eth0'] del ret['ip_admin_eth0.netmask_admin_eth0']
# #
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
ret = api.value.dict() ret = cfg.value.dict()
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1'] assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2 assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
@ -1219,174 +1333,183 @@ def test_leadership_requires_properties():
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}]) requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])
def test_leadership_requires_leader(): def test_leadership_requires_leader(config_type):
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}]) requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [activate, interface1]) od = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
# #
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
# #
api.option('activate').value.set(True) cfg.option('activate').value.set(True)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
assert api.value.dict() == {'activate': False} assert cfg.value.dict() == {'activate': False}
def test_leadership_requires_leader_callback(): def test_leadership_requires_leader_callback(config_type):
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [activate, interface1]) od = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
# #
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
# #
api.option('activate').value.set(True) cfg.option('activate').value.set(True)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
assert api.value.dict() == {'activate': False} assert cfg.value.dict() == {'activate': False}
def test_leadership_requires_leadership(): def test_leadership_requires_leadership(config_type):
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0],
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}]) requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
maconfig = OptionDescription('toto', '', [activate, interface1]) od = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
# #
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
# #
api.option('activate').value.set(True) cfg.option('activate').value.set(True)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
assert api.value.dict() == {'activate': False} assert cfg.value.dict() == {'activate': False}
def test_leadership_requires_leadership_callback(): def test_leadership_requires_leadership_callback(config_type):
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0],
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}])
maconfig = OptionDescription('toto', '', [activate, interface1]) od = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
# #
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
# #
api.option('activate').value.set(True) cfg.option('activate').value.set(True)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
assert api.value.dict() == {'activate': False} assert cfg.value.dict() == {'activate': False}
def test_leadership_requires_no_leader(): def test_leadership_requires_no_leader(config_type):
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}]) requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [activate, interface1]) od = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
api.option('activate').value.set(False) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) cfg.option('activate').value.set(False)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1'] cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1']
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.option('activate').value.set(True) raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None cfg.option('activate').value.set(True)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
api.option('activate').value.set(False) assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.1'], 'activate': False} raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
print('=======================================')
print(cfg.value.dict())
print({'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.1'], 'activate': False})
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.1'], 'activate': False}
def test_leadership_requires_no_leader_callback(): def test_leadership_requires_no_leader_callback(config_type):
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [activate, interface1]) od = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
api.option('activate').value.set(False) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) cfg.option('activate').value.set(False)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1'] cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1']
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.option('activate').value.set(True) raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None cfg.option('activate').value.set(True)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
api.option('activate').value.set(False) assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
dico = api.value.dict() raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
dico = cfg.value.dict()
assert set(dico.keys()) == {'activate', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'} assert set(dico.keys()) == {'activate', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'}
dico['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1'] dico['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
dico['activate'] == False dico['activate'] == False
@ -1394,8 +1517,8 @@ def test_leadership_requires_no_leader_callback():
del dico['ip_admin_eth0.netmask_admin_eth0'][0] del dico['ip_admin_eth0.netmask_admin_eth0'][0]
def test_leadership_requires_complet(): def test_leadership_requires_complet(config_type):
optiontoto = StrOption('unicodetoto', "Unicode leader") optiontoto = StrOption('unicodetoto', "Unicode")
option = StrOption('unicode', "Unicode leader", multi=True) option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True) option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Values 'test' must show 'Unicode follower 3'", multi=True) option2 = StrOption('unicode2', "Values 'test' must show 'Unicode follower 3'", multi=True)
@ -1436,11 +1559,12 @@ def test_leadership_requires_complet():
[option, option1, option2, option3, option4, option5, option6, option7]) [option, option1, option2, option3, option4, option5, option6, option7])
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto]) descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
descr = OptionDescription("unicode1_leadership_requires", "Leader followers with Unicode follower 3 hidden when Unicode follower 2 is test", [descr]) descr = OptionDescription("unicode1_leadership_requires", "Leader followers with Unicode follower 3 hidden when Unicode follower 2 is test", [descr])
config = Config(descr) cfg = Config(descr)
config.property.read_write() cfg.property.read_write()
config.option('options.unicode.unicode').value.set(['test', 'trah']) cfg = get_config(cfg, config_type)
config.option('options.unicode.unicode2', 0).value.set('test') cfg.option('options.unicode.unicode').value.set(['test', 'trah'])
dico = config.value.dict() cfg.option('options.unicode.unicode2', 0).value.set('test')
dico = cfg.value.dict()
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']) assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'])
assert dico['options.unicode.unicode'] == ['test', 'trah'] assert dico['options.unicode.unicode'] == ['test', 'trah']
assert dico['options.unicode.unicode1'] == [None, None] assert dico['options.unicode.unicode1'] == [None, None]
@ -1455,8 +1579,8 @@ def test_leadership_requires_complet():
del dico['options.unicode.unicode4'][1] del dico['options.unicode.unicode4'][1]
del dico['options.unicode.unicode4'] del dico['options.unicode.unicode4']
# #
config.option('options.unicodetoto').value.set('test') cfg.option('options.unicodetoto').value.set('test')
dico = config.value.dict() dico = cfg.value.dict()
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto']) assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto'])
assert dico['options.unicode.unicode'] == ['test', 'trah'] assert dico['options.unicode.unicode'] == ['test', 'trah']
assert dico['options.unicode.unicode1'] == [None, None] assert dico['options.unicode.unicode1'] == [None, None]
@ -1481,7 +1605,7 @@ def test_leadership_requires_complet():
del dico['options.unicode.unicode7'] del dico['options.unicode.unicode7']
def test_leadership_requires_complet_callback(): def test_leadership_requires_complet_callback(config_type):
optiontoto = StrOption('unicodetoto', "Unicode leader") optiontoto = StrOption('unicodetoto', "Unicode leader")
option = StrOption('unicode', "Unicode leader", multi=True) option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True) option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
@ -1530,11 +1654,12 @@ def test_leadership_requires_complet_callback():
[option, option1, option2, option3, option4, option5, option6, option7]) [option, option1, option2, option3, option4, option5, option6, option7])
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto]) descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
descr = OptionDescription("unicode1_leadership_requires", "Leader followers with Unicode follower 3 hidden when Unicode follower 2 is test", [descr]) descr = OptionDescription("unicode1_leadership_requires", "Leader followers with Unicode follower 3 hidden when Unicode follower 2 is test", [descr])
config = Config(descr) cfg = Config(descr)
config.property.read_write() cfg.property.read_write()
config.option('options.unicode.unicode').value.set(['test', 'trah']) cfg = get_config(cfg, config_type)
config.option('options.unicode.unicode2', 0).value.set('test') cfg.option('options.unicode.unicode').value.set(['test', 'trah'])
dico = config.value.dict() cfg.option('options.unicode.unicode2', 0).value.set('test')
dico = cfg.value.dict()
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto']) assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto'])
assert dico['options.unicode.unicode'] == ['test', 'trah'] assert dico['options.unicode.unicode'] == ['test', 'trah']
assert dico['options.unicode.unicode1'] == [None, None] assert dico['options.unicode.unicode1'] == [None, None]
@ -1555,8 +1680,8 @@ def test_leadership_requires_complet_callback():
del dico['options.unicode.unicode7'][0] del dico['options.unicode.unicode7'][0]
del dico['options.unicode.unicode7'][0] del dico['options.unicode.unicode7'][0]
# #
config.option('options.unicodetoto').value.set('test') cfg.option('options.unicodetoto').value.set('test')
dico = config.value.dict() dico = cfg.value.dict()
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto']) assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto'])
assert dico['options.unicode.unicode'] == ['test', 'trah'] assert dico['options.unicode.unicode'] == ['test', 'trah']
assert dico['options.unicode.unicode1'] == [None, None] assert dico['options.unicode.unicode1'] == [None, None]
@ -1581,8 +1706,8 @@ def test_leadership_requires_complet_callback():
del dico['options.unicode.unicode7'] del dico['options.unicode.unicode7']
def test_leadership_requires_transitive(): def test_leadership_requires_transitive1(config_type):
optiontoto = StrOption('unicodetoto', "Unicode leader") optiontoto = StrOption('unicodetoto', "Simple unicode")
option = StrOption('unicode', "Unicode leader", multi=True) option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True) option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Unicode follower 2", requires=[{'option': optiontoto, option2 = StrOption('unicode2', "Unicode follower 2", requires=[{'option': optiontoto,
@ -1607,15 +1732,16 @@ def test_leadership_requires_transitive():
[option, option1, option2, option3, option4]) [option, option1, option2, option3, option4])
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto]) descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
descr = OptionDescription("unicode1", "", [descr]) descr = OptionDescription("unicode1", "", [descr])
config = Config(descr) cfg = Config(descr)
config.property.read_write() cfg.property.read_write()
assert config.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None} cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None}
# #
config.option('options.unicodetoto').value.set('test') cfg.option('options.unicodetoto').value.set('test')
assert config.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'} assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'}
# #
config.option('options.unicode.unicode').value.set(['a', 'b', 'c']) cfg.option('options.unicode.unicode').value.set(['a', 'b', 'c'])
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'test' assert dico['options.unicodetoto'] == 'test'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1634,9 +1760,9 @@ def test_leadership_requires_transitive():
del (dico['options.unicode.unicode4'][1]) del (dico['options.unicode.unicode4'][1])
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
# #
config.option('options.unicode.unicode2', 1).value.set('test') cfg.option('options.unicode.unicode2', 1).value.set('test')
config.option('options.unicode.unicode3', 1).value.set('test') cfg.option('options.unicode.unicode3', 1).value.set('test')
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'test' assert dico['options.unicodetoto'] == 'test'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1655,8 +1781,8 @@ def test_leadership_requires_transitive():
del (dico['options.unicode.unicode4'][1]) del (dico['options.unicode.unicode4'][1])
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
# #
config.option('options.unicode.unicode2', 1).value.set('rah') cfg.option('options.unicode.unicode2', 1).value.set('rah')
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'test' assert dico['options.unicodetoto'] == 'test'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1675,9 +1801,9 @@ def test_leadership_requires_transitive():
del (dico['options.unicode.unicode4'][1]) del (dico['options.unicode.unicode4'][1])
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
# #
config.option('options.unicode.unicode2', 1).value.set('test') cfg.option('options.unicode.unicode2', 1).value.set('test')
config.option('options.unicodetoto').value.set('rah') cfg.option('options.unicodetoto').value.set('rah')
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'rah' assert dico['options.unicodetoto'] == 'rah'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1696,7 +1822,7 @@ def test_leadership_requires_transitive():
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
def test_leadership_requires_transitive_callback(): def test_leadership_requires_transitive_callback(config_type):
optiontoto = StrOption('unicodetoto', "Unicode leader") optiontoto = StrOption('unicodetoto', "Unicode leader")
option = StrOption('unicode', "Unicode leader", multi=True) option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True) option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
@ -1725,15 +1851,16 @@ def test_leadership_requires_transitive_callback():
[option, option1, option2, option3, option4]) [option, option1, option2, option3, option4])
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto]) descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
descr = OptionDescription("unicode1", "", [descr]) descr = OptionDescription("unicode1", "", [descr])
config = Config(descr) cfg = Config(descr)
config.property.read_write() cfg.property.read_write()
assert config.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None} cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None}
# #
config.option('options.unicodetoto').value.set('test') cfg.option('options.unicodetoto').value.set('test')
assert config.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'} assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'}
# #
config.option('options.unicode.unicode').value.set(['a', 'b', 'c']) cfg.option('options.unicode.unicode').value.set(['a', 'b', 'c'])
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'test' assert dico['options.unicodetoto'] == 'test'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1752,9 +1879,9 @@ def test_leadership_requires_transitive_callback():
del (dico['options.unicode.unicode4'][1]) del (dico['options.unicode.unicode4'][1])
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
# #
config.option('options.unicode.unicode2', 1).value.set('test') cfg.option('options.unicode.unicode2', 1).value.set('test')
config.option('options.unicode.unicode3', 1).value.set('test') cfg.option('options.unicode.unicode3', 1).value.set('test')
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'test' assert dico['options.unicodetoto'] == 'test'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1773,8 +1900,8 @@ def test_leadership_requires_transitive_callback():
del (dico['options.unicode.unicode4'][1]) del (dico['options.unicode.unicode4'][1])
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
# #
config.option('options.unicode.unicode2', 1).value.set('rah') cfg.option('options.unicode.unicode2', 1).value.set('rah')
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'test' assert dico['options.unicodetoto'] == 'test'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1793,9 +1920,9 @@ def test_leadership_requires_transitive_callback():
del (dico['options.unicode.unicode4'][1]) del (dico['options.unicode.unicode4'][1])
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
# #
config.option('options.unicode.unicode2', 1).value.set('test') cfg.option('options.unicode.unicode2', 1).value.set('test')
config.option('options.unicodetoto').value.set('rah') cfg.option('options.unicodetoto').value.set('rah')
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'rah' assert dico['options.unicodetoto'] == 'rah'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']

View File

@ -2,12 +2,12 @@
from py.test import raises from py.test import raises
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from tiramisu import BoolOption, StrOption, SymLinkOption, \ from tiramisu import BoolOption, StrOption, SymLinkOption, \
OptionDescription, Leadership, Config OptionDescription, Leadership, Config
from tiramisu.error import PropertiesOptionError, ConfigError from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.setting import groups, owners from tiramisu.setting import groups, owners
from tiramisu.api import TIRAMISU_VERSION
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
@ -20,52 +20,55 @@ def return_value():
#____________________________________________________________ #____________________________________________________________
def test_symlink_option(): def test_symlink_option(config_type):
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
assert api.option('s1.b').value.get() is False cfg = get_config(cfg, config_type)
api.option("s1.b").value.set(True) assert cfg.option('s1.b').value.get() is False
api.option("s1.b").value.set(False) cfg.option("s1.b").value.set(True)
assert api.option('s1.b').value.get() is False cfg.option("s1.b").value.set(False)
assert api.option('c').value.get() is False assert cfg.option('s1.b').value.get() is False
api.option('s1.b').value.set(True) assert cfg.option('c').value.get() is False
assert api.option('s1.b').value.get() is True cfg.option('s1.b').value.set(True)
assert api.option('c').value.get() is True assert cfg.option('s1.b').value.get() is True
api.option('s1.b').value.set(False) assert cfg.option('c').value.get() is True
assert api.option('s1.b').value.get() is False cfg.option('s1.b').value.set(False)
assert api.option('c').value.get() is False assert cfg.option('s1.b').value.get() is False
assert cfg.option('c').value.get() is False
def test_symlink_assign_option(): def test_symlink_assign_option(config_type):
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
raises(ConfigError, "api.option('c').value.set(True)") cfg = get_config(cfg, config_type)
raises(ConfigError, "cfg.option('c').value.set(True)")
def test_symlink_del_option(): def test_symlink_del_option(config_type):
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
raises(TypeError, "api.option('c').value.reset()") cfg = get_config(cfg, config_type)
raises(ConfigError, "cfg.option('c').value.reset()")
def test_symlink_addproperties(): def test_symlink_addproperties():
boolopt = BoolOption('b', '', default=True, properties=('test',)) boolopt = BoolOption('b', '', default=True, properties=('test',))
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription('opt', '', [boolopt, linkopt]) descr = OptionDescription('opt', '', [boolopt, linkopt])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
raises(TypeError, "api.option('c').property.add('new')") raises(TypeError, "cfg.option('c').property.add('new')")
try: try:
api.option('c').property.reset() cfg.option('c').property.reset()
except AssertionError: except AssertionError:
pass pass
else: else:
@ -76,21 +79,21 @@ def test_symlink_getpermissive():
boolopt = BoolOption('b', '', default=True, properties=('test',)) boolopt = BoolOption('b', '', default=True, properties=('test',))
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription('opt', '', [boolopt, linkopt]) descr = OptionDescription('opt', '', [boolopt, linkopt])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.option('b').permissive.set(frozenset(['perm'])) cfg.option('b').permissive.set(frozenset(['perm']))
api.option('c').permissive.get() == frozenset(['perm']) cfg.option('c').permissive.get() == frozenset(['perm'])
def test_symlink_addpermissives(): def test_symlink_addpermissives():
boolopt = BoolOption('b', '', default=True, properties=('test',)) boolopt = BoolOption('b', '', default=True, properties=('test',))
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription('opt', '', [boolopt, linkopt]) descr = OptionDescription('opt', '', [boolopt, linkopt])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
raises(TypeError, "api.option('c').permissive.set(frozenset(['new']))") raises(TypeError, "cfg.option('c').permissive.set(frozenset(['new']))")
try: try:
api.option('c').permissive.reset() cfg.option('c').permissive.reset()
except AssertionError: except AssertionError:
pass pass
else: else:
@ -101,11 +104,8 @@ def test_symlink_getproperties():
boolopt = BoolOption('b', '', default=True, properties=('test',)) boolopt = BoolOption('b', '', default=True, properties=('test',))
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription('opt', '', [boolopt, linkopt]) descr = OptionDescription('opt', '', [boolopt, linkopt])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
if TIRAMISU_VERSION == 2:
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == ('test',)
else:
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == {'test'} assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == {'test'}
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == False assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == False
@ -114,89 +114,86 @@ def test_symlink_getcallback():
boolopt = BoolOption('b', '', callback=return_value) boolopt = BoolOption('b', '', callback=return_value)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription('opt', '', [boolopt, linkopt]) descr = OptionDescription('opt', '', [boolopt, linkopt])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == True assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == True
assert boolopt.impl_get_callback() == linkopt.impl_get_callback() == (return_value, None) assert boolopt.impl_get_callback() == linkopt.impl_get_callback() == (return_value, None)
def test_symlink_requires(): def test_symlink_requires(config_type):
boolopt = BoolOption('b', '', default=True) boolopt = BoolOption('b', '', default=True)
stropt = StrOption('s', '', requires=[{'option': boolopt, stropt = StrOption('s', '', requires=[{'option': boolopt,
'expected': False, 'expected': False,
'action': 'disabled'}]) 'action': 'disabled'}])
linkopt = SymLinkOption("c", stropt) linkopt = SymLinkOption("c", stropt)
descr = OptionDescription('opt', '', [boolopt, stropt, linkopt]) descr = OptionDescription('opt', '', [boolopt, stropt, linkopt])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert api.option('b').value.get() is True cfg = get_config(cfg, config_type)
assert api.option('s').value.get() is None assert cfg.option('b').value.get() is True
assert api.option('c').value.get() is None assert cfg.option('s').value.get() is None
api.option('b').value.set(False) assert cfg.option('c').value.get() is None
cfg.option('b').value.set(False)
# #
props = [] props = []
try: try:
api.option('s').value.get() cfg.option('s').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2:
assert props == ['disabled']
else:
assert props == {'disabled'} assert props == {'disabled'}
# #
props = [] props = []
try: try:
api.option('c').value.get() cfg.option('c').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2:
assert props == ['disabled']
else:
assert props == {'disabled'} assert props == {'disabled'}
def test_symlink_multi(): def test_symlink_multi(config_type):
boolopt = BoolOption("b", "", default=[False], multi=True) boolopt = BoolOption("b", "", default=[False], multi=True)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
assert api.option('s1.b').value.get() == [False] cfg = get_config(cfg, config_type)
assert api.option('c').value.get() == [False] assert cfg.option('s1.b').value.get() == [False]
api.option('s1.b').value.set([True]) assert cfg.option('c').value.get() == [False]
assert api.option('s1.b').value.get() == [True] cfg.option('s1.b').value.set([True])
assert api.option('c').value.get() == [True] assert cfg.option('s1.b').value.get() == [True]
api.option('s1.b').value.set([False]) assert cfg.option('c').value.get() == [True]
assert api.option('s1.b').value.get() == [False] cfg.option('s1.b').value.set([False])
assert api.option('c').value.get() == [False] assert cfg.option('s1.b').value.get() == [False]
api.option('s1.b').value.set([False, True]) assert cfg.option('c').value.get() == [False]
assert api.option('s1.b').value.get() == [False, True] cfg.option('s1.b').value.set([False, True])
assert api.option('c').value.get() == [False, True] assert cfg.option('s1.b').value.get() == [False, True]
assert cfg.option('c').value.get() == [False, True]
assert boolopt.impl_is_multi() is True assert boolopt.impl_is_multi() is True
assert linkopt.impl_is_multi() is True assert linkopt.impl_is_multi() is True
def test_symlink_assign(): def test_symlink_assign(config_type):
if TIRAMISU_VERSION != 2:
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
raises(ConfigError, "api.option('c').value.set(True)") cfg = get_config(cfg, config_type)
raises(ConfigError, "cfg.option('c').value.set(True)")
def test_symlink_owner(): def test_symlink_owner(config_type):
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
assert api.option('s1.b').owner.isdefault() cfg = get_config(cfg, config_type)
assert api.option('c').owner.isdefault() assert cfg.option('s1.b').owner.isdefault()
api.option('s1.b').value.set(True) assert cfg.option('c').owner.isdefault()
assert not api.option('s1.b').owner.isdefault() cfg.option('s1.b').value.set(True)
assert not api.option('c').owner.isdefault() assert not cfg.option('s1.b').owner.isdefault()
assert not cfg.option('c').owner.isdefault()
def test_symlink_get_information(): def test_symlink_get_information():
@ -224,41 +221,44 @@ def test_symlink_followers():
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])") raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_symlink_with_leader(): def test_symlink_with_leader(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
leader = SymLinkOption('leader', ip_admin_eth0) leader = SymLinkOption('leader', ip_admin_eth0)
od = OptionDescription('root', '', [interface1, leader]) od = OptionDescription('root', '', [interface1, leader])
api = Config(od) cfg = Config(od)
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'leader': []} cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'leader': []}
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'leader': ['val1', 'val2']} cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'leader': ['val1', 'val2']}
def test_symlink_with_follower(): def test_symlink_with_follower(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
follower = SymLinkOption('follower', netmask_admin_eth0) follower = SymLinkOption('follower', netmask_admin_eth0)
od = OptionDescription('root', '', [interface1, follower]) od = OptionDescription('root', '', [interface1, follower])
api = Config(od) cfg = Config(od)
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'follower': []} cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'follower': []}
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'follower': [None, None]} cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
print(cfg.value.dict())
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'follower': [None, None]}
# #
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None
assert api.option('follower', 0).value.get() == None assert cfg.option('follower', 0).value.get() == None
assert api.option('follower', 1).value.get() == None assert cfg.option('follower', 1).value.get() == None
# #
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val3') cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val3')
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, 'val3'], 'follower': [None, 'val3']} assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, 'val3'], 'follower': [None, 'val3']}
# #
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3'
assert api.option('follower', 0).value.get() == None assert cfg.option('follower', 0).value.get() == None
assert api.option('follower', 1).value.get() == 'val3' assert cfg.option('follower', 1).value.get() == 'val3'
#____________________________________________________________ #____________________________________________________________
@ -267,36 +267,38 @@ def test_symlink_dependency():
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
assert api.option('s1.b').option.has_dependency() is False assert cfg.option('s1.b').option.has_dependency() is False
assert api.option('c').option.has_dependency() is True assert cfg.option('c').option.has_dependency() is True
assert api.option('s1.b').option.has_dependency(False) is True assert cfg.option('s1.b').option.has_dependency(False) is True
assert api.option('c').option.has_dependency(False) is False assert cfg.option('c').option.has_dependency(False) is False
def test_symlink_makedict(): def test_symlink_makedict(config_type):
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
assert api.value.dict() == {'c': False, 's1.b': False} cfg = get_config(cfg, config_type)
api.option('s1.b').value.set(True) assert cfg.value.dict() == {'c': False, 's1.b': False}
assert api.value.dict() == {'c': True, 's1.b': True} cfg.option('s1.b').value.set(True)
assert cfg.value.dict() == {'c': True, 's1.b': True}
def test_symlink_list(): def test_symlink_list(config_type):
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
cfg = get_config(cfg, config_type)
list_opt = [] list_opt = []
for opt in api.option.list(): for opt in cfg.option.list():
list_opt.append(opt.option.path()) list_opt.append(opt.option.path())
assert list_opt == ['c'] assert list_opt == ['c']
# #
list_opt = [] list_opt = []
for opt in api.option.list(recursive=True): for opt in cfg.option.list(recursive=True):
list_opt.append(opt.option.path()) list_opt.append(opt.option.path())
assert list_opt == ['c', 's1.b'] assert list_opt == ['c', 's1.b']

View File

@ -278,6 +278,11 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription):
option = self._option_bag.option option = self._option_bag.option
return option.impl_get_callback() return option.impl_get_callback()
def validator(self):
"""Get validator for an option (not for optiondescription)"""
option = self._option_bag.option
return option.impl_get_validator()
def pattern(self) -> str: def pattern(self) -> str:
option = self._option_bag.option option = self._option_bag.option
type = option.get_type() type = option.get_type()
@ -374,7 +379,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
only_raises=False): only_raises=False):
"""Get properties for an option""" """Get properties for an option"""
option = self._option_bag.option option = self._option_bag.option
self._test_follower_index() #self._test_follower_index()
if not only_raises: if not only_raises:
return self._option_bag.properties return self._option_bag.properties
# do not check cache properties/permissives which are not save (unrestraint, ...) # do not check cache properties/permissives which are not save (unrestraint, ...)
@ -677,7 +682,6 @@ class _TiramisuOption(CommonTiramisu):
if subfunc in self._registers: if subfunc in self._registers:
subconfig = self._subconfig subconfig = self._subconfig
if subconfig: if subconfig:
option_bag = self._option_bag
option = self._get_option() option = self._get_option()
if option.impl_is_optiondescription() and subfunc == 'option': if option.impl_is_optiondescription() and subfunc == 'option':
config = self._get_config() config = self._get_config()

View File

@ -43,7 +43,7 @@ def manager_callback(callbk: Union[ParamOption, ParamValue],
if config_bag is undefined: if config_bag is undefined:
return undefined return undefined
if isinstance(callbk, ParamContext): if isinstance(callbk, ParamContext):
#Not an option, set full context # Not an option, set full context
return config_bag.context.duplicate(force_values=get_default_values_storages(), return config_bag.context.duplicate(force_values=get_default_values_storages(),
force_settings=get_default_settings_storages()) force_settings=get_default_settings_storages())
opt = callbk.option opt = callbk.option

View File

@ -249,7 +249,7 @@ class SubConfig(object):
_commit=True): _commit=True):
option = option_bag.option option = option_bag.option
if option.impl_is_symlinkoption(): if option.impl_is_symlinkoption():
raise TypeError(_("can't delete a SymLinkOption")) raise ConfigError(_("can't delete a SymLinkOption"))
values = self.cfgimpl_get_values() values = self.cfgimpl_get_values()
if option_bag.index is not None: if option_bag.index is not None:
values.reset_follower(option_bag, values.reset_follower(option_bag,

View File

@ -85,8 +85,10 @@ class PropertiesOptionError(AttributeError):
def __str__(self): def __str__(self):
#this part is a bit slow, so only execute when display #this part is a bit slow, so only execute when display
if self.msg: if self.msg is not None:
return self.msg return self.msg
if self._settings is None:
return 'error'
req = self._settings.apply_requires(self._option_bag, req = self._settings.apply_requires(self._option_bag,
True) True)
#if req != {} or self._orig_opt is not None: #if req != {} or self._orig_opt is not None:

View File

@ -183,6 +183,7 @@ class ConfigBag:
__slots__ = ('context', # link to the current context __slots__ = ('context', # link to the current context
'properties', # properties for current context 'properties', # properties for current context
'true_properties', # properties for current context 'true_properties', # properties for current context
'is_unrestraint',
'permissives', # permissives for current context 'permissives', # permissives for current context
'expiration_time' # EXPIRATION_TIME 'expiration_time' # EXPIRATION_TIME
) )
@ -206,6 +207,8 @@ class ConfigBag:
if key == 'expiration_time': if key == 'expiration_time':
self.expiration_time = EXPIRATION_TIME self.expiration_time = EXPIRATION_TIME
return self.expiration_time return self.expiration_time
if key == 'is_unrestraint':
return False
raise KeyError('unknown key {} for ConfigBag'.format(key)) # pragma: no cover raise KeyError('unknown key {} for ConfigBag'.format(key)) # pragma: no cover
def remove_warnings(self): def remove_warnings(self):
@ -215,6 +218,7 @@ class ConfigBag:
self.properties = frozenset(self.properties - {'validator'}) self.properties = frozenset(self.properties - {'validator'})
def unrestraint(self): def unrestraint(self):
self.is_unrestraint = True
self.true_properties = self.properties self.true_properties = self.properties
self.properties = frozenset(['cache']) self.properties = frozenset(['cache'])
@ -437,7 +441,8 @@ class Settings(object):
search_properties=search_properties) search_properties=search_properties)
props -= self.getpermissives(opt, props -= self.getpermissives(opt,
path) path)
if apply_requires: #if apply_requires and config_bag.properties == config_bag.true_properties:
if apply_requires and not config_bag.is_unrestraint:
self._p_.setcache(path, self._p_.setcache(path,
index, index,
props, props,
@ -761,15 +766,23 @@ class Settings(object):
def calc_raises_properties(self, def calc_raises_properties(self,
option_bag, option_bag,
apply_requires=True): apply_requires=True):
raises_properties = option_bag.config_bag.properties - SPECIAL_PROPERTIES
# remove global permissive properties
if raises_properties and ('permissive' in raises_properties):
raises_properties -= option_bag.config_bag.permissives
if apply_requires and option_bag.properties_setted: if apply_requires and option_bag.properties_setted:
option_properties = option_bag.properties option_properties = option_bag.properties
else: else:
option_properties = self.getproperties(option_bag, option_properties = self.getproperties(option_bag,
apply_requires=apply_requires) apply_requires=apply_requires)
return self._calc_raises_properties(option_bag.config_bag.properties,
option_bag.config_bag.permissives,
option_properties)
def _calc_raises_properties(self,
context_properties,
context_permissives,
option_properties):
raises_properties = context_properties - SPECIAL_PROPERTIES
# remove global permissive properties
if raises_properties and ('permissive' in raises_properties):
raises_properties -= context_permissives
properties = option_properties & raises_properties properties = option_properties & raises_properties
# at this point an option should not remain in properties # at this point an option should not remain in properties
return properties return properties

View File

@ -30,8 +30,6 @@ INPUTS = ['string',
'ip', 'ip',
'domainname'] 'domainname']
ACTION_HIDE = ['hidden', 'disabled']
# return always warning (even if same warning is already returned) # return always warning (even if same warning is already returned)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
@ -137,36 +135,63 @@ class Requires(object):
self.requires = {} self.requires = {}
self.options = {} self.options = {}
self.tiramisu_web = tiramisu_web self.tiramisu_web = tiramisu_web
self.action_hide = self.tiramisu_web.config._config_bag.properties
def manage_requires(self, def manage_requires(self,
childapi, childapi,
path, path,
form, form,
action_hide,
current_action): current_action):
for requires in childapi.option.requires(): for requires in childapi.option.requires():
len_to_long = len(requires) > 1
if childapi.option.isoptiondescription():
isfollower = False
else:
isfollower = childapi.option.isfollower()
if isfollower:
parent_path = path.rsplit('.', 1)[0]
parent = self.tiramisu_web.config.unrestraint.option(parent_path)
leader = next(parent.list())
self.tiramisu_web.set_remotable(leader.option.path(), form, leader)
for require in requires: for require in requires:
options, action, inverse, \ options, action, inverse, transitive, same_action, operator = require
transitive, same_action, operator = require if not len_to_long:
len_to_long = len(options) > 1
for option, expected in options:
if isinstance(option, tuple):
for option_param in chain(option[1].args, option[1].kwargs.values()):
if isinstance(option_param, ParamOption):
self.tiramisu_web.set_remotable(option_param.option.impl_getpath(), form)
elif len_to_long:
self.tiramisu_web.set_remotable(option.impl_getpath(), form)
else:
option_path = option.impl_getpath()
if action in self.action_hide:
if childapi.option.isoptiondescription() or isfollower:
self.tiramisu_web.set_remotable(option_path, form)
continue
require_option = self.tiramisu_web.config.unrestraint.option(option_path)
if transitive is False or same_action is False or operator == 'and': if transitive is False or same_action is False or operator == 'and':
# transitive to "False" not supported yet for a requirement # transitive to "False" not supported yet for a requirement
# same_action to "False" not supported yet for a requirement # same_action to "False" not supported yet for a requirement
# operator "and" not supported yet for a requirement # operator "and" not supported yet for a requirement
self.tiramisu_web.set_remotable(path, form, childapi) self.tiramisu_web.set_remotable(option_path, form, require_option)
return if require_option.option.requires():
for option, expected in options: for reqs in require_option.option.requires():
option_path = option.impl_getpath() for req in reqs:
if action in action_hide: for subopt, subexp in req[0]:
if not isinstance(subopt, tuple):
self.tiramisu_web.set_remotable(subopt.impl_getpath(), form)
if isinstance(option, ChoiceOption): if isinstance(option, ChoiceOption):
choice_obj = self.tiramisu_web.config.unrestraint.option(option_path) require_option = self.tiramisu_web.config.unrestraint.option(option_path)
if choice_obj.value.is_values_callback(): if require_option.value.callbacks():
self.tiramisu_web.set_remotable(option_path, form, choice_obj) self.tiramisu_web.set_remotable(option_path, form, require_option)
return continue
else: else:
values = self.tiramisu_web.get_enum(choice_obj, values = self.tiramisu_web.get_enum(require_option,
choice_obj.option.ismulti(), require_option.option.ismulti(),
option_path, option_path,
choice_obj.option.properties()) require_option.option.properties())
for value in values: for value in values:
if value not in expected: if value not in expected:
self.requires.setdefault(path, self.requires.setdefault(path,
@ -205,7 +230,6 @@ class Requires(object):
self.manage_requires(childapi, self.manage_requires(childapi,
path, path,
form, form,
ACTION_HIDE,
current_action) current_action)
def is_remote(self, path, form): def is_remote(self, path, form):
@ -217,8 +241,6 @@ class Requires(object):
def process(self, form): def process(self, form):
dependencies = {} dependencies = {}
for path, values in self.requires.items(): for path, values in self.requires.items():
if form.get(path, {}).get('remote') is True:
continue
if 'default' in values: if 'default' in values:
for option in values['default'].get('show', []): for option in values['default'].get('show', []):
if path == option: if path == option:
@ -262,7 +284,7 @@ class Requires(object):
if path not in dependencies[option]['expected'][expected]['hide']: if path not in dependencies[option]['expected'][expected]['hide']:
dependencies[option]['expected'][expected]['hide'].append(path) dependencies[option]['expected'][expected]['hide'].append(path)
for path, dependency in dependencies.items(): for path, dependency in dependencies.items():
form[path]['dependencies'] = dependency form.setdefault(path, {})['dependencies'] = dependency
class TiramisuDict: class TiramisuDict:
@ -375,7 +397,6 @@ class TiramisuDict:
childapi, childapi,
path, path,
leader_len, leader_len,
props_no_requires,
updates_status) updates_status)
if order is not None: if order is not None:
order.append(path) order.append(path)
@ -405,6 +426,9 @@ class TiramisuDict:
childtype = child._impl_getopt().__class__.__name__ childtype = child._impl_getopt().__class__.__name__
if childapi_option.issymlinkoption(): if childapi_option.issymlinkoption():
web_type = 'symlink' web_type = 'symlink'
value = None
defaultmulti = None
is_multi = False
else: else:
web_type = childapi_option.type() web_type = childapi_option.type()
value = childapi.option.default() value = childapi.option.default()
@ -443,6 +467,8 @@ class TiramisuDict:
self.add_help(schema[path], self.add_help(schema[path],
childapi) childapi)
except Exception as err: except Exception as err:
import traceback
traceback.print_exc()
if not init: if not init:
raise err raise err
error = err error = err
@ -524,6 +550,15 @@ class TiramisuDict:
if path in form: if path in form:
obj_form.update(form[path]) obj_form.update(form[path])
if not childapi_option.issymlinkoption(): if not childapi_option.issymlinkoption():
if childapi_option.validator() != (None, None):
obj_form['remote'] = True
params = childapi_option.validator()[1]
if params is not None:
for param in chain(params.args, params.kwargs.values()):
if isinstance(param, ParamContext):
raise ValueError(_('context is not supported from now for {}').format(path))
if isinstance(param, ParamOption):
self.set_remotable(param.option.impl_getpath(), form)
if self.clearable == 'all': if self.clearable == 'all':
obj_form['clearable'] = True obj_form['clearable'] = True
if self.clearable != 'none': if self.clearable != 'none':
@ -532,6 +567,8 @@ class TiramisuDict:
obj_form['remote'] = True obj_form['remote'] = True
if childtype == 'IPOption' and (child.impl_get_extra('_private_only') or not child.impl_get_extra('_allow_reserved') or child.impl_get_extra('_cidr')): if childtype == 'IPOption' and (child.impl_get_extra('_private_only') or not child.impl_get_extra('_allow_reserved') or child.impl_get_extra('_cidr')):
obj_form['remote'] = True obj_form['remote'] = True
if childtype == 'DateOption':
obj_form['remote'] = True
if not obj_form.get('remote', False): if not obj_form.get('remote', False):
pattern = childapi_option.pattern() pattern = childapi_option.pattern()
if pattern is not None: if pattern is not None:
@ -553,27 +590,31 @@ class TiramisuDict:
childapi): childapi):
old_properties = childapi._option_bag.config_bag.properties old_properties = childapi._option_bag.config_bag.properties
del childapi._option_bag.config_bag.properties del childapi._option_bag.config_bag.properties
if 'permissive' not in childapi._option_bag.config_bag.properties: has_permissive = 'permissive' in childapi._option_bag.config_bag.properties
if not has_permissive:
childapi._option_bag.config_bag.properties = childapi._option_bag.config_bag.properties | {'permissive'} childapi._option_bag.config_bag.properties = childapi._option_bag.config_bag.properties | {'permissive'}
# 'display=False' means cannot access only without permissive option # 'display=False' means cannot access only without permissive option
# 'hidden=True' means cannot access with or without permissive option # 'hidden=True' means cannot access with or without permissive option
if childapi.option.properties(only_raises=True): properties = childapi.property.get(only_raises=True)
if has_permissive:
properties -= self.config.permissive.get()
properties -= childapi.permissive.get()
if properties:
obj['hidden'] = True obj['hidden'] = True
childapi._option_bag.config_bag.properties = childapi._option_bag.config_bag.properties - {'permissive'} childapi._option_bag.config_bag.properties = childapi._option_bag.config_bag.properties - {'permissive'}
if childapi.option.properties(only_raises=True): properties = childapi.property.get(only_raises=True)
if has_permissive:
properties -= self.config.permissive.get()
properties -= childapi.permissive.get()
if properties:
obj['display'] = False obj['display'] = False
childapi._option_bag.config_bag.properties = old_properties childapi._option_bag.config_bag.properties = old_properties
def _gen_model_properties(self, def _gen_model_properties(self,
childapi, childapi,
path, path,
index, index):
props_no_requires):
isfollower = childapi.option.isfollower() isfollower = childapi.option.isfollower()
if index is None and isfollower:
# cannot calculated requires with follower without index
props = props_no_requires
else:
props = set(childapi.property.get()) props = set(childapi.property.get())
obj = self.gen_properties(props, obj = self.gen_properties(props,
isfollower, isfollower,
@ -589,22 +630,16 @@ class TiramisuDict:
if not isfollower and ismulti: if not isfollower and ismulti:
if 'empty' in properties: if 'empty' in properties:
obj['required'] = True obj['required'] = True
properties.remove('empty')
if 'mandatory' in properties: if 'mandatory' in properties:
obj['needs_len'] = True obj['needs_len'] = True
properties.remove('mandatory')
elif 'mandatory' in properties: elif 'mandatory' in properties:
obj['required'] = True obj['required'] = True
properties.remove('mandatory')
if 'frozen' in properties: if 'frozen' in properties:
obj['readOnly'] = True obj['readOnly'] = True
properties.remove('frozen')
#if 'hidden' in properties: #if 'hidden' in properties:
# obj['hidden'] = True # obj['hidden'] = True
# properties.remove('hidden')
#if 'disabled' in properties: #if 'disabled' in properties:
# obj['hidden'] = True # obj['hidden'] = True
# properties.remove('disabled')
if properties: if properties:
lprops = list(properties) lprops = list(properties)
lprops.sort() lprops.sort()
@ -616,7 +651,6 @@ class TiramisuDict:
childapi, childapi,
path, path,
leader_len, leader_len,
props_no_requires,
updates_status): updates_status):
if childapi.option.isoptiondescription(): if childapi.option.isoptiondescription():
props = set(childapi.property.get()) props = set(childapi.property.get())
@ -633,15 +667,13 @@ class TiramisuDict:
else: else:
obj = self._gen_model_properties(childapi, obj = self._gen_model_properties(childapi,
path, path,
None, None)
props_no_requires)
if childapi.option.isfollower(): if childapi.option.isfollower():
for index in range(leader_len): for index in range(leader_len):
follower_childapi = self.config.unrestraint.option(path, index) follower_childapi = self.config.unrestraint.option(path, index)
sobj = self._gen_model_properties(follower_childapi, sobj = self._gen_model_properties(follower_childapi,
path, path,
index, index)
props_no_requires)
self._get_model_value(follower_childapi, self._get_model_value(follower_childapi,
path, path,
sobj, sobj,
@ -657,7 +689,7 @@ class TiramisuDict:
updates_status) updates_status)
if obj: if obj:
if not childapi.option.isoptiondescription() and childapi.option.isfollower(): if not childapi.option.isoptiondescription() and childapi.option.isfollower():
model.setdefault(path, {})[None] = obj model.setdefault(path, {})['null'] = obj
else: else:
model[path] = obj model[path] = obj
@ -675,9 +707,8 @@ class TiramisuDict:
del updates_status[path][index] del updates_status[path][index]
else: else:
try: try:
nchildapi = self.config.option(path, index=index)
with warnings.catch_warnings(record=True) as warns: with warnings.catch_warnings(record=True) as warns:
value = nchildapi.value.get() value = self.config.option(path, index=index).value.get()
self._get_value_with_exception(obj, self._get_value_with_exception(obj,
childapi, childapi,
warns) warns)
@ -687,6 +718,13 @@ class TiramisuDict:
[err]) [err])
value = self.config.unrestraint.option(path, index=index).value.get() value = self.config.unrestraint.option(path, index=index).value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
config_bag = self.config._config_bag
settings = config_bag.context.cfgimpl_get_settings()
if settings._calc_raises_properties(config_bag.properties,
config_bag.permissives,
set(err.proptype)):
obj['hidden'] = True
obj['display'] = False
value = childapi.value.get() value = childapi.value.get()
if value is not None and value != []: if value is not None and value != []:
obj['value'] = value obj['value'] = value
@ -852,7 +890,6 @@ class TiramisuDict:
buttons = [] buttons = []
else: else:
form = None form = None
ret = {}
self.walk(rootpath, self.walk(rootpath,
None, None,
schema, schema,