find in group or meta should return GroupConfig (and not KerneleGroupConfig) and remote 'first' attributs
This commit is contained in:
parent
5b5f06a612
commit
e4362e9b09
|
@ -248,26 +248,26 @@ def test_meta_meta_set():
|
|||
assert meta.config('meta.conf1').option('od1.i1').value.get() == meta.config('meta.conf2').option('od1.i1').value.get() == 7
|
||||
#
|
||||
dconfigs = []
|
||||
for conf in meta.config.find('i1', value=7, first=True).config.list():
|
||||
for conf in meta.config.find('i1', value=7).config.list():
|
||||
dconfigs.append(conf._config_bag.context)
|
||||
assert [conf1, conf2] == dconfigs
|
||||
meta.config('meta.conf1').option('od1.i1').value.set(8)
|
||||
#
|
||||
dconfigs = []
|
||||
for conf in meta.config.find('i1', first=True).config.list():
|
||||
for conf in meta.config.find('i1').config.list():
|
||||
dconfigs.append(conf._config_bag.context)
|
||||
assert [conf1, conf2] == dconfigs
|
||||
assert conf2 == list(meta.config.find('i1', value=7, first=True).config.list())[0]._config_bag.context
|
||||
assert conf1 == list(meta.config.find('i1', value=8, first=True).config.list())[0]._config_bag.context
|
||||
assert conf2 == list(meta.config.find('i1', value=7).config.list())[0]._config_bag.context
|
||||
assert conf1 == list(meta.config.find('i1', value=8).config.list())[0]._config_bag.context
|
||||
#
|
||||
dconfigs = []
|
||||
for conf in meta.config.find('i5', value=2, first=True).config.list():
|
||||
for conf in meta.config.find('i5', value=2).config.list():
|
||||
dconfigs.append(conf._config_bag.context)
|
||||
assert [conf1, conf2] == dconfigs
|
||||
#
|
||||
raises(AttributeError, "meta.config.find('i1', value=10, first=True)")
|
||||
raises(AttributeError, "meta.config.find('not', value=10, first=True)")
|
||||
raises(AttributeError, "meta.config.find('i6', first=True)")
|
||||
raises(AttributeError, "meta.config.find('i1', value=10)")
|
||||
raises(AttributeError, "meta.config.find('not', value=10)")
|
||||
raises(AttributeError, "meta.config.find('i6')")
|
||||
raises(ValueError, "meta.value.set('od1.i6', 7, only_config=True, force_default=True)")
|
||||
raises(ValueError, "meta.value.set('od1.i6', 7, only_config=True, force_default_if_same=True)")
|
||||
raises(ValueError, "meta.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True)")
|
||||
|
@ -303,9 +303,17 @@ def test_group_find_firsts():
|
|||
conf1 = Config(od2, session_id='conf1')
|
||||
conf2 = Config(od2, session_id='conf2')
|
||||
grp = GroupConfig([conf1, conf2])
|
||||
itr = grp.config.find('i1', first=True).config.list()
|
||||
itr = grp.config.find('i1').config.list()
|
||||
conf1._config_bag.context == next(itr)._config_bag.context
|
||||
conf2._config_bag.context == next(itr)._config_bag.context
|
||||
try:
|
||||
next(itr)
|
||||
except StopIteration:
|
||||
pass
|
||||
except:
|
||||
raise Exception('no')
|
||||
else:
|
||||
raise Exception('no')
|
||||
|
||||
|
||||
def test_group_group():
|
||||
|
@ -352,19 +360,19 @@ def test_meta_master_slaves():
|
|||
conf2 = Config(od, session_id='conf2')
|
||||
meta = MetaConfig([conf1, conf2])
|
||||
meta.property.read_only()
|
||||
itr = meta.config.find('ip_admin_eth0', first=True).config.list()
|
||||
itr = meta.config.find('ip_admin_eth0').config.list()
|
||||
assert conf1._config_bag.context == next(itr)._config_bag.context
|
||||
assert conf2._config_bag.context == next(itr)._config_bag.context
|
||||
itr = meta.config.find('netmask_admin_eth0', first=True).config.list()
|
||||
itr = meta.config.find('netmask_admin_eth0').config.list()
|
||||
assert conf1._config_bag.context == next(itr)._config_bag.context
|
||||
assert conf2._config_bag.context == next(itr)._config_bag.context
|
||||
meta.property.read_write()
|
||||
raises(AttributeError, "meta.config.find('netmask_admin_eth0', first=True)")
|
||||
itr = meta.unrestraint.config.find('netmask_admin_eth0', first=True).config.list()
|
||||
raises(AttributeError, "meta.config.find('netmask_admin_eth0')")
|
||||
itr = meta.unrestraint.config.find('netmask_admin_eth0').config.list()
|
||||
assert conf1._config_bag.context == next(itr)._config_bag.context
|
||||
assert conf2._config_bag.context == next(itr)._config_bag.context
|
||||
meta.property.read_only()
|
||||
itr = meta.config.find('netmask_admin_eth0', first=True).config.list()
|
||||
itr = meta.config.find('netmask_admin_eth0').config.list()
|
||||
assert conf1._config_bag.context == next(itr)._config_bag.context
|
||||
assert conf2._config_bag.context == next(itr)._config_bag.context
|
||||
|
||||
|
|
|
@ -1086,10 +1086,10 @@ class _TiramisuContextConfig(TiramisuContext, _TiramisuContextConfigReset):
|
|||
storage=None,
|
||||
metaconfig_prefix=None):
|
||||
return Config(self._config_bag.context.duplicate(session_id,
|
||||
persistent=persistent,
|
||||
storage=storage,
|
||||
metaconfig_prefix=metaconfig_prefix,
|
||||
deep=True))
|
||||
persistent=persistent,
|
||||
storage=storage,
|
||||
metaconfig_prefix=metaconfig_prefix,
|
||||
deep=True))
|
||||
|
||||
def metaconfig(self):
|
||||
return Config(self._config_bag.context.cfgimpl_get_meta())
|
||||
|
@ -1108,15 +1108,11 @@ class _TiramisuContextGroupConfig(TiramisuContext):
|
|||
|
||||
def find(self,
|
||||
name: str,
|
||||
value=undefined,
|
||||
first: bool=False):
|
||||
"""Find an or a list of options"""
|
||||
if first:
|
||||
return Config(self._config_bag.context.find_firsts(byname=name,
|
||||
byvalue=value,
|
||||
config_bag=self._config_bag))
|
||||
else:
|
||||
raise APIError('not implemented yet')
|
||||
value=undefined):
|
||||
"""Find an or a list of config with finding option"""
|
||||
return GroupConfig(self._config_bag.context.find_group(byname=name,
|
||||
byvalue=value,
|
||||
config_bag=self._config_bag))
|
||||
|
||||
def __call__(self,
|
||||
path: Optional[str]):
|
||||
|
@ -1258,7 +1254,10 @@ class GroupConfig(TiramisuAPI):
|
|||
session_id: Union[str, None]=None) -> None:
|
||||
_children = []
|
||||
for child in children:
|
||||
_children.append(child._config_bag.context)
|
||||
if isinstance(child, TiramisuAPI):
|
||||
_children.append(child._config_bag.context)
|
||||
else:
|
||||
_children.append(child)
|
||||
|
||||
config = KernelGroupConfig(_children,
|
||||
session_id=session_id)
|
||||
|
|
|
@ -871,14 +871,14 @@ class KernelGroupConfig(_CommonConfig):
|
|||
return ret
|
||||
|
||||
|
||||
def find_firsts(self,
|
||||
config_bag,
|
||||
byname=None,
|
||||
bypath=undefined,
|
||||
byoption=undefined,
|
||||
byvalue=undefined,
|
||||
raise_if_not_found=True,
|
||||
_sub=False):
|
||||
def find_group(self,
|
||||
config_bag,
|
||||
byname=None,
|
||||
bypath=undefined,
|
||||
byoption=undefined,
|
||||
byvalue=undefined,
|
||||
raise_if_not_found=True,
|
||||
_sub=False):
|
||||
"""Find first not in current KernelGroupConfig, but in each children
|
||||
"""
|
||||
#if KernelMetaConfig, all children have same OptionDescription in context
|
||||
|
@ -898,13 +898,13 @@ class KernelGroupConfig(_CommonConfig):
|
|||
ret = []
|
||||
for child in self._impl_children:
|
||||
if isinstance(child, KernelGroupConfig):
|
||||
ret.extend(child.find_firsts(byname=byname,
|
||||
bypath=bypath,
|
||||
byoption=byoption,
|
||||
byvalue=byvalue,
|
||||
config_bag=config_bag,
|
||||
raise_if_not_found=False,
|
||||
_sub=True))
|
||||
ret.extend(child.find_group(byname=byname,
|
||||
bypath=bypath,
|
||||
byoption=byoption,
|
||||
byvalue=byvalue,
|
||||
config_bag=config_bag,
|
||||
raise_if_not_found=False,
|
||||
_sub=True))
|
||||
else:
|
||||
try:
|
||||
cconfig_bag = config_bag.copy()
|
||||
|
@ -919,12 +919,10 @@ class KernelGroupConfig(_CommonConfig):
|
|||
ret.append(child)
|
||||
except StopIteration:
|
||||
pass
|
||||
if _sub:
|
||||
return ret
|
||||
else:
|
||||
if not _sub:
|
||||
self._find_return_results(ret != [],
|
||||
raise_if_not_found)
|
||||
return KernelGroupConfig(ret)
|
||||
return ret
|
||||
|
||||
def impl_getname(self):
|
||||
return self._impl_name
|
||||
|
|
Loading…
Reference in New Issue