add 'manage' attribut to service, unmanage services is, for example a fake service

This commit is contained in:
Emmanuel Garette 2020-07-30 09:37:19 +02:00
parent 08f4362816
commit 5f2d1b3eb7
35 changed files with 83 additions and 16 deletions
src/rougail
tests/flattener_dicos
00empty/tiramisu
11disabled_if_in_filelist/tiramisu
11disabled_if_in_filelist_disabled/tiramisu
11disabled_if_in_filelist_multi/tiramisu
11disabledifin_filelist_notexist/tiramisu
11disabledifnotin_filelist_notexist/tiramisu
11disabledifnotin_filelist_notexist_multi/tiramisu
11disabledifnotin_filelist_notexist_validenum/tiramisu
11multi_disabled_if_in_filelist/tiramisu
20notemplating/tiramisu
20override/tiramisu
60extra_group/tiramisu
60extra_help/tiramisu
70container_files/tiramisu
70container_files_symlink_multi/tiramisu
70container_files_symlink_multi_variable/tiramisu
70container_filesmulti/tiramisu
70container_filesredefine/tiramisu
70container_new/tiramisu
70container_newnocont/tiramisu
70container_newwithip/tiramisu
70container_pathaccess/tiramisu
70container_pathaccess_leadership/tiramisu
70container_serviceaccess/tiramisu
70container_servicerestriction/tiramisu
70container_services/tiramisu
70services_unmanage

@ -241,7 +241,7 @@ class ServiceAnnotator:
service = self.objectspace.space.services.service[service_name]
new_service = self.objectspace.service()
for elttype, values in vars(service).items():
if elttype == 'name' or elttype in ERASED_ATTRIBUTES:
if not isinstance(values, (dict, list)) or elttype in ERASED_ATTRIBUTES:
setattr(new_service, elttype, values)
continue
eltname = elttype + 's'
@ -1065,7 +1065,8 @@ class FamilyAnnotator:
for family_name, family in space.items():
if not hasattr(family, 'variable') or len(family.variable) == 0:
removed_families.append(family_name)
del space[family_name]
for family_name in removed_families:
del space[family_name]
def change_family_mode(self): # pylint: disable=C0111
if not hasattr(self.objectspace.space, 'variables'):

@ -47,6 +47,7 @@
<!ELEMENT service ((port* | tcpwrapper* | ip* | interface* | package* | file* | digitalcertificate* | override*)*) >
<!ATTLIST service name CDATA #REQUIRED>
<!ATTLIST service manage (True|False) "True">
<!ELEMENT port (#PCDATA)>
<!ATTLIST port port_type (PortOption|SymLinkOption|variable) "PortOption">

@ -23,7 +23,6 @@ For example: a variable is redefined and shall be moved to another family
means that a variable1 = Variable() object in the object space who lives in the family1 parent
has to be moved in family2. The visit procedure changes the varable1's object space's parent.
"""
from collections import OrderedDict
from lxml.etree import Element, SubElement # pylint: disable=E0611
from .i18n import _
@ -66,20 +65,20 @@ class RootCreoleObject:
class CreoleObjSpace:
"""DOM XML reflexion free internal representation of a Creole Dictionary
"""
choice = type('Choice', (RootCreoleObject,), OrderedDict())
property_ = type('Property', (RootCreoleObject,), OrderedDict())
choice = type('Choice', (RootCreoleObject,), dict())
property_ = type('Property', (RootCreoleObject,), dict())
# Creole ObjectSpace's Leadership variable class type
Leadership = type('Leadership', (RootCreoleObject,), OrderedDict())
Leadership = type('Leadership', (RootCreoleObject,), dict())
"""
This Atom type stands for singleton, that is
an Object Space's atom object is present only once in the
object space's tree
"""
Atom = type('Atom', (RootCreoleObject,), OrderedDict())
Atom = type('Atom', (RootCreoleObject,), dict())
"A variable that can't be redefined"
Redefinable = type('Redefinable', (RootCreoleObject,), OrderedDict())
Redefinable = type('Redefinable', (RootCreoleObject,), dict())
"A variable can be redefined"
UnRedefinable = type('UnRedefinable', (RootCreoleObject,), OrderedDict())
UnRedefinable = type('UnRedefinable', (RootCreoleObject,), dict())
def __init__(self, dtdfilename): # pylint: disable=R0912
@ -314,14 +313,14 @@ class CreoleObjSpace:
for example::
space = Family()
space.variable = OrderedDict()
space.variable = dict()
another example:
space = Variable()
space.value = list()
"""
if child.tag not in vars(space):
if isinstance(variableobj, self.Redefinable):
setattr(space, child.tag, OrderedDict())
setattr(space, child.tag, dict())
elif isinstance(variableobj, self.UnRedefinable):
setattr(space, child.tag, [])
elif not isinstance(variableobj, self.Atom): # pragma: no cover
@ -374,7 +373,7 @@ class CreoleObjSpace:
variable_obj = old_family.variable[name]
del old_family.variable[name]
if 'variable' not in vars(family):
family.variable = OrderedDict()
family.variable = dict()
family.variable[name] = variable_obj
self.paths.add_variable(namespace,
name,

@ -11,7 +11,7 @@ from .annotator import ERASED_ATTRIBUTES
FUNC_TO_DICT = ['valid_not_equal']
FORCE_INFORMATIONS = ['help', 'test', 'separator']
FORCE_INFORMATIONS = ['help', 'test', 'separator', 'manage']
ATTRIBUTES_ORDER = ('name', 'doc', 'default', 'multi')
@ -261,8 +261,9 @@ class Common:
def populate_informations(self):
for key, value in self.informations.items():
value = value.replace('"', '\"')
self.storage.text.append(f'{self.option_name}.impl_set_information("{key}", "{value}")')
if isinstance(value, str):
value = '"' + value.replace('"', '\"') + '"'
self.storage.text.append(f'{self.option_name}.impl_set_information("{key}", {value})')
def get_text(self,
):
@ -472,7 +473,7 @@ class Family(Common):
def populate_attrib(self):
for key in self.get_attributes(self.elt):
value = getattr(self.elt, key)
if key == 'help':
if key in FORCE_INFORMATIONS:
self.informations[key] = value
elif key == 'dynamic':
dynamic = self.storage.get(value).get()

@ -3,5 +3,6 @@ from rougail.tiramisu import ConvertDynOptionDescription
import imp
func = imp.load_source('func', 'tests/flattener_dicos/../eosfunc/test.py')
option_2 = OptionDescription(name='tata', doc='tata', children=[])
option_2.impl_set_information("manage", True)
option_1 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_2])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])

