tiramisu/tests/test_leadership.py

883 lines
49 KiB
Python

# coding: utf-8
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config, value_list, global_owner
from py.test import raises
from tiramisu.setting import groups, owners
from tiramisu import ChoiceOption, BoolOption, IntOption, IPOption, NetmaskOption, \
StrOption, OptionDescription, Leadership, Config
from tiramisu.error import LeadershipError, PropertiesOptionError, APIError, ConfigError
from tiramisu.storage import list_sessions
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def compare(calculated, expected):
def convert_list(val):
if isinstance(val, list):
val = tuple(val)
return val
# convert to tuple
for idx in range(len(calculated[0])):
right_idx = expected[0].index(calculated[0][idx])
for typ in range(4):
assert convert_list(calculated[typ][idx]) == expected[typ][right_idx]
def make_description():
numero_etab = StrOption('numero_etab', "identifiant de l'établissement")
nom_machine = StrOption('nom_machine', "nom de la machine", default="eoleng")
nombre_interfaces = IntOption('nombre_interfaces', "nombre d'interfaces à activer",
default=1)
activer_proxy_client = BoolOption('activer_proxy_client', "utiliser un proxy",
default=False)
mode_conteneur_actif = BoolOption('mode_conteneur_actif', "le serveur est en mode conteneur",
default=False)
mode_conteneur_actif2 = BoolOption('mode_conteneur_actif2', "le serveur est en mode conteneur2",
default=False, properties=('hidden',))
adresse_serveur_ntp = StrOption('serveur_ntp', "adresse serveur ntp", multi=True)
time_zone = ChoiceOption('time_zone', 'fuseau horaire du serveur',
('Paris', 'Londres'), 'Paris')
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé")
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau")
leader = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = OptionDescription('interface1', '', [leader])
interface1.impl_set_group_type(groups.family)
general = OptionDescription('general', '', [numero_etab, nom_machine,
nombre_interfaces, activer_proxy_client,
mode_conteneur_actif, mode_conteneur_actif2,
adresse_serveur_ntp, time_zone])
general.impl_set_group_type(groups.family)
new = OptionDescription('new', '', [], properties=('hidden',))
new.impl_set_group_type(groups.family)
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1, new])
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole])
return descr
def test_base_config(config_type):
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('creole.general.activer_proxy_client').value.get() is False
assert cfg.option('creole.general.nom_machine').value.get() == "eoleng"
if config_type != 'tiramisu-api':
assert cfg.option.find('nom_machine', first=True).value.get() == "eoleng"
result = {'general.numero_etab': None, 'general.nombre_interfaces': 1,
'general.serveur_ntp': [], 'interface1.ip_admin_eth0.ip_admin_eth0': None,
'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris',
'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine':
'eoleng', 'general.activer_proxy_client': False}
assert cfg.option('creole').value.dict() == result
result = {'serveur_ntp': [], 'mode_conteneur_actif': False,
'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None,
'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client':
False, 'nombre_interfaces': 1}
assert cfg.option('creole').value.dict(flatten=True) == result
if config_type == 'tiramisu-api':
cfg.send()
def test_make_dict_filter():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
subresult = {'numero_etab': None, 'nombre_interfaces': 1,
'serveur_ntp': [], 'mode_conteneur_actif': False,
'time_zone': 'Paris', 'nom_machine': 'eoleng',
'activer_proxy_client': False}
result = {}
for key, value in subresult.items():
result['general.' + key] = value
assert cfg.option('creole').value.dict(withoption='numero_etab') == result
raises(AttributeError, "cfg.option('creole').value.dict(withoption='numero_etab', withvalue='toto')")
assert cfg.option('creole').value.dict(withoption='numero_etab', withvalue=None) == result
assert cfg.option('creole.general').value.dict(withoption='numero_etab') == subresult
def test_get_group_type():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
grp = cfg.option('creole.general')
assert grp.group_type() == groups.family
assert grp.group_type() == 'family'
assert isinstance(grp.group_type(), groups.GroupType)
def test_iter_on_groups():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
result = cfg.option('creole').list('optiondescription',
group_type=groups.family)
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1']
for i in cfg.option('creole').list('optiondescription',
group_type=groups.family):
#test StopIteration
break
result = cfg.option('creole').list('option',
group_type=groups.family)
assert list(result) == []
result = cfg.option('creole.general').list('optiondescription',
group_type=groups.family)
assert list(result) == []
def test_list_recursive():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
result = cfg.option('creole').list('all')
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1']
#
result = cfg.option.list(recursive=True)
group_names = [res.option.name() for res in result]
assert group_names == ['numero_etab', 'nom_machine', 'nombre_interfaces',
'activer_proxy_client', 'mode_conteneur_actif',
'serveur_ntp', 'time_zone', 'ip_admin_eth0',
'netmask_admin_eth0']
result = list(cfg.option.list(recursive=True, type='optiondescription'))
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'ip_admin_eth0', 'interface1', 'creole']
def test_iter_on_groups_force_permissive():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
result = cfg.forcepermissive.option('creole.general').list()
group_names = [res.option.name() for res in result]
ass = ['numero_etab', 'nom_machine', 'nombre_interfaces',
'activer_proxy_client', 'mode_conteneur_actif',
'mode_conteneur_actif2', 'serveur_ntp', 'time_zone']
assert group_names == ass
# mode_conteneur_actif2 is not visible is not forcepermissive
result = cfg.option('creole.general').list()
group_names = [res.option.name() for res in result]
ass.remove('mode_conteneur_actif2')
assert group_names == ass
def test_iter_group_on_groups_force_permissive():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
result = cfg.forcepermissive.option('creole').list(type='optiondescription',
group_type=groups.family)
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1', 'new']
def test_iter_on_groups_props():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
cfg.option('creole.interface1').property.add('disabled')
result = cfg.option('creole').list(type='optiondescription',
group_type=groups.family)
group_names = [res.option.name() for res in result]
assert group_names == ['general']
def test_iter_on_empty_group():
cfg = Config(OptionDescription("name", "descr", []))
cfg.property.read_write()
result = list(cfg.option.list(type='optiondescription'))
assert result == []
def test_iter_not_group():
cfg = Config(OptionDescription("name", "descr", []))
cfg.property.read_write()
try:
list(cfg.option.list(type='optiondescription', group_type='family'))
except AssertionError:
pass
else:
raise Exception('must raise')
def test_groups_with_leader():
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
assert interface1.impl_get_group_type() == groups.leadership
def test_groups_is_leader(config_type):
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, default_multi='value')
interface1 = Leadership('leadership', '', [ip_admin_eth0, netmask_admin_eth0])
var = StrOption('var', "ip réseau autorisé", multi=True)
od2 = OptionDescription('od2', '', [var])
od1 = OptionDescription('od', '', [interface1, od2])
cfg = Config(od1)
cfg = get_config(cfg, config_type)
assert not cfg.option('od2').option.isleadership()
assert cfg.option('leadership').option.isleadership()
assert not cfg.option('od2.var').option.isleader()
assert not cfg.option('od2.var').option.isfollower()
assert cfg.option('leadership.ip_admin_eth0').option.ismulti()
assert cfg.option('leadership.netmask_admin_eth0').option.ismulti()
assert not cfg.option('leadership.ip_admin_eth0').option.issubmulti()
assert not cfg.option('leadership.netmask_admin_eth0').option.issubmulti()
assert cfg.option('leadership.ip_admin_eth0').option.isleader()
assert not cfg.option('leadership.ip_admin_eth0').option.isfollower()
assert not cfg.option('leadership.netmask_admin_eth0').option.isleader()
assert cfg.option('leadership.netmask_admin_eth0').option.isfollower()
assert cfg.option('leadership.netmask_admin_eth0').option.path() == 'leadership.netmask_admin_eth0'
assert cfg.option('leadership.netmask_admin_eth0').option.defaultmulti() == 'value'
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_in_root():
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1
raises(ConfigError, "Config(interface1)")
def test_groups_with_leader_in_config():
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
Config(od)
assert interface1.impl_get_group_type() == groups.leadership
def test_groups_with_leader_make_dict(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []}
if config_type != 'tiramisu-api':
# FIXME useful? already in leadership
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 0
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 0
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
if config_type != 'tiramisu-api':
# FIXME
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 2
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 2
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]}
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_default_value(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == []
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2']
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == []
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_default_value_2(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", ['ip1', 'ip2'], multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='netmask1', multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2']
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2']
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip3', 'ip4'])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip3', 'ip4']
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2']
#
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('netmask2')
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask2'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_hidden_in_config():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
cfg = Config(od)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
def test_groups_with_leader_hidden_in_config2():
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=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
cfg = Config(od)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#del
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
cfg.property.pop('hidden')
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
cfg.property.add('hidden')
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
cfg.property.pop('hidden')
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
def test_groups_with_leader_reset_empty(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1])
cfg = Config(od_)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
if config_type != 'tiramisu-api':
raises(LeadershipError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_reset_out_of_range(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1])
cfg_ori = Config(od_)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
if config_type != 'tiramisu-api':
# FIXME
raises(LeadershipError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.reset()")
raises(IndexError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)")
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_hidden_in_config3():
#if leader is hidden, follower are hidden too
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
cfg = Config(od)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
def test_allowed_groups():
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
raises(ValueError, "interface1.impl_set_group_type('toto')")
def test_values_with_leader_disabled_leader(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg_ori = Config(maconfig)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
cfg_ori.option('ip_admin_eth0.ip_admin_eth0').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
if config_type != 'tiramisu-api':
# FIXME
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('192.168.230.145')")
if config_type == 'tiramisu-api':
cfg.send()
def test_sub_group_in_leader_group():
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)
subgroup = OptionDescription("subgroup", '', [])
raises(ValueError, "Leadership('ip_admin_eth0', '', [subgroup, ip_admin_eth0, netmask_admin_eth0])")
def test_group_always_has_multis():
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")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
#____________________________________________________________
def test_values_with_leader_and_followers(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
owner = global_owner(cfg, config_type)
cfg = get_config(cfg, config_type)
assert interface1.impl_get_group_type() == groups.leadership
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
if config_type != 'tiramisu-api':
# FIXME
raises(APIError, "cfg.option('ip_admin_eth0.netmask_admin_eth0').value.set([None])")
raises(APIError, "cfg.option('ip_admin_eth0.netmask_admin_eth0').value.pop(0)")
if config_type == 'tiramisu-api':
cfg.send()
def test_reset_values_with_leader_and_followers(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
owner = global_owner(cfg, config_type)
cfg = Config(maconfig)
assert interface1.impl_get_group_type() == groups.leadership
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#reset
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
def test_reset_values_with_leader_and_followers_default_value():
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, default=['255.255.255.0'])
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_reset_values_with_leader_and_followers_default(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
owner = global_owner(cfg, config_type)
cfg = get_config(cfg, config_type)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
if config_type == 'tiramisu-api':
cfg.send()
def test_values_with_leader_and_followers_follower(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
if config_type != 'tiramisu-api':
raises(LeadershipError,
"cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
if config_type != 'tiramisu-api':
# FIXME
raises(APIError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.pop(1)")
#reset
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145',
'192.168.230.145',
'192.168.230.145'])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
if config_type == 'tiramisu-api':
cfg.send()
def test_values_with_leader_and_followers_pop(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.146'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145', '192.168.230.146']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.146']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
if config_type == 'tiramisu-api':
cfg.send()
def test_values_with_leader_and_followers_leader(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
if config_type != 'tiramisu-api':
raises(LeadershipError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])")
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
if config_type == 'tiramisu-api':
cfg.send()
def test_values_with_leader_and_followers_leader_pop():
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.146"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145", "192.168.230.146"]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (1,)), (('192.168.230.145', '192.168.230.146'), ('255.255.0.0',)), ('user', ('user',))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0,)), (('192.168.230.146',), ('255.255.0.0',)), ('user', ('user',))))
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.146"]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 3).value.set('255.255.0.0')
cfg.option('ip_admin_eth0.netmask_admin_eth0', 4).value.set('255.255.0.0')
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 3, 4)), (('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user'))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(5)
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 3, 4)), (('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user'))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 2, 3)), (('192.168.230.146', "192.168.230.145", "192.168.230.147", "192.168.230.148"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user'))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 2)), (('192.168.230.146', "192.168.230.145", "192.168.230.148"), ('255.255.0.0', '255.255.0.0')), ('user', ('user', 'user'))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0,)), (('192.168.230.146', "192.168.230.145"), ('255.255.0.0',)), ('user', ('user',))))
def test_values_with_leader_owner(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
owner = cfg.owner.get()
cfg = get_config(cfg, config_type)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
def test_values_with_leader_disabled(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg_ori = Config(maconfig)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
if config_type == 'tiramisu-api':
cfg.send()
#delete with value in disabled var
cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
##append with value in disabled var
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", '192.168.230.43'])
if config_type == 'tiramisu-api':
cfg.send()
def test_multi_non_valid_value(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
maconfig = OptionDescription('toto', '', [ip_admin_eth0])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0').value.set(['a'])
raises(ValueError, "cfg.option('ip_admin_eth0').value.set([1])")
if config_type == 'tiramisu-api':
cfg.send()
def test_multi_leader_default_follower(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_get_modified_value():
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
compare(cfg.value.exportation(), ((), (), (), ()))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0',), (None,), (('192.168.1.1',),), ('user',)))
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0',), (None, (0,)), (('192.168.1.1',), ('255.255.255.255',)), ('user', ('user',))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0',), (None, (0, 1)), (('192.168.1.1', '192.168.1.1'), ('255.255.255.255', '255.255.255.255')), ('user', ('user', 'user'))))
def test_groups_with_leader_importation(config_type):
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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg.value.importation([['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'], [None, [0, 1]], [['192.168.1.1', '192.168.1.0'], ['255.255.255.255', '255.255.255.0']], ['user', ['user', 'user']]])
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1', '192.168.1.0']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.255'
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == 'user'
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'user'
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'user'
if config_type == 'tiramisu-api':
cfg.send()
def test_wrong_index():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('od', '', [interface1])
maconfig = OptionDescription('toto', '', [od1])
cfg = Config(maconfig)
cfg.property.read_write()
assert cfg.option('od.ip_admin_eth0.ip_admin_eth0').option.get()
raises(APIError, "cfg.option('od.ip_admin_eth0.ip_admin_eth0', 0).option.get()")
assert cfg.option('od.ip_admin_eth0.netmask_admin_eth0', 0).option.get()
assert cfg.option('od.ip_admin_eth0').option.get()
raises(APIError, "cfg.option('od.ip_admin_eth0', 0).option.get()")
assert cfg.option('od').option.get()
raises(APIError, "cfg.option('od', 0).option.get()")
def test_without_leader_or_follower():
raises(ValueError, "Leadership('ip_admin_eth0', '', [])")
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0])")
#empty optiondescription is allowed
OptionDescription('ip_admin_eth0', '', [])
def test_leader_not_multi():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé")
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_follower_not_multi():
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")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_follower_not_same():
ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
ip_admin_eth1 = IPOption('ip_admin_eth1', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth1 = NetmaskOption('netmask_admin_eth1', "masque du sous-réseau", multi=True)
netmask_admin_eth1.impl_add_consistency('ip_netmask', ip_admin_eth0)
interface1 = Leadership('interface1', '', [ip_admin_eth1, netmask_admin_eth1])
od1 = OptionDescription('od', '', [interface0, interface1])
maconfig = OptionDescription('toto', '', [od1])
raises(ConfigError, "Config(maconfig)")
def test_follower_not_same_not_equal():
ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
ip_admin_eth1 = IPOption('ip_admin_eth1', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth1 = NetmaskOption('netmask_admin_eth1', "masque du sous-réseau", multi=True)
netmask_admin_eth1.impl_add_consistency('not_equal', netmask_admin_eth0)
interface1 = Leadership('interface1', '', [ip_admin_eth1, netmask_admin_eth1])
od1 = OptionDescription('od', '', [interface0, interface1])
maconfig = OptionDescription('toto', '', [od1])
cfg = Config(maconfig)
cfg.property.read_write()
def test_follower_force_store_value():
ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('force_store_value',))
interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('od', '', [interface0])
maconfig = OptionDescription('toto', '', [od1])
raises(ConfigError, "Config(maconfig)")