master/slaves => leader/followers

This commit is contained in:
2019-02-23 19:06:23 +01:00
parent b9ae1ec656
commit c3f968dbde
35 changed files with 923 additions and 1031 deletions

View File

@ -9,9 +9,9 @@ from collections import OrderedDict
from .autopath import do_autopath
do_autopath()
from tiramisu import Config, MetaConfig, \
StrOption, SymLinkOption, OptionDescription, MasterSlaves, DynOptionDescription, \
StrOption, SymLinkOption, OptionDescription, Leadership, DynOptionDescription, \
submulti, undefined, owners, Params, ParamOption
from tiramisu.error import PropertiesOptionError, APIError, ConfigError, SlaveError
from tiramisu.error import PropertiesOptionError, APIError, ConfigError, LeadershipError
ICON = u'\u2937'
OPTIONS_TYPE = {'str': {'type': str,
@ -73,18 +73,18 @@ def autocheck(func):
def _autocheck_default_value(cfg, path, conf, **kwargs):
"""set and get values
"""
# check if is a multi, a master or a slave
# check if is a multi, a leader or a follower
multi = cfg.unrestraint.option(path).option.ismulti()
submulti_ = cfg.unrestraint.option(path).option.issubmulti()
isslave = cfg.unrestraint.option(path).option.isslave()
isfollower = cfg.unrestraint.option(path).option.isfollower()
# set default value (different if value is multi or not)
empty_value = kwargs['default']
# test default value (should be empty)
# cannot test for slave (we cannot get all values for a slave)
# cannot test for follower (we cannot get all values for a follower)
with warnings.catch_warnings(record=True) as w:
if not isslave:
if not isfollower:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert cfg.config(conf).option(path).value.get() == empty_value
assert cfg.config(conf).forcepermissive.option(path).value.get() == empty_value
@ -113,26 +113,26 @@ def _set_value(cfg, pathwrite, conf, **kwargs):
set_permissive = kwargs.get('set_permissive', True)
multi = cfg.unrestraint.option(pathwrite).option.ismulti()
submulti_ = cfg.unrestraint.option(pathwrite).option.issubmulti()
ismaster = cfg.unrestraint.option(pathwrite).option.ismaster()
isslave = cfg.unrestraint.option(pathwrite).option.isslave()
isleader = cfg.unrestraint.option(pathwrite).option.isleader()
isfollower = cfg.unrestraint.option(pathwrite).option.isfollower()
if not multi:
first_value = FIRST_VALUE
elif submulti_ is False:
if not isslave:
if not isfollower:
first_value = LIST_FIRST_VALUE
else:
second_value = LIST_SECOND_VALUE[1]
else:
if not isslave:
if not isfollower:
first_value = SUBLIST_FIRST_VALUE
else:
second_value = SUBLIST_SECOND_VALUE[1]
# for slave should have an index and good length
# for master must append, not set
# for follower should have an index and good length
# for leader must append, not set
with warnings.catch_warnings(record=True) as w:
if ismaster:
if isleader:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
raises(APIError, "cfg.config(conf).option(pathwrite, 0).value.set(first_value[0])")
if not set_permissive:
@ -148,7 +148,7 @@ def _set_value(cfg, pathwrite, conf, **kwargs):
raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathwrite).value.set([first_value[0]])")
if len(first_value) > 1:
raises(APIError, "cfg.config(conf).unrestraint.option(pathwrite).value.set(first_value[1])")
elif isslave:
elif isfollower:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not set_permissive:
cfg.config(conf).option(pathwrite, 1).value.set(second_value)
@ -179,10 +179,10 @@ def _set_value(cfg, pathwrite, conf, **kwargs):
#FIXME raises(APIError, "cfg.config(conf).unrestraint.option(pathwrite).value.set(first_value)")
def _getproperties(multi, isslave, kwargs):
def _getproperties(multi, isfollower, kwargs):
# define properties
properties = copy(PROPERTIES_LIST)
if multi and not isslave:
if multi and not isfollower:
default_props = ['empty']
properties.append('empty')
else:
@ -195,7 +195,7 @@ def _getproperties(multi, isslave, kwargs):
def _check_properties(cfg, mcfg, pathread, conf, kwargs, props_permissive, props):
if not cfg.unrestraint.option(pathread).option.isslave():
if not cfg.unrestraint.option(pathread).option.isfollower():
if not kwargs.get('permissive_od', False):
assert set(cfg.config(conf).option(pathread).property.get()) == set(props_permissive)
assert set(cfg.config(conf).option(pathread).property.get()) == set(props)
@ -229,13 +229,13 @@ def _check_properties(cfg, mcfg, pathread, conf, kwargs, props_permissive, props
def _property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
# check if is a multi or a slave
# check if is a multi or a follower
multi = cfg.unrestraint.option(pathread).option.ismulti()
isslave = cfg.unrestraint.option(pathread).option.isslave()
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
# define properties
properties = copy(PROPERTIES_LIST)
if multi and not isslave:
if multi and not isfollower:
default_props = ['empty']
properties.append('empty')
else:
@ -244,7 +244,7 @@ def _property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **
if extra_properties:
properties.extend(extra_properties)
default_props.extend(extra_properties)
default_props, properties = _getproperties(multi, isslave, kwargs)
default_props, properties = _getproperties(multi, isfollower, kwargs)
if confwrite == confread:
_check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props)
@ -269,25 +269,25 @@ def _autocheck_get_value(cfg, pathread, conf, **kwargs):
set_permissive = kwargs.get('set_permissive', True)
multi = cfg.unrestraint.option(pathread).option.ismulti()
submulti_ = cfg.unrestraint.option(pathread).option.issubmulti()
isslave = cfg.unrestraint.option(pathread).option.isslave()
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
empty_value = kwargs['default']
if not multi:
first_value = FIRST_VALUE
elif submulti_ is False:
if not isslave:
if not isfollower:
first_value = LIST_FIRST_VALUE
else:
second_value = LIST_SECOND_VALUE[1]
else:
if not isslave:
if not isfollower:
first_value = SUBLIST_FIRST_VALUE
else:
second_value = SUBLIST_SECOND_VALUE[1]
# get value after set value without permissive
with warnings.catch_warnings(record=True) as w:
if isslave:
if isfollower:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert cfg.config(conf).option(pathread, 0).value.get() == empty_value
assert cfg.config(conf).option(pathread, 1).value.get() == second_value
@ -319,8 +319,8 @@ def _autocheck_get_value(cfg, pathread, conf, **kwargs):
def _check_owner(cfg, pathread, conf, kwargs, owner, permissive_owner):
isslave = cfg.unrestraint.option(pathread).option.isslave()
if not isslave:
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
if not isfollower:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert cfg.config(conf).option(pathread).owner.get() == owner
assert cfg.config(conf).forcepermissive.option(pathread).owner.get() == owner
@ -351,18 +351,18 @@ def autocheck_option_multi(cfg, mcfg, pathread, pathwrite, confread, confwrite,
if not kwargs.get('permissive_od', False):
cfg.option(pathread).option.ismulti()
cfg.option(pathread).option.issubmulti()
cfg.option(pathread).option.ismaster()
cfg.option(pathread).option.isslave()
cfg.option(pathread).option.isleader()
cfg.option(pathread).option.isfollower()
else:
raises(PropertiesOptionError, "cfg.option(pathread).option.ismulti()")
raises(PropertiesOptionError, "cfg.option(pathread).option.issubmulti()")
raises(PropertiesOptionError, "cfg.option(pathread).option.ismaster()")
raises(PropertiesOptionError, "cfg.option(pathread).option.isslave()")
raises(PropertiesOptionError, "cfg.option(pathread).option.isleader()")
raises(PropertiesOptionError, "cfg.option(pathread).option.isfollower()")
cfg.forcepermissive.option(pathread).option.ismulti()
cfg.forcepermissive.option(pathread).option.issubmulti()
cfg.forcepermissive.option(pathread).option.ismaster()
cfg.forcepermissive.option(pathread).option.isslave()
cfg.forcepermissive.option(pathread).option.isleader()
cfg.forcepermissive.option(pathread).option.isfollower()
@ -370,10 +370,10 @@ def autocheck_option_multi(cfg, mcfg, pathread, pathwrite, confread, confwrite,
def autocheck_default_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
"""check different value of owner when any value is set to this option
"""
isslave = cfg.unrestraint.option(pathread).option.isslave()
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
# check if owner is a string "default" and 'isdefault'
def do(conf):
if not isslave:
if not isfollower:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert cfg.config(conf).option(pathread).owner.get() == 'default'
assert cfg.config(conf).forcepermissive.option(pathread).owner.get() == 'default'
@ -438,7 +438,7 @@ def autocheck_set_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **k
def autocheck_get_value_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
multi = cfg.unrestraint.option(pathread).option.ismulti()
submulti_ = cfg.unrestraint.option(pathread).option.issubmulti()
isslave = cfg.unrestraint.option(pathread).option.isslave()
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
_set_value(cfg, pathwrite, confwrite, **kwargs)
empty_value = kwargs['default']
if not multi:
@ -450,7 +450,7 @@ def autocheck_get_value_permissive(cfg, mcfg, pathread, pathwrite, confread, con
def do(conf):
# get value after set value without permissive
if isslave:
if isfollower:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert cfg.config(conf).option(pathread, 0).value.get() == empty_value
assert cfg.config(conf).forcepermissive.option(pathread, 0).value.get() == empty_value
@ -504,9 +504,9 @@ def autocheck_get_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **k
@autocheck
def autocheck_value_slave(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
isslave = cfg.unrestraint.option(pathread).option.isslave()
if not isslave:
def autocheck_value_follower(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
if not isfollower:
return
if kwargs.get('propertyerror', False):
return
@ -529,28 +529,28 @@ def autocheck_value_slave(cfg, mcfg, pathread, pathwrite, confread, confwrite, *
value.append(cfg.forcepermissive.option(pathread, idx).value.get())
assert value == [empty_value, empty_value]
# cannot access to a slave with index too high
# cannot access to a follower with index too high
if submulti_ is False:
value = LIST_FIRST_VALUE[0]
else:
value = SUBLIST_FIRST_VALUE[0]
raises(SlaveError, "cfg.forcepermissive.option(pathread, length).value.get()")
raises(SlaveError, "cfg.forcepermissive.option(pathread, length).value.set(value)")
raises(SlaveError, "cfg.forcepermissive.option(pathread, length).value.reset()")
raises(SlaveError, "cfg.forcepermissive.option(pathread, length).owner.get()")
raises(SlaveError, "cfg.forcepermissive.option(pathread, length).owner.isdefault()")
raises(SlaveError, "cfg.forcepermissive.option(pathread, length).property.get()")
raises(SlaveError, "cfg.forcepermissive.option(pathread, length).owner.set('new_user')")
raises(SlaveError, "cfg.forcepermissive.option(pathread, length).property.add('prop')")
raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).value.get()")
raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).value.set(value)")
raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).value.reset()")
raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).owner.get()")
raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).owner.isdefault()")
raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).property.get()")
raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).owner.set('new_user')")
raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).property.add('prop')")
@autocheck
def autocheck_reset_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
# check if is a multi, a master or a slave
# check if is a multi, a leader or a follower
multi = cfg.unrestraint.option(pathread).option.ismulti()
submulti_ = cfg.unrestraint.option(pathread).option.issubmulti()
isslave = cfg.unrestraint.option(pathread).option.isslave()
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
# set default value (different if value is multi or not)
if not multi:
@ -567,7 +567,7 @@ def autocheck_reset_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, *
# reset value without permissive
with warnings.catch_warnings(record=True) as w:
if not isslave:
if not isfollower:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
cfg.config(confwrite).option(pathwrite).value.reset()
#else:
@ -580,7 +580,7 @@ def autocheck_reset_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, *
# get value after reset value without permissive
def do(conf):
if isslave:
if isfollower:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert cfg.config(conf).option(pathread, 0).value.get() == empty_value
assert cfg.config(conf).option(pathread, 1).value.get() == second_value[1]
@ -602,111 +602,111 @@ def autocheck_reset_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, *
@autocheck
def autocheck_append_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
ismaster = cfg.unrestraint.option(pathread).option.ismaster()
isleader = cfg.unrestraint.option(pathread).option.isleader()
submulti_ = cfg.unrestraint.option(pathread).option.issubmulti()
if not ismaster:
if not isleader:
return
with warnings.catch_warnings(record=True) as w:
if not kwargs.get('propertyerror', False):
master_value = cfg.config(confread).forcepermissive.option(pathread).value.get()
len_value = len(master_value)
master_value.append(undefined)
leader_value = cfg.config(confread).forcepermissive.option(pathread).value.get()
len_value = len(leader_value)
leader_value.append(undefined)
assert len(cfg.config(confread).forcepermissive.option(pathread).value.get()) == len_value
with warnings.catch_warnings(record=True) as w:
cfg.forcepermissive.config(confwrite).option(pathread).value.set(master_value)
new_master_value = cfg.config(confread).forcepermissive.option(pathread).value.get()
len_new = len(new_master_value)
cfg.forcepermissive.config(confwrite).option(pathread).value.set(leader_value)
new_leader_value = cfg.config(confread).forcepermissive.option(pathread).value.get()
len_new = len(new_leader_value)
assert len_value + 1 == len_new
assert new_master_value[-1] == kwargs['default_multi']
slave_path = pathread.rsplit('.', 1)[0]
if slave_path.endswith('val1') or slave_path.endswith('val2'):
slave_path += '.third' + slave_path[-4:]
assert new_leader_value[-1] == kwargs['default_multi']
follower_path = pathread.rsplit('.', 1)[0]
if follower_path.endswith('val1') or follower_path.endswith('val2'):
follower_path += '.third' + follower_path[-4:]
else:
slave_path += '.third'
follower_path += '.third'
for idx in range(len_new):
assert cfg.config(confread).forcepermissive.option(slave_path, idx).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(follower_path, idx).value.get() == kwargs['default_multi']
#
if not submulti_:
value = 'value'
else:
value = ['value']
master_value.append(value)
assert len(cfg.config(confread).forcepermissive.option(pathread).value.get()) == len(new_master_value)
cfg.forcepermissive.config(confwrite).option(pathread).value.set(master_value)
leader_value.append(value)
assert len(cfg.config(confread).forcepermissive.option(pathread).value.get()) == len(new_leader_value)
cfg.forcepermissive.config(confwrite).option(pathread).value.set(leader_value)
assert cfg.config(confread).forcepermissive.option(pathread).value.get()[-1] == value
@autocheck
def autocheck_pop_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
ismaster = cfg.unrestraint.option(pathread).option.ismaster()
isleader = cfg.unrestraint.option(pathread).option.isleader()
submulti_ = cfg.unrestraint.option(pathread).option.issubmulti()
if not ismaster:
if not isleader:
return
if not kwargs.get('propertyerror', False):
if not submulti_:
values = ['value1', 'value2', 'value3', 'value4']
slave_value = 'slave'
follower_value = 'follower'
else:
values = [['value1'], ['value2'], ['value3'], ['value4']]
slave_value = ['slave']
slaves = [kwargs['default_multi'], slave_value, kwargs['default_multi'], kwargs['default_multi']]
a_slave = pathwrite.rsplit('.', 1)[0]
if a_slave.endswith('val1') or a_slave.endswith('val2'):
a_slave += '.third' + a_slave[-4:]
follower_value = ['follower']
followers = [kwargs['default_multi'], follower_value, kwargs['default_multi'], kwargs['default_multi']]
a_follower = pathwrite.rsplit('.', 1)[0]
if a_follower.endswith('val1') or a_follower.endswith('val2'):
a_follower += '.third' + a_follower[-4:]
else:
a_slave += '.third'
a_follower += '.third'
with warnings.catch_warnings(record=True) as w:
cfg.forcepermissive.config(confwrite).option(pathread).value.set(values)
cfg.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave_value)
cfg.config(confread).forcepermissive.option(a_slave, 0).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_slave, 0).owner.isdefault() is True
cfg.config(confread).forcepermissive.option(a_slave, 1).value.get() == slave_value
assert cfg.config(confread).forcepermissive.option(a_slave, 1).owner.isdefault() is False
cfg.config(confread).forcepermissive.option(a_slave, 2).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_slave, 2).owner.isdefault() is True
cfg.config(confread).forcepermissive.option(a_slave, 3).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_slave, 3).owner.isdefault() is True
cfg.forcepermissive.config(confwrite).option(a_follower, 1).value.set(follower_value)
cfg.config(confread).forcepermissive.option(a_follower, 0).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_follower, 0).owner.isdefault() is True
cfg.config(confread).forcepermissive.option(a_follower, 1).value.get() == follower_value
assert cfg.config(confread).forcepermissive.option(a_follower, 1).owner.isdefault() is False
cfg.config(confread).forcepermissive.option(a_follower, 2).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_follower, 2).owner.isdefault() is True
cfg.config(confread).forcepermissive.option(a_follower, 3).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_follower, 3).owner.isdefault() is True
#
cfg.forcepermissive.config(confwrite).option(pathread).value.pop(3)
cfg.config(confread).forcepermissive.option(a_slave, 0).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_slave, 0).owner.isdefault() is True
cfg.config(confread).forcepermissive.option(a_slave, 1).value.get() == slave_value
assert cfg.config(confread).forcepermissive.option(a_slave, 1).owner.isdefault() is False
cfg.config(confread).forcepermissive.option(a_slave, 2).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_slave, 2).owner.isdefault() is True
cfg.config(confread).forcepermissive.option(a_follower, 0).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_follower, 0).owner.isdefault() is True
cfg.config(confread).forcepermissive.option(a_follower, 1).value.get() == follower_value
assert cfg.config(confread).forcepermissive.option(a_follower, 1).owner.isdefault() is False
cfg.config(confread).forcepermissive.option(a_follower, 2).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_follower, 2).owner.isdefault() is True
#
cfg.forcepermissive.config(confwrite).option(pathread).value.pop(0)
cfg.config(confread).forcepermissive.option(a_slave, 0).value.get() == slave_value
assert cfg.config(confread).forcepermissive.option(a_slave, 0).owner.isdefault() is False
cfg.config(confread).forcepermissive.option(a_slave, 1).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_slave, 1).owner.isdefault() is True
cfg.config(confread).forcepermissive.option(a_follower, 0).value.get() == follower_value
assert cfg.config(confread).forcepermissive.option(a_follower, 0).owner.isdefault() is False
cfg.config(confread).forcepermissive.option(a_follower, 1).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_follower, 1).owner.isdefault() is True
#
cfg.forcepermissive.config(confwrite).option(pathread).value.pop(0)
cfg.config(confread).forcepermissive.option(a_slave, 0).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_slave, 0).owner.isdefault() is True
cfg.config(confread).forcepermissive.option(a_follower, 0).value.get() == kwargs['default_multi']
assert cfg.config(confread).forcepermissive.option(a_follower, 0).owner.isdefault() is True
@autocheck
def autocheck_reset_value_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
# check if is a multi, a master or a slave
isslave = cfg.unrestraint.option(pathread).option.isslave()
# check if is a multi, a leader or a follower
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
_set_value(cfg, pathwrite, confwrite, **kwargs)
# reset value with permissive
with warnings.catch_warnings(record=True) as w:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
if not isfollower:
cfg.forcepermissive.config(confwrite).option(pathwrite).value.reset()
else:
cfg.forcepermissive.option(pathwrite, 1).value.reset()
elif kwargs.get('permissive', False):
if not isslave:
if not isfollower:
cfg.forcepermissive.config(confwrite).option(pathwrite).value.reset()
else:
cfg.forcepermissive.option(pathwrite, 1).value.reset()
#FIXME else:
# if not isslave:
# if not isfollower:
# raises(PropertiesOptionError, "cfg.forcepermissive.config(confwrite).option(pathwrite).value.reset()")
# else:
# raises(PropertiesOptionError, "cfg.forcepermissive.option(pathwrite, 1).value.reset()")
@ -736,11 +736,11 @@ def autocheck_display(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwa
def autocheck_property(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
"""get property from path
"""
# check if is a multi or a slave
# check if is a multi or a follower
multi = cfg.unrestraint.option(pathread).option.ismulti()
isslave = cfg.unrestraint.option(pathread).option.isslave()
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
default_props, properties = _getproperties(multi, isslave, kwargs)
default_props, properties = _getproperties(multi, isfollower, kwargs)
if confread == confwrite:
_check_properties(cfg, mcfg, pathread, confread, kwargs, default_props, default_props)
@ -766,10 +766,10 @@ def autocheck_property_permissive(cfg, mcfg, pathread, pathwrite, confread, conf
def autocheck_reset_property(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
"""check properties after set with permissive
"""
# check if is a multi or a slave
# check if is a multi or a follower
multi = cfg.unrestraint.option(pathread).option.ismulti()
isslave = cfg.unrestraint.option(pathread).option.isslave()
default_props, properties = _getproperties(multi, isslave, kwargs)
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
default_props, properties = _getproperties(multi, isfollower, kwargs)
_property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs)
@ -784,10 +784,10 @@ def autocheck_reset_property(cfg, mcfg, pathread, pathwrite, confread, confwrite
@autocheck
def autocheck_reset_property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
# check if is a multi or a slave
# check if is a multi or a follower
multi = cfg.unrestraint.option(pathread).option.ismulti()
isslave = cfg.unrestraint.option(pathread).option.isslave()
default_props, properties = _getproperties(multi, isslave, kwargs)
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
default_props, properties = _getproperties(multi, isfollower, kwargs)
_property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs)
@ -816,11 +816,11 @@ def autocheck_owner_with_value(cfg, mcfg, pathread, pathwrite, confread, confwri
@autocheck
def autocheck_default_owner_with_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
isslave = cfg.unrestraint.option(pathread).option.isslave()
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
_set_value(cfg, pathwrite, confwrite, **kwargs)
# test if is default owner without permissive
if not isslave:
if not isfollower:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert cfg.config(confwrite).option(pathread).owner.isdefault() is False
if confwrite != confread:
@ -842,15 +842,15 @@ def autocheck_default_owner_with_value(cfg, mcfg, pathread, pathwrite, confread,
@autocheck
def autocheck_default_owner_with_value_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
# check if is a isslave
isslave = cfg.unrestraint.option(pathread).option.isslave()
# check if is a isfollower
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
_set_value(cfg, pathwrite, confwrite, **kwargs)
def do(conf):
# test if is default owner with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
if not isfollower:
assert cfg.config(conf).forcepermissive.option(pathread).owner.isdefault() is False
else:
assert cfg.config(conf).forcepermissive.option(pathread, 0).owner.isdefault() is True
@ -864,9 +864,9 @@ def autocheck_default_owner_with_value_permissive(cfg, mcfg, pathread, pathwrite
@autocheck
def autocheck_set_owner_no_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
isslave = cfg.unrestraint.option(pathread).option.isslave()
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
if not kwargs.get('propertyerror', False):
if not isslave:
if not isfollower:
raises(ConfigError, "cfg.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user')")
else:
raises(ConfigError, "cfg.forcepermissive.option(pathwrite, 1).owner.set('new_user')")
@ -875,12 +875,12 @@ def autocheck_set_owner_no_value(cfg, mcfg, pathread, pathwrite, confread, confw
@autocheck
def autocheck_set_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
# test set owner without permissive
isslave = cfg.unrestraint.option(pathread).option.isslave()
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
_set_value(cfg, pathwrite, confwrite, **kwargs)
# set owner without permissive
if not isslave:
if not isfollower:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
cfg.config(confwrite).option(pathwrite).owner.set('new_user')
raises(ValueError, "cfg.config(confwrite).option(pathwrite).owner.set('default')")
@ -900,18 +900,18 @@ def autocheck_set_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite, **k
@autocheck
def autocheck_set_owner_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
isslave = cfg.unrestraint.option(pathread).option.isslave()
isfollower = cfg.unrestraint.option(pathread).option.isfollower()
_set_value(cfg, pathwrite, confwrite, **kwargs)
# set owner with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
if not isfollower:
cfg.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')
else:
cfg.forcepermissive.option(pathwrite, 1).owner.set('new_user1')
#FIXME else:
# if not isslave:
# if not isfollower:
# raises(PropertiesOptionError,
# "cfg.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')")
# else:
@ -1096,7 +1096,7 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
kwargs['default'] = default_value
is_dyn = False
is_master = False
is_leader = False
dyns = []
has_value = False
for cpath, options in paths_.items():
@ -1107,8 +1107,8 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
for dname in cpath.split('.')[:-1]:
if options.get(dname, {}).get('dyn'):
is_dyn = True
if options.get(dname, {}).get('master'):
is_master = True
if options.get(dname, {}).get('leader'):
is_leader = True
else:
dirname = ''
name = cpath
@ -1132,9 +1132,9 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
dico_value[cpath + 'link'] = default_value
has_value = True
isslave = False
if '.' in path and is_master and not path.rsplit('.', 1)[1].startswith('first'):
isslave = True
isfollower = False
if '.' in path and is_leader and not path.rsplit('.', 1)[1].startswith('first'):
isfollower = True
if not multi is submulti:
kwargs['default'] = None
if is_dyn and dyns:
@ -1181,7 +1181,7 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
if is_dyn:
dico[cpath + 'extraoptconsistencyval1'] = value
dico_value[cpath + 'extraoptconsistencyval1'] = value
if is_master:
if is_leader:
spath = cpath.split('.')
spath[-2] = spath[-2][:-1] + '2'
spath[-3] = spath[-3][:-1] + '2'
@ -1193,7 +1193,7 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
else:
dico[cpath + 'extraoptconsistency'] = value
dico_value[cpath + 'extraoptconsistency'] = value
if is_master:
if is_leader:
for cpath in list(paths_.keys())[len(dyns):]:
if cpath.endswith('.first') or cpath.endswith('.firstval1') or cpath.endswith('.firstval2'):
second_path = cpath.rsplit('.', 1)[0] + '.second'
@ -1216,31 +1216,31 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
dvalue = None
#
kwargs['default_multi'] = dvalue
if isslave:
if isfollower:
kwargs['default'] = dvalue
len_master = len(dico[cpath])
len_leader = len(dico[cpath])
if second_path in dico:
dico[second_path] = [dvalue] * len_master
dico[second_path] = [dvalue] * len_leader
if symlink:
dico[second_path + 'link'] = [dvalue] * len_master
dico[second_path + 'link'] = [dvalue] * len_leader
if third_path in dico:
dico[third_path] = [dvalue] * len_master
dico[third_path] = [dvalue] * len_leader
if symlink:
dico[third_path + 'link'] = [dvalue] * len_master
dico[third_path + 'link'] = [dvalue] * len_leader
if cons_path in dico:
dico[cons_path] = [dvalue] * len_master
dico[cons_path] = [dvalue] * len_leader
#
len_master = len(dico_value[cpath])
len_leader = len(dico_value[cpath])
if second_path in dico_value:
dico_value[second_path] = [dvalue] * len_master
dico_value[second_path] = [dvalue] * len_leader
if symlink:
dico_value[second_path + 'link'] = [dvalue] * len_master
dico_value[second_path + 'link'] = [dvalue] * len_leader
if third_path in dico_value:
dico_value[third_path] = [dvalue] * len_master
dico_value[third_path] = [dvalue] * len_leader
if symlink:
dico_value[third_path + 'link'] = [dvalue] * len_master
dico_value[third_path + 'link'] = [dvalue] * len_leader
if cons_path in dico_value:
dico_value[cons_path] = [dvalue] * len_master
dico_value[cons_path] = [dvalue] * len_leader
return is_dyn, dico, dico_value
if DISPLAY:
text = u' {} launch tests for {}'.format(ICON, path)
@ -1288,33 +1288,33 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
else:
ckwargs['owner'] = OWNER
if mcfg.unrestraint.option(path).option.isslave():
if mcfg.unrestraint.option(path).option.isfollower():
dirname = path.rsplit('.', 1)[0]
master_path = dirname + '.first'
master_path_2 = None
leader_path = dirname + '.first'
leader_path_2 = None
if dirname.endswith('val1') or dirname.endswith('val2'):
master_path += 'val1'
master_path = master_path.replace('val2', 'val1')
master_path_2 = master_path.replace('val1', 'val2')
leader_path += 'val1'
leader_path = leader_path.replace('val2', 'val1')
leader_path_2 = leader_path.replace('val1', 'val2')
if multi is submulti:
value = SUBLIST_SECOND_VALUE
else:
value = LIST_SECOND_VALUE
with warnings.catch_warnings(record=True) as w:
mcfg.option(master_path).value.set(value)
ckwargs['make_dict'][master_path] = value
ckwargs['make_dict_value'][master_path] = value
mcfg.option(leader_path).value.set(value)
ckwargs['make_dict'][leader_path] = value
ckwargs['make_dict_value'][leader_path] = value
if symlink:
ckwargs['make_dict'][master_path + 'link'] = value
ckwargs['make_dict_value'][master_path + 'link'] = value
if master_path_2:
ckwargs['make_dict'][leader_path + 'link'] = value
ckwargs['make_dict_value'][leader_path + 'link'] = value
if leader_path_2:
with warnings.catch_warnings(record=True) as w:
mcfg.option(master_path_2).value.set(value)
ckwargs['make_dict'][master_path_2] = value
ckwargs['make_dict_value'][master_path_2] = value
mcfg.option(leader_path_2).value.set(value)
ckwargs['make_dict'][leader_path_2] = value
ckwargs['make_dict_value'][leader_path_2] = value
if symlink:
ckwargs['make_dict'][master_path_2 + 'link'] = value
ckwargs['make_dict_value'][master_path_2 + 'link'] = value
ckwargs['make_dict'][leader_path_2 + 'link'] = value
ckwargs['make_dict_value'][leader_path_2 + 'link'] = value
if default_multi:
if multi is not submulti:
dvalue = SECOND_VALUE
@ -1337,9 +1337,9 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
ckwargs['make_dict'][npath + 'link'] = [dvalue] * len(value)
ckwargs['make_dict_value'][npath + 'link'] = [dvalue] * len(value)
if path == npath:
ckwargs['make_dict_value'][npath][-1] = ckwargs['make_dict_value'][master_path][-1]
ckwargs['make_dict_value'][npath][-1] = ckwargs['make_dict_value'][leader_path][-1]
if symlink:
ckwargs['make_dict_value'][npath + 'link'][-1] = ckwargs['make_dict_value'][master_path][-1]
ckwargs['make_dict_value'][npath + 'link'][-1] = ckwargs['make_dict_value'][leader_path][-1]
npath = ldirname + '.third' + suffix
if npath in ckwargs['make_dict']:
ckwargs['make_dict'][npath] = [dvalue] * len(value)
@ -1348,9 +1348,9 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
ckwargs['make_dict'][npath + 'link'] = [dvalue] * len(value)
ckwargs['make_dict_value'][npath + 'link'] = [dvalue] * len(value)
if path == npath:
ckwargs['make_dict_value'][npath][-1] = ckwargs['make_dict_value'][master_path][-1]
ckwargs['make_dict_value'][npath][-1] = ckwargs['make_dict_value'][leader_path][-1]
if symlink:
ckwargs['make_dict_value'][npath + 'link'][-1] = ckwargs['make_dict_value'][master_path][-1]
ckwargs['make_dict_value'][npath + 'link'][-1] = ckwargs['make_dict_value'][leader_path][-1]
npath = ldirname + '.extraoptconsistency' + suffix
if npath in ckwargs['make_dict']:
ckwargs['make_dict'][npath] = [dvalue] * len(value)
@ -1416,12 +1416,12 @@ def make_conf(options, multi, default, default_multi, require, consistency, call
weakrefs = []
dyn = []
goptions = []
def make_option(path, option_infos, in_master, master):
def make_option(path, option_infos, in_leader, leader):
option_type = 'str'
option_properties = []
option_requires = []
isslave = False
if in_master and symlink:
isfollower = False
if in_leader and symlink:
return None, None, None
if option_infos is not None:
if require:
@ -1433,7 +1433,7 @@ def make_conf(options, multi, default, default_multi, require, consistency, call
else:
option_requires.append({'option': goptions[0], 'expected': None,
'action': prop})
isslave = option_infos.get('slave', False)
isfollower = option_infos.get('follower', False)
args = [path, "{}'s option".format(path)]
kwargs = {}
call_kwargs = {}
@ -1450,7 +1450,7 @@ def make_conf(options, multi, default, default_multi, require, consistency, call
kwargs['multi'] = multi
if callback:
call_kwargs['multi'] = multi
if ((not in_master or master) and default) and path is not 'extraoptrequire' and not path.endswith('extraoptconsistency'):
if ((not in_leader or leader) and default) and path is not 'extraoptrequire' and not path.endswith('extraoptconsistency'):
if multi is False:
value = FIRST_VALUE
elif multi is True:
@ -1506,10 +1506,10 @@ def make_conf(options, multi, default, default_multi, require, consistency, call
for prop in PROPERTIES:
if infos.get(prop, False) is True:
properties.append(prop)
if infos.get('master', False) is True:
if infos.get('leader', False) is True:
if not multi:
return
optiondescription = MasterSlaves
optiondescription = Leadership
if infos.get('dyn', False) is True:
if symlink:
return
@ -1557,7 +1557,7 @@ def make_conf(options, multi, default, default_multi, require, consistency, call
local_collect_options = local_collect_options[optiondescription]
local_collect_options['properties'].update(option.get(optiondescription, {}))
option_name = path.split('.')[-1]
in_master = False
in_leader = False
if '.' in path:
name_od = path.rsplit('.', 1)[0]
if '.' in name_od:
@ -1565,9 +1565,9 @@ def make_conf(options, multi, default, default_multi, require, consistency, call
oddescr = collect_options.get(subod, {})
else:
oddescr = collect_options
in_master = oddescr.get(name_od, {}).get('properties', {}).get('master')
master = in_master and path.endswith('first')
obj, objcall, sobj = make_option(option_name, option.get(option_name), in_master, master)
in_leader = oddescr.get(name_od, {}).get('properties', {}).get('leader')
leader = in_leader and path.endswith('first')
obj, objcall, sobj = make_option(option_name, option.get(option_name), in_leader, leader)
if obj is None:
return None, None, None
weakrefs.append(weakref.ref(obj))
@ -1576,7 +1576,7 @@ def make_conf(options, multi, default, default_multi, require, consistency, call
if sobj is not None:
weakrefs.append(weakref.ref(sobj))
if '.' in path:
if master:
if leader:
local_collect_options.setdefault('options', []).insert(0, obj)
else:
local_collect_options.setdefault('options', []).append(obj)
@ -1609,10 +1609,10 @@ DICT_PATHS = [
OrderedDict([('subod.subsubod.first', {}),
('subod.subsubod.second', {'second': {'disabled': True}}),
('subod.subsubod.third', {'third': {'hidden': True}})]),
# test a config with masterslaves
OrderedDict([('odmaster.first', {'odmaster': {'master': True}}),
('odmaster.second', {'odmaster': {'master': True}, 'second': {'disabled': True, 'slave': True}}),
('odmaster.third', {'odmaster': {'master': True}, 'third': {'hidden': True, 'slave': True}})]),
# test a config with leadership
OrderedDict([('odleader.first', {'odleader': {'leader': True}}),
('odleader.second', {'odleader': {'leader': True}, 'second': {'disabled': True, 'follower': True}}),
('odleader.third', {'odleader': {'leader': True}, 'third': {'hidden': True, 'follower': True}})]),
# test a config with dynoption
OrderedDict([('subod.first', {'subod': {'dyn': True}}),
('subod.second', {'second': {'disabled': True}}),
@ -1647,10 +1647,10 @@ DICT_PATHS = [
('subod.subsubodval2.firstval2', None),
('subod.subsubodval2.secondval2', None),
('subod.subsubodval2.thirdval2', None)]),
# test a config with dyn subsubod with masterslave
OrderedDict([('subod.subsubod.first', {'subod': {'dyn': True}, 'subsubod': {'master': True}}),
('subod.subsubod.second', {'subod': {'dyn': True}, 'subsubod' : {'master': True}, 'second': {'disabled': True, 'slave': True}}),
('subod.subsubod.third', {'subod': {'dyn': True}, 'subsubod': {'master': True}, 'third': {'hidden': True, 'slave': True}}),
# test a config with dyn subsubod with leadership
OrderedDict([('subod.subsubod.first', {'subod': {'dyn': True}, 'subsubod': {'leader': True}}),
('subod.subsubod.second', {'subod': {'dyn': True}, 'subsubod' : {'leader': True}, 'second': {'disabled': True, 'follower': True}}),
('subod.subsubod.third', {'subod': {'dyn': True}, 'subsubod': {'leader': True}, 'third': {'hidden': True, 'follower': True}}),
('subodval1.subsubodval1.firstval1', None),
('subodval1.subsubodval1.secondval1', None),
('subodval1.subsubodval1.thirdval1', None),

View File

@ -8,7 +8,7 @@ do_autopath()
from tiramisu import setting, value
setting.expires_time = 1
value.expires_time = 1
from tiramisu.option import BoolOption, IPOption, IntOption, StrOption, OptionDescription, MasterSlaves
from tiramisu.option import BoolOption, IPOption, IntOption, StrOption, OptionDescription, Leadership
from tiramisu import Config
from tiramisu.error import ConfigError, PropertiesOptionError
from tiramisu.setting import groups
@ -256,11 +256,10 @@ def test_cache_not_cache():
assert 'u1' not in settings._p_.get_cached()
def test_cache_master_slave():
def test_cache_leadership():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
@ -419,11 +418,10 @@ def test_cache_callback():
'val5': {None: (['yes', 'new4'], None)}})
def test_cache_master_and_slaves_master():
def test_cache_leader_and_followers():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True)
interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
@ -495,11 +493,10 @@ def test_cache_master_and_slaves_master():
# 'val1.val2': {0: (None, None), 1: ('oui', None)}}
def test_cache_master_callback():
def test_cache_leader_callback():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()

View File

@ -35,8 +35,8 @@ def make_description():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé")
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau")
master = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = OptionDescription('interface1', '', [master])
leader = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = OptionDescription('interface1', '', [leader])
interface1.impl_set_group_type(groups.family)
general = OptionDescription('general', '', [numero_etab, nom_machine,

View File

@ -8,7 +8,7 @@ from tiramisu import BoolOption, StrOption, ChoiceOption, IPOption, \
NetworkOption, NetmaskOption, IntOption, FloatOption, \
UnicodeOption, PortOption, BroadcastOption, DomainnameOption, \
EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \
OptionDescription, DynOptionDescription, SynDynOption, submulti, MasterSlaves, \
OptionDescription, DynOptionDescription, SynDynOption, submulti, Leadership, \
Config, Params, ParamOption, ParamValue
from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError
from tiramisu.storage import list_sessions
@ -930,10 +930,10 @@ def test_consistency_ip_in_network_dyndescription():
cfg.option('dodval1.cval1').value.set('192.168.1.1')
def test_masterslaves_dyndescription():
def test_leadership_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
stm = MasterSlaves('st1', '', [st1, st2])
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
@ -988,10 +988,10 @@ def test_masterslaves_dyndescription():
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
def test_masterslaves_default_multi_dyndescription():
def test_leadership_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = MasterSlaves('st1', '', [st1, st2])
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
@ -1011,12 +1011,12 @@ def test_masterslaves_default_multi_dyndescription():
assert api.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
def test_masterslaves_dyndescription_param():
def test_leadership_dyndescription_param():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
odval = OptionDescription('odval1', '', [val1])
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
stm = MasterSlaves('st1', '', [st1, st2])
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list, callback_params=Params(ParamOption(val1)))
od = OptionDescription('od', '', [st, odval])
od2 = OptionDescription('od', '', [od])
@ -1071,10 +1071,10 @@ def test_masterslaves_dyndescription_param():
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
def test_masterslaves_default_multi_dyndescription():
def test_leadership_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = MasterSlaves('st1', '', [st1, st2])
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
@ -1095,7 +1095,7 @@ def test_masterslaves_default_multi_dyndescription():
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
def _test_masterslaves(cfg):
def _test_leadership(cfg):
owner = cfg.owner.get()
cfg.option('od.val1.val1').value.set(['val1', 'val2'])
cfg.option('od.val1.val2', 0).value.set('val1')
@ -1149,24 +1149,24 @@ def _test_masterslaves(cfg):
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
def test_masterslaves_dyndescription_param_master():
def test_leadership_dyndescription_param_leader():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True)
odval = MasterSlaves('val1', '', [val1, val2])
odval = Leadership('val1', '', [val1, val2])
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
stm = MasterSlaves('st1', '', [st1, st2])
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list, callback_params=Params(ParamOption(val1)))
od = OptionDescription('od', '', [st, odval])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
_test_masterslaves(cfg)
_test_leadership(cfg)
def test_masterslaves_default_multi_dyndescription():
def test_leadership_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = MasterSlaves('st1', '', [st1, st2])
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
@ -1187,24 +1187,24 @@ def test_masterslaves_default_multi_dyndescription():
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
def test_masterslaves_dyndescription_param_slave():
def test_leadership_dyndescription_param_follower():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True)
odval = MasterSlaves('val1', '', [val1, val2])
odval = Leadership('val1', '', [val1, val2])
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
stm = MasterSlaves('st1', '', [st1, st2])
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list, callback_params=Params(ParamOption(val2)))
od = OptionDescription('od', '', [st, odval])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
_test_masterslaves(cfg)
_test_leadership(cfg)
def test_masterslaves_default_multi_dyndescription():
def test_leadership_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = MasterSlaves('st1', '', [st1, st2])
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
@ -1225,10 +1225,10 @@ def test_masterslaves_default_multi_dyndescription():
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
def test_masterslaves_submulti_dyndescription():
def test_leadership_submulti_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=submulti)
stm = MasterSlaves('st1', '', [st1, st2])
stm = Leadership('st1', '', [st1, st2])
std = DynOptionDescription('st', '', [stm], callback=return_list)
od1 = OptionDescription('od', '', [std])
od2 = OptionDescription('od', '', [od1])
@ -1257,53 +1257,10 @@ def test_masterslaves_submulti_dyndescription():
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#FIXME DynOptionDescription cannot be MasterSlave
#def test_masterslaves_consistency_ip_dyndescription():
# neta = NetworkOption('net', '', multi=True)
# maskb = NetmaskOption('mask', '', multi=True)
# broadc = BroadcastOption('broad', '', multi=True)
# maskb.impl_add_consistency('network_netmask', neta)
# broadc.impl_add_consistency('broadcast', neta, maskb)
# dod = DynOptionDescription('net', '', [neta, maskb, broadc], callback=return_list)
# dod.impl_set_group_type(groups.master)
# od1 = OptionDescription('od', '', [dod])
# cfg = Config(od1)
# api.option('netval1.netval1').value.set(['192.168.1.0'])
# api.option('netval1.maskval1').value.set(['255.255.255.0'])
# api.option('netval1.broadval1').value.set(['192.168.1.255'])
#
# api.option('netval1.netval1').value.set(['192.168.1.0', '192.168.2.128'])
# api.option('netval1.maskval1').value.set(['255.255.255.0', '255.255.255.128'])
# api.option('netval1.broadval1').value.set(['192.168.1.255', '192.168.2.255'])
# #
# assert cfg.netval1.netval1 == ['192.168.1.0', '192.168.2.128']
# assert cfg.netval1.maskval1 == ['255.255.255.0', '255.255.255.128']
# assert cfg.netval1.broadval1 == ['192.168.1.255', '192.168.2.255']
# assert cfg.netval2.netval2 == []
# assert cfg.netval2.maskval2 == []
# assert cfg.netval2.broadval2 == []
#def test_masterslaves_consistency_ip_dyndescription_propertyerror():
# a = NetworkOption('net', '', multi=True)
# b = NetmaskOption('mask', '', multi=True, properties=('mandatory',))
# c = BroadcastOption('broad', '', multi=True)
# b.impl_add_consistency('network_netmask', a)
# c.impl_add_consistency('broadcast', a, b)
# dod = DynOptionDescription('net', '', [a, b, c], callback=return_list)
# dod.impl_set_group_type(groups.master)
# od = OptionDescription('od', '', [dod])
# cfg = Config(od)
# api.property.read_write()
# cfg.netval1.netval1 = ['192.168.1.0']
# api.property.read_only()
# raises(PropertiesOptionError, "cfg.netval1.netval1")
def test_masterslaves_callback_dyndescription():
def test_leadership_callback_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params=Params(kwargs={'value': ParamOption(st1)}))
stm = MasterSlaves('st1', '', [st1, st2])
stm = Leadership('st1', '', [st1, st2])
st1 = DynOptionDescription('st', '', [stm], callback=return_list)
od1 = OptionDescription('od', '', [st1])
od2 = OptionDescription('od', '', [od1])
@ -1361,10 +1318,10 @@ def test_masterslaves_callback_dyndescription():
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'yes'
def test_masterslaves_callback_value_dyndescription():
def test_leadership_callback_value_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params=Params(kwargs={'value': ParamValue('val')}))
stm = MasterSlaves('st1', '', [st1, st2])
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
@ -1376,11 +1333,11 @@ def test_masterslaves_callback_value_dyndescription():
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'val'
def test_masterslaves_callback_nomulti_dyndescription():
def test_leadership_callback_nomulti_dyndescription():
v11 = StrOption('v1', '', "val")
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params=Params(ParamOption(v11)))
stm = MasterSlaves('st1', '', [st1, st2])
stm = Leadership('st1', '', [st1, st2])
stt = DynOptionDescription('st', '', [stm], callback=return_list)
od1 = OptionDescription('od', '', [stt])
od2 = OptionDescription('od', '', [od1, v11])
@ -1391,11 +1348,11 @@ def test_masterslaves_callback_nomulti_dyndescription():
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'val'
def test_masterslaves_callback_samegroup_dyndescription():
def test_leadership_callback_samegroup_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
st3 = StrOption('st3', "", multi=True, callback=return_dynval, callback_params=Params(ParamOption(st2)))
stm = MasterSlaves('st1', '', [st1, st2, st3])
stm = Leadership('st1', '', [st1, st2, st3])
stt = DynOptionDescription('st', '', [stm], callback=return_list)
od1 = OptionDescription('od', '', [stt])
od2 = OptionDescription('od', '', [od1])

View File

@ -7,7 +7,7 @@ from py.test import raises
from tiramisu.setting import owners, groups
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config, \
StrOption, OptionDescription, SymLinkOption, Leadership, Config, \
Params, ParamContext, ParamOption, ParamValue
from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.storage import list_sessions
@ -178,25 +178,25 @@ def test_force_store_value_no_requirement():
pass
def test_force_store_value_masterslaves_slave():
def test_force_store_value_leadership_follower():
b = IntOption('int', 'Test int option', multi=True)
c = StrOption('str', 'Test string option', multi=True, properties=('force_store_value',))
descr = MasterSlaves("int", "", [b, c])
descr = Leadership("int", "", [b, c])
raises(ConfigError, "conf = Config(descr)")
#def test_force_store_value_masterslaves():
#def test_force_store_value_leadership():
# b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
# c = StrOption('str', 'Test string option', multi=True)
# descr = MasterSlaves("int", "", [b, c])
# descr = Leadership("int", "", [b, c])
# api = Config(descr)
# assert api.value.get() == {'int': ('forced', ())}
def test_force_store_value_masterslaves_sub():
def test_force_store_value_leadership_sub():
b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
c = StrOption('str', 'Test string option', multi=True)
descr = MasterSlaves("int", "", [b, c])
descr = Leadership("int", "", [b, c])
odr = OptionDescription('odr', '', [descr])
api = Config(odr)
compare(api.value.exportation(), (('int.int',), (None,), (tuple(),), ('forced',)))

View File

@ -5,8 +5,8 @@ from py.test import raises
from tiramisu.setting import groups, owners
from tiramisu import ChoiceOption, BoolOption, IntOption, IPOption, NetmaskOption, \
StrOption, OptionDescription, MasterSlaves, Config
from tiramisu.error import SlaveError, PropertiesOptionError, APIError, ConfigError
StrOption, OptionDescription, Leadership, Config
from tiramisu.error import LeadershipError, PropertiesOptionError, APIError, ConfigError
from tiramisu.api import TIRAMISU_VERSION
from tiramisu.storage import list_sessions
@ -46,8 +46,8 @@ def make_description():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé")
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau")
master = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = OptionDescription('interface1', '', [master])
leader = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = OptionDescription('interface1', '', [leader])
interface1.impl_set_group_type(groups.family)
general = OptionDescription('general', '', [numero_etab, nom_machine,
@ -206,59 +206,58 @@ def test_iter_not_group():
raise Exception('must raise')
def test_groups_with_master():
def test_groups_with_leader():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
assert interface1.impl_get_group_type() == groups.master
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
assert interface1.impl_get_group_type() == groups.leadership
def test_groups_is_master():
def test_groups_is_leader():
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 = MasterSlaves('masterslaves', '', [ip_admin_eth0, netmask_admin_eth0])
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.ismasterslaves()
assert api.option('masterslaves').option.ismasterslaves()
assert not api.option('od2.var').option.ismaster()
assert not api.option('od2.var').option.isslave()
assert api.option('masterslaves.ip_admin_eth0').option.ismulti()
assert api.option('masterslaves.netmask_admin_eth0').option.ismulti()
assert not api.option('masterslaves.ip_admin_eth0').option.issubmulti()
assert not api.option('masterslaves.netmask_admin_eth0').option.issubmulti()
assert api.option('masterslaves.ip_admin_eth0').option.ismaster()
assert not api.option('masterslaves.ip_admin_eth0').option.isslave()
assert not api.option('masterslaves.netmask_admin_eth0').option.ismaster()
assert api.option('masterslaves.netmask_admin_eth0').option.isslave()
assert api.option('masterslaves.netmask_admin_eth0').option.path() == 'masterslaves.netmask_admin_eth0'
assert api.option('masterslaves.netmask_admin_eth0').option.defaultmulti() == 'value'
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'
if TIRAMISU_VERSION != 2:
def test_groups_with_master_in_root():
def test_groups_with_leader_in_root():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
raises(ConfigError, "Config(interface1)")
def test_groups_with_master_in_config():
def test_groups_with_leader_in_config():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
Config(od)
assert interface1.impl_get_group_type() == groups.master
assert interface1.impl_get_group_type() == groups.leadership
def test_groups_with_master_make_dict():
def test_groups_with_leader_make_dict():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
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': []}
@ -270,10 +269,10 @@ def test_groups_with_master_make_dict():
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]}
def test_groups_with_master_hidden_in_config():
def test_groups_with_leader_hidden_in_config():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
api = Config(od)
api.property.read_write()
@ -285,10 +284,10 @@ def test_groups_with_master_hidden_in_config():
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
def test_groups_with_master_hidden_in_config2():
def test_groups_with_leader_hidden_in_config2():
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, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
api = Config(od)
api.property.read_write()
@ -312,40 +311,39 @@ def test_groups_with_master_hidden_in_config2():
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
def test_groups_with_master_reset_empty():
def test_groups_with_leader_reset_empty():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
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(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).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()
def test_groups_with_master_reset_out_of_range():
def test_groups_with_leader_reset_out_of_range():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
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(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).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)")
def test_groups_with_master_hidden_in_config3():
#if master is hidden, slave are hidden too
def test_groups_with_leader_hidden_in_config3():
#if leader is hidden, follower are hidden too
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
#interface1.impl_set_group_type(groups.master)
api = Config(od)
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
@ -364,11 +362,10 @@ def test_allowed_groups():
raises(ValueError, "interface1.impl_set_group_type('toto')")
def test_values_with_master_disabled_master():
def test_values_with_leader_disabled_leader():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -381,30 +378,29 @@ def test_values_with_master_disabled_master():
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('192.168.230.145')")
def test_sub_group_in_master_group():
def test_sub_group_in_leader_group():
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)
subgroup = OptionDescription("subgroup", '', [])
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [subgroup, ip_admin_eth0, netmask_admin_eth0])")
raises(ValueError, "Leadership('ip_admin_eth0', '', [subgroup, ip_admin_eth0, netmask_admin_eth0])")
def test_group_always_has_multis():
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")
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
#____________________________________________________________
def test_values_with_master_and_slaves():
def test_values_with_leader_and_followers():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
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 interface1.impl_get_group_type() == groups.master
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"])
@ -417,16 +413,15 @@ def test_values_with_master_and_slaves():
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0').value.pop(0)")
def test_reset_values_with_master_and_slaves():
def test_reset_values_with_leader_and_followers():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
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 interface1.impl_get_group_type() == groups.master
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
@ -441,17 +436,16 @@ def test_reset_values_with_master_and_slaves():
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
def test_reset_values_with_master_and_slaves_default_value():
def test_reset_values_with_leader_and_followers_default_value():
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, default=['255.255.255.0'])
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_reset_values_with_master_and_slaves_default():
def test_reset_values_with_leader_and_followers_default():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -488,15 +482,14 @@ def test_reset_values_with_master_and_slaves_default():
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
def test_values_with_master_and_slaves_slave():
def test_values_with_leader_and_followers_follower():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
raises(SlaveError,
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')
@ -517,11 +510,10 @@ def test_values_with_master_and_slaves_slave():
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
def test_values_with_master_and_slaves_pop():
def test_values_with_leader_and_followers_pop():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -537,11 +529,10 @@ def test_values_with_master_and_slaves_pop():
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
def test_values_with_master_and_slaves_master():
def test_values_with_leader_and_followers_leader():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -550,7 +541,7 @@ def test_values_with_master_and_slaves_master():
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(SlaveError, "api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])")
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)
@ -560,10 +551,10 @@ def test_values_with_master_and_slaves_master():
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
def test_values_with_master_and_slaves_master_pop():
def test_values_with_leader_and_followers_leader_pop():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -591,11 +582,10 @@ def test_values_with_master_and_slaves_master_pop():
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',))))
def test_values_with_master_owner():
def test_values_with_leader_owner():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -608,11 +598,10 @@ def test_values_with_master_owner():
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
def test_values_with_master_disabled():
def test_values_with_leader_disabled():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -649,11 +638,10 @@ def test_multi_non_valid_value():
raises(ValueError, "api.option('ip_admin_eth0').value.set([1])")
def test_multi_master_default_slave():
def test_multi_leader_default_follower():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -661,11 +649,10 @@ def test_multi_master_default_slave():
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
def test_groups_with_master_get_modified_value():
def test_groups_with_leader_get_modified_value():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -679,11 +666,10 @@ def test_groups_with_master_get_modified_value():
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'))))
def test_groups_with_master_importation():
def test_groups_with_leader_importation():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -699,7 +685,7 @@ def test_groups_with_master_importation():
def test_wrong_index():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('od', '', [interface1])
maconfig = OptionDescription('toto', '', [od1])
api = Config(maconfig)
@ -713,57 +699,57 @@ def test_wrong_index():
raises(APIError, "api.option('od', 0).option.get()")
def test_without_master_or_slave():
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [])")
def test_without_leader_or_follower():
raises(ValueError, "Leadership('ip_admin_eth0', '', [])")
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0])")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0])")
#empty optiondescription is allowed
OptionDescription('ip_admin_eth0', '', [])
def test_master_not_multi():
def test_leader_not_multi():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé")
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_slave_not_multi():
def test_follower_not_multi():
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")
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_slave_not_same():
def test_follower_not_same():
ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface0 = MasterSlaves('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
ip_admin_eth1 = IPOption('ip_admin_eth1', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth1 = NetmaskOption('netmask_admin_eth1', "masque du sous-réseau", multi=True)
netmask_admin_eth1.impl_add_consistency('ip_netmask', ip_admin_eth0)
interface1 = MasterSlaves('interface1', '', [ip_admin_eth1, netmask_admin_eth1])
interface1 = Leadership('interface1', '', [ip_admin_eth1, netmask_admin_eth1])
od1 = OptionDescription('od', '', [interface0, interface1])
maconfig = OptionDescription('toto', '', [od1])
raises(ConfigError, "Config(maconfig)")
def test_slave_not_same_not_equal():
def test_follower_not_same_not_equal():
ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface0 = MasterSlaves('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
ip_admin_eth1 = IPOption('ip_admin_eth1', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth1 = NetmaskOption('netmask_admin_eth1', "masque du sous-réseau", multi=True)
netmask_admin_eth1.impl_add_consistency('not_equal', netmask_admin_eth0)
interface1 = MasterSlaves('interface1', '', [ip_admin_eth1, netmask_admin_eth1])
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()
def test_slave_force_store_value():
def test_follower_force_store_value():
ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('force_store_value',))
interface0 = MasterSlaves('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('od', '', [interface0])
maconfig = OptionDescription('toto', '', [od1])
raises(ConfigError, "Config(maconfig)")

View File

@ -6,7 +6,7 @@ from py.test import raises
from tiramisu.api import TIRAMISU_VERSION
from tiramisu import Config
from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \
SymLinkOption, MasterSlaves, undefined, Params, ParamOption
SymLinkOption, Leadership, undefined, Params, ParamOption
from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.setting import groups
from tiramisu.storage import list_sessions
@ -407,37 +407,34 @@ def test_mandatory_warnings_frozen():
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
def test_mandatory_master():
def test_mandatory_leader():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
properties=('mandatory', ))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
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()")
def test_mandatory_warnings_master():
def test_mandatory_warnings_leader():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
properties=('mandatory', ))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
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']
def test_mandatory_master_empty():
def test_mandatory_leader_empty():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
api = Config(descr)
api.property.read_write()
@ -475,12 +472,11 @@ def test_mandatory_master_empty():
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
def test_mandatory_warnings_master_empty():
def test_mandatory_warnings_leader_empty():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
api = Config(descr)
api.property.read_write()
@ -500,12 +496,11 @@ def test_mandatory_warnings_master_empty():
assert list(api.value.mandatory()) == []
def test_mandatory_slave():
def test_mandatory_follower():
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, properties=('mandatory', ))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
api = Config(descr)
api.property.read_only()
@ -530,12 +525,11 @@ def test_mandatory_slave():
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
def test_mandatory_warnings_slave():
def test_mandatory_warnings_follower():
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, properties=('mandatory', ))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
api = Config(descr)
api.property.read_only()
@ -597,32 +591,32 @@ def test_mandatory_warnings_requires():
assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3']
def test_mandatory_warnings_requires_masterslaves():
def test_mandatory_warnings_requires_leadership():
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option', multi=True)
stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
masterslave = MasterSlaves('master', 'masterslaves', [stroption1, stroption2])
descr = OptionDescription('tiram', '', [stroption, masterslave])
leadership = Leadership('leader', 'leadership', [stroption1, stroption2])
descr = OptionDescription('tiram', '', [stroption, leadership])
api = Config(descr)
api.option('str').value.set('')
api.option('master.str1').value.set(['str'])
api.option('leader.str1').value.set(['str'])
assert list(api.value.mandatory()) == ['str']
api.option('str').value.set('yes')
assert list(api.value.mandatory()) == ['master.str2']
assert list(api.value.mandatory()) == ['leader.str2']
def test_mandatory_warnings_requires_masterslaves_slave():
def test_mandatory_warnings_requires_leadership_follower():
stroption = StrOption('str', 'Test string option', multi=True)
stroption1 = StrOption('str1', 'Test string option', multi=True)
stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption1, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
masterslave = MasterSlaves('master', 'masterslaves', [stroption, stroption1, stroption2])
descr = OptionDescription('tiram', '', [masterslave])
leadership = Leadership('leader', 'leadership', [stroption, stroption1, stroption2])
descr = OptionDescription('tiram', '', [leadership])
api = Config(descr)
api.option('master.str').value.set(['str'])
api.option('leader.str').value.set(['str'])
assert list(api.value.mandatory()) == []
api.option('master.str1', 0).value.set('yes')
assert list(api.value.mandatory()) == ['master.str2']
api.option('leader.str1', 0).value.set('yes')
assert list(api.value.mandatory()) == ['leader.str2']
def test_mandatory_od_disabled():

View File

@ -4,9 +4,9 @@ do_autopath()
from tiramisu.setting import groups, owners
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, BoolOption, ChoiceOption, \
IPOption, OptionDescription, MasterSlaves, Config, GroupConfig, MetaConfig, \
IPOption, OptionDescription, Leadership, Config, GroupConfig, MetaConfig, \
Params, ParamOption, ParamValue
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, SlaveError, APIError
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, LeadershipError, APIError
from tiramisu.storage import list_sessions
@ -384,10 +384,10 @@ def test_meta_unconsistent():
raises(ValueError, "MetaConfig([conf3, conf4])")
def test_meta_master_slaves():
def test_meta_leadership():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -410,10 +410,10 @@ def test_meta_master_slaves():
assert conf2._config_bag.context == next(itr)._config_bag.context
def test_meta_master_slaves_value2():
def test_meta_leadership_value2():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -435,10 +435,10 @@ def test_meta_master_slaves_value2():
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
def test_meta_master_slaves_value_default():
def test_meta_leadership_value_default():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -458,17 +458,17 @@ def test_meta_master_slaves_value_default():
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
def test_meta_master_slaves_owners():
def test_meta_leadership_owners():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
meta = MetaConfig([conf1, conf2])
meta.owner.set(owners.meta1)
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
raises(SlaveError, "meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()")
raises(LeadershipError, "meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()")
#
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
@ -497,7 +497,7 @@ def test_meta_master_slaves_owners():
def test_meta_force_default():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -535,7 +535,7 @@ def test_meta_force_default():
def test_meta_force_dont_change_value():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -562,7 +562,7 @@ def test_meta_force_dont_change_value():
def test_meta_force_default_if_same():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -604,7 +604,7 @@ def test_meta_force_default_if_same():
def test_meta_force_default_if_same_and_dont_change():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -646,7 +646,7 @@ def test_meta_force_default_if_same_and_dont_change():
def test_meta_force_default_and_dont_change():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='rconf1')
conf2 = Config(od, session_id='rconf2')
@ -660,7 +660,7 @@ def test_meta_properties_meta():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -675,7 +675,7 @@ def test_meta_exception_meta():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, callback=raise_exception)
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -728,12 +728,12 @@ def test_meta_callback():
meta.option('val4').value.reset()
def test_meta_callback_slave():
def test_meta_callback_follower():
val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val)))
val3 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
val4 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
interface1 = MasterSlaves('val1', '', [val1, val3, val4])
interface1 = Leadership('val1', '', [val1, val3, val4])
od = OptionDescription('root', '', [interface1])
maconfig = OptionDescription('rootconfig', '', [val, interface1])
cfg = Config(maconfig, session_id='cfg1')
@ -774,7 +774,7 @@ def test_meta_callback_slave():
def test_meta_reset():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')

