refactor masterslaves
This commit is contained in:
@ -405,8 +405,13 @@ def _autocheck_get_value(api, path, conf, **kwargs):
|
||||
def autocheck_get_value(api, path, confread, confwrite, **kwargs):
|
||||
_set_value(api, path, confwrite, set_permissive=False, **kwargs)
|
||||
_autocheck_get_value(api, path, confread, set_permissive=False, **kwargs)
|
||||
if path.endswith('val1'):
|
||||
val2_path = path.replace('val1', 'val2')
|
||||
_autocheck_default_value(api, val2_path, confread, **kwargs)
|
||||
if confread != confwrite:
|
||||
_autocheck_get_value(api, path, confwrite, set_permissive=False, **kwargs)
|
||||
if path.endswith('val1'):
|
||||
_autocheck_default_value(api, val2_path, confwrite, **kwargs)
|
||||
|
||||
|
||||
@autocheck
|
||||
@ -528,7 +533,11 @@ def autocheck_append_value(api, path, confread, confwrite, **kwargs):
|
||||
len_new = len(new_master_value)
|
||||
assert len_value + 1 == len_new
|
||||
assert new_master_value[-1] == kwargs['default_multi']
|
||||
slave_path = path.rsplit('.', 1)[0] + '.third'
|
||||
slave_path = path.rsplit('.', 1)[0]
|
||||
if slave_path.endswith('val1') or slave_path.endswith('val2'):
|
||||
slave_path += '.third' + slave_path[-4:]
|
||||
else:
|
||||
slave_path += '.third'
|
||||
for idx in range(len_new):
|
||||
assert api.forcepermissive.config(confread).option(slave_path, idx).value.get() == kwargs['default_multi']
|
||||
#
|
||||
@ -552,17 +561,21 @@ def autocheck_pop_value(api, path, confread, confwrite, **kwargs):
|
||||
if not kwargs.get('propertyerror', False):
|
||||
if not submulti_:
|
||||
values = ['value1', 'value2', 'value3', 'value4']
|
||||
slave = 'slave'
|
||||
slave_value = 'slave'
|
||||
else:
|
||||
values = [['value1'], ['value2'], ['value3'], ['value4']]
|
||||
slave = ['slave']
|
||||
slaves = [kwargs['default_multi'], slave, kwargs['default_multi'], kwargs['default_multi']]
|
||||
a_slave = path.rsplit('.', 1)[0] + '.third'
|
||||
slave_value = ['slave']
|
||||
slaves = [kwargs['default_multi'], slave_value, kwargs['default_multi'], kwargs['default_multi']]
|
||||
a_slave = path.rsplit('.', 1)[0]
|
||||
if a_slave.endswith('val1') or a_slave.endswith('val2'):
|
||||
a_slave += '.third' + a_slave[-4:]
|
||||
else:
|
||||
a_slave += '.third'
|
||||
api.forcepermissive.config(confwrite).option(path).value.set(values)
|
||||
api.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave)
|
||||
api.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave_value)
|
||||
api.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi']
|
||||
assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True
|
||||
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave
|
||||
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value
|
||||
assert api.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False
|
||||
api.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi']
|
||||
assert api.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True
|
||||
@ -572,13 +585,13 @@ def autocheck_pop_value(api, path, confread, confwrite, **kwargs):
|
||||
api.forcepermissive.config(confwrite).option(path).value.pop(3)
|
||||
api.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi']
|
||||
assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True
|
||||
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave
|
||||
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value
|
||||
assert api.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False
|
||||
api.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi']
|
||||
assert api.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True
|
||||
#
|
||||
api.forcepermissive.config(confwrite).option(path).value.pop(0)
|
||||
api.forcepermissive.config(confread).option(a_slave, 0).value.get() == slave
|
||||
api.forcepermissive.config(confread).option(a_slave, 0).value.get() == slave_value
|
||||
assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is False
|
||||
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == kwargs['default_multi']
|
||||
assert api.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is True
|
||||
@ -623,13 +636,15 @@ def autocheck_display(api, path, confread, confwrite, **kwargs):
|
||||
return
|
||||
make_dict = kwargs['make_dict']
|
||||
make_dict_value = kwargs['make_dict_value']
|
||||
#print('--------')
|
||||
#print(make_dict)
|
||||
#print(make_dict_value)
|
||||
#print(api.config(confread).config.make_dict())
|
||||
assert api.config(confread).config.make_dict() == make_dict
|
||||
if confread != confwrite:
|
||||
assert(api.config(confwrite).config.make_dict()) == make_dict
|
||||
_set_value(api, path, confwrite, **kwargs)
|
||||
#print('--')
|
||||
#print(make_dict_value)
|
||||
#print(api.config(confread).config.make_dict())
|
||||
assert api.config(confread).config.make_dict() == make_dict_value
|
||||
if confread != confwrite:
|
||||
@ -1129,13 +1144,6 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
|
||||
else:
|
||||
default_value = value
|
||||
kwargs['default'] = default_value
|
||||
if '.' in path:
|
||||
if paths.get(path, {}) is None:
|
||||
isslave = False
|
||||
else:
|
||||
isslave = paths.get(path, {}).get(path.rsplit('.', 1)[0], {}).get('master') is True and not path.endswith('.first')
|
||||
if isslave and not multi is submulti:
|
||||
kwargs['default'] = None
|
||||
|
||||
is_dyn = False
|
||||
is_master = False
|
||||
@ -1146,20 +1154,21 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
|
||||
break
|
||||
if '.' in cpath:
|
||||
dirname, name = cpath.split('.')[-2:]
|
||||
for dname in cpath.split('.')[:-1]:
|
||||
if options.get(dname, {}).get('dyn'):
|
||||
is_dyn = True
|
||||
if options.get(dname, {}).get('master'):
|
||||
is_master = True
|
||||
else:
|
||||
dirname = ''
|
||||
name = cpath
|
||||
if options.get(dirname, {}).get('hidden'):
|
||||
continue
|
||||
if options.get(dirname, {}).get('dyn'):
|
||||
is_dyn = True
|
||||
if options.get(dirname, {}).get('master'):
|
||||
is_master = True
|
||||
no_propertieserror = not options.get(name, {}).get('disabled') and not options.get(name, {}).get('hidden')
|
||||
allow_req = require and req
|
||||
no_propertieserror = not options.get(name, {}).get('disabled') and not options.get(name, {}).get('hidden')
|
||||
if is_dyn:
|
||||
dyns.append(no_propertieserror or allow_req)
|
||||
elif no_propertieserror or allow_req:
|
||||
if not is_dyn and (no_propertieserror or allow_req):
|
||||
dico[cpath] = default_value
|
||||
if path == cpath:
|
||||
dico_value[cpath] = value
|
||||
@ -1167,7 +1176,12 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
|
||||
dico_value[cpath] = default_value
|
||||
|
||||
has_value = True
|
||||
if is_dyn:
|
||||
isslave = False
|
||||
if '.' in path and is_master and not path.rsplit('.', 1)[1].startswith('first'):
|
||||
isslave = True
|
||||
if not multi is submulti:
|
||||
kwargs['default'] = None
|
||||
if is_dyn and dyns:
|
||||
idx = 0
|
||||
for cpath in list(paths.keys())[len(dyns):]:
|
||||
if dyns[idx]:
|
||||
@ -1198,18 +1212,30 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
|
||||
value = None
|
||||
if is_dyn:
|
||||
dico[cpath + 'extraoptconsistencyval1'] = value
|
||||
dico[cpath[:-2] + '2.' + 'extraoptconsistencyval2'] = value
|
||||
dico_value[cpath + 'extraoptconsistencyval1'] = value
|
||||
dico_value[cpath[:-2] + '2.' + 'extraoptconsistencyval2'] = value
|
||||
if is_master:
|
||||
spath = cpath.split('.')
|
||||
spath[-2] = spath[-2][:-1] + '2'
|
||||
spath[-3] = spath[-3][:-1] + '2'
|
||||
npath = '.'.join(spath) + 'extraoptconsistencyval2'
|
||||
else:
|
||||
npath = cpath[:-2] + '2.' + 'extraoptconsistencyval2'
|
||||
dico[npath] = value
|
||||
dico_value[npath] = value
|
||||
else:
|
||||
dico[cpath + 'extraoptconsistency'] = value
|
||||
dico_value[cpath + 'extraoptconsistency'] = value
|
||||
if is_master:
|
||||
for cpath in list(paths.keys())[len(dyns):]:
|
||||
if cpath.endswith('.first'):
|
||||
if cpath.endswith('.first') or cpath.endswith('.firstval1') or cpath.endswith('.firstval2'):
|
||||
second_path = cpath.rsplit('.', 1)[0] + '.second'
|
||||
third_path = cpath.rsplit('.', 1)[0] + '.third'
|
||||
cons_path = cpath.rsplit('.', 1)[0] + '.extraoptconsistency'
|
||||
if is_dyn:
|
||||
suffix = cpath[-4:]
|
||||
second_path += suffix
|
||||
third_path += suffix
|
||||
cons_path += suffix
|
||||
#
|
||||
if default_multi:
|
||||
if multi is not submulti:
|
||||
@ -1237,11 +1263,9 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
|
||||
dico_value[second_path] = [dvalue] * len_master
|
||||
if third_path in dico_value:
|
||||
dico_value[third_path] = [dvalue] * len_master
|
||||
cons_path = cpath.rsplit('.', 1)[0] + '.extraoptconsistency'
|
||||
if cons_path in dico_value:
|
||||
dico_value[cons_path] = [dvalue] * len_master
|
||||
break
|
||||
return dico, dico_value
|
||||
return is_dyn, dico, dico_value
|
||||
if DISPLAY:
|
||||
text = u' {} launch tests for {}'.format(ICON, path)
|
||||
if multi is True:
|
||||
@ -1267,7 +1291,7 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
|
||||
confwrite = confread = None
|
||||
idx = 0
|
||||
for req in requires:
|
||||
kwargs['make_dict'], kwargs['make_dict_value'] = _build_make_dict()
|
||||
is_dyn, kwargs['make_dict'], kwargs['make_dict_value'] = _build_make_dict()
|
||||
kwargs['callback'] = callback
|
||||
for func in autocheck_registers:
|
||||
cfg_name = 'conftest' + str(idx)
|
||||
@ -1283,6 +1307,11 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
|
||||
if api.unrestraint.option(path).option.isslave():
|
||||
dirname = path.rsplit('.', 1)[0]
|
||||
master_path = dirname + '.first'
|
||||
master_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')
|
||||
if multi is submulti:
|
||||
value = SUBLIST_SECOND_VALUE
|
||||
else:
|
||||
@ -1290,6 +1319,10 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
|
||||
api.option(master_path).value.set(value)
|
||||
ckwargs['make_dict'][master_path] = value
|
||||
ckwargs['make_dict_value'][master_path] = value
|
||||
if master_path_2:
|
||||
api.option(master_path_2).value.set(value)
|
||||
ckwargs['make_dict'][master_path_2] = value
|
||||
ckwargs['make_dict_value'][master_path_2] = value
|
||||
if default_multi:
|
||||
if multi is not submulti:
|
||||
dvalue = SECOND_VALUE
|
||||
@ -1299,19 +1332,33 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
|
||||
dvalue = []
|
||||
else:
|
||||
dvalue = None
|
||||
if dirname + '.second' in ckwargs['make_dict']:
|
||||
ckwargs['make_dict'][dirname + '.second'] = [dvalue] * len(value)
|
||||
ckwargs['make_dict_value'][dirname + '.second'] = [dvalue] * len(value)
|
||||
if path == dirname + '.second':
|
||||
ckwargs['make_dict_value'][dirname + '.second'][-1] = ckwargs['make_dict_value'][master_path][-1]
|
||||
if dirname + '.third' in ckwargs['make_dict']:
|
||||
ckwargs['make_dict'][dirname + '.third'] = [dvalue] * len(value)
|
||||
ckwargs['make_dict_value'][dirname + '.third'] = [dvalue] * len(value)
|
||||
if path == dirname + '.third':
|
||||
ckwargs['make_dict_value'][dirname + '.third'][-1] = ckwargs['make_dict_value'][master_path][-1]
|
||||
if dirname + '.extraoptconsistency' in ckwargs['make_dict']:
|
||||
ckwargs['make_dict'][dirname + '.extraoptconsistency'] = [dvalue] * len(value)
|
||||
ckwargs['make_dict_value'][dirname + '.extraoptconsistency'] = [dvalue] * len(value)
|
||||
def do(suffix, oldsuffix=None):
|
||||
if suffix:
|
||||
ldirname = dirname.replace(oldsuffix, suffix)
|
||||
else:
|
||||
ldirname = dirname
|
||||
npath = ldirname + '.second' + suffix
|
||||
if npath in ckwargs['make_dict']:
|
||||
ckwargs['make_dict'][npath] = [dvalue] * len(value)
|
||||
ckwargs['make_dict_value'][npath] = [dvalue] * len(value)
|
||||
if path == npath:
|
||||
ckwargs['make_dict_value'][npath][-1] = ckwargs['make_dict_value'][master_path][-1]
|
||||
npath = ldirname + '.third' + suffix
|
||||
if npath in ckwargs['make_dict']:
|
||||
ckwargs['make_dict'][npath] = [dvalue] * len(value)
|
||||
ckwargs['make_dict_value'][npath] = [dvalue] * len(value)
|
||||
if path == npath:
|
||||
ckwargs['make_dict_value'][npath][-1] = ckwargs['make_dict_value'][master_path][-1]
|
||||
npath = ldirname + '.extraoptconsistency' + suffix
|
||||
if npath in ckwargs['make_dict']:
|
||||
ckwargs['make_dict'][npath] = [dvalue] * len(value)
|
||||
ckwargs['make_dict_value'][npath] = [dvalue] * len(value)
|
||||
if not is_dyn:
|
||||
do('')
|
||||
else:
|
||||
#do(dirname[-4:])
|
||||
do('val1', 'val2')
|
||||
do('val2', 'val1')
|
||||
|
||||
#FIXME devrait etre dans la config ca ...
|
||||
api.read_write()
|
||||
@ -1478,11 +1525,15 @@ def make_conf(options, meta, multi, default, default_multi, require, consistency
|
||||
local_collect_options = local_collect_options[optiondescription]
|
||||
local_collect_options['properties'].update(option.get(optiondescription, {}))
|
||||
option_name = path.split('.')[-1]
|
||||
in_master = False
|
||||
if '.' in path:
|
||||
name_od = path.rsplit('.', 1)[0]
|
||||
else:
|
||||
name_od = ''
|
||||
in_master = collect_options.get(name_od, {}).get('properties', {}).get('master')
|
||||
if '.' in name_od:
|
||||
subod, name_od = name_od.split('.')
|
||||
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 = make_option(option_name, option.get(option_name), in_master, master)
|
||||
if obj is None:
|
||||
@ -1517,18 +1568,10 @@ DICT_PATHS = [
|
||||
('second', {'second': {'disabled': True}}),
|
||||
('third', {'third': {'hidden': True}})
|
||||
]),
|
||||
#test a config with an optiondescription
|
||||
OrderedDict([('subod.first', {}),
|
||||
('subod.second', {'second': {'disabled': True}}),
|
||||
('subod.third', {'third': {'hidden': True}})]),
|
||||
#test a config with two optiondescription
|
||||
OrderedDict([('subod.subsubod.first', {}),
|
||||
('subod.subsubod.second', {'second': {'disabled': True}}),
|
||||
('subod.subsubod.third', {'third': {'hidden': True}})]),
|
||||
#test a config with mix of different optiondescription
|
||||
OrderedDict([('first', {}),
|
||||
('subod.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}}),
|
||||
@ -1566,7 +1609,17 @@ DICT_PATHS = [
|
||||
('subod.subsubodval1.thirdval1', None),
|
||||
('subod.subsubodval2.firstval2', None),
|
||||
('subod.subsubodval2.secondval2', None),
|
||||
('subod.subsubodval2.thirdval2', 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}}),
|
||||
('subodval1.subsubodval1.firstval1', None),
|
||||
('subodval1.subsubodval1.secondval1', None),
|
||||
('subodval1.subsubodval1.thirdval1', None),
|
||||
('subodval2.subsubodval2.firstval2', None),
|
||||
('subodval2.subsubodval2.secondval2', None),
|
||||
('subodval2.subsubodval2.thirdval2', None)]),
|
||||
]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user