master/slaves => leader/followers

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

View File

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

View File

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

View File

@ -8,7 +8,7 @@ from tiramisu import BoolOption, StrOption, ChoiceOption, IPOption, \
NetworkOption, NetmaskOption, IntOption, FloatOption, \ NetworkOption, NetmaskOption, IntOption, FloatOption, \
UnicodeOption, PortOption, BroadcastOption, DomainnameOption, \ UnicodeOption, PortOption, BroadcastOption, DomainnameOption, \
EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \ EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \
OptionDescription, DynOptionDescription, SynDynOption, submulti, MasterSlaves, \ OptionDescription, DynOptionDescription, SynDynOption, submulti, Leadership, \
Config, Params, ParamOption, ParamValue Config, Params, ParamOption, ParamValue
from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError
from tiramisu.storage import list_sessions 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') cfg.option('dodval1.cval1').value.set('192.168.1.1')
def test_masterslaves_dyndescription(): def test_leadership_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
stm = MasterSlaves('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list) st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
@ -988,10 +988,10 @@ def test_masterslaves_dyndescription():
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() 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) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no') 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) st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) 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.stval1.st1val1.st2val1', 0).owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').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) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
odval = OptionDescription('odval1', '', [val1]) odval = OptionDescription('odval1', '', [val1])
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", 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))) st = DynOptionDescription('st', '', [stm], callback=return_list, callback_params=Params(ParamOption(val1)))
od = OptionDescription('od', '', [st, odval]) od = OptionDescription('od', '', [st, odval])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
@ -1071,10 +1071,10 @@ def test_masterslaves_dyndescription_param():
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default 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) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no') 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) st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
@ -1095,7 +1095,7 @@ def test_masterslaves_default_multi_dyndescription():
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
def _test_masterslaves(cfg): def _test_leadership(cfg):
owner = cfg.owner.get() owner = cfg.owner.get()
cfg.option('od.val1.val1').value.set(['val1', 'val2']) cfg.option('od.val1.val1').value.set(['val1', 'val2'])
cfg.option('od.val1.val2', 0).value.set('val1') 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 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) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True) val2 = StrOption('val2', "", multi=True)
odval = MasterSlaves('val1', '', [val1, val2]) odval = Leadership('val1', '', [val1, val2])
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", 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))) st = DynOptionDescription('st', '', [stm], callback=return_list, callback_params=Params(ParamOption(val1)))
od = OptionDescription('od', '', [st, odval]) od = OptionDescription('od', '', [st, odval])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) 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) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no') 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) st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
@ -1187,24 +1187,24 @@ def test_masterslaves_default_multi_dyndescription():
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() 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) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True) val2 = StrOption('val2', "", multi=True)
odval = MasterSlaves('val1', '', [val1, val2]) odval = Leadership('val1', '', [val1, val2])
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", 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))) st = DynOptionDescription('st', '', [stm], callback=return_list, callback_params=Params(ParamOption(val2)))
od = OptionDescription('od', '', [st, odval]) od = OptionDescription('od', '', [st, odval])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) 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) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no') 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) st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
@ -1225,10 +1225,10 @@ def test_masterslaves_default_multi_dyndescription():
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
def test_masterslaves_submulti_dyndescription(): def test_leadership_submulti_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=submulti) st2 = StrOption('st2', "", multi=submulti)
stm = MasterSlaves('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
std = DynOptionDescription('st', '', [stm], callback=return_list) std = DynOptionDescription('st', '', [stm], callback=return_list)
od1 = OptionDescription('od', '', [std]) od1 = OptionDescription('od', '', [std])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
@ -1257,53 +1257,10 @@ def test_masterslaves_submulti_dyndescription():
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#FIXME DynOptionDescription cannot be MasterSlave def test_leadership_callback_dyndescription():
#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():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params=Params(kwargs={'value': ParamOption(st1)})) 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) st1 = DynOptionDescription('st', '', [stm], callback=return_list)
od1 = OptionDescription('od', '', [st1]) od1 = OptionDescription('od', '', [st1])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
@ -1361,10 +1318,10 @@ def test_masterslaves_callback_dyndescription():
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'yes' 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) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params=Params(kwargs={'value': ParamValue('val')})) 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) st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) 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' 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") v11 = StrOption('v1', '', "val")
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params=Params(ParamOption(v11))) 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) stt = DynOptionDescription('st', '', [stm], callback=return_list)
od1 = OptionDescription('od', '', [stt]) od1 = OptionDescription('od', '', [stt])
od2 = OptionDescription('od', '', [od1, v11]) 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' 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) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
st3 = StrOption('st3', "", multi=True, callback=return_dynval, callback_params=Params(ParamOption(st2))) 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) stt = DynOptionDescription('st', '', [stm], callback=return_list)
od1 = OptionDescription('od', '', [stt]) od1 = OptionDescription('od', '', [stt])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])

View File

@ -7,7 +7,7 @@ from py.test import raises
from tiramisu.setting import owners, groups from tiramisu.setting import owners, groups
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config, \ StrOption, OptionDescription, SymLinkOption, Leadership, Config, \
Params, ParamContext, ParamOption, ParamValue Params, ParamContext, ParamOption, ParamValue
from tiramisu.error import PropertiesOptionError, ConfigError from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
@ -178,25 +178,25 @@ def test_force_store_value_no_requirement():
pass pass
def test_force_store_value_masterslaves_slave(): def test_force_store_value_leadership_follower():
b = IntOption('int', 'Test int option', multi=True) b = IntOption('int', 'Test int option', multi=True)
c = StrOption('str', 'Test string option', multi=True, properties=('force_store_value',)) 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)") 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',)) # b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
# c = StrOption('str', 'Test string option', multi=True) # c = StrOption('str', 'Test string option', multi=True)
# descr = MasterSlaves("int", "", [b, c]) # descr = Leadership("int", "", [b, c])
# api = Config(descr) # api = Config(descr)
# assert api.value.get() == {'int': ('forced', ())} # 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',)) b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
c = StrOption('str', 'Test string option', multi=True) c = StrOption('str', 'Test string option', multi=True)
descr = MasterSlaves("int", "", [b, c]) descr = Leadership("int", "", [b, c])
odr = OptionDescription('odr', '', [descr]) odr = OptionDescription('odr', '', [descr])
api = Config(odr) api = Config(odr)
compare(api.value.exportation(), (('int.int',), (None,), (tuple(),), ('forced',))) 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.setting import groups, owners
from tiramisu import ChoiceOption, BoolOption, IntOption, IPOption, NetmaskOption, \ from tiramisu import ChoiceOption, BoolOption, IntOption, IPOption, NetmaskOption, \
StrOption, OptionDescription, MasterSlaves, Config StrOption, OptionDescription, Leadership, Config
from tiramisu.error import SlaveError, PropertiesOptionError, APIError, ConfigError from tiramisu.error import LeadershipError, PropertiesOptionError, APIError, ConfigError
from tiramisu.api import TIRAMISU_VERSION from tiramisu.api import TIRAMISU_VERSION
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
@ -46,8 +46,8 @@ def make_description():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé") ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé")
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau") netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau")
master = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) leader = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = OptionDescription('interface1', '', [master]) interface1 = OptionDescription('interface1', '', [leader])
interface1.impl_set_group_type(groups.family) interface1.impl_set_group_type(groups.family)
general = OptionDescription('general', '', [numero_etab, nom_machine, general = OptionDescription('general', '', [numero_etab, nom_machine,
@ -206,59 +206,58 @@ def test_iter_not_group():
raise Exception('must raise') 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master) assert interface1.impl_get_group_type() == groups.leadership
assert interface1.impl_get_group_type() == groups.master
def test_groups_is_master(): def test_groups_is_leader():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, default_multi='value') 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) var = StrOption('var', "ip réseau autorisé", multi=True)
od2 = OptionDescription('od2', '', [var]) od2 = OptionDescription('od2', '', [var])
od1 = OptionDescription('od', '', [interface1, od2]) od1 = OptionDescription('od', '', [interface1, od2])
api = Config(od1) api = Config(od1)
assert not api.option('od2').option.ismasterslaves() assert not api.option('od2').option.isleadership()
assert api.option('masterslaves').option.ismasterslaves() assert api.option('leadership').option.isleadership()
assert not api.option('od2.var').option.ismaster() assert not api.option('od2.var').option.isleader()
assert not api.option('od2.var').option.isslave() assert not api.option('od2.var').option.isfollower()
assert api.option('masterslaves.ip_admin_eth0').option.ismulti() assert api.option('leadership.ip_admin_eth0').option.ismulti()
assert api.option('masterslaves.netmask_admin_eth0').option.ismulti() assert api.option('leadership.netmask_admin_eth0').option.ismulti()
assert not api.option('masterslaves.ip_admin_eth0').option.issubmulti() assert not api.option('leadership.ip_admin_eth0').option.issubmulti()
assert not api.option('masterslaves.netmask_admin_eth0').option.issubmulti() assert not api.option('leadership.netmask_admin_eth0').option.issubmulti()
assert api.option('masterslaves.ip_admin_eth0').option.ismaster() assert api.option('leadership.ip_admin_eth0').option.isleader()
assert not api.option('masterslaves.ip_admin_eth0').option.isslave() assert not api.option('leadership.ip_admin_eth0').option.isfollower()
assert not api.option('masterslaves.netmask_admin_eth0').option.ismaster() assert not api.option('leadership.netmask_admin_eth0').option.isleader()
assert api.option('masterslaves.netmask_admin_eth0').option.isslave() assert api.option('leadership.netmask_admin_eth0').option.isfollower()
assert api.option('masterslaves.netmask_admin_eth0').option.path() == 'masterslaves.netmask_admin_eth0' assert api.option('leadership.netmask_admin_eth0').option.path() == 'leadership.netmask_admin_eth0'
assert api.option('masterslaves.netmask_admin_eth0').option.defaultmulti() == 'value' assert api.option('leadership.netmask_admin_eth0').option.defaultmulti() == 'value'
if TIRAMISU_VERSION != 2: 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = 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)") 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = 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]) od = OptionDescription('root', '', [interface1])
Config(od) 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = 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]) od = OptionDescription('root', '', [interface1])
api = Config(od) api = Config(od)
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []} 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]} 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',)) 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',)) 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]) od = OptionDescription('root', '', [interface1])
api = Config(od) api = Config(od)
api.property.read_write() 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()") 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) 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',)) 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]) od = OptionDescription('root', '', [interface1])
api = Config(od) api = Config(od)
api.property.read_write() 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 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = 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]) od_ = OptionDescription('root', '', [interface1])
api = Config(od_) api = Config(od_)
api.property.read_write() api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() 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.ip_admin_eth0').value.set(['192.168.1.1'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset() 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = 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]) od_ = OptionDescription('root', '', [interface1])
api = Config(od_) api = Config(od_)
api.property.read_write() api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) 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.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() 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)") raises(IndexError, "api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)")
def test_groups_with_master_hidden_in_config3(): def test_groups_with_leader_hidden_in_config3():
#if master is hidden, slave are hidden too #if leader is hidden, follower are hidden too
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',)) 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) 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]) od = OptionDescription('root', '', [interface1])
#interface1.impl_set_group_type(groups.master)
api = Config(od) api = Config(od)
api.property.read_write() api.property.read_write()
api.permissive.set(frozenset(['hidden'])) api.permissive.set(frozenset(['hidden']))
@ -364,11 +362,10 @@ def test_allowed_groups():
raises(ValueError, "interface1.impl_set_group_type('toto')") 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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')") 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
subgroup = OptionDescription("subgroup", '', []) 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(): def test_group_always_has_multis():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau") 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
owner = api.owner.get() 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() 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"]) 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)") 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
owner = api.owner.get() 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() 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"]) api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner assert api.option('ip_admin_eth0.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() == [] 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']) 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']) 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']) 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) 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])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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) 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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.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.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')
@ -517,11 +510,10 @@ def test_values_with_master_and_slaves_slave():
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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' 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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.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', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).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', 0).value.get() == '255.255.255.0'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).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) 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() == [] 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = 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]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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',)))) 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -649,11 +638,10 @@ def test_multi_non_valid_value():
raises(ValueError, "api.option('ip_admin_eth0').value.set([1])") 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) 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) 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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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'] 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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')))) 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -699,7 +685,7 @@ def test_groups_with_master_importation():
def test_wrong_index(): def test_wrong_index():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) 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) 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]) od1 = OptionDescription('od', '', [interface1])
maconfig = OptionDescription('toto', '', [od1]) maconfig = OptionDescription('toto', '', [od1])
api = Config(maconfig) api = Config(maconfig)
@ -713,57 +699,57 @@ def test_wrong_index():
raises(APIError, "api.option('od', 0).option.get()") raises(APIError, "api.option('od', 0).option.get()")
def test_without_master_or_slave(): def test_without_leader_or_follower():
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [])") raises(ValueError, "Leadership('ip_admin_eth0', '', [])")
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) 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 #empty optiondescription is allowed
OptionDescription('ip_admin_eth0', '', []) 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é") 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) 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) 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") 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']) 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) 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']) 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 = NetmaskOption('netmask_admin_eth1', "masque du sous-réseau", multi=True)
netmask_admin_eth1.impl_add_consistency('ip_netmask', ip_admin_eth0) 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]) od1 = OptionDescription('od', '', [interface0, interface1])
maconfig = OptionDescription('toto', '', [od1]) maconfig = OptionDescription('toto', '', [od1])
raises(ConfigError, "Config(maconfig)") 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']) 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) 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']) 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 = NetmaskOption('netmask_admin_eth1', "masque du sous-réseau", multi=True)
netmask_admin_eth1.impl_add_consistency('not_equal', netmask_admin_eth0) 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]) od1 = OptionDescription('od', '', [interface0, interface1])
maconfig = OptionDescription('toto', '', [od1]) maconfig = OptionDescription('toto', '', [od1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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']) 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',)) 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]) od1 = OptionDescription('od', '', [interface0])
maconfig = OptionDescription('toto', '', [od1]) maconfig = OptionDescription('toto', '', [od1])
raises(ConfigError, "Config(maconfig)") raises(ConfigError, "Config(maconfig)")