View File

@ -5,9 +5,9 @@ from py.test import raises
from tiramisu.setting import groups, owners
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, \
OptionDescription, MasterSlaves, Config, GroupConfig, MixConfig, \
OptionDescription, Leadership, Config, GroupConfig, MixConfig, \
Params, ParamOption, ParamValue
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, SlaveError, APIError
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, LeadershipError, APIError
from tiramisu.storage import list_sessions
owners.addowner('mix1')
@ -311,10 +311,10 @@ def test_mix_unconsistent():
MixConfig(od2, [conf3, conf4])
def test_mix_master_slaves():
def test_mix_leadership():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -337,10 +337,10 @@ def test_mix_master_slaves():
assert conf2._config_bag.context == next(itr)._config_bag.context
def test_mix_master_slaves_value2():
def test_mix_leadership_value2():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -362,10 +362,10 @@ def test_mix_master_slaves_value2():
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
def test_mix_master_slaves_value_default():
def test_mix_leadership_value_default():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -385,17 +385,17 @@ def test_mix_master_slaves_value_default():
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
def test_mix_master_slaves_owners():
def test_mix_leadership_owners():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
mix = MixConfig(od, [conf1, conf2])
mix.owner.set(owners.mix1)
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
raises(SlaveError, "mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()")
raises(LeadershipError, "mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()")
#
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
@ -424,7 +424,7 @@ def test_mix_master_slaves_owners():
def test_mix_force_default():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -462,7 +462,7 @@ def test_mix_force_default():
def test_mix_force_dont_change_value():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -489,7 +489,7 @@ def test_mix_force_dont_change_value():
def test_mix_force_default_if_same():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -531,7 +531,7 @@ def test_mix_force_default_if_same():
def test_mix_force_default_if_same_and_dont_change():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -573,7 +573,7 @@ def test_mix_force_default_if_same_and_dont_change():
def test_mix_force_default_and_dont_change():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='rconf1')
conf2 = Config(od, session_id='rconf2')
@ -587,7 +587,7 @@ def test_mix_properties_mix():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -602,7 +602,7 @@ def test_mix_exception_mix():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, callback=raise_exception)
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
@ -635,12 +635,12 @@ def test_mix_callback():
mix.option('val4').value.reset()
def test_mix_callback_slave():
def test_mix_callback_follower():
val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val)))
val3 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
val4 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
interface1 = MasterSlaves('val1', '', [val1, val3, val4])
interface1 = Leadership('val1', '', [val1, val3, val4])
od = OptionDescription('root', '', [interface1])
maconfig = OptionDescription('rootconfig', '', [val, interface1])
cfg = Config(maconfig, session_id='cfg1')
@ -681,15 +681,15 @@ def test_mix_callback_slave():
def test_meta_reset():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od0 = OptionDescription('root', '', [interface1])
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('root', '', [interface1])
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od2 = OptionDescription('root', '', [interface1])
conf1 = Config(od0, session_id='conf1')
conf2 = Config(od1, session_id='conf2')

