empty follower without empty property is valid

This commit is contained in:
Emmanuel Garette 2019-12-19 17:18:09 +01:00
parent fb93c0cf6f
commit 0cb69f7a85
2 changed files with 14 additions and 1 deletions

View File

@ -470,7 +470,9 @@ def test_mandatory_follower():
cfg = Config(descr) cfg = Config(descr)
cfg.property.read_only() cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
# assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [],
'ip_admin_eth0.netmask_admin_eth0': []}
cfg.property.read_write() cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
cfg.property.read_only() cfg.property.read_only()
@ -488,6 +490,8 @@ def test_mandatory_follower():
cfg.property.read_only() cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip'],
'ip_admin_eth0.netmask_admin_eth0': ['ip']}
def test_mandatory_warnings_follower(): def test_mandatory_warnings_follower():

View File

@ -54,9 +54,13 @@ permissive
mandatory mandatory
should set value for option with this properties if 'mandatory' is set in should set value for option with this properties if 'mandatory' is set in
config config
example: 'a', ['a'], [None] are valid
None, [] are not valid
empty empty
raise mandatory PropertiesOptionError if multi or leader have empty value raise mandatory PropertiesOptionError if multi or leader have empty value
example: ['a'] is valid
[None] is not valid
unique unique
raise ValueError if a value is set twice or more in a multi Option raise ValueError if a value is set twice or more in a multi Option
@ -702,10 +706,15 @@ class Settings(object):
option_bag): option_bag):
if 'mandatory' in option_bag.config_bag.properties: if 'mandatory' in option_bag.config_bag.properties:
values = option_bag.config_bag.context.cfgimpl_get_values() values = option_bag.config_bag.context.cfgimpl_get_values()
if option_bag.option.impl_is_follower():
force_allow_empty_list = True
else:
force_allow_empty_list = False
if not ('permissive' in option_bag.config_bag.properties and if not ('permissive' in option_bag.config_bag.properties and
'mandatory' in option_bag.config_bag.permissives) and \ 'mandatory' in option_bag.config_bag.permissives) and \
'mandatory' in option_bag.properties and values.isempty(option_bag.option, 'mandatory' in option_bag.properties and values.isempty(option_bag.option,
value, value,
force_allow_empty_list=force_allow_empty_list,
index=option_bag.index): index=option_bag.index):
raise PropertiesOptionError(option_bag, raise PropertiesOptionError(option_bag,
['mandatory'], ['mandatory'],