View File

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

View File

@ -4,9 +4,9 @@ do_autopath()
from tiramisu.setting import groups, owners from tiramisu.setting import groups, owners
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, BoolOption, ChoiceOption, \ from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, BoolOption, ChoiceOption, \
IPOption, OptionDescription, MasterSlaves, Config, GroupConfig, MetaConfig, \ IPOption, OptionDescription, Leadership, Config, GroupConfig, MetaConfig, \
Params, ParamOption, ParamValue 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 from tiramisu.storage import list_sessions
@ -384,10 +384,10 @@ def test_meta_unconsistent():
raises(ValueError, "MetaConfig([conf3, conf4])") raises(ValueError, "MetaConfig([conf3, conf4])")
def test_meta_master_slaves(): def test_meta_leadership():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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 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']) 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) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') conf2 = Config(od, session_id='conf2')
meta = MetaConfig([conf1, conf2]) meta = MetaConfig([conf1, conf2])
meta.owner.set(owners.meta1) meta.owner.set(owners.meta1)
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() 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']) 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 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(): def test_meta_force_default():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') conf2 = Config(od, session_id='conf2')
@ -535,7 +535,7 @@ def test_meta_force_default():
def test_meta_force_dont_change_value(): def test_meta_force_dont_change_value():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') conf2 = Config(od, session_id='conf2')
@ -562,7 +562,7 @@ def test_meta_force_dont_change_value():
def test_meta_force_default_if_same(): def test_meta_force_default_if_same():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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(): def test_meta_force_default_if_same_and_dont_change():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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(): def test_meta_force_default_and_dont_change():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='rconf1') conf1 = Config(od, session_id='rconf1')
conf2 = Config(od, session_id='rconf2') 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']) 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 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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']) 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 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, callback=raise_exception)
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') conf2 = Config(od, session_id='conf2')
@ -728,12 +728,12 @@ def test_meta_callback():
meta.option('val4').value.reset() meta.option('val4').value.reset()
def test_meta_callback_slave(): def test_meta_callback_follower():
val = StrOption('val', "", default='val') val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(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))) 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))) 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]) od = OptionDescription('root', '', [interface1])
maconfig = OptionDescription('rootconfig', '', [val, interface1]) maconfig = OptionDescription('rootconfig', '', [val, interface1])
cfg = Config(maconfig, session_id='cfg1') cfg = Config(maconfig, session_id='cfg1')
@ -774,7 +774,7 @@ def test_meta_callback_slave():
def test_meta_reset(): def test_meta_reset():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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.setting import groups, owners
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, \ from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, \
OptionDescription, MasterSlaves, Config, GroupConfig, MixConfig, \ OptionDescription, Leadership, Config, GroupConfig, MixConfig, \
Params, ParamOption, ParamValue 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 from tiramisu.storage import list_sessions
owners.addowner('mix1') owners.addowner('mix1')
@ -311,10 +311,10 @@ def test_mix_unconsistent():
MixConfig(od2, [conf3, conf4]) MixConfig(od2, [conf3, conf4])
def test_mix_master_slaves(): def test_mix_leadership():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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 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']) 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) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') conf2 = Config(od, session_id='conf2')
mix = MixConfig(od, [conf1, conf2]) mix = MixConfig(od, [conf1, conf2])
mix.owner.set(owners.mix1) mix.owner.set(owners.mix1)
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() 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']) 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 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(): def test_mix_force_default():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') conf2 = Config(od, session_id='conf2')
@ -462,7 +462,7 @@ def test_mix_force_default():
def test_mix_force_dont_change_value(): def test_mix_force_dont_change_value():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') conf2 = Config(od, session_id='conf2')
@ -489,7 +489,7 @@ def test_mix_force_dont_change_value():
def test_mix_force_default_if_same(): def test_mix_force_default_if_same():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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(): def test_mix_force_default_if_same_and_dont_change():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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(): def test_mix_force_default_and_dont_change():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='rconf1') conf1 = Config(od, session_id='rconf1')
conf2 = Config(od, session_id='rconf2') 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']) 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 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') 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']) 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 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, callback=raise_exception)
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0) 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]) od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1') conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2') conf2 = Config(od, session_id='conf2')
@ -635,12 +635,12 @@ def test_mix_callback():
mix.option('val4').value.reset() mix.option('val4').value.reset()
def test_mix_callback_slave(): def test_mix_callback_follower():
val = StrOption('val', "", default='val') val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(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))) 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))) 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]) od = OptionDescription('root', '', [interface1])
maconfig = OptionDescription('rootconfig', '', [val, interface1]) maconfig = OptionDescription('rootconfig', '', [val, interface1])
cfg = Config(maconfig, session_id='cfg1') cfg = Config(maconfig, session_id='cfg1')
@ -681,15 +681,15 @@ def test_mix_callback_slave():
def test_meta_reset(): def test_meta_reset():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od0 = OptionDescription('root', '', [interface1])
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od1 = OptionDescription('root', '', [interface1])
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) 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]) od2 = OptionDescription('root', '', [interface1])
conf1 = Config(od0, session_id='conf1') conf1 = Config(od0, session_id='conf1')
conf2 = Config(od1, session_id='conf2') 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)") raises(ValueError, "od1.impl_set_group_type(groups.notfamily)")
def test_optiondescription_group_masterslave(): def test_optiondescription_group_leadership():
i = IntOption('test', '') i = IntOption('test', '')
od1 = OptionDescription('od', '', [i]) 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.config import KernelConfig
from tiramisu.setting import groups, owners from tiramisu.setting import groups, owners
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, MasterSlaves, \ StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, Leadership, \
undefined, Params, ParamOption, ParamValue, ParamContext undefined, Params, ParamOption, ParamValue, ParamContext
from tiramisu.api import TIRAMISU_VERSION 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.i18n import _
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
@ -502,11 +502,10 @@ def test_callback_multi_callback():
assert api.option('val1.val1').value.get() == ['val1', 'val'] 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) val1 = StrOption('val1', "", multi=True, callback=return_val)
val2 = StrOption('val2', "", multi=True) val2 = StrOption('val2', "", multi=True)
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -517,11 +516,10 @@ def test_callback_master_and_slaves_master():
assert api.option('val1.val2', 1).value.get() == None assert api.option('val1.val2', 1).value.get() == None
def test_callback_slave(): def test_callback_follower():
val1 = StrOption('val1', "", multi=True) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value3, callback_params=Params(ParamValue(['string', 'new']))) val2 = StrOption('val2', "", multi=True, callback=return_value3, callback_params=Params(ParamValue(['string', 'new'])))
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -541,13 +539,12 @@ def test_callback_slave():
assert api.option('val1.val2', 3).value.get() == None 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) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, default_multi='val2') val2 = StrOption('val2', "", multi=True, default_multi='val2')
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(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))) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4]) interface1 = Leadership('val1', '', [val1, val2, val3, val4])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -557,13 +554,12 @@ def test_callback_master_and_slaves_master2():
assert api.option('val1.val2', 0).value.get() == 'val2' 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') val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',)) val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',))
val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',)) val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
val4 = StrOption('val4', "", 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 = Leadership('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [val, interface1]) maconfig = OptionDescription('rootconfig', '', [val, interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_only() 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()") 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')
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',)) 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',)) 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',)) 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 = Leadership('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1]) maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_only() 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'] 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')
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',)) 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',)) 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',)) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
interface1 = MasterSlaves('val1', '', [val1, val3, val4]) interface1 = Leadership('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1]) maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_only() 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'] 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') val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',)) val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',))
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), 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',)) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
interface1 = MasterSlaves('val1', '', [val1, val3, val4]) interface1 = Leadership('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [val, interface1]) maconfig = OptionDescription('rootconfig', '', [val, interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_only() 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' 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')) val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty'))
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',)) val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',))
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(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))) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4]) interface1 = Leadership('val1', '', [val1, val2, val3, val4])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
assert list(api.value.mandatory()) == ['val1.val1'] 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',)) val1 = StrOption('val1', "", ['val1'], multi=True, properties=('mandatory',))
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert', '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))) 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))) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4]) interface1 = Leadership('val1', '', [val1, val2, val3, val4])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -688,7 +679,7 @@ def test_callback_master_and_slaves_master4():
assert list(api.value.mandatory()) == [] 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 #default value
val1 = IPOption('val1', "", ['192.168.0.1'], multi=True, properties=('mandatory',)) val1 = IPOption('val1', "", ['192.168.0.1'], multi=True, properties=('mandatory',))
val2 = NetmaskOption('val2', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory')) val2 = 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',)) val3 = IPOption('val3', "", multi=True, properties=('mandatory',))
val4 = NetmaskOption('val4', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory')) val4 = NetmaskOption('val4', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
val4.impl_add_consistency('ip_netmask', val3) val4.impl_add_consistency('ip_netmask', val3)
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
interface2 = MasterSlaves('val3', '', [val3, val4]) interface2 = Leadership('val3', '', [val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1, interface2]) maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -712,7 +703,7 @@ def test_consistency_master_and_slaves_master_mandatory_transitive():
assert list(api.value.mandatory()) == [] 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 #no value
val1 = IPOption('val1', "", multi=True, properties=('mandatory',)) val1 = IPOption('val1', "", multi=True, properties=('mandatory',))
val2 = NetmaskOption('val2', "", multi=True, default_multi='255.255.255.0', properties=('disabled', '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',)) 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 = NetmaskOption('val4', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
val4.impl_add_consistency('ip_netmask', val3, transitive=False) val4.impl_add_consistency('ip_netmask', val3, transitive=False)
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
interface2 = MasterSlaves('val3', '', [val3, val4]) interface2 = Leadership('val3', '', [val3, val4])
#interface1.impl_set_group_type(groups.master)
#interface2.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1, interface2]) maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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"] 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) val1 = StrOption('val1', "", multi=True, callback=return_list)
val2 = StrOption('val2', "", multi=True) val2 = StrOption('val2', "", multi=True)
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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 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) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_list) val2 = StrOption('val2', "", multi=True, callback=return_list)
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
assert api.option('val1.val1').value.get() == [] assert api.option('val1.val1').value.get() == []
api.option('val1.val1').value.set(['val1']) 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) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_val) val2 = StrOption('val2', "", multi=True, callback=return_val)
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -813,21 +799,20 @@ def test_callback_master_and_slaves_slave():
assert api.option('val1.val2', 2).value.get() == 'val' 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) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_val) val2 = StrOption('val2', "", multi=True, callback=return_val)
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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) val3 = StrOption('val3', "", multi=True)
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3))) val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
val2 = StrOption('val2', "", multi=True, callback=return_val) val2 = StrOption('val2', "", multi=True, callback=return_val)
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val3]) maconfig = OptionDescription('rootconfig', '', [interface1, val3])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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', 0).value.get() == 'val'
assert api.option('val1.val2', 1).value.get() == 'val' assert api.option('val1.val2', 1).value.get() == 'val'
assert api.option('val1.val1').value.get() == ['val1', 'val2'] 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', 0).value.set('val1')
api.option('val1.val2', 1).value.set('val2') api.option('val1.val2', 1).value.set('val2')
api.option('val3').value.set(['val1']) api.option('val3').value.set(['val1'])
assert api.option('val1.val1').value.get() == ['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']) api.option('val3').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val2', 0).value.get() == 'val1' 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' 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 #properties must be transitive
val1 = StrOption('val1', "", ['val1'], multi=True, properties=('disabled',)) val1 = StrOption('val1', "", ['val1'], multi=True, properties=('disabled',))
val2 = StrOption('val2', "", multi=True) val2 = StrOption('val2', "", multi=True)
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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()") 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',)) val0 = StrOption('val0', "", multi=True, properties=('disabled',))
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0))) val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0)))
val2 = StrOption('val2', "", multi=True) val2 = StrOption('val2', "", multi=True)
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1, val0]) maconfig = OptionDescription('rootconfig', '', [interface1, val0])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -891,11 +874,10 @@ def test_callback_master_and_slaves_master_callback_disabled():
assert api.option('val1.val1').value.get() == [] 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) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, properties=('disabled',)) val2 = StrOption('val2', "", multi=True, properties=('disabled',))
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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' 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',)) val0 = StrOption('val0', "", multi=True, properties=('disabled',))
val1 = StrOption('val1', "", multi=True) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0))) val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0)))
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1, val0]) maconfig = OptionDescription('rootconfig', '', [interface1, val0])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -939,28 +920,27 @@ def test_callback_master_and_slaves_slave_callback_disabled():
api.option('val1.val1').value.pop(1) 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']) val4 = StrOption('val4', '', multi=True, default=['val10', 'val11'])
val1 = StrOption('val1', "", multi=True) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1))) 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'))) 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))) 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))) val6 = StrOption('val6', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val5)))
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val5, val6]) interface1 = Leadership('val1', '', [val1, val2, val3, val5, val6])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1, val4]) maconfig = OptionDescription('rootconfig', '', [interface1, val4])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
api.option('val4').value.get() == ['val10', 'val11'] api.option('val4').value.get() == ['val10', 'val11']
assert api.option('val1.val1').value.get() == [] assert api.option('val1.val1').value.get() == []
#raises(SlaveError, "cfg.val1.val1") #raises(LeadershipError, "cfg.val1.val1")
#raises(SlaveError, "cfg.val1.val2") #raises(LeadershipError, "cfg.val1.val2")
#raises(SlaveError, "cfg.val1.val3") #raises(LeadershipError, "cfg.val1.val3")
#raises(SlaveError, "cfg.val1.val5") #raises(LeadershipError, "cfg.val1.val5")
#raises(SlaveError, "cfg.val1.val6") #raises(LeadershipError, "cfg.val1.val6")
# #
#default calculation has greater length #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']) api.option('val1.val1').value.set(['val1', 'val2'])
assert api.option('val1.val1').value.get() == ['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.val2', 1).value.get() == 'val2'
assert api.option('val1.val3', 0).value.get() == 'yes' assert api.option('val1.val3', 0).value.get() == 'yes'
assert api.option('val1.val3', 1).value.get() == 'yes' assert api.option('val1.val3', 1).value.get() == 'yes'
raises(SlaveError, "api.option('val1.val5', 0).value.get()") raises(LeadershipError, "api.option('val1.val5', 0).value.get()")
raises(SlaveError, "api.option('val1.val5', 1).value.get()") raises(LeadershipError, "api.option('val1.val5', 1).value.get()")
raises(SlaveError, "api.option('val1.val6', 0).value.get()") raises(LeadershipError, "api.option('val1.val6', 0).value.get()")
raises(SlaveError, "api.option('val1.val6', 1).value.get()") raises(LeadershipError, "api.option('val1.val6', 1).value.get()")
# #
api.option('val1.val1').value.set(['val1', 'val2', 'val3']) api.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val1').value.get() == ['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', 0).value.get() == 'yes'
assert api.option('val1.val3', 1).value.get() == 'yes' assert api.option('val1.val3', 1).value.get() == 'yes'
assert api.option('val1.val3', 2).value.get() == 'yes' assert api.option('val1.val3', 2).value.get() == 'yes'
raises(SlaveError, "api.option('val1.val5', 2).value.get()") raises(LeadershipError, "api.option('val1.val5', 2).value.get()")
raises(SlaveError, "api.option('val1.val6', 2).value.get()") raises(LeadershipError, "api.option('val1.val6', 2).value.get()")
# #
api.option('val1.val1').value.pop(2) api.option('val1.val1').value.pop(2)
assert api.option('val1.val1').value.get() == ['val1', 'val2'] 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' 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) val2 = StrOption('val2', "", multi=True, callback=return_value)
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2))) 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(): def test_callback_different_type():
@ -1022,8 +1002,7 @@ def test_callback_different_type():
val_ = IntOption('val_', "", default=3) val_ = IntOption('val_', "", default=3)
val1 = IntOption('val1', "", multi=True) val1 = IntOption('val1', "", multi=True)
val2 = IntOption('val2', "", multi=True, callback=return_calc, callback_params=Params((ParamOption(val), ParamOption(val1)), {'k': ParamOption(val_)})) val2 = IntOption('val2', "", multi=True, callback=return_calc, callback_params=Params((ParamOption(val), ParamOption(val1)), {'k': ParamOption(val_)}))
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1, val, val_]) maconfig = OptionDescription('rootconfig', '', [interface1, val, val_])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -1181,11 +1160,10 @@ def test_callback_multi_list_params_key():
assert api.option('val2.val2').value.get() == ['val', 'val'] assert api.option('val2.val2').value.get() == ['val', 'val']
def test_masterslaves_callback_description(): def test_leadership_callback_description():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(st1))) st2 = StrOption('st2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(st1)))
stm = MasterSlaves('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
#stm.impl_set_group_type(groups.master)
st = OptionDescription('st', '', [stm]) st = OptionDescription('st', '', [stm])
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])