View File

@ -195,10 +195,10 @@ def test_optiondescription_group_redefined():
raises(ValueError, "od1.impl_set_group_type(groups.notfamily)")
def test_optiondescription_group_masterslave():
def test_optiondescription_group_leadership():
i = IntOption('test', '')
od1 = OptionDescription('od', '', [i])
raises(ConfigError, "od1.impl_set_group_type(groups.master)")
raises(ConfigError, "od1.impl_set_group_type(groups.leadership)")

View File

@ -7,10 +7,10 @@ from tiramisu import Config
from tiramisu.config import KernelConfig
from tiramisu.setting import groups, owners
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, MasterSlaves, \
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, Leadership, \
undefined, Params, ParamOption, ParamValue, ParamContext
from tiramisu.api import TIRAMISU_VERSION
from tiramisu.error import PropertiesOptionError, ConflictError, SlaveError, ConfigError
from tiramisu.error import PropertiesOptionError, ConflictError, LeadershipError, ConfigError
from tiramisu.i18n import _
from tiramisu.storage import list_sessions
@ -502,11 +502,10 @@ def test_callback_multi_callback():
assert api.option('val1.val1').value.get() == ['val1', 'val']
def test_callback_master_and_slaves_master():
def test_callback_leader_and_followers_leader():
val1 = StrOption('val1', "", multi=True, callback=return_val)
val2 = StrOption('val2', "", multi=True)
interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -517,11 +516,10 @@ def test_callback_master_and_slaves_master():
assert api.option('val1.val2', 1).value.get() == None
def test_callback_slave():
def test_callback_follower():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value3, callback_params=Params(ParamValue(['string', 'new'])))
interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -541,13 +539,12 @@ def test_callback_slave():
assert api.option('val1.val2', 3).value.get() == None
def test_callback_master_and_slaves_master2():
def test_callback_leader_and_followers_leader2():
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 = MasterSlaves('val1', '', [val1, val2, val3, val4])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -557,13 +554,12 @@ def test_callback_master_and_slaves_master2():
assert api.option('val1.val2', 0).value.get() == 'val2'
def test_callback_master_and_slaves_master_mandatory():
def test_callback_leader_and_followers_leader_mandatory():
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 = MasterSlaves('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, interface1])
api = Config(maconfig)
api.property.read_only()
@ -579,14 +575,13 @@ def test_callback_master_and_slaves_master_mandatory():
raises(PropertiesOptionError, "api.option('val1.val4', 1).value.get()")
def test_callback_master_and_slaves_master_mandatory2():
def test_callback_leader_and_followers_leader_mandatory2():
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',))
val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1), {'val2': ParamOption(val_)}), properties=('mandatory',))
val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1), {'val2': ParamOption(val_)}), properties=('mandatory',))
interface1 = MasterSlaves('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
api = Config(maconfig)
api.property.read_only()
@ -608,14 +603,13 @@ def test_callback_master_and_slaves_master_mandatory2():
assert api.option('val1.val1').value.get() == ['val', 'val_', 'val3']
def test_callback_master_and_slaves_master_mandatory3():
def test_callback_leader_and_followers_leader_mandatory3():
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',))
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 = MasterSlaves('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
api = Config(maconfig)
api.property.read_only()
@ -636,13 +630,12 @@ def test_callback_master_and_slaves_master_mandatory3():
assert api.option('val1.val1').value.get() == ['val', 'val_', 'val3']
def test_callback_master_and_slaves_master_mandatory4():
def test_callback_leader_and_followers_leader_mandatory4():
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 = MasterSlaves('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, interface1])
api = Config(maconfig)
api.property.read_only()
@ -660,26 +653,24 @@ def test_callback_master_and_slaves_master_mandatory4():
assert api.option('val1.val4', 1).value.get() == 'val3'
def test_callback_master_and_slaves_master3():
def test_callback_leader_and_followers_leader3():
val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty'))
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',))
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 = MasterSlaves('val1', '', [val1, val2, val3, val4])
#interface1.impl_set_group_type(groups.master)
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']
def test_callback_master_and_slaves_master4():
def test_callback_leader_and_followers_leader4():
val1 = StrOption('val1', "", ['val1'], multi=True, properties=('mandatory',))
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert', 'mandatory'))
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 = MasterSlaves('val1', '', [val1, val2, val3, val4])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -688,7 +679,7 @@ def test_callback_master_and_slaves_master4():
assert list(api.value.mandatory()) == []
def test_consistency_master_and_slaves_master_mandatory_transitive():
def test_consistency_leader_and_followers_leader_mandatory_transitive():
#default value
val1 = IPOption('val1', "", ['192.168.0.1'], multi=True, properties=('mandatory',))
val2 = NetmaskOption('val2', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
@ -697,8 +688,8 @@ def test_consistency_master_and_slaves_master_mandatory_transitive():
val3 = IPOption('val3', "", multi=True, properties=('mandatory',))
val4 = NetmaskOption('val4', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
val4.impl_add_consistency('ip_netmask', val3)
interface1 = MasterSlaves('val1', '', [val1, val2])
interface2 = MasterSlaves('val3', '', [val3, val4])
interface1 = Leadership('val1', '', [val1, val2])
interface2 = Leadership('val3', '', [val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
api = Config(maconfig)
api.property.read_write()
@ -712,7 +703,7 @@ def test_consistency_master_and_slaves_master_mandatory_transitive():
assert list(api.value.mandatory()) == []
def test_consistency_master_and_slaves_master_mandatory_non_transitive():
def test_consistency_leader_and_followers_leader_mandatory_non_transitive():
#no value
val1 = IPOption('val1', "", multi=True, properties=('mandatory',))
val2 = NetmaskOption('val2', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
@ -721,10 +712,8 @@ def test_consistency_master_and_slaves_master_mandatory_non_transitive():
val3 = IPOption('val3', "", ['192.168.0.1'], multi=True, properties=('mandatory',))
val4 = NetmaskOption('val4', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
val4.impl_add_consistency('ip_netmask', val3, transitive=False)
interface1 = MasterSlaves('val1', '', [val1, val2])
interface2 = MasterSlaves('val3', '', [val3, val4])
#interface1.impl_set_group_type(groups.master)
#interface2.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
interface2 = Leadership('val3', '', [val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
api = Config(maconfig)
api.property.read_write()
@ -734,11 +723,10 @@ def test_consistency_master_and_slaves_master_mandatory_non_transitive():
assert list(api.value.mandatory()) == ["val1.val1"]
def test_callback_master_and_slaves_master_list():
def test_callback_leader_and_followers_leader_list():
val1 = StrOption('val1', "", multi=True, callback=return_list)
val2 = StrOption('val2', "", multi=True)
interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -759,24 +747,22 @@ def test_callback_master_and_slaves_master_list():
assert api.option('val1.val2', 0).value.get() == None
def test_callback_master_and_slaves_master_slave_list():
def test_callback_leader_and_followers_leader_follower_list():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_list)
interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
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(SlaveError, "api.option('val1.val2', 0).value.get()")
raises(LeadershipError, "api.option('val1.val2', 0).value.get()")
def test_callback_master_and_slaves_slave():
def test_callback_leader_and_followers_follower():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_val)
interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -813,21 +799,20 @@ def test_callback_master_and_slaves_slave():
assert api.option('val1.val2', 2).value.get() == 'val'
def test_callback_master_and_slaves():
def test_callback_leader_and_followers():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_val)
interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
def test_callback_master_and_slaves_slave_cal():
def test_callback_leader_and_followers_follower_cal():
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 = MasterSlaves('val1', '', [val1, val2])
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val3])
api = Config(maconfig)
api.property.read_write()
@ -847,12 +832,12 @@ def test_callback_master_and_slaves_slave_cal():
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']
# len of slave is higher than master's one
# 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(SlaveError, "api.option('val1.val2', 0).value.get()")
raises(LeadershipError, "api.option('val1.val2', 0).value.get()")
#
api.option('val3').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val2', 0).value.get() == 'val1'
@ -860,12 +845,11 @@ def test_callback_master_and_slaves_slave_cal():
assert api.option('val1.val2', 2).value.get() == 'val'
def test_callback_master_and_slaves_master_disabled():
def test_callback_leader_and_followers_leader_disabled():
#properties must be transitive
val1 = StrOption('val1', "", ['val1'], multi=True, properties=('disabled',))
val2 = StrOption('val2', "", multi=True)
interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -874,12 +858,11 @@ def test_callback_master_and_slaves_master_disabled():
raises(PropertiesOptionError, "api.option('val1.val2', 0).value.get()")
def test_callback_master_and_slaves_master_callback_disabled():
def test_callback_leader_and_followers_leader_callback_disabled():
val0 = StrOption('val0', "", multi=True, properties=('disabled',))
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0)))
val2 = StrOption('val2', "", multi=True)
interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val0])
api = Config(maconfig)
api.property.read_write()
@ -891,11 +874,10 @@ def test_callback_master_and_slaves_master_callback_disabled():
assert api.option('val1.val1').value.get() == []
def test_callback_master_and_slaves_slave_disabled():
def test_callback_leader_and_followers_follower_disabled():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, properties=('disabled',))
interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -919,12 +901,11 @@ def test_callback_master_and_slaves_slave_disabled():
assert api.option('val1.val2', 1).value.get() == 'no1'
def test_callback_master_and_slaves_slave_callback_disabled():
def test_callback_leader_and_followers_follower_callback_disabled():
val0 = StrOption('val0', "", multi=True, properties=('disabled',))
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0)))
interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val0])
api = Config(maconfig)
api.property.read_write()
@ -939,28 +920,27 @@ def test_callback_master_and_slaves_slave_callback_disabled():
api.option('val1.val1').value.pop(1)
def test_callback_master_and_slaves_value():
def test_callback_leader_and_followers_value():
val4 = StrOption('val4', '', multi=True, default=['val10', 'val11'])
val1 = StrOption('val1', "", 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')))
val5 = StrOption('val5', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val4)))
val6 = StrOption('val6', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val5)))
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val5, val6])
#interface1.impl_set_group_type(groups.master)
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() == []
#raises(SlaveError, "cfg.val1.val1")
#raises(SlaveError, "cfg.val1.val2")
#raises(SlaveError, "cfg.val1.val3")
#raises(SlaveError, "cfg.val1.val5")
#raises(SlaveError, "cfg.val1.val6")
#raises(LeadershipError, "cfg.val1.val1")
#raises(LeadershipError, "cfg.val1.val2")
#raises(LeadershipError, "cfg.val1.val3")
#raises(LeadershipError, "cfg.val1.val5")
#raises(LeadershipError, "cfg.val1.val6")
#
#default calculation has greater length
#raises(SlaveError, "api.option('val1.val1').value.set(['val1']")
#raises(LeadershipError, "api.option('val1.val1').value.set(['val1']")
#
api.option('val1.val1').value.set(['val1', 'val2'])
assert api.option('val1.val1').value.get() == ['val1', 'val2']
@ -968,10 +948,10 @@ def test_callback_master_and_slaves_value():
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(SlaveError, "api.option('val1.val5', 0).value.get()")
raises(SlaveError, "api.option('val1.val5', 1).value.get()")
raises(SlaveError, "api.option('val1.val6', 0).value.get()")
raises(SlaveError, "api.option('val1.val6', 1).value.get()")
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()")
#
api.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
@ -981,8 +961,8 @@ def test_callback_master_and_slaves_value():
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(SlaveError, "api.option('val1.val5', 2).value.get()")
raises(SlaveError, "api.option('val1.val6', 2).value.get()")
raises(LeadershipError, "api.option('val1.val5', 2).value.get()")
raises(LeadershipError, "api.option('val1.val6', 2).value.get()")
#
api.option('val1.val1').value.pop(2)
assert api.option('val1.val1').value.get() == ['val1', 'val2']
@ -1011,10 +991,10 @@ def test_callback_master_and_slaves_value():
assert api.option('val1.val3', 2).value.get() == 'yes'
def test_callback_master():
def test_callback_leader():
val2 = StrOption('val2', "", multi=True, callback=return_value)
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2)))
raises(ValueError, "MasterSlaves('val1', '', [val1, val2])")
raises(ValueError, "Leadership('val1', '', [val1, val2])")
def test_callback_different_type():
@ -1022,8 +1002,7 @@ def test_callback_different_type():
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 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val, val_])
api = Config(maconfig)
api.property.read_write()
@ -1181,11 +1160,10 @@ def test_callback_multi_list_params_key():
assert api.option('val2.val2').value.get() == ['val', 'val']
def test_masterslaves_callback_description():
def test_leadership_callback_description():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(st1)))
stm = MasterSlaves('st1', '', [st1, st2])
#stm.impl_set_group_type(groups.master)
stm = Leadership('st1', '', [st1, st2])
st = OptionDescription('st', '', [stm])
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])

