From b9107867c9487ba47ccb025e0e29da79c0274aa7 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 3 Nov 2020 22:34:57 +0100 Subject: [PATCH] do not remove notempty and notunique properties --- tests/test_leadership.py | 38 +++++++++++++++++++++++++++++++++++ tests/test_option_setting.py | 6 +++--- tiramisu/option/baseoption.py | 8 ++------ tiramisu/setting.py | 1 + 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/tests/test_leadership.py b/tests/test_leadership.py index 467bd4d..3b4f2a8 100644 --- a/tests/test_leadership.py +++ b/tests/test_leadership.py @@ -735,6 +735,19 @@ async def test_values_with_leader_and_followers_leader_pop(): assert not await list_sessions() +@pytest.mark.asyncio +async def test_follower_unique(): + ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) + netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('unique',)) + interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) + maconfig = OptionDescription('toto', '', [interface1]) + async with await Config(maconfig) as cfg: + await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.146"]) + # unique property is removed for a follower + assert not await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).property.get() + assert not await list_sessions() + + @pytest.mark.asyncio async def test_values_with_leader_owner(config_type): ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) @@ -976,3 +989,28 @@ async def test_follower_force_store_value_reset(): await cfg.option('od.interface0.ip_admin_eth0').value.reset() assert not await cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() assert not await list_sessions() + + +@pytest.mark.asyncio +async def test_follower_properties(): + ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) + netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('aproperty',)) + interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) + maconfig = OptionDescription('toto', '', [interface1]) + async with await Config(maconfig) as cfg: + await cfg.property.read_write() + await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['1.1.1.1', '192.168.0.0']) + await cfg.option('ip_admin_eth0.netmask_admin_eth0').property.get() == ('aproperty',) + await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).property.get() == ('aproperty',) + await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).property.get() == ('aproperty',) + # + await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).property.add('newproperty') + await cfg.option('ip_admin_eth0.netmask_admin_eth0').property.get() == ('aproperty',) + await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).property.get() == ('aproperty', 'newproperty') + await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).property.get() == ('aproperty',) + # + await cfg.option('ip_admin_eth0.netmask_admin_eth0').property.add('newproperty1') + await cfg.option('ip_admin_eth0.netmask_admin_eth0').property.get() == ('aproperty', 'newproperty1') + await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).property.get() == ('aproperty', 'newproperty', 'newproperty1') + await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).property.get() == ('aproperty', 'newproperty1') + assert not await list_sessions() diff --git a/tests/test_option_setting.py b/tests/test_option_setting.py index 797e773..197168a 100644 --- a/tests/test_option_setting.py +++ b/tests/test_option_setting.py @@ -191,9 +191,9 @@ async def test_property_get_unique_empty(): async with await Config(descr) as cfg: await cfg.property.read_write() assert await cfg.option('string').property.get() == {'empty', 'unique'} - assert await cfg.option('string2').property.get() == {'empty'} - assert await cfg.option('string3').property.get() == {'unique'} - assert await cfg.option('string4').property.get() == set() + assert await cfg.option('string2').property.get() == {'empty', 'notunique'} + assert await cfg.option('string3').property.get() == {'unique', 'notempty'} + assert await cfg.option('string4').property.get() == {'notunique', 'notempty'} assert not await list_sessions() diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index 40a3909..87b37a9 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -72,13 +72,9 @@ class Base: if is_multi: # if option is a multi, it cannot be 'empty' (None not allowed in the list) and cannot have multiple time the same value # 'empty' and 'unique' are removed for follower's option - if 'notunique' in properties: - properties = properties - {'notunique'} - else: + if 'notunique' not in properties: properties = properties | {'unique'} - if 'notempty' in properties: - properties = properties - {'notempty'} - else: + if 'notempty' not in properties: properties = properties | {'empty'} assert isinstance(properties, frozenset), _('invalid properties type {0} for {1},' ' must be a frozenset').format(type(properties), diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 04d3c48..f6abf33 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -117,6 +117,7 @@ FORBIDDEN_SET_PERMISSIVES = frozenset(['force_default_on_freeze', 'force_metaconfig_on_freeze', 'force_store_value']) ALLOWED_LEADER_PROPERTIES = frozenset(['empty', + 'notunique', 'unique', 'force_store_value', 'mandatory',