better error message if option that does not exists is in root optiondescription
This commit is contained in:
parent
42291aec51
commit
280d2ebd0a
|
@ -4,9 +4,8 @@ do_autopath()
|
||||||
from py.test import raises
|
from py.test import raises
|
||||||
|
|
||||||
from tiramisu.setting import groups
|
from tiramisu.setting import groups
|
||||||
from tiramisu import Config, MetaConfig
|
from tiramisu import Config, MetaConfig, ChoiceOption, BoolOption, IntOption, \
|
||||||
from tiramisu import ChoiceOption, BoolOption, IntOption, \
|
StrOption, OptionDescription, groups
|
||||||
StrOption, OptionDescription
|
|
||||||
from .test_state import _diff_opts, _diff_conf
|
from .test_state import _diff_opts, _diff_conf
|
||||||
from tiramisu.storage import list_sessions
|
from tiramisu.storage import list_sessions
|
||||||
|
|
||||||
|
@ -37,15 +36,12 @@ def make_description():
|
||||||
|
|
||||||
leader = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
leader = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
interface1 = OptionDescription('interface1', '', [leader])
|
interface1 = OptionDescription('interface1', '', [leader])
|
||||||
interface1.impl_set_group_type(groups.family)
|
|
||||||
|
|
||||||
general = OptionDescription('general', '', [numero_etab, nom_machine,
|
general = OptionDescription('general', '', [numero_etab, nom_machine,
|
||||||
nombre_interfaces, activer_proxy_client,
|
nombre_interfaces, activer_proxy_client,
|
||||||
mode_conteneur_actif, mode_conteneur_actif2,
|
mode_conteneur_actif, mode_conteneur_actif2,
|
||||||
adresse_serveur_ntp, time_zone, wantref_option])
|
adresse_serveur_ntp, time_zone, wantref_option])
|
||||||
general.impl_set_group_type(groups.family)
|
|
||||||
new = OptionDescription('new', '', [], properties=('hidden',))
|
new = OptionDescription('new', '', [], properties=('hidden',))
|
||||||
new.impl_set_group_type(groups.family)
|
|
||||||
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1, new])
|
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1, new])
|
||||||
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole])
|
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole])
|
||||||
return descr
|
return descr
|
||||||
|
|
|
@ -11,6 +11,9 @@ from tiramisu.error import LeadershipError, PropertiesOptionError, APIError, Con
|
||||||
from tiramisu.storage import list_sessions
|
from tiramisu.storage import list_sessions
|
||||||
|
|
||||||
|
|
||||||
|
groups.family = groups.GroupType('family')
|
||||||
|
|
||||||
|
|
||||||
def teardown_function(function):
|
def teardown_function(function):
|
||||||
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,13 @@ do_autopath()
|
||||||
from py.test import raises
|
from py.test import raises
|
||||||
|
|
||||||
from tiramisu.error import APIError, ConfigError
|
from tiramisu.error import APIError, ConfigError
|
||||||
from tiramisu import IntOption, SymLinkOption, OptionDescription, Config, Calculation
|
from tiramisu import IntOption, SymLinkOption, OptionDescription, Config, Calculation, groups, list_sessions
|
||||||
from tiramisu.setting import groups
|
|
||||||
from tiramisu.storage import list_sessions
|
|
||||||
from tiramisu.i18n import _
|
from tiramisu.i18n import _
|
||||||
|
|
||||||
|
try:
|
||||||
|
groups.family
|
||||||
|
except:
|
||||||
|
groups.family = groups.GroupType('family')
|
||||||
|
|
||||||
def teardown_function(function):
|
def teardown_function(function):
|
||||||
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
||||||
|
|
|
@ -20,7 +20,7 @@ from .option import *
|
||||||
from .error import APIError
|
from .error import APIError
|
||||||
from .api import Config, MetaConfig, GroupConfig, MixConfig
|
from .api import Config, MetaConfig, GroupConfig, MixConfig
|
||||||
from .option import __all__ as all_options
|
from .option import __all__ as all_options
|
||||||
from .setting import owners, undefined
|
from .setting import owners, groups, undefined
|
||||||
from .storage import default_storage, Storage, list_sessions, \
|
from .storage import default_storage, Storage, list_sessions, \
|
||||||
delete_session
|
delete_session
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@ allfuncs = ['Calculation',
|
||||||
'Config',
|
'Config',
|
||||||
'APIError',
|
'APIError',
|
||||||
'undefined',
|
'undefined',
|
||||||
|
'owners',
|
||||||
|
'groups',
|
||||||
'default_storage',
|
'default_storage',
|
||||||
'Storage',
|
'Storage',
|
||||||
'list_sessions',
|
'list_sessions',
|
||||||
|
|
|
@ -27,7 +27,7 @@ from .error import PropertiesOptionError, ConfigError, ConflictError, \
|
||||||
LeadershipError
|
LeadershipError
|
||||||
from .option import SynDynOptionDescription, DynOptionDescription, Leadership
|
from .option import SynDynOptionDescription, DynOptionDescription, Leadership
|
||||||
from .option.baseoption import BaseOption, valid_name
|
from .option.baseoption import BaseOption, valid_name
|
||||||
from .setting import OptionBag, ConfigBag, Settings, undefined
|
from .setting import OptionBag, ConfigBag, Settings, undefined, groups
|
||||||
from .storage import get_storages, gen_storage_id, get_default_values_storages, list_sessions, Cache
|
from .storage import get_storages, gen_storage_id, get_default_values_storages, list_sessions, Cache
|
||||||
from .value import Values
|
from .value import Values
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
@ -573,6 +573,7 @@ class _CommonConfig(SubConfig):
|
||||||
def _impl_build_all_caches(self):
|
def _impl_build_all_caches(self):
|
||||||
descr = self.cfgimpl_get_description()
|
descr = self.cfgimpl_get_description()
|
||||||
if not descr.impl_already_build_caches():
|
if not descr.impl_already_build_caches():
|
||||||
|
descr._group_type = groups.root
|
||||||
descr._build_cache(display_name=self._display_name)
|
descr._build_cache(display_name=self._display_name)
|
||||||
config_bag = ConfigBag(context=self)
|
config_bag = ConfigBag(context=self)
|
||||||
descr.impl_build_force_store_values(config_bag)
|
descr.impl_build_force_store_values(config_bag)
|
||||||
|
|
|
@ -222,9 +222,14 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||||
if name == cname + suffix:
|
if name == cname + suffix:
|
||||||
return child.to_dynoption(subpath,
|
return child.to_dynoption(subpath,
|
||||||
suffix)
|
suffix)
|
||||||
|
if self.impl_get_group_type() == groups.root:
|
||||||
|
raise AttributeError(_('unknown option "{0}" '
|
||||||
|
'in root optiondescription'
|
||||||
|
'').format(name))
|
||||||
|
else:
|
||||||
raise AttributeError(_('unknown option "{0}" '
|
raise AttributeError(_('unknown option "{0}" '
|
||||||
'in optiondescription "{1}"'
|
'in optiondescription "{1}"'
|
||||||
'').format(name, self.impl_getname()))
|
'').format(name, self.impl_get_display_name()))
|
||||||
|
|
||||||
def get_children(self,
|
def get_children(self,
|
||||||
config_bag: Union[ConfigBag, Undefined],
|
config_bag: Union[ConfigBag, Undefined],
|
||||||
|
@ -329,6 +334,7 @@ class OptionDescription(OptionDescriptionWalk):
|
||||||
:param group_type: an instance of `GroupType` or `LeadershipGroupType`
|
:param group_type: an instance of `GroupType` or `LeadershipGroupType`
|
||||||
that lives in `setting.groups`
|
that lives in `setting.groups`
|
||||||
"""
|
"""
|
||||||
|
if __debug__:
|
||||||
if self._group_type != groups.default:
|
if self._group_type != groups.default:
|
||||||
raise ValueError(_('cannot change group_type if already set '
|
raise ValueError(_('cannot change group_type if already set '
|
||||||
'(old {0}, new {1})').format(self._group_type,
|
'(old {0}, new {1})').format(self._group_type,
|
||||||
|
|
|
@ -175,6 +175,7 @@ class OptionBag:
|
||||||
for key in self.__slots__:
|
for key in self.__slots__:
|
||||||
if key == 'properties' and self.config_bag is undefined:
|
if key == 'properties' and self.config_bag is undefined:
|
||||||
continue
|
continue
|
||||||
|
if hasattr(self, key):
|
||||||
setattr(option_bag, key, getattr(self, key))
|
setattr(option_bag, key, getattr(self, key))
|
||||||
return option_bag
|
return option_bag
|
||||||
|
|
||||||
|
@ -285,6 +286,11 @@ class GroupModule(_NameSpace):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class RootGroupType(GroupType):
|
||||||
|
"""root means this is the root optiondescription of whole config
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class OwnerModule(_NameSpace):
|
class OwnerModule(_NameSpace):
|
||||||
"""emulates a module to manage unique owner names.
|
"""emulates a module to manage unique owner names.
|
||||||
|
@ -321,9 +327,9 @@ groups.default = groups.DefaultGroupType('default')
|
||||||
leader's option"""
|
leader's option"""
|
||||||
groups.leadership = groups.LeadershipGroupType('leadership')
|
groups.leadership = groups.LeadershipGroupType('leadership')
|
||||||
|
|
||||||
""" groups.family
|
""" groups.root
|
||||||
example of group, no special behavior with this group's type"""
|
this group is the root optiondescription of whole config"""
|
||||||
groups.family = groups.GroupType('family')
|
groups.root = groups.RootGroupType('root')
|
||||||
|
|
||||||
|
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
|
Loading…
Reference in New Issue