@ -17,5 +17,6 @@ option_16 = BoolOption(properties=frozenset({Calculation(calc_value, Params(Para
option_9 = OptionDescription(name='file', doc='file', children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
option_8 = OptionDescription(name='files', doc='files', children=[option_9])
option_7 = OptionDescription(name='test', doc='test', children=[option_8])
option_7.impl_set_information("manage", True)
option_6 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_7])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_6])

@ -17,5 +17,6 @@ option_16 = BoolOption(properties=frozenset({Calculation(calc_value, Params(Para
option_9 = OptionDescription(name='file', doc='file', children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
option_8 = OptionDescription(name='files', doc='files', children=[option_9])
option_7 = OptionDescription(name='test', doc='test', children=[option_8])
option_7.impl_set_information("manage", True)
option_6 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_7])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_6])

@ -25,5 +25,6 @@ option_24 = BoolOption(properties=frozenset({Calculation(calc_value, Params(Para
option_17 = OptionDescription(name='file2', doc='file2', children=[option_18, option_19, option_20, option_21, option_22, option_23, option_24])
option_8 = OptionDescription(name='files', doc='files', children=[option_9, option_17])
option_7 = OptionDescription(name='test', doc='test', children=[option_8])
option_7.impl_set_information("manage", True)
option_6 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_7])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_6])

@ -17,5 +17,6 @@ option_16 = BoolOption(properties=frozenset({'disabled'}), name='activate', doc=
option_9 = OptionDescription(name='file', doc='file', children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
option_8 = OptionDescription(name='files', doc='files', children=[option_9])
option_7 = OptionDescription(name='test', doc='test', children=[option_8])
option_7.impl_set_information("manage", True)
option_6 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_7])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_6])

@ -17,5 +17,6 @@ option_16 = BoolOption(properties=frozenset({'disabled'}), name='activate', doc=
option_9 = OptionDescription(name='file', doc='file', children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
option_8 = OptionDescription(name='files', doc='files', children=[option_9])
option_7 = OptionDescription(name='test', doc='test', children=[option_8])
option_7.impl_set_information("manage", True)
option_6 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_7])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_6])

@ -17,5 +17,6 @@ option_16 = BoolOption(properties=frozenset({'disabled'}), name='activate', doc=
option_9 = OptionDescription(name='file', doc='file', children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
option_8 = OptionDescription(name='files', doc='files', children=[option_9])
option_7 = OptionDescription(name='test', doc='test', children=[option_8])
option_7.impl_set_information("manage", True)
option_6 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_7])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_6])

