From d3008dc2176f30285ce2f40fba6520704bc5b816 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 29 Apr 2021 18:20:05 +0200 Subject: [PATCH] disabled a service (ref #4) --- doc/service/service.md | 10 ++++++++++ src/rougail/annotator/service.py | 3 ++- src/rougail/data/rougail.dtd | 1 + .../70service_disabled/00-base.xml | 12 +++++++++++ .../70service_disabled/__init__.py | 0 .../70service_disabled/makedict/after.json | 14 +++++++++++++ .../70service_disabled/makedict/base.json | 5 +++++ .../70service_disabled/makedict/before.json | 14 +++++++++++++ .../result/systemd/system/test.service | 1 + .../result/tmpfiles.d/rougail.conf | 0 .../70service_disabled/tiramisu/base.py | 20 +++++++++++++++++++ 11 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tests/dictionaries/70service_disabled/00-base.xml create mode 100644 tests/dictionaries/70service_disabled/__init__.py create mode 100644 tests/dictionaries/70service_disabled/makedict/after.json create mode 100644 tests/dictionaries/70service_disabled/makedict/base.json create mode 100644 tests/dictionaries/70service_disabled/makedict/before.json create mode 120000 tests/dictionaries/70service_disabled/result/systemd/system/test.service create mode 100644 tests/dictionaries/70service_disabled/result/tmpfiles.d/rougail.conf create mode 100644 tests/dictionaries/70service_disabled/tiramisu/base.py diff --git a/doc/service/service.md b/doc/service/service.md index 06473ea8..de1efbaf 100644 --- a/doc/service/service.md +++ b/doc/service/service.md @@ -29,6 +29,16 @@ Un service non géré ne peut conteneur que des fichiers. ## Désactiver la génération d'un service +Il est possible de désactiver un service. Pour cela il faut rajouter l'attribut "disabled" à True : + +``` + + + +``` + +Dans ce cas, tous les services et les éléments qu'il compose ([fichier](file.md), ...) seront désactivés. + Il est possible de définir une [condition](../condition/README.md) de type "disabled_if_in" ou "disabled_if_not_in" sur une balise service : ``` diff --git a/src/rougail/annotator/service.py b/src/rougail/annotator/service.py index de14cf9b..69158b86 100644 --- a/src/rougail/annotator/service.py +++ b/src/rougail/annotator/service.py @@ -76,10 +76,11 @@ class Annotator: None, None, 'activate', - True, + not service.disabled, service, '.'.join(['services', normalize_family(service_name), 'activate']), ) + service.disabled = None for elttype, values in dict(vars(service)).items(): if elttype == 'servicelist': self.objectspace.list_conditions.setdefault('servicelist', diff --git a/src/rougail/data/rougail.dtd b/src/rougail/data/rougail.dtd index df58c72e..1e8c6171 100644 --- a/src/rougail/data/rougail.dtd +++ b/src/rougail/data/rougail.dtd @@ -50,6 +50,7 @@ + diff --git a/tests/dictionaries/70service_disabled/00-base.xml b/tests/dictionaries/70service_disabled/00-base.xml new file mode 100644 index 00000000..f39bcf44 --- /dev/null +++ b/tests/dictionaries/70service_disabled/00-base.xml @@ -0,0 +1,12 @@ + + + + + + + + + no + + + diff --git a/tests/dictionaries/70service_disabled/__init__.py b/tests/dictionaries/70service_disabled/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/70service_disabled/makedict/after.json b/tests/dictionaries/70service_disabled/makedict/after.json new file mode 100644 index 00000000..08915df9 --- /dev/null +++ b/tests/dictionaries/70service_disabled/makedict/after.json @@ -0,0 +1,14 @@ +{ + "rougail.condition": { + "owner": "default", + "value": "no" + }, + "services.test.activate": { + "owner": "default", + "value": false + }, + "services.test.manage": { + "owner": "default", + "value": true + } +} diff --git a/tests/dictionaries/70service_disabled/makedict/base.json b/tests/dictionaries/70service_disabled/makedict/base.json new file mode 100644 index 00000000..393b57d7 --- /dev/null +++ b/tests/dictionaries/70service_disabled/makedict/base.json @@ -0,0 +1,5 @@ +{ + "rougail.condition": "no", + "services.test.activate": false, + "services.test.manage": true +} diff --git a/tests/dictionaries/70service_disabled/makedict/before.json b/tests/dictionaries/70service_disabled/makedict/before.json new file mode 100644 index 00000000..08915df9 --- /dev/null +++ b/tests/dictionaries/70service_disabled/makedict/before.json @@ -0,0 +1,14 @@ +{ + "rougail.condition": { + "owner": "default", + "value": "no" + }, + "services.test.activate": { + "owner": "default", + "value": false + }, + "services.test.manage": { + "owner": "default", + "value": true + } +} diff --git a/tests/dictionaries/70service_disabled/result/systemd/system/test.service b/tests/dictionaries/70service_disabled/result/systemd/system/test.service new file mode 120000 index 00000000..dc1dc0cd --- /dev/null +++ b/tests/dictionaries/70service_disabled/result/systemd/system/test.service @@ -0,0 +1 @@ +/dev/null \ No newline at end of file diff --git a/tests/dictionaries/70service_disabled/result/tmpfiles.d/rougail.conf b/tests/dictionaries/70service_disabled/result/tmpfiles.d/rougail.conf new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/70service_disabled/tiramisu/base.py b/tests/dictionaries/70service_disabled/tiramisu/base.py new file mode 100644 index 00000000..5a830258 --- /dev/null +++ b/tests/dictionaries/70service_disabled/tiramisu/base.py @@ -0,0 +1,20 @@ +from importlib.machinery import SourceFileLoader +from importlib.util import spec_from_loader, module_from_spec +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 key, value in dict(locals()).items(): + if key != ['SourceFileLoader', 'func']: + setattr(func, key, value) +try: + from tiramisu3 import * +except: + from tiramisu import * +option_2 = StrOption(name="condition", doc="condition", default="no", properties=frozenset({"mandatory", "normal"})) +option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) +option_5 = BoolOption(name="activate", doc="activate", default=False) +option_6 = BoolOption(name="manage", doc="manage", default=True) +option_4 = OptionDescription(name="test", doc="test", children=[option_5, option_6]) +option_3 = OptionDescription(name="services", doc="services", children=[option_4], properties=frozenset({"hidden"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_3]) -- 2.17.1