better mandatory/empty support for mandatory_warnings
This commit is contained in:
parent
0c8398e4a6
commit
44d585a5e2
|
@ -284,9 +284,9 @@ def test_force_cache():
|
||||||
'u2': {None: (None, None)},
|
'u2': {None: (None, None)},
|
||||||
'u3': {None: ([], None)},
|
'u3': {None: ([], None)},
|
||||||
'u4': {None: (None, None)}}
|
'u4': {None: (None, None)}}
|
||||||
assert c.cfgimpl_get_settings()._p_.get_cached(c) == {'u1': {None: (set([]), None)},
|
assert c.cfgimpl_get_settings()._p_.get_cached(c) == {'u1': {None: (set(['empty']), None)},
|
||||||
'u2': {None: (set([]), None)},
|
'u2': {None: (set([]), None)},
|
||||||
'u3': {None: (set([]), None)},
|
'u3': {None: (set(['empty']), None)},
|
||||||
'u4': {None: (set(['disabled']), None)}}
|
'u4': {None: (set(['disabled']), None)}}
|
||||||
c.read_only()
|
c.read_only()
|
||||||
|
|
||||||
|
@ -294,9 +294,9 @@ def test_force_cache():
|
||||||
assert c.cfgimpl_get_values()._p_.get_cached(c) == {'u1': {None: ([], None)},
|
assert c.cfgimpl_get_values()._p_.get_cached(c) == {'u1': {None: ([], None)},
|
||||||
'u2': {None: (None, None)},
|
'u2': {None: (None, None)},
|
||||||
'u3': {None: ([], None)}}
|
'u3': {None: ([], None)}}
|
||||||
assert c.cfgimpl_get_settings()._p_.get_cached(c) == {'u1': {None: (set([]), None)},
|
assert c.cfgimpl_get_settings()._p_.get_cached(c) == {'u1': {None: (set(['empty']), None)},
|
||||||
'u2': {None: (set([]), None)},
|
'u2': {None: (set([]), None)},
|
||||||
'u3': {None: (set([]), None)},
|
'u3': {None: (set(['empty']), None)},
|
||||||
'u4': {None: (set(['disabled']), None)}}
|
'u4': {None: (set(['disabled']), None)}}
|
||||||
|
|
||||||
c.cfgimpl_get_settings().remove('cache')
|
c.cfgimpl_get_settings().remove('cache')
|
||||||
|
|
|
@ -434,6 +434,23 @@ def test_mandatory_master():
|
||||||
del(config)
|
del(config)
|
||||||
|
|
||||||
|
|
||||||
|
def test_mandatory_warnings_master():
|
||||||
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
|
||||||
|
properties=('mandatory', ))
|
||||||
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
||||||
|
multi=True)
|
||||||
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
o = OptionDescription('o', '', [interface1])
|
||||||
|
config = Config(o)
|
||||||
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||||
|
try:
|
||||||
|
delete_session('config', config.impl_getsessionid())
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
del(config)
|
||||||
|
|
||||||
|
|
||||||
def test_mandatory_master_empty():
|
def test_mandatory_master_empty():
|
||||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
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",
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
||||||
|
@ -478,6 +495,37 @@ def test_mandatory_master_empty():
|
||||||
del(config)
|
del(config)
|
||||||
|
|
||||||
|
|
||||||
|
def test_mandatory_warnings_master_empty():
|
||||||
|
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)
|
||||||
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
o = OptionDescription('o', '', [interface1])
|
||||||
|
config = Config(o)
|
||||||
|
config.read_write()
|
||||||
|
config.ip_admin_eth0.ip_admin_eth0.append()
|
||||||
|
assert config.ip_admin_eth0.ip_admin_eth0 == [None]
|
||||||
|
assert config.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||||
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||||
|
del(config.ip_admin_eth0.ip_admin_eth0)
|
||||||
|
del(config.ip_admin_eth0.netmask_admin_eth0)
|
||||||
|
#
|
||||||
|
config.ip_admin_eth0.ip_admin_eth0.append('')
|
||||||
|
assert config.ip_admin_eth0.ip_admin_eth0 == ['']
|
||||||
|
assert config.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||||
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||||
|
#
|
||||||
|
config.read_write()
|
||||||
|
config.ip_admin_eth0.ip_admin_eth0 = ['ip']
|
||||||
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == []
|
||||||
|
try:
|
||||||
|
delete_session('config', config.impl_getsessionid())
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
del(config)
|
||||||
|
|
||||||
|
|
||||||
def test_mandatory_slave():
|
def test_mandatory_slave():
|
||||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
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",
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
||||||
|
@ -514,6 +562,29 @@ def test_mandatory_slave():
|
||||||
del(config)
|
del(config)
|
||||||
|
|
||||||
|
|
||||||
|
def test_mandatory_warnings_slave():
|
||||||
|
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=('mandatory', ))
|
||||||
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
o = OptionDescription('o', '', [interface1])
|
||||||
|
config = Config(o)
|
||||||
|
config.read_only()
|
||||||
|
assert config.ip_admin_eth0.ip_admin_eth0 == []
|
||||||
|
assert config.ip_admin_eth0.netmask_admin_eth0 == []
|
||||||
|
#
|
||||||
|
config.read_write()
|
||||||
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == []
|
||||||
|
config.ip_admin_eth0.ip_admin_eth0.append('ip')
|
||||||
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['ip_admin_eth0.netmask_admin_eth0']
|
||||||
|
try:
|
||||||
|
delete_session('config', config.impl_getsessionid())
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
del(config)
|
||||||
|
|
||||||
|
|
||||||
def test_mandatory_warnings_symlink():
|
def test_mandatory_warnings_symlink():
|
||||||
descr = make_description_sym()
|
descr = make_description_sym()
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
|
|
|
@ -220,6 +220,7 @@ class MasterSlaves(object):
|
||||||
# not self_properties,
|
# not self_properties,
|
||||||
# depends to index
|
# depends to index
|
||||||
#self_properties=self_properties,
|
#self_properties=self_properties,
|
||||||
|
setting_properties=setting_properties,
|
||||||
masterlen=masterlen,
|
masterlen=masterlen,
|
||||||
from_masterslave=True,
|
from_masterslave=True,
|
||||||
returns_raise=True)
|
returns_raise=True)
|
||||||
|
|
|
@ -391,9 +391,13 @@ class Settings(object):
|
||||||
is_cached, props = self._p_.getcache(path, ntime, index)
|
is_cached, props = self._p_.getcache(path, ntime, index)
|
||||||
if not is_cached:
|
if not is_cached:
|
||||||
props = self._p_.getproperties(path, opt.impl_getproperties())
|
props = self._p_.getproperties(path, opt.impl_getproperties())
|
||||||
|
if opt.impl_is_multi() and not opt.impl_is_master_slaves('slave'):
|
||||||
|
props.add('empty')
|
||||||
if apply_requires:
|
if apply_requires:
|
||||||
props = copy(props)
|
requires = self.apply_requires(opt, path, setting_properties, index)
|
||||||
props |= self.apply_requires(opt, path, setting_properties, index)
|
if requires != set([]):
|
||||||
|
props = copy(props)
|
||||||
|
props |= requires
|
||||||
if 'cache' in setting_properties:
|
if 'cache' in setting_properties:
|
||||||
if 'expire' in setting_properties:
|
if 'expire' in setting_properties:
|
||||||
ntime = ntime + expires_time
|
ntime = ntime + expires_time
|
||||||
|
@ -477,9 +481,8 @@ class Settings(object):
|
||||||
not self._getcontext().cfgimpl_get_values()._isempty(
|
not self._getcontext().cfgimpl_get_values()._isempty(
|
||||||
opt_or_descr, value, index=index):
|
opt_or_descr, value, index=index):
|
||||||
properties.remove('mandatory')
|
properties.remove('mandatory')
|
||||||
elif opt_or_descr.impl_is_multi() and \
|
elif 'empty' in properties and \
|
||||||
'empty' in setting_properties and \
|
'empty' in setting_properties and \
|
||||||
not opt_or_descr.impl_is_master_slaves('slave') and \
|
|
||||||
self._getcontext().cfgimpl_get_values()._isempty(
|
self._getcontext().cfgimpl_get_values()._isempty(
|
||||||
opt_or_descr, value, force_allow_empty_list=True):
|
opt_or_descr, value, force_allow_empty_list=True):
|
||||||
properties.add('mandatory')
|
properties.add('mandatory')
|
||||||
|
@ -488,6 +491,8 @@ class Settings(object):
|
||||||
properties.add('frozen')
|
properties.add('frozen')
|
||||||
elif 'frozen' in properties and not check_frozen:
|
elif 'frozen' in properties and not check_frozen:
|
||||||
properties.remove('frozen')
|
properties.remove('frozen')
|
||||||
|
if 'empty' in properties:
|
||||||
|
properties.remove('empty')
|
||||||
# at this point an option should not remain in properties
|
# at this point an option should not remain in properties
|
||||||
if properties != frozenset():
|
if properties != frozenset():
|
||||||
props = list(properties)
|
props = list(properties)
|
||||||
|
|
|
@ -616,7 +616,7 @@ class Values(object):
|
||||||
context = self._getcontext()
|
context = self._getcontext()
|
||||||
settings = context.cfgimpl_get_settings()
|
settings = context.cfgimpl_get_settings()
|
||||||
setting_properties = context.cfgimpl_get_settings()._getproperties()
|
setting_properties = context.cfgimpl_get_settings()._getproperties()
|
||||||
setting_properties.add('mandatory')
|
setting_properties.update(['mandatory', 'empty'])
|
||||||
|
|
||||||
def _mandatory_warnings(description, currpath=None):
|
def _mandatory_warnings(description, currpath=None):
|
||||||
if currpath is None:
|
if currpath is None:
|
||||||
|
@ -638,7 +638,7 @@ class Values(object):
|
||||||
self_properties = settings._getproperties(opt, path,
|
self_properties = settings._getproperties(opt, path,
|
||||||
read_write=False,
|
read_write=False,
|
||||||
setting_properties=setting_properties)
|
setting_properties=setting_properties)
|
||||||
if 'mandatory' in self_properties:
|
if 'mandatory' in self_properties or 'empty' in self_properties:
|
||||||
err = self._get_cached_value(opt, path=path,
|
err = self._get_cached_value(opt, path=path,
|
||||||
trusted_cached_properties=False,
|
trusted_cached_properties=False,
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
|
|
Loading…
Reference in New Issue