update todict support and tests

This commit is contained in:
Emmanuel Garette 2019-06-21 23:04:04 +02:00
parent 55da00f131
commit 83f05197fb
21 changed files with 2820 additions and 2296 deletions

View File

@ -3,12 +3,12 @@ from py.test import raises
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config, value_list, global_owner
from tiramisu.setting import owners
from tiramisu import ChoiceOption, StrOption, OptionDescription, Config
from tiramisu.error import ConfigError
from tiramisu import undefined, Params, ParamValue, ParamOption
from tiramisu.api import TIRAMISU_VERSION
from tiramisu.storage import list_sessions
@ -32,12 +32,13 @@ def return_error(*args, **kwargs):
raise Exception('test')
def test_choiceoption():
def test_choiceoption(config_type):
choice = ChoiceOption('choice', '', values=('val1', 'val2'))
odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc)
cfg.property.read_write()
owner = cfg.owner.get()
cfg = get_config(cfg, config_type)
owner = global_owner(cfg, config_type)
assert cfg.option('choice').owner.get() == owners.default
assert cfg.option('choice').owner.isdefault()
#
@ -53,15 +54,16 @@ def test_choiceoption():
assert cfg.option('choice').owner.get() == owners.default
assert cfg.option('choice').owner.isdefault()
#
assert cfg.option('choice').value.list() == ('val1', 'val2')
assert value_list(cfg.option('choice').value.list()) == ('val1', 'val2')
def test_choiceoption_function():
def test_choiceoption_function(config_type):
choice = ChoiceOption('choice', '', values=return_list)
odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc)
cfg.property.read_write()
owner = cfg.owner.get()
cfg = get_config(cfg, config_type)
owner = global_owner(cfg, config_type)
assert cfg.option('choice').owner.isdefault()
#
cfg.option('choice').value.set('val1')
@ -73,7 +75,7 @@ def test_choiceoption_function():
raises(ValueError, "cfg.option('choice').value.set('no')")
assert cfg.option('choice').owner.isdefault()
#
assert cfg.option('choice').value.list() == ['val1', 'val2']
assert value_list(cfg.option('choice').value.list()) == ('val1', 'val2')
def test_choiceoption_function_error():
@ -100,12 +102,13 @@ def test_choiceoption_function_error_kwargs():
raises(ConfigError, "cfg.option('choice').value.set('val1')")
def test_choiceoption_calc_function():
def test_choiceoption_calc_function(config_type):
choice = ChoiceOption('choice', "", values=return_calc_list, values_params=Params((ParamValue('val1'),)))
odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc)
cfg.property.read_write()
owner = cfg.owner.get()
cfg = get_config(cfg, config_type)
owner = global_owner(cfg, config_type)
assert cfg.option('choice').owner.isdefault()
#
cfg.option('choice').value.set('val1')
@ -118,7 +121,7 @@ def test_choiceoption_calc_function():
assert cfg.option('choice').owner.isdefault()
def test_choiceoption_calc_opt_function():
def test_choiceoption_calc_opt_function(config_type):
str_ = StrOption('str', '', 'val1')
choice = ChoiceOption('choice',
"",
@ -128,6 +131,7 @@ def test_choiceoption_calc_opt_function():
cfg = Config(odesc)
cfg.property.read_write()
owner = cfg.owner.get()
cfg = get_config(cfg, config_type)
assert cfg.option('choice').owner.isdefault()
#
cfg.option('choice').value.set('val1')
@ -149,13 +153,13 @@ def test_choiceoption_calc_opt_function_propertyerror():
odesc = OptionDescription('od', '', [str_, choice])
cfg = Config(odesc)
cfg.property.read_write()
if TIRAMISU_VERSION == 2:
raises(ValueError, "cfg.option('choice').value.set('no')")
else:
raises(ConfigError, "cfg.option('choice').value.set('no')")
#def test_choiceoption_calc_opt_multi_function(config_type):
def test_choiceoption_calc_opt_multi_function():
# FIXME
config_type = 'tiramisu'
str_ = StrOption('str', '', ['val1'], multi=True)
choice = ChoiceOption('choice',
"",
@ -173,6 +177,7 @@ def test_choiceoption_calc_opt_multi_function():
cfg = Config(odesc)
cfg.property.read_write()
owner = cfg.owner.get()
cfg = get_config(cfg, config_type, True)
assert cfg.option('choice').owner.isdefault()
assert cfg.option('choice').value.get() == []
#
@ -193,7 +198,7 @@ def test_choiceoption_calc_opt_multi_function():
raises(ValueError, "cfg.option('ch2').value.get()")
def test_choiceoption_calc_opt_multi_function_kwargs():
def test_choiceoption_calc_opt_multi_function_kwargs(config_type):
str_ = StrOption('str', '', ['val1'], multi=True)
choice = ChoiceOption('choice',
"",
@ -211,6 +216,7 @@ def test_choiceoption_calc_opt_multi_function_kwargs():
cfg = Config(odesc)
cfg.property.read_write()
owner = cfg.owner.get()
# FIXME cfg = get_config(cfg, config_type)
assert cfg.option('choice').owner.isdefault()
assert cfg.option('choice').value.get() == []
#

View File

@ -7,6 +7,7 @@ import weakref
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config, value_list, global_owner
from tiramisu import Config
from tiramisu.config import SubConfig
@ -44,13 +45,14 @@ def make_description():
return descr
def test_base_config():
def test_base_config(config_type):
"""making a :class:`tiramisu.config.Config()` object
and a :class:`tiramisu.option.OptionDescription()` object
"""
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
cfg = Config(descr)
cfg = get_config(cfg, config_type)
assert cfg.option('dummy').value.get() is False
#dmo = cfg.unwrap_from_path('dummy')
#assert dmo.impl_getname() == 'dummy'
@ -87,9 +89,12 @@ def test_base_config_force_permissive():
def test_base_config_in_a_tree():
# FIXME
config_type = 'tiramisu'
"how options are organized into a tree, see :ref:`tree`"
descr = make_description()
config = Config(descr)
config = get_config(config, config_type)
#
config.option('bool').value.set(False)
#
@ -216,11 +221,12 @@ def test_get_modified_values():
assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', tuple()), ('user', 'user'))
def test_get_modified_values_not_modif():
def test_get_modified_values_not_modif(config_type):
g1 = StrOption('g1', '', multi=True)
d1 = OptionDescription('od', '', [g1])
root = OptionDescription('root', '', [d1])
config = Config(root)
config = get_config(config, config_type)
assert config.option('od.g1').value.get() == []
value = config.option('od.g1').value.get()
value.append('val')
@ -249,12 +255,13 @@ def test_cannot_assign_value_to_option_description():
raises(APIError, "cfg.option('gc').value.set(3)")
def test_config_multi():
def test_config_multi(config_type):
i1 = IntOption('test1', '', multi=True)
i2 = IntOption('test2', '', multi=True, default_multi=1)
i3 = IntOption('test3', '', default=[2], multi=True, default_multi=1)
od = OptionDescription('test', '', [i1, i2, i3])
config = Config(od)
config = get_config(config, config_type)
assert config.option('test1').value.get() == []
assert config.option('test2').value.get() == []
config.option('test2').value.set([undefined])
@ -282,20 +289,24 @@ def test_prefix_error():
def test_no_validation():
# FIXME
config_type = 'tiramisu'
i1 = IntOption('test1', '')
od = OptionDescription('test', '', [i1])
config = Config(od)
config.property.read_write()
config.option('test1').value.set(1)
raises(ValueError, "config.option('test1').value.set('yes')")
assert config.option('test1').value.get() == 1
cfg = get_config(config, config_type)
cfg.option('test1').value.set(1)
raises(ValueError, "cfg.option('test1').value.set('yes')")
assert cfg.option('test1').value.get() == 1
config.property.pop('validator')
config.option('test1').value.set('yes')
assert config.option('test1').value.get() == 'yes'
config.property.add('validator')
raises(ValueError, "config.option('test1').value.get()")
config.option('test1').value.reset()
assert config.option('test1').value.get() is None
cfg = get_config(config, config_type)
cfg.option('test1').value.set('yes')
assert cfg.option('test1').value.get() == 'yes'
cfg.property.add('validator')
raises(ValueError, "cfg.option('test1').value.get()")
cfg.option('test1').value.reset()
assert cfg.option('test1').value.get() is None
def test_subconfig():
@ -325,30 +336,33 @@ def test_config_invalidsession():
raises(ValueError, 'Config(o2, session_id=2)')
def test_config_od_name():
def test_config_od_name(config_type):
i = IntOption('i', '')
s = SymLinkOption('s', i)
o = OptionDescription('val', '', [i, s])
o2 = OptionDescription('val', '', [o])
c = Config(o2)
c = get_config(c, config_type)
assert c.option('val.i').option.name() == 'i'
assert c.option('val.s').option.name() == 's'
assert c.option('val.s').option.name(follow_symlink=True) == 'i'
def test_config_od_type():
def test_config_od_type(config_type):
i = IntOption('i', '')
o = OptionDescription('val', '', [i])
o2 = OptionDescription('val', '', [o])
c = Config(o2)
c = get_config(c, config_type)
assert c.option('val.i').option.type() == 'integer'
def test_config_default():
def test_config_default(config_type):
i = IntOption('i', '', 8)
o = OptionDescription('val', '', [i])
o2 = OptionDescription('val', '', [o])
c = Config(o2)
c = get_config(c, config_type)
assert c.option('val.i').value.default() == 8
c.option('val.i').value.set(9)
assert c.option('val.i').value.get() == 9

View File

@ -3,6 +3,7 @@ from py.test import raises
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config, value_list, global_owner
from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \
BoolOption, FilenameOption, UnicodeOption, SymLinkOption, IPOption, \
@ -59,7 +60,7 @@ def test_str():
c # does not crash
def test_make_dict():
def test_make_dict(config_type):
"serialization of the whole config to a dict"
descr = OptionDescription("opt", "", [
OptionDescription("s1", "", [
@ -69,6 +70,7 @@ def test_make_dict():
config = Config(descr)
config.property.read_write()
config.permissive.set(frozenset(['hidden']))
config = get_config(config, config_type)
d = config.value.dict()
assert d == {"s1.a": False, "int": 42}
config.option('int').value.set(43)
@ -77,12 +79,14 @@ def test_make_dict():
assert d == {"s1.a": True, "int": 43}
d2 = config.value.dict(flatten=True)
assert d2 == {'a': True, 'int': 43}
if config_type == 'tiramisu':
# FIXME
raises(ValueError, 'd2 = config.value.dict(withvalue="3")')
d = config.forcepermissive.value.dict()
assert d == {"s1.a": True, "s1.b": False, "int": 43}
def test_make_dict_with_disabled():
def test_make_dict_with_disabled(config_type):
descr = OptionDescription("opt", "", [
OptionDescription("s1", "", [
BoolOption("a", "", default=False),
@ -93,7 +97,9 @@ def test_make_dict_with_disabled():
IntOption("int", "", default=42)])
config = Config(descr)
config.property.read_only()
config = get_config(config, config_type)
assert config.value.dict() == {"s1.a": False, "int": 42}
if config_type == 'tiramisu':
assert config.forcepermissive.value.dict() == {"s1.a": False, "int": 42}
assert config.unrestraint.value.dict() == {"int": 42, "s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False}
@ -114,7 +120,7 @@ def test_make_dict_with_disabled_withoption():
assert config.unrestraint.value.dict(withoption="a") == {"s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False}
def test_make_dict_with_disabled_in_callback():
def test_make_dict_with_disabled_in_callback(config_type):
descr = OptionDescription("opt", "", [
OptionDescription("s1", "", [
BoolOption("a", "", default=False),
@ -125,11 +131,12 @@ def test_make_dict_with_disabled_in_callback():
IntOption("int", "", default=42)])
config = Config(descr)
config.property.read_only()
config = get_config(config, config_type)
d = config.value.dict()
assert d == {"s1.a": False, "int": 42}
def test_make_dict_fullpath():
def test_make_dict_fullpath(config_type):
descr = OptionDescription("root", "", [
OptionDescription("opt", "", [
OptionDescription("s1", "", [
@ -142,9 +149,14 @@ def test_make_dict_fullpath():
IntOption("introot", "", default=42)])
config = Config(descr)
config.property.read_only()
config = get_config(config, config_type)
assert config.value.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
if config_type == 'tiramisu':
# FIXME
assert config.option('opt').value.dict() == {"s1.a": False, "int": 42}
assert config.value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
if config_type == 'tiramisu':
# FIXME
assert config.option('opt').value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42}
@ -273,10 +285,11 @@ def test_does_not_find_in_config():
raises(AttributeError, "list(conf.option.find('IDontExist'))")
def test_filename():
def test_filename(config_type):
a = FilenameOption('a', '')
o = OptionDescription('o', '', [a])
cfg = Config(o)
# FIXME cfg = get_config(cfg, config_type)
cfg.option('a').value.set('/')
cfg.option('a').value.set('/tmp')
cfg.option('a').value.set('/tmp/')

View File

@ -1,5 +1,6 @@
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config, value_list, global_owner
import warnings, sys
from py.test import raises
@ -14,7 +15,7 @@ def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def test_domainname():
def test_domainname(config_type):
d = DomainnameOption('d', '')
f = DomainnameOption('f', '', allow_without_dot=True)
g = DomainnameOption('g', '', allow_ip=True)
@ -22,6 +23,7 @@ def test_domainname():
od = OptionDescription('a', '', [d, f, g, h])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
#
cfg.option('d').value.set('toto.com')
raises(ValueError, "cfg.option('d').value.set('toto')")
@ -40,6 +42,8 @@ def test_domainname():
cfg.option('f').value.set('d')
cfg.option('f').value.set('d.t')
#
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('f').value.set('192.168.1.1')")
raises(ValueError, "cfg.option('f').value.set('192.168.1.0/24')")
#
@ -49,22 +53,27 @@ def test_domainname():
raises(ValueError, "cfg.option('g').value.set('192.168.1.0/24')")
#
cfg.option('h').value.set('toto.com')
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('h').value.set('192.168.1.0')")
raises(ValueError, "cfg.option('h').value.set('192.168.1.29')")
cfg.option('h').value.set('192.168.1.0/24')
def test_domainname_upper():
def test_domainname_upper(config_type):
d = DomainnameOption('d', '')
od = OptionDescription('a', '', [d])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('d').value.set('toto.com')
msg = _('some characters are uppercase')
has_error = False
try:
cfg.option('d').value.set('TOTO.COM')
except ValueError as err:
if config_type != 'tiramisu-api':
# FIXME
assert msg in str(err)
has_error = True
assert has_error is True
@ -72,12 +81,14 @@ def test_domainname_upper():
try:
cfg.option('d').value.set('toTo.com')
except ValueError as err:
if config_type != 'tiramisu-api':
# FIXME
assert msg in str(err)
has_error = True
assert has_error is True
def test_domainname_warning():
def test_domainname_warning(config_type):
d = DomainnameOption('d', '', warnings_only=True)
f = DomainnameOption('f', '', allow_without_dot=True, warnings_only=True)
g = DomainnameOption('g', '', allow_ip=True, warnings_only=True)
@ -85,9 +96,12 @@ def test_domainname_warning():
warnings.simplefilter("always", ValueWarning)
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('d').value.set('toto.com')
raises(ValueError, "cfg.option('d').value.set('toto')")
cfg.option('d').value.set('toto3.com')
if config_type != 'tiramisu-api':
# FIXME
with warnings.catch_warnings(record=True) as w:
cfg.option('d').value.set('toto_super.com')
assert len(w) == 1
@ -102,17 +116,21 @@ def test_domainname_warning():
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')")
cfg.option('f').value.set('d')
cfg.option('f').value.set('d.t')
#
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('f').value.set('192.168.1.1')")
cfg.option('g').value.set('toto.com')
cfg.option('g').value.set('192.168.1.0')
cfg.option('g').value.set('192.168.1.29')
def test_special_domain_name():
def test_special_domain_name(config_type):
"""domain name option that starts with a number or not
"""
d = DomainnameOption('d', '')
@ -120,39 +138,43 @@ def test_special_domain_name():
od = OptionDescription('a', '', [d, e])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('d').value.set('1toto.com')
cfg.option('d').value.set('123toto.com')
cfg.option('e').value.set('toto')
cfg.option('e').value.set('1toto')
def test_domainname_netbios():
def test_domainname_netbios(config_type):
d = DomainnameOption('d', '', type_='netbios')
e = DomainnameOption('e', '', "toto", type_='netbios')
od = OptionDescription('a', '', [d, e])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('d').value.set('toto.com')")
cfg.option('d').value.set('toto')
raises(ValueError, "cfg.option('d').value.set('domainnametoolong')")
def test_domainname_hostname():
def test_domainname_hostname(config_type):
d = DomainnameOption('d', '', type_='hostname')
e = DomainnameOption('e', '', "toto", type_='hostname')
od = OptionDescription('a', '', [d, e])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('d').value.set('toto.com')")
cfg.option('d').value.set('toto')
cfg.option('d').value.set('domainnametoolong')
def test_email():
def test_email(config_type):
e = EmailOption('e', '')
od = OptionDescription('a', '', [e])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('e').value.set('foo-bar.baz@example.com')
cfg.option('e').value.set('root@foo.com')
cfg.option('e').value.set('root@domain')
@ -161,25 +183,34 @@ def test_email():
raises(ValueError, "cfg.option('e').value.set('root[]@domain')")
def test_url():
def test_url(config_type):
u = URLOption('u', '')
od = OptionDescription('a', '', [u])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('u').value.set('http://foo.com')
cfg.option('u').value.set('https://foo.com')
cfg.option('u').value.set('https://foo.com/')
raises(ValueError, "cfg.option('u').value.set(1)")
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('u').value.set('ftp://foo.com')")
raises(ValueError, "cfg.option('u').value.set('foo.com')")
raises(ValueError, "cfg.option('u').value.set(':/foo.com')")
raises(ValueError, "cfg.option('u').value.set('foo.com/http://')")
cfg.option('u').value.set('https://foo.com/index.html')
cfg.option('u').value.set('https://foo.com/index.html?var=value&var2=val2')
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('u').value.set('https://foo.com/index\\n.html')")
cfg.option('u').value.set('https://foo.com:8443')
cfg.option('u').value.set('https://foo.com:8443/')
cfg.option('u').value.set('https://foo.com:8443/index.html')
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('u').value.set('https://foo.com:84438989')")
cfg.option('u').value.set('https://foo.com:8443/INDEX')
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('u').value.set('https://FOO.COM:8443')")

View File

@ -1,5 +1,6 @@
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config, value_list, global_owner
import warnings
from py.test import raises
@ -13,25 +14,34 @@ def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def test_ip():
def test_ip(config_type):
a = IPOption('a', '')
b = IPOption('b', '', private_only=True)
d = IPOption('d', '', warnings_only=True, private_only=True)
warnings.simplefilter("always", ValueWarning)
od = OptionDescription('od', '', [a, b, d])
config = Config(od)
config = get_config(config, config_type)
config.option('a').value.set('192.168.1.1')
config.option('a').value.set('192.168.1.0')
config.option('a').value.set('88.88.88.88')
config.option('a').value.set('0.0.0.0')
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "config.option('a').value.set('255.255.255.0')")
config.option('b').value.set('192.168.1.1')
config.option('b').value.set('192.168.1.0')
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "config.option('b').value.set('88.88.88.88')")
config.option('b').value.set('0.0.0.0')
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "config.option('b').value.set('255.255.255.0')")
raises(ValueError, "config.option('a').value.set('333.0.1.20')")
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "IPOption('a', 'ip', default='192.000.023.01')")
with warnings.catch_warnings(record=True) as w:
config.option('d').value.set('88.88.88.88')
@ -60,44 +70,55 @@ def test_ip_default():
c.option('a').value.get() == '88.88.88.88'
def test_ip_reserved():
def test_ip_reserved(config_type):
a = IPOption('a', '')
b = IPOption('b', '', allow_reserved=True)
c = IPOption('c', '', warnings_only=True)
od = OptionDescription('od', '', [a, b, c])
warnings.simplefilter("always", ValueWarning)
cfg = Config(od)
cfg = get_config(cfg, config_type)
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('a').value.set('240.94.1.1')")
cfg.option('b').value.set('240.94.1.1')
if config_type != 'tiramisu-api':
# FIXME
with warnings.catch_warnings(record=True) as w:
cfg.option('c').value.set('240.94.1.1')
assert len(w) == 1
def test_network():
def test_network(config_type):
a = NetworkOption('a', '')
b = NetworkOption('b', '', warnings_only=True)
od = OptionDescription('od', '', [a, b])
warnings.simplefilter("always", ValueWarning)
cfg = Config(od)
cfg = get_config(cfg, config_type)
cfg.option('a').value.set('192.168.1.1')
cfg.option('a').value.set('192.168.1.0')
cfg.option('a').value.set('88.88.88.88')
cfg.option('a').value.set('0.0.0.0')
raises(ValueError, "cfg.option('a').value.set(1)")
raises(ValueError, "cfg.option('a').value.set('1.1.1.1.1')")
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('a').value.set('255.255.255.0')")
raises(ValueError, "cfg.option('a').value.set('192.168.001.0')")
raises(ValueError, "cfg.option('a').value.set('333.168.1.1')")
if config_type != 'tiramisu-api':
# FIXME
with warnings.catch_warnings(record=True) as w:
cfg.option('b').value.set('255.255.255.0')
assert len(w) == 1
def test_network_cidr():
def test_network_cidr(config_type):
a = NetworkOption('a', '', cidr=True)
od = OptionDescription('od', '', [a])
cfg = Config(od)
# FIXME cfg = get_config(cfg, config_type)
cfg.option('a').value.set('192.168.1.1/32')
cfg.option('a').value.set('192.168.1.0/24')
cfg.option('a').value.set('88.88.88.88/32')
@ -111,11 +132,14 @@ def test_network_invalid():
raises(ValueError, "NetworkOption('a', '', default='toto')")
def test_netmask():
def test_netmask(config_type):
a = NetmaskOption('a', '')
od = OptionDescription('od', '', [a])
cfg = Config(od)
cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set('192.168.1.1.1')")
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('a').value.set('192.168.1.1')")
raises(ValueError, "cfg.option('a').value.set('192.168.1.0')")
raises(ValueError, "cfg.option('a').value.set('88.88.88.88')")
@ -125,10 +149,11 @@ def test_netmask():
cfg.option('a').value.set('255.255.255.0')
def test_broadcast():
def test_broadcast(config_type):
a = BroadcastOption('a', '')
od = OptionDescription('od', '', [a])
cfg = Config(od)
# FIXME cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set('192.168.1.255.1')")
raises(ValueError, "cfg.option('a').value.set('192.168.001.255')")
raises(ValueError, "cfg.option('a').value.set('192.168.0.300')")
@ -139,7 +164,7 @@ def test_broadcast():
cfg.option('a').value.set('255.255.255.0')
def test_port():
def test_port(config_type):
a = PortOption('a', '')
b = PortOption('b', '', allow_zero=True)
c = PortOption('c', '', allow_zero=True, allow_registred=False)
@ -148,6 +173,7 @@ def test_port():
f = PortOption('f', '', allow_private=True)
od = OptionDescription('od', '', [a, b, c, d, e, f])
cfg = Config(od)
# FIXME cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set('0')")
cfg.option('a').value.set('1')
cfg.option('a').value.set('1023')
@ -202,7 +228,7 @@ def test_port():
raises(ValueError, "cfg.option('f').value.set('65536')")
def test_port_range():
def test_port_range(config_type):
a = PortOption('a', '', allow_range=True)
b = PortOption('b', '', allow_range=True, allow_zero=True)
c = PortOption('c', '', allow_range=True, allow_zero=True, allow_registred=False)
@ -211,6 +237,7 @@ def test_port_range():
f = PortOption('f', '', allow_range=True, allow_private=True)
od = OptionDescription('od', '', [a, b, c, d, e, f])
cfg = Config(od)
# FIXME cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set('0')")
cfg.option('a').value.set('1')
cfg.option('a').value.set('1023')

View File

@ -1,6 +1,7 @@
# coding: utf-8
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config, value_list, global_owner
from py.test import raises
from tiramisu.setting import groups, owners
@ -61,30 +62,34 @@ def make_description():
return descr
def test_base_config():
def test_base_config(config_type):
descr = make_description()
api = Config(descr)
api.property.read_write()
assert api.option('creole.general.activer_proxy_client').value.get() is False
assert api.option('creole.general.nom_machine').value.get() == "eoleng"
assert api.option.find('nom_machine', first=True).value.get() == "eoleng"
cfg = Config(descr)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('creole.general.activer_proxy_client').value.get() is False
assert cfg.option('creole.general.nom_machine').value.get() == "eoleng"
if config_type != 'tiramisu-api':
assert cfg.option.find('nom_machine', first=True).value.get() == "eoleng"
result = {'general.numero_etab': None, 'general.nombre_interfaces': 1,
'general.serveur_ntp': [], 'interface1.ip_admin_eth0.ip_admin_eth0': None,
'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris',
'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine':
'eoleng', 'general.activer_proxy_client': False}
assert api.option('creole').value.dict() == result
assert cfg.option('creole').value.dict() == result
result = {'serveur_ntp': [], 'mode_conteneur_actif': False,
'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None,
'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client':
False, 'nombre_interfaces': 1}
assert api.option('creole').value.dict(flatten=True) == result
assert cfg.option('creole').value.dict(flatten=True) == result
if config_type == 'tiramisu-api':
cfg.send()
def test_make_dict_filter():
descr = make_description()
api = Config(descr)
api.property.read_write()
cfg = Config(descr)
cfg.property.read_write()
subresult = {'numero_etab': None, 'nombre_interfaces': 1,
'serveur_ntp': [], 'mode_conteneur_actif': False,
'time_zone': 'Paris', 'nom_machine': 'eoleng',
@ -92,17 +97,17 @@ def test_make_dict_filter():
result = {}
for key, value in subresult.items():
result['general.' + key] = value
assert api.option('creole').value.dict(withoption='numero_etab') == result
raises(AttributeError, "api.option('creole').value.dict(withoption='numero_etab', withvalue='toto')")
assert api.option('creole').value.dict(withoption='numero_etab', withvalue=None) == result
assert api.option('creole.general').value.dict(withoption='numero_etab') == subresult
assert cfg.option('creole').value.dict(withoption='numero_etab') == result
raises(AttributeError, "cfg.option('creole').value.dict(withoption='numero_etab', withvalue='toto')")
assert cfg.option('creole').value.dict(withoption='numero_etab', withvalue=None) == result
assert cfg.option('creole.general').value.dict(withoption='numero_etab') == subresult
def test_get_group_type():
descr = make_description()
api = Config(descr)
api.property.read_write()
grp = api.option('creole.general')
cfg = Config(descr)
cfg.property.read_write()
grp = cfg.option('creole.general')
assert grp.group_type() == groups.family
assert grp.group_type() == 'family'
assert isinstance(grp.group_type(), groups.GroupType)
@ -110,55 +115,55 @@ def test_get_group_type():
def test_iter_on_groups():
descr = make_description()
api = Config(descr)
api.property.read_write()
result = api.option('creole').list('optiondescription',
cfg = Config(descr)
cfg.property.read_write()
result = cfg.option('creole').list('optiondescription',
group_type=groups.family)
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1']
for i in api.option('creole').list('optiondescription',
for i in cfg.option('creole').list('optiondescription',
group_type=groups.family):
#test StopIteration
break
result = api.option('creole').list('option',
result = cfg.option('creole').list('option',
group_type=groups.family)
assert list(result) == []
result = api.option('creole.general').list('optiondescription',
result = cfg.option('creole.general').list('optiondescription',
group_type=groups.family)
assert list(result) == []
def test_list_recursive():
descr = make_description()
api = Config(descr)
api.property.read_write()
result = api.option('creole').list('all')
cfg = Config(descr)
cfg.property.read_write()
result = cfg.option('creole').list('all')
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1']
#
result = api.option.list(recursive=True)
result = cfg.option.list(recursive=True)
group_names = [res.option.name() for res in result]
assert group_names == ['numero_etab', 'nom_machine', 'nombre_interfaces',
'activer_proxy_client', 'mode_conteneur_actif',
'serveur_ntp', 'time_zone', 'ip_admin_eth0',
'netmask_admin_eth0']
result = list(api.option.list(recursive=True, type='optiondescription'))
result = list(cfg.option.list(recursive=True, type='optiondescription'))
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'ip_admin_eth0', 'interface1', 'creole']
def test_iter_on_groups_force_permissive():
descr = make_description()
api = Config(descr)
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
result = api.forcepermissive.option('creole.general').list()
cfg = Config(descr)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
result = cfg.forcepermissive.option('creole.general').list()
group_names = [res.option.name() for res in result]
ass = ['numero_etab', 'nom_machine', 'nombre_interfaces',
'activer_proxy_client', 'mode_conteneur_actif',
'mode_conteneur_actif2', 'serveur_ntp', 'time_zone']
assert group_names == ass
# mode_conteneur_actif2 is not visible is not forcepermissive
result = api.option('creole.general').list()
result = cfg.option('creole.general').list()
group_names = [res.option.name() for res in result]
ass.remove('mode_conteneur_actif2')
assert group_names == ass
@ -166,10 +171,10 @@ def test_iter_on_groups_force_permissive():
def test_iter_group_on_groups_force_permissive():
descr = make_description()
api = Config(descr)
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
result = api.forcepermissive.option('creole').list(type='optiondescription',
cfg = Config(descr)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
result = cfg.forcepermissive.option('creole').list(type='optiondescription',
group_type=groups.family)
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1', 'new']
@ -177,27 +182,27 @@ def test_iter_group_on_groups_force_permissive():
def test_iter_on_groups_props():
descr = make_description()
api = Config(descr)
api.property.read_write()
api.option('creole.interface1').property.add('disabled')
result = api.option('creole').list(type='optiondescription',
cfg = Config(descr)
cfg.property.read_write()
cfg.option('creole.interface1').property.add('disabled')
result = cfg.option('creole').list(type='optiondescription',
group_type=groups.family)
group_names = [res.option.name() for res in result]
assert group_names == ['general']
def test_iter_on_empty_group():
api = Config(OptionDescription("name", "descr", []))
api.property.read_write()
result = list(api.option.list(type='optiondescription'))
cfg = Config(OptionDescription("name", "descr", []))
cfg.property.read_write()
result = list(cfg.option.list(type='optiondescription'))
assert result == []
def test_iter_not_group():
api = Config(OptionDescription("name", "descr", []))
api.property.read_write()
cfg = Config(OptionDescription("name", "descr", []))
cfg.property.read_write()
try:
list(api.option.list(type='optiondescription', group_type='family'))
list(cfg.option.list(type='optiondescription', group_type='family'))
except AssertionError:
pass
else:
@ -211,28 +216,31 @@ def test_groups_with_leader():
assert interface1.impl_get_group_type() == groups.leadership
def test_groups_is_leader():
def test_groups_is_leader(config_type):
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, default_multi='value')
interface1 = Leadership('leadership', '', [ip_admin_eth0, netmask_admin_eth0])
var = StrOption('var', "ip réseau autorisé", multi=True)
od2 = OptionDescription('od2', '', [var])
od1 = OptionDescription('od', '', [interface1, od2])
api = Config(od1)
assert not api.option('od2').option.isleadership()
assert api.option('leadership').option.isleadership()
assert not api.option('od2.var').option.isleader()
assert not api.option('od2.var').option.isfollower()
assert api.option('leadership.ip_admin_eth0').option.ismulti()
assert api.option('leadership.netmask_admin_eth0').option.ismulti()
assert not api.option('leadership.ip_admin_eth0').option.issubmulti()
assert not api.option('leadership.netmask_admin_eth0').option.issubmulti()
assert api.option('leadership.ip_admin_eth0').option.isleader()
assert not api.option('leadership.ip_admin_eth0').option.isfollower()
assert not api.option('leadership.netmask_admin_eth0').option.isleader()
assert api.option('leadership.netmask_admin_eth0').option.isfollower()
assert api.option('leadership.netmask_admin_eth0').option.path() == 'leadership.netmask_admin_eth0'
assert api.option('leadership.netmask_admin_eth0').option.defaultmulti() == 'value'
cfg = Config(od1)
cfg = get_config(cfg, config_type)
assert not cfg.option('od2').option.isleadership()
assert cfg.option('leadership').option.isleadership()
assert not cfg.option('od2.var').option.isleader()
assert not cfg.option('od2.var').option.isfollower()
assert cfg.option('leadership.ip_admin_eth0').option.ismulti()
assert cfg.option('leadership.netmask_admin_eth0').option.ismulti()
assert not cfg.option('leadership.ip_admin_eth0').option.issubmulti()
assert not cfg.option('leadership.netmask_admin_eth0').option.issubmulti()
assert cfg.option('leadership.ip_admin_eth0').option.isleader()
assert not cfg.option('leadership.ip_admin_eth0').option.isfollower()
assert not cfg.option('leadership.netmask_admin_eth0').option.isleader()
assert cfg.option('leadership.netmask_admin_eth0').option.isfollower()
assert cfg.option('leadership.netmask_admin_eth0').option.path() == 'leadership.netmask_admin_eth0'
assert cfg.option('leadership.netmask_admin_eth0').option.defaultmulti() == 'value'
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_in_root():
@ -252,57 +260,70 @@ def test_groups_with_leader_in_config():
assert interface1.impl_get_group_type() == groups.leadership
def test_groups_with_leader_make_dict():
def test_groups_with_leader_make_dict(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
api = Config(od)
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []}
assert api.option('ip_admin_eth0.ip_admin_eth0').value.len() == 0
assert api.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 0
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.len() == 2
assert api.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 2
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]}
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []}
if config_type != 'tiramisu-api':
# FIXME useful? already in leadership
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 0
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 0
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
if config_type != 'tiramisu-api':
# FIXME
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 2
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 2
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]}
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_default_value():
def test_groups_with_leader_default_value(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
api = Config(od)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert api.option('ip_admin_eth0.ip_admin_eth0').value.default() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2']
assert api.option('ip_admin_eth0.ip_admin_eth0').value.default() == []
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == []
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2']
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == []
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_default_value_2():
def test_groups_with_leader_default_value_2(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", ['ip1', 'ip2'], multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='netmask1', multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
api = Config(od)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2']
assert api.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2']
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip3', 'ip4'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip3', 'ip4']
assert api.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2']
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2']
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2']
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip3', 'ip4'])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip3', 'ip4']
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2']
#
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('netmask2')
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask2'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('netmask2')
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask2'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_hidden_in_config():
@ -310,14 +331,14 @@ def test_groups_with_leader_hidden_in_config():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
api = Config(od)
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
cfg = Config(od)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
def test_groups_with_leader_hidden_in_config2():
@ -325,53 +346,67 @@ def test_groups_with_leader_hidden_in_config2():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
api = Config(od)
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg = Config(od)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#del
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.property.pop('hidden')
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
api.property.add('hidden')
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.property.pop('hidden')
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
cfg.property.pop('hidden')
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
cfg.property.add('hidden')
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
cfg.property.pop('hidden')
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
def test_groups_with_leader_reset_empty():
def test_groups_with_leader_reset_empty(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1])
api = Config(od_)
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
raises(LeadershipError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()")
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
cfg = Config(od_)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
if config_type != 'tiramisu-api':
raises(LeadershipError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_reset_out_of_range():
def test_groups_with_leader_reset_out_of_range(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1])
api = Config(od_)
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
raises(LeadershipError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.reset()")
raises(IndexError, "api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)")
cfg_ori = Config(od_)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
if config_type != 'tiramisu-api':
# FIXME
raises(LeadershipError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.reset()")
raises(IndexError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)")
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_hidden_in_config3():
@ -380,14 +415,14 @@ def test_groups_with_leader_hidden_in_config3():
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])
od = OptionDescription('root', '', [interface1])
api = Config(od)
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
cfg = Config(od)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
def test_allowed_groups():
@ -398,20 +433,26 @@ def test_allowed_groups():
raises(ValueError, "interface1.impl_set_group_type('toto')")
def test_values_with_leader_disabled_leader():
def test_values_with_leader_disabled_leader(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
api.option('ip_admin_eth0.ip_admin_eth0').property.add('disabled')
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('192.168.230.145')")
cfg_ori = Config(maconfig)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
cfg_ori.option('ip_admin_eth0.ip_admin_eth0').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
if config_type != 'tiramisu-api':
# FIXME
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('192.168.230.145')")
if config_type == 'tiramisu-api':
cfg.send()
def test_sub_group_in_leader_group():
@ -428,48 +469,54 @@ def test_group_always_has_multis():
#____________________________________________________________
def test_values_with_leader_and_followers():
def test_values_with_leader_and_followers(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
owner = api.owner.get()
cfg = Config(maconfig)
cfg.property.read_write()
owner = global_owner(cfg, config_type)
cfg = get_config(cfg, config_type)
assert interface1.impl_get_group_type() == groups.leadership
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
#
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0').value.set([None])")
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0').value.pop(0)")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
if config_type != 'tiramisu-api':
# FIXME
raises(APIError, "cfg.option('ip_admin_eth0.netmask_admin_eth0').value.set([None])")
raises(APIError, "cfg.option('ip_admin_eth0.netmask_admin_eth0').value.pop(0)")
if config_type == 'tiramisu-api':
cfg.send()
def test_reset_values_with_leader_and_followers():
def test_reset_values_with_leader_and_followers(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
owner = api.owner.get()
cfg = Config(maconfig)
cfg.property.read_write()
owner = global_owner(cfg, config_type)
cfg = Config(maconfig)
assert interface1.impl_get_group_type() == groups.leadership
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#reset
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
def test_reset_values_with_leader_and_followers_default_value():
@ -478,113 +525,129 @@ def test_reset_values_with_leader_and_followers_default_value():
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_reset_values_with_leader_and_followers_default():
def test_reset_values_with_leader_and_followers_default(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['192.168.230.145'])
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])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
owner = api.owner.get()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg = Config(maconfig)
cfg.property.read_write()
owner = global_owner(cfg, config_type)
cfg = get_config(cfg, config_type)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
if config_type == 'tiramisu-api':
cfg.send()
def test_values_with_leader_and_followers_follower():
def test_values_with_leader_and_followers_follower(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
if config_type != 'tiramisu-api':
raises(LeadershipError,
"api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')")
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
"cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
#
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.pop(1)")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
if config_type != 'tiramisu-api':
# FIXME
raises(APIError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.pop(1)")
#reset
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145',
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145',
'192.168.230.145',
'192.168.230.145'])
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
if config_type == 'tiramisu-api':
cfg.send()
def test_values_with_leader_and_followers_pop():
def test_values_with_leader_and_followers_pop(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.146'])
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145', '192.168.230.146']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.146']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.146'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145', '192.168.230.146']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.146']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
if config_type == 'tiramisu-api':
cfg.send()
def test_values_with_leader_and_followers_leader():
def test_values_with_leader_and_followers_leader(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
raises(LeadershipError, "api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])")
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
if config_type != 'tiramisu-api':
raises(LeadershipError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])")
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
if config_type == 'tiramisu-api':
cfg.send()
def test_values_with_leader_and_followers_leader_pop():
@ -592,97 +655,122 @@ def test_values_with_leader_and_followers_leader_pop():
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])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.146"])
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145", "192.168.230.146"]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (1,)), (('192.168.230.145', '192.168.230.146'), ('255.255.0.0',)), ('user', ('user',))))
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0,)), (('192.168.230.146',), ('255.255.0.0',)), ('user', ('user',))))
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.146"]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149"])
api.option('ip_admin_eth0.netmask_admin_eth0', 3).value.set('255.255.0.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 4).value.set('255.255.0.0')
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 3, 4)), (('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user'))))
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(5)
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 3, 4)), (('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user'))))
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 2, 3)), (('192.168.230.146', "192.168.230.145", "192.168.230.147", "192.168.230.148"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user'))))
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 2)), (('192.168.230.146', "192.168.230.145", "192.168.230.148"), ('255.255.0.0', '255.255.0.0')), ('user', ('user', 'user'))))
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0,)), (('192.168.230.146', "192.168.230.145"), ('255.255.0.0',)), ('user', ('user',))))
cfg = Config(maconfig)
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.146"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145", "192.168.230.146"]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (1,)), (('192.168.230.145', '192.168.230.146'), ('255.255.0.0',)), ('user', ('user',))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0,)), (('192.168.230.146',), ('255.255.0.0',)), ('user', ('user',))))
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.146"]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 3).value.set('255.255.0.0')
cfg.option('ip_admin_eth0.netmask_admin_eth0', 4).value.set('255.255.0.0')
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 3, 4)), (('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user'))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(5)
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 3, 4)), (('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user'))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 2, 3)), (('192.168.230.146', "192.168.230.145", "192.168.230.147", "192.168.230.148"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user'))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 2)), (('192.168.230.146', "192.168.230.145", "192.168.230.148"), ('255.255.0.0', '255.255.0.0')), ('user', ('user', 'user'))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0,)), (('192.168.230.146', "192.168.230.145"), ('255.255.0.0',)), ('user', ('user',))))
def test_values_with_leader_owner():
def test_values_with_leader_owner(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
owner = api.owner.get()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
cfg = Config(maconfig)
cfg.property.read_write()
owner = cfg.owner.get()
cfg = get_config(cfg, config_type)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
def test_values_with_leader_disabled():
def test_values_with_leader_disabled(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
cfg_ori = Config(maconfig)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
if config_type == 'tiramisu-api':
cfg.send()
#delete with value in disabled var
api.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
api.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
#append with value in disabled var
api.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
api.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", '192.168.230.43'])
##append with value in disabled var
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", '192.168.230.43'])
if config_type == 'tiramisu-api':
cfg.send()
def test_multi_non_valid_value():
def test_multi_non_valid_value(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
maconfig = OptionDescription('toto', '', [ip_admin_eth0])
api = Config(maconfig)
api.property.read_write()
api.option('ip_admin_eth0').value.set(['a'])
raises(ValueError, "api.option('ip_admin_eth0').value.set([1])")
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0').value.set(['a'])
raises(ValueError, "cfg.option('ip_admin_eth0').value.set([1])")
if config_type == 'tiramisu-api':
cfg.send()
def test_multi_leader_default_follower():
def test_multi_leader_default_follower(config_type):
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", default_multi="255.255.255.0", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_get_modified_value():
@ -690,32 +778,35 @@ def test_groups_with_leader_get_modified_value():
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])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
compare(api.value.exportation(), ((), (), (), ()))
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0',), (None,), (('192.168.1.1',),), ('user',)))
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0',), (None, (0,)), (('192.168.1.1',), ('255.255.255.255',)), ('user', ('user',))))
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1'])
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0',), (None, (0, 1)), (('192.168.1.1', '192.168.1.1'), ('255.255.255.255', '255.255.255.255')), ('user', ('user', 'user'))))
cfg = Config(maconfig)
cfg.property.read_write()
compare(cfg.value.exportation(), ((), (), (), ()))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0',), (None,), (('192.168.1.1',),), ('user',)))
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0',), (None, (0,)), (('192.168.1.1',), ('255.255.255.255',)), ('user', ('user',))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0',), (None, (0, 1)), (('192.168.1.1', '192.168.1.1'), ('255.255.255.255', '255.255.255.255')), ('user', ('user', 'user'))))
def test_groups_with_leader_importation():
def test_groups_with_leader_importation(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
api.value.importation([['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'], [None, [0, 1]], [['192.168.1.1', '192.168.1.0'], ['255.255.255.255', '255.255.255.0']], ['user', ['user', 'user']]])
api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1', '192.168.1.0']
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.255'
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == 'user'
api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'user'
api.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'user'
cfg = Config(maconfig)
cfg.property.read_write()
cfg.value.importation([['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'], [None, [0, 1]], [['192.168.1.1', '192.168.1.0'], ['255.255.255.255', '255.255.255.0']], ['user', ['user', 'user']]])
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1', '192.168.1.0']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.255'
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == 'user'
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'user'
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'user'
if config_type == 'tiramisu-api':
cfg.send()
def test_wrong_index():
@ -724,15 +815,15 @@ def test_wrong_index():
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('od', '', [interface1])
maconfig = OptionDescription('toto', '', [od1])
api = Config(maconfig)
api.property.read_write()
assert api.option('od.ip_admin_eth0.ip_admin_eth0').option.get()
raises(APIError, "api.option('od.ip_admin_eth0.ip_admin_eth0', 0).option.get()")
assert api.option('od.ip_admin_eth0.netmask_admin_eth0', 0).option.get()
assert api.option('od.ip_admin_eth0').option.get()
raises(APIError, "api.option('od.ip_admin_eth0', 0).option.get()")
assert api.option('od').option.get()
raises(APIError, "api.option('od', 0).option.get()")
cfg = Config(maconfig)
cfg.property.read_write()
assert cfg.option('od.ip_admin_eth0.ip_admin_eth0').option.get()
raises(APIError, "cfg.option('od.ip_admin_eth0.ip_admin_eth0', 0).option.get()")
assert cfg.option('od.ip_admin_eth0.netmask_admin_eth0', 0).option.get()
assert cfg.option('od.ip_admin_eth0').option.get()
raises(APIError, "cfg.option('od.ip_admin_eth0', 0).option.get()")
assert cfg.option('od').option.get()
raises(APIError, "cfg.option('od', 0).option.get()")
def test_without_leader_or_follower():
@ -778,8 +869,8 @@ def test_follower_not_same_not_equal():
interface1 = Leadership('interface1', '', [ip_admin_eth1, netmask_admin_eth1])
od1 = OptionDescription('od', '', [interface0, interface1])
maconfig = OptionDescription('toto', '', [od1])
api = Config(maconfig)
api.property.read_write()
cfg = Config(maconfig)
cfg.property.read_write()
def test_follower_force_store_value():

View File

@ -1,9 +1,9 @@
# coding: utf-8
from .autopath import do_autopath
do_autopath()
# FIXME from .config import config_type, get_config
from py.test import raises
from tiramisu.api import TIRAMISU_VERSION
from tiramisu import Config
from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \
SymLinkOption, Leadership, undefined, Params, ParamOption
@ -78,71 +78,71 @@ def make_description3():
def test_mandatory_ro():
descr = make_description()
api = Config(descr)
api.property.read_only()
cfg = Config(descr)
cfg.property.read_only()
prop = []
try:
api.option('str1').value.get()
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
api.property.read_write()
api.option('str1').value.set('yes')
api.property.read_only()
assert api.option('str1').value.get() == 'yes'
cfg.property.read_write()
cfg.option('str1').value.set('yes')
cfg.property.read_only()
assert cfg.option('str1').value.get() == 'yes'
def test_mandatory_ro_dict():
descr = make_description()
api = Config(descr)
api.property.read_only()
cfg = Config(descr)
cfg.property.read_only()
prop = []
try:
api.value.dict()
cfg.value.dict()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
api.property.read_write()
api.option('str1').value.set('yes')
api.option('unicode2').value.set('yes')
api.property.read_only()
cfg.property.read_write()
cfg.option('str1').value.set('yes')
cfg.option('unicode2').value.set('yes')
cfg.property.read_only()
try:
api.value.dict()
cfg.value.dict()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
api.property.read_write()
api.option('str3').value.set(['yes'])
api.property.read_only()
assert api.value.dict() == {'str': 'abc', 'str1': 'yes', 'str3': ['yes'], 'str4': [], 'unicode2': 'yes'}
cfg.property.read_write()
cfg.option('str3').value.set(['yes'])
cfg.property.read_only()
assert cfg.value.dict() == {'str': 'abc', 'str1': 'yes', 'str3': ['yes'], 'str4': [], 'unicode2': 'yes'}
def test_mandatory_rw():
descr = make_description()
api = Config(descr)
api.property.read_write()
cfg = Config(descr)
cfg.property.read_write()
# not mandatory in rw
api.option('str1').value.get()
api.option('str1').value.set('yes')
assert api.option('str1').value.get() == 'yes'
cfg.option('str1').value.get()
cfg.option('str1').value.set('yes')
assert cfg.option('str1').value.get() == 'yes'
def test_mandatory_default():
descr = make_description()
api = Config(descr)
api.property.read_only()
cfg = Config(descr)
cfg.property.read_only()
#not mandatory in rw
api.option('str').value.get()
api.property.read_write()
api.option('str').value.set('yes')
api.property.read_only()
api.option('str').value.get()
api.property.read_write()
api.option('str').value.set(None)
api.property.read_only()
cfg.option('str').value.get()
cfg.property.read_write()
cfg.option('str').value.set('yes')
cfg.property.read_only()
cfg.option('str').value.get()
cfg.property.read_write()
cfg.option('str').value.set(None)
cfg.property.read_only()
prop = []
try:
api.option('str').value.get()
cfg.option('str').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
@ -150,40 +150,40 @@ def test_mandatory_default():
def test_mandatory_delete():
descr = make_description()
api = Config(descr)
api.property.read_only()
api.option('str').value.get()
cfg = Config(descr)
cfg.property.read_only()
cfg.option('str').value.get()
try:
api.option('str1').value.get()
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
api.property.read_write()
api.option('str1').value.set('yes')
api.property.read_only()
assert api.option('str1').value.get() == 'yes'
api.property.pop('everything_frozen')
cfg.property.read_write()
cfg.option('str1').value.set('yes')
cfg.property.read_only()
assert cfg.option('str1').value.get() == 'yes'
cfg.property.pop('everything_frozen')
prop = []
try:
api.option('str1').value.reset()
cfg.option('str1').value.reset()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
api.option('str').value.reset()
cfg.option('str').value.reset()
assert api.option('str1').value.get() == 'yes'
assert cfg.option('str1').value.get() == 'yes'
#valeur vide : None, '', u'', ...
def test_mandatory_none():
descr = make_description()
api = Config(descr)
api.option('str1').value.set(None)
assert api.option('str1').owner.get() == 'user'
api.property.read_only()
cfg = Config(descr)
cfg.option('str1').value.set(None)
assert cfg.option('str1').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
api.option('str1').value.get()
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
@ -191,13 +191,13 @@ def test_mandatory_none():
def test_mandatory_empty():
descr = make_description()
api = Config(descr)
api.option('str1').value.set('')
assert api.option('str1').owner.get() == 'user'
api.property.read_only()
cfg = Config(descr)
cfg.option('str1').value.set('')
assert cfg.option('str1').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
api.option('str1').value.get()
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
@ -205,23 +205,23 @@ def test_mandatory_empty():
def test_mandatory_multi_none():
descr = make_description()
api = Config(descr)
api.option('str3').value.set([None])
assert api.option('str3').owner.get() == 'user'
api.property.read_only()
cfg = Config(descr)
cfg.option('str3').value.set([None])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
api.option('str3').value.get()
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
api.property.read_write()
api.option('str3').value.set(['yes', None])
assert api.option('str3').owner.get() == 'user'
api.property.read_only()
cfg.property.read_write()
cfg.option('str3').value.set(['yes', None])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
api.option('str3').value.get()
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
@ -229,35 +229,35 @@ def test_mandatory_multi_none():
def test_mandatory_multi_empty():
descr = make_description()
api = Config(descr)
api.option('str3').value.set([])
assert api.option('str3').owner.get() == 'user'
api.property.read_only()
cfg = Config(descr)
cfg.option('str3').value.set([])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
api.option('str3').value.get()
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
api.property.read_write()
api.option('str3').value.set([''])
assert api.option('str3').owner.get() == 'user'
api.property.read_only()
cfg.property.read_write()
cfg.option('str3').value.set([''])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
api.option('str3').value.get()
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
api.property.read_write()
api.option('str3').value.set(['yes', ''])
assert api.option('str3').owner.get() == 'user'
api.property.read_only()
cfg.property.read_write()
cfg.option('str3').value.set(['yes', ''])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
api.option('str3').value.get()
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
@ -265,31 +265,31 @@ def test_mandatory_multi_empty():
def test_mandatory_multi_empty_allow_empty_list():
descr = make_description()
api = Config(descr)
api.option('str4').value.set([])
assert api.option('str4').owner.get() == 'user'
api.property.read_only()
cfg = Config(descr)
cfg.option('str4').value.set([])
assert cfg.option('str4').owner.get() == 'user'
cfg.property.read_only()
prop = []
api.option('str4').value.get()
cfg.option('str4').value.get()
#
api.property.read_write()
api.option('str4').value.set([''])
assert api.option('str4').owner.get() == 'user'
api.property.read_only()
cfg.property.read_write()
cfg.option('str4').value.set([''])
assert cfg.option('str4').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
api.option('str4').value.get()
cfg.option('str4').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
api.property.read_write()
api.option('str4').value.set(['yes', ''])
assert api.option('str4').owner.get() == 'user'
api.property.read_only()
cfg.property.read_write()
cfg.option('str4').value.set(['yes', ''])
assert cfg.option('str4').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
api.option('str4').value.get()
cfg.option('str4').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
@ -297,47 +297,44 @@ def test_mandatory_multi_empty_allow_empty_list():
def test_mandatory_multi_append():
descr = make_description()
api = Config(descr)
api.option('str3').value.set(['yes'])
api.property.read_write()
api.option('str3').value.get().append(None)
cfg = Config(descr)
cfg.option('str3').value.set(['yes'])
cfg.property.read_write()
cfg.option('str3').value.get().append(None)
def test_mandatory_disabled():
descr = make_description()
api = Config(descr)
api.option('str1').value.get()
api.option('str1').property.add('disabled')
api.property.read_only()
cfg = Config(descr)
cfg.option('str1').value.get()
cfg.option('str1').property.add('disabled')
cfg.property.read_only()
pop = []
try:
api.option('str1').value.get()
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
if TIRAMISU_VERSION == 2:
search_prop = {'disabled', 'mandatory'}
else:
search_prop = {'disabled'}
assert set(prop) == search_prop
def test_mandatory_unicode():
descr = make_description()
api = Config(descr)
api.option('unicode2').value.get()
api.property.read_only()
cfg = Config(descr)
cfg.option('unicode2').value.get()
cfg.property.read_only()
prop = []
try:
api.option('unicode2').value.get()
cfg.option('unicode2').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
api.property.read_write()
api.option('unicode2').value.set(u'')
api.property.read_only()
cfg.property.read_write()
cfg.option('unicode2').value.set(u'')
cfg.property.read_only()
prop = []
try:
api.option('unicode2').value.get()
cfg.option('unicode2').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
@ -345,66 +342,66 @@ def test_mandatory_unicode():
def test_mandatory_warnings_ro():
descr = make_description()
api = Config(descr)
api.option('str').value.set('')
api.property.read_only()
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_only()
proc = []
try:
api.option('str').value.get()
cfg.option('str').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
api.property.read_write()
api.option('str').value.set('a')
api.property.read_only()
assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3']
assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
cfg.property.read_write()
cfg.option('str').value.set('a')
cfg.property.read_only()
assert list(cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
def test_mandatory_warnings_rw():
descr = make_description()
api = Config(descr)
api.option('str').value.set('')
api.property.read_write()
api.option('str').value.get()
assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
api.option('str').value.set('a')
assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3']
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
cfg.option('str').value.set('a')
assert list(cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
def test_mandatory_warnings_disabled():
descr = make_description()
api = Config(descr)
api.option('str').value.set('')
api.property.read_write()
api.option('str').value.get()
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
api.option('str').property.add('disabled')
assert set(api.value.mandatory()) == {'str1', 'unicode2', 'str3'}
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
cfg.option('str').property.add('disabled')
assert set(cfg.value.mandatory()) == {'str1', 'unicode2', 'str3'}
def test_mandatory_warnings_hidden():
descr = make_description()
api = Config(descr)
api.option('str').value.set('')
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
api.option('str').value.get()
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
api.option('str').property.add('hidden')
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
cfg.option('str').value.get()
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
cfg.option('str').property.add('hidden')
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
def test_mandatory_warnings_frozen():
descr = make_description()
api = Config(descr)
api.option('str').value.set('')
api.property.read_write()
api.option('str').value.get()
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
api.option('str').property.add('frozen')
api.property.read_only()
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
cfg.option('str').property.add('frozen')
cfg.property.read_only()
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
def test_mandatory_leader():
@ -414,10 +411,10 @@ def test_mandatory_leader():
multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
api = Config(descr)
api.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.value.dict()")
cfg = Config(descr)
cfg.property.read_only()
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "cfg.value.dict()")
def test_mandatory_warnings_leader():
@ -427,8 +424,8 @@ def test_mandatory_warnings_leader():
multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
api = Config(descr)
assert list(api.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
cfg = Config(descr)
assert list(cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
def test_mandatory_leader_empty():
@ -437,40 +434,40 @@ def test_mandatory_leader_empty():
multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
api = Config(descr)
api.property.read_write()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg = Config(descr)
cfg.property.read_write()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
api.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
cfg.property.read_only()
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
api.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
api.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
cfg.property.read_only()
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
cfg.property.read_write()
#
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
api.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
#
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip2'])
api.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.reset()")
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip2'])
cfg.property.read_only()
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()")
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
def test_mandatory_warnings_leader_empty():
@ -479,22 +476,22 @@ def test_mandatory_warnings_leader_empty():
multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
api = Config(descr)
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert list(api.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
cfg = Config(descr)
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert list(cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
#
api.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert list(api.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert list(cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
#
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
assert list(api.value.mandatory()) == []
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
assert list(cfg.value.mandatory()) == []
def test_mandatory_follower():
@ -503,27 +500,27 @@ def test_mandatory_follower():
multi=True, properties=('mandatory', ))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
api = Config(descr)
api.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg = Config(descr)
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
api.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
#
api.property.read_write()
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('')
api.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
cfg.property.read_write()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('')
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
#
api.property.read_write()
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('ip')
api.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
cfg.property.read_write()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('ip')
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
def test_mandatory_warnings_follower():
@ -532,43 +529,43 @@ def test_mandatory_warnings_follower():
multi=True, properties=('mandatory', ))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
api = Config(descr)
api.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg = Config(descr)
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
api.property.read_write()
assert list(api.value.mandatory()) == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
assert list(api.value.mandatory()) == ['ip_admin_eth0.netmask_admin_eth0']
cfg.property.read_write()
assert list(cfg.value.mandatory()) == []
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
assert list(cfg.value.mandatory()) == ['ip_admin_eth0.netmask_admin_eth0']
def test_mandatory_warnings_symlink():
descr = make_description_sym()
api = Config(descr)
api.option('str').value.set('')
api.property.read_write()
api.option('str').value.get()
assert list(api.value.mandatory()) == ['str', 'str1', 'str3']
api.option('str').property.add('frozen')
api.property.read_only()
assert list(api.value.mandatory()) == ['str', 'str1', 'str3']
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
assert list(cfg.value.mandatory()) == ['str', 'str1', 'str3']
cfg.option('str').property.add('frozen')
cfg.property.read_only()
assert list(cfg.value.mandatory()) == ['str', 'str1', 'str3']
#def test_mandatory_warnings_validate():
# descr = make_description3()
# api = Config(descr)
# api.option('str').value.set('')
# raises(ValueError, "list(api.value.mandatory())")
# api.option('str').value.set('test')
# raises(ValueError, "list(api.value.mandatory())")
# cfg = Config(descr)
# cfg.option('str').value.set('')
# raises(ValueError, "list(cfg.value.mandatory())")
# cfg.option('str').value.set('test')
# raises(ValueError, "list(cfg.value.mandatory())")
def test_mandatory_warnings_validate_empty():
descr = make_description2()
api = Config(descr)
api.option('str').value.set('')
api.property.read_only()
assert list(api.value.mandatory()) == ['str', 'str1', 'str3', 'unicode1']
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_only()
assert list(cfg.value.mandatory()) == ['str', 'str1', 'str3', 'unicode1']
def test_mandatory_warnings_requires():
@ -580,16 +577,16 @@ def test_mandatory_warnings_requires():
properties=('mandatory', ))
stroption3 = StrOption('str3', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
api = Config(descr)
api.option('str').value.set('')
api.property.read_write()
api.option('str').value.get()
assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2']
api.property.read_only()
assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2']
api.property.read_write()
api.option('str').value.set('yes')
assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3']
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2']
cfg.property.read_only()
assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2']
cfg.property.read_write()
cfg.option('str').value.set('yes')
assert list(cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
def test_mandatory_warnings_requires_leadership():
@ -599,12 +596,12 @@ def test_mandatory_warnings_requires_leadership():
stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
leadership = Leadership('leader', 'leadership', [stroption1, stroption2])
descr = OptionDescription('tiram', '', [stroption, leadership])
api = Config(descr)
api.option('str').value.set('')
api.option('leader.str1').value.set(['str'])
assert list(api.value.mandatory()) == ['str']
api.option('str').value.set('yes')
assert list(api.value.mandatory()) == ['leader.str2']
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.option('leader.str1').value.set(['str'])
assert list(cfg.value.mandatory()) == ['str']
cfg.option('str').value.set('yes')
assert list(cfg.value.mandatory()) == ['leader.str2']
def test_mandatory_warnings_requires_leadership_follower():
@ -613,18 +610,18 @@ def test_mandatory_warnings_requires_leadership_follower():
stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption1, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
leadership = Leadership('leader', 'leadership', [stroption, stroption1, stroption2])
descr = OptionDescription('tiram', '', [leadership])
api = Config(descr)
api.option('leader.str').value.set(['str'])
assert list(api.value.mandatory()) == []
api.option('leader.str1', 0).value.set('yes')
assert list(api.value.mandatory()) == ['leader.str2']
cfg = Config(descr)
cfg.option('leader.str').value.set(['str'])
assert list(cfg.value.mandatory()) == []
cfg.option('leader.str1', 0).value.set('yes')
assert list(cfg.value.mandatory()) == ['leader.str2']
def test_mandatory_od_disabled():
descr = make_description()
descr = OptionDescription('od', '', [descr])
api = Config(descr)
api.property.read_only()
assert list(api.value.mandatory()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
api.option('tiram').property.add('disabled')
assert list(api.value.mandatory()) == []
cfg = Config(descr)
cfg.property.read_only()
assert list(cfg.value.mandatory()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
cfg.option('tiram').property.add('disabled')
assert list(cfg.value.mandatory()) == []

View File

@ -1,5 +1,6 @@
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config
from py.test import raises
@ -9,7 +10,6 @@ from tiramisu.setting import groups, owners
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, Leadership, \
undefined, Params, ParamOption, ParamValue, ParamContext, calc_value
from tiramisu.api import TIRAMISU_VERSION
from tiramisu.error import PropertiesOptionError, ConflictError, LeadershipError, ConfigError
from tiramisu.i18n import _
from tiramisu.storage import list_sessions
@ -79,8 +79,8 @@ def is_config(config, **kwargs):
def ret_from_config(config):
api = Config(config)
return api.option('val1').value.get()
cfg = Config(config)
return cfg.option('val1').value.get()
def return_raise(*arg):
@ -126,21 +126,24 @@ def test_identical_paths():
raises(ConflictError, "make_description_duplicates()")
def test_hidden_if_in():
def test_hidden_if_in2(config_type):
intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default="abc",
requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
descr = OptionDescription('constraints', '', [stroption, intoption])
api = Config(descr)
api.property.read_write()
assert not 'hidden' in api.option('str').property.get()
api.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('str').value.get()")
raises(PropertiesOptionError, "api.option('str').value.set('uvw')")
assert 'hidden' in api.unrestraint.option('str').property.get()
cfg_ori = Config(descr)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
assert not 'hidden' in cfg.option('str').property.get()
cfg.option('int').value.set(1)
raises(PropertiesOptionError, "cfg.option('str').value.get()")
raises(PropertiesOptionError, "cfg.option('str').value.set('uvw')")
if config_type == 'tiramisu-api':
cfg.send()
assert 'hidden' in cfg_ori.unrestraint.option('str').property.get()
def test_hidden_if_in_with_group():
def test_hidden_if_in_with_group(config_type):
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False)
@ -155,11 +158,14 @@ def test_hidden_if_in_with_group():
requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
descr = OptionDescription('constraints', '', [gcgroup, booloption,
objspaceoption, stroption, intoption])
api = Config(descr)
api.property.read_write()
assert not 'hidden' in api.option('str').property.get()
api.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('gc.name').value.get()")
cfg_ori = Config(descr)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
assert not 'hidden' in cfg_ori.option('str').property.get()
cfg.option('int').value.set(1)
if config_type == 'tiramisu-api':
cfg.send()
raises(PropertiesOptionError, "cfg_ori.option('gc.name').value.get()")
def test_disabled_with_group():
@ -177,11 +183,11 @@ def test_disabled_with_group():
requires=({'option': intoption, 'expected': 1, 'action': 'disabled'},))
descr = OptionDescription('constraints', '', [gcgroup, booloption,
objspaceoption, stroption, intoption])
api = Config(descr)
api.property.read_write()
assert api.option('gc.name').value.get()
api.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('gc.name').value.get()")
cfg = Config(descr)
cfg.property.read_write()
assert cfg.option('gc.name').value.get()
cfg.option('int').value.set(1)
raises(PropertiesOptionError, "cfg.option('gc.name').value.get()")
#____________________________________________________________
@ -211,38 +217,40 @@ def make_description_callback():
def test_has_callback():
descr = make_description_callback()
# here the owner is 'default'
api = Config(descr)
api.property.read_write()
api.option('bool').value.set(False)
cfg = Config(descr)
cfg.property.read_write()
cfg.option('bool').value.set(False)
# because dummy has a callback
api.property.add('freeze')
api.option('gc.dummy').property.add('frozen')
raises(PropertiesOptionError, "api.option('gc.dummy').value.set(True)")
cfg.property.add('freeze')
cfg.option('gc.dummy').property.add('frozen')
raises(PropertiesOptionError, "cfg.option('gc.dummy').value.set(True)")
def test_freeze_and_has_callback():
descr = make_description_callback()
api = Config(descr)
api.property.read_write()
api.option('bool').value.set(False)
api.property.add('freeze')
api.option('gc.dummy').property.add('frozen')
raises(PropertiesOptionError, "api.option('gc.dummy').value.set(True)")
cfg = Config(descr)
cfg.property.read_write()
cfg.option('bool').value.set(False)
cfg.property.add('freeze')
cfg.option('gc.dummy').property.add('frozen')
raises(PropertiesOptionError, "cfg.option('gc.dummy').value.set(True)")
def test_callback():
def test_callback(config_type):
val1 = StrOption('val1', "", callback=return_val)
val2 = StrOption('val2', "")
maconfig = OptionDescription('rootconfig', '', [val1, val2])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1').option.callbacks() != (None, None)
assert api.option('val2').option.callbacks() == (None, None)
assert api.option('val1').value.get() == 'val'
api.option('val1').value.set('new-val')
assert api.option('val1').value.get() == 'new-val'
api.option('val1').value.reset()
assert api.option('val1').value.get() == 'val'
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
if config_type != 'tiramisu-api':
assert cfg.option('val1').option.callbacks() != (None, None)
assert cfg.option('val2').option.callbacks() == (None, None)
assert cfg.option('val1').value.get() == 'val'
cfg.option('val1').value.set('new-val')
assert cfg.option('val1').value.get() == 'new-val'
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == 'val'
def test_callback_params_without_callback():
@ -281,8 +289,8 @@ def test_callback_with_context():
params = Params((context,), {'value': value})
val1 = StrOption("val1", "", callback=is_config, callback_params=params)
maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig)
assert api.option('val1').value.get() == 'yes'
cfg = Config(maconfig)
assert cfg.option('val1').value.get() == 'yes'
def test_callback_with_context_named():
@ -290,15 +298,16 @@ def test_callback_with_context_named():
params = Params(kwargs={'config': context})
val1 = StrOption("val1", "", callback=is_config, callback_params=params)
maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig)
assert api.option('val1').value.get() == 'yes'
cfg = Config(maconfig)
assert cfg.option('val1').value.get() == 'yes'
def test_callback_with_error():
def test_callback_with_error(config_type):
val1 = StrOption("val1", "", callback=is_config, callback_params=Params(ParamValue('string'), kwargs={'value': ParamValue('string')}))
maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig)
assert api.option('val1').value.get() == 'no'
cfg = Config(maconfig)
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == 'no'
def test_callback_with_context_value():
@ -307,66 +316,72 @@ def test_callback_with_context_value():
val1 = StrOption("val1", "")
val2 = StrOption("val2", "", callback=ret_from_config, callback_params=params)
maconfig = OptionDescription('rootconfig', '', [val1, val2])
api = Config(maconfig)
api.option('val1').value.set('yes')
assert api.option('val1').value.get() == 'yes'
assert api.option('val2').value.get() == 'yes'
api.option('val1').value.set('no')
assert api.option('val1').value.get() == 'no'
assert api.option('val2').value.get() == 'no'
cfg = Config(maconfig)
cfg.option('val1').value.set('yes')
assert cfg.option('val1').value.get() == 'yes'
assert cfg.option('val2').value.get() == 'yes'
cfg.option('val1').value.set('no')
assert cfg.option('val1').value.get() == 'no'
assert cfg.option('val2').value.get() == 'no'
def test_callback_value():
def test_callback_value(config_type):
val1 = StrOption('val1', "", 'val')
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamValue('yes')))
val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
val5 = StrOption('val5', "", callback=return_value, callback_params=Params(ParamValue('yes')))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1').value.get() == 'val'
assert api.option('val2').value.get() == 'val'
assert api.option('val4').value.get() == 'val'
api.option('val1').value.set('new-val')
assert api.option('val1').value.get() == 'new-val'
assert api.option('val2').value.get() == 'new-val'
assert api.option('val4').value.get() == 'new-val'
api.option('val1').value.reset()
assert api.option('val1').value.get() == 'val'
assert api.option('val2').value.get() == 'val'
assert api.option('val3').value.get() == 'yes'
assert api.option('val4').value.get() == 'val'
assert api.option('val5').value.get() == 'yes'
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == 'val'
assert cfg.option('val2').value.get() == 'val'
assert cfg.option('val4').value.get() == 'val'
cfg.option('val1').value.set('new-val')
assert cfg.option('val1').value.get() == 'new-val'
assert cfg.option('val2').value.get() == 'new-val'
assert cfg.option('val4').value.get() == 'new-val'
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == 'val'
assert cfg.option('val2').value.get() == 'val'
assert cfg.option('val3').value.get() == 'yes'
assert cfg.option('val4').value.get() == 'val'
assert cfg.option('val5').value.get() == 'yes'
def test_callback_value_tuple():
def test_callback_value_tuple(config_type):
val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "", 'val2')
val3 = StrOption('val3', "", callback=return_concat, callback_params=Params((ParamOption(val1), ParamOption(val2))))
val4 = StrOption('val4', "", callback=return_concat, callback_params=Params((ParamValue('yes'), ParamValue('no'))))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1').value.get() == 'val1'
assert api.option('val2').value.get() == 'val2'
assert api.option('val3').value.get() == 'val1.val2'
assert api.option('val4').value.get() == 'yes.no'
api.option('val1').value.set('new-val')
assert api.option('val3').value.get() == 'new-val.val2'
api.option('val1').value.reset()
assert api.option('val3').value.get() == 'val1.val2'
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == 'val1'
assert cfg.option('val2').value.get() == 'val2'
assert cfg.option('val3').value.get() == 'val1.val2'
assert cfg.option('val4').value.get() == 'yes.no'
cfg.option('val1').value.set('new-val')
assert cfg.option('val3').value.get() == 'new-val.val2'
cfg.option('val1').value.reset()
assert cfg.option('val3').value.get() == 'val1.val2'
def test_callback_value_force_permissive():
def test_callback_value_force_permissive2(config_type):
config_type = 'tiramisu-api'
val1 = StrOption('val1', "", 'val', properties=('disabled',))
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val1, True)))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
api = Config(maconfig)
api.property.read_only()
raises(ConfigError, "api.option('val2').value.get()")
api.option('val3').value.get() is None
cfg = Config(maconfig)
cfg.property.read_only()
if config_type != 'tiramisu-api':
raises(ConfigError, "cfg.option('val2').value.get()")
cfg.option('val3').value.get() is None
else:
raises(ConfigError, "get_config(cfg, config_type)")
def test_callback_value_force_permissive_kwargs():
@ -374,36 +389,37 @@ def test_callback_value_force_permissive_kwargs():
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(value=ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(value=ParamOption(val1, True)))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
api = Config(maconfig)
api.property.read_only()
raises(ConfigError, "api.option('val2').value.get()")
api.option('val3').value.get() is None
cfg = Config(maconfig)
cfg.property.read_only()
raises(ConfigError, "cfg.option('val2').value.get()")
cfg.option('val3').value.get() is None
def test_callback_symlink():
def test_callback_symlink(config_type):
val1 = StrOption('val1', "", 'val')
val2 = SymLinkOption('val2', val1)
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val2)))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1').value.get() == 'val'
assert api.option('val2').value.get() == 'val'
assert api.option('val3').value.get() == 'val'
api.option('val1').value.set('new-val')
assert api.option('val1').value.get() == 'new-val'
assert api.option('val3').value.get() == 'new-val'
api.option('val1').value.reset()
assert api.option('val1').value.get() == 'val'
assert api.option('val3').value.get() == 'val'
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == 'val'
assert cfg.option('val2').value.get() == 'val'
assert cfg.option('val3').value.get() == 'val'
cfg.option('val1').value.set('new-val')
assert cfg.option('val1').value.get() == 'new-val'
assert cfg.option('val3').value.get() == 'new-val'
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == 'val'
assert cfg.option('val3').value.get() == 'val'
def test_callback_list():
val1 = StrOption('val1', "", callback=return_list)
maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig)
api.property.read_write()
raises(ValueError, "api.option('val1').value.get()")
cfg = Config(maconfig)
cfg.property.read_write()
raises(ValueError, "cfg.option('val1').value.get()")
def test_callback_list2():
@ -411,28 +427,29 @@ def test_callback_list2():
#val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) # , 'forcepermissive': False}]})
maconfig = OptionDescription('rootconfig', '', [val1, val2])
api = Config(maconfig)
api.property.read_write()
raises(ValueError, "api.option('val1').value.get()")
cfg = Config(maconfig)
cfg.property.read_write()
raises(ValueError, "cfg.option('val1').value.get()")
#cfg.val2
raises(ValueError, "api.option('val2').value.get()")
raises(ValueError, "cfg.option('val2').value.get()")
def test_callback_multi():
def test_callback_multi(config_type):
val1 = StrOption('val1', "", callback=return_val, multi=True)
maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1').value.get() == ['val']
api.option('val1').value.set(['new-val'])
assert api.option('val1').value.get() == ['new-val']
api.option('val1').value.set(['new-val', 'new-val2'])
assert api.option('val1').value.get() == ['new-val', 'new-val2']
api.option('val1').value.reset()
assert api.option('val1').value.get() == ['val']
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == ['val']
cfg.option('val1').value.set(['new-val'])
assert cfg.option('val1').value.get() == ['new-val']
cfg.option('val1').value.set(['new-val', 'new-val2'])
assert cfg.option('val1').value.get() == ['new-val', 'new-val2']
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == ['val']
def test_callback_multi_value():
def test_callback_multi_value(config_type):
val1 = StrOption('val1', "", ['val'], multi=True)
#val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
#val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamValue('yes')))
@ -446,136 +463,148 @@ def test_callback_multi_value():
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=params2)
val4 = StrOption('val4', "", multi=True, callback=return_list2, callback_params=params3)
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1').value.get() == ['val']
assert api.option('val2').value.get() == ['val']
assert api.option('val4').value.get() == ['val', 'yes']
api.option('val1').value.set(['new-val'])
assert api.option('val1').value.get() == ['new-val']
assert api.option('val2').value.get() == ['new-val']
assert api.option('val4').value.get() == ['new-val', 'yes']
api.option('val1').value.set(['new-val', 'new-val2'])
assert api.option('val1').value.get() == ['new-val', 'new-val2']
assert api.option('val2').value.get() == ['new-val', 'new-val2']
assert api.option('val4').value.get() == ['new-val', 'new-val2', 'yes']
api.option('val1').value.reset()
assert api.option('val1').value.get() == ['val']
assert api.option('val2').value.get() == ['val']
assert api.option('val3').value.get() == ['yes']
assert api.option('val4').value.get() == ['val', 'yes']
api.option('val2').value.set(['val', 'new'])
assert api.option('val1').value.get() == ['val']
assert api.option('val2').value.get() == ['val', 'new']
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == ['val']
assert cfg.option('val2').value.get() == ['val']
assert cfg.option('val4').value.get() == ['val', 'yes']
cfg.option('val1').value.set(['new-val'])
assert cfg.option('val1').value.get() == ['new-val']
assert cfg.option('val2').value.get() == ['new-val']
assert cfg.option('val4').value.get() == ['new-val', 'yes']
cfg.option('val1').value.set(['new-val', 'new-val2'])
assert cfg.option('val1').value.get() == ['new-val', 'new-val2']
assert cfg.option('val2').value.get() == ['new-val', 'new-val2']
assert cfg.option('val4').value.get() == ['new-val', 'new-val2', 'yes']
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == ['val']
assert cfg.option('val2').value.get() == ['val']
assert cfg.option('val3').value.get() == ['yes']
assert cfg.option('val4').value.get() == ['val', 'yes']
cfg.option('val2').value.set(['val', 'new'])
assert cfg.option('val1').value.get() == ['val']
assert cfg.option('val2').value.get() == ['val', 'new']
def test_callback_multi_list():
def test_callback_multi_list(config_type):
val1 = StrOption('val1', "", callback=return_list, multi=True)
maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1').value.get() == ['val', 'val']
api.option('val1').value.set(['new-val'])
assert api.option('val1').value.get() == ['new-val']
api.option('val1').value.set(['new-val', 'new-val2'])
assert api.option('val1').value.get() == ['new-val', 'new-val2']
api.option('val1').value.reset()
assert api.option('val1').value.get() == ['val', 'val']
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == ['val', 'val']
cfg.option('val1').value.set(['new-val'])
assert cfg.option('val1').value.get() == ['new-val']
cfg.option('val1').value.set(['new-val', 'new-val2'])
assert cfg.option('val1').value.get() == ['new-val', 'new-val2']
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == ['val', 'val']
def test_callback_multi_list_extend():
def test_callback_multi_list_extend(config_type):
val1 = StrOption('val1', "", callback=return_list2, callback_params=Params((ParamValue(['1', '2', '3']), ParamValue(['4', '5']))), multi=True)
maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1').value.get() == ['1', '2', '3', '4', '5']
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == ['1', '2', '3', '4', '5']
def test_callback_multi_callback():
def test_callback_multi_callback(config_type):
val1 = StrOption('val1', "", multi=True, callback=return_val)
interface1 = OptionDescription('val1', '', [val1])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1.val1').value.get() == ['val']
api.option('val1.val1').value.set(['val1', undefined])
assert api.option('val1.val1').value.get() == ['val1', 'val']
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').value.get() == ['val']
cfg.option('val1.val1').value.set(['val1', undefined])
assert cfg.option('val1.val1').value.get() == ['val1', 'val']
def test_callback_leader_and_followers_leader():
def test_callback_leader_and_followers_leader(config_type):
val1 = StrOption('val1', "", multi=True, callback=return_val)
val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1.val1').value.get() == ['val']
api.option('val1.val1').value.set([undefined, undefined])
assert api.option('val1.val1').value.get() == ['val', 'val']
assert api.option('val1.val2', 0).value.get() == None
assert api.option('val1.val2', 1).value.get() == None
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').value.get() == ['val']
cfg.option('val1.val1').value.set([undefined, undefined])
assert cfg.option('val1.val1').value.get() == ['val', 'val']
assert cfg.option('val1.val2', 0).value.get() == None
assert cfg.option('val1.val2', 1).value.get() == None
def test_callback_follower():
def test_callback_follower(config_type):
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value3, callback_params=Params(ParamValue(['string', 'new'])))
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
api.option('val1.val1').value.set(['val'])
assert api.option('val1.val2', 0).value.get() == 'string'
api.option('val1.val1').value.set(['val', 'val1'])
assert api.option('val1.val2', 0).value.get() == 'string'
assert api.option('val1.val2', 1).value.get() == 'new'
api.option('val1.val1').value.set(['val', 'val1', 'val2'])
assert api.option('val1.val2', 0).value.get() == 'string'
assert api.option('val1.val2', 1).value.get() == 'new'
assert api.option('val1.val2', 2).value.get() == None
api.option('val1.val1').value.set(['val', 'val1', 'val2', 'val3'])
assert api.option('val1.val2', 0).value.get() == 'string'
assert api.option('val1.val2', 1).value.get() == 'new'
assert api.option('val1.val2', 2).value.get() == None
assert api.option('val1.val2', 3).value.get() == None
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('val1.val1').value.set(['val'])
assert cfg.option('val1.val2', 0).value.get() == 'string'
cfg.option('val1.val1').value.set(['val', 'val1'])
assert cfg.option('val1.val2', 0).value.get() == 'string'
assert cfg.option('val1.val2', 1).value.get() == 'new'
cfg.option('val1.val1').value.set(['val', 'val1', 'val2'])
assert cfg.option('val1.val2', 0).value.get() == 'string'
assert cfg.option('val1.val2', 1).value.get() == 'new'
assert cfg.option('val1.val2', 2).value.get() == None
cfg.option('val1.val1').value.set(['val', 'val1', 'val2', 'val3'])
assert cfg.option('val1.val2', 0).value.get() == 'string'
assert cfg.option('val1.val2', 1).value.get() == 'new'
assert cfg.option('val1.val2', 2).value.get() == None
assert cfg.option('val1.val2', 3).value.get() == None
def test_callback_leader_and_followers_leader2():
def test_callback_leader_and_followers_leader2(config_type):
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, default_multi='val2')
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2)))
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
api.option('val1.val1').value.set(['val'])
assert api.option('val1.val4', 0).value.get() == 'val2'
assert api.option('val1.val3', 0).value.get() == 'val2'
assert api.option('val1.val2', 0).value.get() == 'val2'
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('val1.val1').value.set(['val'])
assert cfg.option('val1.val4', 0).value.get() == 'val2'
assert cfg.option('val1.val3', 0).value.get() == 'val2'
assert cfg.option('val1.val2', 0).value.get() == 'val2'
def test_callback_leader_and_followers_leader_mandatory():
def test_callback_leader_and_followers_leader_mandatory(config_type):
val = StrOption('val', "", default='val')
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',))
val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, interface1])
api = Config(maconfig)
api.property.read_only()
assert api.option('val1.val3', 0).value.get() == 'val'
assert api.option('val1.val4', 0).value.get() == 'val'
assert api.option('val1.val1').value.get() == ['val']
api.property.read_write()
api.option('val1.val1').value.set([undefined, 'val3'])
api.property.read_only()
assert api.option('val1.val1').value.get() == ['val', 'val3']
assert api.option('val1.val3', 0).value.get() == 'val'
raises(PropertiesOptionError, "api.option('val1.val3', 1).value.get()")
raises(PropertiesOptionError, "api.option('val1.val4', 1).value.get()")
cfg_ori = Config(maconfig)
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val1').value.get() == ['val']
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('val1.val1').value.set([undefined, 'val3'])
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val1').value.get() == ['val', 'val3']
assert cfg.option('val1.val3', 0).value.get() == 'val'
if config_type != 'tiramisu-api':
# FIXME
raises(PropertiesOptionError, "cfg.option('val1.val3', 1).value.get()")
raises(PropertiesOptionError, "cfg.option('val1.val4', 1).value.get()")
def test_callback_leader_and_followers_leader_mandatory2():
def test_callback_leader_and_followers_leader_mandatory2(config_type):
val = StrOption('val', "", default='val')
val_ = StrOption('val_', "", default='val_')
val1 = StrOption('val1', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val), {'val2': ParamOption(val_)}), properties=('mandatory',))
@ -583,27 +612,32 @@ def test_callback_leader_and_followers_leader_mandatory2():
val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1), {'val2': ParamOption(val_)}), properties=('mandatory',))
interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
api = Config(maconfig)
api.property.read_only()
assert api.option('val1.val3', 0).value.get() == 'val'
assert api.option('val1.val3', 1).value.get() == 'val_'
assert api.option('val1.val4', 0).value.get() == 'val'
assert api.option('val1.val4', 1).value.get() == 'val_'
assert api.option('val1.val1').value.get() == ['val', 'val_']
api.property.read_write()
api.option('val1.val1').value.set(['val', 'val_', 'val3'])
assert api.option('val1.val1').value.get() == ['val', 'val_', 'val3']
api.property.read_only()
assert api.option('val1.val3', 0).value.get() == 'val'
assert api.option('val1.val3', 1).value.get() == 'val_'
assert api.option('val1.val4', 0).value.get() == 'val'
assert api.option('val1.val4', 1).value.get() == 'val_'
raises(PropertiesOptionError, "api.option('val1.val3', 2).value.get()")
raises(PropertiesOptionError, "api.option('val1.val4', 2).value.get()")
assert api.option('val1.val1').value.get() == ['val', 'val_', 'val3']
cfg_ori = Config(maconfig)
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val3', 1).value.get() == 'val_'
assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val4', 1).value.get() == 'val_'
assert cfg.option('val1.val1').value.get() == ['val', 'val_']
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('val1.val1').value.set(['val', 'val_', 'val3'])
assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val3', 1).value.get() == 'val_'
assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val4', 1).value.get() == 'val_'
if config_type != 'tiramisu-api':
# FIXME
raises(PropertiesOptionError, "cfg.option('val1.val3', 2).value.get()")
raises(PropertiesOptionError, "cfg.option('val1.val4', 2).value.get()")
assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
def test_callback_leader_and_followers_leader_mandatory3():
def test_callback_leader_and_followers_leader_mandatory3(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), {'val': ParamOption(val_)}), properties=('mandatory',))
@ -611,46 +645,52 @@ def test_callback_leader_and_followers_leader_mandatory3():
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
api = Config(maconfig)
api.property.read_only()
assert api.option('val1.val3', 0).value.get() == 'val'
assert api.option('val1.val3', 1).value.get() == 'val_'
assert api.option('val1.val4', 0).value.get() == 'val'
assert api.option('val1.val4', 1).value.get() == 'val_'
assert api.option('val1.val1').value.get() == ['val', 'val_']
api.property.read_write()
api.option('val1.val1').value.set(['val', 'val_', 'val3'])
api.property.read_only()
assert api.option('val1.val3', 0).value.get() == 'val'
assert api.option('val1.val3', 1).value.get() == 'val_'
assert api.option('val1.val3', 2).value.get() == 'val3'
assert api.option('val1.val4', 0).value.get() == 'val'
assert api.option('val1.val4', 1).value.get() == 'val_'
assert api.option('val1.val4', 2).value.get() == 'val3'
assert api.option('val1.val1').value.get() == ['val', 'val_', 'val3']
cfg_ori = Config(maconfig)
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val3', 1).value.get() == 'val_'
assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val4', 1).value.get() == 'val_'
assert cfg.option('val1.val1').value.get() == ['val', 'val_']
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('val1.val1').value.set(['val', 'val_', 'val3'])
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val3', 1).value.get() == 'val_'
assert cfg.option('val1.val3', 2).value.get() == 'val3'
assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val4', 1).value.get() == 'val_'
assert cfg.option('val1.val4', 2).value.get() == 'val3'
assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
def test_callback_leader_and_followers_leader_mandatory4():
def test_callback_leader_and_followers_leader_mandatory4(config_type):
val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',))
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, interface1])
api = Config(maconfig)
api.property.read_only()
#raises(IndexError, "api.option('val1.val3').value.get()")
assert api.option('val1.val3', 0).value.get() == 'val'
assert api.option('val1.val4', 0).value.get() == 'val'
assert api.option('val1.val1').value.get() == ['val']
api.property.read_write()
api.option('val1.val1').value.set(['val', 'val3'])
api.property.read_only()
assert api.option('val1.val1').value.get() == ['val', 'val3']
assert api.option('val1.val3', 0).value.get() == 'val'
assert api.option('val1.val3', 1).value.get() == 'val3'
assert api.option('val1.val4', 0).value.get() == 'val'
assert api.option('val1.val4', 1).value.get() == 'val3'
cfg_ori = Config(maconfig)
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
#raises(IndexError, "cfg.option('val1.val3').value.get()")
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val1').value.get() == ['val']
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('val1.val1').value.set(['val', 'val3'])
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val1').value.get() == ['val', 'val3']
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val3', 1).value.get() == 'val3'
assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val4', 1).value.get() == 'val3'
def test_callback_leader_and_followers_leader3():
@ -660,9 +700,10 @@ def test_callback_leader_and_followers_leader3():
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
assert list(api.value.mandatory()) == ['val1.val1']
cfg = Config(maconfig)
cfg.property.read_write()
# FIXME cfg = get_config(cfg, config_type)
assert list(cfg.value.mandatory()) == ['val1.val1']
def test_callback_leader_and_followers_leader4():
@ -672,11 +713,12 @@ def test_callback_leader_and_followers_leader4():
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
api.property.add('expert')
api.permissive.set(frozenset(['expert']))
assert list(api.value.mandatory()) == []
cfg = Config(maconfig)
cfg.property.read_write()
# FIXME cfg = get_config(cfg, config_type)
cfg.property.add('expert')
cfg.permissive.set(frozenset(['expert']))
assert list(cfg.value.mandatory()) == []
def test_consistency_leader_and_followers_leader_mandatory_transitive():
@ -691,16 +733,17 @@ def test_consistency_leader_and_followers_leader_mandatory_transitive():
interface1 = Leadership('val1', '', [val1, val2])
interface2 = Leadership('val3', '', [val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
api = Config(maconfig)
api.property.read_write()
cfg = Config(maconfig)
cfg.property.read_write()
# FIXME cfg = get_config(cfg, config_type)
try:
api.option('val1.val1').value.get()
cfg.option('val1.val1').value.get()
except PropertiesOptionError as error:
assert str(error) == str(_('cannot access to {0} "{1}" because "{2}" has {3} {4}').format('option', 'val1', 'val2', _('property'), '"disabled"'))
else:
raise Exception('must raises')
raises(PropertiesOptionError, "api.option('val3.val3').value.get()")
assert list(api.value.mandatory()) == []
raises(PropertiesOptionError, "cfg.option('val3.val3').value.get()")
assert list(cfg.value.mandatory()) == []
def test_consistency_leader_and_followers_leader_mandatory_non_transitive():
@ -715,88 +758,93 @@ def test_consistency_leader_and_followers_leader_mandatory_non_transitive():
interface1 = Leadership('val1', '', [val1, val2])
interface2 = Leadership('val3', '', [val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
api = Config(maconfig)
api.property.read_write()
if TIRAMISU_VERSION == 2:
assert list(api.value.mandatory()) == ["val1.val1", "val1.val2"]
else:
assert list(api.value.mandatory()) == ["val1.val1"]
cfg = Config(maconfig)
cfg.property.read_write()
# FIXME cfg = get_config(cfg, config_type)
assert list(cfg.value.mandatory()) == ["val1.val1"]
def test_callback_leader_and_followers_leader_list():
def test_callback_leader_and_followers_leader_list(config_type):
val1 = StrOption('val1', "", multi=True, callback=return_list)
val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1.val1').value.get() == ['val', 'val']
assert api.option('val1.val2', 0).value.get() == None
assert api.option('val1.val2', 1).value.get() == None
api.option('val1.val1').value.set(['val', 'val', undefined])
assert api.option('val1.val1').value.get() == ['val', 'val', None]
assert api.option('val1.val2', 0).value.get() == None
assert api.option('val1.val2', 1).value.get() == None
assert api.option('val1.val2', 1).value.get() == None
api.option('val1.val1').value.reset()
assert api.option('val1.val1').value.get() == ['val', 'val']
assert api.option('val1.val2', 0).value.get() == None
assert api.option('val1.val2', 1).value.get() == None
api.option('val1.val1').value.pop(1)
assert api.option('val1.val1').value.get() == ['val']
assert api.option('val1.val2', 0).value.get() == None
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').value.get() == ['val', 'val']
assert cfg.option('val1.val2', 0).value.get() == None
assert cfg.option('val1.val2', 1).value.get() == None
cfg.option('val1.val1').value.set(['val', 'val', undefined])
assert cfg.option('val1.val1').value.get() == ['val', 'val', None]
assert cfg.option('val1.val2', 0).value.get() == None
assert cfg.option('val1.val2', 1).value.get() == None
assert cfg.option('val1.val2', 2).value.get() == None
cfg.option('val1.val1').value.reset()
assert cfg.option('val1.val1').value.get() == ['val', 'val']
assert cfg.option('val1.val2', 0).value.get() == None
assert cfg.option('val1.val2', 1).value.get() == None
cfg.option('val1.val1').value.pop(1)
assert cfg.option('val1.val1').value.get() == ['val']
assert cfg.option('val1.val2', 0).value.get() == None
def test_callback_leader_and_followers_leader_follower_list():
def test_callback_leader_and_followers_leader_follower_list(config_type):
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_list)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1.val1').value.get() == []
api.option('val1.val1').value.set(['val1'])
raises(LeadershipError, "api.option('val1.val2', 0).value.get()")
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').value.get() == []
if config_type == 'tiramisu-api':
# when "tiramisu-api", raise when set and not in get function
raises(ConfigError, "cfg.option('val1.val1').value.set(['val1'])")
else:
cfg.option('val1.val1').value.set(['val1'])
raises(LeadershipError, "cfg.option('val1.val2', 0).value.get()")
def test_callback_leader_and_followers_follower():
def test_callback_leader_and_followers_follower(config_type):
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_val)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1.val1').value.get() == []
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').value.get() == []
#
api.option('val1.val1').value.set(['val1'])
assert api.option('val1.val1').value.get() == ['val1']
assert api.option('val1.val2', 0).value.get() == 'val'
cfg.option('val1.val1').value.set(['val1'])
assert cfg.option('val1.val1').value.get() == ['val1']
assert cfg.option('val1.val2', 0).value.get() == 'val'
#
api.option('val1.val1').value.set(['val1', 'val2'])
assert api.option('val1.val1').value.get() == ['val1', 'val2']
assert api.option('val1.val2', 0).value.get() == 'val'
assert api.option('val1.val2', 1).value.get() == 'val'
cfg.option('val1.val1').value.set(['val1', 'val2'])
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert cfg.option('val1.val2', 0).value.get() == 'val'
assert cfg.option('val1.val2', 1).value.get() == 'val'
#
api.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
assert api.option('val1.val2', 0).value.get() == 'val'
assert api.option('val1.val2', 1).value.get() == 'val'
assert api.option('val1.val2', 2).value.get() == 'val'
cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert cfg.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
assert cfg.option('val1.val2', 0).value.get() == 'val'
assert cfg.option('val1.val2', 1).value.get() == 'val'
assert cfg.option('val1.val2', 2).value.get() == 'val'
#
api.option('val1.val1').value.pop(2)
assert api.option('val1.val1').value.get() == ['val1', 'val2']
assert api.option('val1.val2', 0).value.get() == 'val'
assert api.option('val1.val2', 1).value.get() == 'val'
cfg.option('val1.val1').value.pop(2)
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert cfg.option('val1.val2', 0).value.get() == 'val'
assert cfg.option('val1.val2', 1).value.get() == 'val'
#
api.option('val1.val2', 0).value.set('val2')
api.option('val1.val2', 1).value.set('val2')
assert api.option('val1.val2', 0).value.get() == 'val2'
assert api.option('val1.val2', 1).value.get() == 'val2'
cfg.option('val1.val2', 0).value.set('val2')
cfg.option('val1.val2', 1).value.set('val2')
assert cfg.option('val1.val2', 0).value.get() == 'val2'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
#
api.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val2', 0).value.get() == 'val2'
assert api.option('val1.val2', 1).value.get() == 'val2'
assert api.option('val1.val2', 2).value.get() == 'val'
cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert cfg.option('val1.val2', 0).value.get() == 'val2'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert cfg.option('val1.val2', 2).value.get() == 'val'
def test_callback_leader_and_followers():
@ -804,45 +852,50 @@ def test_callback_leader_and_followers():
val2 = StrOption('val2', "", multi=True, callback=return_val)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
cfg = Config(maconfig)
cfg.property.read_write()
def test_callback_leader_and_followers_follower_cal():
def test_callback_leader_and_followers_follower_cal(config_type):
val3 = StrOption('val3', "", multi=True)
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
val2 = StrOption('val2', "", multi=True, callback=return_val)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val3])
api = Config(maconfig)
api.property.read_write()
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
#
assert api.option('val3').value.get() == []
assert api.option('val1.val1').value.get() == []
assert cfg.option('val3').value.get() == []
assert cfg.option('val1.val1').value.get() == []
#
api.option('val1.val1').value.set(['val1'])
api.option('val3').value.set(['val1'])
assert api.option('val1.val1').value.get() == ['val1']
assert api.option('val1.val2', 0).value.get() == 'val'
cfg.option('val1.val1').value.set(['val1'])
cfg.option('val3').value.set(['val1'])
assert cfg.option('val1.val1').value.get() == ['val1']
assert cfg.option('val1.val2', 0).value.get() == 'val'
#
api.option('val1.val1').value.reset()
api.option('val1.val2', 0).value.set('val')
cfg.option('val1.val1').value.reset()
cfg.option('val1.val2', 0).value.set('val')
#
api.option('val3').value.set(['val1', 'val2'])
assert api.option('val1.val2', 0).value.get() == 'val'
assert api.option('val1.val2', 1).value.get() == 'val'
assert api.option('val1.val1').value.get() == ['val1', 'val2']
cfg.option('val3').value.set(['val1', 'val2'])
assert cfg.option('val1.val2', 0).value.get() == 'val'
assert cfg.option('val1.val2', 1).value.get() == 'val'
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
# len of follower is higher than leader's one
api.option('val1.val2', 0).value.set('val1')
api.option('val1.val2', 1).value.set('val2')
api.option('val3').value.set(['val1'])
assert api.option('val1.val1').value.get() == ['val1']
raises(LeadershipError, "api.option('val1.val2', 0).value.get()")
cfg.option('val1.val2', 0).value.set('val1')
cfg.option('val1.val2', 1).value.set('val2')
if config_type == 'tiramisu-api':
# when "tiramisu-api", raise when set and not in get function
raises(ConfigError, "cfg.option('val3').value.set(['val1'])")
else:
cfg.option('val3').value.set(['val1'])
assert cfg.option('val1.val1').value.get() == ['val1']
raises(LeadershipError, "cfg.option('val1.val2', 0).value.get()")
#
api.option('val3').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val2', 0).value.get() == 'val1'
assert api.option('val1.val2', 1).value.get() == 'val2'
assert api.option('val1.val2', 2).value.get() == 'val'
cfg.option('val3').value.set(['val1', 'val2', 'val3'])
assert cfg.option('val1.val2', 0).value.get() == 'val1'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert cfg.option('val1.val2', 2).value.get() == 'val'
def test_callback_leader_and_followers_leader_disabled():
@ -851,11 +904,11 @@ def test_callback_leader_and_followers_leader_disabled():
val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
raises(PropertiesOptionError, "api.option('val1.val1').value.get()")
raises(PropertiesOptionError, "api.option('val1.val1').value.set(['yes'])")
raises(PropertiesOptionError, "api.option('val1.val2', 0).value.get()")
cfg = Config(maconfig)
cfg.property.read_write()
raises(PropertiesOptionError, "cfg.option('val1.val1').value.get()")
raises(PropertiesOptionError, "cfg.option('val1.val1').value.set(['yes'])")
raises(PropertiesOptionError, "cfg.option('val1.val2', 0).value.get()")
def test_callback_leader_and_followers_leader_callback_disabled():
@ -864,14 +917,14 @@ def test_callback_leader_and_followers_leader_callback_disabled():
val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val0])
api = Config(maconfig)
api.property.read_write()
raises(ConfigError, "api.option('val1.val1').value.get()")
raises(ConfigError, "api.option('val1.val2').value.get()")
api.property.pop('disabled')
api.option('val1.val1').value.set([])
api.property.add('disabled')
assert api.option('val1.val1').value.get() == []
cfg = Config(maconfig)
cfg.property.read_write()
raises(ConfigError, "cfg.option('val1.val1').value.get()")
raises(ConfigError, "cfg.option('val1.val2').value.get()")
cfg.property.pop('disabled')
cfg.option('val1.val1').value.set([])
cfg.property.add('disabled')
assert cfg.option('val1.val1').value.get() == []
def test_callback_leader_and_followers_follower_disabled():
@ -879,26 +932,25 @@ def test_callback_leader_and_followers_follower_disabled():
val2 = StrOption('val2', "", multi=True, properties=('disabled',))
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1.val1').value.get() == []
#raises(PropertiesOptionError, "api.option('val1.val2').value.get()")
api.option('val1.val1').value.set(['yes'])
assert api.option('val1.val1').value.get() == ['yes']
api.property.pop('disabled')
assert api.option('val1.val2', 0).value.get() == None
api.option('val1.val2', 0).value.set('no')
api.option('val1.val1').value.set(['yes', 'yes2', 'yes3'])
api.option('val1.val2', 2).value.set('no1')
assert api.option('val1.val2', 0).value.get() == 'no'
assert api.option('val1.val2', 1).value.get() == None
assert api.option('val1.val2', 2).value.get() == 'no1'
api.property.add('disabled')
api.option('val1.val1').value.pop(0)
assert api.option('val1.val1').value.get() == ['yes2', 'yes3']
api.property.pop('disabled')
assert api.option('val1.val2', 0).value.get() == None
assert api.option('val1.val2', 1).value.get() == 'no1'
cfg = Config(maconfig)
cfg.property.read_write()
assert cfg.option('val1.val1').value.get() == []
cfg.option('val1.val1').value.set(['yes'])
assert cfg.option('val1.val1').value.get() == ['yes']
cfg.property.pop('disabled')
assert cfg.option('val1.val2', 0).value.get() == None
cfg.option('val1.val2', 0).value.set('no')
cfg.option('val1.val1').value.set(['yes', 'yes2', 'yes3'])
cfg.option('val1.val2', 2).value.set('no1')
assert cfg.option('val1.val2', 0).value.get() == 'no'
assert cfg.option('val1.val2', 1).value.get() == None
assert cfg.option('val1.val2', 2).value.get() == 'no1'
cfg.property.add('disabled')
cfg.option('val1.val1').value.pop(0)
assert cfg.option('val1.val1').value.get() == ['yes2', 'yes3']
cfg.property.pop('disabled')
assert cfg.option('val1.val2', 0).value.get() == None
assert cfg.option('val1.val2', 1).value.get() == 'no1'
def test_callback_leader_and_followers_follower_callback_disabled():
@ -907,17 +959,17 @@ def test_callback_leader_and_followers_follower_callback_disabled():
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0)))
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val0])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1.val1').value.get() == []
api.option('val1.val1').value.set(['yes'])
assert api.option('val1.val1').value.get() == ['yes']
api.property.pop('disabled')
api.option('val1.val2', 0).value.set('no')
api.option('val1.val1').value.set(['yes', 'yes1'])
assert api.option('val1.val2', 0).value.get() == 'no'
api.property.add('disabled')
api.option('val1.val1').value.pop(1)
cfg = Config(maconfig)
cfg.property.read_write()
assert cfg.option('val1.val1').value.get() == []
cfg.option('val1.val1').value.set(['yes'])
assert cfg.option('val1.val1').value.get() == ['yes']
cfg.property.pop('disabled')
cfg.option('val1.val2', 0).value.set('no')
cfg.option('val1.val1').value.set(['yes', 'yes1'])
assert cfg.option('val1.val2', 0).value.get() == 'no'
cfg.property.add('disabled')
cfg.option('val1.val1').value.pop(1)
def test_callback_leader_and_followers_value():
@ -929,10 +981,10 @@ def test_callback_leader_and_followers_value():
val6 = StrOption('val6', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val5)))
interface1 = Leadership('val1', '', [val1, val2, val3, val5, val6])
maconfig = OptionDescription('rootconfig', '', [interface1, val4])
api = Config(maconfig)
api.property.read_write()
api.option('val4').value.get() == ['val10', 'val11']
assert api.option('val1.val1').value.get() == []
cfg = Config(maconfig)
cfg.property.read_write()
cfg.option('val4').value.get() == ['val10', 'val11']
assert cfg.option('val1.val1').value.get() == []
#raises(LeadershipError, "cfg.val1.val1")
#raises(LeadershipError, "cfg.val1.val2")
#raises(LeadershipError, "cfg.val1.val3")
@ -940,55 +992,55 @@ def test_callback_leader_and_followers_value():
#raises(LeadershipError, "cfg.val1.val6")
#
#default calculation has greater length
#raises(LeadershipError, "api.option('val1.val1').value.set(['val1']")
#raises(LeadershipError, "cfg.option('val1.val1').value.set(['val1']")
#
api.option('val1.val1').value.set(['val1', 'val2'])
assert api.option('val1.val1').value.get() == ['val1', 'val2']
assert api.option('val1.val2', 0).value.get() == 'val1'
assert api.option('val1.val2', 1).value.get() == 'val2'
assert api.option('val1.val3', 0).value.get() == 'yes'
assert api.option('val1.val3', 1).value.get() == 'yes'
raises(LeadershipError, "api.option('val1.val5', 0).value.get()")
raises(LeadershipError, "api.option('val1.val5', 1).value.get()")
raises(LeadershipError, "api.option('val1.val6', 0).value.get()")
raises(LeadershipError, "api.option('val1.val6', 1).value.get()")
cfg.option('val1.val1').value.set(['val1', 'val2'])
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert cfg.option('val1.val2', 0).value.get() == 'val1'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert cfg.option('val1.val3', 0).value.get() == 'yes'
assert cfg.option('val1.val3', 1).value.get() == 'yes'
raises(LeadershipError, "cfg.option('val1.val5', 0).value.get()")
raises(LeadershipError, "cfg.option('val1.val5', 1).value.get()")
raises(LeadershipError, "cfg.option('val1.val6', 0).value.get()")
raises(LeadershipError, "cfg.option('val1.val6', 1).value.get()")
#
api.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
assert api.option('val1.val2', 0).value.get() == 'val1'
assert api.option('val1.val2', 1).value.get() == 'val2'
assert api.option('val1.val2', 2).value.get() == 'val3'
assert api.option('val1.val3', 0).value.get() == 'yes'
assert api.option('val1.val3', 1).value.get() == 'yes'
assert api.option('val1.val3', 2).value.get() == 'yes'
raises(LeadershipError, "api.option('val1.val5', 2).value.get()")
raises(LeadershipError, "api.option('val1.val6', 2).value.get()")
cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert cfg.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
assert cfg.option('val1.val2', 0).value.get() == 'val1'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert cfg.option('val1.val2', 2).value.get() == 'val3'
assert cfg.option('val1.val3', 0).value.get() == 'yes'
assert cfg.option('val1.val3', 1).value.get() == 'yes'
assert cfg.option('val1.val3', 2).value.get() == 'yes'
raises(LeadershipError, "cfg.option('val1.val5', 2).value.get()")
raises(LeadershipError, "cfg.option('val1.val6', 2).value.get()")
#
api.option('val1.val1').value.pop(2)
assert api.option('val1.val1').value.get() == ['val1', 'val2']
assert api.option('val1.val2', 0).value.get() == 'val1'
assert api.option('val1.val2', 1).value.get() == 'val2'
assert api.option('val1.val3', 0).value.get() == 'yes'
assert api.option('val1.val3', 1).value.get() == 'yes'
cfg.option('val1.val1').value.pop(2)
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert cfg.option('val1.val2', 0).value.get() == 'val1'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert cfg.option('val1.val3', 0).value.get() == 'yes'
assert cfg.option('val1.val3', 1).value.get() == 'yes'
#
api.option('val1.val2', 0).value.set('val2')
api.option('val1.val2', 1).value.set('val2')
api.option('val1.val3', 0).value.set('val2')
api.option('val1.val3', 1).value.set('val2')
api.option('val1.val5', 0).value.set('val2')
api.option('val1.val5', 1).value.set('val2')
assert api.option('val1.val2', 0).value.get() == 'val2'
assert api.option('val1.val2', 1).value.get() == 'val2'
assert api.option('val1.val3', 0).value.get() == 'val2'
assert api.option('val1.val3', 1).value.get() == 'val2'
assert api.option('val1.val5', 0).value.get() == 'val2'
assert api.option('val1.val5', 1).value.get() == 'val2'
assert api.option('val1.val6', 0).value.get() == 'val2'
assert api.option('val1.val6', 1).value.get() == 'val2'
cfg.option('val1.val2', 0).value.set('val2')
cfg.option('val1.val2', 1).value.set('val2')
cfg.option('val1.val3', 0).value.set('val2')
cfg.option('val1.val3', 1).value.set('val2')
cfg.option('val1.val5', 0).value.set('val2')
cfg.option('val1.val5', 1).value.set('val2')
assert cfg.option('val1.val2', 0).value.get() == 'val2'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert cfg.option('val1.val3', 0).value.get() == 'val2'
assert cfg.option('val1.val3', 1).value.get() == 'val2'
assert cfg.option('val1.val5', 0).value.get() == 'val2'
assert cfg.option('val1.val5', 1).value.get() == 'val2'
assert cfg.option('val1.val6', 0).value.get() == 'val2'
assert cfg.option('val1.val6', 1).value.get() == 'val2'
#
api.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val2', 2).value.get() == 'val3'
assert api.option('val1.val3', 2).value.get() == 'yes'
cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert cfg.option('val1.val2', 2).value.get() == 'val3'
assert cfg.option('val1.val3', 2).value.get() == 'yes'
def test_callback_leader():
@ -997,28 +1049,29 @@ def test_callback_leader():
raises(ValueError, "Leadership('val1', '', [val1, val2])")
def test_callback_different_type():
def test_callback_different_type(config_type):
val = IntOption('val', "", default=2)
val_ = IntOption('val_', "", default=3)
val1 = IntOption('val1', "", multi=True)
val2 = IntOption('val2', "", multi=True, callback=return_calc, callback_params=Params((ParamOption(val), ParamOption(val1)), {'k': ParamOption(val_)}))
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val, val_])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1.val1').value.get() == []
api.option('val1.val1').value.set([1])
assert api.option('val1.val1').value.get() == [1]
assert api.option('val1.val2', 0).value.get() == 6
api.option('val1.val1').value.set([1, 3])
assert api.option('val1.val1').value.get() == [1, 3]
assert api.option('val1.val2', 0).value.get() == 6
assert api.option('val1.val2', 1).value.get() == 8
api.option('val1.val1').value.set([1, 3, 5])
assert api.option('val1.val1').value.get() == [1, 3, 5]
assert api.option('val1.val2', 0).value.get() == 6
assert api.option('val1.val2', 1).value.get() == 8
assert api.option('val1.val2', 2).value.get() == 10
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').value.get() == []
cfg.option('val1.val1').value.set([1])
assert cfg.option('val1.val1').value.get() == [1]
assert cfg.option('val1.val2', 0).value.get() == 6
cfg.option('val1.val1').value.set([1, 3])
assert cfg.option('val1.val1').value.get() == [1, 3]
assert cfg.option('val1.val2', 0).value.get() == 6
assert cfg.option('val1.val2', 1).value.get() == 8
cfg.option('val1.val1').value.set([1, 3, 5])
assert cfg.option('val1.val1').value.get() == [1, 3, 5]
assert cfg.option('val1.val2', 0).value.get() == 6
assert cfg.option('val1.val2', 1).value.get() == 8
assert cfg.option('val1.val2', 2).value.get() == 10
def test_callback_hidden():
@ -1027,11 +1080,11 @@ def test_callback_hidden():
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig)
api.property.read_write()
raises(PropertiesOptionError, "api.option('od1.opt1').value.get()")
cfg = Config(maconfig)
cfg.property.read_write()
raises(PropertiesOptionError, "cfg.option('od1.opt1').value.get()")
# do not raise, forcepermissive
api.option('od2.opt2').value.get()
cfg.option('od2.opt2').value.get()
def test_callback_hidden_permissive():
@ -1040,11 +1093,11 @@ def test_callback_hidden_permissive():
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig)
api.permissive.set(frozenset(['hidden']))
api.property.read_write()
raises(PropertiesOptionError, "api.option('od1.opt1').value.get()")
api.option('od2.opt2').value.get()
cfg = Config(maconfig)
cfg.permissive.set(frozenset(['hidden']))
cfg.property.read_write()
raises(PropertiesOptionError, "cfg.option('od1.opt1').value.get()")
cfg.option('od2.opt2').value.get()
def test_callback_hidden_permissive_callback():
@ -1053,10 +1106,10 @@ def test_callback_hidden_permissive_callback():
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig)
api.property.read_write()
raises(PropertiesOptionError, "api.option('od1.opt1').value.get()")
api.option('od2.opt2').value.get()
cfg = Config(maconfig)
cfg.property.read_write()
raises(PropertiesOptionError, "cfg.option('od1.opt1').value.get()")
cfg.option('od2.opt2').value.get()
def test_callback_two_disabled():
@ -1065,9 +1118,9 @@ def test_callback_two_disabled():
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig)
api.property.read_write()
raises(PropertiesOptionError, "api.option('od2.opt2').value.get()")
cfg = Config(maconfig)
cfg.property.read_write()
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
def test_callback_two_disabled2():
@ -1076,11 +1129,11 @@ def test_callback_two_disabled2():
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig)
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
raises(PropertiesOptionError, "api.option('od2.opt2').value.get()")
assert api.forcepermissive.option('od2.opt2').owner.isdefault()
cfg = Config(maconfig)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
assert cfg.forcepermissive.option('od2.opt2').owner.isdefault()
def test_callback_calculating_invalid():
@ -1089,11 +1142,11 @@ def test_callback_calculating_invalid():
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig)
api.property.read_write()
raises(ValueError, "api.option('od2.opt2').value.get()")
api.unrestraint.option('od2.opt2').property.add('disabled')
raises(PropertiesOptionError, "api.option('od2.opt2').value.get()")
cfg = Config(maconfig)
cfg.property.read_write()
raises(ValueError, "cfg.option('od2.opt2').value.get()")
cfg.unrestraint.option('od2.opt2').property.add('disabled')
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
def test_callback_calculating_disabled():
@ -1102,9 +1155,9 @@ def test_callback_calculating_disabled():
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig)
api.property.read_write()
raises(ConfigError, "api.option('od2.opt2').value.get()")
cfg = Config(maconfig)
cfg.property.read_write()
raises(ConfigError, "cfg.option('od2.opt2').value.get()")
def test_callback_calculating_mandatory():
@ -1113,9 +1166,9 @@ def test_callback_calculating_mandatory():
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig)
api.property.read_only()
raises(ConfigError, "api.option('od2.opt2').value.get()")
cfg = Config(maconfig)
cfg.property.read_only()
raises(ConfigError, "cfg.option('od2.opt2').value.get()")
def test_callback_calculating_mandatory_multi():
@ -1124,9 +1177,9 @@ def test_callback_calculating_mandatory_multi():
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig)
api.property.read_only()
raises(ConfigError, "api.option('od2.opt2').value.get()")
cfg = Config(maconfig)
cfg.property.read_only()
raises(ConfigError, "cfg.option('od2.opt2').value.get()")
def test_callback_two_disabled_multi():
@ -1135,47 +1188,50 @@ def test_callback_two_disabled_multi():
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig)
api.property.read_write()
raises(PropertiesOptionError, "api.option('od2.opt2').value.get()")
cfg = Config(maconfig)
cfg.property.read_write()
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
def test_callback_multi_list_params():
def test_callback_multi_list_params(config_type):
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(ParamOption(val1)))
oval2 = OptionDescription('val2', '', [val2])
maconfig = OptionDescription('rootconfig', '', [val1, oval2])
api = Config(maconfig)
api.property.read_write()
assert api.option('val2.val2').value.get() == ['val', 'val']
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val2.val2').value.get() == ['val', 'val']
def test_callback_multi_list_params_key():
def test_callback_multi_list_params_key(config_type):
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(kwargs={'value': ParamOption(val1)}))
oval2 = OptionDescription('val2', '', [val2])
maconfig = OptionDescription('rootconfig', '', [val1, oval2])
api = Config(maconfig)
api.property.read_write()
assert api.option('val2.val2').value.get() == ['val', 'val']
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val2.val2').value.get() == ['val', 'val']
def test_leadership_callback_description():
def test_leadership_callback_description(config_type):
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(st1)))
stm = Leadership('st1', '', [st1, st2])
st = OptionDescription('st', '', [stm])
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
assert api.option('od.st.st1.st1').value.get() == []
assert api.option('od.st.st1.st1').owner.isdefault()
cfg = Config(od2)
cfg = get_config(cfg, config_type)
owner = cfg.owner.get()
assert cfg.option('od.st.st1.st1').value.get() == []
assert cfg.option('od.st.st1.st1').owner.isdefault()
##
api.option('od.st.st1.st1').value.set(['yes'])
api.option('od.st.st1.st2', 0).value.set('yes')
assert api.option('od.st.st1.st1').owner.get() == owner
assert api.option('od.st.st1.st2', 0).owner.get() == owner
cfg.option('od.st.st1.st1').value.set(['yes'])
cfg.option('od.st.st1.st2', 0).value.set('yes')
assert cfg.option('od.st.st1.st1').owner.get() == owner
assert cfg.option('od.st.st1.st2', 0).owner.get() == owner
def test_callback_raise():
@ -1184,32 +1240,34 @@ def test_callback_raise():
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig)
api.property.read_write()
cfg = Config(maconfig)
cfg.property.read_write()
try:
api.option('od1.opt1').value.get()
cfg.option('od1.opt1').value.get()
except ConfigError as err:
assert '"Option 1"' in str(err)
try:
api.option('od2.opt2').value.get()
cfg.option('od2.opt2').value.get()
except ConfigError as err:
assert '"Option 2"' in str(err)
def test_calc_value_simple():
def test_calc_value_simple(config_type):
val1 = StrOption('val1', '', 'val1')
val2 = StrOption('val2', '', callback=calc_value, callback_params=Params(ParamOption(val1)))
od = OptionDescription('root', '', [val1, val2])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'}
def test_calc_value_multi():
def test_calc_value_multi(config_type):
val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "", 'val2')
val3 = StrOption('val3', "", multi=True, callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True)))
od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': ['val1', 'val2']}
@ -1224,7 +1282,7 @@ def test_calc_value_disabled():
assert cfg.value.dict() == {'val2': 'default_value'}
def test_calc_value_condition():
def test_calc_value_condition(config_type):
boolean = BoolOption('boolean', '', True)
val1 = StrOption('val1', '', 'val1')
val2 = StrOption('val2', '', callback=calc_value, callback_params=Params(ParamOption(val1, True),
@ -1234,35 +1292,39 @@ def test_calc_value_condition():
od = OptionDescription('root', '', [boolean, val1, val2])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'boolean': True, 'val1': 'val1', 'val2': 'val1'}
cfg.option('boolean').value.set(False)
assert cfg.value.dict() == {'boolean': False, 'val1': 'val1', 'val2': 'default_value'}
def test_calc_value_allow_none():
def test_calc_value_allow_none(config_type):
val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "")
val3 = StrOption('val3', "", multi=True, callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), allow_none=ParamValue(True)))
od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': None, 'val3': ['val1', None]}
def test_calc_value_remove_duplicate():
def test_calc_value_remove_duplicate(config_type):
val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "", 'val1')
val3 = StrOption('val3', "", multi=True, callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), remove_duplicate_value=ParamValue(True)))
od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1', 'val3': ['val1']}
def test_calc_value_join():
def test_calc_value_join(config_type):
val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "", 'val2')
val3 = StrOption('val3', "", callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), join=ParamValue('.')))
od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val1.val2'}
@ -1279,10 +1341,11 @@ def test_calc_value_min():
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val4': ''}
def test_calc_value_add():
def test_calc_value_add(config_type):
val1 = IntOption('val1', "", 1)
val2 = IntOption('val2', "", 2)
val3 = IntOption('val3', "", callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), operator=ParamValue('add')))
od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 1, 'val2': 2, 'val3': 3}

