From 2ea43832e53816af9e4d2037221a1c4c0ee97bf3 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 9 Dec 2021 18:51:40 +0100 Subject: [PATCH] dyn properties to dynoptiondescription --- tests/test_dyn_optiondescription.py | 15 +++++++++++++ tiramisu/option/optiondescription.py | 3 +++ tiramisu/option/syndynoptiondescription.py | 26 +++++++++++++--------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/tests/test_dyn_optiondescription.py b/tests/test_dyn_optiondescription.py index 431e7d0..ef87667 100644 --- a/tests/test_dyn_optiondescription.py +++ b/tests/test_dyn_optiondescription.py @@ -1834,3 +1834,18 @@ async def test_dyn_leadership_requires(): {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.1'}], 'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': []} assert not await list_sessions() + + +@pytest.mark.asyncio +async def test_dyn_leadership_mandatory(): + nsd_zones_all = StrOption(name="nsd_zones_all", doc="nsd_zones_all", multi=True, default=['val1', 'val2']) + is_auto = BoolOption(name="is_auto_", doc="is auto") +# hostname = DomainnameOption(name="hostname_", multi=True, type='hostname', properties=frozenset({Calculation(func.calc_value, Params(ParamValue('frozen'), kwargs={'condition': ParamOption(is_auto, todict=True, notraisepropertyerror=True), 'expected': ParamValue(True)})), Calculation(func.calc_value, Params(ParamValue('force_default_on_freeze'), kwargs={'condition': ParamOption(is_auto, todict=True, notraisepropertyerror=True), 'expected': ParamValue(True)}))})) + hostname = DomainnameOption(name="hostname_", doc="hostname_", multi=True, type='hostname') + choice = ChoiceOption(name="type_", doc="type_", values=('A', 'CNAME'), multi=True, default_multi="A") + leadership = Leadership(name="hostname_", doc="hostname_", children=[hostname, choice], properties=frozenset({Calculation(calc_value, Params(ParamValue('hidden'), kwargs={'condition': ParamOption(is_auto, todict=True, notraisepropertyerror=True), 'expected': ParamValue(True)}))})) + dyn = DynOptionDescription(name="nsd_zone_", doc="Zone ", suffixes=Calculation(calc_value, Params((ParamOption(nsd_zones_all, notraisepropertyerror=True)))), children=[is_auto, leadership], properties=frozenset({"normal"})) + od = OptionDescription(name="nsd", doc="nsd", children=[nsd_zones_all, dyn]) + async with await Config(od) as cfg: + await cfg.value.mandatory() + assert not await list_sessions() diff --git a/tiramisu/option/optiondescription.py b/tiramisu/option/optiondescription.py index 3520a52..99f2ece 100644 --- a/tiramisu/option/optiondescription.py +++ b/tiramisu/option/optiondescription.py @@ -329,3 +329,6 @@ class OptionDescription(OptionDescriptionWalk): rootpath, suffix, ori_dyn) + + def impl_is_dynsymlinkoption(self) -> bool: + return False diff --git a/tiramisu/option/syndynoptiondescription.py b/tiramisu/option/syndynoptiondescription.py index 6df1cf5..4a4180e 100644 --- a/tiramisu/option/syndynoptiondescription.py +++ b/tiramisu/option/syndynoptiondescription.py @@ -30,20 +30,20 @@ from .syndynoption import SynDynOption class SynDynOptionDescription: __slots__ = ('_opt', - '_subpath', + 'rootpath', '_suffix', 'ori_dyn') def __init__(self, opt: BaseOption, - subpath: str, + rootpath: str, suffix: str, ori_dyn) -> None: self._opt = opt - if subpath is None: - subpath = '' - assert isinstance(subpath, str), 'subpath must be a string, not {}'.format(type(subpath)) - self._subpath = subpath + if rootpath is None: + rootpath = '' + assert isinstance(rootpath, str), 'rootpath must be a string, not {}'.format(type(rootpath)) + self.rootpath = rootpath self._suffix = suffix # For a Leadership inside a DynOptionDescription self.ori_dyn = ori_dyn @@ -94,6 +94,9 @@ class SynDynOptionDescription: self._opt)) return children + def impl_is_dynsymlinkoption(self) -> bool: + return True + async def get_children_recursively(self, bytype: Optional[BaseOption], byname: Optional[str], @@ -106,10 +109,10 @@ class SynDynOptionDescription: yield option def impl_getpath(self) -> str: - subpath = self._subpath - if subpath != '': - subpath += '.' - return subpath + self.impl_getname() + rootpath = self.rootpath + if rootpath != '': + rootpath += '.' + return rootpath + self.impl_getname() def impl_get_display_name(self) -> str: return self._opt.impl_get_display_name() + self._suffix @@ -157,3 +160,6 @@ class SynDynLeadership(SynDynOptionDescription): option_bag, owner, dyn=self) + + def impl_getsuffix(self) -> str: + return self._suffix