diff --git a/tests/test_leadership.py b/tests/test_leadership.py index 2bbdc3b..07ae6b8 100644 --- a/tests/test_leadership.py +++ b/tests/test_leadership.py @@ -1074,3 +1074,16 @@ async def test_follower_properties(): await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).property.get() == ('aproperty', 'newproperty', 'newproperty1') await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).property.get() == ('aproperty', 'newproperty1') assert not await list_sessions() + + +@pytest.mark.asyncio +async def test_api_get_leader(config_type): + 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 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) + maconfig = OptionDescription('conf', '', [interface1]) + async with await Config(maconfig) as cfg: + option = await cfg.option('ip_admin_eth0.netmask_admin_eth0').option.leader() + assert await option.option.get() == ip_admin_eth0 + + assert not await list_sessions() diff --git a/tiramisu/api.py b/tiramisu/api.py index ec3ff58..20bc8c8 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -439,6 +439,12 @@ class TiramisuOptionOption(_TiramisuOptionOptionDescription): self._option_bag.config_bag, ) + @option_and_connection + async def leader(self): + return TiramisuOption(self._option_bag.option.impl_get_leadership().get_leader().impl_getpath(), + None, + self._option_bag.config_bag) + class TiramisuOptionOwner(CommonTiramisuOption): #FIXME optiondescription must not have Owner! @@ -771,6 +777,7 @@ class TiramisuOptionValue(CommonTiramisuOption): option = self._option_bag.option values = self._option_bag.config_bag.context.cfgimpl_get_values() if option.impl_is_follower() and self._option_bag.index is None: +# IF OU PAS IF ?? if self._option_bag.option.impl_is_symlinkoption(): value = [] length = await self._subconfig.cfgimpl_get_length_leadership(self._option_bag) settings = self._option_bag.config_bag.context.cfgimpl_get_settings() @@ -782,6 +789,7 @@ class TiramisuOptionValue(CommonTiramisuOption): soption_bag.properties = await settings.getproperties(soption_bag) value.append(await values.getdefaultvalue(soption_bag)) return value +# raise APIError('index must be set with a follower option') else: return await values.getdefaultvalue(self._option_bag)