get leader option from follower

This commit is contained in:
egarette@silique.fr 2023-04-12 11:14:40 +02:00
parent a36d3cb9bf
commit 7fad2b5d7d
2 changed files with 21 additions and 0 deletions

View file

@ -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()

View file

@ -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)