View File

@ -5,7 +5,7 @@ from py.test import raises
from tiramisu.setting import owners, groups from tiramisu.setting import owners, groups
from tiramisu import IPOption, NetworkOption, NetmaskOption, IntOption,\ from tiramisu import IPOption, NetworkOption, NetmaskOption, IntOption,\
BroadcastOption, StrOption, SymLinkOption, OptionDescription, submulti, MasterSlaves,\ BroadcastOption, StrOption, SymLinkOption, OptionDescription, submulti, Leadership,\
Config, undefined, Params, ParamOption Config, undefined, Params, ParamOption
from tiramisu.error import ConfigError, ValueWarning, PropertiesOptionError from tiramisu.error import ConfigError, ValueWarning, PropertiesOptionError
from tiramisu.api import TIRAMISU_VERSION from tiramisu.api import TIRAMISU_VERSION
@ -264,7 +264,7 @@ def test_consistency_mix():
b = IntOption('b', '', multi=True) b = IntOption('b', '', multi=True)
c = IntOption('c', '', multi=True) c = IntOption('c', '', multi=True)
d = IntOption('d', '', multi=True) d = IntOption('d', '', multi=True)
od = MasterSlaves('c', '', [c, d]) od = Leadership('c', '', [c, d])
od2 = OptionDescription('a', '', [b, od]) od2 = OptionDescription('a', '', [b, od])
c.impl_add_consistency('not_equal', b, d) c.impl_add_consistency('not_equal', b, d)
cfg = Config(od2) cfg = Config(od2)
@ -295,10 +295,10 @@ def test_consistency_not_equal_default_submulti():
raises(ConfigError, "a.impl_add_consistency('not_equal', b)") 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) a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True) b = IntOption('b', '', multi=True)
od = MasterSlaves('a', '', [a, b]) od = Leadership('a', '', [a, b])
od2 = OptionDescription('b', '', [od]) od2 = OptionDescription('b', '', [od])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od2) api = Config(od2)
@ -313,27 +313,27 @@ def test_consistency_not_equal_masterslave():
api.value.dict() api.value.dict()
def test_consistency_not_equal_masterslave_error_multi1(): def test_consistency_not_equal_leadership_error_multi1():
a = IPOption('a', '', multi=True) a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
c = NetmaskOption('c', '', multi=True) c = NetmaskOption('c', '', multi=True)
od = MasterSlaves('a', '', [a, b]) od = Leadership('a', '', [a, b])
od2 = OptionDescription('b', '', [od, c]) od2 = OptionDescription('b', '', [od, c])
c.impl_add_consistency('ip_netmask', a) c.impl_add_consistency('ip_netmask', a)
raises(ConfigError, "Config(od2)") 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) a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
c = IPOption('c', '', multi=True) c = IPOption('c', '', multi=True)
od = MasterSlaves('a', '', [a, b]) od = Leadership('a', '', [a, b])
od2 = OptionDescription('b', '', [od, c]) od2 = OptionDescription('b', '', [od, c])
b.impl_add_consistency('ip_netmask', c) b.impl_add_consistency('ip_netmask', c)
raises(ConfigError, "Config(od2)") 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) a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
od = OptionDescription('a', '', [a, b]) od = OptionDescription('a', '', [a, b])
@ -342,34 +342,34 @@ def test_consistency_ip_netmask_masterslave_error_not_master():
raises(ConfigError, "Config(od2)") 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) a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
c = IPOption('c', '', multi=True) c = IPOption('c', '', multi=True)
d = NetmaskOption('d', '', multi=True) d = NetmaskOption('d', '', multi=True)
od = MasterSlaves('a', '', [a, b]) od = Leadership('a', '', [a, b])
od2 = OptionDescription('c', '', [c, d]) od2 = OptionDescription('c', '', [c, d])
od3 = OptionDescription('b', '', [od, od2]) od3 = OptionDescription('b', '', [od, od2])
d.impl_add_consistency('ip_netmask', a) d.impl_add_consistency('ip_netmask', a)
raises(ConfigError, "Config(od3)") 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) a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
c = IPOption('c', '', multi=True) c = IPOption('c', '', multi=True)
d = NetmaskOption('d', '', multi=True) d = NetmaskOption('d', '', multi=True)
od = MasterSlaves('a', '', [a, b]) od = Leadership('a', '', [a, b])
od2 = MasterSlaves('c', '', [c, d]) od2 = Leadership('c', '', [c, d])
od3 = OptionDescription('b', '', [od, od2]) od3 = OptionDescription('b', '', [od, od2])
d.impl_add_consistency('ip_netmask', a) d.impl_add_consistency('ip_netmask', a)
raises(ConfigError, "Config(od2)") raises(ConfigError, "Config(od2)")
def test_consistency_not_equal_masterslaves_default(): def test_consistency_not_equal_leadership_default():
a = IntOption('a', '', multi=True) a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True, default_multi=1) b = IntOption('b', '', multi=True, default_multi=1)
od = MasterSlaves('a', '', [a, b]) od = Leadership('a', '', [a, b])
od2 = OptionDescription('a', '', [od]) od2 = OptionDescription('a', '', [od])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od2) api = Config(od2)
@ -423,10 +423,10 @@ def test_consistency_not_equal_multi_default2():
a.impl_add_consistency('not_equal', b) 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]) a = IntOption('a', '', multi=True, default=[2, 1])
b = IntOption('b', '', multi=True, default_multi=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) a.impl_add_consistency('not_equal', b)
od2 = OptionDescription('a', '', [od]) od2 = OptionDescription('a', '', [od])
api = Config(od2) api = Config(od2)
@ -586,7 +586,7 @@ def test_consistency_ip_netmask_error_multi():
def test_consistency_ip_netmask_multi(): def test_consistency_ip_netmask_multi():
a = IPOption('a', '', multi=True) a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
od = MasterSlaves('a', '', [a, b]) od = Leadership('a', '', [a, b])
b.impl_add_consistency('ip_netmask', a) b.impl_add_consistency('ip_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) api = Config(od2)
@ -606,7 +606,7 @@ def test_consistency_ip_netmask_multi():
def test_consistency_network_netmask_multi(): def test_consistency_network_netmask_multi():
a = NetworkOption('a', '', multi=True) a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
od = MasterSlaves('a', '', [a, b]) od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) 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'])") 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',)) 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',)) 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]) od2 = OptionDescription('od2', '', [od])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
api = Config(od2) 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' 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',)) a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', default_multi=u'255.255.255.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])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) api = Config(od2)
@ -657,19 +657,19 @@ def return_netmask(*args, **kwargs):
return u'255.255.255.0' return u'255.255.255.0'
def return_netmask2(master): def return_netmask2(leader):
if master is not None: if leader is not None:
if master.endswith('2.1'): if leader.endswith('2.1'):
return u'255.255.255.0' 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.255'
return u'255.255.255.0' 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',)) a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', callback=return_netmask, 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) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) 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']) 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',)) a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', callback=return_netmask2, callback_params=Params(ParamOption(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) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) 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') 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) a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
od = MasterSlaves('a', '', [a, b]) od = Leadership('a', '', [a, b])
b.impl_add_consistency('ip_netmask', a) b.impl_add_consistency('ip_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) 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']) 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) a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
od = MasterSlaves('a', '', [a, b]) od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) api = Config(od2)
@ -749,7 +749,7 @@ def test_consistency_broadcast():
a = NetworkOption('a', '', multi=True) a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', 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) b.impl_add_consistency('network_netmask', a)
c.impl_add_consistency('broadcast', a, b) c.impl_add_consistency('broadcast', a, b)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
@ -776,7 +776,7 @@ def test_consistency_broadcast_error():
a = NetworkOption('a', '', multi=True) a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', multi=True) c = BroadcastOption('c', '', multi=True)
od = MasterSlaves('a', '', [a, b, c]) od = Leadership('a', '', [a, b, c])
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
c.impl_add_consistency('broadcast', a) c.impl_add_consistency('broadcast', a)
@ -825,7 +825,7 @@ def test_consistency_not_all():
a = NetworkOption('a', '', multi=True) a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', 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) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) api = Config(od2)
@ -991,7 +991,7 @@ def test_consistency_warnings_error():
def test_consistency_network_netmask_mandatory(): def test_consistency_network_netmask_mandatory():
a = NetworkOption('a', '', multi=True, properties=('mandatory',), default=[u'0.0.0.0']) 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') 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) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) api = Config(od2)

View File

@ -7,7 +7,7 @@ from py.test import raises
from tiramisu.setting import owners from tiramisu.setting import owners
from tiramisu.error import PropertiesOptionError, ConfigError from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu import IntOption, FloatOption, StrOption, ChoiceOption, \ from tiramisu import IntOption, FloatOption, StrOption, ChoiceOption, \
BoolOption, OptionDescription, MasterSlaves, Config, undefined BoolOption, OptionDescription, Leadership, Config, undefined
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
@ -112,31 +112,31 @@ def test_force_default_on_freeze_multi():
api.option('dummy1').property.add('frozen') 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',)) dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_default_on_freeze',))
dummy2 = BoolOption('dummy2', 'Test string option', multi=True) dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = MasterSlaves("dummy1", "", [dummy1, dummy2]) descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr]) descr = OptionDescription("root", "", [descr])
raises(ConfigError, "Config(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')) dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_default_on_freeze', 'frozen'))
dummy2 = BoolOption('dummy2', 'Test string option', multi=True) dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = MasterSlaves("dummy1", "", [dummy1, dummy2]) descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr]) descr = OptionDescription("root", "", [descr])
api = Config(descr) api = Config(descr)
raises(ConfigError, "api.option('dummy1.dummy1').property.pop('frozen')") 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) dummy1 = BoolOption('dummy1', 'Test int option', multi=True)
dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',)) 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]) descr = OptionDescription("root", "", [descr])
api = Config(descr) api = Config(descr)
api.property.read_write() api.property.read_write()
owners.addowner("frozenmultislave2") owners.addowner("frozenmultifollower2")
api.option('dummy1.dummy1').value.set([True]) api.option('dummy1.dummy1').value.set([True])
api.option('dummy1.dummy2', 0).value.set(False) api.option('dummy1.dummy2', 0).value.set(False)
assert api.option('dummy1.dummy1').value.get() == [True] 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.dummy2', 0).value.get() == None
assert api.option('dummy1.dummy1').owner.get() == 'user' assert api.option('dummy1.dummy1').owner.get() == 'user'
assert api.option('dummy1.dummy2', 0).owner.isdefault() 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.dummy2').property.pop('frozen')
api.option('dummy1.dummy1').value.set([True, True]) 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.setting import owners, groups
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ 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.error import ConfigError, ConstError, PropertiesOptionError, APIError
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
@ -165,10 +165,10 @@ def test_setowner_symlinkoption():
raises(ConfigError, "api.option('tiramisu.symdummy').owner.set('user')") 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) b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', multi=True) c = StrOption('str', 'Test string option', multi=True)
descr = MasterSlaves("int", "", [b, c]) descr = Leadership("int", "", [b, c])
od = OptionDescription('od', '', [descr]) od = OptionDescription('od', '', [descr])
api = Config(od) api = Config(od)
raises(ConfigError, "api.option('int.str', 0).owner.set('user')") 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.error import display_list, ConfigError
from tiramisu.setting import owners, groups from tiramisu.setting import owners, groups
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, MasterSlaves, Config, undefined StrOption, OptionDescription, Leadership, Config, undefined
from tiramisu.error import PropertiesOptionError from tiramisu.error import PropertiesOptionError
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
@ -335,25 +335,25 @@ def test_multi_with_requires_that_is_multi_inverse():
raises(ValueError, "Config(descr)") 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) 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) 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]) od = OptionDescription('root', '', [descr])
Config(od) 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) b = IntOption('int', 'Test int option', multi=True)
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], 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) b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', 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) 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]) descr2 = OptionDescription('od', '', [descr])
api = Config(descr2) api = Config(descr2)
api.property.read_write() 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()") 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) b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', 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) 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]) descr2 = OptionDescription('od', '', [descr])
api = Config(descr2) api = Config(descr2)
api.property.read_write() 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()") 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) 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) c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
descr1 = MasterSlaves("int", "", [b, c]) descr1 = Leadership("int", "", [b, c])
#descr1.impl_set_group_type(groups.master)
d = IntOption('int1', 'Test int option', default=[0], multi=True) 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) e = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
descr2 = MasterSlaves("int1", "", [d, e]) descr2 = Leadership("int1", "", [d, e])
#descr2.impl_set_group_type(groups.master)
descr3 = OptionDescription('val', '', [descr1, descr2]) descr3 = OptionDescription('val', '', [descr1, descr2])
descr3 descr3
raises(ValueError, "Config(descr3)") raises(ValueError, "Config(descr3)")

