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'}],
'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()

View file

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

View file

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