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)") 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(): def test_force_default_on_freeze_slave():
dummy1 = BoolOption('dummy1', 'Test int option', multi=True) dummy1 = BoolOption('dummy1', 'Test int option', multi=True)
dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',)) 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 inspect import ismethod, getdoc
from .error import APIError, ConfigError, SlaveError from .error import APIError, ConfigError, SlaveError
from .i18n import _ from .i18n import _
from .setting import ConfigBag, owners, undefined from .setting import ConfigBag, owners, undefined, FORBIDDEN_SET_PROPERTIES
from .option import ChoiceOption from .option import ChoiceOption
from time import time from time import time
from copy import deepcopy from copy import deepcopy
@ -329,18 +329,28 @@ class TiramisuOptionProperty(CommonTiramisuOption):
@count @count
def add(self, prop): def add(self, prop):
#FIXME not index !!
self._get_option() self._get_option()
self.settings.addproperty(self.path, if prop in FORBIDDEN_SET_PROPERTIES:
prop, raise ConfigError(_('cannot add this property: "{0}"').format(
self.config_bag) ' '.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 @count
def pop(self, prop): def pop(self, prop):
self._get_option() self._get_option()
self.settings.popproperty(self.path, props = self.settings.getproperties(self.path,
prop, self.index,
self.config_bag) self.config_bag,
apply_requires=False)
self.settings.setproperties(self.path,
props - {prop},
self.config_bag)
@count @count
def reset(self): def reset(self):

View File

@ -75,12 +75,15 @@ class CacheOptionDescription(BaseOption):
option._set_readonly() option._set_readonly()
is_multi = option.impl_is_multi() is_multi = option.impl_is_multi()
if not option.impl_is_symlinkoption(): 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)) 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'): option.impl_is_master_slaves('master'):
raise ConfigError(_('a master ({0}) cannot have ' 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(): for cons_id, func, all_cons_opts, params in option.get_consistencies():
option._valid_consistencies(all_cons_opts[1:], init=False) option._valid_consistencies(all_cons_opts[1:], init=False)
if func not in ALLOWED_CONST_LIST and is_multi: if func not in ALLOWED_CONST_LIST and is_multi:

View File

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

View File

@ -88,7 +88,8 @@ class Values(object):
if setting_properties and 'cache' in setting_properties and \ if setting_properties and 'cache' in setting_properties and \
self._p_.hascache(path, self._p_.hascache(path,
index): 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()) ntime = int(time())
is_cached, value = self._p_.getcache(path, is_cached, value = self._p_.getcache(path,
ntime, ntime,