View File

@ -1,5 +1,6 @@
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config
from py.test import raises
@ -49,42 +50,44 @@ def test_consistency_warnings_only_default():
assert w != []
def test_consistency_warnings_only():
def test_consistency_warnings_only(config_type):
a = IntOption('a', '')
b = IntOption('b', '')
c = IntOption('c', '')
od = OptionDescription('od', '', [a, b, c])
a.impl_add_consistency('not_equal', b, warnings_only=True)
api = Config(od)
assert api.option('a').option.consistencies()
assert not api.option('b').option.consistencies()
assert not api.option('c').option.consistencies()
api.option('a').value.set(1)
cfg = Config(od)
assert cfg.option('a').option.consistencies()
assert not cfg.option('b').option.consistencies()
assert not cfg.option('c').option.consistencies()
cfg = get_config(cfg, config_type)
cfg.option('a').value.set(1)
warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w:
api.option('b').value.set(1)
cfg.option('b').value.set(1)
assert w != []
def test_consistency_warnings_only_more_option():
def test_consistency_warnings_only_more_option(config_type):
a = IntOption('a', '')
b = IntOption('b', '')
d = IntOption('d', '')
od = OptionDescription('od', '', [a, b, d])
a.impl_add_consistency('not_equal', b, d, warnings_only=True)
api = Config(od)
api.option('a').value.set(1)
cfg = Config(od)
cfg = get_config(cfg, config_type)
cfg.option('a').value.set(1)
warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w:
api.option('b').value.set(1)
cfg.option('b').value.set(1)
assert w != []
assert len(w) == 1
with warnings.catch_warnings(record=True) as w:
api.option('d').value.get()
cfg.option('d').value.get()
assert w != []
assert len(w) == 1
with warnings.catch_warnings(record=True) as w:
api.option('d').value.set(1)
cfg.option('d').value.set(1)
assert w != []
assert len(w) == 1
@ -94,63 +97,72 @@ def test_consistency_error_prefix():
b = IntOption('b', '')
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
api = Config(od)
api.option('a').value.set(1)
cfg = Config(od)
cfg.option('a').value.set(1)
try:
api.option('b').value.set(1)
cfg.option('b').value.set(1)
except Exception as err:
assert str(err) == _('"{0}" is an invalid {1} for "{2}"').format('1', _('integer'), 'b') + ', ' + _('must be different from the value of {}').format('"a"')
try:
api.option('b').value.set(1)
cfg.option('b').value.set(1)
except Exception as err:
err.prefix = ''
assert str(err) == _('must be different from the value of {}').format('"a"')
def test_consistency_warnings_only_option():
def test_consistency_warnings_only_option(config_type):
a = IntOption('a', '')
b = IntOption('b', '', warnings_only=True)
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
api = Config(od)
api.option('a').value.set(1)
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
cfg.option('a').value.set(1)
warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w:
api.option('b').value.set(1)
cfg.option('b').value.set(1)
assert w != []
api.option('a').value.reset()
api.option('b').value.set(1)
raises(ValueError, "api.option('a').value.set(1)")
cfg.option('a').value.reset()
cfg.option('b').value.set(1)
raises(ValueError, "cfg.option('a').value.set(1)")
#
api.property.add('demoting_error_warning')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w:
api.option('a').value.set(1)
cfg.option('a').value.set(1)
assert len(w) == 1
def test_consistency_not_equal():
def test_consistency_not_equal(config_type):
a = IntOption('a', '')
b = IntOption('b', '')
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
api = Config(od)
assert api.option('a').value.get() is None
assert api.option('b').value.get() is None
api.option('a').value.set(1)
api.option('a').value.reset()
api.option('a').value.set(1)
raises(ValueError, "api.option('b').value.set(1)")
api.option('b').value.set(2)
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a').value.get() is None
assert cfg.option('b').value.get() is None
cfg.option('a').value.set(1)
cfg.option('a').value.reset()
cfg.option('a').value.set(1)
raises(ValueError, "cfg.option('b').value.set(1)")
cfg.option('b').value.set(2)
#
api.property.add('demoting_error_warning')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w:
api.option('b').value.set(1)
cfg.option('b').value.set(1)
assert len(w) == 1
def test_consistency_not_equal_many_opts():
def test_consistency_not_equal_many_opts(config_type):
config_type='tiramisu-api'
a = IntOption('a', '')
b = IntOption('b', '')
c = IntOption('c', '')
@ -159,38 +171,42 @@ def test_consistency_not_equal_many_opts():
f = IntOption('f', '')
od = OptionDescription('od', '', [a, b, c, d, e, f])
a.impl_add_consistency('not_equal', b, c, d, e, f)
api = Config(od)
assert api.option('a').value.get() is None
assert api.option('b').value.get() is None
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a').value.get() is None
assert cfg.option('b').value.get() is None
#
api.option('a').value.set(1)
api.option('a').value.reset()
cfg.option('a').value.set(1)
cfg.option('a').value.reset()
#
api.option('a').value.set(1)
raises(ValueError, "api.option('b').value.set(1)")
cfg.option('a').value.set(1)
raises(ValueError, "cfg.option('b').value.set(1)")
#
api.option('b').value.set(2)
raises(ValueError, "api.option('f').value.set(2)")
raises(ValueError, "api.option('f').value.set(1)")
cfg.option('b').value.set(2)
raises(ValueError, "cfg.option('f').value.set(2)")
raises(ValueError, "cfg.option('f').value.set(1)")
#
api.option('d').value.set(3)
raises(ValueError, "api.option('f').value.set(3)")
raises(ValueError, "api.option('a').value.set(3)")
api.option('d').value.set(3)
raises(ValueError, "api.option('c').value.set(3)")
raises(ValueError, "api.option('e').value.set(3)")
cfg.option('d').value.set(3)
raises(ValueError, "cfg.option('f').value.set(3)")
raises(ValueError, "cfg.option('a').value.set(3)")
cfg.option('d').value.set(3)
raises(ValueError, "cfg.option('c').value.set(3)")
raises(ValueError, "cfg.option('e').value.set(3)")
#
api.property.add('demoting_error_warning')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w:
api.option('c').value.set(3)
cfg.option('c').value.set(3)
assert len(w) == 1
with warnings.catch_warnings(record=True) as w:
api.option('e').value.set(3)
cfg.option('e').value.set(3)
assert len(w) == 1
def test_consistency_not_equal_many_opts_one_disabled():
def test_consistency_not_equal_many_opts_one_disabled(config_type):
a = IntOption('a', '')
b = IntOption('b', '')
c = IntOption('c', '')
@ -200,30 +216,36 @@ def test_consistency_not_equal_many_opts_one_disabled():
g = IntOption('g', '', properties=('disabled',))
od = OptionDescription('od', '', [a, b, c, d, e, f, g])
a.impl_add_consistency('not_equal', b, c, d, e, f, g, transitive=False)
api = Config(od)
api.property.read_write()
assert api.option('a').value.get() is None
assert api.option('b').value.get() is None
cfg_ori = Config(od)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a').value.get() is None
assert cfg.option('b').value.get() is None
#
api.option('a').value.set(1)
api.option('a').value.reset()
cfg.option('a').value.set(1)
cfg.option('a').value.reset()
#
api.option('a').value.set(1)
raises(ValueError, "api.option('b').value.set(1)")
cfg.option('a').value.set(1)
raises(ValueError, "cfg.option('b').value.set(1)")
#
api.option('b').value.set(2)
raises(ValueError, "api.option('f').value.set(2)")
raises(ValueError, "api.option('f').value.set(1)")
cfg.option('b').value.set(2)
raises(ValueError, "cfg.option('f').value.set(2)")
raises(ValueError, "cfg.option('f').value.set(1)")
#
api.option('d').value.set(3)
raises(ValueError, "api.option('f').value.set(3)")
raises(ValueError, "api.option('a').value.set(3)")
raises(ValueError, "api.option('c').value.set(3)")
raises(ValueError, "api.option('e').value.set(3)")
cfg.option('d').value.set(3)
raises(ValueError, "cfg.option('f').value.set(3)")
raises(ValueError, "cfg.option('a').value.set(3)")
raises(ValueError, "cfg.option('c').value.set(3)")
raises(ValueError, "cfg.option('e').value.set(3)")
#
api.property.add('demoting_error_warning')
if config_type == 'tiramisu-api':
cfg.send()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
api.option('c').value.set(3)
cfg.option('c').value.set(3)
assert len(w) == 1
@ -275,25 +297,29 @@ def test_consistency_not_equal_symlink():
c = SymLinkOption('c', a)
od = OptionDescription('od', '', [a, b, c])
a.impl_add_consistency('not_equal', b)
api = Config(od)
cfg = Config(od)
assert set(od._cache_consistencies.keys()) == set([a, b])
def test_consistency_mix():
def test_consistency_mix(config_type):
b = IntOption('b', '', multi=True)
c = IntOption('c', '', multi=True)
d = IntOption('d', '', multi=True)
od = Leadership('c', '', [c, d])
od2 = OptionDescription('a', '', [b, od])
c.impl_add_consistency('not_equal', b, d)
cfg = Config(od2)
cfg_ori = Config(od2)
cfg = get_config(cfg_ori, config_type)
cfg.option('b').value.set([1, 2, 3])
cfg.option('c.c').value.set([4, 5])
raises(ValueError, "cfg.option('c.c').value.set([1, 2])")
raises(ValueError, "cfg.option('c.d', 0).value.set(1)")
raises(ValueError, "cfg.option('c.d', 1).value.set(4)")
#
cfg.property.add('demoting_error_warning')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
cfg.option('c.d', 1).value.set(4)
assert len(w) == 1
@ -314,22 +340,23 @@ def test_consistency_not_equal_default_submulti():
raises(ConfigError, "a.impl_add_consistency('not_equal', b)")
def test_consistency_not_equal_leadership():
def test_consistency_not_equal_leadership(config_type):
a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True)
od = Leadership('a', '', [a, b])
od2 = OptionDescription('b', '', [od])
a.impl_add_consistency('not_equal', b)
api = Config(od2)
assert api.option('a.a').value.get() == []
api.option('a.a').value.set([1])
api.option('a.a').value.reset()
api.option('a.a').value.set([1])
raises(ValueError, "api.option('a.b', 0).value.set(1)")
api.option('a.b', 0).value.set(2)
api.option('a.a').value.reset()
api.option('a.a').value.set([1])
api.value.dict()
cfg = Config(od2)
cfg = get_config(cfg, config_type)
assert cfg.option('a.a').value.get() == []
cfg.option('a.a').value.set([1])
cfg.option('a.a').value.reset()
cfg.option('a.a').value.set([1])
raises(ValueError, "cfg.option('a.b', 0).value.set(1)")
cfg.option('a.b', 0).value.set(2)
cfg.option('a.a').value.reset()
cfg.option('a.a').value.set([1])
cfg.value.dict()
def test_consistency_not_equal_leadership_error_multi1():
@ -391,39 +418,44 @@ def test_consistency_not_equal_leadership_default():
od = Leadership('a', '', [a, b])
od2 = OptionDescription('a', '', [od])
a.impl_add_consistency('not_equal', b)
api = Config(od2)
assert api.option('a.a').value.get() == []
raises(ValueError, "api.option('a.a').value.set([1])")
api.option('a.a').value.set([2])
api.option('a.a').value.reset()
cfg = Config(od2)
# FIXME cfg = get_config(cfg, config_type)
assert cfg.option('a.a').value.get() == []
raises(ValueError, "cfg.option('a.a').value.set([1])")
cfg.option('a.a').value.set([2])
cfg.option('a.a').value.reset()
#
api.property.add('demoting_error_warning')
cfg.property.add('demoting_error_warning')
with warnings.catch_warnings(record=True) as w:
api.option('a.a').value.set([1])
cfg.option('a.a').value.set([1])
assert len(w) == 1
def test_consistency_not_equal_multi():
def test_consistency_not_equal_multi(config_type):
a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True)
od = OptionDescription('a', '', [a, b])
a.impl_add_consistency('not_equal', b)
api = Config(od)
assert api.option('a').value.get() == []
assert api.option('b').value.get() == []
api.option('a').value.set([1])
api.option('a').value.reset()
api.option('a').value.set([1])
raises(ValueError, "api.option('b').value.set([1])")
api.option('a').value.set([2])
raises(ValueError, "api.option('b').value.set([2, 1])")
api.option('a').value.set([2, 3])
raises(ValueError, "api.option('a').value.set([2, 3, 3])")
raises(ValueError, "api.option('b').value.set([2, 3])")
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a').value.get() == []
assert cfg.option('b').value.get() == []
cfg.option('a').value.set([1])
cfg.option('a').value.reset()
cfg.option('a').value.set([1])
raises(ValueError, "cfg.option('b').value.set([1])")
cfg.option('a').value.set([2])
raises(ValueError, "cfg.option('b').value.set([2, 1])")
cfg.option('a').value.set([2, 3])
raises(ValueError, "cfg.option('a').value.set([2, 3, 3])")
raises(ValueError, "cfg.option('b').value.set([2, 3])")
#
api.property.add('demoting_error_warning')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
api.option('b').value.set([2, 3])
cfg.option('b').value.set([2, 3])
assert len(w) == 1
@ -442,34 +474,39 @@ def test_consistency_not_equal_multi_default2():
a.impl_add_consistency('not_equal', b)
def test_consistency_not_equal_leader_default():
def test_consistency_not_equal_leader_default(config_type):
a = IntOption('a', '', multi=True, default=[2, 1])
b = IntOption('b', '', multi=True, default_multi=1)
od = Leadership('a', '', [a, b])
a.impl_add_consistency('not_equal', b)
od2 = OptionDescription('a', '', [od])
api = Config(od2)
cfg = Config(od2)
cfg = get_config(cfg, config_type)
# default_multi not tested
raises(ValueError, "api.option('a.b', 0).value.get()")
api.option('a.b', 0).value.set(3)
api.option('a.b', 1).value.set(3)
assert api.option('a.b', 1).value.get() == 3
raises(ValueError, "cfg.option('a.b', 0).value.get()")
cfg.option('a.b', 0).value.set(3)
cfg.option('a.b', 1).value.set(3)
assert cfg.option('a.b', 1).value.get() == 3
def test_consistency_not_equal_multi_default_modif():
def test_consistency_not_equal_multi_default_modif(config_type):
a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True, default=[1, 2])
od = OptionDescription('a', '', [a, b])
a.impl_add_consistency('not_equal', b)
api = Config(od)
assert api.option('a').value.get() == []
assert api.option('b').value.get() == [1, 2]
raises(ValueError, "api.option('a').value.set([1])")
raises(ValueError, "api.option('b').value.set([1, 2, 1])")
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a').value.get() == []
assert cfg.option('b').value.get() == [1, 2]
raises(ValueError, "cfg.option('a').value.set([1])")
raises(ValueError, "cfg.option('b').value.set([1, 2, 1])")
#
api.property.add('demoting_error_warning')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
api.option('b').value.set([1, 2, 1])
cfg.option('b').value.set([1, 2, 1])
assert len(w) == 1
@ -495,42 +532,48 @@ def test_consistency_default_diff():
b = IntOption('b', '', 1)
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
api = Config(od)
raises(ValueError, "api.option('a').value.set(1)")
api.option('a').value.set(2)
api.option('b').value.set(3)
owner = api.owner.get()
assert api.option('a').owner.get() == owner
raises(ValueError, "api.option('a').value.reset()")
assert api.option('a').owner.get() == owner
cfg = Config(od)
# FIXME cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set(1)")
cfg.option('a').value.set(2)
cfg.option('b').value.set(3)
owner = cfg.owner.get()
assert cfg.option('a').owner.get() == owner
raises(ValueError, "cfg.option('a').value.reset()")
assert cfg.option('a').owner.get() == owner
#
api.property.add('demoting_error_warning')
cfg.property.add('demoting_error_warning')
with warnings.catch_warnings(record=True) as w:
api.option('a').value.reset()
cfg.option('a').value.reset()
assert len(w) == 1
def test_consistency_ip_netmask():
def test_consistency_ip_netmask(config_type):
a = IPOption('a', '')
b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('ip_netmask', a)
api = Config(od)
api.option('a').value.set('192.168.1.1')
api.option('b').value.set('255.255.255.0')
api.option('a').value.set('192.168.1.2')
api.option('b').value.set('255.255.255.128')
api.option('b').value.set('255.255.255.0')
raises(ValueError, "api.option('a').value.set('192.168.1.0')")
raises(ValueError, "api.option('a').value.set('192.168.1.255')")
api.option('a').value.reset()
api.option('b').value.reset()
api.option('a').value.set('192.168.1.255')
raises(ValueError, "api.option('b').value.set('255.255.255.0')")
cfg_ori = Config(od)
cfg = cfg_ori
cfg = get_config(cfg_ori, config_type)
cfg.option('a').value.set('192.168.1.1')
cfg.option('b').value.set('255.255.255.0')
cfg.option('a').value.set('192.168.1.2')
cfg.option('b').value.set('255.255.255.128')
cfg.option('b').value.set('255.255.255.0')
raises(ValueError, "cfg.option('a').value.set('192.168.1.0')")
raises(ValueError, "cfg.option('a').value.set('192.168.1.255')")
cfg.option('a').value.reset()
cfg.option('b').value.reset()
cfg.option('a').value.set('192.168.1.255')
raises(ValueError, "cfg.option('b').value.set('255.255.255.0')")
#
api.property.add('demoting_error_warning')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
api.option('b').value.set('255.255.255.0')
cfg.option('b').value.set('255.255.255.0')
assert len(w) == 1
@ -540,22 +583,27 @@ def test_consistency_ip_netmask_invalid():
raises(ConfigError, "b.impl_add_consistency('ip_netmask')")
def test_consistency_network_netmask():
def test_consistency_network_netmask(config_type):
config_type = 'tiramisu-api'
a = NetworkOption('a', '')
b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('network_netmask', a)
api = Config(od)
api.option('a').value.set('192.168.1.1')
api.option('b').value.set('255.255.255.255')
api.option('b').value.reset()
api.option('a').value.set('192.168.1.0')
api.option('b').value.set('255.255.255.0')
raises(ValueError, "api.option('a').value.set('192.168.1.1')")
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
cfg.option('a').value.set('192.168.1.1')
cfg.option('b').value.set('255.255.255.255')
cfg.option('b').value.reset()
cfg.option('a').value.set('192.168.1.0')
cfg.option('b').value.set('255.255.255.0')
raises(ValueError, "cfg.option('a').value.set('192.168.1.1')")
#
api.property.add('demoting_error_warning')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
api.option('a').value.set('192.168.1.1')
cfg.option('a').value.set('192.168.1.1')
assert len(w) == 1
@ -565,7 +613,7 @@ def test_consistency_network_netmask_invalid():
raises(ConfigError, "b.impl_add_consistency('network_netmask')")
def test_consistency_ip_in_network():
def test_consistency_ip_in_network(config_type):
a = NetworkOption('a', '')
b = NetmaskOption('b', '')
c = IPOption('c', '')
@ -574,19 +622,20 @@ def test_consistency_ip_in_network():
c.impl_add_consistency('in_network', a, b)
d.impl_add_consistency('in_network', a, b, warnings_only=True)
warnings.simplefilter("always", ValueWarning)
api = Config(od)
api.option('a').value.set('192.168.1.0')
api.option('b').value.set('255.255.255.0')
api.option('c').value.set('192.168.1.1')
raises(ValueError, "api.option('c').value.set('192.168.2.1')")
raises(ValueError, "api.option('c').value.set('192.168.1.0')")
raises(ValueError, "api.option('c').value.set('192.168.1.255')")
cfg = Config(od)
cfg = get_config(cfg, config_type)
cfg.option('a').value.set('192.168.1.0')
cfg.option('b').value.set('255.255.255.0')
cfg.option('c').value.set('192.168.1.1')
raises(ValueError, "cfg.option('c').value.set('192.168.2.1')")
raises(ValueError, "cfg.option('c').value.set('192.168.1.0')")
raises(ValueError, "cfg.option('c').value.set('192.168.1.255')")
with warnings.catch_warnings(record=True) as w:
api.option('d').value.set('192.168.2.1')
cfg.option('d').value.set('192.168.2.1')
assert len(w) == 1
def test_consistency_ip_in_network_cidr():
def test_consistency_ip_in_network_cidr(config_type):
a = NetworkOption('a', '', cidr=True)
c = IPOption('c', '')
d = IPOption('d', '')
@ -594,14 +643,15 @@ def test_consistency_ip_in_network_cidr():
c.impl_add_consistency('in_network', a)
d.impl_add_consistency('in_network', a, warnings_only=True)
warnings.simplefilter("always", ValueWarning)
api = Config(od)
api.option('a').value.set('192.168.1.0/24')
api.option('c').value.set('192.168.1.1')
raises(ValueError, "api.option('c').value.set('192.168.2.1')")
raises(ValueError, "api.option('c').value.set('192.168.1.0')")
raises(ValueError, "api.option('c').value.set('192.168.1.255')")
cfg = Config(od)
cfg = get_config(cfg, config_type)
cfg.option('a').value.set('192.168.1.0/24')
cfg.option('c').value.set('192.168.1.1')
raises(ValueError, "cfg.option('c').value.set('192.168.2.1')")
raises(ValueError, "cfg.option('c').value.set('192.168.1.0')")
raises(ValueError, "cfg.option('c').value.set('192.168.1.255')")
with warnings.catch_warnings(record=True) as w:
api.option('d').value.set('192.168.2.1')
cfg.option('d').value.set('192.168.2.1')
assert len(w) == 1
@ -621,74 +671,87 @@ def test_consistency_ip_netmask_error_multi():
raises(ConfigError, "b.impl_add_consistency('ip_netmask', a)")
def test_consistency_ip_netmask_multi():
def test_consistency_ip_netmask_multi(config_type):
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = Leadership('a', '', [a, b])
b.impl_add_consistency('ip_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
api.option('a.a').value.set(['192.168.1.1'])
api.option('a.b', 0).value.set('255.255.255.0')
api.option('a.a').value.set(['192.168.1.2'])
api.option('a.b', 0).value.set('255.255.255.128')
api.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0'])")
cfg_ori = Config(od2)
cfg = get_config(cfg_ori, config_type)
cfg.option('a.a').value.set(['192.168.1.1'])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.a').value.set(['192.168.1.2'])
cfg.option('a.b', 0).value.set('255.255.255.128')
cfg.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.0'])")
#
api.property.add('demoting_error_warning')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
api.option('a.a').value.set(['192.168.1.0'])
cfg.option('a.a').value.set(['192.168.1.0'])
assert len(w) == 1
def test_consistency_network_netmask_multi():
def test_consistency_network_netmask_multi(config_type):
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od', '', [od])
api = Config(od2)
api.option('a.a').value.set(['192.168.1.1'])
api.option('a.b', 0).value.set('255.255.255.255')
api.option('a.b', 0).value.reset()
api.option('a.a').value.set(['192.168.1.0'])
api.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
cfg = Config(od2)
cfg = get_config(cfg, config_type)
cfg.option('a.a').value.set(['192.168.1.1'])
cfg.option('a.b', 0).value.set('255.255.255.255')
cfg.option('a.b', 0).value.reset()
cfg.option('a.a').value.set(['192.168.1.0'])
cfg.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.1'])")
def test_consistency_network_netmask_multi_follower_default_multi():
def test_consistency_network_netmask_multi_follower_default_multi(config_type):
a = NetworkOption('a', '', default_multi=u'192.168.1.0', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
od = Leadership('a', '', [a, b])
od2 = OptionDescription('od2', '', [od])
b.impl_add_consistency('network_netmask', a)
api = Config(od2)
api.property.read_write()
api.option('a.a').value.set([undefined])
assert api.option('a.a').value.get() == ['192.168.1.0']
assert api.option('a.b', 0).value.get() == '255.255.255.0'
cfg = Config(od2)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('a.a').value.set([undefined])
assert cfg.option('a.a').value.get() == ['192.168.1.0']
assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
def test_consistency_network_netmask_multi_follower_default():
def test_consistency_network_netmask_multi_follower_default(config_type):
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
api.property.read_write()
api.property.pop('cache')
assert api.option('a.a').value.get() == []
api.option('a.a').value.set(['192.168.1.0'])
api.property.read_only()
assert api.option('a.a').value.get() == [u'192.168.1.0']
assert api.option('a.b', 0).value.get() == u'255.255.255.0'
api.property.read_write()
raises(ValueError, "api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])")
api.option('a.a').value.set(['192.168.1.0', undefined])
api.option('a.b', 0).value.set('255.255.255.0')
api.option('a.b', 1).value.set('255.255.255.255')
api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])
cfg_ori = Config(od2)
cfg_ori.property.read_write()
cfg_ori.property.pop('cache')
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a.a').value.get() == []
cfg.option('a.a').value.set(['192.168.1.0'])
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a.a').value.get() == [u'192.168.1.0']
assert cfg.option('a.b', 0).value.get() == u'255.255.255.0'
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
raises(ValueError, "cfg.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])")
cfg.option('a.a').value.set(['192.168.1.0', undefined])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.b', 1).value.set('255.255.255.255')
cfg.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])
def return_netmask(*args, **kwargs):
@ -704,86 +767,96 @@ def return_netmask2(leader):
return u'255.255.255.0'
def test_consistency_network_netmask_multi_follower_callback():
def test_consistency_network_netmask_multi_follower_callback(config_type):
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', callback=return_netmask, multi=True, properties=('mandatory',))
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
api.property.read_write()
api.property.pop('cache')
assert api.option('a.a').value.get() == []
api.option('a.a').value.set(['192.168.1.0'])
api.property.read_only()
assert api.option('a.a').value.get() == [u'192.168.1.0']
assert api.option('a.b', 0).value.get() == '255.255.255.0'
api.property.read_write()
raises(ValueError, "assert api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])")
api.option('a.a').value.set(['192.168.1.0', undefined])
api.option('a.b', 0).value.set('255.255.255.0')
api.option('a.b', 1).value.set('255.255.255.255')
api.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
cfg_ori = Config(od2)
cfg_ori.property.read_write()
cfg_ori.property.pop('cache')
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a.a').value.get() == []
cfg.option('a.a').value.set(['192.168.1.0'])
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a.a').value.get() == [u'192.168.1.0']
assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
raises(ValueError, "assert cfg.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])")
cfg.option('a.a').value.set(['192.168.1.0', undefined])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.b', 1).value.set('255.255.255.255')
cfg.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
def test_consistency_network_netmask_multi_follower_callback_value():
def test_consistency_network_netmask_multi_follower_callback_value(config_type):
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', callback=return_netmask2, callback_params=Params(ParamOption(a)), multi=True, properties=('mandatory',))
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
api.property.read_write()
api.property.pop('cache')
assert api.option('a.a').value.get() == []
api.option('a.a').value.set(['192.168.1.0'])
assert api.option('a.a').value.get() == ['192.168.1.0']
assert api.option('a.b', 0).value.get() == '255.255.255.0'
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0', '192.168.2.1'])")
assert api.option('a.a').value.get() == [u'192.168.1.0']
assert api.option('a.b', 0).value.get() == '255.255.255.0'
raises(ValueError, "api.option('a.a').value.set(['192.168.2.1'])")
assert api.option('a.a').value.get() == [u'192.168.1.0']
assert api.option('a.b', 0).value.get() == '255.255.255.0'
api.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
api.option('a.b', 0).value.set('255.255.255.0')
api.option('a.b', 1).value.set('255.255.255.255')
cfg = Config(od2)
cfg.property.read_write()
cfg.property.pop('cache')
cfg = get_config(cfg, config_type)
assert cfg.option('a.a').value.get() == []
cfg.option('a.a').value.set(['192.168.1.0'])
assert cfg.option('a.a').value.get() == ['192.168.1.0']
assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.0', '192.168.2.1'])")
assert cfg.option('a.a').value.get() == [u'192.168.1.0']
assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
raises(ValueError, "cfg.option('a.a').value.set(['192.168.2.1'])")
assert cfg.option('a.a').value.get() == [u'192.168.1.0']
assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
cfg.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.b', 1).value.set('255.255.255.255')
def test_consistency_ip_netmask_multi_leader():
def test_consistency_ip_netmask_multi_leader(config_type):
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = Leadership('a', '', [a, b])
b.impl_add_consistency('ip_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
api.option('a.a').value.set(['192.168.1.1'])
api.option('a.b', 0).value.set('255.255.255.0')
api.option('a.a').value.set(['192.168.1.2'])
api.option('a.b', 0).value.set('255.255.255.128')
api.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0'])")
api.option('a.a').value.set(['192.168.1.128'])
raises(ValueError, "api.option('a.b', 0).value.set('255.255.255.128')")
api.option('a.a').value.set(['192.168.1.2', '192.168.1.3'])
cfg = Config(od2)
cfg = get_config(cfg, config_type)
cfg.option('a.a').value.set(['192.168.1.1'])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.a').value.set(['192.168.1.2'])
cfg.option('a.b', 0).value.set('255.255.255.128')
cfg.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.0'])")
cfg.option('a.a').value.set(['192.168.1.128'])
raises(ValueError, "cfg.option('a.b', 0).value.set('255.255.255.128')")
cfg.option('a.a').value.set(['192.168.1.2', '192.168.1.3'])
def test_consistency_network_netmask_multi_leader():
def test_consistency_network_netmask_multi_leader(config_type):
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
api.option('a.a').value.set(['192.168.1.1'])
api.option('a.b', 0).value.set('255.255.255.255')
api.option('a.b', 0).value.reset()
api.option('a.a').value.set(['192.168.1.0'])
api.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
cfg = Config(od2)
cfg = get_config(cfg, config_type)
cfg.option('a.a').value.set(['192.168.1.1'])
cfg.option('a.b', 0).value.set('255.255.255.255')
cfg.option('a.b', 0).value.reset()
cfg.option('a.a').value.set(['192.168.1.0'])
cfg.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.1'])")
def test_consistency_broadcast():
def test_consistency_broadcast(config_type):
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', multi=True)
@ -791,26 +864,27 @@ def test_consistency_broadcast():
b.impl_add_consistency('network_netmask', a)
c.impl_add_consistency('broadcast', a, b)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
cfg = Config(od2)
cfg = get_config(cfg, config_type)
#first, test network_netmask
api.option('a.a').value.set(['192.168.1.128'])
raises(ValueError, "api.option('a.a').value.set(['255.255.255.0'])")
cfg.option('a.a').value.set(['192.168.1.128'])
raises(ValueError, "cfg.option('a.a').value.set(['255.255.255.0'])")
#
api.option('a.a').value.set(['192.168.1.0'])
api.option('a.b', 0).value.set('255.255.255.0')
api.option('a.c', 0).value.set('192.168.1.255')
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
cfg.option('a.a').value.set(['192.168.1.0'])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.c', 0).value.set('192.168.1.255')
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.1'])")
#
api.option('a.a').value.set(['192.168.1.0', '192.168.2.128'])
api.option('a.b', 0).value.set('255.255.255.0')
api.option('a.b', 1).value.set('255.255.255.128')
api.option('a.c', 0).value.set('192.168.1.255')
api.option('a.c', 1).value.set('192.168.2.255')
raises(ValueError, "api.option('a.c', 1).value.set('192.168.2.128')")
api.option('a.c', 1).value.set('192.168.2.255')
cfg.option('a.a').value.set(['192.168.1.0', '192.168.2.128'])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.b', 1).value.set('255.255.255.128')
cfg.option('a.c', 0).value.set('192.168.1.255')
cfg.option('a.c', 1).value.set('192.168.2.255')
raises(ValueError, "cfg.option('a.c', 1).value.set('192.168.2.128')")
cfg.option('a.c', 1).value.set('192.168.2.255')
def test_consistency_broadcast_error():
def test_consistency_broadcast_error(config_type):
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', multi=True)
@ -818,25 +892,30 @@ def test_consistency_broadcast_error():
od2 = OptionDescription('od2', '', [od])
b.impl_add_consistency('network_netmask', a)
c.impl_add_consistency('broadcast', a)
api = Config(od2)
raises(ConfigError, "api.option('a.a').value.set(['192.168.1.0'])")
cfg = Config(od2)
cfg = get_config(cfg, config_type)
raises(ConfigError, "cfg.option('a.a').value.set(['192.168.1.0'])")
def test_consistency_broadcast_warnings():
def test_consistency_broadcast_warnings(config_type):
warnings.simplefilter("always", ValueWarning)
a = NetworkOption('a', '', properties=('mandatory', 'disabled'))
b = NetmaskOption('b', '', properties=('mandatory', 'disabled'))
c = NetmaskOption('c', '', properties=('mandatory', 'disabled'))
od = OptionDescription('a', '', [a, b, c])
b.impl_add_consistency('network_netmask', a, warnings_only=True)
api = Config(od)
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
api.option('a').value.set('192.168.1.4')
api.option('b').value.set('255.255.255.0')
cfg.option('a').value.set('192.168.1.4')
cfg.option('b').value.set('255.255.255.0')
assert len(w) == 1
api.property.read_write()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
list(api.value.mandatory())
list(cfg.value.mandatory())
assert len(w) == 0
@ -858,7 +937,7 @@ def test_consistency_broadcast_default_2():
d.impl_add_consistency('broadcast', a, b)
def test_consistency_not_all():
def test_consistency_not_all(config_type):
#_cache_consistencies is not None by not options has consistencies
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
@ -866,44 +945,48 @@ def test_consistency_not_all():
od = Leadership('a', '', [a, b, c])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
api.option('a.a').value.set(['192.168.1.0'])
api.option('a.b', 0).value.set('255.255.255.0')
api.option('a.c', 0).value.set('192.168.1.255')
cfg = Config(od2)
cfg = get_config(cfg, config_type)
cfg.option('a.a').value.set(['192.168.1.0'])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.c', 0).value.set('192.168.1.255')
def test_consistency_permissive():
def test_consistency_permissive(config_type):
a = IntOption('a', '', 1)
b = IntOption('b', '', 2, properties=('hidden',))
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
api = Config(od)
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
api.option('a').value.set(1)
cfg = Config(od)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
cfg = get_config(cfg, config_type)
cfg.option('a').value.set(1)
def test_consistency_disabled():
def test_consistency_disabled(config_type):
a = IntOption('a', '')
b = IntOption('b', '', properties=('disabled',))
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
api = Config(od)
api.property.read_write()
raises(PropertiesOptionError, "api.option('a').value.set(1)")
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
raises(PropertiesOptionError, "cfg.option('a').value.set(1)")
def test_consistency_disabled_transitive():
def test_consistency_disabled_transitive(config_type):
a = IntOption('a', '')
b = IntOption('b', '', properties=('disabled',))
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b, transitive=False)
api = Config(od)
api.property.read_write()
api.option('a').value.set(1)
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('a').value.set(1)
def test_consistency_disabled_transitive_2():
def test_consistency_disabled_transitive_2(config_type):
a = IPOption('a', '')
b = IPOption('b', '')
c = NetworkOption('c', '', default='192.168.1.0')
@ -911,19 +994,26 @@ def test_consistency_disabled_transitive_2():
od = OptionDescription('od', '', [a, b, c, d])
a.impl_add_consistency('not_equal', b)
a.impl_add_consistency('in_network', c, d, transitive=False)
api = Config(od)
api.property.read_write()
api.option('a').value.set('192.168.1.1')
raises(ValueError, "api.option('b').value.set('192.168.1.1')")
api.option('a').value.set('192.168.2.1')
cfg_ori = Config(od)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('a').value.set('192.168.1.1')
raises(ValueError, "cfg.option('b').value.set('192.168.1.1')")
cfg.option('a').value.set('192.168.2.1')
#
api.option('a').value.set('192.168.1.1')
api.property.pop('disabled')
raises(ValueError, "api.option('a').value.set('192.168.2.1')")
cfg.option('a').value.set('192.168.1.1')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('disabled')
cfg = get_config(cfg_ori, config_type)
raises(ValueError, "cfg.option('a').value.set('192.168.2.1')")
#
api.property.add('demoting_error_warning')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
api.option('a').value.set('192.168.2.1')
cfg.option('a').value.set('192.168.2.1')
assert len(w) == 1
@ -931,17 +1021,18 @@ def return_val(*args, **kwargs):
return '192.168.1.1'
def test_consistency_with_callback():
def test_consistency_with_callback(config_type):
a = NetworkOption('a', '', default='192.168.1.0')
b = NetmaskOption('b', '', default='255.255.255.0')
c = IPOption('c', '', callback=return_val, callback_params=Params(ParamOption(a)))
od = OptionDescription('od', '', [a, b, c])
c.impl_add_consistency('in_network', a, b)
api = Config(od)
api.option('c').value.get()
cfg = Config(od)
cfg = get_config(cfg, config_type)
cfg.option('c').value.get()
def test_consistency_warnings_only_options():
def test_consistency_warnings_only_options(config_type):
a = IPOption('a', '', warnings_only=True)
b = IPOption('b', '')
c = NetworkOption('c', '', default='192.168.1.0')
@ -949,20 +1040,24 @@ def test_consistency_warnings_only_options():
od = OptionDescription('od', '', [a, b, c, d])
a.impl_add_consistency('not_equal', b)
a.impl_add_consistency('in_network', c, d, transitive=False)
api = Config(od)
api.property.read_write()
api.option('a').value.set('192.168.1.1')
raises(ValueError, "api.option('b').value.set('192.168.1.1')")
api.option('a').value.set('192.168.2.1')
cfg_ori = Config(od)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('a').value.set('192.168.1.1')
raises(ValueError, "cfg.option('b').value.set('192.168.1.1')")
cfg.option('a').value.set('192.168.2.1')
#
api.option('a').value.set('192.168.1.1')
api.property.pop('disabled')
cfg.option('a').value.set('192.168.1.1')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('disabled')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
api.option('a').value.set('192.168.2.1')
cfg.option('a').value.set('192.168.2.1')
assert len(w) == 1
def test_consistency_warnings_only_options_callback():
def test_consistency_warnings_only_options_callback(config_type):
a = IPOption('a', '', warnings_only=True)
b = IPOption('b', '')
c = NetworkOption('c', '', default='192.168.1.0')
@ -970,22 +1065,26 @@ def test_consistency_warnings_only_options_callback():
od = OptionDescription('od', '', [a, b, c, d])
a.impl_add_consistency('not_equal', b)
a.impl_add_consistency('in_network', c, d, transitive=False)
api = Config(od)
api.property.read_write()
api.option('a').value.set('192.168.1.1')
raises(ValueError, "api.option('b').value.set('192.168.1.1')")
cfg_ori = Config(od)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('a').value.set('192.168.1.1')
raises(ValueError, "cfg.option('b').value.set('192.168.1.1')")
with warnings.catch_warnings(record=True) as w:
api.option('a').value.set('192.168.2.1')
cfg.option('a').value.set('192.168.2.1')
assert len(w) == 1
#
api.option('a').value.set('192.168.1.1')
api.property.pop('disabled')
cfg.option('a').value.set('192.168.1.1')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('disabled')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
api.option('a').value.set('192.168.2.1')
cfg.option('a').value.set('192.168.2.1')
assert len(w) == 1
def test_consistency_double_warnings():
def test_consistency_double_warnings(config_type):
a = IntOption('a', '')
b = IntOption('b', '', 1)
c = IntOption('c', '', 1)
@ -994,25 +1093,34 @@ def test_consistency_double_warnings():
a.impl_add_consistency('not_equal', b, warnings_only=True)
a.impl_add_consistency('not_equal', c, warnings_only=True)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
cfg_ori = Config(od2)
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
api.option('od.a').value.set(1)
cfg.option('od.a').value.set(1)
assert w != []
if config_type == 'tiramisu-api':
# in this case warnings is for '"a" and "b"'
assert len(w) == 1
else:
# in this cas one warnings is for "a" and the second for "b"
assert len(w) == 2
with warnings.catch_warnings(record=True) as w:
api.option('od.c').value.set(2)
cfg.option('od.c').value.set(2)
assert len(w) == 0
with warnings.catch_warnings(record=True) as w:
api.option('od.a').value.set(2)
assert w != []
cfg.option('od.a').value.set(2)
assert len(w) == 1
api.property.pop('warnings')
#
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('warnings')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
api.option('od.a').value.set(1)
cfg.option('od.a').value.set(1)
assert w == []
def test_consistency_warnings_error():
def test_consistency_warnings_error(config_type):
a = IntOption('a', '')
b = IntOption('b', '', 1)
c = IntOption('c', '', 1)
@ -1020,22 +1128,24 @@ def test_consistency_warnings_error():
warnings.simplefilter("always", ValueWarning)
a.impl_add_consistency('not_equal', b, warnings_only=True)
a.impl_add_consistency('not_equal', c)
api = Config(od)
cfg = Config(od)
cfg = get_config(cfg, config_type)
with warnings.catch_warnings(record=True) as w:
raises(ValueError, "api.option('a').value.set(1)")
raises(ValueError, "cfg.option('a').value.set(1)")
assert w == []
def test_consistency_network_netmask_mandatory():
def test_consistency_network_netmask_mandatory(config_type):
a = NetworkOption('a', '', multi=True, properties=('mandatory',), default=[u'0.0.0.0'])
b = NetmaskOption('b', '', multi=True, properties=('mandatory',), default_multi=u'0.0.0.0')
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
api.property.read_only()
api.property.pop('mandatory')
api.value.dict()
cfg = Config(od2)
cfg.property.read_only()
cfg.property.pop('mandatory')
cfg = get_config(cfg, config_type)
cfg.value.dict()
def test_consistency_has_dependency():
@ -1043,11 +1153,11 @@ def test_consistency_has_dependency():
b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('ip_netmask', a)
api = Config(od)
assert api.option('a').option.has_dependency() is True
assert api.option('b').option.has_dependency() is True
assert api.option('a').option.has_dependency(False) is True
assert api.option('b').option.has_dependency(False) is True
cfg = Config(od)
assert cfg.option('a').option.has_dependency() is True
assert cfg.option('b').option.has_dependency() is True
assert cfg.option('a').option.has_dependency(False) is True
assert cfg.option('b').option.has_dependency(False) is True
def test_consistency_not_equal_has_dependency():
@ -1055,8 +1165,8 @@ def test_consistency_not_equal_has_dependency():
b = IntOption('b', '')
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
api = Config(od)
assert api.option('a').option.has_dependency() is False
assert api.option('b').option.has_dependency() is False
assert api.option('a').option.has_dependency(False) is True
assert api.option('b').option.has_dependency(False) is True
cfg = Config(od)
assert cfg.option('a').option.has_dependency() is False
assert cfg.option('b').option.has_dependency() is False
assert cfg.option('a').option.has_dependency(False) is True
assert cfg.option('b').option.has_dependency(False) is True

View File

@ -1,6 +1,7 @@
"test all types of option default values for options, add new option in a descr"
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config
from py.test import raises
@ -11,6 +12,9 @@ from tiramisu import IntOption, FloatOption, StrOption, ChoiceOption, \
from tiramisu.storage import list_sessions
owners.addowner("frozenmultifollower")
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
@ -41,7 +45,7 @@ def make_description():
#____________________________________________________________
# default values
def test_default_is_none():
def test_default_is_none(config_type):
"""
Most constructors take a ``default`` argument that specifies the default
value of the option. If this argument is not supplied the default value is
@ -50,10 +54,11 @@ def test_default_is_none():
dummy1 = BoolOption('dummy1', 'doc dummy')
dummy2 = BoolOption('dummy2', 'doc dummy')
group = OptionDescription('group', '', [dummy1, dummy2])
api = Config(group)
cfg = Config(group)
cfg = get_config(cfg, config_type)
# so when the default value is not set, there is actually a default value
assert api.option('dummy1').value.get() is None
assert api.option('dummy2').value.get() is None
assert cfg.option('dummy1').value.get() is None
assert cfg.option('dummy2').value.get() is None
def test_set_defaut_value_from_option_object():
@ -67,49 +72,73 @@ def test_force_default_on_freeze():
dummy1 = BoolOption('dummy1', 'doc dummy', default=False, properties=('force_default_on_freeze',))
dummy2 = BoolOption('dummy2', 'doc dummy', default=True)
group = OptionDescription('group', '', [dummy1, dummy2])
api = Config(group)
api.property.read_write()
owner = api.owner.get()
api.option('dummy1').value.set(True)
api.option('dummy2').value.set(False)
assert api.option('dummy1').owner.get() == owner
assert api.option('dummy2').owner.get() == owner
api.option('dummy1').property.add('frozen')
api.option('dummy2').property.add('frozen')
assert api.option('dummy1').value.get() is False
assert api.option('dummy2').value.get() is False
assert api.option('dummy1').owner.isdefault()
assert api.option('dummy2').owner.get() == owner
raises(PropertiesOptionError, "api.option('dummy2').owner.set('frozen')")
raises(PropertiesOptionError, "api.option('dummy1').value.reset()")
api.option('dummy1').property.pop('frozen')
api.option('dummy1').value.reset()
api.option('dummy1').property.add('frozen')
raises(PropertiesOptionError, "api.option('dummy2').owner.set('frozen')")
cfg_ori = Config(group)
cfg_ori.property.read_write()
cfg = cfg_ori
# FIXME cfg = get_config(cfg_ori, config_type)
owner = cfg.owner.get()
cfg.option('dummy1').value.set(True)
cfg.option('dummy2').value.set(False)
assert cfg.option('dummy1').owner.get() == owner
assert cfg.option('dummy2').owner.get() == owner
# if config_type == 'tiramisu-api':
# cfg.send()
cfg_ori.option('dummy1').property.add('frozen')
cfg_ori.option('dummy2').property.add('frozen')
# cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy1').value.get() is False
assert cfg.option('dummy2').value.get() is False
assert cfg.option('dummy1').owner.isdefault()
assert cfg.option('dummy2').owner.get() == owner
# if config_type == 'tiramisu-api':
# cfg.send()
raises(PropertiesOptionError, "cfg_ori.option('dummy2').owner.set('frozen')")
# cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('dummy1').value.reset()")
# if config_type == 'tiramisu-api':
# cfg.send()
cfg_ori.option('dummy1').property.pop('frozen')
# cfg = get_config(cfg_ori, config_type)
cfg.option('dummy1').value.reset()
# if config_type == 'tiramisu-api':
# cfg.send()
cfg.option('dummy1').property.add('frozen')
# cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('dummy2').owner.set('frozen')")
def test_force_default_on_freeze_multi():
dummy1 = BoolOption('dummy1', 'doc dummy', default=[False], properties=('force_default_on_freeze',), multi=True)
dummy2 = BoolOption('dummy2', 'doc dummy', default=[True], multi=True)
group = OptionDescription('group', '', [dummy1, dummy2])
api = Config(group)
api.property.read_write()
api.option('dummy1').value.set([undefined, True])
api.option('dummy2').value.set([undefined, False])
owner = api.owner.get()
assert api.option('dummy1').owner.get() == owner
assert api.option('dummy2').owner.get() == owner
api.option('dummy1').property.add('frozen')
api.option('dummy2').property.add('frozen')
assert api.option('dummy1').value.get() == [False]
assert api.option('dummy2').value.get() == [True, False]
assert api.option('dummy1').owner.isdefault()
assert api.option('dummy2').owner.get() == owner
raises(PropertiesOptionError, "api.option('dummy2').owner.set('owner')")
raises(PropertiesOptionError, "api.option('dummy2').value.reset()")
api.option('dummy1').property.pop('frozen')
api.option('dummy1').value.reset()
api.option('dummy1').property.add('frozen')
cfg_ori = Config(group)
cfg_ori.property.read_write()
cfg = cfg_ori
# FIXME cfg = get_config(cfg_ori, config_type)
cfg.option('dummy1').value.set([undefined, True])
cfg.option('dummy2').value.set([undefined, False])
owner = cfg.owner.get()
assert cfg.option('dummy1').owner.get() == owner
assert cfg.option('dummy2').owner.get() == owner
# if config_type == 'tiramisu-api':
# cfg.send()
cfg_ori.option('dummy1').property.add('frozen')
cfg_ori.option('dummy2').property.add('frozen')
# cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy1').value.get() == [False]
assert cfg.option('dummy2').value.get() == [True, False]
assert cfg.option('dummy1').owner.isdefault()
assert cfg.option('dummy2').owner.get() == owner
# if config_type == 'tiramisu-api':
# cfg.send()
raises(PropertiesOptionError, "cfg_ori.option('dummy2').owner.set('owner')")
# cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('dummy2').value.reset()")
# if config_type == 'tiramisu-api':
# cfg.send()
cfg_ori.option('dummy1').property.pop('frozen')
# cfg = get_config(cfg_ori, config_type)
cfg.option('dummy1').value.reset()
def test_force_default_on_freeze_leader():
@ -133,8 +162,8 @@ def test_force_default_on_freeze_leader_frozen():
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr])
api = Config(descr)
raises(ConfigError, "api.option('dummy1.dummy1').property.pop('frozen')")
cfg = Config(descr)
raises(ConfigError, "cfg.option('dummy1.dummy1').property.pop('frozen')")
def test_force_metaconfig_on_freeze_leader_frozen():
@ -142,75 +171,93 @@ def test_force_metaconfig_on_freeze_leader_frozen():
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr])
api = Config(descr)
raises(ConfigError, "api.option('dummy1.dummy1').property.pop('frozen')")
cfg = Config(descr)
raises(ConfigError, "cfg.option('dummy1.dummy1').property.pop('frozen')")
def test_force_default_on_freeze_follower():
def test_force_default_on_freeze_follower(config_type):
dummy1 = BoolOption('dummy1', 'Test int option', multi=True)
dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',))
descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr])
api = Config(descr)
api.property.read_write()
owners.addowner("frozenmultifollower2")
api.option('dummy1.dummy1').value.set([True])
api.option('dummy1.dummy2', 0).value.set(False)
assert api.option('dummy1.dummy1').value.get() == [True]
assert api.option('dummy1.dummy2', 0).value.get() == False
assert api.option('dummy1.dummy1').owner.get() == 'user'
assert api.option('dummy1.dummy2', 0).owner.get() == 'user'
cfg_ori = Config(descr)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('dummy1.dummy1').value.set([True])
cfg.option('dummy1.dummy2', 0).value.set(False)
assert cfg.option('dummy1.dummy1').value.get() == [True]
assert cfg.option('dummy1.dummy2', 0).value.get() == False
assert cfg.option('dummy1.dummy1').owner.get() == 'user'
assert cfg.option('dummy1.dummy2', 0).owner.get() == 'user'
#
api.option('dummy1.dummy2').property.add('frozen')
assert api.option('dummy1.dummy1').value.get() == [True]
assert api.option('dummy1.dummy2', 0).value.get() == None
assert api.option('dummy1.dummy1').owner.get() == 'user'
assert api.option('dummy1.dummy2', 0).owner.isdefault()
raises(PropertiesOptionError, "api.option('dummy1.dummy2', 0).owner.set('frozenmultifollower2')")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('dummy1.dummy2').property.add('frozen')
cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy1.dummy1').value.get() == [True]
assert cfg.option('dummy1.dummy2', 0).value.get() == None
assert cfg.option('dummy1.dummy1').owner.get() == 'user'
assert cfg.option('dummy1.dummy2', 0).owner.isdefault()
if config_type == 'tiramisu-api':
cfg.send()
raises(PropertiesOptionError, "cfg_ori.option('dummy1.dummy2', 0).owner.set('frozenmultifollower')")
cfg = get_config(cfg_ori, config_type)
#
api.option('dummy1.dummy2').property.pop('frozen')
api.option('dummy1.dummy1').value.set([True, True])
api.option('dummy1.dummy2', 1).value.set(False)
assert api.option('dummy1.dummy1').value.get() == [True, True]
assert api.option('dummy1.dummy2', 0).value.get() == False
assert api.option('dummy1.dummy2', 1).value.get() == False
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('dummy1.dummy2').property.pop('frozen')
cfg = get_config(cfg_ori, config_type)
cfg.option('dummy1.dummy1').value.set([True, True])
cfg.option('dummy1.dummy2', 1).value.set(False)
assert cfg.option('dummy1.dummy1').value.get() == [True, True]
assert cfg.option('dummy1.dummy2', 0).value.get() == False
assert cfg.option('dummy1.dummy2', 1).value.get() == False
#
api.option('dummy1.dummy2').property.add('frozen')
assert api.option('dummy1.dummy1').value.get() == [True, True]
assert api.option('dummy1.dummy2', 0).value.get() == None
assert api.option('dummy1.dummy2', 1).value.get() == None
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('dummy1.dummy2').property.add('frozen')
cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy1.dummy1').value.get() == [True, True]
assert cfg.option('dummy1.dummy2', 0).value.get() == None
assert cfg.option('dummy1.dummy2', 1).value.get() == None
#
api.option('dummy1.dummy1').value.pop(1)
assert api.option('dummy1.dummy1').value.get() == [True]
assert api.option('dummy1.dummy2', 0).value.get() == None
cfg.option('dummy1.dummy1').value.pop(1)
assert cfg.option('dummy1.dummy1').value.get() == [True]
assert cfg.option('dummy1.dummy2', 0).value.get() == None
#
api.option('dummy1.dummy2').property.pop('frozen')
assert api.option('dummy1.dummy1').value.get() == [True]
assert api.option('dummy1.dummy2', 0).value.get() == False
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('dummy1.dummy2').property.pop('frozen')
cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy1.dummy1').value.get() == [True]
assert cfg.option('dummy1.dummy2', 0).value.get() == False
#
api.option('dummy1.dummy1').value.set([True, True])
assert api.option('dummy1.dummy2', 0).value.get() == False
assert api.option('dummy1.dummy2', 1).value.get() == None
cfg.option('dummy1.dummy1').value.set([True, True])
assert cfg.option('dummy1.dummy2', 0).value.get() == False
assert cfg.option('dummy1.dummy2', 1).value.get() == None
def test_overrides_changes_option_value():
def test_overrides_changes_option_value(config_type):
"with config.override(), the default is changed and the value is changed"
descr = OptionDescription("test", "", [
BoolOption("b", "", default=False)])
api = Config(descr)
api.option('b').value.set(True)
cfg = Config(descr)
cfg = get_config(cfg, config_type)
cfg.option('b').value.set(True)
def test_choice_with_no_default():
def test_choice_with_no_default(config_type):
descr = OptionDescription("test", "", [
ChoiceOption("backend", "", ("c", "cli"))])
api = Config(descr)
assert api.option('backend').value.get() is None
api.option('backend').value.set('c')
cfg = Config(descr)
cfg = get_config(cfg, config_type)
assert cfg.option('backend').value.get() is None
cfg.option('backend').value.set('c')
def test_choice_with_default():
def test_choice_with_default(config_type):
descr = OptionDescription("test", "", [
ChoiceOption("backend", "", ("c", "cli"), default="cli")])
api = Config(descr)
assert api.option('backend').value.get() == 'cli'
cfg = Config(descr)
cfg = get_config(cfg, config_type)
assert cfg.option('backend').value.get() == 'cli'

View File

@ -1,5 +1,6 @@
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config
from py.test import raises
@ -10,6 +11,10 @@ from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, APIEr
from tiramisu.storage import list_sessions
owners.addowner("readonly2")
owners.addowner("new2")
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
@ -36,41 +41,46 @@ def make_description():
return descr
def test_default_owner():
def test_default_owner(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr)
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == 'default'
api.option('dummy').value.set(True)
owner = api.owner.get()
assert api.option('dummy').owner.get() == owner
cfg = Config(descr)
cfg = get_config(cfg, config_type)
assert cfg.option('dummy').value.get() is False
assert cfg.option('dummy').owner.get() == 'default'
cfg.option('dummy').value.set(True)
owner = cfg.owner.get()
assert cfg.option('dummy').owner.get() == owner
def test_hidden_owner():
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('hidden',))
descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr)
api.property.read_write()
#raises(PropertiesOptionError, "api.forcepermissive.option('dummy').owner.get()")
#raises(PropertiesOptionError, "api.option('dummy').owner.isdefault()")
#raises(PropertiesOptionError, "api.forcepermissive.option('dummy').owner.isdefault()")
api.permissive.set(frozenset(['hidden']))
api.forcepermissive.option('dummy').value.get()
api.forcepermissive.option('dummy').owner.isdefault()
cfg = Config(descr)
cfg.property.read_write()
#raises(PropertiesOptionError, "cfg.forcepermissive.option('dummy').owner.get()")
#raises(PropertiesOptionError, "cfg.option('dummy').owner.isdefault()")
#raises(PropertiesOptionError, "cfg.forcepermissive.option('dummy').owner.isdefault()")
cfg.permissive.set(frozenset(['hidden']))
cfg.forcepermissive.option('dummy').value.get()
cfg.forcepermissive.option('dummy').owner.isdefault()
def test_addowner():
def test_addowner(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr)
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == 'default'
assert api.option('dummy').owner.isdefault()
api.owner.set('gen_config')
api.option('dummy').value.set(True)
assert api.option('dummy').owner.get() == owners.gen_config
assert not api.option('dummy').owner.isdefault()
cfg_ori = Config(descr)
cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy').value.get() is False
assert cfg.option('dummy').owner.get() == 'default'
assert cfg.option('dummy').owner.isdefault()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.owner.set('gen_config')
cfg = get_config(cfg_ori, config_type)
cfg.option('dummy').value.set(True)
assert cfg.option('dummy').owner.get() == owners.gen_config
assert not cfg.option('dummy').owner.isdefault()
def test_addowner_multiple_time():
@ -83,102 +93,128 @@ def test_delete_owner():
raises(ConstError, 'del(owners.deleted2)')
def test_owner_is_not_a_string():
def test_owner_is_not_a_string(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr)
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == owners.default
assert api.option('dummy').owner.get() == 'default'
assert isinstance(api.option('dummy').owner.get(), owners.Owner)
api.option('dummy').value.set(True)
assert api.option('dummy').owner.get() == 'user'
cfg = Config(descr)
cfg = get_config(cfg, config_type)
assert cfg.option('dummy').value.get() is False
assert cfg.option('dummy').owner.get() == owners.default
assert cfg.option('dummy').owner.get() == 'default'
assert isinstance(cfg.option('dummy').owner.get(), owners.Owner)
cfg.option('dummy').value.set(True)
assert cfg.option('dummy').owner.get() == 'user'
def test_setowner_without_valid_owner():
def test_setowner_without_valid_owner(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr)
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == 'default'
cfg = Config(descr)
cfg = get_config(cfg, config_type)
assert cfg.option('dummy').value.get() is False
assert cfg.option('dummy').owner.get() == 'default'
def test_setowner_for_value():
def test_setowner_for_value(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr)
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == 'default'
owners.addowner("new2")
raises(ConfigError, "api.option('dummy').owner.set('new2')")
api.option('dummy').value.set(False)
assert api.option('dummy').owner.get() == owners.user
api.option('dummy').owner.set('new2')
assert api.option('dummy').owner.get() == owners.new2
cfg_ori = Config(descr)
cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy').value.get() is False
assert cfg.option('dummy').owner.get() == 'default'
if config_type == 'tiramisu-api':
cfg.send()
raises(ConfigError, "cfg_ori.option('dummy').owner.set('new2')")
cfg = get_config(cfg_ori, config_type)
cfg.option('dummy').value.set(False)
assert cfg.option('dummy').owner.get() == owners.user
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('dummy').owner.set('new2')
cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy').owner.get() == owners.new2
def test_setowner_forbidden():
def test_setowner_forbidden(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr)
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == 'default'
raises(ValueError, "api.owner.set('default')")
api.option('dummy').value.set(False)
raises(ValueError, "api.option('dummy').owner.set('default')")
cfg_ori = Config(descr)
cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy').value.get() is False
assert cfg.option('dummy').owner.get() == 'default'
if config_type == 'tiramisu-api':
cfg.send()
raises(ValueError, "cfg_ori.owner.set('default')")
cfg = get_config(cfg_ori, config_type)
cfg.option('dummy').value.set(False)
if config_type == 'tiramisu-api':
cfg.send()
raises(ValueError, "cfg_ori.option('dummy').owner.set('default')")
cfg = get_config(cfg_ori, config_type)
def test_setowner_read_only():
def test_setowner_read_only(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr)
api.property.read_write()
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == 'default'
owners.addowner("readonly2")
api.option('dummy').value.set(False)
assert api.option('dummy').owner.get() == owners.user
api.property.read_only()
cfg_ori = Config(descr)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy').value.get() is False
assert cfg.option('dummy').owner.get() == 'default'
cfg.option('dummy').value.set(False)
assert cfg.option('dummy').owner.get() == owners.user
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_only()
raises(PropertiesOptionError,
"api.option('dummy').owner.set('readonly2')")
assert api.option('dummy').owner.get() == owners.user
"cfg_ori.option('dummy').owner.set('readonly2')")
cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy').owner.get() == owners.user
def test_setowner_optiondescription():
def test_setowner_optiondescription(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr1 = OptionDescription('tiramisu', '', [gcdummy])
descr = OptionDescription('tiramisu', '', [descr1])
api = Config(descr)
raises(APIError, "api.option('tiramisu').owner.get()")
raises(APIError, "api.option('tiramisu').owner.set('user')")
cfg = Config(descr)
cfg = get_config(cfg, config_type)
raises(APIError, "cfg.option('tiramisu').owner.get()")
raises(APIError, "cfg.option('tiramisu').owner.set('user')")
def test_setowner_symlinkoption():
def test_setowner_symlinkoption(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
s = SymLinkOption('symdummy', gcdummy)
descr1 = OptionDescription('tiramisu', '', [gcdummy, s])
descr = OptionDescription('tiramisu', '', [descr1])
api = Config(descr)
assert api.option('tiramisu.symdummy').owner.isdefault()
api.option('tiramisu.dummy').value.set(True)
assert not api.option('tiramisu.symdummy').owner.isdefault()
raises(ConfigError, "api.option('tiramisu.symdummy').owner.set('user')")
cfg_ori = Config(descr)
cfg = get_config(cfg_ori, config_type)
assert cfg.option('tiramisu.symdummy').owner.isdefault()
cfg.option('tiramisu.dummy').value.set(True)
assert not cfg.option('tiramisu.symdummy').owner.isdefault()
if config_type == 'tiramisu-api':
cfg.send()
raises(ConfigError, "cfg_ori.option('tiramisu.symdummy').owner.set('user')")
def test_owner_leadership():
def test_owner_leadership(config_type):
b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', multi=True)
descr = Leadership("int", "", [b, c])
od = OptionDescription('od', '', [descr])
api = Config(od)
raises(ConfigError, "api.option('int.str', 0).owner.set('user')")
cfg_ori = Config(od)
raises(ConfigError, "cfg_ori.option('int.str', 0).owner.set('user')")
cfg = get_config(cfg_ori, config_type)
api.option('int.int').value.set([0, 1])
api.option('int.str', 0).value.set('yes')
assert not api.option('int.str', 0).owner.isdefault()
assert api.option('int.str', 1).owner.isdefault()
api.option('int.str', 0).owner.set('user')
assert api.option('int.str', 0).owner.get() == owners.user
assert api.option('int.str', 1).owner.isdefault()
assert api.option('int.str', 0).value.get() == 'yes'
assert api.option('int.str', 1).value.get() == None
cfg.option('int.int').value.set([0, 1])
cfg.option('int.str', 0).value.set('yes')
assert not cfg.option('int.str', 0).owner.isdefault()
assert cfg.option('int.str', 1).owner.isdefault()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('int.str', 0).owner.set('user')
cfg = get_config(cfg_ori, config_type)
assert cfg.option('int.str', 0).owner.get() == owners.user
assert cfg.option('int.str', 1).owner.isdefault()
assert cfg.option('int.str', 0).value.get() == 'yes'
assert cfg.option('int.str', 1).value.get() == None

View File

@ -1,6 +1,7 @@
"config.set() or config.setoption() or option.setoption()"
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config
from py.test import raises
@ -40,14 +41,15 @@ def make_description():
#____________________________________________________________
# change with __setattr__
def test_attribute_access():
def test_attribute_access(config_type):
"Once set, option values can't be changed again by attribute access"
s = StrOption("string", "", default="string")
descr = OptionDescription("options", "", [s])
api = Config(descr)
cfg = Config(descr)
cfg = get_config(cfg, config_type)
# let's try to change it again
api.option('string').value.set('foo')
assert api.option('string').value.get() == 'foo'
cfg.option('string').value.set('foo')
assert cfg.option('string').value.get() == 'foo'
def test_mod_read_only_write():
@ -122,42 +124,45 @@ def test_mod_read_only_write():
raises(ValueError, "config2.property.getdefault('read_write', 'unknown')")
def test_setitem():
def test_setitem(config_type):
s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True)
descr = OptionDescription("options", "", [s])
api = Config(descr)
api.option('string').value.set([undefined, 'foo'])
assert api.option('string').value.get() == ['string', 'foo']
cfg = Config(descr)
cfg = get_config(cfg, config_type)
cfg.option('string').value.set([undefined, 'foo'])
assert cfg.option('string').value.get() == ['string', 'foo']
def test_reset():
def test_reset(config_type):
"if value is None, resets to default owner"
s = StrOption("string", "", default="string")
descr = OptionDescription("options", "", [s])
api = Config(descr)
api.option('string').value.set('foo')
assert api.option('string').value.get() == "foo"
assert api.option('string').owner.get() ==owners.user
api.option('string').value.reset()
assert api.option('string').value.get() == 'string'
assert api.option('string').owner.get() ==owners.default
cfg = Config(descr)
cfg = get_config(cfg, config_type)
cfg.option('string').value.set('foo')
assert cfg.option('string').value.get() == "foo"
assert cfg.option('string').owner.get() ==owners.user
cfg.option('string').value.reset()
assert cfg.option('string').value.get() == 'string'
assert cfg.option('string').owner.get() ==owners.default
def test_reset_with_multi():
def test_reset_with_multi(config_type):
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
descr = OptionDescription("options", "", [s])
api = Config(descr)
# api.option('string').value.set([])
api.option('string').value.reset()
assert api.option('string').value.get() == ["string"]
assert api.option('string').owner.get() =='default'
api.option('string').value.set(["eggs", "spam", "foo"])
assert api.option('string').owner.get() =='user'
api.option('string').value.set([])
api.option('string').value.reset()
# assert api.option('string').value.get() == ["string"]
assert api.option('string').owner.get() =='default'
raises(ValueError, "api.option('string').value.set(None)")
cfg = Config(descr)
cfg = get_config(cfg, config_type)
# cfg.option('string').value.set([])
cfg.option('string').value.reset()
assert cfg.option('string').value.get() == ["string"]
assert cfg.option('string').owner.get() =='default'
cfg.option('string').value.set(["eggs", "spam", "foo"])
assert cfg.option('string').owner.get() =='user'
cfg.option('string').value.set([])
cfg.option('string').value.reset()
# assert cfg.option('string').value.get() == ["string"]
assert cfg.option('string').owner.get() =='default'
raises(ValueError, "cfg.option('string').value.set(None)")
def test_property_only_raises():
@ -166,58 +171,61 @@ def test_property_only_raises():
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = OptionDescription("options", "", [s, intoption, stroption])
api = Config(descr)
api.property.read_write()
assert api.option('str').property.get() == {'empty'}
assert api.option('str').property.get(only_raises=True) == set()
cfg = Config(descr)
cfg.property.read_write()
assert cfg.option('str').property.get() == {'empty'}
assert cfg.option('str').property.get(only_raises=True) == set()
def test_default_with_multi():
"default with multi is a list"
s = StrOption("string", "", default=[], default_multi="string", multi=True)
descr = OptionDescription("options", "", [s])
api = Config(descr)
assert api.option('string').value.get() == []
cfg = Config(descr)
assert cfg.option('string').value.get() == []
s = StrOption("string", "", default=None, default_multi="string", multi=True)
descr = OptionDescription("options", "", [s])
api = Config(descr)
assert api.option('string').value.get() == []
cfg = Config(descr)
assert cfg.option('string').value.get() == []
def test_idontexist():
descr = make_description()
api = Config(descr)
api.value.dict()
raises(AttributeError, "api.option('idontexist').value.get()")
cfg = Config(descr)
cfg.value.dict()
raises(AttributeError, "cfg.option('idontexist').value.get()")
# ____________________________________________________________
def test_attribute_access_with_multi():
def test_attribute_access_with_multi(config_type):
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
descr = OptionDescription("options", "", [s])
api = Config(descr)
api.option('string').value.set(["foo", "bar"])
assert api.option('string').value.get() == ["foo", "bar"]
cfg = Config(descr)
cfg = get_config(cfg, config_type)
cfg.option('string').value.set(["foo", "bar"])
assert cfg.option('string').value.get() == ["foo", "bar"]
def test_item_access_with_multi():
def test_item_access_with_multi(config_type):
s = StrOption("string", "", default=["string"], multi=True)
descr = OptionDescription("options", "", [s])
api = Config(descr)
api.option('string').value.set(["foo", "bar"])
assert api.option('string').value.get() == ["foo", "bar"]
api.option('string').value.set(["changetest", "bar"])
assert api.option('string').value.get() == ["changetest", "bar"]
cfg = Config(descr)
cfg = get_config(cfg, config_type)
cfg.option('string').value.set(["foo", "bar"])
assert cfg.option('string').value.get() == ["foo", "bar"]
cfg.option('string').value.set(["changetest", "bar"])
assert cfg.option('string').value.get() == ["changetest", "bar"]
def test_access_with_multi_default():
def test_access_with_multi_default(config_type):
s = StrOption("string", "", default=["string"], multi=True)
descr = OptionDescription("options", "", [s])
api = Config(descr)
assert api.option('string').owner.get() =='default'
api.option('string').value.set(["foo", "bar"])
assert api.option('string').value.get() == ["foo", "bar"]
assert api.option('string').owner.get() =='user'
cfg = Config(descr)
cfg = get_config(cfg, config_type)
assert cfg.option('string').owner.get() =='default'
cfg.option('string').value.set(["foo", "bar"])
assert cfg.option('string').value.get() == ["foo", "bar"]
assert cfg.option('string').owner.get() =='user'
def test_multi_with_requires():
@ -226,12 +234,12 @@ def test_multi_with_requires():
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = OptionDescription("options", "", [s, intoption, stroption])
api = Config(descr)
api.property.read_write()
assert not 'hidden' in api.option('str').property.get()
api.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('str').value.set(['a', 'b'])")
assert 'hidden' in api.forcepermissive.option('str').property.get()
cfg = Config(descr)
cfg.property.read_write()
assert not 'hidden' in cfg.option('str').property.get()
cfg.option('int').value.set(1)
raises(PropertiesOptionError, "cfg.option('str').value.set(['a', 'b'])")
assert 'hidden' in cfg.forcepermissive.option('str').property.get()
def test__requires_with_inverted():
@ -240,10 +248,10 @@ def test__requires_with_inverted():
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
requires=[{'option': intoption, 'expected': 1, 'action': 'hide', 'inverse': True}], multi=True)
descr = OptionDescription("options", "", [s, intoption, stroption])
api = Config(descr)
assert not 'hidden' in api.option('str').property.get()
api.option('int').value.set(1)
assert not 'hidden' in api.option('str').property.get()
cfg = Config(descr)
assert not 'hidden' in cfg.option('str').property.get()
cfg.option('int').value.set(1)
assert not 'hidden' in cfg.option('str').property.get()
def test_multi_with_requires_in_another_group():
@ -253,12 +261,12 @@ def test_multi_with_requires_in_another_group():
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
api = Config(descr2)
api.property.read_write()
assert not 'hidden' in api.option('opt.str').property.get()
api.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('opt.str').value.set(['a', 'b'])")
assert 'hidden' in api.forcepermissive.option('opt.str').property.get()
cfg = Config(descr2)
cfg.property.read_write()
assert not 'hidden' in cfg.option('opt.str').property.get()
cfg.option('int').value.set(1)
raises(PropertiesOptionError, "cfg.option('opt.str').value.set(['a', 'b'])")
assert 'hidden' in cfg.forcepermissive.option('opt.str').property.get()
def test_multi_with_requires_in_another_group_inverse():
@ -268,12 +276,12 @@ def test_multi_with_requires_in_another_group_inverse():
requires=[{'option': intoption, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True)
descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
api = Config(descr2)
api.property.read_write()
assert not 'hidden' in api.option('opt.str').property.get()
api.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('opt.str').value.set(['a', 'b'])")
assert 'hidden' in api.forcepermissive.option('opt.str').property.get()
cfg = Config(descr2)
cfg.property.read_write()
assert not 'hidden' in cfg.option('opt.str').property.get()
cfg.option('int').value.set(1)
raises(PropertiesOptionError, "cfg.option('opt.str').value.set(['a', 'b'])")
assert 'hidden' in cfg.forcepermissive.option('opt.str').property.get()
def test_apply_requires_from_config():
@ -283,14 +291,14 @@ def test_apply_requires_from_config():
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
api = Config(descr2)
api.property.read_write()
assert not 'hidden' in api.option('opt.str').property.get()
api.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('opt.str').value.get()")
assert 'hidden' in api.forcepermissive.option('opt.str').property.get()
assert 'hidden' not in api.forcepermissive.option('opt.str').option.properties()
assert 'hidden' not in api.forcepermissive.option('opt.str').option.properties(only_raises=True)
cfg = Config(descr2)
cfg.property.read_write()
assert not 'hidden' in cfg.option('opt.str').property.get()
cfg.option('int').value.set(1)
raises(PropertiesOptionError, "cfg.option('opt.str').value.get()")
assert 'hidden' in cfg.forcepermissive.option('opt.str').property.get()
assert 'hidden' not in cfg.forcepermissive.option('opt.str').option.properties()
assert 'hidden' not in cfg.forcepermissive.option('opt.str').option.properties(only_raises=True)
def test_apply_requires_with_disabled():
@ -300,14 +308,14 @@ def test_apply_requires_with_disabled():
requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
api = Config(descr2)
api.property.read_write()
assert not 'disabled' in api.option('opt.str').property.get()
api.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('opt.str').value.get()")
assert 'disabled' not in api.unrestraint.option('opt.str').option.properties()
assert 'disabled' not in api.unrestraint.option('opt.str').option.properties(only_raises=True)
assert 'disabled' in api.unrestraint.option('opt.str').property.get()
cfg = Config(descr2)
cfg.property.read_write()
assert not 'disabled' in cfg.option('opt.str').property.get()
cfg.option('int').value.set(1)
raises(PropertiesOptionError, "cfg.option('opt.str').value.get()")
assert 'disabled' not in cfg.unrestraint.option('opt.str').option.properties()
assert 'disabled' not in cfg.unrestraint.option('opt.str').option.properties(only_raises=True)
assert 'disabled' in cfg.unrestraint.option('opt.str').property.get()
def test_multi_with_requires_with_disabled_in_another_group():
@ -317,12 +325,12 @@ def test_multi_with_requires_with_disabled_in_another_group():
requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
api = Config(descr2)
api.property.read_write()
assert not 'disabled' in api.option('opt.str').property.get()
api.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('opt.str').value.set(['a', 'b'])")
assert 'disabled' in api.unrestraint.option('opt.str').property.get()
cfg = Config(descr2)
cfg.property.read_write()
assert not 'disabled' in cfg.option('opt.str').property.get()
cfg.option('int').value.set(1)
raises(PropertiesOptionError, "cfg.option('opt.str').value.set(['a', 'b'])")
assert 'disabled' in cfg.unrestraint.option('opt.str').property.get()
def test_multi_with_requires_that_is_multi():
@ -361,24 +369,24 @@ def test_multi_with_requires_that_is_leadership_follower():
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': '1', 'action': 'hidden'}], multi=True)
descr = Leadership("int", "", [b, c, d])
descr2 = OptionDescription('od', '', [descr])
api = Config(descr2)
api.property.read_write()
assert api.option('int.int').value.get() == [0]
assert api.option('int.str', 0).value.get() == None
assert api.option('int.str1', 0).value.get() == None
api.option('int.int').value.set([0, 1])
assert api.option('int.int').value.get() == [0, 1]
assert api.option('int.str', 0).value.get() == None
assert api.option('int.str', 1).value.get() == None
assert api.option('int.str1', 0).value.get() == None
assert api.option('int.str1', 1).value.get() == None
api.option('int.str', 1).value.set('1')
api.property.read_only()
assert api.option('int.str1', 0).value.get() == None
assert api.option('int.str1', 1).value.get() == None
api.property.read_write()
assert api.option('int.str1', 0).value.get() == None
raises(PropertiesOptionError, "api.option('int.str1', 1).value.get()")
cfg = Config(descr2)
cfg.property.read_write()
assert cfg.option('int.int').value.get() == [0]
assert cfg.option('int.str', 0).value.get() == None
assert cfg.option('int.str1', 0).value.get() == None
cfg.option('int.int').value.set([0, 1])
assert cfg.option('int.int').value.get() == [0, 1]
assert cfg.option('int.str', 0).value.get() == None
assert cfg.option('int.str', 1).value.get() == None
assert cfg.option('int.str1', 0).value.get() == None
assert cfg.option('int.str1', 1).value.get() == None
cfg.option('int.str', 1).value.set('1')
cfg.property.read_only()
assert cfg.option('int.str1', 0).value.get() == None
assert cfg.option('int.str1', 1).value.get() == None
cfg.property.read_write()
assert cfg.option('int.str1', 0).value.get() == None
raises(PropertiesOptionError, "cfg.option('int.str1', 1).value.get()")
def test_multi_with_requires_that_is_leadership_follower_inverse():
@ -387,24 +395,24 @@ def test_multi_with_requires_that_is_leadership_follower_inverse():
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True)
descr = Leadership("int", "", [b, c, d])
descr2 = OptionDescription('od', '', [descr])
api = Config(descr2)
api.property.read_write()
assert api.option('int.int').value.get() == [0]
assert api.option('int.str', 0).value.get() is None
assert api.option('int.str1', 0).value.get() is None
api.option('int.int').value.set([0, 1])
assert api.option('int.int').value.get() == [0, 1]
assert api.option('int.str', 0).value.get() is None
assert api.option('int.str', 1).value.get() is None
assert api.option('int.str1', 0).value.get() is None
assert api.option('int.str1', 1).value.get() is None
api.option('int.str', 1).value.set('1')
api.property.read_only()
assert api.option('int.str1', 0).value.get() is None
assert api.option('int.str1', 1).value.get() is None
api.property.read_write()
assert api.option('int.str1', 0).value.get() is None
raises(PropertiesOptionError, "api.option('int.str1', 1).value.get()")
cfg = Config(descr2)
cfg.property.read_write()
assert cfg.option('int.int').value.get() == [0]
assert cfg.option('int.str', 0).value.get() is None
assert cfg.option('int.str1', 0).value.get() is None
cfg.option('int.int').value.set([0, 1])
assert cfg.option('int.int').value.get() == [0, 1]
assert cfg.option('int.str', 0).value.get() is None
assert cfg.option('int.str', 1).value.get() is None
assert cfg.option('int.str1', 0).value.get() is None
assert cfg.option('int.str1', 1).value.get() is None
cfg.option('int.str', 1).value.set('1')
cfg.property.read_only()
assert cfg.option('int.str1', 0).value.get() is None
assert cfg.option('int.str1', 1).value.get() is None
cfg.property.read_write()
assert cfg.option('int.str1', 0).value.get() is None
raises(PropertiesOptionError, "cfg.option('int.str1', 1).value.get()")
def test_multi_with_requires_that_is_not_same_leadership():
@ -422,32 +430,32 @@ def test_multi_with_requires_that_is_not_same_leadership():
def test_multi_with_bool():
s = BoolOption("bool", "", default=[False], multi=True)
descr = OptionDescription("options", "", [s])
api = Config(descr)
api.option('bool').value.set([True, False])
assert api.option('bool').value.get() == [True, False]
cfg = Config(descr)
cfg.option('bool').value.set([True, False])
assert cfg.option('bool').value.get() == [True, False]
def test_choice_access_with_multi():
ch = ChoiceOption("t1", "", ("a", "b"), default=["a"], multi=True)
descr = OptionDescription("options", "", [ch])
api = Config(descr)
api.option('t1').value.set(["a", "b", "a", "b"])
assert api.option('t1').value.get() == ["a", "b", "a", "b"]
cfg = Config(descr)
cfg.option('t1').value.set(["a", "b", "a", "b"])
assert cfg.option('t1').value.get() == ["a", "b", "a", "b"]
#____________________________________________________________
def test_accepts_multiple_changes_from_option():
s = StrOption("string", "", default="string")
descr = OptionDescription("options", "", [s])
api = Config(descr)
api.option('string').value.set("egg")
assert api.option('string').option.default() == "string"
assert api.option('string').value.get() == "egg"
api.option('string').value.set('blah')
assert api.option('string').option.default() == "string"
assert api.option('string').value.get() == "blah"
api.option('string').value.set('bol')
assert api.option('string').value.get() == 'bol'
cfg = Config(descr)
cfg.option('string').value.set("egg")
assert cfg.option('string').option.default() == "string"
assert cfg.option('string').value.get() == "egg"
cfg.option('string').value.set('blah')
assert cfg.option('string').option.default() == "string"
assert cfg.option('string').value.get() == "blah"
cfg.option('string').value.set('bol')
assert cfg.option('string').value.get() == 'bol'
def test_allow_multiple_changes_from_config():
@ -459,21 +467,21 @@ def test_allow_multiple_changes_from_config():
s2 = StrOption("string2", "", default="string")
suboption = OptionDescription("bip", "", [s2])
descr = OptionDescription("options", "", [s, suboption])
api = Config(descr)
api.option('string').value.set("oh")
assert api.option('string').value.get() == "oh"
api.option('string').value.set("blah")
assert api.option('string').value.get() == "blah"
cfg = Config(descr)
cfg.option('string').value.set("oh")
assert cfg.option('string').value.get() == "oh"
cfg.option('string').value.set("blah")
assert cfg.option('string').value.get() == "blah"
# ____________________________________________________________
# accessing a value by the get method
def test_access_by_get():
descr = make_description()
api = Config(descr)
raises(AttributeError, "list(api.option.find('idontexist'))")
assert api.option.find('wantref', first=True).value.get() is False
assert api.option.find('dummy', first=True).value.get() is False
cfg = Config(descr)
raises(AttributeError, "list(cfg.option.find('idontexist'))")
assert cfg.option.find('wantref', first=True).value.get() is False
assert cfg.option.find('dummy', first=True).value.get() is False
def test_access_by_get_whith_hide():
@ -484,74 +492,74 @@ def test_access_by_get_whith_hide():
BoolOption("d1", "")]),
BoolOption("b2", ""),
BoolOption("d1", "")])
api = Config(descr)
api.property.read_write()
raises(AttributeError, "api.option.find('b1').value.get()")
cfg = Config(descr)
cfg.property.read_write()
raises(AttributeError, "cfg.option.find('b1').value.get()")
def test_append_properties():
descr = make_description()
api = Config(descr)
assert api.option('gc.dummy').property.get() == set()
api.option('gc.dummy').property.add('test')
assert api.option('gc.dummy').property.get() == {'test'}
raises(ConfigError, "api.option('gc.dummy').property.add('force_store_value')")
assert api.option('gc.dummy').property.get() == {'test'}
cfg = Config(descr)
assert cfg.option('gc.dummy').property.get() == set()
cfg.option('gc.dummy').property.add('test')
assert cfg.option('gc.dummy').property.get() == {'test'}
raises(ConfigError, "cfg.option('gc.dummy').property.add('force_store_value')")
assert cfg.option('gc.dummy').property.get() == {'test'}
def test_reset_properties():
descr = make_description()
api = Config(descr)
assert api.option('gc.dummy').property.get() == set()
api.option('gc.dummy').property.add('frozen')
assert api.option('gc.dummy').property.get() == {'frozen'}
api.option('gc.dummy').property.reset()
assert api.option('gc.dummy').property.get() == set()
cfg = Config(descr)
assert cfg.option('gc.dummy').property.get() == set()
cfg.option('gc.dummy').property.add('frozen')
assert cfg.option('gc.dummy').property.get() == {'frozen'}
cfg.option('gc.dummy').property.reset()
assert cfg.option('gc.dummy').property.get() == set()
def test_properties_cached():
b1 = BoolOption("b1", "", properties=('test',))
descr = OptionDescription("opt", "", [OptionDescription("sub", "", [b1])])
api = Config(descr)
api.property.read_write()
assert api.option('sub.b1').property.get() == {'test'}
cfg = Config(descr)
cfg.property.read_write()
assert cfg.option('sub.b1').property.get() == {'test'}
def test_append_properties_force_store_value():
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
gcgroup = OptionDescription('gc', '', [gcdummy])
descr = OptionDescription('tiramisu', '', [gcgroup])
api = Config(descr)
assert api.option('gc.dummy').property.get() == {'force_store_value'}
api.option('gc.dummy').property.add('test')
assert api.option('gc.dummy').property.get() == {'force_store_value', 'test'}
cfg = Config(descr)
assert cfg.option('gc.dummy').property.get() == {'force_store_value'}
cfg.option('gc.dummy').property.add('test')
assert cfg.option('gc.dummy').property.get() == {'force_store_value', 'test'}
def test_reset_properties_force_store_value():
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
gcgroup = OptionDescription('gc', '', [gcdummy])
descr = OptionDescription('tiramisu', '', [gcgroup])
api = Config(descr)
assert api.property.exportation() == {}
api.property.add('frozen')
assert api.property.exportation() == \
cfg = Config(descr)
assert cfg.property.exportation() == {}
cfg.property.add('frozen')
assert cfg.property.exportation() == \
{None: set(('frozen', 'cache', 'validator', 'warnings'))}
api.property.reset()
assert api.property.exportation() == {}
api.option('gc.dummy').property.add('test')
assert api.property.exportation() == {'gc.dummy': set(('test', 'force_store_value'))}
api.property.reset()
assert api.property.exportation() == {'gc.dummy': set(('test', 'force_store_value'))}
api.property.add('frozen')
assert api.property.exportation() == \
cfg.property.reset()
assert cfg.property.exportation() == {}
cfg.option('gc.dummy').property.add('test')
assert cfg.property.exportation() == {'gc.dummy': set(('test', 'force_store_value'))}
cfg.property.reset()
assert cfg.property.exportation() == {'gc.dummy': set(('test', 'force_store_value'))}
cfg.property.add('frozen')
assert cfg.property.exportation() == \
{None: set(('frozen', 'validator', 'cache', 'warnings')),
'gc.dummy': set(('test', 'force_store_value'))}
api.property.add('frozen')
assert api.property.exportation() == \
cfg.property.add('frozen')
assert cfg.property.exportation() == \
{None: set(('frozen', 'validator', 'cache', 'warnings')),
'gc.dummy': set(('test', 'force_store_value'))}
api.option('gc.dummy').property.add('test')
assert api.property.exportation() == \
cfg.option('gc.dummy').property.add('test')
assert cfg.property.exportation() == \
{None: set(('frozen', 'validator', 'cache', 'warnings')),
'gc.dummy': set(('test', 'force_store_value'))}
@ -580,10 +588,10 @@ def test_set_modified_value():
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
gcgroup = OptionDescription('gc', '', [gcdummy])
descr = OptionDescription('tiramisu', '', [gcgroup])
api = Config(descr)
assert api.property.exportation() == {}
api.property.importation({None: set(('frozen', 'cache', 'validator', 'warnings'))})
assert api.property.exportation() == \
cfg = Config(descr)
assert cfg.property.exportation() == {}
cfg.property.importation({None: set(('frozen', 'cache', 'validator', 'warnings'))})
assert cfg.property.exportation() == \
{None: set(('frozen', 'cache', 'validator', 'warnings'))}
@ -611,12 +619,12 @@ def test_pprint():
val3 = StrOption('val3', "", requires=[{'option': stroption, 'expected': '2', 'action': 'hidden', 'inverse': True}])
descr = OptionDescription("options", "", [s, s2, s3, intoption, stroption, descr2, val3])
api = Config(descr)
api.property.read_write()
api.option('int').value.set(1)
cfg = Config(descr)
cfg.property.read_write()
cfg.option('int').value.set(1)
err = None
try:
api.option('str').value.get()
cfg.option('str').value.get()
except PropertiesOptionError as error:
err = error
@ -627,7 +635,7 @@ def test_pprint():
err = None
try:
api.option('options.val2').value.get()
cfg.option('options.val2').value.get()
except PropertiesOptionError as error:
err = error
@ -635,7 +643,7 @@ def test_pprint():
#err = None
#try:
# api.option('val3').value.get()
# cfg.option('val3').value.get()
#except PropertiesOptionError as error:
# err = error
@ -648,7 +656,7 @@ def test_pprint():
err = None
try:
api.option('string').value.get()
cfg.option('string').value.get()
except Exception as error:
err = error
@ -657,7 +665,7 @@ def test_pprint():
err = None
try:
api.option('string3').value.get()
cfg.option('string3').value.get()
except Exception as error:
err = error

View File

@ -257,7 +257,16 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription):
def defaultmulti(self):
"""Get default value when added a value for a multi option (not for optiondescription)"""
option = self._option_bag.option
return option.impl_getdefault_multi()
ret = option.impl_getdefault_multi()
if ret is None and option.impl_is_multi() and option.impl_has_callback() and not self.isfollower():
callback, callback_params = option.impl_get_callback()
values = self._option_bag.config_bag.context.cfgimpl_get_values()
value = values.carry_out_calculation(self._option_bag,
callback,
callback_params)
if not isinstance(value, list):
ret = value
return ret
def consistencies(self):
"""Get consistencies for an option (not for optiondescription)"""
@ -556,6 +565,11 @@ class _TiramisuOptionValueChoiceOption:
option = self._option_bag.option
return option.impl_get_values(self._option_bag)
def callbacks(self):
"""Get callbacks for a values"""
option = self._option_bag.option
return option.get_callback()
class _TiramisuOptionValueOptionDescription:

View File

@ -78,7 +78,7 @@ class PropertiesOptionError(AttributeError):
self.proptype = proptype
self._settings = settings
self.msg = None
super(PropertiesOptionError, self).__init__(None)
super().__init__(None)
def set_orig_opt(self, opt):
self._orig_opt = opt
@ -168,6 +168,7 @@ class _CommonError:
self.val = val
self.display_type = display_type
self.opt = weakref.ref(opt)
self.name = opt.impl_get_display_name()
self.err_msg = err_msg
self.index = index
super().__init__(self.err_msg)
@ -178,7 +179,7 @@ class _CommonError:
except AttributeError:
self.prefix = self.tmpl.format(self.val,
self.display_type,
self.opt().impl_get_display_name())
self.name)
msg = self.prefix
if self.err_msg:
if msg:

View File

@ -75,7 +75,7 @@ msgstr "group_type inconnu: {0}"
#: tiramisu/api.py:753 tiramisu/api.py:1208
msgid "please use .dict() before .updates()"
msgstr "faire .dico() avant .updates()"
msgstr "faire .dict() avant .updates()"
#: tiramisu/api.py:1000
msgid "properties must be a set"

View File

@ -81,25 +81,34 @@ class ChoiceOption(Option):
properties=properties,
warnings_only=warnings_only)
def get_callback(self):
values = self._choice_values
if isinstance(values, FunctionType):
return (values, getattr(self, '_choice_values_params', {}))
else:
return (None, None)
def impl_get_values(self,
option_bag,
current_opt=undefined):
if current_opt is undefined:
current_opt = self
values = self._choice_values
if isinstance(values, FunctionType):
values, values_params = self.get_callback()
if values is not None:
if option_bag is undefined:
values = undefined
else:
values = carry_out_calculation(current_opt,
callback=values,
callback_params=getattr(self, '_choice_values_params', {}),
callback_params=values_params,
index=None,
config_bag=option_bag.config_bag,
fromconsistency=[])
if values is not undefined and not isinstance(values, list):
raise ConfigError(_('calculated values for {0} is not a list'
'').format(self.impl_getname()))
else:
values = self._choice_values
return values

View File

@ -707,8 +707,7 @@ class Option(BaseOption):
for opt_ in [opts[idx_inf], opts[idx_inf + idx_sup + 1]]:
if opt_ == current_opt:
is_current = True
else:
if opt_ not in equal:
elif opt_ not in equal:
equal.append(opt_)
if equal:
if is_current:

View File

@ -406,7 +406,8 @@ class Settings(object):
def getproperties(self,
option_bag,
apply_requires=True):
apply_requires=True,
search_properties=None):
"""
"""
opt = option_bag.option
@ -432,7 +433,8 @@ class Settings(object):
opt.impl_getproperties())
if apply_requires:
props |= self.apply_requires(option_bag,
False)
False,
search_properties=search_properties)
props -= self.getpermissives(opt,
path)
if apply_requires:
@ -457,7 +459,8 @@ class Settings(object):
def apply_requires(self,
option_bag,
readable):
readable,
search_properties=None):
"""carries out the jit (just in time) requirements between options
a requirement is a tuple of this form that comes from the option's
@ -517,6 +520,8 @@ class Settings(object):
for requires in current_requires:
for require in requires:
exps, action, inverse, transitive, same_action, operator = require
#if search_properties and action not in search_properties:
# continue
breaked = False
for option, expected in exps:
if not isinstance(option, tuple):

