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