Multi: don't touch slave's value if it's default one's + don't check slave properties (if, for example, disabled for example)

This commit is contained in:
2013-05-17 18:11:14 +02:00
parent d6098f353e
commit 1d8c248d1b
2 changed files with 91 additions and 18 deletions

View File

@ -42,6 +42,7 @@ def make_description():
def test_base_config():
descr = make_description()
config = Config(descr)
config.read_write()
assert config.creole.general.activer_proxy_client is False
assert config.creole.general.nom_machine == "eoleng"
assert config.find_first(byname='nom_machine', type_='value') == "eoleng"
@ -61,6 +62,7 @@ def test_base_config():
def test_make_dict_filter():
descr = make_description()
config = Config(descr)
config.read_write()
result = {'general.numero_etab': None, 'general.nombre_interfaces': 1,
'general.serveur_ntp': [], 'general.mode_conteneur_actif': False,
'general.time_zone': 'Paris', 'general.nom_machine': 'eoleng',
@ -73,6 +75,7 @@ def test_make_dict_filter():
def test_get_group_type():
descr = make_description()
config = Config(descr)
config.read_write()
grp = config.unwrap_from_path('creole.general')
assert grp.impl_get_group_type() == groups.family
assert grp.impl_get_group_type() == 'family'
@ -83,6 +86,7 @@ def test_get_group_type():
def test_iter_on_groups():
descr = make_description()
config = Config(descr)
config.read_write()
result = list(config.creole.iter_groups(group_type=groups.family))
group_names = [res[0] for res in result]
assert group_names == ['general', 'interface1']
@ -90,6 +94,7 @@ def test_iter_on_groups():
def test_iter_on_empty_group():
config = Config(OptionDescription("name", "descr", []))
config.read_write()
result = list(config.iter_groups())
assert result == []
for i in config.iter_groups():
@ -153,6 +158,7 @@ def test_values_with_master_and_slaves():
interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.read_write()
owner = cfg.cfgimpl_get_settings().getowner()
assert interface1.impl_get_group_type() == groups.master
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default
@ -172,6 +178,7 @@ def test_reset_values_with_master_and_slaves():
interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.read_write()
owner = cfg.cfgimpl_get_settings().getowner()
assert interface1.impl_get_group_type() == groups.master
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default
@ -193,6 +200,7 @@ def test_values_with_master_and_slaves_slave():
interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.read_write()
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']")
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
@ -215,6 +223,7 @@ def test_values_with_master_and_slaves_master():
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.230.145")
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145", "192.168.230.145"]
@ -222,3 +231,55 @@ def test_values_with_master_and_slaves_master():
raises(SlaveError, 'cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]')
cfg.ip_admin_eth0.ip_admin_eth0.pop(1)
assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"]
def test_values_with_master_owner():
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)
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.read_write()
owner = cfg.cfgimpl_get_settings().getowner()
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default
assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owner
assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owner
assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default
def test_values_with_master_disabled():
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)
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.read_write()
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
cfg.ip_admin_eth0.netmask_admin_eth0 = ["192.168.230.145"]
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
del(cfg.ip_admin_eth0.netmask_admin_eth0)
cfg.cfgimpl_get_settings()[netmask_admin_eth0].append('disabled')
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
#delete with value in disabled var
cfg.cfgimpl_get_settings()[netmask_admin_eth0].remove('disabled')
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
cfg.ip_admin_eth0.netmask_admin_eth0 = ["192.168.230.145"]
cfg.cfgimpl_get_settings()[netmask_admin_eth0].append('disabled')
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
#append with value in disabled var
cfg.cfgimpl_get_settings()[netmask_admin_eth0].remove('disabled')
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
cfg.ip_admin_eth0.netmask_admin_eth0 = ["192.168.230.145"]
cfg.cfgimpl_get_settings()[netmask_admin_eth0].append('disabled')
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.230.43')