dyn properties to dynoptiondescription

This commit is contained in:
Emmanuel Garette 2021-12-09 18:51:40 +01:00
parent 64017d5cd4
commit 2ea43832e5
3 changed files with 34 additions and 10 deletions

View file

@ -1834,3 +1834,18 @@ async def test_dyn_leadership_requires():
{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.1'}], {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.1'}],
'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': []} 'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': []}
assert not await list_sessions() 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()

View file

@ -329,3 +329,6 @@ class OptionDescription(OptionDescriptionWalk):
rootpath, rootpath,
suffix, suffix,
ori_dyn) ori_dyn)
def impl_is_dynsymlinkoption(self) -> bool:
return False

View file

@ -30,20 +30,20 @@ from .syndynoption import SynDynOption
class SynDynOptionDescription: class SynDynOptionDescription:
__slots__ = ('_opt', __slots__ = ('_opt',
'_subpath', 'rootpath',
'_suffix', '_suffix',
'ori_dyn') 'ori_dyn')
def __init__(self, def __init__(self,
opt: BaseOption, opt: BaseOption,
subpath: str, rootpath: str,
suffix: str, suffix: str,
ori_dyn) -> None: ori_dyn) -> None:
self._opt = opt self._opt = opt
if subpath is None: if rootpath is None:
subpath = '' rootpath = ''
assert isinstance(subpath, str), 'subpath must be a string, not {}'.format(type(subpath)) assert isinstance(rootpath, str), 'rootpath must be a string, not {}'.format(type(rootpath))
self._subpath = subpath self.rootpath = rootpath
self._suffix = suffix self._suffix = suffix
# For a Leadership inside a DynOptionDescription # For a Leadership inside a DynOptionDescription
self.ori_dyn = ori_dyn self.ori_dyn = ori_dyn
@ -94,6 +94,9 @@ class SynDynOptionDescription:
self._opt)) self._opt))
return children return children
def impl_is_dynsymlinkoption(self) -> bool:
return True
async def get_children_recursively(self, async def get_children_recursively(self,
bytype: Optional[BaseOption], bytype: Optional[BaseOption],
byname: Optional[str], byname: Optional[str],
@ -106,10 +109,10 @@ class SynDynOptionDescription:
yield option yield option
def impl_getpath(self) -> str: def impl_getpath(self) -> str:
subpath = self._subpath rootpath = self.rootpath
if subpath != '': if rootpath != '':
subpath += '.' rootpath += '.'
return subpath + self.impl_getname() return rootpath + self.impl_getname()
def impl_get_display_name(self) -> str: def impl_get_display_name(self) -> str:
return self._opt.impl_get_display_name() + self._suffix return self._opt.impl_get_display_name() + self._suffix
@ -157,3 +160,6 @@ class SynDynLeadership(SynDynOptionDescription):
option_bag, option_bag,
owner, owner,
dyn=self) dyn=self)
def impl_getsuffix(self) -> str:
return self._suffix