force_store_value for follower
This commit is contained in:
parent
1bcad4d7ed
commit
709c0bf228
|
@ -76,8 +76,7 @@ class Values(object):
|
||||||
option_bag,
|
option_bag,
|
||||||
check_error=True)
|
check_error=True)
|
||||||
# store value in cache
|
# store value in cache
|
||||||
properties = option_bag.config_bag.properties
|
validator = 'validator' in setting_properties and 'demoting_error_warning' not in setting_properties
|
||||||
validator = 'validator' in properties and 'demoting_error_warning' not in properties
|
|
||||||
if not is_cached or validator:
|
if not is_cached or validator:
|
||||||
cache.setcache(option_bag.path,
|
cache.setcache(option_bag.path,
|
||||||
option_bag.index,
|
option_bag.index,
|
||||||
|
@ -102,7 +101,7 @@ class Values(object):
|
||||||
if 'force_metaconfig_on_freeze' in option_bag.properties:
|
if 'force_metaconfig_on_freeze' in option_bag.properties:
|
||||||
settings = option_bag.config_bag.context.cfgimpl_get_settings()
|
settings = option_bag.config_bag.context.cfgimpl_get_settings()
|
||||||
if 'force_metaconfig_on_freeze' in option_bag.option.impl_getproperties() and \
|
if 'force_metaconfig_on_freeze' in option_bag.option.impl_getproperties() and \
|
||||||
not settings._p_.getproperties(option_bag.path, frozenset()):
|
not settings._p_.getproperties(option_bag.path, None, frozenset()):
|
||||||
# if force_metaconfig_on_freeze is only in option (not in config)
|
# if force_metaconfig_on_freeze is only in option (not in config)
|
||||||
return option_bag.config_bag.context.impl_type == 'config'
|
return option_bag.config_bag.context.impl_type == 'config'
|
||||||
else:
|
else:
|
||||||
|
@ -150,11 +149,12 @@ class Values(object):
|
||||||
value = self.calc_value(option_bag, value)
|
value = self.calc_value(option_bag, value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def calc_value(self, option_bag, value):
|
def calc_value(self, option_bag, value, reset_cache=True):
|
||||||
if isinstance(value, Calculation):
|
if isinstance(value, Calculation):
|
||||||
value = value.execute(option_bag)
|
value = value.execute(option_bag, leadership_must_have_index=True)
|
||||||
elif isinstance(value, (list, tuple)):
|
elif isinstance(value, (list, tuple)):
|
||||||
value = list(self._do_value_list(value, option_bag))
|
value = list(self._do_value_list(value, option_bag))
|
||||||
|
if reset_cache:
|
||||||
self.calculate_reset_cache(option_bag, value)
|
self.calculate_reset_cache(option_bag, value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -267,13 +267,7 @@ class Values(object):
|
||||||
"convenience method to know if an option is empty"
|
"convenience method to know if an option is empty"
|
||||||
empty = opt._empty
|
empty = opt._empty
|
||||||
if index in [None, undefined] and opt.impl_is_multi():
|
if index in [None, undefined] and opt.impl_is_multi():
|
||||||
if force_allow_empty_list:
|
isempty = value is None or (not force_allow_empty_list and value == []) or \
|
||||||
allow_empty_list = True
|
|
||||||
else:
|
|
||||||
allow_empty_list = opt.impl_allow_empty_list()
|
|
||||||
if allow_empty_list is undefined:
|
|
||||||
allow_empty_list = opt.impl_is_follower()
|
|
||||||
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:
|
||||||
isempty = value is None or value == empty or (opt.impl_is_submulti() and value == [])
|
isempty = value is None or value == empty or (opt.impl_is_submulti() and value == [])
|
||||||
|
@ -294,7 +288,25 @@ class Values(object):
|
||||||
self._setvalue(option_bag,
|
self._setvalue(option_bag,
|
||||||
value,
|
value,
|
||||||
owner,
|
owner,
|
||||||
commit=_commit)
|
commit=False)
|
||||||
|
setting_properties = option_bag.config_bag.properties
|
||||||
|
validator = 'validator' in setting_properties and 'demoting_error_warning' not in setting_properties
|
||||||
|
if validator:
|
||||||
|
cache = option_bag.config_bag.context._impl_values_cache
|
||||||
|
cache.setcache(option_bag.path,
|
||||||
|
option_bag.index,
|
||||||
|
value,
|
||||||
|
option_bag.properties,
|
||||||
|
setting_properties,
|
||||||
|
validator)
|
||||||
|
if 'force_store_value' in setting_properties and option_bag.option.impl_is_leader():
|
||||||
|
option_bag.option.impl_get_leadership().follower_force_store_value(self,
|
||||||
|
value,
|
||||||
|
option_bag,
|
||||||
|
owners.forced,
|
||||||
|
_commit=_commit)
|
||||||
|
if _commit:
|
||||||
|
self._p_.commit()
|
||||||
|
|
||||||
def setvalue_validation(self,
|
def setvalue_validation(self,
|
||||||
value,
|
value,
|
||||||
|
@ -303,10 +315,11 @@ class Values(object):
|
||||||
# First validate properties with this value
|
# First validate properties with this value
|
||||||
opt = option_bag.option
|
opt = option_bag.option
|
||||||
settings.validate_frozen(option_bag)
|
settings.validate_frozen(option_bag)
|
||||||
settings.validate_mandatory(value,
|
val = self.calc_value(option_bag, value, False)
|
||||||
|
settings.validate_mandatory(val,
|
||||||
option_bag)
|
option_bag)
|
||||||
# Value must be valid for option
|
# Value must be valid for option
|
||||||
opt.impl_validate(value,
|
opt.impl_validate(val,
|
||||||
option_bag,
|
option_bag,
|
||||||
check_error=True)
|
check_error=True)
|
||||||
if 'warnings' in option_bag.config_bag.properties:
|
if 'warnings' in option_bag.config_bag.properties:
|
||||||
|
@ -449,6 +462,7 @@ class Values(object):
|
||||||
|
|
||||||
context = option_bag.config_bag.context
|
context = option_bag.config_bag.context
|
||||||
hasvalue = self._p_.hasvalue(option_bag.path)
|
hasvalue = self._p_.hasvalue(option_bag.path)
|
||||||
|
setting_properties = option_bag.config_bag.properties
|
||||||
|
|
||||||
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()
|
fake_context = context._gen_fake_values()
|
||||||
|
@ -469,7 +483,7 @@ class Values(object):
|
||||||
option_bag,
|
option_bag,
|
||||||
_commit=_commit)
|
_commit=_commit)
|
||||||
if hasvalue:
|
if hasvalue:
|
||||||
if 'force_store_value' in option_bag.properties:
|
if 'force_store_value' in option_bag.config_bag.properties and 'force_store_value' in option_bag.properties:
|
||||||
value = self.getdefaultvalue(option_bag)
|
value = self.getdefaultvalue(option_bag)
|
||||||
|
|
||||||
self._setvalue(option_bag,
|
self._setvalue(option_bag,
|
||||||
|
@ -477,9 +491,19 @@ class Values(object):
|
||||||
owners.forced,
|
owners.forced,
|
||||||
commit=_commit)
|
commit=_commit)
|
||||||
else:
|
else:
|
||||||
|
# for leader only
|
||||||
|
value = None
|
||||||
self._p_.resetvalue(option_bag.path,
|
self._p_.resetvalue(option_bag.path,
|
||||||
_commit)
|
_commit)
|
||||||
context.cfgimpl_reset_cache(option_bag)
|
context.cfgimpl_reset_cache(option_bag)
|
||||||
|
if 'force_store_value' in setting_properties and option_bag.option.impl_is_leader():
|
||||||
|
if value is None:
|
||||||
|
value = self.getdefaultvalue(option_bag)
|
||||||
|
option_bag.option.impl_get_leadership().follower_force_store_value(self,
|
||||||
|
value,
|
||||||
|
option_bag,
|
||||||
|
owners.forced,
|
||||||
|
_commit=_commit)
|
||||||
|
|
||||||
def reset_follower(self,
|
def reset_follower(self,
|
||||||
option_bag,
|
option_bag,
|
||||||
|
@ -487,7 +511,8 @@ class Values(object):
|
||||||
|
|
||||||
if self._p_.hasvalue(option_bag.path, index=option_bag.index):
|
if self._p_.hasvalue(option_bag.path, index=option_bag.index):
|
||||||
context = option_bag.config_bag.context
|
context = option_bag.config_bag.context
|
||||||
if 'validator' in option_bag.config_bag.properties:
|
setting_properties = option_bag.config_bag.properties
|
||||||
|
if 'validator' in setting_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()
|
||||||
|
@ -499,6 +524,14 @@ class Values(object):
|
||||||
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)
|
||||||
|
if 'force_store_value' in setting_properties and 'force_store_value' in option_bag.properties:
|
||||||
|
value = self.getdefaultvalue(option_bag)
|
||||||
|
|
||||||
|
self._setvalue(option_bag,
|
||||||
|
value,
|
||||||
|
owners.forced,
|
||||||
|
commit=_commit)
|
||||||
|
else:
|
||||||
self._p_.resetvalue_index(option_bag.path,
|
self._p_.resetvalue_index(option_bag.path,
|
||||||
option_bag.index,
|
option_bag.index,
|
||||||
_commit)
|
_commit)
|
||||||
|
@ -558,8 +591,7 @@ class Values(object):
|
||||||
subconfig,
|
subconfig,
|
||||||
od_config_bag):
|
od_config_bag):
|
||||||
settings = context.cfgimpl_get_settings()
|
settings = context.cfgimpl_get_settings()
|
||||||
for option in description.get_children(config_bag,
|
for option in description.get_children(config_bag):
|
||||||
context):
|
|
||||||
name = option.impl_getname()
|
name = option.impl_getname()
|
||||||
path = '.'.join(currpath + [name])
|
path = '.'.join(currpath + [name])
|
||||||
|
|
||||||
|
@ -599,11 +631,11 @@ class Values(object):
|
||||||
path,
|
path,
|
||||||
index,
|
index,
|
||||||
config_bag)
|
config_bag)
|
||||||
if 'mandatory' in option_bag.properties:
|
if 'mandatory' in option_bag.properties or 'empty' in option_bag.properties:
|
||||||
subconfig.getattr(name,
|
subconfig.getattr(name,
|
||||||
option_bag)
|
option_bag)
|
||||||
except PropertiesOptionError as err:
|
except PropertiesOptionError as err:
|
||||||
if err.proptype == ['mandatory']:
|
if err.proptype in (['mandatory'], ['empty']):
|
||||||
yield path
|
yield path
|
||||||
except ConfigError:
|
except ConfigError:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue