master/slaves => leader/followers

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

View File

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