View File

@ -4,7 +4,7 @@ do_autopath()
import warnings import warnings
from py.test import raises 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.setting import groups
from tiramisu.error import ValueWarning, ConfigError from tiramisu.error import ValueWarning, ConfigError
from tiramisu.i18n import _ from tiramisu.i18n import _
@ -153,33 +153,30 @@ def test_validator_params_value_values_index():
api.option('opt1').value.set(['val1', 'val2']) 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values_index)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] 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') 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values_index) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values_index)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] 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, multi=True,
validator=value_empty, validator=value_empty,
validator_params=Params(ParamOption(v))) validator_params=Params(ParamOption(v)))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [v, interface1]) root = OptionDescription('root', '', [v, interface1])
api = Config(root) api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] 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, multi=True,
validator=value_values_auto, validator=value_values_auto,
validator_params=Params(kwargs={'auto': ParamOption(v)})) validator_params=Params(kwargs={'auto': ParamOption(v)}))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [v, interface1]) root = OptionDescription('root', '', [v, interface1])
api = Config(root) api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] 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, multi=True,
validator=value_values_auto2, validator=value_values_auto2,
validator_params=Params(kwargs={'values': ParamOption(ip_admin_eth0)})) validator_params=Params(kwargs={'values': ParamOption(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])
#interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
@ -268,8 +261,7 @@ def test_validator_params_value_values_kwargs2():
multi=True, multi=True,
validator=value_values_index2, validator=value_values_index2,
validator_params=Params(ParamValue(['val1']), {'index': ParamOption(ip_admin_eth0)})) validator_params=Params(ParamValue(['val1']), {'index': ParamOption(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])
#interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] 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, multi=True,
validator=value_values_index2, validator=value_values_index2,
validator_params=Params(kwargs={'index': ParamOption(ip_admin_eth0)})) validator_params=Params(kwargs={'index': ParamOption(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])
#interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
@ -439,14 +430,13 @@ def test_validator_warning_disabled():
assert len(w) == 1 assert len(w) == 1
def test_validator_warning_master_slave(): def test_validator_warning_leadership():
display_name_ip = "ip reseau autorise" display_name_ip = "ip reseau autorise"
display_name_netmask = "masque du sous-reseau" display_name_netmask = "masque du sous-reseau"
ip_admin_eth0 = StrOption('ip_admin_eth0', display_name_ip, multi=True, validator=return_false, warnings_only=True) ip_admin_eth0 = StrOption('ip_admin_eth0', display_name_ip, multi=True, validator=return_false, warnings_only=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', display_name_netmask, multi=True, validator=return_if_val, 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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master) assert interface1.impl_get_group_type() == groups.leadership
assert interface1.impl_get_group_type() == groups.master
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) api = Config(root)
warnings.simplefilter("always", ValueWarning) 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') 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) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
"masque du sous-reseau", "masque du sous-reseau",
multi=True, multi=True,
validator=return_true, validator=return_true,
validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)})) validator_params=Params(kwargs={'param': ParamOption(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])
#interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) api = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] 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 from tiramisu import setting
setting.expires_time = 1 setting.expires_time = 1
from tiramisu import IPOption, OptionDescription, BoolOption, IntOption, StrOption, \ from tiramisu import IPOption, OptionDescription, BoolOption, IntOption, StrOption, \
MasterSlaves, Config Leadership, Config
from tiramisu.error import PropertiesOptionError, RequirementError from tiramisu.error import PropertiesOptionError, RequirementError
from py.test import raises from py.test import raises
from tiramisu.storage import list_sessions, delete_session from tiramisu.storage import list_sessions, delete_session
@ -956,11 +956,11 @@ def test_properties_conflict():
raises(ValueError, "od1 = OptionDescription('service', '', [a], properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])") raises(ValueError, "od1 = OptionDescription('service', '', [a], properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
def test_master_slave_requires(): def test_leadership_requires():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}]) requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
interface1 = 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]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -1006,46 +1006,46 @@ def test_master_slave_requires():
del ret['ip_admin_eth0.netmask_admin_eth0'] 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 = StrOption('ip_admin_eth0', "ip réseau autorisé")
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}]) 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) 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 = StrOption('ip_admin', "ip réseau autorisé")
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}]) requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
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 = StrOption('ip_admin', "ip réseau autorisé")
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}]) 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, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}]) requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
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 = StrOption('ip_admin', "ip réseau autorisé")
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}]) requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
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'}]) 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) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}]) requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = 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]) maconfig = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -1068,11 +1068,11 @@ def test_master_slave_requires_master():
assert api.value.dict() == {'activate': False} 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) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = 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'}]) requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
maconfig = OptionDescription('toto', '', [activate, interface1]) maconfig = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) api = Config(maconfig)
@ -1096,13 +1096,12 @@ def test_master_slave_requires_masterslaves():
assert api.value.dict() == {'activate': False} 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) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}]) requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [activate, interface1]) maconfig = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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] assert v[1][key][i] == val2[idx][1][key][i]
else: else:
assert v[1] == val2[idx][1] assert v[1] == val2[idx][1]
elif attr == '_master_slaves': elif attr == '_leadership':
assert val1._p_._sm_getmaster().impl_getname() == val2._p_._sm_getmaster().impl_getname() 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_getslaves()] sval1 = [opt.impl_getname() for opt in val1._p_._sm_get_followers()]
sval2 = [opt.impl_getname() for opt in val2._p_._sm_getslaves()] sval2 = [opt.impl_getname() for opt in val2._p_._sm_get_followers()]
assert sval1 == sval2 assert sval1 == sval2
elif attr == '_subdyn': elif attr == '_subdyn':
try: try:
@ -124,13 +124,13 @@ def _diff_opt(opt1, opt2):
lst1 = [] lst1 = []
lst2 = [] lst2 = []
for idx, val in enumerate(val1): for idx, val in enumerate(val1):
if isinstance(val, MasterSlaves): if isinstance(val, Leadership):
lst1.append(val._p_.master.impl_getname()) lst1.append(val._p_.leader.impl_getname())
else: else:
lst1.append(val.impl_getname()) lst1.append(val.impl_getname())
for idx, val in enumerate(val2): for idx, val in enumerate(val2):
if isinstance(val, MasterSlaves): if isinstance(val, Leadership):
lst2.append(val._p_.master.impl_getname()) lst2.append(val._p_.leader.impl_getname())
else: else:
lst2.append(val.impl_getname()) lst2.append(val.impl_getname())
assert set(lst1) == set(lst2), '{} - {}'.format(lst1, lst2) 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.error import ConfigError
from tiramisu import Config 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.setting import groups, owners
from tiramisu.storage import list_sessions, delete_session from tiramisu.storage import list_sessions, delete_session
@ -174,11 +174,10 @@ def test_create_persistent_retrieve_owner():
del c del c
def test_create_persistent_retrieve_owner_masterslaves(): def test_create_persistent_retrieve_owner_leadership():
a = BoolOption('a', '', multi=True) a = BoolOption('a', '', multi=True)
b = BoolOption('b', '', multi=True) b = BoolOption('b', '', multi=True)
o = MasterSlaves('a', '', [a, b]) o = Leadership('a', '', [a, b])
#o.impl_set_group_type(groups.master)
o1 = OptionDescription('a', '', [o]) o1 = OptionDescription('a', '', [o])
try: try:
c = Config(o1, session_id='test_persistent', persistent=True) 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.api import TIRAMISU_VERSION
from tiramisu.setting import groups, owners 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 MetaConfig, undefined, Params, ParamOption
from tiramisu.error import SlaveError from tiramisu.error import LeadershipError
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
@ -199,33 +199,31 @@ def test_callback_submulti_list_list():
assert api.option('multi').owner.get() == owners.default 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) 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) 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])
#interface1.impl_set_group_type(groups.master) assert interface1.impl_get_group_type() == groups.leadership
assert interface1.impl_get_group_type() == groups.master
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) 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) 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]) od = OptionDescription('root', '', [interface1])
Config(od) 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) 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) 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])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
owner = api.owner.get() 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 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"]) api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"] assert api.option('ip_admin_eth0.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']])") 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) 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) 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])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
owner = api.owner.get() 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 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']) api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner assert api.option('ip_admin_eth0.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() == [] 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) 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) 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])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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.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'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0', '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']) 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) 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) 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])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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() == [] 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) 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) 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])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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 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) 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) 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]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() 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) 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) 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) 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])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
owner = api.owner.get() 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() 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"]]) api.option('ip_admin_eth0.ip_admin_eth0').value.set([["192.168.230.145"]])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [["192.168.230.145"]] assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [["192.168.230.145"]]

View File

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

View File