View File

@ -5,7 +5,7 @@ from py.test import raises
from tiramisu.setting import owners, groups
from tiramisu import IPOption, NetworkOption, NetmaskOption, IntOption,\
BroadcastOption, StrOption, SymLinkOption, OptionDescription, submulti, MasterSlaves,\
BroadcastOption, StrOption, SymLinkOption, OptionDescription, submulti, Leadership,\
Config, undefined, Params, ParamOption
from tiramisu.error import ConfigError, ValueWarning, PropertiesOptionError
from tiramisu.api import TIRAMISU_VERSION
@ -264,7 +264,7 @@ def test_consistency_mix():
b = IntOption('b', '', multi=True)
c = IntOption('c', '', multi=True)
d = IntOption('d', '', multi=True)
od = MasterSlaves('c', '', [c, d])
od = Leadership('c', '', [c, d])
od2 = OptionDescription('a', '', [b, od])
c.impl_add_consistency('not_equal', b, d)
cfg = Config(od2)
@ -295,10 +295,10 @@ def test_consistency_not_equal_default_submulti():
raises(ConfigError, "a.impl_add_consistency('not_equal', b)")
def test_consistency_not_equal_masterslave():
def test_consistency_not_equal_leadership():
a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True)
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
od2 = OptionDescription('b', '', [od])
a.impl_add_consistency('not_equal', b)
api = Config(od2)
@ -313,27 +313,27 @@ def test_consistency_not_equal_masterslave():
api.value.dict()
def test_consistency_not_equal_masterslave_error_multi1():
def test_consistency_not_equal_leadership_error_multi1():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = NetmaskOption('c', '', multi=True)
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
od2 = OptionDescription('b', '', [od, c])
c.impl_add_consistency('ip_netmask', a)
raises(ConfigError, "Config(od2)")
def test_consistency_not_equal_masterslave_error_multi2():
def test_consistency_not_equal_leadership_error_multi2():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = IPOption('c', '', multi=True)
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
od2 = OptionDescription('b', '', [od, c])
b.impl_add_consistency('ip_netmask', c)
raises(ConfigError, "Config(od2)")
def test_consistency_ip_netmask_masterslave_error_not_master():
def test_consistency_ip_netmask_leadership_error_not_leader():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = OptionDescription('a', '', [a, b])
@ -342,34 +342,34 @@ def test_consistency_ip_netmask_masterslave_error_not_master():
raises(ConfigError, "Config(od2)")
def test_consistency_ip_netmask_masterslave_error_master_and_not():
def test_consistency_ip_netmask_leadership_error_leader_and_not():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = IPOption('c', '', multi=True)
d = NetmaskOption('d', '', multi=True)
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
od2 = OptionDescription('c', '', [c, d])
od3 = OptionDescription('b', '', [od, od2])
d.impl_add_consistency('ip_netmask', a)
raises(ConfigError, "Config(od3)")
def test_consistency_ip_netmask_masterslave_error_othermaster():
def test_consistency_ip_netmask_leadership_error_otherleader():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = IPOption('c', '', multi=True)
d = NetmaskOption('d', '', multi=True)
od = MasterSlaves('a', '', [a, b])
od2 = MasterSlaves('c', '', [c, d])
od = Leadership('a', '', [a, b])
od2 = Leadership('c', '', [c, d])
od3 = OptionDescription('b', '', [od, od2])
d.impl_add_consistency('ip_netmask', a)
raises(ConfigError, "Config(od2)")
def test_consistency_not_equal_masterslaves_default():
def test_consistency_not_equal_leadership_default():
a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True, default_multi=1)
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
od2 = OptionDescription('a', '', [od])
a.impl_add_consistency('not_equal', b)
api = Config(od2)
@ -423,10 +423,10 @@ def test_consistency_not_equal_multi_default2():
a.impl_add_consistency('not_equal', b)
def test_consistency_not_equal_master_default():
def test_consistency_not_equal_leader_default():
a = IntOption('a', '', multi=True, default=[2, 1])
b = IntOption('b', '', multi=True, default_multi=1)
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
a.impl_add_consistency('not_equal', b)
od2 = OptionDescription('a', '', [od])
api = Config(od2)
@ -586,7 +586,7 @@ def test_consistency_ip_netmask_error_multi():
def test_consistency_ip_netmask_multi():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
b.impl_add_consistency('ip_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
@ -606,7 +606,7 @@ def test_consistency_ip_netmask_multi():
def test_consistency_network_netmask_multi():
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od', '', [od])
api = Config(od2)
@ -618,10 +618,10 @@ def test_consistency_network_netmask_multi():
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
def test_consistency_network_netmask_multi_slave_default_multi():
def test_consistency_network_netmask_multi_follower_default_multi():
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 = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
od2 = OptionDescription('od2', '', [od])
b.impl_add_consistency('network_netmask', a)
api = Config(od2)
@ -631,10 +631,10 @@ def test_consistency_network_netmask_multi_slave_default_multi():
assert api.option('a.b', 0).value.get() == '255.255.255.0'
def test_consistency_network_netmask_multi_slave_default():
def test_consistency_network_netmask_multi_follower_default():
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
@ -657,19 +657,19 @@ def return_netmask(*args, **kwargs):
return u'255.255.255.0'
def return_netmask2(master):
if master is not None:
if master.endswith('2.1'):
def return_netmask2(leader):
if leader is not None:
if leader.endswith('2.1'):
return u'255.255.255.0'
if not master.endswith('.0'):
if not leader.endswith('.0'):
return u'255.255.255.255'
return u'255.255.255.0'
def test_consistency_network_netmask_multi_slave_callback():
def test_consistency_network_netmask_multi_follower_callback():
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', callback=return_netmask, multi=True, properties=('mandatory',))
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
@ -688,10 +688,10 @@ def test_consistency_network_netmask_multi_slave_callback():
api.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
def test_consistency_network_netmask_multi_slave_callback_value():
def test_consistency_network_netmask_multi_follower_callback_value():
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', callback=return_netmask2, callback_params=Params(ParamOption(a)), multi=True, properties=('mandatory',))
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
@ -712,10 +712,10 @@ def test_consistency_network_netmask_multi_slave_callback_value():
api.option('a.b', 1).value.set('255.255.255.255')
def test_consistency_ip_netmask_multi_master():
def test_consistency_ip_netmask_multi_leader():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
b.impl_add_consistency('ip_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
@ -730,10 +730,10 @@ def test_consistency_ip_netmask_multi_master():
api.option('a.a').value.set(['192.168.1.2', '192.168.1.3'])
def test_consistency_network_netmask_multi_master():
def test_consistency_network_netmask_multi_leader():
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
@ -749,7 +749,7 @@ def test_consistency_broadcast():
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', multi=True)
od = MasterSlaves('a', '', [a, b, c])
od = Leadership('a', '', [a, b, c])
b.impl_add_consistency('network_netmask', a)
c.impl_add_consistency('broadcast', a, b)
od2 = OptionDescription('od2', '', [od])
@ -776,7 +776,7 @@ def test_consistency_broadcast_error():
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', multi=True)
od = MasterSlaves('a', '', [a, b, c])
od = Leadership('a', '', [a, b, c])
od2 = OptionDescription('od2', '', [od])
b.impl_add_consistency('network_netmask', a)
c.impl_add_consistency('broadcast', a)
@ -825,7 +825,7 @@ def test_consistency_not_all():
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', multi=True)
od = MasterSlaves('a', '', [a, b, c])
od = Leadership('a', '', [a, b, c])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)
@ -991,7 +991,7 @@ def test_consistency_warnings_error():
def test_consistency_network_netmask_mandatory():
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 = MasterSlaves('a', '', [a, b])
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
api = Config(od2)

View File

@ -7,7 +7,7 @@ from py.test import raises
from tiramisu.setting import owners
from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu import IntOption, FloatOption, StrOption, ChoiceOption, \
BoolOption, OptionDescription, MasterSlaves, Config, undefined
BoolOption, OptionDescription, Leadership, Config, undefined
from tiramisu.storage import list_sessions
@ -112,31 +112,31 @@ def test_force_default_on_freeze_multi():
api.option('dummy1').property.add('frozen')
def test_force_default_on_freeze_master():
def test_force_default_on_freeze_leader():
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_default_on_freeze',))
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = MasterSlaves("dummy1", "", [dummy1, dummy2])
descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr])
raises(ConfigError, "Config(descr)")
def test_force_default_on_freeze_master_frozen():
def test_force_default_on_freeze_leader_frozen():
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_default_on_freeze', 'frozen'))
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = MasterSlaves("dummy1", "", [dummy1, dummy2])
descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr])
api = Config(descr)
raises(ConfigError, "api.option('dummy1.dummy1').property.pop('frozen')")
def test_force_default_on_freeze_slave():
def test_force_default_on_freeze_follower():
dummy1 = BoolOption('dummy1', 'Test int option', multi=True)
dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',))
descr = MasterSlaves("dummy1", "", [dummy1, dummy2])
descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr])
api = Config(descr)
api.property.read_write()
owners.addowner("frozenmultislave2")
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]
@ -149,7 +149,7 @@ def test_force_default_on_freeze_slave():
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('frozenmultislave2')")
raises(PropertiesOptionError, "api.option('dummy1.dummy2', 0).owner.set('frozenmultifollower2')")
#
api.option('dummy1.dummy2').property.pop('frozen')
api.option('dummy1.dummy1').value.set([True, True])

