synchronise config_bag and context
This commit is contained in:
parent
d61d1c2931
commit
4b0c142e3e
|
@ -291,9 +291,7 @@ def test_consistency_not_equal_masterslave_error_othermaster():
|
||||||
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 = MasterSlaves('a', '', [a, b])
|
||||||
#od.impl_set_group_type(groups.master)
|
|
||||||
od2 = MasterSlaves('c', '', [c, d])
|
od2 = MasterSlaves('c', '', [c, d])
|
||||||
#od2.impl_set_group_type(groups.master)
|
|
||||||
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)")
|
||||||
|
@ -304,7 +302,6 @@ def test_consistency_not_equal_masterslaves_default():
|
||||||
b = IntOption('b', '', multi=True, default_multi=1)
|
b = IntOption('b', '', multi=True, default_multi=1)
|
||||||
od = MasterSlaves('a', '', [a, b])
|
od = MasterSlaves('a', '', [a, b])
|
||||||
od2 = OptionDescription('a', '', [od])
|
od2 = OptionDescription('a', '', [od])
|
||||||
#od.impl_set_group_type(groups.master)
|
|
||||||
a.impl_add_consistency('not_equal', b)
|
a.impl_add_consistency('not_equal', b)
|
||||||
api = Config(od2)
|
api = Config(od2)
|
||||||
assert api.option('a.a').value.get() == []
|
assert api.option('a.a').value.get() == []
|
||||||
|
|
|
@ -947,10 +947,12 @@ class KernelGroupConfig(_CommonConfig):
|
||||||
_sub=True))
|
_sub=True))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
cconfig_bag = config_bag.copy()
|
||||||
|
cconfig_bag.context = child
|
||||||
next(child.find(None,
|
next(child.find(None,
|
||||||
byname,
|
byname,
|
||||||
byvalue,
|
byvalue,
|
||||||
config_bag=config_bag,
|
config_bag=cconfig_bag,
|
||||||
raise_if_not_found=False,
|
raise_if_not_found=False,
|
||||||
only_path=bypath,
|
only_path=bypath,
|
||||||
only_option=byoption))
|
only_option=byoption))
|
||||||
|
@ -1121,8 +1123,10 @@ class KernelMetaConfig(KernelGroupConfig):
|
||||||
option,
|
option,
|
||||||
rconfig_bag)
|
rconfig_bag)
|
||||||
for child in self._impl_children:
|
for child in self._impl_children:
|
||||||
|
option_bag.config_bag.context = child
|
||||||
child.cfgimpl_get_values().reset(option_bag,
|
child.cfgimpl_get_values().reset(option_bag,
|
||||||
_commit=False)
|
_commit=False)
|
||||||
|
option_bag.config_bag.context = self
|
||||||
self.cfgimpl_get_values().reset(option_bag)
|
self.cfgimpl_get_values().reset(option_bag)
|
||||||
|
|
||||||
def new_config(self,
|
def new_config(self,
|
||||||
|
|
|
@ -125,7 +125,7 @@ class MasterSlaves(OptionDescription):
|
||||||
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 slave in self.getslaves():
|
||||||
slave_path = slave.impl_getpath(values._getcontext())
|
slave_path = slave.impl_getpath(option_bag.config_bag.context)
|
||||||
soption_bag = OptionBag()
|
soption_bag = OptionBag()
|
||||||
soption_bag.set_option(slave,
|
soption_bag.set_option(slave,
|
||||||
slave_path,
|
slave_path,
|
||||||
|
@ -140,7 +140,7 @@ class MasterSlaves(OptionDescription):
|
||||||
option_bag,
|
option_bag,
|
||||||
slaves=undefined):
|
slaves=undefined):
|
||||||
|
|
||||||
context = values._getcontext()
|
context = option_bag.config_bag.context
|
||||||
if slaves is undefined:
|
if slaves is undefined:
|
||||||
slaves = self.getslaves()
|
slaves = self.getslaves()
|
||||||
config_bag = option_bag.config_bag.copy()
|
config_bag = option_bag.config_bag.copy()
|
||||||
|
@ -191,7 +191,7 @@ class MasterSlaves(OptionDescription):
|
||||||
values,
|
values,
|
||||||
settings,
|
settings,
|
||||||
resetted_opts)
|
resetted_opts)
|
||||||
context = values._getcontext()
|
context = values.context()
|
||||||
mpath = master.impl_getpath(context)
|
mpath = master.impl_getpath(context)
|
||||||
master.reset_cache(mpath,
|
master.reset_cache(mpath,
|
||||||
values,
|
values,
|
||||||
|
|
|
@ -312,7 +312,6 @@ class Option(OnlyOption):
|
||||||
check_error,
|
check_error,
|
||||||
is_warnings_only)
|
is_warnings_only)
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
#raise err
|
|
||||||
if debug: # pragma: no cover
|
if debug: # pragma: no cover
|
||||||
log.debug('do_validation: value: {0}, index: {1}:'
|
log.debug('do_validation: value: {0}, index: {1}:'
|
||||||
' {2}'.format(val,
|
' {2}'.format(val,
|
||||||
|
@ -512,14 +511,15 @@ class Option(OnlyOption):
|
||||||
option_bag.fromconsistency = []
|
option_bag.fromconsistency = []
|
||||||
|
|
||||||
def _get_consistency_value(self,
|
def _get_consistency_value(self,
|
||||||
option_bag,
|
index,
|
||||||
current_option,
|
current_option,
|
||||||
|
fromoption,
|
||||||
|
fromconsistency,
|
||||||
cons_id,
|
cons_id,
|
||||||
context,
|
context,
|
||||||
config_bag,
|
config_bag,
|
||||||
value,
|
value,
|
||||||
func):
|
func):
|
||||||
index = option_bag.index
|
|
||||||
if func in ALLOWED_CONST_LIST:
|
if func in ALLOWED_CONST_LIST:
|
||||||
index = None
|
index = None
|
||||||
index_ = None
|
index_ = None
|
||||||
|
@ -527,7 +527,7 @@ class Option(OnlyOption):
|
||||||
index_ = None
|
index_ = None
|
||||||
else:
|
else:
|
||||||
index_ = index
|
index_ = index
|
||||||
if option_bag.ori_option == current_option:
|
if fromoption == current_option:
|
||||||
# orig_option is current option
|
# orig_option is current option
|
||||||
# we have already value, so use it
|
# we have already value, so use it
|
||||||
return value
|
return value
|
||||||
|
@ -541,9 +541,8 @@ class Option(OnlyOption):
|
||||||
path,
|
path,
|
||||||
index_,
|
index_,
|
||||||
config_bag)
|
config_bag)
|
||||||
cons_ids = option_bag.fromconsistency.copy()
|
fromconsistency.append(cons_id)
|
||||||
cons_ids.append(cons_id)
|
coption_bag.fromconsistency = fromconsistency
|
||||||
coption_bag.fromconsistency = cons_ids
|
|
||||||
|
|
||||||
opt_value = context.getattr(path,
|
opt_value = context.getattr(path,
|
||||||
coption_bag)
|
coption_bag)
|
||||||
|
@ -592,8 +591,10 @@ class Option(OnlyOption):
|
||||||
opt = opt()
|
opt = opt()
|
||||||
is_multi = False
|
is_multi = False
|
||||||
try:
|
try:
|
||||||
opt_value = self._get_consistency_value(option_bag,
|
opt_value = self._get_consistency_value(option_bag.index,
|
||||||
opt,
|
opt,
|
||||||
|
option_bag.ori_option,
|
||||||
|
option_bag.fromconsistency.copy(),
|
||||||
cons_id,
|
cons_id,
|
||||||
context,
|
context,
|
||||||
config_bag,
|
config_bag,
|
||||||
|
|
|
@ -45,20 +45,6 @@ class Values(object):
|
||||||
# store the storage
|
# store the storage
|
||||||
self._p_ = storage
|
self._p_ = storage
|
||||||
|
|
||||||
#______________________________________________________________________
|
|
||||||
# get context
|
|
||||||
|
|
||||||
def _getcontext(self):
|
|
||||||
"""context is a weakref so context could be None, we need to test it
|
|
||||||
context is None only if all reference to `Config` object is deleted
|
|
||||||
(for example we delete a `Config` and we manipulate a reference to
|
|
||||||
old `SubConfig`, `Values`, `Multi` or `Settings`)
|
|
||||||
"""
|
|
||||||
context = self.context()
|
|
||||||
if context is None: # pragma: no cover
|
|
||||||
raise ConfigError(_('the context does not exist anymore'))
|
|
||||||
return context
|
|
||||||
|
|
||||||
#______________________________________________________________________
|
#______________________________________________________________________
|
||||||
# get value
|
# get value
|
||||||
|
|
||||||
|
@ -82,10 +68,8 @@ class Values(object):
|
||||||
# no cached value so get value
|
# no cached value so get value
|
||||||
value = self.getvalue(option_bag)
|
value = self.getvalue(option_bag)
|
||||||
# validate value
|
# validate value
|
||||||
context = self._getcontext()
|
context = option_bag.config_bag.context
|
||||||
opt = option_bag.option
|
opt = option_bag.option
|
||||||
#print('===', option_bag.path)
|
|
||||||
#if not is_cached:
|
|
||||||
opt.impl_validate(value,
|
opt.impl_validate(value,
|
||||||
option_bag,
|
option_bag,
|
||||||
context=context,
|
context=context,
|
||||||
|
@ -157,8 +141,8 @@ class Values(object):
|
||||||
:type index: int
|
:type index: int
|
||||||
:returns: default value
|
:returns: default value
|
||||||
"""
|
"""
|
||||||
context = self._getcontext()
|
|
||||||
config_bag = option_bag.config_bag
|
config_bag = option_bag.config_bag
|
||||||
|
context = config_bag.context
|
||||||
opt = option_bag.option
|
opt = option_bag.option
|
||||||
index = option_bag.index
|
index = option_bag.index
|
||||||
def _reset_cache(_value):
|
def _reset_cache(_value):
|
||||||
|
@ -280,7 +264,7 @@ class Values(object):
|
||||||
option_bag,
|
option_bag,
|
||||||
_commit):
|
_commit):
|
||||||
|
|
||||||
context = self._getcontext()
|
context = option_bag.config_bag.context
|
||||||
owner = context.cfgimpl_get_settings().getowner()
|
owner = context.cfgimpl_get_settings().getowner()
|
||||||
if 'validator' in option_bag.config_bag.properties:
|
if 'validator' in option_bag.config_bag.properties:
|
||||||
if option_bag.index is not None or option_bag.option._has_consistencies(context):
|
if option_bag.index is not None or option_bag.option._has_consistencies(context):
|
||||||
|
@ -289,13 +273,15 @@ class Values(object):
|
||||||
tested_context = context._gen_fake_values()
|
tested_context = context._gen_fake_values()
|
||||||
config_bag = option_bag.config_bag.copy()
|
config_bag = option_bag.config_bag.copy()
|
||||||
config_bag.remove_validation()
|
config_bag.remove_validation()
|
||||||
|
config_bag.context = tested_context
|
||||||
soption_bag = option_bag.copy()
|
soption_bag = option_bag.copy()
|
||||||
soption_bag.config_bag = config_bag
|
soption_bag.config_bag = config_bag
|
||||||
tested_context.cfgimpl_get_values().setvalue(value,
|
tested_context.cfgimpl_get_values().setvalue(value,
|
||||||
soption_bag,
|
soption_bag,
|
||||||
True)
|
True)
|
||||||
tested_context.getattr(option_bag.path,
|
soption_bag.config_bag.properties = option_bag.config_bag.properties
|
||||||
option_bag)
|
tested_context.getattr(soption_bag.path,
|
||||||
|
soption_bag)
|
||||||
else:
|
else:
|
||||||
self.setvalue_validation(value,
|
self.setvalue_validation(value,
|
||||||
option_bag)
|
option_bag)
|
||||||
|
@ -309,7 +295,7 @@ class Values(object):
|
||||||
value,
|
value,
|
||||||
option_bag):
|
option_bag):
|
||||||
|
|
||||||
context = self._getcontext()
|
context = option_bag.config_bag.context
|
||||||
settings = context.cfgimpl_get_settings()
|
settings = context.cfgimpl_get_settings()
|
||||||
# First validate properties with this value
|
# First validate properties with this value
|
||||||
opt = option_bag.option
|
opt = option_bag.option
|
||||||
|
@ -334,7 +320,7 @@ class Values(object):
|
||||||
owner,
|
owner,
|
||||||
commit=True):
|
commit=True):
|
||||||
|
|
||||||
self._getcontext().cfgimpl_reset_cache(option_bag)
|
option_bag.config_bag.context.cfgimpl_reset_cache(option_bag)
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
# copy
|
# copy
|
||||||
value = value.copy()
|
value = value.copy()
|
||||||
|
@ -346,7 +332,7 @@ class Values(object):
|
||||||
|
|
||||||
def _is_meta(self,
|
def _is_meta(self,
|
||||||
option_bag):
|
option_bag):
|
||||||
context = self._getcontext()
|
context = option_bag.config_bag.context
|
||||||
meta = context.cfgimpl_get_meta()
|
meta = context.cfgimpl_get_meta()
|
||||||
if meta is None:
|
if meta is None:
|
||||||
return False
|
return False
|
||||||
|
@ -357,7 +343,11 @@ class Values(object):
|
||||||
if self._p_.hasvalue(masterp,
|
if self._p_.hasvalue(masterp,
|
||||||
index=None):
|
index=None):
|
||||||
return False
|
return False
|
||||||
return not meta.cfgimpl_get_values().is_default_owner(option_bag)
|
doption_bag = option_bag.copy()
|
||||||
|
config_bag = option_bag.config_bag.copy()
|
||||||
|
config_bag.context = meta
|
||||||
|
doption_bag.config_bag = config_bag
|
||||||
|
return not meta.cfgimpl_get_values().is_default_owner(doption_bag)
|
||||||
|
|
||||||
|
|
||||||
#______________________________________________________________________
|
#______________________________________________________________________
|
||||||
|
@ -382,7 +372,7 @@ class Values(object):
|
||||||
was present
|
was present
|
||||||
:returns: a `setting.owners.Owner` object
|
:returns: a `setting.owners.Owner` object
|
||||||
"""
|
"""
|
||||||
context = self._getcontext()
|
context = option_bag.config_bag.context
|
||||||
opt = option_bag.option
|
opt = option_bag.option
|
||||||
if opt.impl_is_symlinkoption():
|
if opt.impl_is_symlinkoption():
|
||||||
option_bag.ori_option = opt
|
option_bag.ori_option = opt
|
||||||
|
@ -407,7 +397,10 @@ class Values(object):
|
||||||
if owner is owners.default and validate_meta is not False and self._is_meta(option_bag):
|
if owner is owners.default and validate_meta is not False and self._is_meta(option_bag):
|
||||||
moption_bag = option_bag.copy()
|
moption_bag = option_bag.copy()
|
||||||
moption_bag.properties = frozenset()
|
moption_bag.properties = frozenset()
|
||||||
|
config_bag = moption_bag.config_bag.copy()
|
||||||
meta = context.cfgimpl_get_meta()
|
meta = context.cfgimpl_get_meta()
|
||||||
|
config_bag.context = meta
|
||||||
|
moption_bag.config_bag = config_bag
|
||||||
owner = meta.cfgimpl_get_values().getowner(moption_bag,
|
owner = meta.cfgimpl_get_values().getowner(moption_bag,
|
||||||
only_default=only_default)
|
only_default=only_default)
|
||||||
return owner
|
return owner
|
||||||
|
@ -431,7 +424,7 @@ class Values(object):
|
||||||
if not self._p_.hasvalue(option_bag.path):
|
if not self._p_.hasvalue(option_bag.path):
|
||||||
raise ConfigError(_('no value for {0} cannot change owner to {1}'
|
raise ConfigError(_('no value for {0} cannot change owner to {1}'
|
||||||
'').format(option_bag.path, owner))
|
'').format(option_bag.path, owner))
|
||||||
self._getcontext().cfgimpl_get_settings().validate_frozen(option_bag)
|
option_bag.config_bag.context.cfgimpl_get_settings().validate_frozen(option_bag)
|
||||||
self._p_.setowner(option_bag.path,
|
self._p_.setowner(option_bag.path,
|
||||||
owner,
|
owner,
|
||||||
index=option_bag.index)
|
index=option_bag.index)
|
||||||
|
@ -442,21 +435,23 @@ class Values(object):
|
||||||
option_bag,
|
option_bag,
|
||||||
_commit=True):
|
_commit=True):
|
||||||
|
|
||||||
context = self._getcontext()
|
context = option_bag.config_bag.context
|
||||||
setting = context.cfgimpl_get_settings()
|
setting = context.cfgimpl_get_settings()
|
||||||
hasvalue = self._p_.hasvalue(option_bag.path)
|
hasvalue = self._p_.hasvalue(option_bag.path)
|
||||||
|
|
||||||
if hasvalue and 'validator' in option_bag.config_bag.properties:
|
if hasvalue and 'validator' in option_bag.config_bag.properties:
|
||||||
|
fake_context = context._gen_fake_values()
|
||||||
config_bag = option_bag.config_bag.copy()
|
config_bag = option_bag.config_bag.copy()
|
||||||
config_bag.remove_validation()
|
config_bag.remove_validation()
|
||||||
|
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_context = context._gen_fake_values()
|
|
||||||
fake_value = fake_context.cfgimpl_get_values()
|
fake_value = fake_context.cfgimpl_get_values()
|
||||||
fake_value.reset(soption_bag)
|
fake_value.reset(soption_bag)
|
||||||
value = fake_value.getdefaultvalue(option_bag)
|
soption_bag.config_bag.properties = option_bag.config_bag.properties
|
||||||
|
value = fake_value.getdefaultvalue(soption_bag)
|
||||||
fake_value.setvalue_validation(value,
|
fake_value.setvalue_validation(value,
|
||||||
option_bag)
|
soption_bag)
|
||||||
opt = option_bag.option
|
opt = option_bag.option
|
||||||
if opt.impl_is_master_slaves('master'):
|
if opt.impl_is_master_slaves('master'):
|
||||||
opt.impl_get_master_slaves().reset(self,
|
opt.impl_get_master_slaves().reset(self,
|
||||||
|
@ -482,12 +477,13 @@ class Values(object):
|
||||||
option_bag):
|
option_bag):
|
||||||
|
|
||||||
if self._p_.hasvalue(option_bag.path, index=option_bag.index):
|
if self._p_.hasvalue(option_bag.path, index=option_bag.index):
|
||||||
context = self._getcontext()
|
context = option_bag.config_bag.context
|
||||||
if 'validator' in option_bag.config_bag.properties:
|
if 'validator' in option_bag.config_bag.properties:
|
||||||
fake_context = context._gen_fake_values()
|
fake_context = context._gen_fake_values()
|
||||||
fake_value = fake_context.cfgimpl_get_values()
|
fake_value = fake_context.cfgimpl_get_values()
|
||||||
config_bag = option_bag.config_bag.copy()
|
config_bag = option_bag.config_bag.copy()
|
||||||
config_bag.remove_validation()
|
config_bag.remove_validation()
|
||||||
|
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_slave(soption_bag)
|
||||||
|
@ -611,7 +607,7 @@ class Values(object):
|
||||||
|
|
||||||
:returns: generator of mandatory Option's path
|
:returns: generator of mandatory Option's path
|
||||||
"""
|
"""
|
||||||
context = self._getcontext()
|
context = config_bag.context
|
||||||
# copy
|
# copy
|
||||||
od_setting_properties = config_bag.properties - {'mandatory', 'empty'}
|
od_setting_properties = config_bag.properties - {'mandatory', 'empty'}
|
||||||
setting_properties = set(config_bag.properties) - {'warnings'}
|
setting_properties = set(config_bag.properties) - {'warnings'}
|
||||||
|
|
Loading…
Reference in New Issue