2012-07-13 09:42:14 +02:00
|
|
|
# coding: utf-8
|
|
|
|
import autopath
|
2012-07-23 14:52:08 +02:00
|
|
|
from tiramisu.config import *
|
|
|
|
from tiramisu.option import *
|
2013-02-25 11:33:20 +01:00
|
|
|
from tiramisu.setting import groups, owners
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2012-12-06 15:19:43 +01:00
|
|
|
from py.test import raises
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
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)
|
2012-07-13 09:42:14 +02:00
|
|
|
mode_conteneur_actif = BoolOption('mode_conteneur_actif', "le serveur est en mode conteneur",
|
|
|
|
default=False)
|
|
|
|
adresse_serveur_ntp = StrOption('serveur_ntp', "adresse serveur ntp", multi=True)
|
|
|
|
time_zone = ChoiceOption('time_zone', 'fuseau horaire du serveur',
|
2013-04-03 12:20:26 +02:00
|
|
|
('Paris', 'Londres'), 'Paris')
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
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])
|
2012-12-06 18:14:57 +01:00
|
|
|
interface1.set_group_type(groups.family)
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2012-11-06 15:19:36 +01:00
|
|
|
general = OptionDescription('general', '', [numero_etab, nom_machine,
|
2012-07-13 09:42:14 +02:00
|
|
|
nombre_interfaces, activer_proxy_client,
|
2012-11-06 15:19:36 +01:00
|
|
|
mode_conteneur_actif, adresse_serveur_ntp,
|
2012-07-13 09:42:14 +02:00
|
|
|
time_zone])
|
2012-12-06 18:14:57 +01:00
|
|
|
general.set_group_type(groups.family)
|
2012-07-13 09:42:14 +02:00
|
|
|
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1])
|
|
|
|
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole] )
|
|
|
|
return descr
|
|
|
|
|
|
|
|
def test_base_config():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
assert config.creole.general.activer_proxy_client == False
|
|
|
|
assert config.creole.general.nom_machine == "eoleng"
|
2012-11-06 15:19:36 +01:00
|
|
|
assert config.get('nom_machine') == "eoleng"
|
2012-07-13 09:42:14 +02:00
|
|
|
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 make_dict(config.creole) == 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 make_dict(config.creole, flatten=True) == result
|
|
|
|
|
|
|
|
def test_get_group_type():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
grp = config.unwrap_from_path('creole.general')
|
2012-12-10 14:10:05 +01:00
|
|
|
assert grp.get_group_type() == groups.family
|
|
|
|
assert grp.get_group_type() == 'family'
|
2012-12-10 14:38:25 +01:00
|
|
|
assert isinstance(grp.get_group_type(), groups.GroupType)
|
2012-12-10 14:10:05 +01:00
|
|
|
grp.set_group_type(groups.default)
|
2012-12-10 14:38:25 +01:00
|
|
|
assert isinstance(grp.get_group_type(), groups.DefaultGroupType)
|
2012-12-10 14:10:05 +01:00
|
|
|
assert grp.get_group_type() == groups.default
|
|
|
|
assert grp.get_group_type() == 'default'
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
def test_iter_on_groups():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
2012-12-06 18:14:57 +01:00
|
|
|
result = list(config.creole.iter_groups(group_type=groups.family))
|
2012-07-13 09:42:14 +02:00
|
|
|
group_names = [res[0] for res in result]
|
|
|
|
assert group_names == ['general', 'interface1']
|
2012-11-06 15:19:36 +01:00
|
|
|
|
|
|
|
def test_iter_on_empty_group():
|
|
|
|
config = Config(OptionDescription("name", "descr", [] ))
|
|
|
|
result = list(config.iter_groups())
|
|
|
|
assert result == []
|
|
|
|
for i in config.iter_groups():
|
|
|
|
pass
|
|
|
|
for i in config:
|
|
|
|
pass
|
|
|
|
assert [] == list(config)
|
2012-12-06 15:19:43 +01:00
|
|
|
|
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)
|
|
|
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
|
|
interface1.set_group_type(groups.master)
|
|
|
|
assert interface1.get_group_type() == groups.master
|
|
|
|
|
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)
|
|
|
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
|
|
interface1.set_group_type(groups.master)
|
|
|
|
cfg = Config(interface1)
|
|
|
|
assert interface1.get_group_type() == groups.master
|
|
|
|
|
2013-02-06 16:21:30 +01:00
|
|
|
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)
|
2013-02-06 16:21:30 +01:00
|
|
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
|
|
raises(ConfigError, "interface1.set_group_type('toto')")
|
2012-12-06 15:19:43 +01:00
|
|
|
|
2013-02-06 16:21:30 +01:00
|
|
|
def test_master_not_valid_name():
|
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)
|
2013-02-06 16:21:30 +01:00
|
|
|
invalid_group = OptionDescription('interface1', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
|
|
raises(ConfigError, "invalid_group.set_group_type(groups.master)")
|
2012-12-06 15:19:43 +01:00
|
|
|
|
2013-02-06 16:21:30 +01: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)
|
2013-02-06 16:21:30 +01:00
|
|
|
subgroup = OptionDescription("subgroup", '', [])
|
|
|
|
invalid_group = OptionDescription('ip_admin_eth0', '', [subgroup, ip_admin_eth0, netmask_admin_eth0])
|
|
|
|
raises(ConfigError, "invalid_group.set_group_type(groups.master)")
|
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")
|
|
|
|
group = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
|
|
raises(ConfigError, "group.set_group_type(groups.master)")
|
2013-02-25 11:33:20 +01:00
|
|
|
|
|
|
|
#____________________________________________________________
|
|
|
|
|
|
|
|
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)
|
|
|
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
|
|
interface1.set_group_type(groups.master)
|
|
|
|
maconfig = OptionDescription('toto', '', [interface1])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
opt = cfg.unwrap_from_path("ip_admin_eth0.ip_admin_eth0")
|
|
|
|
owner = cfg._cfgimpl_context._cfgimpl_settings.getowner()
|
|
|
|
assert interface1.get_group_type() == groups.master
|
2013-04-03 12:20:26 +02:00
|
|
|
assert cfg.cfgimpl_get_values().getowner(opt) == owners.default
|
2013-02-25 11:33:20 +01:00
|
|
|
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
|
|
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"]
|
2013-04-03 12:20:26 +02:00
|
|
|
assert cfg.cfgimpl_get_values().getowner(opt) == owner
|
2013-02-25 11:33:20 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
|
|
interface1.set_group_type(groups.master)
|
|
|
|
maconfig = OptionDescription('toto', '', [interface1])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
opt = cfg.unwrap_from_path("ip_admin_eth0.ip_admin_eth0")
|
|
|
|
owner = cfg._cfgimpl_context._cfgimpl_settings.getowner()
|
|
|
|
assert interface1.get_group_type() == groups.master
|
2013-04-03 12:20:26 +02:00
|
|
|
assert cfg.cfgimpl_get_values().getowner(opt) == owners.default
|
2013-02-25 11:33:20 +01:00
|
|
|
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
2013-04-03 12:20:26 +02:00
|
|
|
assert cfg.cfgimpl_get_values().getowner(opt) == owner
|
|
|
|
cfg.cfgimpl_get_values().reset(opt)
|
|
|
|
assert cfg.cfgimpl_get_values().getowner(opt) == owners.default
|
2013-02-25 11:33:20 +01:00
|
|
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|