better hidden/display support
This commit is contained in:
parent
83f05197fb
commit
fb1286e50e
14 changed files with 1489 additions and 1195 deletions
|
@ -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']
|
||||||
|
|
|
@ -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])
|
||||||
|
|
|
@ -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
|
||||||
assert 'hidden' in prop
|
if config_type == 'tiramisu-api':
|
||||||
|
assert 'disabled' in prop
|
||||||
|
else:
|
||||||
|
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
|
||||||
assert 'hidden' in prop
|
if config_type == 'tiramisu-api':
|
||||||
api.forcepermissive.option('objspace').property.pop('hidden')
|
assert 'disabled' in prop
|
||||||
assert not 'hidden' in api.option('objspace').property.get()
|
else:
|
||||||
api.option('objspace').value.set(['std', 'std'])
|
assert 'hidden' in prop
|
||||||
|
if config_type == 'tiramisu-api':
|
||||||
|
cfg.send()
|
||||||
|
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')")
|
||||||
|
|
|
@ -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
|
||||||
assert w[0].message.opt() == opt2
|
if config_type != 'tiramisu-api':
|
||||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false'
|
assert w[0].message.opt() == opt2
|
||||||
|
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
|
||||||
assert w[0].message.opt() == opt3
|
if config_type != 'tiramisu-api':
|
||||||
assert str(w[0].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error'
|
assert w[0].message.opt() == opt3
|
||||||
|
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
|
||||||
assert w[0].message.opt() == opt2
|
if config_type != 'tiramisu-api':
|
||||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false'
|
assert w[0].message.opt() == opt2
|
||||||
assert w[1].message.opt() == opt3
|
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false'
|
||||||
assert str(w[1].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error'
|
assert w[1].message.opt() == opt3
|
||||||
|
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':
|
||||||
warnings.simplefilter("always", ValueWarning)
|
cfg.send()
|
||||||
with warnings.catch_warnings(record=True) as w:
|
cfg_ori.property.add('demoting_error_warning')
|
||||||
api.option('opt2').value.set(1)
|
cfg = get_config(cfg_ori, config_type)
|
||||||
assert len(w) == 1
|
if config_type != 'tiramisu-api':
|
||||||
|
warnings.simplefilter("always", ValueWarning)
|
||||||
|
with warnings.catch_warnings(record=True) as w:
|
||||||
|
cfg.option('opt2').value.set(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
|
||||||
assert w[0].message.opt() == netmask_admin_eth0
|
if config_type != 'tiramisu-api':
|
||||||
assert str(w[0].message) == msg_err.format('val1', netmask_admin_eth0._display_name, display_name_netmask) + ', test error'
|
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'
|
||||||
#
|
#
|
||||||
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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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'])
|
||||||
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
|
cfg.unrestraint.permissive.set(frozenset(['mandatory', 'disabled']))
|
||||||
else:
|
assert cfg.unrestraint.permissive.get() == frozenset(['mandatory', 'disabled'])
|
||||||
assert frozenset(props) == frozenset(['disabled'])
|
cfg.property.add('permissive')
|
||||||
api.unrestraint.permissive.set(frozenset(['mandatory', 'disabled']))
|
cfg.option('u1').value.get()
|
||||||
assert api.unrestraint.permissive.get() == frozenset(['mandatory', 'disabled'])
|
cfg.property.pop('permissive')
|
||||||
api.property.add('permissive')
|
|
||||||
api.option('u1').value.get()
|
|
||||||
api.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'])
|
||||||
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
|
|
||||||
else:
|
|
||||||
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'])
|
||||||
assert frozenset(props) == frozenset(['disabled', 'frozen'])
|
cfg.property.add('permissive')
|
||||||
else:
|
cfg.option('u1').value.set(1)
|
||||||
assert frozenset(props) == frozenset(['disabled'])
|
assert cfg.option('u1').value.get() == 1
|
||||||
api.property.add('permissive')
|
cfg.property.pop('permissive')
|
||||||
api.option('u1').value.set(1)
|
|
||||||
assert api.option('u1').value.get() == 1
|
|
||||||
api.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'])
|
||||||
assert frozenset(props) == frozenset(['disabled', 'frozen'])
|
|
||||||
else:
|
|
||||||
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'])
|
||||||
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
|
cfg.unrestraint.option('u1').permissive.set(frozenset(['mandatory', 'disabled']))
|
||||||
else:
|
assert cfg.unrestraint.option('u1').permissive.get() == frozenset(['mandatory', 'disabled'])
|
||||||
assert frozenset(props) == frozenset(['disabled'])
|
cfg.property.add('permissive')
|
||||||
api.unrestraint.option('u1').permissive.set(frozenset(['mandatory', 'disabled']))
|
cfg.option('u1').value.get()
|
||||||
assert api.unrestraint.option('u1').permissive.get() == frozenset(['mandatory', 'disabled'])
|
cfg.property.pop('permissive')
|
||||||
api.property.add('permissive')
|
|
||||||
api.option('u1').value.get()
|
|
||||||
api.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'])
|
||||||
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
|
|
||||||
else:
|
|
||||||
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()
|
cfg = Config(descr)
|
||||||
api = Config(descr)
|
cfg.property.read_write()
|
||||||
api.property.read_write()
|
raises(TypeError, "cfg.unrestraint.option('u1').permissive.set(['frozen', 'disabled'])")
|
||||||
raises(TypeError, "api.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()")
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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,12 +104,9 @@ 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'}
|
||||||
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == ('test',)
|
|
||||||
else:
|
|
||||||
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'}
|
||||||
assert props == ['disabled']
|
|
||||||
else:
|
|
||||||
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'}
|
||||||
assert props == ['disabled']
|
|
||||||
else:
|
|
||||||
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)
|
|
||||||
linkopt = SymLinkOption("c", boolopt)
|
|
||||||
descr = OptionDescription("opt", "",
|
|
||||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
|
||||||
api = Config(descr)
|
|
||||||
raises(ConfigError, "api.option('c').value.set(True)")
|
|
||||||
|
|
||||||
|
|
||||||
def test_symlink_owner():
|
|
||||||
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()
|
raises(ConfigError, "cfg.option('c').value.set(True)")
|
||||||
api.option('s1.b').value.set(True)
|
|
||||||
assert not api.option('s1.b').owner.isdefault()
|
|
||||||
assert not api.option('c').owner.isdefault()
|
def test_symlink_owner(config_type):
|
||||||
|
boolopt = BoolOption("b", "", default=False)
|
||||||
|
linkopt = SymLinkOption("c", boolopt)
|
||||||
|
descr = OptionDescription("opt", "",
|
||||||
|
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||||
|
cfg = Config(descr)
|
||||||
|
cfg = get_config(cfg, config_type)
|
||||||
|
assert cfg.option('s1.b').owner.isdefault()
|
||||||
|
assert cfg.option('c').owner.isdefault()
|
||||||
|
cfg.option('s1.b').value.set(True)
|
||||||
|
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']
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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,62 +135,89 @@ 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:
|
||||||
if transitive is False or same_action is False or operator == 'and':
|
len_to_long = len(options) > 1
|
||||||
# transitive 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
|
|
||||||
self.tiramisu_web.set_remotable(path, form, childapi)
|
|
||||||
return
|
|
||||||
for option, expected in options:
|
for option, expected in options:
|
||||||
option_path = option.impl_getpath()
|
if isinstance(option, tuple):
|
||||||
if action in action_hide:
|
for option_param in chain(option[1].args, option[1].kwargs.values()):
|
||||||
if isinstance(option, ChoiceOption):
|
if isinstance(option_param, ParamOption):
|
||||||
choice_obj = self.tiramisu_web.config.unrestraint.option(option_path)
|
self.tiramisu_web.set_remotable(option_param.option.impl_getpath(), form)
|
||||||
if choice_obj.value.is_values_callback():
|
elif len_to_long:
|
||||||
self.tiramisu_web.set_remotable(option_path, form, choice_obj)
|
self.tiramisu_web.set_remotable(option.impl_getpath(), form)
|
||||||
return
|
|
||||||
else:
|
|
||||||
values = self.tiramisu_web.get_enum(choice_obj,
|
|
||||||
choice_obj.option.ismulti(),
|
|
||||||
option_path,
|
|
||||||
choice_obj.option.properties())
|
|
||||||
for value in values:
|
|
||||||
if value not in expected:
|
|
||||||
self.requires.setdefault(path,
|
|
||||||
{'expected': {}}
|
|
||||||
)['expected'].setdefault(value,
|
|
||||||
{}).setdefault(inv_act,
|
|
||||||
[]).append(option_path)
|
|
||||||
if current_action is None:
|
|
||||||
current_action = action
|
|
||||||
elif current_action != action:
|
|
||||||
self.tiramisu_web.set_remotable(option_path, form)
|
|
||||||
if inverse:
|
|
||||||
act = 'show'
|
|
||||||
inv_act = 'hide'
|
|
||||||
else:
|
|
||||||
act = 'hide'
|
|
||||||
inv_act = 'show'
|
|
||||||
for exp in expected:
|
|
||||||
self.requires.setdefault(path,
|
|
||||||
{'expected': {}}
|
|
||||||
)['expected'].setdefault(exp,
|
|
||||||
{}).setdefault(act,
|
|
||||||
[]).append(option_path)
|
|
||||||
self.requires[path].setdefault('default', {}).setdefault(inv_act, []).append(option_path)
|
|
||||||
else:
|
else:
|
||||||
self.tiramisu_web.set_remotable(option_path, form)
|
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':
|
||||||
|
# transitive 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
|
||||||
|
self.tiramisu_web.set_remotable(option_path, form, require_option)
|
||||||
|
if require_option.option.requires():
|
||||||
|
for reqs in require_option.option.requires():
|
||||||
|
for req in reqs:
|
||||||
|
for subopt, subexp in req[0]:
|
||||||
|
if not isinstance(subopt, tuple):
|
||||||
|
self.tiramisu_web.set_remotable(subopt.impl_getpath(), form)
|
||||||
|
if isinstance(option, ChoiceOption):
|
||||||
|
require_option = self.tiramisu_web.config.unrestraint.option(option_path)
|
||||||
|
if require_option.value.callbacks():
|
||||||
|
self.tiramisu_web.set_remotable(option_path, form, require_option)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
values = self.tiramisu_web.get_enum(require_option,
|
||||||
|
require_option.option.ismulti(),
|
||||||
|
option_path,
|
||||||
|
require_option.option.properties())
|
||||||
|
for value in values:
|
||||||
|
if value not in expected:
|
||||||
|
self.requires.setdefault(path,
|
||||||
|
{'expected': {}}
|
||||||
|
)['expected'].setdefault(value,
|
||||||
|
{}).setdefault(inv_act,
|
||||||
|
[]).append(option_path)
|
||||||
|
if current_action is None:
|
||||||
|
current_action = action
|
||||||
|
elif current_action != action:
|
||||||
|
self.tiramisu_web.set_remotable(option_path, form)
|
||||||
|
if inverse:
|
||||||
|
act = 'show'
|
||||||
|
inv_act = 'hide'
|
||||||
|
else:
|
||||||
|
act = 'hide'
|
||||||
|
inv_act = 'show'
|
||||||
|
for exp in expected:
|
||||||
|
self.requires.setdefault(path,
|
||||||
|
{'expected': {}}
|
||||||
|
)['expected'].setdefault(exp,
|
||||||
|
{}).setdefault(act,
|
||||||
|
[]).append(option_path)
|
||||||
|
self.requires[path].setdefault('default', {}).setdefault(inv_act, []).append(option_path)
|
||||||
|
else:
|
||||||
|
self.tiramisu_web.set_remotable(option_path, form)
|
||||||
|
|
||||||
def add(self, path, childapi, form):
|
def add(self, path, childapi, form):
|
||||||
#collect id of all options
|
#collect id of all options
|
||||||
|
@ -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,28 +590,32 @@ 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:
|
props = set(childapi.property.get())
|
||||||
# cannot calculated requires with follower without index
|
|
||||||
props = props_no_requires
|
|
||||||
else:
|
|
||||||
props = set(childapi.property.get())
|
|
||||||
obj = self.gen_properties(props,
|
obj = self.gen_properties(props,
|
||||||
isfollower,
|
isfollower,
|
||||||
childapi.option.ismulti())
|
childapi.option.ismulti())
|
||||||
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue