Merge branch 'master' of ssh://git.labs.libre-entreprise.org/gitroot/tiramisu
This commit is contained in:
commit
480ed190aa
|
@ -42,6 +42,7 @@ def make_description():
|
||||||
def test_base_config():
|
def test_base_config():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
|
config.read_write()
|
||||||
assert config.creole.general.activer_proxy_client is False
|
assert config.creole.general.activer_proxy_client is False
|
||||||
assert config.creole.general.nom_machine == "eoleng"
|
assert config.creole.general.nom_machine == "eoleng"
|
||||||
assert config.find_first(byname='nom_machine', type_='value') == "eoleng"
|
assert config.find_first(byname='nom_machine', type_='value') == "eoleng"
|
||||||
|
@ -61,6 +62,7 @@ def test_base_config():
|
||||||
def test_make_dict_filter():
|
def test_make_dict_filter():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
|
config.read_write()
|
||||||
result = {'general.numero_etab': None, 'general.nombre_interfaces': 1,
|
result = {'general.numero_etab': None, 'general.nombre_interfaces': 1,
|
||||||
'general.serveur_ntp': [], 'general.mode_conteneur_actif': False,
|
'general.serveur_ntp': [], 'general.mode_conteneur_actif': False,
|
||||||
'general.time_zone': 'Paris', 'general.nom_machine': 'eoleng',
|
'general.time_zone': 'Paris', 'general.nom_machine': 'eoleng',
|
||||||
|
@ -73,6 +75,7 @@ def test_make_dict_filter():
|
||||||
def test_get_group_type():
|
def test_get_group_type():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
|
config.read_write()
|
||||||
grp = config.unwrap_from_path('creole.general')
|
grp = config.unwrap_from_path('creole.general')
|
||||||
assert grp.impl_get_group_type() == groups.family
|
assert grp.impl_get_group_type() == groups.family
|
||||||
assert grp.impl_get_group_type() == 'family'
|
assert grp.impl_get_group_type() == 'family'
|
||||||
|
@ -83,6 +86,7 @@ def test_get_group_type():
|
||||||
def test_iter_on_groups():
|
def test_iter_on_groups():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
|
config.read_write()
|
||||||
result = list(config.creole.iter_groups(group_type=groups.family))
|
result = list(config.creole.iter_groups(group_type=groups.family))
|
||||||
group_names = [res[0] for res in result]
|
group_names = [res[0] for res in result]
|
||||||
assert group_names == ['general', 'interface1']
|
assert group_names == ['general', 'interface1']
|
||||||
|
@ -90,6 +94,7 @@ def test_iter_on_groups():
|
||||||
|
|
||||||
def test_iter_on_empty_group():
|
def test_iter_on_empty_group():
|
||||||
config = Config(OptionDescription("name", "descr", []))
|
config = Config(OptionDescription("name", "descr", []))
|
||||||
|
config.read_write()
|
||||||
result = list(config.iter_groups())
|
result = list(config.iter_groups())
|
||||||
assert result == []
|
assert result == []
|
||||||
for i in config.iter_groups():
|
for i in config.iter_groups():
|
||||||
|
@ -153,6 +158,7 @@ def test_values_with_master_and_slaves():
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
maconfig = OptionDescription('toto', '', [interface1])
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
cfg = Config(maconfig)
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_write()
|
||||||
owner = cfg.cfgimpl_get_settings().getowner()
|
owner = cfg.cfgimpl_get_settings().getowner()
|
||||||
assert interface1.impl_get_group_type() == groups.master
|
assert interface1.impl_get_group_type() == groups.master
|
||||||
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default
|
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default
|
||||||
|
@ -172,6 +178,7 @@ def test_reset_values_with_master_and_slaves():
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
maconfig = OptionDescription('toto', '', [interface1])
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
cfg = Config(maconfig)
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_write()
|
||||||
owner = cfg.cfgimpl_get_settings().getowner()
|
owner = cfg.cfgimpl_get_settings().getowner()
|
||||||
assert interface1.impl_get_group_type() == groups.master
|
assert interface1.impl_get_group_type() == groups.master
|
||||||
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default
|
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default
|
||||||
|
@ -193,6 +200,7 @@ def test_values_with_master_and_slaves_slave():
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
maconfig = OptionDescription('toto', '', [interface1])
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
cfg = Config(maconfig)
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_write()
|
||||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']")
|
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']")
|
||||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||||
|
@ -215,6 +223,7 @@ def test_values_with_master_and_slaves_master():
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
maconfig = OptionDescription('toto', '', [interface1])
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
cfg = Config(maconfig)
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_write()
|
||||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||||
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]
|
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]
|
||||||
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145", "192.168.230.145"]
|
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145", "192.168.230.145"]
|
||||||
|
@ -222,3 +231,55 @@ def test_values_with_master_and_slaves_master():
|
||||||
raises(SlaveError, 'cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]')
|
raises(SlaveError, 'cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]')
|
||||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(1)
|
cfg.ip_admin_eth0.ip_admin_eth0.pop(1)
|
||||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"]
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"]
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_write()
|
||||||
|
owner = cfg.cfgimpl_get_settings().getowner()
|
||||||
|
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default
|
||||||
|
assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||||
|
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owner
|
||||||
|
assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||||
|
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owner
|
||||||
|
assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_write()
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||||
|
cfg.ip_admin_eth0.netmask_admin_eth0 = ["192.168.230.145"]
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||||
|
del(cfg.ip_admin_eth0.netmask_admin_eth0)
|
||||||
|
cfg.cfgimpl_get_settings()[netmask_admin_eth0].append('disabled')
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||||
|
|
||||||
|
#delete with value in disabled var
|
||||||
|
cfg.cfgimpl_get_settings()[netmask_admin_eth0].remove('disabled')
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||||
|
cfg.ip_admin_eth0.netmask_admin_eth0 = ["192.168.230.145"]
|
||||||
|
cfg.cfgimpl_get_settings()[netmask_admin_eth0].append('disabled')
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||||
|
|
||||||
|
#append with value in disabled var
|
||||||
|
cfg.cfgimpl_get_settings()[netmask_admin_eth0].remove('disabled')
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||||
|
cfg.ip_admin_eth0.netmask_admin_eth0 = ["192.168.230.145"]
|
||||||
|
cfg.cfgimpl_get_settings()[netmask_admin_eth0].append('disabled')
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.230.43')
|
||||||
|
|
|
@ -508,6 +508,10 @@ class MetaConfig(ConfigCommon):
|
||||||
self._impl_settings = Setting(self)
|
self._impl_settings = Setting(self)
|
||||||
self._impl_values = Values(self)
|
self._impl_values = Values(self)
|
||||||
self._impl_meta = None
|
self._impl_meta = None
|
||||||
|
self._impl_informations = {}
|
||||||
|
|
||||||
|
def cfgimpl_get_children(self):
|
||||||
|
return self._impl_children
|
||||||
|
|
||||||
def cfgimpl_get_context(self):
|
def cfgimpl_get_context(self):
|
||||||
"a meta config is a config wich has a setting, that is itself"
|
"a meta config is a config wich has a setting, that is itself"
|
||||||
|
|
|
@ -93,18 +93,21 @@ class Values(object):
|
||||||
return self._values
|
return self._values
|
||||||
|
|
||||||
def getitem(self, opt, validate=True, force_permissive=False,
|
def getitem(self, opt, validate=True, force_permissive=False,
|
||||||
force_properties=None):
|
force_properties=None, validate_properties=True):
|
||||||
if opt in self._cache:
|
if opt in self._cache:
|
||||||
exp = time()
|
exp = time()
|
||||||
value, created = self._cache[opt]
|
value, created = self._cache[opt]
|
||||||
if exp < created:
|
if exp < created:
|
||||||
return value
|
return value
|
||||||
val = self._getitem(opt, validate, force_permissive, force_properties)
|
val = self._getitem(opt, validate, force_permissive, force_properties,
|
||||||
if validate and force_permissive is False and force_properties is None:
|
validate_properties)
|
||||||
|
if validate and validate_properties and force_permissive is False and \
|
||||||
|
force_properties is None:
|
||||||
self._set_cache(opt, val)
|
self._set_cache(opt, val)
|
||||||
return val
|
return val
|
||||||
|
|
||||||
def _getitem(self, opt, validate, force_permissive, force_properties):
|
def _getitem(self, opt, validate, force_permissive, force_properties,
|
||||||
|
validate_properties):
|
||||||
# options with callbacks
|
# options with callbacks
|
||||||
setting = self.context.cfgimpl_get_settings()
|
setting = self.context.cfgimpl_get_settings()
|
||||||
value = self._get_value(opt, validate)
|
value = self._get_value(opt, validate)
|
||||||
|
@ -133,6 +136,7 @@ class Values(object):
|
||||||
if self.is_default_owner(opt) and \
|
if self.is_default_owner(opt) and \
|
||||||
'force_store_value' in setting[opt]:
|
'force_store_value' in setting[opt]:
|
||||||
self.setitem(opt, value, is_write=False)
|
self.setitem(opt, value, is_write=False)
|
||||||
|
if validate_properties:
|
||||||
setting.validate_properties(opt, False, False, value=value,
|
setting.validate_properties(opt, False, False, value=value,
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
force_properties=force_properties)
|
force_properties=force_properties)
|
||||||
|
@ -152,9 +156,11 @@ class Values(object):
|
||||||
self._setvalue(opt, value, force_permissive=force_permissive,
|
self._setvalue(opt, value, force_permissive=force_permissive,
|
||||||
is_write=is_write)
|
is_write=is_write)
|
||||||
|
|
||||||
def _setvalue(self, opt, value, force_permissive=False, force_properties=None, is_write=True):
|
def _setvalue(self, opt, value, force_permissive=False, force_properties=None,
|
||||||
|
is_write=True, validate_properties=True):
|
||||||
self.context.cfgimpl_reset_cache()
|
self.context.cfgimpl_reset_cache()
|
||||||
setting = self.context.cfgimpl_get_settings()
|
setting = self.context.cfgimpl_get_settings()
|
||||||
|
if validate_properties:
|
||||||
setting.validate_properties(opt, False, is_write,
|
setting.validate_properties(opt, False, is_write,
|
||||||
value=value,
|
value=value,
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
|
@ -276,11 +282,13 @@ class Multi(list):
|
||||||
for slave in self.opt.impl_get_master_slaves():
|
for slave in self.opt.impl_get_master_slaves():
|
||||||
values = self.context.cfgimpl_get_values()
|
values = self.context.cfgimpl_get_values()
|
||||||
if not values.is_default_owner(slave):
|
if not values.is_default_owner(slave):
|
||||||
values[slave].append(slave.impl_getdefault_multi(),
|
#get multi without valid properties
|
||||||
|
values.getitem(slave, validate_properties=False).append(
|
||||||
|
slave.impl_getdefault_multi(),
|
||||||
force=True)
|
force=True)
|
||||||
self._validate(value)
|
self._validate(value)
|
||||||
#assume not checking mandatory property
|
#set value without valid properties
|
||||||
self.context.cfgimpl_get_values()._setvalue(self.opt, self)
|
self.context.cfgimpl_get_values()._setvalue(self.opt, self, validate_properties=not force)
|
||||||
super(Multi, self).append(value)
|
super(Multi, self).append(value)
|
||||||
|
|
||||||
def _validate(self, value):
|
def _validate(self, value):
|
||||||
|
@ -302,6 +310,10 @@ class Multi(list):
|
||||||
" which is a slave").format(self.opt._name))
|
" which is a slave").format(self.opt._name))
|
||||||
elif self.opt.impl_get_multitype() == multitypes.master:
|
elif self.opt.impl_get_multitype() == multitypes.master:
|
||||||
for slave in self.opt.impl_get_master_slaves():
|
for slave in self.opt.impl_get_master_slaves():
|
||||||
self.context.cfgimpl_get_values()[slave].pop(key, force=True)
|
values = self.context.cfgimpl_get_values()
|
||||||
self.context.cfgimpl_get_values()._setvalue(self.opt, self)
|
if not values.is_default_owner(slave):
|
||||||
|
#get multi without valid properties
|
||||||
|
values.getitem(slave, validate_properties=False).pop(key, force=True)
|
||||||
|
#set value without valid properties
|
||||||
|
self.context.cfgimpl_get_values()._setvalue(self.opt, self, validate_properties=not force)
|
||||||
return super(Multi, self).pop(key)
|
return super(Multi, self).pop(key)
|
||||||
|
|
Loading…
Reference in New Issue