View File

@ -5,7 +5,7 @@ from py.test import raises
from tiramisu.setting import owners, groups
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config
StrOption, OptionDescription, SymLinkOption, Leadership, Config
from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, APIError
from tiramisu.storage import list_sessions
@ -165,10 +165,10 @@ def test_setowner_symlinkoption():
raises(ConfigError, "api.option('tiramisu.symdummy').owner.set('user')")
def test_owner_masterslaves():
def test_owner_leadership():
b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', multi=True)
descr = MasterSlaves("int", "", [b, c])
descr = Leadership("int", "", [b, c])
od = OptionDescription('od', '', [descr])
api = Config(od)
raises(ConfigError, "api.option('int.str', 0).owner.set('user')")

View File

@ -8,7 +8,7 @@ from tiramisu.i18n import _
from tiramisu.error import display_list, ConfigError
from tiramisu.setting import owners, groups
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, MasterSlaves, Config, undefined
StrOption, OptionDescription, Leadership, Config, undefined
from tiramisu.error import PropertiesOptionError
from tiramisu.storage import list_sessions
@ -335,25 +335,25 @@ def test_multi_with_requires_that_is_multi_inverse():
raises(ValueError, "Config(descr)")
def test_multi_with_requires_that_is_masterslave():
def test_multi_with_requires_that_is_leadership():
b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = MasterSlaves("int", "", [b, c])
descr = Leadership("int", "", [b, c])
od = OptionDescription('root', '', [descr])
Config(od)
def test_multi_with_requires_that_is_masterslave_master():
def test_multi_with_requires_that_is_leadership_leader():
b = IntOption('int', 'Test int option', multi=True)
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
raises(ValueError, "MasterSlaves('str', '', [c, b])")
raises(ValueError, "Leadership('str', '', [c, b])")
def test_multi_with_requires_that_is_masterslave_slave():
def test_multi_with_requires_that_is_leadership_follower():
b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', multi=True)
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': '1', 'action': 'hidden'}], multi=True)
descr = MasterSlaves("int", "", [b, c, d])
descr = Leadership("int", "", [b, c, d])
descr2 = OptionDescription('od', '', [descr])
api = Config(descr2)
api.property.read_write()
@ -375,11 +375,11 @@ def test_multi_with_requires_that_is_masterslave_slave():
raises(PropertiesOptionError, "api.option('int.str1', 1).value.get()")
def test_multi_with_requires_that_is_masterslave_slave_inverse():
def test_multi_with_requires_that_is_leadership_follower_inverse():
b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', multi=True)
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True)
descr = MasterSlaves("int", "", [b, c, d])
descr = Leadership("int", "", [b, c, d])
descr2 = OptionDescription('od', '', [descr])
api = Config(descr2)
api.property.read_write()
@ -401,15 +401,13 @@ def test_multi_with_requires_that_is_masterslave_slave_inverse():
raises(PropertiesOptionError, "api.option('int.str1', 1).value.get()")
def test_multi_with_requires_that_is_not_same_masterslave():
def test_multi_with_requires_that_is_not_same_leadership():
b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
descr1 = MasterSlaves("int", "", [b, c])
#descr1.impl_set_group_type(groups.master)
descr1 = Leadership("int", "", [b, c])
d = IntOption('int1', 'Test int option', default=[0], multi=True)
e = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
descr2 = MasterSlaves("int1", "", [d, e])
#descr2.impl_set_group_type(groups.master)
descr2 = Leadership("int1", "", [d, e])
descr3 = OptionDescription('val', '', [descr1, descr2])
descr3
raises(ValueError, "Config(descr3)")