@ -17,5 +17,6 @@ option_16 = BoolOption(properties=frozenset({Calculation(calc_value, Params(Para
option_9 = OptionDescription(name='file', doc='file', children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
option_8 = OptionDescription(name='files', doc='files', children=[option_9])
option_7 = OptionDescription(name='test', doc='test', children=[option_8])
option_7.impl_set_information("manage", True)
option_6 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_7])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_6])

@ -16,5 +16,6 @@ option_15 = BoolOption(properties=frozenset({'disabled'}), name='activate', doc=
option_8 = OptionDescription(name='file1', doc='file1', children=[option_9, option_10, option_11, option_12, option_13, option_14, option_15])
option_7 = OptionDescription(name='files', doc='files', children=[option_8])
option_6 = OptionDescription(name='test', doc='test', children=[option_7])
option_6.impl_set_information("manage", True)
option_5 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_6])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_5])

@ -15,5 +15,6 @@ option_14 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_7 = OptionDescription(name='file', doc='file', children=[option_8, option_9, option_10, option_11, option_12, option_13, option_14])
option_6 = OptionDescription(name='files', doc='files', children=[option_7])
option_5 = OptionDescription(name='test', doc='test', children=[option_6])
option_5.impl_set_information("manage", True)
option_4 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_5])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_4])

@ -15,5 +15,6 @@ option_14 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_7 = OptionDescription(name='test_service', doc='test.service', children=[option_8, option_9, option_10, option_11, option_12, option_13, option_14])
option_6 = OptionDescription(name='overrides', doc='overrides', children=[option_7])
option_5 = OptionDescription(name='test', doc='test', children=[option_6])
option_5.impl_set_information("manage", True)
option_4 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_5])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_4])

@ -21,5 +21,6 @@ option_20 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_13 = OptionDescription(name='mailname', doc='mailname', children=[option_14, option_15, option_16, option_17, option_18, option_19, option_20])
option_12 = OptionDescription(name='files', doc='files', children=[option_13])
option_11 = OptionDescription(name='test', doc='test', children=[option_12])
option_11.impl_set_information("manage", True)
option_10 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_11])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_5, option_10])

@ -22,5 +22,6 @@ option_20 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_13 = OptionDescription(name='mailname', doc='mailname', children=[option_14, option_15, option_16, option_17, option_18, option_19, option_20])
option_12 = OptionDescription(name='files', doc='files', children=[option_13])
option_11 = OptionDescription(name='test', doc='test', children=[option_12])
option_11.impl_set_information("manage", True)
option_10 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_11])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_5, option_10])

@ -23,5 +23,6 @@ option_22 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_15 = OptionDescription(name='rougail_conf', doc='rougail.conf', children=[option_16, option_17, option_18, option_19, option_20, option_21, option_22])
option_6 = OptionDescription(name='files', doc='files', children=[option_7, option_15])
option_5 = OptionDescription(name='test', doc='test', children=[option_6])
option_5.impl_set_information("manage", True)
option_4 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_5])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_4])

@ -16,5 +16,6 @@ option_15 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_8 = OptionDescription(name='mailname', doc='mailname', children=[option_9, option_10, option_11, option_12, option_13, option_14, option_15])
option_7 = OptionDescription(name='files', doc='files', children=[option_8])
option_6 = OptionDescription(name='test', doc='test', children=[option_7])
option_6.impl_set_information("manage", True)
option_5 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_6])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_5])

@ -18,5 +18,6 @@ option_17 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_9 = OptionDescription(name='mailname', doc='mailname', children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16, option_17])
option_8 = OptionDescription(name='files', doc='files', children=[option_9])
option_7 = OptionDescription(name='test', doc='test', children=[option_8])
option_7.impl_set_information("manage", True)
option_6 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_7])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_6])

@ -23,5 +23,6 @@ option_22 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_15 = OptionDescription(name='mailname2', doc='mailname2', children=[option_16, option_17, option_18, option_19, option_20, option_21, option_22])
option_6 = OptionDescription(name='files', doc='files', children=[option_7, option_15])
option_5 = OptionDescription(name='test', doc='test', children=[option_6])
option_5.impl_set_information("manage", True)
option_4 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_5])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_4])

