feat: add forcepermissive() and index(None) + improvment
This commit is contained in:
parent
6b0a0d8e56
commit
27b1bb8294
4 changed files with 56 additions and 27 deletions
|
|
@ -200,6 +200,24 @@ def test_groups_is_leader(config_type):
|
||||||
# assert not list_sessions()
|
# assert not list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
def test_leader_follower_index():
|
||||||
|
ip = StrOption('ip', "", ['val1', 'val2'], multi=True)
|
||||||
|
netmask = StrOption('netmask', "", multi=True, default_multi='value')
|
||||||
|
interface1 = Leadership('leadership', '', [ip, netmask])
|
||||||
|
od1 = OptionDescription('od', '', [interface1])
|
||||||
|
cfg = Config(od1)
|
||||||
|
assert cfg.option('leadership.ip').value.get() == ['val1', 'val2']
|
||||||
|
with pytest.raises(ConfigError):
|
||||||
|
cfg.option('leadership.ip').index(0)
|
||||||
|
follower = cfg.option('leadership.netmask')
|
||||||
|
with pytest.raises(ConfigError):
|
||||||
|
follower.value.get()
|
||||||
|
assert follower.index(0).value.get() == 'value'
|
||||||
|
assert follower.index(0).index(None).index() is None
|
||||||
|
with pytest.raises(ConfigError):
|
||||||
|
follower.index(0).index(None).value.get()
|
||||||
|
|
||||||
|
|
||||||
def test_leader_list(config_type):
|
def test_leader_list(config_type):
|
||||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", ['val1'], multi=True)
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", ['val1'], multi=True)
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, default_multi='value')
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, default_multi='value')
|
||||||
|
|
|
||||||
|
|
@ -64,15 +64,17 @@ def test_hidden_owner():
|
||||||
od1 = OptionDescription('tiramisu', '', [gcdummy])
|
od1 = OptionDescription('tiramisu', '', [gcdummy])
|
||||||
cfg = Config(od1)
|
cfg = Config(od1)
|
||||||
cfg.property.read_write()
|
cfg.property.read_write()
|
||||||
#with pytest.raises(PropertiesOptionError):
|
with pytest.raises(PropertiesOptionError):
|
||||||
# cfg.forcepermissive.option('dummy').owner.get()
|
cfg.option('dummy').value.get()
|
||||||
#with pytest.raises(PropertiesOptionError):
|
with pytest.raises(PropertiesOptionError):
|
||||||
# cfg.option('dummy').owner.isdefault()
|
cfg.option('dummy').owner.isdefault()
|
||||||
#with pytest.raises(PropertiesOptionError):
|
|
||||||
# cfg.forcepermissive.option('dummy').owner.isdefault()
|
|
||||||
cfg.permissive.add('hidden')
|
cfg.permissive.add('hidden')
|
||||||
cfg.forcepermissive.option('dummy').value.get()
|
cfg.forcepermissive.option('dummy').value.get()
|
||||||
cfg.forcepermissive.option('dummy').owner.isdefault()
|
cfg.forcepermissive.option('dummy').owner.isdefault()
|
||||||
|
option = cfg.option("dummy")
|
||||||
|
option.forcepermissive()
|
||||||
|
option.value.get()
|
||||||
|
option.owner.isdefault()
|
||||||
# assert not list_sessions()
|
# assert not list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -253,11 +253,12 @@ class CommonTiramisuOption(CommonTiramisu):
|
||||||
path: str,
|
path: str,
|
||||||
index: Optional[int],
|
index: Optional[int],
|
||||||
config_bag: ConfigBag,
|
config_bag: ConfigBag,
|
||||||
|
subconfig: Optional[SubConfig]=None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self._path = path
|
self._path = path
|
||||||
self._index = index
|
self._index = index
|
||||||
self._config_bag = config_bag
|
self._config_bag = config_bag
|
||||||
self._subconfig = None
|
self._subconfig = subconfig
|
||||||
self._set_subconfig()
|
self._set_subconfig()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -662,11 +663,16 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription):
|
||||||
return r"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
return r"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
||||||
|
|
||||||
@option_type(["option", "with_or_without_index", "symlink"])
|
@option_type(["option", "with_or_without_index", "symlink"])
|
||||||
def index(self, index=None):
|
def index(self, index=undefined):
|
||||||
"""Get index of option"""
|
"""Get index of option"""
|
||||||
if index is None:
|
if index is undefined:
|
||||||
return self._subconfig.index
|
return self._subconfig.index
|
||||||
return TiramisuOption(self._path, index, self._config_bag)
|
subconfig = self._subconfig.parent.get_child(
|
||||||
|
self._subconfig.option,
|
||||||
|
index,
|
||||||
|
True,
|
||||||
|
)
|
||||||
|
return TiramisuOption(self._path, index, self._config_bag, subconfig=subconfig)
|
||||||
|
|
||||||
@option_type(["symlink", "optiondescription", "allow_dynoption"])
|
@option_type(["symlink", "optiondescription", "allow_dynoption"])
|
||||||
def option(self, *args, **kwargs):
|
def option(self, *args, **kwargs):
|
||||||
|
|
@ -1062,11 +1068,6 @@ class TiramisuOptionValue(CommonTiramisuOption, _TiramisuODGet):
|
||||||
self.__class__.__name__, func.__name__
|
self.__class__.__name__, func.__name__
|
||||||
)
|
)
|
||||||
raise ConfigError(msg)
|
raise ConfigError(msg)
|
||||||
if (
|
|
||||||
"force_store_value" in self._subconfig.properties
|
|
||||||
and "force_store_value" in self._config_bag.properties
|
|
||||||
):
|
|
||||||
return self._get(self._subconfig)
|
|
||||||
return self._config_bag.context.get_values().get_default_value(self._subconfig)
|
return self._config_bag.context.get_values().get_default_value(self._subconfig)
|
||||||
|
|
||||||
@option_type(
|
@option_type(
|
||||||
|
|
@ -1238,6 +1239,7 @@ class TiramisuOption(
|
||||||
self._path,
|
self._path,
|
||||||
self._index,
|
self._index,
|
||||||
self._config_bag,
|
self._config_bag,
|
||||||
|
self._subconfig,
|
||||||
)
|
)
|
||||||
raise ConfigError(
|
raise ConfigError(
|
||||||
_("please specify a valid sub function ({0}.{1}) for {2}").format(
|
_("please specify a valid sub function ({0}.{1}) for {2}").format(
|
||||||
|
|
@ -1317,6 +1319,10 @@ class TiramisuOption(
|
||||||
self._load_dict()
|
self._load_dict()
|
||||||
return self._tiramisu_dict.set_updates(body)
|
return self._tiramisu_dict.set_updates(body)
|
||||||
|
|
||||||
|
def forcepermissive(self):
|
||||||
|
self._set_subconfig()
|
||||||
|
self._subconfig.config_bag.set_permissive()
|
||||||
|
|
||||||
|
|
||||||
class TiramisuContextInformation(TiramisuConfig):
|
class TiramisuContextInformation(TiramisuConfig):
|
||||||
"""Manage config informations"""
|
"""Manage config informations"""
|
||||||
|
|
|
||||||
|
|
@ -318,28 +318,31 @@ class Values:
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
# copy
|
# copy
|
||||||
value = value.copy()
|
value = value.copy()
|
||||||
elif isinstance(value, Calculation):
|
|
||||||
value, _has_calculation = get_calculated_value(
|
|
||||||
subconfig,
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
self._setvalue(
|
self._setvalue(
|
||||||
subconfig,
|
subconfig,
|
||||||
ori_value,
|
ori_value,
|
||||||
owner,
|
owner,
|
||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
"force_store_value" in self_properties
|
"force_store_value" in setting_properties
|
||||||
and subconfig.option.impl_is_leader()
|
and subconfig.option.impl_is_leader()
|
||||||
):
|
):
|
||||||
leader = subconfig.option.impl_get_leadership()
|
leader = subconfig.option.impl_get_leadership()
|
||||||
parent = subconfig.parent
|
parent = subconfig.parent
|
||||||
|
try:
|
||||||
|
if isinstance(value, Calculation):
|
||||||
|
value, has_calculation = get_calculated_value(
|
||||||
|
subconfig,
|
||||||
|
value,
|
||||||
|
)
|
||||||
parent._length = len(value)
|
parent._length = len(value)
|
||||||
leader.follower_force_store_value(
|
leader.follower_force_store_value(
|
||||||
value,
|
value,
|
||||||
parent,
|
parent,
|
||||||
owners.forced,
|
owners.forced,
|
||||||
)
|
)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
validator = (
|
validator = (
|
||||||
"validator" in setting_properties
|
"validator" in setting_properties
|
||||||
and "validator" in self_properties
|
and "validator" in self_properties
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue