diff --git a/src/rougail/annotator.py b/src/rougail/annotator.py index 0c0e61859..0edc0e448 100644 --- a/src/rougail/annotator.py +++ b/src/rougail/annotator.py @@ -242,8 +242,11 @@ class ServiceAnnotator: ) return variable + def _update_override(self, file_, index, service_path): + self._update_file(file_, index, service_path) + def _update_file(self, file_, index, service_path): - if file_.file_type == "UnicodeOption": + if not hasattr(file_, 'file_type') or file_.file_type == "UnicodeOption": if not hasattr(file_, 'source'): file_.source = basename(file_.name) elif not hasattr(file_, 'source'): diff --git a/src/rougail/data/rougail.dtd b/src/rougail/data/rougail.dtd index df0540160..555c7397a 100644 --- a/src/rougail/data/rougail.dtd +++ b/src/rougail/data/rougail.dtd @@ -66,7 +66,7 @@ - + @@ -109,6 +109,7 @@ + @@ -118,6 +119,10 @@ + + + + diff --git a/src/rougail/template.py b/src/rougail/template.py index 928e7f702..e9e9a0ed0 100644 --- a/src/rougail/template.py +++ b/src/rougail/template.py @@ -261,11 +261,14 @@ class CreoleTemplateEngine: eosfunc_file: str, distrib_dir: str, tmp_dir: str, - dest_dir:str) -> None: + dest_dir: str, + tmpfile_name: str, + ) -> None: self.config = config self.dest_dir = dest_dir self.tmp_dir = tmp_dir self.distrib_dir = distrib_dir + self.tmpfile_name = tmpfile_name eos = {} if eosfunc_file is not None: eosfunc = imp.load_source('eosfunc', eosfunc_file) @@ -342,6 +345,7 @@ class CreoleTemplateEngine: self.patch_template(filename) def process(self, + source: str, destfilename: str, filevar: Dict, variable: Any): @@ -350,8 +354,7 @@ class CreoleTemplateEngine: # full path of the destination file log.info(_(f"Cheetah processing: '{destfilename}'")) try: - cheetah_template = CheetahTemplate(join(self.tmp_dir, - filevar['source']), + cheetah_template = CheetahTemplate(source, self.creole_variables_dict, self.eosfunc, destfilename, @@ -368,19 +371,24 @@ class CreoleTemplateEngine: def instance_file(self, filevar: Dict, - systemd_rights: list) -> None: + systemd_rights: list, + override: bool, + service_name: str) -> None: """Run templatisation on one file """ log.info(_("Instantiating file '{filename}'")) - filenames = filevar['name'] if 'variable' in filevar: variable = filevar['variable'] else: variable = None - if not isinstance(filenames, list): - filenames = [filenames] - if variable: - variable = [variable] + if override: + filenames = [f'/system/{service_name}.service.d/rougail.conf'] + else: + filenames = filevar['name'] + if not isinstance(filenames, list): + filenames = [filenames] + if variable: + variable = [variable] for idx, filename in enumerate(filenames): destfilename = join(self.dest_dir, filename[1:]) @@ -389,11 +397,17 @@ class CreoleTemplateEngine: var = variable[idx] else: var = None - self.process(destfilename, - filevar, - var) - systemd_rights.append(f'C {filename} {filevar["mode"]} {filevar["owner"]} {filevar["group"]} - -') - systemd_rights.append(f'z {filename} - - - - -') + source = join(self.tmp_dir, filevar['source']) + if filevar['templating']: + self.process(source, + destfilename, + filevar, + var) + else: + copy(source, destfilename) + if not override and self.tmpfile_name: + systemd_rights.append(f'C {filename} {filevar["mode"]} {filevar["owner"]} {filevar["group"]} - -') + systemd_rights.append(f'z {filename} - - - - -') async def instance_files(self) -> None: """Run templatisation on all files @@ -411,33 +425,41 @@ class CreoleTemplateEngine: self.prepare_template(join(self.distrib_dir, template)) systemd_rights = [] for service_obj in await self.config.option('services').list('all'): + service_name = await service_obj.option.doc() for fills in await service_obj.list('all'): - if await fills.option.name() == 'files': + if await fills.option.name() in ['files', 'overrides']: for fill_obj in await fills.list('all'): fill = await fill_obj.value.dict() filename = fill['source'] distib_file = join(self.distrib_dir, filename) if not isfile(distib_file): raise FileNotFound(_(f"File {distib_file} does not exist.")) - if fill.get('activate', False): + override = await fills.option.name() == 'overrides' + if override or fill.get('activate', False): self.instance_file(fill, - systemd_rights) + systemd_rights, + override, + service_name, + ) else: log.debug(_("Instantiation of file '{filename}' disabled")) - with open(join(self.dest_dir, 'rougail.conf'), 'w') as fh: - fh.write('\n'.join(systemd_rights)) - fh.write('\n') + if self.tmpfile_name: + with open(self.tmpfile_name, 'w') as fh: + fh.write('\n'.join(systemd_rights)) + fh.write('\n') async def generate(config: Config, - eosfunc_file: str, - distrib_dir: str, - tmp_dir: str, - dest_dir: str) -> None: + eosfunc_file: str, + distrib_dir: str, + tmp_dir: str, + dest_dir: str, + tmpfile_name: str=None) -> None: engine = CreoleTemplateEngine(config, eosfunc_file, distrib_dir, tmp_dir, - dest_dir) + dest_dir, + tmpfile_name) await engine.instance_files() diff --git a/tests/flattener_dicos/11disabled_if_in_filelist/00-base.xml b/tests/flattener_dicos/11disabled_if_in_filelist/00-base.xml index 03c6b9d3b..e9e2d1cd4 100644 --- a/tests/flattener_dicos/11disabled_if_in_filelist/00-base.xml +++ b/tests/flattener_dicos/11disabled_if_in_filelist/00-base.xml @@ -3,7 +3,7 @@ - + diff --git a/tests/flattener_dicos/11disabled_if_in_filelist/makedict/base.json b/tests/flattener_dicos/11disabled_if_in_filelist/makedict/base.json index 4547d403c..ef363b98c 100644 --- a/tests/flattener_dicos/11disabled_if_in_filelist/makedict/base.json +++ b/tests/flattener_dicos/11disabled_if_in_filelist/makedict/base.json @@ -1 +1 @@ -{"creole.general.condition": "non", "creole.general.mode_conteneur_actif": "non", "creole.general.mode_conteneur_actif2": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file", "services.service0.files.file0.activate": true} +{"creole.general.condition": "non", "creole.general.mode_conteneur_actif": "non", "creole.general.mode_conteneur_actif2": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file", "services.service0.files.file0.templating": true, "services.service0.files.file0.activate": true} diff --git a/tests/flattener_dicos/11disabled_if_in_filelist/result/00-base.xml b/tests/flattener_dicos/11disabled_if_in_filelist/result/00-base.xml index 55b84d678..902c09b3e 100644 --- a/tests/flattener_dicos/11disabled_if_in_filelist/result/00-base.xml +++ b/tests/flattener_dicos/11disabled_if_in_filelist/result/00-base.xml @@ -18,7 +18,7 @@ mandatory - /tmp/file + /etc/file mandatory @@ -32,6 +32,10 @@ mandatory file + + mandatory + True + mandatory disabled diff --git a/tests/flattener_dicos/11disabled_if_in_filelist_disabled/00-base.xml b/tests/flattener_dicos/11disabled_if_in_filelist_disabled/00-base.xml index 6ac8dfd33..3a9fbc968 100644 --- a/tests/flattener_dicos/11disabled_if_in_filelist_disabled/00-base.xml +++ b/tests/flattener_dicos/11disabled_if_in_filelist_disabled/00-base.xml @@ -3,7 +3,7 @@ - + diff --git a/tests/flattener_dicos/11disabled_if_in_filelist_disabled/makedict/base.json b/tests/flattener_dicos/11disabled_if_in_filelist_disabled/makedict/base.json index 93a8cfbd6..624f287ee 100644 --- a/tests/flattener_dicos/11disabled_if_in_filelist_disabled/makedict/base.json +++ b/tests/flattener_dicos/11disabled_if_in_filelist_disabled/makedict/base.json @@ -1 +1 @@ -{"creole.general.condition": "oui", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file"} +{"creole.general.condition": "oui", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file", "services.service0.files.file0.templating": true} diff --git a/tests/flattener_dicos/11disabled_if_in_filelist_disabled/result/00-base.xml b/tests/flattener_dicos/11disabled_if_in_filelist_disabled/result/00-base.xml index 1231859c8..6faa8167a 100644 --- a/tests/flattener_dicos/11disabled_if_in_filelist_disabled/result/00-base.xml +++ b/tests/flattener_dicos/11disabled_if_in_filelist_disabled/result/00-base.xml @@ -18,7 +18,7 @@ mandatory - /tmp/file + /etc/file mandatory @@ -32,6 +32,10 @@ mandatory file + + mandatory + True + mandatory disabled diff --git a/tests/flattener_dicos/11disabled_if_in_filelist_multi/makedict/base.json b/tests/flattener_dicos/11disabled_if_in_filelist_multi/makedict/base.json index 1d5c76faa..029626740 100644 --- a/tests/flattener_dicos/11disabled_if_in_filelist_multi/makedict/base.json +++ b/tests/flattener_dicos/11disabled_if_in_filelist_multi/makedict/base.json @@ -1 +1 @@ -{"creole.general.condition": "non", "creole.general.mode_conteneur_actif": "non", "creole.general.mode_conteneur_actif2": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file1", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file1", "services.service0.files.file0.activate": true, "services.service0.files.file1.group": "root", "services.service0.files.file1.mkdir": false, "services.service0.files.file1.mode": "0644", "services.service0.files.file1.name": "/tmp/file2", "services.service0.files.file1.owner": "root", "services.service0.files.file1.rm": false, "services.service0.files.file1.source": "file2", "services.service0.files.file1.activate": true} +{"creole.general.condition": "non", "creole.general.mode_conteneur_actif": "non", "creole.general.mode_conteneur_actif2": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file1", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file1", "services.service0.files.file0.templating": true, "services.service0.files.file0.activate": true, "services.service0.files.file1.group": "root", "services.service0.files.file1.mkdir": false, "services.service0.files.file1.mode": "0644", "services.service0.files.file1.name": "/tmp/file2", "services.service0.files.file1.owner": "root", "services.service0.files.file1.rm": false, "services.service0.files.file1.source": "file2", "services.service0.files.file1.templating": true, "services.service0.files.file1.activate": true} diff --git a/tests/flattener_dicos/11disabled_if_in_filelist_multi/result/00-base.xml b/tests/flattener_dicos/11disabled_if_in_filelist_multi/result/00-base.xml index 4134df57b..84ed62e65 100644 --- a/tests/flattener_dicos/11disabled_if_in_filelist_multi/result/00-base.xml +++ b/tests/flattener_dicos/11disabled_if_in_filelist_multi/result/00-base.xml @@ -32,6 +32,10 @@ mandatory file1 + + mandatory + True + mandatory disabled @@ -67,6 +71,10 @@ mandatory file2 + + mandatory + True + mandatory disabled diff --git a/tests/flattener_dicos/11disabledifin_filelist_notexist/makedict/base.json b/tests/flattener_dicos/11disabledifin_filelist_notexist/makedict/base.json index 4905fa3c4..8c818688a 100644 --- a/tests/flattener_dicos/11disabledifin_filelist_notexist/makedict/base.json +++ b/tests/flattener_dicos/11disabledifin_filelist_notexist/makedict/base.json @@ -1 +1 @@ -{"creole.general.condition": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file"} +{"creole.general.condition": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file", "services.service0.files.file0.templating": true} diff --git a/tests/flattener_dicos/11disabledifin_filelist_notexist/result/00-base.xml b/tests/flattener_dicos/11disabledifin_filelist_notexist/result/00-base.xml index 426106d89..44710af06 100644 --- a/tests/flattener_dicos/11disabledifin_filelist_notexist/result/00-base.xml +++ b/tests/flattener_dicos/11disabledifin_filelist_notexist/result/00-base.xml @@ -32,6 +32,10 @@ mandatory file + + mandatory + True + disabled mandatory diff --git a/tests/flattener_dicos/11disabledifnotin_filelist_notexist/makedict/base.json b/tests/flattener_dicos/11disabledifnotin_filelist_notexist/makedict/base.json index 4905fa3c4..8c818688a 100644 --- a/tests/flattener_dicos/11disabledifnotin_filelist_notexist/makedict/base.json +++ b/tests/flattener_dicos/11disabledifnotin_filelist_notexist/makedict/base.json @@ -1 +1 @@ -{"creole.general.condition": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file"} +{"creole.general.condition": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file", "services.service0.files.file0.templating": true} diff --git a/tests/flattener_dicos/11disabledifnotin_filelist_notexist/result/00-base.xml b/tests/flattener_dicos/11disabledifnotin_filelist_notexist/result/00-base.xml index 426106d89..44710af06 100644 --- a/tests/flattener_dicos/11disabledifnotin_filelist_notexist/result/00-base.xml +++ b/tests/flattener_dicos/11disabledifnotin_filelist_notexist/result/00-base.xml @@ -32,6 +32,10 @@ mandatory file + + mandatory + True + disabled mandatory diff --git a/tests/flattener_dicos/11disabledifnotin_filelist_notexist_multi/makedict/base.json b/tests/flattener_dicos/11disabledifnotin_filelist_notexist_multi/makedict/base.json index 4905fa3c4..8c818688a 100644 --- a/tests/flattener_dicos/11disabledifnotin_filelist_notexist_multi/makedict/base.json +++ b/tests/flattener_dicos/11disabledifnotin_filelist_notexist_multi/makedict/base.json @@ -1 +1 @@ -{"creole.general.condition": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file"} +{"creole.general.condition": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file", "services.service0.files.file0.templating": true} diff --git a/tests/flattener_dicos/11disabledifnotin_filelist_notexist_multi/result/00-base.xml b/tests/flattener_dicos/11disabledifnotin_filelist_notexist_multi/result/00-base.xml index 426106d89..44710af06 100644 --- a/tests/flattener_dicos/11disabledifnotin_filelist_notexist_multi/result/00-base.xml +++ b/tests/flattener_dicos/11disabledifnotin_filelist_notexist_multi/result/00-base.xml @@ -32,6 +32,10 @@ mandatory file + + mandatory + True + disabled mandatory diff --git a/tests/flattener_dicos/11disabledifnotin_filelist_notexist_validenum/makedict/base.json b/tests/flattener_dicos/11disabledifnotin_filelist_notexist_validenum/makedict/base.json index 4905fa3c4..8c818688a 100644 --- a/tests/flattener_dicos/11disabledifnotin_filelist_notexist_validenum/makedict/base.json +++ b/tests/flattener_dicos/11disabledifnotin_filelist_notexist_validenum/makedict/base.json @@ -1 +1 @@ -{"creole.general.condition": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file"} +{"creole.general.condition": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file", "services.service0.files.file0.templating": true} diff --git a/tests/flattener_dicos/11disabledifnotin_filelist_notexist_validenum/result/00-base.xml b/tests/flattener_dicos/11disabledifnotin_filelist_notexist_validenum/result/00-base.xml index 3d688747c..8fa31afb0 100644 --- a/tests/flattener_dicos/11disabledifnotin_filelist_notexist_validenum/result/00-base.xml +++ b/tests/flattener_dicos/11disabledifnotin_filelist_notexist_validenum/result/00-base.xml @@ -32,6 +32,10 @@ mandatory file + + mandatory + True + mandatory disabled diff --git a/tests/flattener_dicos/11multi_disabled_if_in_filelist/makedict/base.json b/tests/flattener_dicos/11multi_disabled_if_in_filelist/makedict/base.json index c0f41953f..9c1367cfa 100644 --- a/tests/flattener_dicos/11multi_disabled_if_in_filelist/makedict/base.json +++ b/tests/flattener_dicos/11multi_disabled_if_in_filelist/makedict/base.json @@ -1 +1 @@ -{"creole.general.condition": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file1", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file1"} +{"creole.general.condition": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/tmp/file1", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file1", "services.service0.files.file0.templating": true} diff --git a/tests/flattener_dicos/11multi_disabled_if_in_filelist/result/00-base.xml b/tests/flattener_dicos/11multi_disabled_if_in_filelist/result/00-base.xml index db8f324d1..1ed40d7f6 100644 --- a/tests/flattener_dicos/11multi_disabled_if_in_filelist/result/00-base.xml +++ b/tests/flattener_dicos/11multi_disabled_if_in_filelist/result/00-base.xml @@ -32,6 +32,10 @@ mandatory file1 + + mandatory + True + disabled mandatory diff --git a/tests/flattener_dicos/20notemplating/00-base.xml b/tests/flattener_dicos/20notemplating/00-base.xml new file mode 100644 index 000000000..e77aea141 --- /dev/null +++ b/tests/flattener_dicos/20notemplating/00-base.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + non + + + + + + diff --git a/tests/flattener_dicos/20notemplating/makedict/base.json b/tests/flattener_dicos/20notemplating/makedict/base.json new file mode 100644 index 000000000..4ad98959d --- /dev/null +++ b/tests/flattener_dicos/20notemplating/makedict/base.json @@ -0,0 +1 @@ +{"creole.general.mode_conteneur_actif": "non", "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/file", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "file", "services.service0.files.file0.templating": false, "services.service0.files.file0.activate": true} diff --git a/tests/flattener_dicos/20notemplating/result/00-base.xml b/tests/flattener_dicos/20notemplating/result/00-base.xml new file mode 100644 index 000000000..45e172cf8 --- /dev/null +++ b/tests/flattener_dicos/20notemplating/result/00-base.xml @@ -0,0 +1,61 @@ + + + + + + + + mandatory + root + + + mandatory + False + + + mandatory + 0644 + + + mandatory + /etc/file + + + mandatory + root + + + mandatory + False + + + mandatory + file + + + mandatory + False + + + mandatory + True + + + + basic + + + + + normal + + oui + non + mandatory + normal + non + + + + + diff --git a/tests/flattener_dicos/20override/00-base.xml b/tests/flattener_dicos/20override/00-base.xml new file mode 100644 index 000000000..f3606bf77 --- /dev/null +++ b/tests/flattener_dicos/20override/00-base.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + non + + + + + + diff --git a/tests/flattener_dicos/20override/makedict/base.json b/tests/flattener_dicos/20override/makedict/base.json new file mode 100644 index 000000000..84573e713 --- /dev/null +++ b/tests/flattener_dicos/20override/makedict/base.json @@ -0,0 +1 @@ +{"creole.general.mode_conteneur_actif": "non", "services.service0.overrides.override0.name": "test.service", "services.service0.overrides.override0.source": "test.service", "services.service0.overrides.override0.templating": true, "services.service0.overrides.override0.activate": true} diff --git a/tests/flattener_dicos/20override/result/00-base.xml b/tests/flattener_dicos/20override/result/00-base.xml new file mode 100644 index 000000000..f59d3cfab --- /dev/null +++ b/tests/flattener_dicos/20override/result/00-base.xml @@ -0,0 +1,41 @@ + + + + + + + + mandatory + test.service + + + mandatory + test.service + + + mandatory + True + + + mandatory + True + + + + basic + + + + + normal + + oui + non + mandatory + normal + non + + + + + diff --git a/tests/flattener_dicos/60extra_group/makedict/base.json b/tests/flattener_dicos/60extra_group/makedict/base.json index ba1fd6440..dc38f83f0 100644 --- a/tests/flattener_dicos/60extra_group/makedict/base.json +++ b/tests/flattener_dicos/60extra_group/makedict/base.json @@ -1 +1 @@ -{"services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/mailname", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.activate": true, "extra.ejabberd.description.description": ["test"], "extra.ejabberd.description.mode": ["pre"]} +{"services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/mailname", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.templating": true, "services.service0.files.file0.activate": true, "extra.ejabberd.description.description": ["test"], "extra.ejabberd.description.mode": ["pre"]} diff --git a/tests/flattener_dicos/60extra_group/result/00-base.xml b/tests/flattener_dicos/60extra_group/result/00-base.xml index e9553cfb7..637c73eab 100644 --- a/tests/flattener_dicos/60extra_group/result/00-base.xml +++ b/tests/flattener_dicos/60extra_group/result/00-base.xml @@ -32,6 +32,10 @@ mandatory mailname + + mandatory + True + mandatory True diff --git a/tests/flattener_dicos/60extra_help/makedict/base.json b/tests/flattener_dicos/60extra_help/makedict/base.json index 7256b5c7c..d2a9b0001 100644 --- a/tests/flattener_dicos/60extra_help/makedict/base.json +++ b/tests/flattener_dicos/60extra_help/makedict/base.json @@ -1 +1 @@ -{"services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/mailname", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.activate": true, "extra.ejabberd.description": "Exportation de la base de ejabberd", "extra.ejabberd.day": null, "extra.ejabberd.mode": "pre"} +{"services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/mailname", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.templating": true, "services.service0.files.file0.activate": true, "extra.ejabberd.description": "Exportation de la base de ejabberd", "extra.ejabberd.day": null, "extra.ejabberd.mode": "pre"} diff --git a/tests/flattener_dicos/60extra_help/result/00-base.xml b/tests/flattener_dicos/60extra_help/result/00-base.xml index c46f11b81..5157061ba 100644 --- a/tests/flattener_dicos/60extra_help/result/00-base.xml +++ b/tests/flattener_dicos/60extra_help/result/00-base.xml @@ -32,6 +32,10 @@ mandatory mailname + + mandatory + True + mandatory True diff --git a/tests/flattener_dicos/70container_files/makedict/base.json b/tests/flattener_dicos/70container_files/makedict/base.json index e0b008454..a6feb5b63 100644 --- a/tests/flattener_dicos/70container_files/makedict/base.json +++ b/tests/flattener_dicos/70container_files/makedict/base.json @@ -1 +1 @@ -{"services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/mailname", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.activate": true} +{"services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/mailname", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.templating": true, "services.service0.files.file0.activate": true} diff --git a/tests/flattener_dicos/70container_files/result/00-base.xml b/tests/flattener_dicos/70container_files/result/00-base.xml index 4d1291b85..210359165 100644 --- a/tests/flattener_dicos/70container_files/result/00-base.xml +++ b/tests/flattener_dicos/70container_files/result/00-base.xml @@ -32,6 +32,10 @@ mandatory mailname + + mandatory + True + mandatory True diff --git a/tests/flattener_dicos/70container_files_symlink_multi/makedict/base.json b/tests/flattener_dicos/70container_files_symlink_multi/makedict/base.json index 6db8313c0..d8f262743 100644 --- a/tests/flattener_dicos/70container_files_symlink_multi/makedict/base.json +++ b/tests/flattener_dicos/70container_files_symlink_multi/makedict/base.json @@ -1 +1 @@ -{"creole.general.file_name": ["/etc/mailname", "/etc/mailname2"], "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": ["/etc/mailname", "/etc/mailname2"], "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.activate": true} +{"creole.general.file_name": ["/etc/mailname", "/etc/mailname2"], "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": ["/etc/mailname", "/etc/mailname2"], "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.templating": true, "services.service0.files.file0.activate": true} diff --git a/tests/flattener_dicos/70container_files_symlink_multi/result/00-base.xml b/tests/flattener_dicos/70container_files_symlink_multi/result/00-base.xml index ba720294b..d3cc83bb6 100644 --- a/tests/flattener_dicos/70container_files_symlink_multi/result/00-base.xml +++ b/tests/flattener_dicos/70container_files_symlink_multi/result/00-base.xml @@ -31,6 +31,10 @@ mandatory mailname + + mandatory + True + mandatory True diff --git a/tests/flattener_dicos/70container_files_symlink_multi_variable/makedict/base.json b/tests/flattener_dicos/70container_files_symlink_multi_variable/makedict/base.json index b5cd78542..616edcdb8 100644 --- a/tests/flattener_dicos/70container_files_symlink_multi_variable/makedict/base.json +++ b/tests/flattener_dicos/70container_files_symlink_multi_variable/makedict/base.json @@ -1 +1 @@ -{"creole.general.file_name": ["/etc/mailname", "/etc/mailname2"], "creole.general.var": ["mailname", "mailname2"], "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": ["/etc/mailname", "/etc/mailname2"], "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.variable": ["mailname", "mailname2"], "services.service0.files.file0.activate": true} +{"creole.general.file_name": ["/etc/mailname", "/etc/mailname2"], "creole.general.var": ["mailname", "mailname2"], "services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": ["/etc/mailname", "/etc/mailname2"], "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.templating": true, "services.service0.files.file0.variable": ["mailname", "mailname2"], "services.service0.files.file0.activate": true} diff --git a/tests/flattener_dicos/70container_files_symlink_multi_variable/result/00-base.xml b/tests/flattener_dicos/70container_files_symlink_multi_variable/result/00-base.xml index 478c116a4..9111a9275 100644 --- a/tests/flattener_dicos/70container_files_symlink_multi_variable/result/00-base.xml +++ b/tests/flattener_dicos/70container_files_symlink_multi_variable/result/00-base.xml @@ -31,6 +31,10 @@ mandatory mailname + + mandatory + True + mandatory diff --git a/tests/flattener_dicos/70container_filesmulti/makedict/base.json b/tests/flattener_dicos/70container_filesmulti/makedict/base.json index 67e63a500..c3de456b9 100644 --- a/tests/flattener_dicos/70container_filesmulti/makedict/base.json +++ b/tests/flattener_dicos/70container_filesmulti/makedict/base.json @@ -1 +1 @@ -{"services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/mailname", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.activate": true, "services.service0.files.file1.group": "root", "services.service0.files.file1.mkdir": false, "services.service0.files.file1.mode": "0644", "services.service0.files.file1.name": "/etc/mailname2", "services.service0.files.file1.owner": "root", "services.service0.files.file1.rm": false, "services.service0.files.file1.source": "mailname2", "services.service0.files.file1.activate": true} +{"services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/mailname", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.templating": true, "services.service0.files.file0.activate": true, "services.service0.files.file1.group": "root", "services.service0.files.file1.mkdir": false, "services.service0.files.file1.mode": "0644", "services.service0.files.file1.name": "/etc/mailname2", "services.service0.files.file1.owner": "root", "services.service0.files.file1.rm": false, "services.service0.files.file1.source": "mailname2", "services.service0.files.file1.templating": true, "services.service0.files.file1.activate": true} diff --git a/tests/flattener_dicos/70container_filesmulti/result/00-base.xml b/tests/flattener_dicos/70container_filesmulti/result/00-base.xml index 778c82e3d..5c5b10aaf 100644 --- a/tests/flattener_dicos/70container_filesmulti/result/00-base.xml +++ b/tests/flattener_dicos/70container_filesmulti/result/00-base.xml @@ -32,6 +32,10 @@ mandatory mailname + + mandatory + True + mandatory True @@ -66,6 +70,10 @@ mandatory mailname2 + + mandatory + True + mandatory True diff --git a/tests/flattener_dicos/70container_filesredefine/makedict/base.json b/tests/flattener_dicos/70container_filesredefine/makedict/base.json index 59f727602..e668ece0e 100644 --- a/tests/flattener_dicos/70container_filesredefine/makedict/base.json +++ b/tests/flattener_dicos/70container_filesredefine/makedict/base.json @@ -1 +1 @@ -{"services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/mailname", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname.new", "services.service0.files.file0.activate": true} +{"services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/mailname", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": false, "services.service0.files.file0.source": "mailname.new", "services.service0.files.file0.templating": true, "services.service0.files.file0.activate": true} diff --git a/tests/flattener_dicos/70container_filesredefine/result/00-base.xml b/tests/flattener_dicos/70container_filesredefine/result/00-base.xml index 2f75ed75e..55000c8a9 100644 --- a/tests/flattener_dicos/70container_filesredefine/result/00-base.xml +++ b/tests/flattener_dicos/70container_filesredefine/result/00-base.xml @@ -32,6 +32,10 @@ mandatory mailname.new + + mandatory + True + mandatory True diff --git a/tests/flattener_dicos/70container_filesrm/makedict/base.json b/tests/flattener_dicos/70container_filesrm/makedict/base.json index 513e7ba8a..5a9c97161 100644 --- a/tests/flattener_dicos/70container_filesrm/makedict/base.json +++ b/tests/flattener_dicos/70container_filesrm/makedict/base.json @@ -1 +1 @@ -{"services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/mailname", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": true, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.activate": true} +{"services.service0.files.file0.group": "root", "services.service0.files.file0.mkdir": false, "services.service0.files.file0.mode": "0644", "services.service0.files.file0.name": "/etc/mailname", "services.service0.files.file0.owner": "root", "services.service0.files.file0.rm": true, "services.service0.files.file0.source": "mailname", "services.service0.files.file0.templating": true, "services.service0.files.file0.activate": true} diff --git a/tests/flattener_dicos/70container_filesrm/result/00-base.xml b/tests/flattener_dicos/70container_filesrm/result/00-base.xml index e98ad2f18..ad0f1c882 100644 --- a/tests/flattener_dicos/70container_filesrm/result/00-base.xml +++ b/tests/flattener_dicos/70container_filesrm/result/00-base.xml @@ -32,6 +32,10 @@ mandatory mailname + + mandatory + True + mandatory True diff --git a/tests/templates/11disabled_if_in_filelist/00-base.xml b/tests/templates/11disabled_if_in_filelist/00-base.xml index f7f8c1a15..902c09b3e 100644 --- a/tests/templates/11disabled_if_in_filelist/00-base.xml +++ b/tests/templates/11disabled_if_in_filelist/00-base.xml @@ -32,6 +32,10 @@ mandatory file + + mandatory + True + mandatory disabled diff --git a/tests/templates/11disabled_if_in_filelist_disabled/00-base.xml b/tests/templates/11disabled_if_in_filelist_disabled/00-base.xml index 1231859c8..6faa8167a 100644 --- a/tests/templates/11disabled_if_in_filelist_disabled/00-base.xml +++ b/tests/templates/11disabled_if_in_filelist_disabled/00-base.xml @@ -18,7 +18,7 @@ mandatory - /tmp/file + /etc/file mandatory @@ -32,6 +32,10 @@ mandatory file + + mandatory + True + mandatory disabled diff --git a/tests/templates/11disabled_if_in_filelist_disabled/result/rougail.conf b/tests/templates/11disabled_if_in_filelist_disabled/result/rougail.conf new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/templates/11disabled_if_in_filelist_disabled/result/rougail.conf @@ -0,0 +1 @@ + diff --git a/tests/templates/20notemplating/00-base.xml b/tests/templates/20notemplating/00-base.xml new file mode 100644 index 000000000..45e172cf8 --- /dev/null +++ b/tests/templates/20notemplating/00-base.xml @@ -0,0 +1,61 @@ + + + + + + + + mandatory + root + + + mandatory + False + + + mandatory + 0644 + + + mandatory + /etc/file + + + mandatory + root + + + mandatory + False + + + mandatory + file + + + mandatory + False + + + mandatory + True + + + + basic + + + + + normal + + oui + non + mandatory + normal + non + + + + + diff --git a/tests/templates/20notemplating/result/etc/file b/tests/templates/20notemplating/result/etc/file new file mode 100644 index 000000000..5113d9aae --- /dev/null +++ b/tests/templates/20notemplating/result/etc/file @@ -0,0 +1 @@ +%%condition diff --git a/tests/templates/20notemplating/result/rougail.conf b/tests/templates/20notemplating/result/rougail.conf new file mode 100644 index 000000000..481d9601d --- /dev/null +++ b/tests/templates/20notemplating/result/rougail.conf @@ -0,0 +1,2 @@ +C /etc/file 0644 root root - - +z /etc/file - - - - - diff --git a/tests/templates/20notemplating/tmpl/file b/tests/templates/20notemplating/tmpl/file new file mode 100644 index 000000000..5113d9aae --- /dev/null +++ b/tests/templates/20notemplating/tmpl/file @@ -0,0 +1 @@ +%%condition diff --git a/tests/templates/20override/00-base.xml b/tests/templates/20override/00-base.xml new file mode 100644 index 000000000..f59d3cfab --- /dev/null +++ b/tests/templates/20override/00-base.xml @@ -0,0 +1,41 @@ + + + + + + + + mandatory + test.service + + + mandatory + test.service + + + mandatory + True + + + mandatory + True + + + + basic + + + + + normal + + oui + non + mandatory + normal + non + + + + + diff --git a/tests/templates/20override/result/rougail.conf b/tests/templates/20override/result/rougail.conf new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/templates/20override/result/rougail.conf @@ -0,0 +1 @@ + diff --git a/tests/templates/20override/result/system/test.service.d/rougail.conf b/tests/templates/20override/result/system/test.service.d/rougail.conf new file mode 100644 index 000000000..d907505b5 --- /dev/null +++ b/tests/templates/20override/result/system/test.service.d/rougail.conf @@ -0,0 +1 @@ +non diff --git a/tests/templates/20override/tmpl/test.service b/tests/templates/20override/tmpl/test.service new file mode 100644 index 000000000..a29cfeaf3 --- /dev/null +++ b/tests/templates/20override/tmpl/test.service @@ -0,0 +1 @@ +%%mode_conteneur_actif diff --git a/tests/templates/60extra_group/00-base.xml b/tests/templates/60extra_group/00-base.xml index e9553cfb7..637c73eab 100644 --- a/tests/templates/60extra_group/00-base.xml +++ b/tests/templates/60extra_group/00-base.xml @@ -32,6 +32,10 @@ mandatory mailname + + mandatory + True + mandatory True diff --git a/tests/templates/70container_files/00-base.xml b/tests/templates/70container_files/00-base.xml index 4d1291b85..210359165 100644 --- a/tests/templates/70container_files/00-base.xml +++ b/tests/templates/70container_files/00-base.xml @@ -32,6 +32,10 @@ mandatory mailname + + mandatory + True + mandatory True diff --git a/tests/templates/70container_files_symlink_multi/00-base.xml b/tests/templates/70container_files_symlink_multi/00-base.xml index ba720294b..d3cc83bb6 100644 --- a/tests/templates/70container_files_symlink_multi/00-base.xml +++ b/tests/templates/70container_files_symlink_multi/00-base.xml @@ -31,6 +31,10 @@ mandatory mailname + + mandatory + True + mandatory True diff --git a/tests/templates/70container_files_symlink_multi_variable/00-base.xml b/tests/templates/70container_files_symlink_multi_variable/00-base.xml index 478c116a4..9111a9275 100644 --- a/tests/templates/70container_files_symlink_multi_variable/00-base.xml +++ b/tests/templates/70container_files_symlink_multi_variable/00-base.xml @@ -31,6 +31,10 @@ mandatory mailname + + mandatory + True + mandatory diff --git a/tests/test_flattener.py b/tests/test_flattener.py index 9fa081df6..4e984a48d 100644 --- a/tests/test_flattener.py +++ b/tests/test_flattener.py @@ -83,7 +83,7 @@ def launch_flattener(test_dir, test_ok=False): eolobj.save(destfile) result_file = join(test_dir, 'result/00-base.xml') if isfile(result_file): - # eolobj.save(result_file) + eolobj.save(result_file) compare_xml(destfile, result_file) elif test_ok: raise Exception(f'no test found for {test_dir}') diff --git a/tests/test_makedict.py b/tests/test_makedict.py index dcbc16d11..2256573f5 100644 --- a/tests/test_makedict.py +++ b/tests/test_makedict.py @@ -50,12 +50,12 @@ async def launch_flattener(test_dir): await config.property.read_write() config_dict = await config.value.dict() # if not isfile(makedict_file) and config_dict: - #if config_dict: - # if not isdir(makedict_dir): - # mkdir(makedict_dir) - # with open(makedict_file, 'w') as fh: - # dump(config_dict, fh) - # fh.write('\n') + if config_dict: + if not isdir(makedict_dir): + mkdir(makedict_dir) + with open(makedict_file, 'w') as fh: + dump(config_dict, fh) + fh.write('\n') if not isfile(makedict_file): if config_dict: raise Exception('dict is not empty') diff --git a/tests/test_template.py b/tests/test_template.py index 051316574..3e5f7d5ae 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -54,10 +54,11 @@ async def test_dictionary(test_dir): funcs_file, distrib_dir, tmp_dir, - dest_dir) + dest_dir, + join(dest_dir, 'rougail.conf')) list_templates = set() - if isdir(join(dest_dir, 'etc')): + if isdir(dest_dir): find_files(join(dest_dir), [], list_templates) list_results = set() if isdir(join(test_dir, 'result')):