allow force_default_on_freeze for master if frozen

This commit is contained in:
Emmanuel Garette 2018-04-03 15:51:45 +02:00
parent 80881875b2
commit dc84608348
5 changed files with 42 additions and 57 deletions

View File

@ -115,6 +115,15 @@ def test_force_default_on_freeze_master():
raises(ConfigError, "Config(descr)")
def test_force_default_on_freeze_master_frozen():
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_default_on_freeze', 'frozen'))
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = MasterSlaves("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr])
api = getapi(Config(descr))
raises(ConfigError, "api.option('dummy1.dummy1').property.pop('frozen')")
def test_force_default_on_freeze_slave():
dummy1 = BoolOption('dummy1', 'Test int option', multi=True)
dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',))

View File

@ -17,7 +17,7 @@
from inspect import ismethod, getdoc
from .error import APIError, ConfigError, SlaveError
from .i18n import _
from .setting import ConfigBag, owners, undefined
from .setting import ConfigBag, owners, undefined, FORBIDDEN_SET_PROPERTIES
from .option import ChoiceOption
from time import time
from copy import deepcopy
@ -329,18 +329,28 @@ class TiramisuOptionProperty(CommonTiramisuOption):
@count
def add(self, prop):
#FIXME not index !!
self._get_option()
self.settings.addproperty(self.path,
prop,
self.config_bag)
if prop in FORBIDDEN_SET_PROPERTIES:
raise ConfigError(_('cannot add this property: "{0}"').format(
' '.join(prop)))
props = self.settings.getproperties(self.path,
None,
self.config_bag,
apply_requires=False)
self.settings.setproperties(self.path,
props | {prop},
self.config_bag)
@count
def pop(self, prop):
self._get_option()
self.settings.popproperty(self.path,
prop,
self.config_bag)
props = self.settings.getproperties(self.path,
self.index,
self.config_bag,
apply_requires=False)
self.settings.setproperties(self.path,
props - {prop},
self.config_bag)
@count
def reset(self):

View File

@ -75,12 +75,15 @@ class CacheOptionDescription(BaseOption):
option._set_readonly()
is_multi = option.impl_is_multi()
if not option.impl_is_symlinkoption():
if 'force_store_value' in option.impl_getproperties():
properties = option.impl_getproperties()
if 'force_store_value' in properties:
force_store_values.append((subpath, option))
if 'force_default_on_freeze' in option.impl_getproperties() and \
if 'force_default_on_freeze' in properties and \
'frozen' not in properties and \
option.impl_is_master_slaves('master'):
raise ConfigError(_('a master ({0}) cannot have '
'force_default_on_freeze property').format(subpath))
'"force_default_on_freeze" property without "frozen"'
'').format(subpath))
for cons_id, func, all_cons_opts, params in option.get_consistencies():
option._valid_consistencies(all_cons_opts[1:], init=False)
if func not in ALLOWED_CONST_LIST and is_multi:

View File

@ -560,8 +560,7 @@ class Settings(object):
def setproperties(self,
path,
properties,
config_bag,
force=False):
config_bag):
"""save properties for specified path
(never save properties if same has option properties)
"""
@ -587,11 +586,12 @@ class Settings(object):
if opt and opt.impl_is_symlinkoption():
raise TypeError(_("can't assign properties to the SymLinkOption \"{}\""
"").format(opt.impl_get_display_name()))
if not force:
forbidden_properties = FORBIDDEN_SET_PROPERTIES & properties
if forbidden_properties:
raise ConfigError(_('cannot add those properties: {0}').format(
' '.join(forbidden_properties)))
if 'force_default_on_freeze' in properties and \
'frozen' not in properties and \
opt.impl_is_master_slaves('master'):
raise ConfigError(_('a master ({0}) cannot have '
'"force_default_on_freeze" property without "frozen"'
'').format(opt.impl_get_display_name()))
if not isinstance(properties, frozenset):
raise TypeError(_('properties must be a frozenset'))
self._p_.setproperties(path,
@ -600,44 +600,6 @@ class Settings(object):
self._getcontext().cfgimpl_reset_cache(opt=opt,
path=path)
def addproperty(self,
path,
property_,
config_bag):
if property_ in FORBIDDEN_SET_PROPERTIES:
raise ConfigError(_('cannot add this property: "{0}"').format(
' '.join(property_)))
self_properties = config_bag.properties
if self_properties is None:
index = None
self_properties = self.getproperties(path,
index,
config_bag,
apply_requires=False)
config_bag.properties = self_properties
self.setproperties(path,
self_properties | {property_},
config_bag,
force=True)
def popproperty(self,
path,
property_,
config_bag):
self_properties = config_bag.properties
if self_properties is None:
index = None
self_properties = self.getproperties(path,
index,
config_bag,
apply_requires=False)
config_bag.properties = self_properties
self.setproperties(path,
self_properties - {property_},
config_bag,
force=True)
def set_context_permissive(self, permissive):
self.setpermissive(None, None, permissive)

View File

@ -88,7 +88,8 @@ class Values(object):
if setting_properties and 'cache' in setting_properties and \
self._p_.hascache(path,
index):
if 'expire' in setting_properties or 'expire' in config_bag.properties:
if 'expire' in setting_properties or \
(config_bag.properties and 'expire' in config_bag.properties):
ntime = int(time())
is_cached, value = self._p_.getcache(path,
ntime,