remove slave values when delete a master without value
This commit is contained in:
parent
6fc921fc19
commit
2c6275ffbd
|
@ -2,6 +2,7 @@ Sun Apr 19 09:14:21 2015 +0200 Emmanuel Garette <egarette@cadoles.com>
|
||||||
* valid Option is an unicode or a string if needed
|
* valid Option is an unicode or a string if needed
|
||||||
* difference between option/optiondescription in PropertiesOptionError
|
* difference between option/optiondescription in PropertiesOptionError
|
||||||
message
|
message
|
||||||
|
* remove slave values when delete a master without value
|
||||||
|
|
||||||
Sat Apr 18 22:42:53 2015 +0200 Emmanuel Garette <egarette@cadoles.com>
|
Sat Apr 18 22:42:53 2015 +0200 Emmanuel Garette <egarette@cadoles.com>
|
||||||
* refactor validation, build a fake context (with new Values and
|
* refactor validation, build a fake context (with new Values and
|
||||||
|
|
|
@ -335,6 +335,47 @@ def test_reset_values_with_master_and_slaves():
|
||||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_reset_values_with_master_and_slaves_default():
|
||||||
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['192.168.230.145'])
|
||||||
|
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)
|
||||||
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_write()
|
||||||
|
owner = cfg.cfgimpl_get_settings().getowner()
|
||||||
|
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||||
|
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||||
|
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0[0] = "192.168.230.146"
|
||||||
|
assert cfg.getowner(ip_admin_eth0) == owner
|
||||||
|
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||||
|
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||||
|
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||||
|
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||||
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.230.145']
|
||||||
|
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||||
|
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0[0] = "192.168.230.146"
|
||||||
|
cfg.ip_admin_eth0.netmask_admin_eth0[0] = "255.255.255.0"
|
||||||
|
assert cfg.getowner(ip_admin_eth0) == owner
|
||||||
|
assert cfg.getowner(netmask_admin_eth0) == owner
|
||||||
|
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||||
|
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||||
|
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||||
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.230.145']
|
||||||
|
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||||
|
|
||||||
|
cfg.ip_admin_eth0.netmask_admin_eth0[0] = "255.255.255.0"
|
||||||
|
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||||
|
assert cfg.getowner(netmask_admin_eth0) == owner
|
||||||
|
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||||
|
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||||
|
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||||
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.230.145']
|
||||||
|
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||||
|
|
||||||
|
|
||||||
def test_values_with_master_and_slaves_slave():
|
def test_values_with_master_and_slaves_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", multi=True)
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||||
|
@ -558,3 +599,16 @@ def test_multi_non_valid_value():
|
||||||
cfg.read_write()
|
cfg.read_write()
|
||||||
cfg.ip_admin_eth0 = ['a']
|
cfg.ip_admin_eth0 = ['a']
|
||||||
raises(ValueError, 'cfg.ip_admin_eth0[0] = 1')
|
raises(ValueError, 'cfg.ip_admin_eth0[0] = 1')
|
||||||
|
|
||||||
|
|
||||||
|
def test_multi_master_default_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", default_multi="255.255.255.0", multi=True)
|
||||||
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_write()
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||||
|
cfg.cfgimpl_reset_cache()
|
||||||
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.1.1']
|
||||||
|
|
|
@ -158,18 +158,21 @@ class Values(object):
|
||||||
if validate:
|
if validate:
|
||||||
context.cfgimpl_get_settings().validate_properties(opt, False,
|
context.cfgimpl_get_settings().validate_properties(opt, False,
|
||||||
True, path)
|
True, path)
|
||||||
if self._contains(path):
|
|
||||||
if validate:
|
hasvalue = self._contains(path)
|
||||||
setting = context.cfgimpl_get_settings()
|
|
||||||
fake_context = context._gen_fake_values()
|
if hasvalue and validate:
|
||||||
setting_properties = setting._getproperties()
|
setting = context.cfgimpl_get_settings()
|
||||||
fake_value = fake_context.cfgimpl_get_values()
|
fake_context = context._gen_fake_values()
|
||||||
fake_value.reset(opt, path, validate=False)
|
setting_properties = setting._getproperties()
|
||||||
opt.impl_validate(getattr(fake_context, path),
|
fake_value = fake_context.cfgimpl_get_values()
|
||||||
fake_context, 'validator' in setting_properties)
|
fake_value.reset(opt, path, validate=False)
|
||||||
context.cfgimpl_reset_cache()
|
opt.impl_validate(getattr(fake_context, path),
|
||||||
if opt.impl_is_master_slaves('master'):
|
fake_context, 'validator' in setting_properties)
|
||||||
opt.impl_get_master_slaves().reset(opt, self)
|
context.cfgimpl_reset_cache()
|
||||||
|
if opt.impl_is_master_slaves('master'):
|
||||||
|
opt.impl_get_master_slaves().reset(opt, self)
|
||||||
|
if hasvalue:
|
||||||
self._p_.resetvalue(path)
|
self._p_.resetvalue(path)
|
||||||
|
|
||||||
def _isempty(self, opt, value):
|
def _isempty(self, opt, value):
|
||||||
|
|
Loading…
Reference in New Issue