View File

@ -4,7 +4,7 @@ do_autopath()
import warnings
from py.test import raises
from tiramisu import BoolOption, StrOption, OptionDescription, MasterSlaves, Config, Params, ParamValue, ParamOption, ParamContext
from tiramisu import BoolOption, StrOption, OptionDescription, Leadership, Config, Params, ParamValue, ParamOption, ParamContext
from tiramisu.setting import groups
from tiramisu.error import ValueWarning, ConfigError
from tiramisu.i18n import _
@ -153,33 +153,30 @@ def test_validator_params_value_values_index():
api.option('opt1').value.set(['val1', 'val2'])
def test_validator_params_value_values_master():
def test_validator_params_value_values_leader():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1])
api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
def test_validator_params_value_values_index_master():
def test_validator_params_value_values_index_leader():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values_index)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1])
api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
def test_validator_params_value_values_slave():
def test_validator_params_value_values_follower():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1])
api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
@ -189,11 +186,10 @@ def test_validator_params_value_values_slave():
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
def test_validator_params_value_values_index_slave():
def test_validator_params_value_values_index_follower():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values_index)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1])
api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
@ -215,8 +211,7 @@ def test_validator_params_value_values_kwargs_empty():
multi=True,
validator=value_empty,
validator_params=Params(ParamOption(v)))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [v, interface1])
api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
@ -233,8 +228,7 @@ def test_validator_params_value_values_kwargs():
multi=True,
validator=value_values_auto,
validator_params=Params(kwargs={'auto': ParamOption(v)}))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [v, interface1])
api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
@ -250,8 +244,7 @@ def test_validator_params_value_values_kwargs_values():
multi=True,
validator=value_values_auto2,
validator_params=Params(kwargs={'values': ParamOption(ip_admin_eth0)}))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1])
api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
@ -268,8 +261,7 @@ def test_validator_params_value_values_kwargs2():
multi=True,
validator=value_values_index2,
validator_params=Params(ParamValue(['val1']), {'index': ParamOption(ip_admin_eth0)}))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1])
api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
@ -285,8 +277,7 @@ def test_validator_params_value_values_kwargs_index():
multi=True,
validator=value_values_index2,
validator_params=Params(kwargs={'index': ParamOption(ip_admin_eth0)}))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1])
api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
@ -439,14 +430,13 @@ def test_validator_warning_disabled():
assert len(w) == 1
def test_validator_warning_master_slave():
def test_validator_warning_leadership():
display_name_ip = "ip reseau autorise"
display_name_netmask = "masque du sous-reseau"
ip_admin_eth0 = StrOption('ip_admin_eth0', display_name_ip, multi=True, validator=return_false, warnings_only=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', display_name_netmask, multi=True, validator=return_if_val, warnings_only=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
assert interface1.impl_get_group_type() == groups.master
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
assert interface1.impl_get_group_type() == groups.leadership
root = OptionDescription('root', '', [interface1])
api = Config(root)
warnings.simplefilter("always", ValueWarning)
@ -489,15 +479,14 @@ def test_validator_warning_master_slave():
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')
def test_validator_slave_param():
def test_validator_follower_param():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
"masque du sous-reseau",
multi=True,
validator=return_true,
validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)}))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1])
api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []

