From 73d45f54cf67808f63f535d382d00069c83adc5b Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sun, 14 Jul 2019 10:35:46 +0200 Subject: [PATCH] follower option with consistency --- tests/test_leadership.py | 14 ++++++++++++++ tests/test_symlink.py | 1 - tiramisu/config.py | 9 +++++++-- tiramisu/locale/fr/LC_MESSAGES/tiramisu.po | 2 +- tiramisu/option/option.py | 3 ++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/test_leadership.py b/tests/test_leadership.py index accc836..6b8a227 100644 --- a/tests/test_leadership.py +++ b/tests/test_leadership.py @@ -873,6 +873,20 @@ def test_follower_not_same_not_equal(): cfg.property.read_write() +def test_follower_consistency(): + ip_admin_eth1 = IPOption('ip_admin_eth1', "ip réseau autorisé", multi=True, default=['1.1.1.1']) + netmask_admin_eth1 = NetmaskOption('netmask_admin_eth1', "masque du sous-réseau", multi=True) + netmask_admin_eth1.impl_add_consistency('ip_netmask', ip_admin_eth1) + interface1 = Leadership('interface1', '', [ip_admin_eth1, netmask_admin_eth1]) + od1 = OptionDescription('od', '', [interface1]) + maconfig = OptionDescription('toto', '', [od1]) + cfg = Config(maconfig) + cfg.property.read_write() + cfg.option('od.interface1.ip_admin_eth1').value.set(['192.168.1.1', '192.168.2.1']) + cfg.option('od.interface1.netmask_admin_eth1', 1).value.set('255.255.255.0') + cfg.option('od.interface1.ip_admin_eth1').value.pop(0) + + def test_follower_force_store_value(): ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('force_store_value',)) diff --git a/tests/test_symlink.py b/tests/test_symlink.py index a55f07c..3f0b0b5 100644 --- a/tests/test_symlink.py +++ b/tests/test_symlink.py @@ -244,7 +244,6 @@ def test_symlink_with_follower(config_type): cfg = get_config(cfg, config_type) assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'follower': []} cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) - print(cfg.value.dict()) assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'follower': [None, None]} # assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None diff --git a/tiramisu/config.py b/tiramisu/config.py index 3b4cfdf..9d2e498 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -282,7 +282,8 @@ class SubConfig(object): def getattr(self, name, option_bag, - from_follower=False): + from_follower=False, + follower_check_length=True): """ attribute notation mechanism for accessing the value of an option :param name: attribute name @@ -314,7 +315,7 @@ class SubConfig(object): if not from_follower or option_bag.option.impl_getrequires(): self.cfgimpl_get_settings().validate_properties(option_bag) - if option.impl_is_follower() and not from_follower: + if follower_check_length and option.impl_is_follower() and not from_follower: length = self.cfgimpl_get_length_leadership(option_bag) follower_len = self.cfgimpl_get_values()._p_.get_max_length(option_bag.path) if follower_len > length: @@ -323,8 +324,12 @@ class SubConfig(object): follower_len, length, option_bag.index)) + else: + length = None if option.impl_is_follower() and option_bag.index is None: value = [] + if length is None: + length = self.cfgimpl_get_length_leadership(option_bag) for idx in range(length): soption_bag = OptionBag() soption_bag.set_option(option, diff --git a/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po b/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po index 901ef71..788a53c 100644 --- a/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po +++ b/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po @@ -154,7 +154,7 @@ msgid "" "the follower option \"{}\" has greater length ({}) than the leader length " "({})" msgstr "" -"l'option suiveuse \"{}\" a une longueur supérieur ({}) à la longueur de " +"l'option suiveuse \"{}\" a une longueur supérieur ({}) à la longueur de " "l'option leader ({})" #: tiramisu/config.py:418 diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index d437373..80b39c9 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -686,7 +686,8 @@ class Option(BaseOption): fromconsistency.append(cons_id) coption_bag.fromconsistency = fromconsistency current_value = option_bag.config_bag.context.getattr(path, - coption_bag) + coption_bag, + follower_check_length=False) if index_ is None and index is not None: #if self is a follower and current_option is a leader and func not in ALLOWED_CONST_LIST #return only the value of the leader for isolate follower