@ -19,7 +19,7 @@ from time import time
from typing import List, Set, Any, Optional, Callable, Union, Dict from typing import List, Set, Any, Optional, Callable, Union, Dict
from .error import APIError, ConfigError, SlaveError, PropertiesOptionError from .error import APIError, ConfigError, LeadershipError, PropertiesOptionError
from .i18n import _ from .i18n import _
from .setting import ConfigBag, OptionBag, owners, groups, Undefined, undefined, \ from .setting import ConfigBag, OptionBag, owners, groups, Undefined, undefined, \
FORBIDDEN_SET_PROPERTIES, SPECIAL_PROPERTIES FORBIDDEN_SET_PROPERTIES, SPECIAL_PROPERTIES
@ -96,11 +96,11 @@ class CommonTiramisu(TiramisuHelp):
self._option_bag = option_bag self._option_bag = option_bag
index = self._option_bag.index index = self._option_bag.index
if index is not None: if index is not None:
if option.impl_is_optiondescription() or not option.impl_is_master_slaves('slave'): if option.impl_is_optiondescription() or not option.impl_is_follower():
raise APIError('index must be set only with a slave option') raise APIError('index must be set only with a follower option')
self._length = self._subconfig.cfgimpl_get_length_slave(self._option_bag) self._length = self._subconfig.cfgimpl_get_length_leadership(self._option_bag)
if index >= self._length: if index >= self._length:
raise SlaveError(_('index "{}" is higher than the master length "{}" ' raise LeadershipError(_('index "{}" is higher than the leadership length "{}" '
'for option "{}"').format(index, 'for option "{}"').format(index,
self._length, self._length,
option.impl_get_display_name())) option.impl_get_display_name()))
@ -111,7 +111,7 @@ class CommonTiramisu(TiramisuHelp):
class CommonTiramisuOption(CommonTiramisu): class CommonTiramisuOption(CommonTiramisu):
_allow_optiondescription = False _allow_optiondescription = False
_slave_need_index = True _follower_need_index = True
_validate_properties = False _validate_properties = False
def __init__(self, def __init__(self,
@ -124,15 +124,15 @@ class CommonTiramisuOption(CommonTiramisu):
# for help() # for help()
if option_bag is not None and self._option_bag.config_bag.context.impl_type != 'group': if option_bag is not None and self._option_bag.config_bag.context.impl_type != 'group':
self._get_option() self._get_option()
if option_bag.config_bag is not None and self._slave_need_index: if option_bag.config_bag is not None and self._follower_need_index:
self._test_slave_index() self._test_follower_index()
def _test_slave_index(self) -> None: def _test_follower_index(self) -> None:
option = self._option_bag.option option = self._option_bag.option
if not option.impl_is_optiondescription() and \ if not option.impl_is_optiondescription() and \
self._option_bag.index is None and \ self._option_bag.index is None and \
option.impl_is_master_slaves('slave'): option.impl_is_follower():
raise APIError(_('index must be set with the slave option "{}"').format(self._option_bag.path)) raise APIError(_('index must be set with the follower option "{}"').format(self._option_bag.path))
def __getattr__(self, name): def __getattr__(self, name):
raise APIError(_('unknown method {}').format(name)) raise APIError(_('unknown method {}').format(name))
@ -141,7 +141,7 @@ class CommonTiramisuOption(CommonTiramisu):
class _TiramisuOptionOptionDescription(CommonTiramisuOption): class _TiramisuOptionOptionDescription(CommonTiramisuOption):
"""Manage option""" """Manage option"""
_allow_optiondescription = True _allow_optiondescription = True
_slave_need_index = False _follower_need_index = False
def get(self): def get(self):
"""Get Tiramisu option""" """Get Tiramisu option"""
@ -154,10 +154,10 @@ class _TiramisuOptionOptionDescription(CommonTiramisuOption):
type_ = type_.lower() type_ = type_.lower()
return type_ return type_
def ismasterslaves(self): def isleadership(self):
"""Test if option is a master or a slave""" """Test if option is a leader or a follower"""
option = self._option_bag.option option = self._option_bag.option
return option.impl_is_master_slaves() return option.impl_is_leadership()
def doc(self): def doc(self):
"""Get option document""" """Get option document"""
@ -220,15 +220,15 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription):
option = self._option_bag.option option = self._option_bag.option
return option.impl_is_submulti() return option.impl_is_submulti()
def ismaster(self): def isleader(self):
"""Test if option is a master""" """Test if option is a leader"""
option = self._option_bag.option option = self._option_bag.option
return option.impl_is_master_slaves('master') return option.impl_is_leader()
def isslave(self): def isfollower(self):
"""Test if option is a slave""" """Test if option is a follower"""
option = self._option_bag.option option = self._option_bag.option
return option.impl_is_master_slaves('slave') return option.impl_is_follower()
def issymlinkoption(self) -> bool: def issymlinkoption(self) -> bool:
option = self._option_bag.option option = self._option_bag.option
@ -258,7 +258,7 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription):
class TiramisuOptionOption(CommonTiramisuOption): class TiramisuOptionOption(CommonTiramisuOption):
"""Manage option""" """Manage option"""
_allow_optiondescription = True _allow_optiondescription = True
_slave_need_index = False _follower_need_index = False
def __new__(cls, def __new__(cls,
name, name,
@ -318,7 +318,7 @@ class TiramisuOptionOwner(CommonTiramisuOption):
class TiramisuOptionProperty(CommonTiramisuOption): class TiramisuOptionProperty(CommonTiramisuOption):
"""Manage option's property""" """Manage option's property"""
_allow_optiondescription = True _allow_optiondescription = True
_slave_need_index = False _follower_need_index = False
def __init__(self, def __init__(self,
name: str, name: str,
@ -334,7 +334,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
only_raises=False): only_raises=False):
"""Get properties for an option""" """Get properties for an option"""
option = self._option_bag.option option = self._option_bag.option
self._test_slave_index() self._test_follower_index()
properties = self._option_bag.properties properties = self._option_bag.properties
if not only_raises: if not only_raises:
return properties return properties
@ -376,7 +376,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
class TiramisuOptionPermissive(CommonTiramisuOption): class TiramisuOptionPermissive(CommonTiramisuOption):
"""Manage option's permissive""" """Manage option's permissive"""
_allow_optiondescription = True _allow_optiondescription = True
_slave_need_index = False _follower_need_index = False
def __init__(self, def __init__(self,
name: str, name: str,
@ -407,7 +407,7 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
class TiramisuOptionInformation(CommonTiramisuOption): class TiramisuOptionInformation(CommonTiramisuOption):
"""Manage option's informations""" """Manage option's informations"""
_allow_optiondescription = True _allow_optiondescription = True
_slave_need_index = False _follower_need_index = False
def get(self, key, default=undefined): def get(self, key, default=undefined):
"""Get information""" """Get information"""
@ -443,14 +443,14 @@ class _TiramisuOptionValueOption:
def get(self): def get(self):
"""Get option's value""" """Get option's value"""
option = self._option_bag.option option = self._option_bag.option
self._test_slave_index() self._test_follower_index()
return self._subconfig.getattr(self._name, return self._subconfig.getattr(self._name,
self._option_bag) self._option_bag)
def set(self, value): def set(self, value):
"""Change option's value""" """Change option's value"""
option = self._option_bag.option option = self._option_bag.option
self._test_slave_index() self._test_follower_index()
values = self._option_bag.config_bag.context.cfgimpl_get_values() values = self._option_bag.config_bag.context.cfgimpl_get_values()
if isinstance(value, list): if isinstance(value, list):
while undefined in value: while undefined in value:
@ -464,16 +464,16 @@ class _TiramisuOptionValueOption:
def reset(self): def reset(self):
"""Reset value for an option""" """Reset value for an option"""
self._test_slave_index() self._test_follower_index()
self._subconfig.delattr(self._option_bag) self._subconfig.delattr(self._option_bag)
def default(self): def default(self):
"""Get default value (default of option or calculated value)""" """Get default value (default of option or calculated value)"""
option = self._option_bag.option option = self._option_bag.option
values = self._option_bag.config_bag.context.cfgimpl_get_values() values = self._option_bag.config_bag.context.cfgimpl_get_values()
if option.impl_is_master_slaves('slave') and self._option_bag.index is None: if option.impl_is_follower() and self._option_bag.index is None:
value = [] value = []
length = self._subconfig.cfgimpl_get_length_slave(self._option_bag) length = self._subconfig.cfgimpl_get_length_leadership(self._option_bag)
for idx in range(length): for idx in range(length):
soption_bag = OptionBag() soption_bag = OptionBag()
soption_bag.set_option(option, soption_bag.set_option(option,
@ -485,16 +485,17 @@ class _TiramisuOptionValueOption:
return values.getdefaultvalue(self._option_bag) return values.getdefaultvalue(self._option_bag)
class _TiramisuOptionValueMaster: class _TiramisuOptionValueLeader:
def pop(self, index): def pop(self, index):
"""Pop a value""" """Pop a value"""
assert not self._option_bag.option.impl_is_symlinkoption(), _("can't delete a SymLinkOption") option_bag = self._option_bag
self._option_bag.config_bag.context.cfgimpl_get_values().reset_master(index, assert not option_bag.option.impl_is_symlinkoption(), _("can't delete a SymLinkOption")
self._option_bag, option_bag.config_bag.context.cfgimpl_get_values().reset_leadership(index,
option_bag,
self._subconfig) self._subconfig)
def len(self): def len(self):
"""Length of master option""" """Length of leadership"""
option = self._option_bag.option option = self._option_bag.option
# for example if index is None # for example if index is None
if '_length' not in vars(self): if '_length' not in vars(self):
@ -508,13 +509,13 @@ class _TiramisuOptionValueGroup:
self._option_bag.config_bag.context.reset(self._option_bag.path) self._option_bag.config_bag.context.reset(self._option_bag.path)
class _TiramisuOptionValueSlave: class _TiramisuOptionValueFollower:
def len(self): def len(self):
"""Length of slave option""" """Length of follower option"""
option = self._option_bag.option option = self._option_bag.option
# for example if index is None # for example if index is None
if '_length' not in vars(self): if '_length' not in vars(self):
self._length = self._subconfig.cfgimpl_get_length_slave(self._option_bag) self._length = self._subconfig.cfgimpl_get_length_leadership(self._option_bag)
return self._length return self._length
@ -550,7 +551,7 @@ class _TiramisuOptionValueOptionDescription:
class TiramisuOptionValue(CommonTiramisuOption): class TiramisuOptionValue(CommonTiramisuOption):
"""Manage option's value""" """Manage option's value"""
_allow_optiondescription = True _allow_optiondescription = True
_slave_need_index = False _follower_need_index = False
def __new__(cls, def __new__(cls,
name, name,
@ -570,14 +571,14 @@ class TiramisuOptionValue(CommonTiramisuOption):
types.append(_TiramisuOptionValueOption) types.append(_TiramisuOptionValueOption)
if isinstance(option, ChoiceOption): if isinstance(option, ChoiceOption):
types.append(_TiramisuOptionValueChoiceOption) types.append(_TiramisuOptionValueChoiceOption)
if option.impl_is_master_slaves('master'): if option.impl_is_leader():
types.append(_TiramisuOptionValueMaster) types.append(_TiramisuOptionValueLeader)
elif option.impl_is_master_slaves('slave'): elif option.impl_is_follower():
types.append(_TiramisuOptionValueSlave) types.append(_TiramisuOptionValueFollower)
if option_bag.config_bag.context.impl_type == 'group': if option_bag.config_bag.context.impl_type == 'group':
types.append(_TiramisuOptionValueGroup) types.append(_TiramisuOptionValueGroup)
new_type_dict = {'_allow_optiondescription': cls._allow_optiondescription, new_type_dict = {'_allow_optiondescription': cls._allow_optiondescription,
'_slave_need_index': cls._slave_need_index} '_follower_need_index': cls._follower_need_index}
new_type = type('TiramisuOptionValue', tuple(types), new_type_dict)(name=name, new_type = type('TiramisuOptionValue', tuple(types), new_type_dict)(name=name,
subconfig=subconfig, subconfig=subconfig,
option_bag=option_bag) option_bag=option_bag)
@ -651,7 +652,7 @@ class _TiramisuOptionDescription(_TiramisuOption):
self._config_bag) self._config_bag)
t_option = TiramisuOption(name, t_option = TiramisuOption(name,
path, path,
None, # index for a slave ? None, # index for a follower ?
subconfig, subconfig,
self._config_bag) self._config_bag)
if first: if first:

View File

@ -21,7 +21,7 @@
from typing import Any, Optional, Union, Callable, Dict, List from typing import Any, Optional, Union, Callable, Dict, List
from .error import PropertiesOptionError, ConfigError, SlaveError from .error import PropertiesOptionError, ConfigError, LeadershipError
from .i18n import _ from .i18n import _
from .setting import undefined, ConfigBag, OptionBag, Undefined from .setting import undefined, ConfigBag, OptionBag, Undefined
from .storage import get_default_values_storages, get_default_settings_storages from .storage import get_default_values_storages, get_default_settings_storages
@ -51,12 +51,12 @@ def manager_callback(callbk: Union[ParamOption, ParamValue],
opt = opt.to_dynoption(option.rootpath, opt = opt.to_dynoption(option.rootpath,
option.impl_getsuffix()) option.impl_getsuffix())
path = opt.impl_getpath() path = opt.impl_getpath()
if index is not None and opt.impl_is_master_slaves() and \ if index is not None and opt.impl_get_leadership() and \
opt.impl_get_master_slaves().in_same_group(option): opt.impl_get_leadership().in_same_group(option):
if opt == option: if opt == option:
index_ = None index_ = None
with_index = False with_index = False
elif opt.impl_is_master_slaves('slave'): elif opt.impl_is_follower():
index_ = index index_ = index
with_index = False with_index = False
else: else:
@ -66,7 +66,7 @@ def manager_callback(callbk: Union[ParamOption, ParamValue],
index_ = None index_ = None
with_index = False with_index = False
if opt == option and orig_value is not undefined and \ if opt == option and orig_value is not undefined and \
(not opt.impl_is_master_slaves('slave') or index is None): (not opt.impl_is_follower() or index is None):
return orig_value return orig_value
# don't validate if option is option that we tried to validate # don't validate if option is option that we tried to validate
config_bag = config_bag.copy() config_bag = config_bag.copy()
@ -152,17 +152,17 @@ def carry_out_calculation(option,
opt1 == 11 opt1 == 11
=> calculate(<function func at 0x1cea320>, [11], {}) => calculate(<function func at 0x1cea320>, [11], {})
- a multi option and not master/slave: - a multi option and not leadership
opt1 == [1, 2, 3] opt1 == [1, 2, 3]
=> calculate(<function func at 0x223c320>, [[1, 2, 3]], {}) => calculate(<function func at 0x223c320>, [[1, 2, 3]], {})
- option is master or slave of opt1: - option is leader or follower of opt1:
opt1 == [1, 2, 3] opt1 == [1, 2, 3]
=> calculate(<function func at 0x223c320>, [1], {}) => calculate(<function func at 0x223c320>, [1], {})
=> calculate(<function func at 0x223c320>, [2], {}) => calculate(<function func at 0x223c320>, [2], {})
=> calculate(<function func at 0x223c320>, [3], {}) => calculate(<function func at 0x223c320>, [3], {})
- opt is a master or slave but not related to option: - opt is a leader or follower but not related to option:
opt1 == [1, 2, 3] opt1 == [1, 2, 3]
=> calculate(<function func at 0x11b0320>, [[1, 2, 3]], {}) => calculate(<function func at 0x11b0320>, [[1, 2, 3]], {})
@ -252,17 +252,17 @@ def carry_out_calculation(option,
args, args,
kwargs) kwargs)
if isinstance(ret, list) and not option.impl_is_dynoptiondescription() and \ if isinstance(ret, list) and not option.impl_is_dynoptiondescription() and \
option.impl_is_master_slaves('slave'): option.impl_is_follower():
if args or kwargs: if args or kwargs:
raise SlaveError(_('function "{}" with arguments "{}" and "{}" ' raise LeadershipError(_('function "{}" with arguments "{}" and "{}" '
'return the list "{}" for the slave option "{}"' 'return the list "{}" for the follower option "{}"'
'').format(callback.__name__, '').format(callback.__name__,
args, args,
kwargs, kwargs,
ret, ret,
option.impl_get_display_name())) option.impl_get_display_name()))
else: else:
raise SlaveError(_('function "{}" return the list "{}" for the slave option "{}"' raise LeadershipError(_('function "{}" return the list "{}" for the follower option "{}"'
'').format(callback.__name__, '').format(callback.__name__,
ret, ret,
option.impl_getname())) option.impl_getname()))

View File

@ -23,10 +23,11 @@ import weakref
from copy import copy from copy import copy
from .error import PropertiesOptionError, ConfigError, ConflictError, SlaveError from .error import PropertiesOptionError, ConfigError, ConflictError, \
from .option import SynDynOptionDescription, DynOptionDescription, MasterSlaves LeadershipError
from .option import SynDynOptionDescription, DynOptionDescription, Leadership
from .option.baseoption import BaseOption, valid_name from .option.baseoption import BaseOption, valid_name
from .setting import OptionBag, ConfigBag, groups, Settings, undefined from .setting import OptionBag, ConfigBag, Settings, undefined
from .storage import get_storages, gen_storage_id, get_default_values_storages from .storage import get_storages, gen_storage_id, get_default_values_storages
from .value import Values from .value import Values
from .i18n import _ from .i18n import _
@ -49,7 +50,7 @@ class SubConfig(object):
config_bag, config_bag,
subpath=None, subpath=None,
fromconsistency=None): fromconsistency=None):
""" Configuration option management master class """ Configuration option management class
:param descr: describes the configuration schema :param descr: describes the configuration schema
:type descr: an instance of ``option.OptionDescription`` :type descr: an instance of ``option.OptionDescription``
@ -58,10 +59,9 @@ class SubConfig(object):
:type subpath: `str` with the path name :type subpath: `str` with the path name
""" """
# main option description # main option description
error = False if __debug__ and descr is not None and \
if descr is not None and (not isinstance(descr, (BaseOption, SynDynOptionDescription)) or not descr.impl_is_optiondescription()): (not isinstance(descr, (BaseOption, SynDynOptionDescription)) or
error = True not descr.impl_is_optiondescription()):
if error:
try: try:
msg = descr.impl_get_displayname() msg = descr.impl_get_displayname()
except AttributeError: except AttributeError:
@ -71,28 +71,27 @@ class SubConfig(object):
self._impl_descr = descr self._impl_descr = descr
self._impl_context = context self._impl_context = context
self._impl_path = subpath self._impl_path = subpath
if descr is not None and \ if descr is not None and descr.impl_is_leadership():
descr.impl_get_group_type() == groups.master: leader = descr.get_leader()
master = descr.getmaster() leaderpath = leader.impl_getname()
masterpath = master.impl_getname() full_leaderpath = self._get_subpath(leaderpath)
full_masterpath = self._get_subpath(masterpath)
cconfig_bag = config_bag.copy() cconfig_bag = config_bag.copy()
cconfig_bag.remove_validation() cconfig_bag.remove_validation()
moption_bag = OptionBag() moption_bag = OptionBag()
moption_bag.set_option(master, moption_bag.set_option(leader,
full_masterpath, full_leaderpath,
None, None,
cconfig_bag) cconfig_bag)
if fromconsistency: if fromconsistency:
moption_bag.fromconsistency = fromconsistency moption_bag.fromconsistency = fromconsistency
value = self.getattr(masterpath, value = self.getattr(leaderpath,
moption_bag) moption_bag)
self._impl_length = len(value) self._impl_length = len(value)
def cfgimpl_get_length(self): def cfgimpl_get_length(self):
return self._impl_length return self._impl_length
def cfgimpl_get_length_slave(self, def cfgimpl_get_length_leadership(self,
option_bag): option_bag):
if option_bag.option.impl_is_symlinkoption(): if option_bag.option.impl_is_symlinkoption():
context = self.cfgimpl_get_context() context = self.cfgimpl_get_context()
@ -238,8 +237,8 @@ class SubConfig(object):
raise ConfigError(_("can't assign to a SymLinkOption")) raise ConfigError(_("can't assign to a SymLinkOption"))
context = option_bag.config_bag.context context = option_bag.config_bag.context
context.cfgimpl_get_settings().validate_properties(option_bag) context.cfgimpl_get_settings().validate_properties(option_bag)
if option_bag.option.impl_is_master_slaves('master') and len(value) < self._impl_length: if option_bag.option.impl_is_leader() and len(value) < self._impl_length:
raise SlaveError(_('cannot reduce length of the master "{}"' raise LeadershipError(_('cannot reduce length of a leader "{}"'
'').format(option_bag.option.impl_get_display_name())) '').format(option_bag.option.impl_get_display_name()))
return context.cfgimpl_get_values().setvalue(value, return context.cfgimpl_get_values().setvalue(value,
option_bag, option_bag,
@ -253,7 +252,7 @@ class SubConfig(object):
raise TypeError(_("can't delete a SymLinkOption")) raise TypeError(_("can't delete a SymLinkOption"))
values = self.cfgimpl_get_values() values = self.cfgimpl_get_values()
if option_bag.index is not None: if option_bag.index is not None:
values.reset_slave(option_bag, values.reset_follower(option_bag,
_commit) _commit)
else: else:
values.reset(option_bag, values.reset(option_bag,
@ -313,16 +312,16 @@ class SubConfig(object):
self.cfgimpl_get_settings().validate_properties(option_bag) self.cfgimpl_get_settings().validate_properties(option_bag)
if option.impl_is_master_slaves('slave'): if option.impl_is_follower():
length = self.cfgimpl_get_length_slave(option_bag) length = self.cfgimpl_get_length_leadership(option_bag)
slave_len = self.cfgimpl_get_values()._p_.get_max_length(option_bag.path) follower_len = self.cfgimpl_get_values()._p_.get_max_length(option_bag.path)
if slave_len > length: if follower_len > length:
raise SlaveError(_('slave option "{}" has higher length "{}" than the master ' raise LeadershipError(_('follower option "{}" has higher length "{}" than the leader '
'length "{}"').format(option.impl_get_display_name(), 'length "{}"').format(option.impl_get_display_name(),
slave_len, follower_len,
length, length,
option_bag.index)) option_bag.index))
if option.impl_is_master_slaves('slave') and option_bag.index is None: if option.impl_is_follower() and option_bag.index is None:
value = [] value = []
for idx in range(length): for idx in range(length):
soption_bag = OptionBag() soption_bag = OptionBag()
@ -717,7 +716,7 @@ class KernelConfig(_CommonConfig):
force_settings=None, force_settings=None,
_duplicate=False, _duplicate=False,
storage=None): storage=None):
""" Configuration option management master class """ Configuration option management class
:param descr: describes the configuration schema :param descr: describes the configuration schema
:type descr: an instance of ``option.OptionDescription`` :type descr: an instance of ``option.OptionDescription``
@ -730,8 +729,8 @@ class KernelConfig(_CommonConfig):
:type persistent: `boolean` :type persistent: `boolean`
""" """
self._impl_meta = None self._impl_meta = None
if isinstance(descr, MasterSlaves): if isinstance(descr, Leadership):
raise ConfigError(_('cannot set masterslaves object has root optiondescription')) raise ConfigError(_('cannot set leadership object has root optiondescription'))
if isinstance(descr, DynOptionDescription): if isinstance(descr, DynOptionDescription):
raise ConfigError(_('cannot set dynoptiondescription object has root optiondescription')) raise ConfigError(_('cannot set dynoptiondescription object has root optiondescription'))
if force_settings is not None and force_values is not None: if force_settings is not None and force_values is not None:
@ -872,7 +871,7 @@ class KernelGroupConfig(_CommonConfig):
err._requires, err._requires,
err._name, err._name,
err._orig_opt)) err._orig_opt))
except (ValueError, SlaveError, AttributeError) as err: except (ValueError, LeadershipError, AttributeError) as err:
ret.append(err) ret.append(err)
if _commit and self.impl_type != 'group': if _commit and self.impl_type != 'group':
self.cfgimpl_get_values()._p_.commit() self.cfgimpl_get_values()._p_.commit()
@ -1089,7 +1088,7 @@ class KernelMixConfig(KernelGroupConfig):
err._requires, err._requires,
err._name, err._name,
err._orig_opt)) err._orig_opt))
except (ValueError, SlaveError, AttributeError) as err: except (ValueError, LeadershipError, AttributeError) as err:
ret.append(err) ret.append(err)
try: try:
@ -1100,7 +1099,7 @@ class KernelMixConfig(KernelGroupConfig):
subconfig.setattr(value, subconfig.setattr(value,
option_bag, option_bag,
_commit=False) _commit=False)
except (PropertiesOptionError, ValueError, SlaveError) as err: except (PropertiesOptionError, ValueError, LeadershipError) as err:
ret.append(err) ret.append(err)
return ret return ret

View File

@ -144,8 +144,8 @@ class RequirementError(Exception):
pass pass
class SlaveError(Exception): class LeadershipError(Exception):
"problem with a slave's value length" "problem with a leadership's value length"
pass pass

View File

@ -1,7 +1,7 @@
from .optiondescription import OptionDescription from .optiondescription import OptionDescription
from .dynoptiondescription import DynOptionDescription from .dynoptiondescription import DynOptionDescription
from .syndynoptiondescription import SynDynOptionDescription, SynDynMasterSlaves from .syndynoptiondescription import SynDynOptionDescription, SynDynLeadership
from .masterslaves import MasterSlaves from .leadership import Leadership
from .baseoption import submulti from .baseoption import submulti
from .symlinkoption import SymLinkOption from .symlinkoption import SymLinkOption
from .syndynoption import SynDynOption from .syndynoption import SynDynOption
@ -25,8 +25,8 @@ from .filenameoption import FilenameOption
from .passwordoption import PasswordOption from .passwordoption import PasswordOption
__all__ = ('MasterSlaves', 'OptionDescription', 'DynOptionDescription', __all__ = ('Leadership', 'OptionDescription', 'DynOptionDescription',
'SynDynOptionDescription', 'SynDynMasterSlaves', 'Option', 'SymLinkOption', 'SynDynOptionDescription', 'SynDynLeadership', 'Option', 'SymLinkOption',
'SynDynOption', 'ChoiceOption', 'BoolOption', 'DateOption', 'SynDynOption', 'ChoiceOption', 'BoolOption', 'DateOption',
'IntOption', 'FloatOption', 'StrOption', 'UnicodeOption', 'IntOption', 'FloatOption', 'StrOption', 'UnicodeOption',
'IPOption', 'PortOption', 'NetworkOption', 'NetmaskOption', 'IPOption', 'PortOption', 'NetworkOption', 'NetmaskOption',

View File

@ -90,7 +90,7 @@ class Base:
properties = frozenset(properties) properties = frozenset(properties)
if is_multi and 'empty' not in properties: if is_multi and 'empty' not in properties:
# if option is a multi, it cannot be "empty" (None not allowed in the list) # if option is a multi, it cannot be "empty" (None not allowed in the list)
# "empty" is removed for slave's option # "empty" is removed for follower's option
properties = properties | {'empty'} properties = properties | {'empty'}
if not isinstance(properties, frozenset): if not isinstance(properties, frozenset):
raise TypeError(_('invalid properties type {0} for {1},' raise TypeError(_('invalid properties type {0} for {1},'

View File

@ -52,7 +52,7 @@ class DynOptionDescription(OptionDescription):
# check children + set relation to this dynoptiondescription # check children + set relation to this dynoptiondescription
for child in children: for child in children:
if isinstance(child, OptionDescription): if isinstance(child, OptionDescription):
if __debug__ and child.impl_get_group_type() != groups.master: if __debug__ and child.impl_get_group_type() != groups.leadership:
raise ConfigError(_('cannot set optiondescription in a ' raise ConfigError(_('cannot set optiondescription in a '
'dynoptiondescription')) 'dynoptiondescription'))
for chld in child.get_children(config_bag=undefined): for chld in child.get_children(config_bag=undefined):

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"master slaves support" "Leadership support"
# Copyright (C) 2014-2019 Team tiramisu (see AUTHORS for all contributors) # Copyright (C) 2014-2019 Team tiramisu (see AUTHORS for all contributors)
# #
# This program is free software: you can redistribute it and/or modify it # This program is free software: you can redistribute it and/or modify it
@ -28,16 +28,16 @@ from ..i18n import _
from ..setting import groups, undefined, OptionBag, Settings from ..setting import groups, undefined, OptionBag, Settings
from ..value import Values from ..value import Values
from .optiondescription import OptionDescription from .optiondescription import OptionDescription
from .syndynoptiondescription import SynDynMasterSlaves from .syndynoptiondescription import SynDynLeadership
from .baseoption import BaseOption from .baseoption import BaseOption
from .option import Option from .option import Option
from ..error import SlaveError, PropertiesOptionError, RequirementError from ..error import RequirementError
from ..function import ParamOption from ..function import ParamOption
class MasterSlaves(OptionDescription): class Leadership(OptionDescription):
__slots__ = ('master', __slots__ = ('leader',
'slaves') 'followers')
def __init__(self, def __init__(self,
name: str, name: str,
@ -46,86 +46,86 @@ class MasterSlaves(OptionDescription):
requires=None, requires=None,
properties=None) -> None: properties=None) -> None:
super(MasterSlaves, self).__init__(name, super().__init__(name,
doc, doc,
children, children,
requires=requires, requires=requires,
properties=properties) properties=properties)
self._group_type = groups.master self._group_type = groups.leadership
slaves = [] followers = []
if len(children) < 2: if len(children) < 2:
raise ValueError(_('a master and a slave are mandatories in masterslaves "{}"' raise ValueError(_('a leader and a follower are mandatories in leadership "{}"'
'').format(name)) '').format(name))
master = children[0] leader = children[0]
for idx, child in enumerate(children): for idx, child in enumerate(children):
if __debug__: if __debug__:
if child.impl_is_symlinkoption(): if child.impl_is_symlinkoption():
raise ValueError(_('masterslaves "{0}" shall not have ' raise ValueError(_('leadership "{0}" shall not have '
"a symlinkoption").format(self.impl_get_display_name())) "a symlinkoption").format(self.impl_get_display_name()))
if not isinstance(child, Option): if not isinstance(child, Option):
raise ValueError(_('masterslaves "{0}" shall not have ' raise ValueError(_('leadership "{0}" shall not have '
'a subgroup').format(self.impl_get_display_name())) 'a subgroup').format(self.impl_get_display_name()))
if not child.impl_is_multi(): if not child.impl_is_multi():
raise ValueError(_('only multi option allowed in masterslaves "{0}" but option ' raise ValueError(_('only multi option allowed in leadership "{0}" but option '
'"{1}" is not a multi' '"{1}" is not a multi'
'').format(self.impl_get_display_name(), '').format(self.impl_get_display_name(),
child.impl_get_display_name())) child.impl_get_display_name()))
if idx != 0 and child.impl_getdefault() != []: if idx != 0 and child.impl_getdefault() != []:
raise ValueError(_('not allowed default value for slave option "{0}" ' raise ValueError(_('not allowed default value for follower option "{0}" '
'in masterslaves "{1}"' 'in leadership "{1}"'
'').format(child.impl_get_display_name(), '').format(child.impl_get_display_name(),
self.impl_get_display_name())) self.impl_get_display_name()))
if idx != 0: if idx != 0:
# remove empty property for slave # remove empty property for follower
child_properties = list(child._properties) child_properties = list(child._properties)
child_properties.remove('empty') child_properties.remove('empty')
child._properties = frozenset(child_properties) child._properties = frozenset(child_properties)
slaves.append(child) followers.append(child)
child._add_dependency(self) child._add_dependency(self)
child._master_slaves = weakref.ref(self) child._leadership = weakref.ref(self)
callback, callback_params = master.impl_get_callback() callback, callback_params = leader.impl_get_callback()
if callback is not None and callback_params is not None: if callback is not None and callback_params is not None:
for callbk in chain(callback_params.args, callback_params.kwargs.values()): for callbk in chain(callback_params.args, callback_params.kwargs.values()):
if isinstance(callbk, ParamOption) and callbk.option in slaves: if isinstance(callbk, ParamOption) and callbk.option in followers:
raise ValueError(_("callback of master's option shall " raise ValueError(_("callback of leader's option shall "
"not refered to a slave's ones")) "not refered to a follower's ones"))
# master should not have requires, only MasterSlaves should have # leader should not have requires, only Leadership should have
# so move requires to MasterSlaves # so move requires to Leadership
# if MasterSlaves has requires too, cannot manage this move so raises # if Leadership has requires too, cannot manage this move so raises
master_requires = getattr(master, '_requires', None) leader_requires = getattr(leader, '_requires', None)
if master_requires: if leader_requires:
if __debug__ and self.impl_getrequires(): if __debug__ and self.impl_getrequires():
raise RequirementError(_('master {} have requirement, but MasterSlaves {} too' raise RequirementError(_('leader {} have requirement, but Leadership {} too'
'').format(master.impl_getname(), '').format(leader.impl_getname(),
self.impl_getname())) self.impl_getname()))
master_calproperties = getattr(master, '_calc_properties', None) leader_calproperties = getattr(leader, '_calc_properties', None)
if master_calproperties: if leader_calproperties:
if __debug__ and properties is not None: if __debug__ and properties is not None:
self.validate_properties(name, master_calproperties, frozenset(properties)) self.validate_properties(name, leader_calproperties, frozenset(properties))
setattr(self, '_calc_properties', master_calproperties) setattr(self, '_calc_properties', leader_calproperties)
setattr(self, '_requires', master_requires) setattr(self, '_requires', leader_requires)
delattr(master, '_requires') delattr(leader, '_requires')
if __debug__: if __debug__:
for requires_ in getattr(self, '_requires', ()): for requires_ in getattr(self, '_requires', ()):
for require in requires_: for require in requires_:
for require_opt, values in require[0]: for require_opt, values in require[0]:
if require_opt.impl_is_multi() and require_opt.impl_is_master_slaves(): if require_opt.impl_is_multi() and require_opt.impl_get_leadership():
raise ValueError(_('malformed requirements option "{0}" ' raise ValueError(_('malformed requirements option "{0}" '
'must not be in slave for "{1}"').format( 'must not be in follower for "{1}"').format(
require_opt.impl_getname(), require_opt.impl_getname(),
self.impl_getname())) self.impl_getname()))
def is_master(self, def is_leader(self,
opt: Option) -> bool: opt: Option) -> bool:
master = self.getmaster() leader = self.get_leader()
return opt == master or (opt.impl_is_dynsymlinkoption() and opt.opt == master) return opt == leader or (opt.impl_is_dynsymlinkoption() and opt.opt == leader)
def getmaster(self) -> Option: def get_leader(self) -> Option:
return self._children[1][0] return self._children[1][0]
def getslaves(self) -> Iterator[Option]: def get_followers(self) -> Iterator[Option]:
for slave in self._children[1][1:]: for follower in self._children[1][1:]:
yield slave yield follower
def in_same_group(self, def in_same_group(self,
opt: Option) -> bool: opt: Option) -> bool:
@ -139,11 +139,11 @@ class MasterSlaves(OptionDescription):
_commit: bool=True) -> None: _commit: bool=True) -> None:
config_bag = option_bag.config_bag.copy() config_bag = option_bag.config_bag.copy()
config_bag.remove_validation() config_bag.remove_validation()
for slave in self.getslaves(): for follower in self.get_followers():
slave_path = slave.impl_getpath() follower_path = follower.impl_getpath()
soption_bag = OptionBag() soption_bag = OptionBag()
soption_bag.set_option(slave, soption_bag.set_option(follower,
slave_path, follower_path,
None, None,
config_bag) config_bag)
values.reset(soption_bag, values.reset(soption_bag,
@ -153,31 +153,31 @@ class MasterSlaves(OptionDescription):
values: Values, values: Values,
index: int, index: int,
option_bag: OptionBag, option_bag: OptionBag,
slaves: Optional[List[Option]]=undefined) -> None: followers: Optional[List[Option]]=undefined) -> None:
if slaves is undefined: if followers is undefined:
# slaves is not undefined only in SynDynMasterSlaves # followers are not undefined only in SynDynLeadership
slaves = self.getslaves() followers = self.get_followers()
config_bag = option_bag.config_bag.copy() config_bag = option_bag.config_bag.copy()
config_bag.remove_validation() config_bag.remove_validation()
for slave in slaves: for follower in followers:
slave_path = slave.impl_getpath() follower_path = follower.impl_getpath()
slavelen = values._p_.get_max_length(slave_path) followerlen = values._p_.get_max_length(follower_path)
soption_bag = OptionBag() soption_bag = OptionBag()
soption_bag.set_option(slave, soption_bag.set_option(follower,
slave_path, follower_path,
index, index,
config_bag) config_bag)
# do not check force_default_on_freeze # do not check force_default_on_freeze
soption_bag.properties = set() soption_bag.properties = set()
if not values.is_default_owner(soption_bag, if not values.is_default_owner(soption_bag,
validate_meta=False) and slavelen > index: validate_meta=False) and followerlen > index:
values._p_.resetvalue_index(slave_path, values._p_.resetvalue_index(follower_path,
index, index,
True) True)
if slavelen > index + 1: if followerlen > index + 1:
for idx in range(index + 1, slavelen): for idx in range(index + 1, followerlen):
if values._p_.hasvalue(slave_path, idx): if values._p_.hasvalue(follower_path, idx):
values._p_.reduce_index(slave_path, values._p_.reduce_index(follower_path,
idx) idx)
def reset_cache(self, def reset_cache(self,
@ -186,16 +186,16 @@ class MasterSlaves(OptionDescription):
settings: Settings, settings: Settings,
resetted_opts: List[Option]) -> None: resetted_opts: List[Option]) -> None:
self._reset_cache(path, self._reset_cache(path,
self.getmaster(), self.get_leader(),
self.getslaves(), self.get_followers(),
values, values,
settings, settings,
resetted_opts) resetted_opts)
def _reset_cache(self, def _reset_cache(self,
path: str, path: str,
master: Option, leader: Option,
slaves: List[Option], followers: List[Option],
values: Values, values: Values,
settings: Settings, settings: Settings,
resetted_opts: List[Option]) -> None: resetted_opts: List[Option]) -> None:
@ -203,24 +203,24 @@ class MasterSlaves(OptionDescription):
values, values,
settings, settings,
resetted_opts) resetted_opts)
master.reset_cache(master.impl_getpath(), leader.reset_cache(leader.impl_getpath(),
values, values,
settings, settings,
None) None)
for slave in slaves: for follower in followers:
spath = slave.impl_getpath() spath = follower.impl_getpath()
slave.reset_cache(spath, follower.reset_cache(spath,
values, values,
settings, settings,
None) None)
resetted_opts.append(spath) resetted_opts.append(spath)
def impl_is_master_slaves(self) -> None: def impl_is_leadership(self) -> None:
return True return True
def to_dynoption(self, def to_dynoption(self,
rootpath: str, rootpath: str,
suffix: str) -> SynDynMasterSlaves: suffix: str) -> SynDynLeadership:
return SynDynMasterSlaves(self, return SynDynLeadership(self,
rootpath, rootpath,
suffix) suffix)

View File

@ -52,7 +52,7 @@ class Option(BaseOption):
#calcul #calcul
'_val_call', '_val_call',
# #
'_master_slaves', '_leadership',
'_choice_values', '_choice_values',
'_choice_values_params', '_choice_values_params',
) )
@ -381,24 +381,27 @@ class Option(BaseOption):
pass pass
#__________________________________________________________________________ #__________________________________________________________________________
# master/slaves # leadership
# def impl_is_leadership(self):
# return self.impl_get_leadership() is not None
def impl_is_master_slaves(self, def impl_is_leader(self):
type_: str='both') -> bool: leadership = self.impl_get_leadership()
master_slaves = self.impl_get_master_slaves() if leadership is None:
if master_slaves is not None: return leadership
if type_ == 'both': return self.impl_get_leadership().is_leader(self)
return True
is_master = master_slaves.is_master(self)
if (type_ == 'master' and is_master) or (type_ == 'slave' and not is_master):
return True
return False
def impl_get_master_slaves(self): def impl_is_follower(self):
masterslave = getattr(self, '_master_slaves', None) leadership = self.impl_get_leadership()
if masterslave is None: if leadership is None:
return masterslave return leadership
return masterslave() return not leadership.is_leader(self)
def impl_get_leadership(self):
leadership = getattr(self, '_leadership', None)
if leadership is None:
return leadership
return leadership()
#____________________________________________________________ #____________________________________________________________
# consistencies # consistencies
@ -662,7 +665,7 @@ class Option(BaseOption):
if func in ALLOWED_CONST_LIST: if func in ALLOWED_CONST_LIST:
index = None index = None
index_ = None index_ = None
elif current_option.impl_is_master_slaves('master'): elif current_option.impl_is_leader():
index = option_bag.index index = option_bag.index
index_ = None index_ = None
else: else:
@ -681,8 +684,8 @@ class Option(BaseOption):
current_value = option_bag.config_bag.context.getattr(path, current_value = option_bag.config_bag.context.getattr(path,
coption_bag) coption_bag)
if index_ is None and index is not None: if index_ is None and index is not None:
#if self is a slave and current_option is a master and func not in ALLOWED_CONST_LIST #if self is a follower and current_option is a leader and func not in ALLOWED_CONST_LIST
#return only the value of the master for isolate slave #return only the value of the leader for isolate follower
current_value = current_value[index] current_value = current_value[index]
return current_value return current_value

