add tmpfile_dest_dir option

This commit is contained in:
Emmanuel Garette 2022-03-06 18:54:57 +01:00
parent b610d66fcd
commit 0f4e49149d
16 changed files with 153 additions and 17 deletions

View File

@ -102,6 +102,11 @@ Le répertoire de temporaire est géré dans la clef "tmp_dir" et a comme valeur
Le répertoire de destination des fichiers générés est géré dans la clef "destinations_dir" et a comme valeur par défaut : "/srv/rougail/destinations".
### Le nom du répertoire où se trouve les fichiers pour tmpfile.d
Le répertoire où se trouve les fichiers tmpfile.d sont par défaut dans "/usr/local/lib", il est possible de changer ce répertoire avec la clef "tmpfile_dest_dir".
## La configuration par défaut des fichiers
### Le moteur de templates par défaut

View File

@ -40,6 +40,7 @@ RougailConfig = {'dictionaries_dir': [join(ROUGAILROOT, 'dictionaries')],
'tmp_dir': join(ROUGAILROOT, 'tmp'),
'dtdfilename': join(DTDDIR, 'rougail.dtd'),
'functions_file': join(ROUGAILROOT, 'functions.py'),
'tmpfile_dest_dir': '/usr/local/lib',
'variable_namespace': 'rougail',
'auto_freeze_variable': 'server_deployed',
'internal_functions': [],

View File

@ -38,18 +38,24 @@ IPAddressDeny=any
"""
ROUGAIL_DEST = '/usr/local/lib'
ROUGAIL_GLOBAL_SYSTEMD_FILE = '/usr/lib/systemd/system'
ROUGAIL_DEST_FILE = '/tmpfiles.d/0rougail.conf'
LOCAL_DIR = ('/etc/', '/var/', '/srv/')
ROUGAIL_TMPL_TEMPLATE = f"""%def display(%%file, %%filename)
class RougailSystemdTemplate(RougailBaseTemplate):
def __init__(self, # pylint: disable=R0913
config: 'Config',
rougailconfig: 'RougailConfig'=None,
) -> None:
self.ip_per_service = None
super().__init__(config, rougailconfig)
self.rougail_tmpl_template = f"""%def display(%%file, %%filename)
"""
TMP_LOCAL_DIR = (f"%%filename.startswith('{local_dir}')" for local_dir in LOCAL_DIR)
ROUGAIL_TMPL_TEMPLATE += '%if ' + ' or '.join(TMP_LOCAL_DIR)
ROUGAIL_TMPL_TEMPLATE += f"""
C %%filename %%file.mode %%file.owner %%file.group - {ROUGAIL_DEST}%%filename
tmp_local_dir = (f"%%filename.startswith('{local_dir}')" for local_dir in LOCAL_DIR)
self.rougail_tmpl_template += '%if ' + ' or '.join(tmp_local_dir)
self.rougail_tmpl_template += f"""
C %%filename %%file.mode %%file.owner %%file.group - {self.rougailconfig['tmpfile_dest_dir']}%%filename
%end if
%end def
%for %%service in %%services
@ -69,15 +75,6 @@ C %%filename %%file.mode %%file.owner %%file.group - {ROUGAIL_DEST}%%filename
%end for
"""
class RougailSystemdTemplate(RougailBaseTemplate):
def __init__(self, # pylint: disable=R0913
config: 'Config',
rougailconfig: 'RougailConfig'=None,
) -> None:
self.ip_per_service = None
super().__init__(config, rougailconfig)
def get_data_files(self,
filevar: Dict,
destfile: str,
@ -158,7 +155,7 @@ class RougailSystemdTemplate(RougailBaseTemplate):
if global_service:
source_filename = f'{ROUGAIL_GLOBAL_SYSTEMD_FILE}/{service_name}'
else:
source_filename = f'{ROUGAIL_DEST}/systemd/system/{service_name}'
source_filename = f"{self.rougailconfig['tmpfile_dest_dir']}/systemd/system/{service_name}"
symlink(source_filename, filename)
def post_instance_service(self,
@ -204,7 +201,7 @@ class RougailSystemdTemplate(RougailBaseTemplate):
makedirs(dirname(destfilename), exist_ok=True)
self.log.info(_(f"creole processing: '{destfilename}'"))
self.engines['creole'].process(filename=None,
source=ROUGAIL_TMPL_TEMPLATE,
source=self.rougail_tmpl_template,
true_destfilename=ROUGAIL_DEST_FILE,
destfilename=destfilename,
destdir=self.destinations_dir,

View File

@ -0,0 +1,16 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<services>
<service name="test">
<file>/etc/file</file>
<file engine="jinja2">/etc/file2</file>
</service>
</services>
<variables>
<family name="general">
<variable name="mode_conteneur_actif" type="string" description="Description">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View File

@ -0,0 +1,30 @@
{
"rougail.general.mode_conteneur_actif": {
"owner": "default",
"value": "non"
},
"services.test_service.files.file.name": {
"owner": "default",
"value": "/etc/file"
},
"services.test_service.files.file.activate": {
"owner": "default",
"value": true
},
"services.test_service.files.file2.name": {
"owner": "default",
"value": "/etc/file2"
},
"services.test_service.files.file2.activate": {
"owner": "default",
"value": true
},
"services.test_service.activate": {
"owner": "default",
"value": true
},
"services.test_service.manage": {
"owner": "default",
"value": true
}
}

View File

@ -0,0 +1,9 @@
{
"rougail.general.mode_conteneur_actif": "non",
"services.test_service.files.file.name": "/etc/file",
"services.test_service.files.file.activate": true,
"services.test_service.files.file2.name": "/etc/file2",
"services.test_service.files.file2.activate": true,
"services.test_service.activate": true,
"services.test_service.manage": true
}

View File

@ -0,0 +1,30 @@
{
"rougail.general.mode_conteneur_actif": {
"owner": "default",
"value": "non"
},
"services.test_service.files.file.name": {
"owner": "default",
"value": "/etc/file"
},
"services.test_service.files.file.activate": {
"owner": "default",
"value": true
},
"services.test_service.files.file2.name": {
"owner": "default",
"value": "/etc/file2"
},
"services.test_service.files.file2.activate": {
"owner": "default",
"value": true
},
"services.test_service.activate": {
"owner": "default",
"value": true
},
"services.test_service.manage": {
"owner": "default",
"value": true
}
}

View File

@ -0,0 +1,2 @@
non
non

View File

@ -0,0 +1,2 @@
non
non

View File

@ -0,0 +1,2 @@
C /etc/file 0644 root root - /test/new/file/etc/file
C /etc/file2 0644 root root - /test/new/file/etc/file2

View File

@ -0,0 +1,34 @@
from importlib.machinery import SourceFileLoader as _SourceFileLoader
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
class func:
pass
_loader = _SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py')
_spec = _spec_from_loader(_loader.name, _loader)
_func = _module_from_spec(_spec)
_loader.exec_module(_func)
for function in dir(_func):
if function.startswith('_'):
continue
setattr(func, function, getattr(_func, function))
try:
from tiramisu3 import *
except:
from tiramisu import *
option_3 = StrOption(name="mode_conteneur_actif", doc="Description", default="non", properties=frozenset({"mandatory", "normal"}))
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"normal"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
option_8 = FilenameOption(name="name", doc="name", default="/etc/file")
option_9 = BoolOption(name="activate", doc="activate", default=True)
option_7 = OptionDescription(name="file", doc="file", children=[option_8, option_9])
option_7.impl_set_information('source', "file")
option_11 = FilenameOption(name="name", doc="name", default="/etc/file2")
option_12 = BoolOption(name="activate", doc="activate", default=True)
option_10 = OptionDescription(name="file2", doc="file2", children=[option_11, option_12])
option_10.impl_set_information('engine', "jinja2")
option_10.impl_set_information('source', "file2")
option_6 = OptionDescription(name="files", doc="files", children=[option_7, option_10])
option_13 = BoolOption(name="activate", doc="activate", default=True)
option_14 = BoolOption(name="manage", doc="manage", default=True)
option_5 = OptionDescription(name="test_service", doc="test.service", children=[option_6, option_13, option_14])
option_4 = OptionDescription(name="services", doc="services", children=[option_5], properties=frozenset({"hidden"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_4])

View File

@ -0,0 +1,2 @@
%%mode_conteneur_actif
%%rougail.general.mode_conteneur_actif

View File

@ -0,0 +1,2 @@
{{ mode_conteneur_actif }}
{{ rougail.general.mode_conteneur_actif }}

View File

@ -65,6 +65,10 @@ async def test_dictionary(test_dir):
RougailConfig['tmp_dir'] = tmp_dir
RougailConfig['functions_file'] = funcs_file
RougailConfig['destinations_dir'] = dest_dir
if isfile(join(test_dir, 'file_tmpfile_dest_dir')):
RougailConfig['tmpfile_dest_dir'] = '/test/new/file'
else:
RougailConfig['tmpfile_dest_dir'] = '/usr/local/lib'
engine = RougailSystemdTemplate(config)
await engine.instance_files()
list_templates = set()