View File

@ -65,6 +65,14 @@ class Values(Cache):
# follower
self._values[nb].append([value])
def _add_new_value(self, index, nb, value):
if index is None or nb == 0:
# not follower or path
self._values[nb].append(value)
else:
# follower
self._values[nb].append([value])
# value
def setvalue(self,
path,

View File

@ -3,8 +3,9 @@
import warnings
import sys
from copy import copy
from collections import OrderedDict
from .error import ValueWarning, ValueErrorWarning, PropertiesOptionError
from itertools import chain
from .error import ValueWarning, ValueErrorWarning, PropertiesOptionError, ConfigError
from .setting import undefined
from . import SynDynOption, RegexpOption, ChoiceOption, ParamContext, ParamOption
from .i18n import _
@ -57,23 +58,21 @@ class Callbacks(object):
def process_properties(self, form):
for callback, callback_params, path, childapi, schema, force_store_value in self.callbacks:
if childapi.option.isfollower():
self.tiramisu_web.set_remotable(path, form, childapi)
continue
has_option = False
if callback_params is not None:
for callback_param in callback_params.args:
for callback_param in chain(callback_params.args, callback_params.kwargs.values()):
if isinstance(callback_param, ParamContext):
raise ValueError(_('context is not supported from now for {}').format(path))
if isinstance(callback_param, ParamOption):
has_option = True
if callback.__name__ != 'tiramisu_copy' or 'expire' in childapi.option.properties():
if self.remotable == 'none':
raise ValueError(_('option {} only works when remotable is not "none"').format(path))
form[callback_param.option.impl_getpath()]['remote'] = True
remote = True
if not has_option and form.get(path, {}).get('remote') == False:
self.tiramisu_web.set_remotable(callback_param.option.impl_getpath(), form)
if not has_option and form.get(path, {}).get('remote', False) == False:
if 'expire' in childapi.option.properties():
if self.remotable == 'none':
raise ValueError(_('option {} only works when remotable is not "none"').format(path))
form.setdefault(path, {})['remote'] = True
self.tiramisu_web.set_remotable(path, form, childapi)
elif childapi.owner.isdefault():
# get calculated value and set clearable
schema[path]['value'] = childapi.value.get()
@ -83,7 +82,7 @@ class Callbacks(object):
def manage_callbacks(self, form):
for callback, callback_params, path, childapi, schema, force_store_value in self.callbacks:
if callback_params is not None:
for callback_param in callback_params.args:
for callback_param in chain(callback_params.args, callback_params.kwargs.values()):
if isinstance(callback_param, ParamOption) and callback.__name__ == 'tiramisu_copy':
opt_path = callback_param.option.impl_getpath()
if form.get(opt_path, {}).get('remote') is not True:
@ -98,41 +97,39 @@ class Callbacks(object):
class Consistencies(object):
def __init__(self, tiramisu_web):
self.not_equal = []
self.options = {}
self.not_equal = {}
self.tiramisu_web = tiramisu_web
def add(self, path, childapi):
child = childapi.option.get()
if isinstance(child, SynDynOption):
child = child._impl_getopt()
self.options[child] = path
def add(self, path, childapi, form):
if not childapi.option.isoptiondescription():
for consistency in childapi.option.consistencies():
cons_id, func, all_cons_opts, params = consistency
if func == '_cons_not_equal':
options = []
if func == '_cons_not_equal' and params.get('transitive', True) is True:
options_path = []
for option in all_cons_opts:
options_path.append(option()._path)
for idx, option in enumerate(all_cons_opts):
option = option()
options.append(option)
# FIXME transitive
self.not_equal.append((options, params.get('warnings_only')))
paths = options_path.copy()
paths.pop(idx)
warnings_only = params.get('warnings_only') or getattr(option, '_warnings_only', False)
self.not_equal.setdefault(option._path, {}).setdefault(warnings_only, []).extend(paths)
else:
for option in all_cons_opts:
self.tiramisu_web.set_remotable(option()._path, form)
def process(self, form):
for not_equal, warnings_only in self.not_equal:
not_equal_option = []
for option in not_equal:
not_equal_option.append(self.options[option])
for idx, path in enumerate(not_equal_option):
if form.get(path, {}).get('remote') is True:
continue
options = copy(not_equal_option)
options.pop(idx)
form.setdefault(path, {}).setdefault('not_equal',
{'options': []})
form[path]['not_equal']['options'].extend(options)
if warnings_only or getattr(option, '_warnings_only', False):
form[path]['not_equal']['warnings'] = True
for path in self.not_equal:
for warnings_only in self.not_equal[path]:
options = self.not_equal[path][warnings_only]
if path not in form:
form[path] = {}
if 'not_equal' not in form[path]:
form[path]['not_equal'] = []
obj = {'options': options}
if warnings_only:
obj['warnings'] = True
form[path]['not_equal'].append(obj)
class Requires(object):
@ -140,8 +137,6 @@ class Requires(object):
self.requires = {}
self.options = {}
self.tiramisu_web = tiramisu_web
self.config = tiramisu_web.config
self.remotable = tiramisu_web.remotable
def manage_requires(self,
childapi,
@ -153,37 +148,36 @@ class Requires(object):
for require in requires:
options, action, inverse, \
transitive, same_action, operator = require
if transitive is False:
if transitive is False or same_action is False or operator == 'and':
# transitive to "False" not supported yet for a requirement
if self.remotable == 'none':
raise ValueError('require set for {} but remotable is "none"'
''.format(path))
form.setdefault(path, {'key': path})['remote'] = True
return
if same_action is False:
# same_action to "False" not supported yet for a requirement
if self.remotable == 'none':
raise ValueError('require set for {} but remotable is "none"'
''.format(path))
form.setdefault(path, {'key': path})['remote'] = True
return
if operator == 'and':
# operator "and" not supported yet for a requirement
if self.remotable == 'none':
raise ValueError('require set for {} but remotable is "none"'
''.format(path))
form.setdefault(path, {'key': path})['remote'] = True
self.tiramisu_web.set_remotable(path, form, childapi)
return
for option, expected in options:
option_path = self.options.get(option)
if option_path is not None and action in action_hide:
option_path = option.impl_getpath()
if action in action_hide:
if isinstance(option, ChoiceOption):
choice_obj = self.tiramisu_web.config.unrestraint.option(option_path)
if choice_obj.value.is_values_callback():
self.tiramisu_web.set_remotable(option_path, form, choice_obj)
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:
if self.remotable == 'none':
raise ValueError('require set for {} but remotable is "none"'
''.format(path))
form.setdefault(option_path, {'key': option_path})['remote'] = True
self.tiramisu_web.set_remotable(option_path, form)
if inverse:
act = 'show'
inv_act = 'hide'
@ -196,25 +190,9 @@ class Requires(object):
)['expected'].setdefault(exp,
{}).setdefault(act,
[]).append(option_path)
if isinstance(option, ChoiceOption):
choice_obj = self.config.unrestraint.option(option_path)
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)
self.requires[path].setdefault('default', {}).setdefault(inv_act, []).append(option_path)
else:
if self.remotable == 'none':
raise ValueError('require set for {} but remotable est "none"'
''.format(path))
form.setdefault(option_path, {'key': option_path})['remote'] = True
self.tiramisu_web.set_remotable(option_path, form)
def add(self, path, childapi, form):
#collect id of all options
@ -231,7 +209,7 @@ class Requires(object):
current_action)
def is_remote(self, path, form):
if self.remotable == 'all':
if self.tiramisu_web.remotable == 'all':
return True
else:
return form.get(path) and form[path].get('remote', False)
@ -244,7 +222,7 @@ class Requires(object):
if 'default' in values:
for option in values['default'].get('show', []):
if path == option:
form.setdefault(path, {'key': path})['remote'] = True
self.tiramisu_web.set_remotable(path, form)
if not self.is_remote(option, form):
dependencies.setdefault(option,
{'default': {}, 'expected': {}}
@ -253,7 +231,7 @@ class Requires(object):
dependencies[option]['default']['show'].append(path)
for option in values['default'].get('hide', []):
if path == option:
form.setdefault(path, {'key': path})['remote'] = True
self.tiramisu_web.set_remotable(path, form)
if not self.is_remote(option, form):
dependencies.setdefault(option,
{'default': {}, 'expected': {}}
@ -265,7 +243,7 @@ class Requires(object):
expected = ''
for option in actions.get('show', []):
if path == option:
form.setdefault(path, {'key': path})['remote'] = True
self.tiramisu_web.set_remotable(path, form)
if not self.is_remote(option, form):
dependencies.setdefault(option,
{'expected': {}}
@ -275,7 +253,7 @@ class Requires(object):
dependencies[option]['expected'][expected]['show'].append(path)
for option in actions.get('hide', []):
if path == option:
form.setdefault(path, {'key': path})['remote'] = True
self.tiramisu_web.set_remotable(path, form)
if not self.is_remote(option, form):
dependencies.setdefault(option,
{'expected': {}}
@ -336,6 +314,18 @@ class TiramisuDict:
path = root + '.' + childname
yield path, childapi
def set_remotable(self, path, form, childapi=None):
if self.remotable == 'none':
raise ValueError(_('option {} only works when remotable is not "none"').format(path))
form.setdefault(path, {})['remote'] = True
if childapi is None:
childapi = self.config.unrestraint.option(path)
if childapi.option.isfollower():
parent_path = path.rsplit('.', 1)[0]
parent = self.config.unrestraint.option(parent_path)
leader = next(parent.list())
form.setdefault(leader.option.path(), {})['remote'] = True
def walk(self,
root,
subchildapi,
@ -345,6 +335,7 @@ class TiramisuDict:
order,
updates_status,
init=False):
error = None
if init:
if form is not None:
self.requires = Requires(self)
@ -352,6 +343,7 @@ class TiramisuDict:
self.callbacks = Callbacks(self)
else:
init = False
try:
if subchildapi is None:
if root is None:
subchildapi = self.config.unrestraint.option
@ -364,13 +356,15 @@ class TiramisuDict:
for path, childapi in self.get_list(root, subchildapi):
if isleadership and leader_len is None:
leader_len = childapi.value.len()
one_is_remote = False
props_no_requires = set(childapi.option.properties())
if form is not None:
self.requires.add(path,
childapi,
form)
self.consistencies.add(path,
childapi)
childapi,
form)
self.callbacks.add(path,
childapi,
schema,
@ -392,7 +386,7 @@ class TiramisuDict:
else:
type_ = 'object'
if schema is not None:
schema[path] = {'properties': OrderedDict(),
schema[path] = {'properties': {},
'type': type_}
subschema = schema[path]['properties']
else:
@ -414,21 +408,16 @@ class TiramisuDict:
else:
web_type = childapi_option.type()
value = childapi.option.default()
if value not in [[], None]:
has_value = True
else:
if value == []:
value = None
has_value = False
is_multi = childapi_option.ismulti()
if is_multi:
default = childapi_option.defaultmulti()
if default not in [None, []]:
has_value = True
defaultmulti = childapi_option.defaultmulti()
if defaultmulti == []:
defaultmulti = None
else:
default = None
else:
default = None
defaultmulti = None
if schema is not None:
self.gen_schema(schema,
@ -437,28 +426,37 @@ class TiramisuDict:
path,
props_no_requires,
value,
default,
defaultmulti,
is_multi,
web_type)
web_type,
form)
if form is not None:
self.gen_form(form,
web_type,
path,
child,
childapi_option,
childtype,
has_value)
childtype)
if schema is not None:
if web_type != 'symlink':
schema[path]['title'] = childapi_option.doc()
self.add_help(schema[path],
childapi)
except Exception as err:
if not init:
raise err
error = err
if init and form is not None:
self.callbacks.process(form)
self.requires.process(form)
self.consistencies.process(form)
del self.requires
del self.consistencies
del self.callbacks
if error:
msg = str(error)
del error
raise ConfigError(_('unable to transform tiramisu object to dict: {}').format(msg))
def gen_schema(self,
@ -468,9 +466,10 @@ class TiramisuDict:
path,
props_no_requires,
value,
default,
defaultmulti,
is_multi,
web_type):
web_type,
form):
schema[path] = {'type': web_type}
if childapi_option.issymlinkoption():
schema[path]['opt_path'] = childapi_option.get().impl_getopt().impl_getpath()
@ -478,8 +477,8 @@ class TiramisuDict:
if value is not None:
schema[path]['value'] = value
if default is not None:
schema[path]['default'] = default
if defaultmulti is not None:
schema[path]['defaultmulti'] = defaultmulti
if is_multi:
schema[path]['isMulti'] = is_multi
@ -491,6 +490,12 @@ class TiramisuDict:
schema[path]['autoFreeze'] = True
if web_type == 'choice':
values, values_params = childapi.value.callbacks()
if values_params:
for values_param in chain(values_params.args, values_params.kwargs.values()):
if isinstance(values_param, ParamOption):
self.set_remotable(path, form, childapi)
return
schema[path]['enum'] = self.get_enum(childapi,
is_multi,
path,
@ -514,26 +519,28 @@ class TiramisuDict:
path,
child,
childapi_option,
childtype,
has_value):
childtype):
obj_form = {}
if path in form:
obj_form.update(form[path])
if not childapi_option.issymlinkoption():
if self.clearable == 'all':
obj_form['clearable'] = True
if has_value and self.clearable != 'none':
if self.clearable != 'none':
obj_form['clearable'] = True
if self.remotable == 'all' or childapi_option.has_dependency():
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')):
obj_form['remote'] = True
if not obj_form.get('remote', False):
pattern = childapi_option.pattern()
if pattern is not None:
obj_form['pattern'] = pattern
if childtype == 'FloatOption':
obj_form['step'] = 'any'
if childtype == 'PortOption':
obj_form['min'] = child.impl_get_extra('_min_value')
obj_form['max'] = child.impl_get_extra('_max_value')
if childtype == 'FloatOption':
obj_form['step'] = 'any'
if web_type == 'choice':
obj_form['type'] = 'choice'
elif web_type in INPUTS:
@ -541,50 +548,67 @@ class TiramisuDict:
if obj_form:
form[path] = obj_form
def calc_raises_properties(self, childapi):
def calc_raises_properties(self,
obj,
childapi):
old_properties = childapi._option_bag.config_bag.properties
del childapi._option_bag.config_bag.properties
ret = childapi.option.properties(only_raises=True)
if 'permissive' not in childapi._option_bag.config_bag.properties:
childapi._option_bag.config_bag.properties = childapi._option_bag.config_bag.properties | {'permissive'}
# 'display=False' means cannot access only without permissive option
# 'hidden=True' means cannot access with or without permissive option
if childapi.option.properties(only_raises=True):
obj['hidden'] = True
childapi._option_bag.config_bag.properties = childapi._option_bag.config_bag.properties - {'permissive'}
if childapi.option.properties(only_raises=True):
obj['display'] = False
childapi._option_bag.config_bag.properties = old_properties
return ret
def _gen_model_properties(self,
childapi,
path,
index,
props_no_requires):
obj = {}
isfollower = childapi.option.isfollower()
if index is None and isfollower:
# cannot calculated requires with follower without index
props = props_no_requires
else:
props = set(childapi.property.get())
if self.calc_raises_properties(childapi):
obj['display'] = False
if not isfollower and childapi.option.ismulti():
if 'empty' in props:
obj = self.gen_properties(props,
isfollower,
childapi.option.ismulti())
self.calc_raises_properties(obj, childapi)
return obj
def gen_properties(self,
properties,
isfollower=False,
ismulti=False):
obj = {}
if not isfollower and ismulti:
if 'empty' in properties:
obj['required'] = True
props.remove('empty')
if 'mandatory' in props:
properties.remove('empty')
if 'mandatory' in properties:
obj['needs_len'] = True
props.remove('mandatory')
elif 'mandatory' in props:
properties.remove('mandatory')
elif 'mandatory' in properties:
obj['required'] = True
props.remove('mandatory')
if 'frozen' in props:
properties.remove('mandatory')
if 'frozen' in properties:
obj['readOnly'] = True
props.remove('frozen')
if 'hidden' in props:
obj['hidden'] = True
props.remove('hidden')
if 'disabled' in props:
obj['hidden'] = True
props.remove('disabled')
if props:
lprops = list(props)
properties.remove('frozen')
#if 'hidden' in properties:
# obj['hidden'] = True
# properties.remove('hidden')
#if 'disabled' in properties:
# obj['hidden'] = True
# properties.remove('disabled')
if properties:
lprops = list(properties)
lprops.sort()
obj['properties'] = lprops
obj['props'] = lprops
return obj
def gen_model(self,
@ -597,14 +621,11 @@ class TiramisuDict:
if childapi.option.isoptiondescription():
props = set(childapi.property.get())
obj = {}
if self.calc_raises_properties(childapi):
obj['display'] = False
self.calc_raises_properties(obj, childapi)
if props:
lprops = list(props)
lprops.sort()
obj['properties'] = lprops
if 'hidden' in props or 'disabled' in props:
obj['hidden'] = True
try:
self.config.option(path).option.get()
except PropertiesOptionError:
@ -646,7 +667,13 @@ class TiramisuDict:
obj,
index,
updates_status):
# FIXME unrestraint ...
if path in updates_status and index in updates_status[path]:
value = childapi.value.get()
self._get_value_with_exception(obj,
childapi,
updates_status[path][index])
del updates_status[path][index]
else:
try:
nchildapi = self.config.option(path, index=index)
with warnings.catch_warnings(record=True) as warns:
@ -654,9 +681,13 @@ class TiramisuDict:
self._get_value_with_exception(obj,
childapi,
warns)
except PropertiesOptionError:
except ValueError as err:
self._get_value_with_exception(obj,
childapi,
[err])
value = self.config.unrestraint.option(path, index=index).value.get()
except PropertiesOptionError as err:
value = childapi.value.get()
warns = []
if value is not None and value != []:
obj['value'] = value
obj['owner'] = childapi.owner.get()
@ -666,9 +697,13 @@ class TiramisuDict:
childapi,
values):
for value in values:
if isinstance(value.message, ValueErrorWarning):
if isinstance(value, ValueError):
obj.setdefault('error', [])
obj['error'].append(str(value))
obj['invalid'] = True
elif isinstance(value.message, ValueErrorWarning):
value.message.prefix = ''
if childapi.option.isleader():
if childapi.option.isfollower():
obj.setdefault('invalid', [])
obj['invalid'].append({'error': str(value.message),
'index': value.message.index})
@ -681,10 +716,19 @@ class TiramisuDict:
obj['warnings'].append(str(value.message))
obj['hasWarnings'] = True
def gen_global(self):
ret = {}
ret['owner'] = self.config.owner.get()
ret['properties'] = list(self.config.property.get())
ret['properties'].sort()
ret['permissives'] = list(self.config.permissive.get())
ret['permissives'].sort()
return ret
def get_form(self, form):
ret = []
buttons = []
dict_form = OrderedDict()
dict_form = {}
for form_ in form:
if 'key' in form_:
dict_form[form_['key']] = form_
@ -723,7 +767,7 @@ class TiramisuDict:
childapi.value.set(value)
else:
multi = childapi.value.get()
if not multi and index == 0:
if len(multi) < index + 1:
multi.append(value)
else:
multi[index] = value
@ -744,12 +788,12 @@ class TiramisuDict:
if childapi_option.isfollower():
childapi = self.config.option(path, index)
with warnings.catch_warnings(record=True) as warns:
#try:
try:
if update['action'] == 'modify':
self.mod_value(childapi,
path,
index,
update.get('value'))
update.get('value', undefined))
elif update['action'] == 'delete':
self.del_value(childapi,
path,
@ -761,9 +805,8 @@ class TiramisuDict:
raise ValueError(_('only multi option can have action "add", but "{}" is not a multi').format(path))
else:
raise ValueError(_('unknown action'))
#except ValueError as err:
# updates_status.setdefault(path, {})[index] = err
# continue
except ValueError as err:
updates_status.setdefault(path, {})[index] = [err]
if warns != []:
updates_status.setdefault(path, {}).setdefault(index, []).extend(warns)
return updates_status
@ -797,7 +840,7 @@ class TiramisuDict:
updates_status={}):
rootpath = self.root
if build_schema:
schema = OrderedDict()
schema = {}
else:
schema = None
if build_model:
@ -809,6 +852,7 @@ class TiramisuDict:
buttons = []
else:
form = None
ret = {}
self.walk(rootpath,
None,
schema,
@ -832,6 +876,7 @@ class TiramisuDict:
ret['schema'] = schema
if build_model:
ret['model'] = model
ret['global'] = self.gen_global()
if build_form:
ret['form'] = form
ret['version'] = '1.0'

View File

@ -77,7 +77,7 @@ class Values(object):
check_error=True)
# store value in cache
validator = 'validator' in option_bag.config_bag.properties
if not is_cached or validator:
if not option_bag.fromconsistency and (not is_cached or validator):
self._p_.setcache(option_bag.path,
option_bag.index,
value,