View File

@ -26,7 +26,7 @@ from ..i18n import _
from ..setting import ConfigBag, OptionBag, groups, undefined, owners, Undefined from ..setting import ConfigBag, OptionBag, groups, undefined, owners, Undefined
from .baseoption import BaseOption from .baseoption import BaseOption
from .option import ALLOWED_CONST_LIST from .option import ALLOWED_CONST_LIST
from .syndynoptiondescription import SynDynOptionDescription, SynDynMasterSlaves from .syndynoptiondescription import SynDynOptionDescription, SynDynLeadership
from ..error import ConfigError, ConflictError from ..error import ConfigError, ConflictError
@ -80,9 +80,9 @@ class CacheOptionDescription(BaseOption):
properties = option.impl_getproperties() properties = option.impl_getproperties()
if 'force_store_value' in properties: if 'force_store_value' in properties:
if __debug__: if __debug__:
if option.impl_is_master_slaves('slave'): if option.impl_is_follower():
# problem with index # problem with index
raise ConfigError(_('the slave "{0}" cannot have ' raise ConfigError(_('the follower "{0}" cannot have '
'"force_store_value" property').format( '"force_store_value" property').format(
option.impl_get_display_name())) option.impl_get_display_name()))
if option.issubdyn(): if option.issubdyn():
@ -92,28 +92,28 @@ class CacheOptionDescription(BaseOption):
force_store_values.append((subpath, option)) force_store_values.append((subpath, option))
if __debug__ and 'force_default_on_freeze' in properties and \ if __debug__ and 'force_default_on_freeze' in properties and \
'frozen' not in properties and \ 'frozen' not in properties and \
option.impl_is_master_slaves('master'): option.impl_is_leader():
raise ConfigError(_('a master ({0}) cannot have ' raise ConfigError(_('a leader ({0}) cannot have '
'"force_default_on_freeze" property without "frozen"' '"force_default_on_freeze" property without "frozen"'
'').format(subpath)) '').format(subpath))
for cons_id, func, all_cons_opts, params in option.get_consistencies(): for cons_id, func, all_cons_opts, params in option.get_consistencies():
option._valid_consistencies(all_cons_opts[1:], init=False) option._valid_consistencies(all_cons_opts[1:], init=False)
if func not in ALLOWED_CONST_LIST and is_multi: if func not in ALLOWED_CONST_LIST and is_multi:
if __debug__ and not option.impl_is_master_slaves(): if __debug__ and not option.impl_get_leadership():
raise ConfigError(_('malformed consistency option "{0}" ' raise ConfigError(_('malformed consistency option "{0}" '
'must be a masterslaves').format( 'must be a leadership').format(
option.impl_getname())) option.impl_getname()))
masterslaves = option.impl_get_master_slaves() leadership = option.impl_get_leadership()
for weak_opt in all_cons_opts: for weak_opt in all_cons_opts:
opt = weak_opt() opt = weak_opt()
if __debug__ and func not in ALLOWED_CONST_LIST and is_multi: if __debug__ and func not in ALLOWED_CONST_LIST and is_multi:
if not opt.impl_is_master_slaves(): if not opt.impl_get_leadership():
raise ConfigError(_('malformed consistency option "{0}" ' raise ConfigError(_('malformed consistency option "{0}" '
'must not be a multi for "{1}"').format( 'must not be a multi for "{1}"').format(
option.impl_getname(), opt.impl_getname())) option.impl_getname(), opt.impl_getname()))
elif masterslaves != opt.impl_get_master_slaves(): elif leadership != opt.impl_get_leadership():
raise ConfigError(_('malformed consistency option "{0}" ' raise ConfigError(_('malformed consistency option "{0}" '
'must be in same masterslaves as "{1}"').format( 'must be in same leadership as "{1}"').format(
option.impl_getname(), opt.impl_getname())) option.impl_getname(), opt.impl_getname()))
_consistencies.setdefault(weak_opt, _consistencies.setdefault(weak_opt,
[]).append((_consistencies_id, []).append((_consistencies_id,
@ -126,25 +126,25 @@ class CacheOptionDescription(BaseOption):
self._add_dependency(option) self._add_dependency(option)
if __debug__: if __debug__:
is_slave = None is_follower = None
if is_multi: if is_multi:
all_requires = option.impl_getrequires() all_requires = option.impl_getrequires()
for requires in all_requires: for requires in all_requires:
for require in requires: for require in requires:
#if option in require is a multi: #if option in require is a multi:
# * option in require must be a master or a slave # * option in require must be a leader or a follower
# * current option must be a slave (and only a slave) # * current option must be a follower (and only a follower)
# * option in require and current option must be in same masterslaves # * option in require and current option must be in same leadership
for require_opt, values in require[0]: for require_opt, values in require[0]:
if require_opt.impl_is_multi(): if require_opt.impl_is_multi():
if is_slave is None: if is_follower is None:
is_slave = option.impl_is_master_slaves('slave') is_follower = option.impl_is_follower()
if is_slave: if is_follower:
masterslaves = option.impl_get_master_slaves() leadership = option.impl_get_leadership()
if is_slave and require_opt.impl_is_master_slaves(): if is_follower and require_opt.impl_get_leadership():
if masterslaves != require_opt.impl_get_master_slaves(): if leadership != require_opt.impl_get_leadership():
raise ValueError(_('malformed requirements option "{0}" ' raise ValueError(_('malformed requirements option "{0}" '
'must be in same masterslaves for "{1}"').format( 'must be in same leadership for "{1}"').format(
require_opt.impl_getname(), option.impl_getname())) require_opt.impl_getname(), option.impl_getname()))
else: else:
raise ValueError(_('malformed requirements option "{0}" ' raise ValueError(_('malformed requirements option "{0}" '
@ -311,7 +311,7 @@ class OptionDescription(OptionDescriptionWalk):
def impl_is_dynoptiondescription(self) -> bool: def impl_is_dynoptiondescription(self) -> bool:
return False return False
def impl_is_master_slaves(self) -> bool: def impl_is_leadership(self) -> bool:
return False return False
# ____________________________________________________________ # ____________________________________________________________
@ -319,7 +319,7 @@ class OptionDescription(OptionDescriptionWalk):
group_type: groups.GroupType) -> None: group_type: groups.GroupType) -> None:
"""sets a given group object to an OptionDescription """sets a given group object to an OptionDescription
:param group_type: an instance of `GroupType` or `MasterGroupType` :param group_type: an instance of `GroupType` or `LeadershipGroupType`
that lives in `setting.groups` that lives in `setting.groups`
""" """
if self._group_type != groups.default: if self._group_type != groups.default:
@ -329,8 +329,8 @@ class OptionDescription(OptionDescriptionWalk):
if not isinstance(group_type, groups.GroupType): if not isinstance(group_type, groups.GroupType):
raise ValueError(_('group_type: {0}' raise ValueError(_('group_type: {0}'
' not allowed').format(group_type)) ' not allowed').format(group_type))
if isinstance(group_type, groups.MasterGroupType): if isinstance(group_type, groups.LeadershipGroupType):
raise ConfigError('please use MasterSlaves object instead of OptionDescription') raise ConfigError('please use Leadership object instead of OptionDescription')
self._group_type = group_type self._group_type = group_type
def impl_get_group_type(self) -> groups.GroupType: def impl_get_group_type(self) -> groups.GroupType:

View File

@ -104,16 +104,15 @@ class SynDynOptionDescription:
return self._opt.impl_get_display_name() + self._suffix return self._opt.impl_get_display_name() + self._suffix
class SynDynMasterSlaves(SynDynOptionDescription): class SynDynLeadership(SynDynOptionDescription):
def get_leader(self) -> SynDynOption:
def getmaster(self) -> SynDynOption: return self._opt.get_leader().to_dynoption(self.impl_getpath(),
return self._opt.getmaster().to_dynoption(self.impl_getpath(),
self._suffix) self._suffix)
def getslaves(self) -> Iterator[SynDynOption]: def get_followers(self) -> Iterator[SynDynOption]:
subpath = self.impl_getpath() subpath = self.impl_getpath()
for slave in self._opt.getslaves(): for follower in self._opt.get_followers():
yield slave.to_dynoption(subpath, yield follower.to_dynoption(subpath,
self._suffix) self._suffix)
def reset_cache(self, def reset_cache(self,
@ -121,11 +120,11 @@ class SynDynMasterSlaves(SynDynOptionDescription):
values: Values, values: Values,
settings: Settings, settings: Settings,
resetted_opts: List[str]) -> None: resetted_opts: List[str]) -> None:
master = self.getmaster() leader = self.get_leader()
slaves = self.getslaves() followers = self.get_followers()
self._reset_cache(path, self._reset_cache(path,
master, leader,
slaves, followers,
values, values,
settings, settings,
resetted_opts) resetted_opts)
@ -134,5 +133,5 @@ class SynDynMasterSlaves(SynDynOptionDescription):
*args, *args,
**kwargs) -> None: **kwargs) -> None:
self._opt.pop(*args, self._opt.pop(*args,
slaves=self.getslaves(), followers=self.get_followers(),
**kwargs) **kwargs)

View File

@ -75,7 +75,7 @@ everything_frozen
property) property)
empty empty
raise mandatory PropertiesOptionError if multi or master have empty value raise mandatory PropertiesOptionError if multi or leader have empty value
validator validator
launch validator set by user in option (this property has no effect launch validator set by user in option (this property has no effect
@ -258,7 +258,7 @@ class GroupModule(_NameSpace):
"emulates a module to manage unique group (OptionDescription) names" "emulates a module to manage unique group (OptionDescription) names"
class GroupType(str): class GroupType(str):
"""allowed normal group (OptionDescription) names """allowed normal group (OptionDescription) names
*normal* means : groups that are not master *normal* means : groups that are not leader
""" """
pass pass
@ -266,9 +266,9 @@ class GroupModule(_NameSpace):
"""groups that are default (typically 'default')""" """groups that are default (typically 'default')"""
pass pass
class MasterGroupType(GroupType): class LeadershipGroupType(GroupType):
"""allowed normal group (OptionDescription) names """allowed normal group (OptionDescription) names
*master* means : groups that have the 'master' attribute set *leadership* means : groups that have the 'leadership' attribute set
""" """
pass pass
@ -301,12 +301,12 @@ groups = GroupModule()
default group set when creating a new optiondescription""" default group set when creating a new optiondescription"""
groups.default = groups.DefaultGroupType('default') groups.default = groups.DefaultGroupType('default')
"""groups.master """groups.leadership
master group is a special optiondescription, all suboptions should be leadership group is a special optiondescription, all suboptions should be
multi option and all values should have same length, to find master's multi option and all values should have same length, to find leader's
option, the optiondescription's name should be same than de master's option, the optiondescription's name should be same than de leader's
option""" option"""
groups.master = groups.MasterGroupType('master') groups.leadership = groups.LeadershipGroupType('leadership')
""" groups.family """ groups.family
example of group, no special behavior with this group's type""" example of group, no special behavior with this group's type"""
@ -520,7 +520,7 @@ class Settings(object):
"'{1}'").format(option_bag.path, reqpath)) "'{1}'").format(option_bag.path, reqpath))
idx = None idx = None
is_indexed = False is_indexed = False
if option.impl_is_master_slaves('slave'): if option.impl_is_follower():
idx = option_bag.index idx = option_bag.index
elif option.impl_is_multi() and option_bag.index is not None: elif option.impl_is_multi() and option_bag.index is not None:
is_indexed = True is_indexed = True
@ -638,13 +638,13 @@ class Settings(object):
"").format(opt.impl_get_display_name())) "").format(opt.impl_get_display_name()))
if 'force_default_on_freeze' in properties and \ if 'force_default_on_freeze' in properties and \
'frozen' not in properties and \ 'frozen' not in properties and \
opt.impl_is_master_slaves('master'): opt.impl_is_leader():
raise ConfigError(_('a master ({0}) cannot have ' raise ConfigError(_('a leader ({0}) cannot have '
'"force_default_on_freeze" property without "frozen"' '"force_default_on_freeze" property without "frozen"'
'').format(opt.impl_get_display_name())) '').format(opt.impl_get_display_name()))
self._p_.setproperties(path, self._p_.setproperties(path,
properties) properties)
#values too because of slave values could have a PropertiesOptionError has value # values too because of follower values could have a PropertiesOptionError has value
context.cfgimpl_reset_cache(option_bag) context.cfgimpl_reset_cache(option_bag)
if option_bag is not None: if option_bag is not None:
del option_bag.properties del option_bag.properties

View File

@ -36,7 +36,7 @@ class Cache(DictCache):
def setcache(self, path, index, val, self_props, props): def setcache(self, path, index, val, self_props, props):
"""add val in cache for a specified path """add val in cache for a specified path
if slave, add index if follower, add index
""" """
if 'cache' in props or 'cache' in self_props: if 'cache' in props or 'cache' in self_props:
if DEBUG: if DEBUG:

View File

@ -98,15 +98,15 @@ class Values(object):
"""actually retrieves the value """actually retrieves the value
:param path: the path of the `Option` :param path: the path of the `Option`
:param index: index for a slave `Option` :param index: index for a follower `Option`
:returns: value :returns: value
""" """
# get owner and value from store # get owner and value from store
# index allowed only for slave # index allowed only for follower
index = option_bag.index index = option_bag.index
is_slave = option_bag.option.impl_is_master_slaves('slave') is_follower = option_bag.option.impl_is_follower()
if index is None or not is_slave: if index is None or not is_follower:
_index = None _index = None
else: else:
_index = index _index = index
@ -231,7 +231,7 @@ class Values(object):
else: else:
allow_empty_list = opt.impl_allow_empty_list() allow_empty_list = opt.impl_allow_empty_list()
if allow_empty_list is undefined: if allow_empty_list is undefined:
allow_empty_list = opt.impl_is_master_slaves('slave') allow_empty_list = opt.impl_is_follower()
isempty = value is None or (not allow_empty_list and value == []) or \ isempty = value is None or (not allow_empty_list and value == []) or \
None in value or empty in value None in value or empty in value
else: else:
@ -315,11 +315,11 @@ class Values(object):
meta = context.cfgimpl_get_meta() meta = context.cfgimpl_get_meta()
if meta is None: if meta is None:
return None return None
if option_bag.option.impl_is_master_slaves('slave'): if option_bag.option.impl_is_follower():
master = option_bag.option.impl_get_master_slaves().getmaster() leader = option_bag.option.impl_get_leadership().get_leader()
masterp = master.impl_getpath() leaderpath = leader.impl_getpath()
# slave could be a "meta" only if master hasn't value # follower could be a "meta" only if leader hasn't value
if self._p_.hasvalue(masterp, if self._p_.hasvalue(leaderpath,
index=None): index=None):
return None return None
doption_bag = option_bag.copy() doption_bag = option_bag.copy()
@ -432,8 +432,8 @@ class Values(object):
fake_value.setvalue_validation(value, fake_value.setvalue_validation(value,
soption_bag) soption_bag)
opt = option_bag.option opt = option_bag.option
if opt.impl_is_master_slaves('master'): if opt.impl_is_leader():
opt.impl_get_master_slaves().reset(self, opt.impl_get_leadership().reset(self,
option_bag, option_bag,
_commit=_commit) _commit=_commit)
if hasvalue: if hasvalue:
@ -449,7 +449,7 @@ class Values(object):
_commit) _commit)
context.cfgimpl_reset_cache(option_bag) context.cfgimpl_reset_cache(option_bag)
def reset_slave(self, def reset_follower(self,
option_bag, option_bag,
_commit=True): _commit=True):
@ -463,7 +463,7 @@ class Values(object):
config_bag.context = fake_context config_bag.context = fake_context
soption_bag = option_bag.copy() soption_bag = option_bag.copy()
soption_bag.config_bag = config_bag soption_bag.config_bag = config_bag
fake_value.reset_slave(soption_bag) fake_value.reset_follower(soption_bag)
value = fake_value.getdefaultvalue(soption_bag) value = fake_value.getdefaultvalue(soption_bag)
fake_value.setvalue_validation(value, fake_value.setvalue_validation(value,
soption_bag) soption_bag)
@ -472,7 +472,7 @@ class Values(object):
_commit) _commit)
context.cfgimpl_reset_cache(option_bag) context.cfgimpl_reset_cache(option_bag)
def reset_master(self, def reset_leadership(self,
index, index,
option_bag, option_bag,
subconfig): subconfig):
@ -552,7 +552,7 @@ class Values(object):
elif not option.impl_is_symlinkoption(): elif not option.impl_is_symlinkoption():
# don't verifying symlink # don't verifying symlink
try: try:
if not option.impl_is_master_slaves('slave'): if not option.impl_is_follower():
option_bag = OptionBag() option_bag = OptionBag()
option_bag.set_option(option, option_bag.set_option(option,
path, path,