do not remove notempty and notunique properties

This commit is contained in:
Emmanuel Garette 2020-11-03 22:34:57 +01:00
parent 3e0e7244ef
commit b9107867c9
4 changed files with 44 additions and 9 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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),

View File

@ -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',