tiramisu/test/test_submulti.py

329 lines
16 KiB
Python
Raw Normal View History

2014-04-25 22:57:08 +02:00
# coding: utf-8
2017-07-09 09:49:03 +02:00
from .autopath import do_autopath
2015-07-24 17:54:10 +02:00
do_autopath()
2014-04-25 22:57:08 +02:00
from tiramisu.setting import groups, owners
2017-02-11 17:22:50 +01:00
from tiramisu.config import Config, MetaConfig
2017-10-14 13:33:25 +02:00
from tiramisu.option import StrOption, IntOption, OptionDescription, submulti, MasterSlaves
2017-11-12 14:33:05 +01:00
#from tiramisu.value import SubMulti, Multi
2014-04-25 22:57:08 +02:00
from tiramisu.error import SlaveError
from py.test import raises
def return_val(val=None):
if val is None:
return 'val'
else:
return val
2014-04-25 22:57:08 +02:00
def return_list(value=None):
return ['val', 'val']
def return_list2(value=None):
return [['val', 'val']]
def test_submulti():
multi = StrOption('multi', '', multi=submulti)
2017-11-12 14:33:05 +01:00
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
2014-04-25 22:57:08 +02:00
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
od = OptionDescription('od', '', [multi, multi2, multi3])
cfg = Config(od)
assert cfg.getowner(multi) == owners.default
assert cfg.multi == []
assert cfg.getowner(multi) == owners.default
assert cfg.getowner(multi) == owners.default
assert cfg.multi3 == [['yes']]
assert cfg.multi3[0] == ['yes']
assert cfg.multi3[0][0] == 'yes'
cfg.multi3[0]
assert cfg.getowner(multi) == owners.default
#FIXME multi sur une master
def test_groups_with_master_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
assert interface1.impl_get_group_type() == groups.master
def test_groups_with_master_in_config_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
Config(interface1)
assert interface1.impl_get_group_type() == groups.master
def test_reset_values_with_master_and_slaves_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
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) == owners.default
assert cfg.getowner(netmask_admin_eth0) == owners.default
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
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 == []
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
#
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
cfg.ip_admin_eth0.netmask_admin_eth0[0].append('255.255.255.0')
assert cfg.getowner(ip_admin_eth0) == owner
2015-11-19 22:25:00 +01:00
assert cfg.getowner(netmask_admin_eth0, 0) == owner
2014-04-25 22:57:08 +02:00
del(cfg.ip_admin_eth0.ip_admin_eth0)
assert cfg.getowner(ip_admin_eth0) == owners.default
2015-11-19 22:25:00 +01:00
# assert cfg.getowner(netmask_admin_eth0) == owners.default
2014-04-25 22:57:08 +02:00
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
def test_values_with_master_and_slaves_slave_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
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")
cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0']]
cfg.ip_admin_eth0.netmask_admin_eth0[0] = ['255.255.255.0']
cfg.ip_admin_eth0.netmask_admin_eth0[0][0] = '255.255.255.0'
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0'], ['255.255.255.0']]")
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = []")
del(cfg.ip_admin_eth0.netmask_admin_eth0)
cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0']]
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [['255.255.255.0'], []]
cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0'], ['255.255.255.0']]
raises(SlaveError, 'cfg.ip_admin_eth0.netmask_admin_eth0.pop(1)')
def test_values_with_master_and_slaves_master_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
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"]
cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0'], ['255.255.255.0']]
raises(SlaveError, 'cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]')
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [['255.255.255.0'], ['255.255.255.0']]
cfg.ip_admin_eth0.ip_admin_eth0.pop(1)
assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"]
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [['255.255.255.0']]
del(cfg.ip_admin_eth0.ip_admin_eth0)
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
def test_values_with_master_and_slaves_master_error_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.read_write()
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145", "192.168.230.145"]
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0']]")
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0'], ['255.255.255.0'], ['255.255.255.0']]")
cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0'], ['255.255.255.0']]
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0']]")
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0'], ['255.255.255.0'], ['255.255.255.0']]")
def test_values_with_master_owner_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
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.append("192.168.230.145")
assert cfg.getowner(ip_admin_eth0) == owner
assert cfg.getowner(netmask_admin_eth0) == owners.default
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
assert cfg.getowner(ip_admin_eth0) == owner
assert cfg.getowner(netmask_admin_eth0) == owners.default
def test_values_with_master_disabled_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
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')
def test_multi_insert_master_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.read_write()
raises(SlaveError, "cfg.ip_admin_eth0.ip_admin_eth0.insert(0, 'nok')")
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0.insert(0, 'nok')")
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0[0].insert(0, 'nok')")
def test_multi_sort_master_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.read_write()
raises(SlaveError, "cfg.ip_admin_eth0.ip_admin_eth0.sort()")
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0.sort()")
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0[0].sort()")
def test_multi_reverse_master_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.read_write()
raises(SlaveError, "cfg.ip_admin_eth0.ip_admin_eth0.reverse()")
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0.reverse()")
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0[0].reverse()")
def test_multi_extend_master_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.read_write()
raises(SlaveError, "cfg.ip_admin_eth0.ip_admin_eth0.extend(['ok'])")
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0.extend(['ok'])")
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0[0].extend(['ok'])")
def test_slave_submulti():
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=submulti)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.read_write()
assert cfg.ip_admin_eth0.ip_admin_eth0.__class__.__name__ == 'Multi'
assert cfg.ip_admin_eth0.netmask_admin_eth0.__class__.__name__ == 'Multi'
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
assert cfg.ip_admin_eth0.ip_admin_eth0.__class__.__name__ == 'Multi'
assert cfg.ip_admin_eth0.netmask_admin_eth0.__class__.__name__ == 'Multi'
assert cfg.ip_admin_eth0.ip_admin_eth0[0].__class__.__name__ == 'str'
assert cfg.ip_admin_eth0.netmask_admin_eth0[0].__class__.__name__ == 'SubMulti'
def test__master_is_submulti():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=submulti)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
2014-04-25 22:57:08 +02:00
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) == owners.default
assert cfg.getowner(netmask_admin_eth0) == owners.default
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
cfg.ip_admin_eth0.ip_admin_eth0.append(["192.168.230.145"])
assert cfg.ip_admin_eth0.ip_admin_eth0 == [["192.168.230.145"]]
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
assert cfg.getowner(ip_admin_eth0) == owner
assert cfg.getowner(netmask_admin_eth0) == owners.default
cfg.ip_admin_eth0.ip_admin_eth0 = [["192.168.230.145"], ["192.168.230.147"]]
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None, None]
raises(SlaveError, 'cfg.ip_admin_eth0.netmask_admin_eth0.append(None)')
raises(SlaveError, 'cfg.ip_admin_eth0.netmask_admin_eth0.pop(0)')
cfg.ip_admin_eth0.ip_admin_eth0[0].append('192.168.1.1')
assert cfg.ip_admin_eth0.ip_admin_eth0 == [["192.168.230.145", '192.168.1.1'], ["192.168.230.147"]]
cfg.ip_admin_eth0.ip_admin_eth0[0].pop(0)
assert cfg.ip_admin_eth0.ip_admin_eth0 == [["192.168.1.1"], ["192.168.230.147"]]
raises(ValueError, 'cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.1.1", "192.168.1.1"]')
def test_callback_submulti():
multi = StrOption('multi', '', multi=submulti)
multi2 = StrOption('multi2', '', multi=submulti, callback=return_val, callback_params={'': ((multi, False),)})
od = OptionDescription('multi', '', [multi, multi2])
cfg = Config(od)
cfg.read_write()
owner = cfg.cfgimpl_get_settings().getowner()
assert cfg.getowner(multi) == owners.default
assert cfg.multi == []
assert cfg.multi2 == []
cfg.multi.append(['val'])
assert cfg.getowner(multi) == owner
assert cfg.getowner(multi2) == owners.default
assert cfg.multi == [['val']]
assert cfg.multi2 == [['val']]