View File

@ -8,7 +8,7 @@ from tiramisu.setting import groups
from tiramisu import setting
setting.expires_time = 1
from tiramisu import IPOption, OptionDescription, BoolOption, IntOption, StrOption, \
MasterSlaves, Config
Leadership, Config
from tiramisu.error import PropertiesOptionError, RequirementError
from py.test import raises
from tiramisu.storage import list_sessions, delete_session
@ -956,11 +956,11 @@ def test_properties_conflict():
raises(ValueError, "od1 = OptionDescription('service', '', [a], properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
def test_master_slave_requires():
def test_leadership_requires():
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,
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -1006,46 +1006,46 @@ def test_master_slave_requires():
del ret['ip_admin_eth0.netmask_admin_eth0']
def test_master_slave_requires_both():
def test_leadership_requires_both():
ip_admin = StrOption('ip_admin_eth0', "ip réseau autorisé")
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
raises(RequirementError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])")
raises(RequirementError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])")
def test_master_slave_requires_properties_invalid():
def test_leadership_requires_properties_invalid():
ip_admin = StrOption('ip_admin', "ip réseau autorisé")
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,
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',), requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',), requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])")
def test_master_slave_requires_properties_invalid_2():
def test_leadership_requires_properties_invalid_2():
ip_admin = StrOption('ip_admin', "ip réseau autorisé")
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',))")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',))")
def test_master_slave_requires_properties():
def test_leadership_requires_properties():
ip_admin = StrOption('ip_admin', "ip réseau autorisé")
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,
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('hidden',),
Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('hidden',),
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])
def test_master_slave_requires_master():
def test_leadership_requires_leader():
activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig)
api.property.read_write()
@ -1068,11 +1068,11 @@ def test_master_slave_requires_master():
assert api.value.dict() == {'activate': False}
def test_master_slave_requires_masterslaves():
def test_leadership_requires_leadership():
activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0],
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0],
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
maconfig = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig)
@ -1096,13 +1096,12 @@ def test_master_slave_requires_masterslaves():
assert api.value.dict() == {'activate': False}
def test_master_slave_requires_no_master():
def test_leadership_requires_no_leader():
activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig)
api.property.read_write()

