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 *
|
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",
|
|
|
|
default=False)
|
|
|
|
mode_conteneur_actif = BoolOption('mode_conteneur_actif', "le serveur est en mode conteneur",
|
|
|
|
default=False)
|
|
|
|
# hidden (variable cachée)
|
|
|
|
# mode_conteneur_actif.taint()
|
|
|
|
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.set_group_type('group')
|
|
|
|
|
|
|
|
general = OptionDescription('general', '', [numero_etab, nom_machine,
|
|
|
|
nombre_interfaces, activer_proxy_client,
|
|
|
|
mode_conteneur_actif, adresse_serveur_ntp,
|
|
|
|
time_zone])
|
|
|
|
general.set_group_type('family')
|
|
|
|
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"
|
|
|
|
assert config.get('nom_machine') == "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 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')
|
|
|
|
assert grp.get_group_type() == "family"
|
|
|
|
|
|
|
|
def test_iter_on_groups():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
result = list(config.creole.iter_groups(group_type= "family"))
|
|
|
|
group_names = [res[0] for res in result]
|
|
|
|
assert group_names == ['general']
|
|
|
|
result = list(config.creole.iter_groups())
|
|
|
|
group_names = [res[0] for res in result]
|
|
|
|
assert group_names == ['general', 'interface1']
|
|
|
|
|