@ -15,5 +15,6 @@ option_14 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_7 = OptionDescription(name='mailname_new', doc='mailname.new', children=[option_8, option_9, option_10, option_11, option_12, option_13, option_14])
option_6 = OptionDescription(name='files', doc='files', children=[option_7])
option_5 = OptionDescription(name='test', doc='test', children=[option_6])
option_5.impl_set_information("manage", True)
option_4 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_5])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_4])

@ -6,5 +6,6 @@ option_3 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen
option_2 = OptionDescription(name='general', doc='général', properties=frozenset({'normal'}), children=[option_3])
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
option_5 = OptionDescription(name='test', doc='test', children=[])
option_5.impl_set_information("manage", True)
option_4 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_5])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_4])

@ -6,5 +6,6 @@ option_3 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen
option_2 = OptionDescription(name='general', doc='général', properties=frozenset({'normal'}), children=[option_3])
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
option_5 = OptionDescription(name='test', doc='test', children=[])
option_5.impl_set_information("manage", True)
option_4 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_5])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_4])

@ -7,5 +7,6 @@ option_4 = IPOption(allow_reserved=True, properties=frozenset({'normal'}), name=
option_2 = OptionDescription(name='general', doc='général', properties=frozenset({'normal'}), children=[option_3, option_4])
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
option_6 = OptionDescription(name='test', doc='test', children=[])
option_6.impl_set_information("manage", True)
option_5 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_6])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_5])

@ -14,5 +14,6 @@ option_13 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_9 = OptionDescription(name='nut_monitor_host', doc='nut_monitor_host', children=[option_10, option_11, option_12, option_13])
option_8 = OptionDescription(name='ips', doc='ips', children=[option_9])
option_7 = OptionDescription(name='nut', doc='nut', children=[option_8])
option_7.impl_set_information("manage", True)
option_6 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_7])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_6])

@ -15,5 +15,6 @@ option_14 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_10 = OptionDescription(name='nut_monitor_host', doc='nut_monitor_host', children=[option_11, option_12, option_13, option_14])
option_9 = OptionDescription(name='ips', doc='ips', children=[option_10])
option_8 = OptionDescription(name='ntp', doc='ntp', children=[option_9])
option_8.impl_set_information("manage", True)
option_7 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_8])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_7])

@ -11,5 +11,6 @@ option_10 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_7 = OptionDescription(name='123', doc='123', children=[option_8, option_9, option_10])
option_6 = OptionDescription(name='ports', doc='ports', children=[option_7])
option_5 = OptionDescription(name='ntp', doc='ntp', children=[option_6])
option_5.impl_set_information("manage", True)
option_4 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_5])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_4])

@ -12,5 +12,6 @@ option_11 = BoolOption(name='activate', doc='activate', multi=False, default=Tru
option_7 = OptionDescription(name='192_168_1_1', doc='192.168.1.1', children=[option_8, option_9, option_10, option_11])
option_6 = OptionDescription(name='ips', doc='ips', children=[option_7])
option_5 = OptionDescription(name='testsrv', doc='testsrv', children=[option_6])
option_5.impl_set_information("manage", True)
option_4 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_5])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_4])

@ -6,5 +6,6 @@ option_3 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen
option_2 = OptionDescription(name='general', doc='général', properties=frozenset({'normal'}), children=[option_3])
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
option_5 = OptionDescription(name='testsrv', doc='testsrv', children=[])
option_5.impl_set_information("manage", True)
option_4 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_5])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_4])

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<rougail>
<services>
<service name='testsrv' manage='False'>
</service>
</services>
<variables>
<family name='général'>
<variable name='mode_conteneur_actif' type='oui/non' description="No change" hidden="True">
<value>oui</value>
</variable>
</family>
<separators/>
</variables>
<constraints>
</constraints>
<help/>
</rougail>
<!-- vim: ts=4 sw=4 expandtab
-->

@ -0,0 +1 @@
{"rougail.general.mode_conteneur_actif": "oui"}

@ -0,0 +1,11 @@
from tiramisu import *
from rougail.tiramisu import ConvertDynOptionDescription
import imp
func = imp.load_source('func', 'tests/flattener_dicos/../eosfunc/test.py')
option_3 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='oui', values=('oui', 'non'))
option_2 = OptionDescription(name='general', doc='général', properties=frozenset({'normal'}), children=[option_3])
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
option_5 = OptionDescription(name='testsrv', doc='testsrv', children=[])
option_5.impl_set_information("manage", False)
option_4 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_5])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_4])