View File

@ -109,10 +109,10 @@ def _diff_opt(opt1, opt2):
assert v[1][key][i] == val2[idx][1][key][i]
else:
assert v[1] == val2[idx][1]
elif attr == '_master_slaves':
assert val1._p_._sm_getmaster().impl_getname() == val2._p_._sm_getmaster().impl_getname()
sval1 = [opt.impl_getname() for opt in val1._p_._sm_getslaves()]
sval2 = [opt.impl_getname() for opt in val2._p_._sm_getslaves()]
elif attr == '_leadership':
assert val1._p_._sm_get_leader().impl_getname() == val2._p_._sm_get_leader().impl_getname()
sval1 = [opt.impl_getname() for opt in val1._p_._sm_get_followers()]
sval2 = [opt.impl_getname() for opt in val2._p_._sm_get_followers()]
assert sval1 == sval2
elif attr == '_subdyn':
try:
@ -124,13 +124,13 @@ def _diff_opt(opt1, opt2):
lst1 = []
lst2 = []
for idx, val in enumerate(val1):
if isinstance(val, MasterSlaves):
lst1.append(val._p_.master.impl_getname())
if isinstance(val, Leadership):
lst1.append(val._p_.leader.impl_getname())
else:
lst1.append(val.impl_getname())
for idx, val in enumerate(val2):
if isinstance(val, MasterSlaves):
lst2.append(val._p_.master.impl_getname())
if isinstance(val, Leadership):
lst2.append(val._p_.leader.impl_getname())
else:
lst2.append(val.impl_getname())
assert set(lst1) == set(lst2), '{} - {}'.format(lst1, lst2)

View File

@ -6,7 +6,7 @@ from py.test import raises
from tiramisu.error import ConfigError
from tiramisu import Config
from tiramisu.option import BoolOption, OptionDescription, MasterSlaves
from tiramisu.option import BoolOption, OptionDescription, Leadership
from tiramisu.setting import groups, owners
from tiramisu.storage import list_sessions, delete_session
@ -174,11 +174,10 @@ def test_create_persistent_retrieve_owner():
del c
def test_create_persistent_retrieve_owner_masterslaves():
def test_create_persistent_retrieve_owner_leadership():
a = BoolOption('a', '', multi=True)
b = BoolOption('b', '', multi=True)
o = MasterSlaves('a', '', [a, b])
#o.impl_set_group_type(groups.master)
o = Leadership('a', '', [a, b])
o1 = OptionDescription('a', '', [o])
try:
c = Config(o1, session_id='test_persistent', persistent=True)

View File

@ -6,9 +6,9 @@ from py.test import raises
from tiramisu.api import TIRAMISU_VERSION
from tiramisu.setting import groups, owners
from tiramisu import StrOption, IntOption, OptionDescription, submulti, MasterSlaves, Config, \
from tiramisu import StrOption, IntOption, OptionDescription, submulti, Leadership, Config, \
MetaConfig, undefined, Params, ParamOption
from tiramisu.error import SlaveError
from tiramisu.error import LeadershipError
from tiramisu.storage import list_sessions
@ -199,33 +199,31 @@ def test_callback_submulti_list_list():
assert api.option('multi').owner.get() == owners.default
def test_groups_with_master_submulti():
def test_groups_with_leader_submulti():
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=submulti)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
assert interface1.impl_get_group_type() == groups.master
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
assert interface1.impl_get_group_type() == groups.leadership
def test_groups_with_master_in_config_submulti():
def test_groups_with_leader_in_config_submulti():
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=submulti)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
Config(od)
assert interface1.impl_get_group_type() == groups.master
assert interface1.impl_get_group_type() == groups.leadership
def test_values_with_master_and_slaves_submulti():
def test_values_with_leader_and_followers_submulti():
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=submulti)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
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 interface1.impl_get_group_type() == groups.master
assert interface1.impl_get_group_type() == groups.leadership
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
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"]
@ -242,16 +240,15 @@ def test_values_with_master_and_slaves_submulti():
raises(ValueError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set([['255.255.255.0']])")
def test_reset_values_with_master_and_slaves_submulti():
def test_reset_values_with_leader_and_followers_submulti():
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=submulti)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
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 interface1.impl_get_group_type() == groups.master
assert interface1.impl_get_group_type() == groups.leadership
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
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
@ -269,15 +266,14 @@ def test_reset_values_with_master_and_slaves_submulti():
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
def test_values_with_master_and_slaves_slave_submulti():
def test_values_with_leader_and_followers_follower_submulti():
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=submulti)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
raises(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])")
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.set(['255.255.255.0', '255.255.255.0'])
@ -289,11 +285,10 @@ def test_values_with_master_and_slaves_slave_submulti():
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
def test_values_with_master_and_slaves_master_submulti():
def test_values_with_leader_and_leadership_submulti():
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=submulti)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -310,11 +305,10 @@ def test_values_with_master_and_slaves_master_submulti():
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
def test_values_with_master_owner_submulti():
def test_values_with_leader_owner_submulti():
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=submulti)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -327,10 +321,10 @@ def test_values_with_master_owner_submulti():
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
def test_values_with_master_disabled_submulti():
def test_values_with_leader_disabled_submulti():
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=submulti)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig)
api.property.read_write()
@ -352,16 +346,15 @@ def test_values_with_master_disabled_submulti():
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
def test__master_is_submulti():
def test_leader_is_submulti():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=submulti)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
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 interface1.impl_get_group_type() == groups.master
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').value.get() == [["192.168.230.145"]]

View File

@ -4,7 +4,7 @@ from .autopath import do_autopath
do_autopath()
from tiramisu import BoolOption, StrOption, SymLinkOption, \
OptionDescription, MasterSlaves, Config
OptionDescription, Leadership, Config
from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.setting import groups, owners
from tiramisu.api import TIRAMISU_VERSION
@ -210,55 +210,55 @@ def test_symlink_get_information():
assert linkopt.impl_get_information('test') == 'test2'
def test_symlink_master():
def test_symlink_leader():
a = StrOption('a', "", multi=True)
ip_admin_eth0 = SymLinkOption('ip_admin_eth0', a)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "", multi=True)
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_symlink_slaves():
def test_symlink_followers():
a = StrOption('a', "", multi=True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = SymLinkOption('netmask_admin_eth0', a)
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_symlink_with_master():
def test_symlink_with_leader():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
master = SymLinkOption('master', ip_admin_eth0)
od = OptionDescription('root', '', [interface1, master])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
leader = SymLinkOption('leader', ip_admin_eth0)
od = OptionDescription('root', '', [interface1, leader])
api = Config(od)
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'master': []}
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'leader': []}
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'master': ['val1', 'val2']}
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'leader': ['val1', 'val2']}
def test_symlink_with_slave():
def test_symlink_with_follower():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
slave = SymLinkOption('slave', netmask_admin_eth0)
od = OptionDescription('root', '', [interface1, slave])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
follower = SymLinkOption('follower', netmask_admin_eth0)
od = OptionDescription('root', '', [interface1, follower])
api = Config(od)
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'slave': []}
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'follower': []}
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'slave': [None, None]}
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'follower': [None, None]}
#
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None
assert api.option('slave', 0).value.get() == None
assert api.option('slave', 1).value.get() == None
assert api.option('follower', 0).value.get() == None
assert api.option('follower', 1).value.get() == None
#
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val3')
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, 'val3'], 'slave': [None, 'val3']}
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, 'val3'], 'follower': [None, 'val3']}
#
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3'
assert api.option('slave', 0).value.get() == None
assert api.option('slave', 1).value.get() == 'val3'
assert api.option('follower', 0).value.get() == None
assert api.option('follower', 1).value.get() == 'val3'
#____________________________________________________________