tiramisu/test/test_masterslaves.py

770 lines
44 KiB
Python
Raw Normal View History

# 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()
2018-10-31 08:00:19 +01:00
from py.test import raises
2015-07-24 17:54:10 +02:00
from tiramisu.setting import groups, owners
2018-04-12 23:04:33 +02:00
from tiramisu import ChoiceOption, BoolOption, IntOption, IPOption, NetmaskOption, \
2018-08-14 23:07:07 +02:00
StrOption, OptionDescription, MasterSlaves, Config
2018-03-19 08:33:53 +01:00
from tiramisu.error import SlaveError, PropertiesOptionError, APIError, ConfigError
from tiramisu.api import TIRAMISU_VERSION
2018-10-31 08:00:19 +01:00
from tiramisu.storage import list_sessions
2018-10-31 08:00:19 +01:00
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
2012-12-06 15:19:43 +01:00
2018-06-09 18:59:40 +02:00
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",
2012-11-06 15:19:36 +01:00
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")
master = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = OptionDescription('interface1', '', [master])
interface1.impl_set_group_type(groups.family)
2012-11-06 15:19:36 +01:00
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():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
assert api.option('creole.general.activer_proxy_client').value.get() is False
assert api.option('creole.general.nom_machine').value.get() == "eoleng"
2018-04-10 12:33:51 +02:00
assert api.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}
2018-09-09 12:21:47 +02:00
assert api.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}
2018-09-09 12:21:47 +02:00
assert api.option('creole').value.dict(flatten=True) == result
def test_make_dict_filter():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
2013-08-24 22:32:54 +02:00
subresult = {'numero_etab': None, 'nombre_interfaces': 1,
'serveur_ntp': [], 'mode_conteneur_actif': False,
'time_zone': 'Paris', 'nom_machine': 'eoleng',
'activer_proxy_client': False}
2013-08-24 22:32:54 +02:00
result = {}
for key, value in subresult.items():
result['general.' + key] = value
2018-09-09 12:21:47 +02:00
assert api.option('creole').value.dict(withoption='numero_etab') == result
raises(AttributeError, "api.option('creole').value.dict(withoption='numero_etab', withvalue='toto')")
assert api.option('creole').value.dict(withoption='numero_etab', withvalue=None) == result
assert api.option('creole.general').value.dict(withoption='numero_etab') == subresult
def test_get_group_type():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
grp = api.option('creole.general')
assert grp.group_type() == groups.family
assert grp.group_type() == 'family'
assert isinstance(grp.group_type(), groups.GroupType)
#raises(TypeError, 'grp.impl_set_group_type(groups.default)')
def test_iter_on_groups():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
2018-09-10 21:59:54 +02:00
result = api.option('creole').list('optiondescription',
group_type=groups.family)
2018-08-01 08:37:58 +02:00
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1']
2018-09-10 21:59:54 +02:00
for i in api.option('creole').list('optiondescription',
group_type=groups.family):
2014-02-02 22:47:46 +01:00
#test StopIteration
break
2018-09-29 18:52:13 +02:00
result = api.option('creole').list('option',
group_type=groups.family)
assert list(result) == []
result = api.option('creole.general').list('optiondescription',
group_type=groups.family)
assert list(result) == []
2014-02-02 22:47:46 +01:00
2018-09-10 21:59:54 +02:00
def test_list_recursive():
descr = make_description()
api = Config(descr)
api.property.read_write()
result = api.option('creole').list('all')
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1']
#
2018-10-31 08:00:19 +01:00
result = api.option.list(recursive=True)
2018-09-10 21:59:54 +02:00
group_names = [res.option.name() for res in result]
2018-10-31 08:00:19 +01:00
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']
2018-09-29 18:52:13 +02:00
result = list(api.option.list(recursive=True, type='optiondescription'))
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'ip_admin_eth0', 'interface1', 'creole']
2018-09-10 21:59:54 +02:00
2014-02-02 22:47:46 +01:00
def test_iter_on_groups_force_permissive():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
2018-08-01 08:37:58 +02:00
result = api.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
2018-08-01 08:37:58 +02:00
# mode_conteneur_actif2 is not visible is not forcepermissive
result = api.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()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
2018-09-10 21:59:54 +02:00
result = api.forcepermissive.option('creole').list(type='optiondescription',
group_type=groups.family)
2018-08-01 08:37:58 +02:00
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1', 'new']
2014-02-02 22:47:46 +01:00
def test_iter_on_groups_props():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('creole.interface1').property.add('disabled')
2018-09-10 21:59:54 +02:00
result = api.option('creole').list(type='optiondescription',
group_type=groups.family)
2018-08-01 08:37:58 +02:00
group_names = [res.option.name() for res in result]
2014-02-02 22:47:46 +01:00
assert group_names == ['general']
2012-11-06 15:19:36 +01:00
2012-11-06 15:19:36 +01:00
def test_iter_on_empty_group():
2018-08-14 23:07:07 +02:00
api = Config(OptionDescription("name", "descr", []))
2018-03-19 08:33:53 +01:00
api.property.read_write()
result = list(api.option.list(type='optiondescription'))
2012-11-06 15:19:36 +01:00
assert result == []
2012-12-06 15:19:43 +01:00
def test_iter_not_group():
2018-08-14 23:07:07 +02:00
api = Config(OptionDescription("name", "descr", []))
2018-03-19 08:33:53 +01:00
api.property.read_write()
2018-10-31 08:00:19 +01:00
try:
list(api.option.list(type='optiondescription', group_type='family'))
except AssertionError:
pass
else:
raise Exception('must raise')
2013-02-06 17:19:56 +01:00
def test_groups_with_master():
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)
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)
assert interface1.impl_get_group_type() == groups.master
2013-02-06 17:19:56 +01:00
2018-04-11 16:36:15 +02:00
def test_groups_is_master():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
var = StrOption('var', "ip réseau autorisé", multi=True)
od2 = OptionDescription('od2', '', [var])
od1 = OptionDescription('od', '', [interface1, od2])
2018-08-14 23:07:07 +02:00
api = Config(od1)
2018-04-11 16:36:15 +02:00
assert not api.option('od2').option.ismasterslaves()
assert api.option('ip_admin_eth0').option.ismasterslaves()
assert not api.option('od2.var').option.ismaster()
assert not api.option('od2.var').option.isslave()
2018-09-22 17:45:52 +02:00
assert api.option('ip_admin_eth0.ip_admin_eth0').option.ismulti()
assert api.option('ip_admin_eth0.netmask_admin_eth0').option.ismulti()
assert not api.option('ip_admin_eth0.ip_admin_eth0').option.issubmulti()
assert not api.option('ip_admin_eth0.netmask_admin_eth0').option.issubmulti()
2018-04-11 16:36:15 +02:00
assert api.option('ip_admin_eth0.ip_admin_eth0').option.ismaster()
assert not api.option('ip_admin_eth0.ip_admin_eth0').option.isslave()
assert not api.option('ip_admin_eth0.netmask_admin_eth0').option.ismaster()
assert api.option('ip_admin_eth0.netmask_admin_eth0').option.isslave()
assert api.option('ip_admin_eth0.netmask_admin_eth0').option.path() == 'ip_admin_eth0.netmask_admin_eth0'
assert api.option('ip_admin_eth0.netmask_admin_eth0').option.defaultmulti() == 'value'
2018-03-19 08:33:53 +01:00
if TIRAMISU_VERSION != 2:
def test_groups_with_master_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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
raises(ConfigError, "Config(interface1)")
2013-02-21 17:07:00 +01:00
def test_groups_with_master_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)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
2018-03-19 08:33:53 +01:00
od = OptionDescription('root', '', [interface1])
Config(od)
assert interface1.impl_get_group_type() == groups.master
2013-02-21 17:07:00 +01:00
2018-04-19 08:19:03 +02:00
def test_groups_with_master_make_dict():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(od)
2018-09-09 12:21:47 +02:00
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []}
2018-09-29 20:05:28 +02:00
assert api.option('ip_admin_eth0.ip_admin_eth0').value.len() == 0
assert api.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 0
2018-04-19 08:19:03 +02:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
2018-09-29 20:05:28 +02:00
assert api.option('ip_admin_eth0.ip_admin_eth0').value.len() == 2
assert api.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 2
2018-09-09 12:21:47 +02:00
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]}
2018-04-19 08:19:03 +02:00
def test_groups_with_master_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',))
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
2018-03-19 08:33:53 +01:00
od = OptionDescription('root', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(od)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
def test_groups_with_master_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',))
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
2018-03-19 08:33:53 +01:00
od = OptionDescription('root', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(od)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#del
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.property.pop('hidden')
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
api.property.add('hidden')
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.property.pop('hidden')
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
2018-03-24 22:37:48 +01:00
def test_groups_with_master_reset_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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(od_)
2018-03-24 22:37:48 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
raises(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()")
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
def test_groups_with_master_reset_out_of_range():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(od_)
2018-03-24 22:37:48 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
raises(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.reset()")
raises(IndexError, "api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)")
def test_groups_with_master_hidden_in_config3():
#if master is hidden, slave 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)
2017-10-14 13:33:25 +02:00
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
2018-03-19 08:33:53 +01:00
od = OptionDescription('root', '', [interface1])
2017-10-14 13:33:25 +02:00
#interface1.impl_set_group_type(groups.master)
2018-08-14 23:07:07 +02:00
api = Config(od)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
def test_allowed_groups():
2013-02-06 17:19:56 +01:00
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')")
2012-12-06 15:19:43 +01:00
def test_values_with_master_disabled_master():
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)
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)
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
api.option('ip_admin_eth0.ip_admin_eth0').property.add('disabled')
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('192.168.230.145')")
2017-05-17 22:13:05 +02:00
def test_sub_group_in_master_group():
2013-02-06 17:19:56 +01:00
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", '', [])
2017-10-14 13:33:25 +02:00
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [subgroup, ip_admin_eth0, netmask_admin_eth0])")
2013-02-06 17:19:56 +01:00
2013-02-21 17:07:00 +01:00
def test_group_always_has_multis():
2013-02-06 17:19:56 +01:00
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")
2017-10-14 13:33:25 +02:00
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
#____________________________________________________________
def test_values_with_master_and_slaves():
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)
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)
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
owner = api.owner.get()
assert interface1.impl_get_group_type() == groups.master
2018-03-19 08:33:53 +01:00
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
#
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0').value.set([None])")
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0').value.pop(0)")
def test_reset_values_with_master_and_slaves():
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)
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)
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
owner = api.owner.get()
assert interface1.impl_get_group_type() == groups.master
2018-03-19 08:33:53 +01:00
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#reset
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
2013-04-18 23:06:14 +02:00
def test_reset_values_with_master_and_slaves_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'])
2017-10-14 13:33:25 +02:00
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [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)
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)
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
owner = api.owner.get()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
2013-04-18 23:06:14 +02:00
def test_values_with_master_and_slaves_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)
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)
2013-04-18 23:06:14 +02:00
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
raises(SlaveError,
"api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')")
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
#
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.pop(1)")
#reset
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145',
'192.168.230.145',
'192.168.230.145'])
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
2013-04-18 23:06:14 +02:00
2017-07-24 18:27:24 +02:00
def test_values_with_master_and_slaves_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)
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)
2017-07-24 18:27:24 +02:00
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.146'])
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145', '192.168.230.146']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.146']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
2017-07-24 18:27:24 +02:00
2013-04-18 23:06:14 +02:00
def test_values_with_master_and_slaves_master():
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)
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)
2013-04-18 23:06:14 +02:00
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
raises(SlaveError, "api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])")
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
2017-10-22 15:10:50 +02:00
def test_values_with_master_and_slaves_master_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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.146"])
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145", "192.168.230.146"]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
2018-06-09 18:59:40 +02:00
compare(api.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',))))
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
2018-06-09 18:59:40 +02:00
compare(api.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',))))
2018-03-19 08:33:53 +01:00
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.146"]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
api.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"])
api.option('ip_admin_eth0.netmask_admin_eth0', 3).value.set('255.255.0.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 4).value.set('255.255.0.0')
2018-06-09 18:59:40 +02:00
compare(api.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'))))
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(5)
2018-06-09 18:59:40 +02:00
compare(api.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'))))
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
2018-06-09 18:59:40 +02:00
compare(api.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'))))
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
2018-06-09 18:59:40 +02:00
compare(api.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'))))
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
2018-06-09 18:59:40 +02:00
compare(api.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_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)
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)
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
owner = api.owner.get()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
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)
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)
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
#delete with value in disabled var
api.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
api.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
#append with value in disabled var
api.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
api.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", '192.168.230.43'])
def test_multi_non_valid_value():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
maconfig = OptionDescription('toto', '', [ip_admin_eth0])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0').value.set(['a'])
raises(ValueError, "api.option('ip_admin_eth0').value.set([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)
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)
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
2017-02-03 23:39:24 +01:00
def test_groups_with_master_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)
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)
2017-02-03 23:39:24 +01:00
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-03-19 08:33:53 +01:00
api.property.read_write()
2018-06-09 18:59:40 +02:00
compare(api.value.exportation(), ((), (), (), ()))
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
2018-06-09 18:59:40 +02:00
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0',), (None,), (('192.168.1.1',),), ('user',)))
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
2018-06-09 18:59:40 +02:00
compare(api.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',))))
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1'])
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
2018-06-09 18:59:40 +02:00
compare(api.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_master_importation():
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-06-09 18:59:40 +02:00
api.property.read_write()
api.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'))))
api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1', '192.168.1.0']
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.255'
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == 'user'
api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'user'
api.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'user'
2018-04-06 23:51:25 +02:00
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('od', '', [interface1])
maconfig = OptionDescription('toto', '', [od1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-04-06 23:51:25 +02:00
api.property.read_write()
assert api.option('od.ip_admin_eth0.ip_admin_eth0').option.get()
raises(APIError, "api.option('od.ip_admin_eth0.ip_admin_eth0', 0).option.get()")
assert api.option('od.ip_admin_eth0.netmask_admin_eth0', 0).option.get()
assert api.option('od.ip_admin_eth0').option.get()
raises(APIError, "api.option('od.ip_admin_eth0', 0).option.get()")
assert api.option('od').option.get()
raises(APIError, "api.option('od', 0).option.get()")
2018-04-09 21:37:49 +02:00
def test_without_master_or_slave():
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [])")
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0])")
#empty optiondescription is allowed
OptionDescription('ip_admin_eth0', '', [])
def test_master_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, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_slave_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, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
2018-04-12 23:04:33 +02:00
def test_slave_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 = MasterSlaves('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 = MasterSlaves('interface1', '', [ip_admin_eth1, netmask_admin_eth1])
od1 = OptionDescription('od', '', [interface0, interface1])
maconfig = OptionDescription('toto', '', [od1])
2018-08-14 23:07:07 +02:00
raises(ConfigError, "Config(maconfig)")
2018-04-12 23:04:33 +02:00
def test_slave_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 = MasterSlaves('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 = MasterSlaves('interface1', '', [ip_admin_eth1, netmask_admin_eth1])
od1 = OptionDescription('od', '', [interface0, interface1])
maconfig = OptionDescription('toto', '', [od1])
2018-08-14 23:07:07 +02:00
api = Config(maconfig)
2018-04-12 23:04:33 +02:00
api.property.read_write()
def test_slave_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 = MasterSlaves('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('od', '', [interface0])
maconfig = OptionDescription('toto', '', [od1])
2018-08-14 23:07:07 +02:00
raises(ConfigError, "Config(maconfig)")