From debf717481099ae651c0fae4abcfa81daa15fc00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=81?= Date: Tue, 8 Dec 2020 13:24:23 +0300 Subject: [PATCH] Registers in open rc configs are fixed #37 --- calculate/templates/format/openrc_format.py | 12 ++++++-- tests/templates/format/test_openrc.py | 30 +++++++++++++++++++ .../templates/format/testfiles/openrc/result | 6 ++-- .../format/testfiles/openrc/template | 2 +- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/calculate/templates/format/openrc_format.py b/calculate/templates/format/openrc_format.py index b903deb..4a3b899 100644 --- a/calculate/templates/format/openrc_format.py +++ b/calculate/templates/format/openrc_format.py @@ -59,14 +59,20 @@ class OpenRCFormat(Format): self._join(self._document_dictionary, template._document_dictionary, self._join_before) - print('AFTER JOIN') - self.print_dictionary() def _correct_register(self, template: "OpenRCFormat") -> dict: '''Метод для корректировки всех регистров.''' corrected_dict = OrderedDict() + template_keys = {key[1].lower(): key[1] for key + in template._document_dictionary.keys()} - return self._document_dictionary + for key, value in self._document_dictionary.items(): + if key[1].lower() in template_keys: + corrected_dict[('', template_keys[key[1].lower()])] = value + else: + corrected_dict[key] = value + + return corrected_dict @classmethod def _initialize_parser(cls): diff --git a/tests/templates/format/test_openrc.py b/tests/templates/format/test_openrc.py index c620882..a45a5e4 100644 --- a/tests/templates/format/test_openrc.py +++ b/tests/templates/format/test_openrc.py @@ -307,3 +307,33 @@ INSTANCE="openldap${SVCNAME#slapd}" template_object = OpenRCFormat(template_text, '/path/to/template') original_object.join_template(template_object) assert original_object.document_text == join_result + + def test_register_changing(self): + original = '''PARAM=1 +param2=2 +BIG_PARAM=1 +low_param=2''' + + template = '''big_param=3 +LOW_PARAM=4 +new_param=5 +NEW_PARAM2=6''' + + result = '''PARAM=1 + +param2=2 + +big_param=3 + +LOW_PARAM=4 + +new_param=5 + +NEW_PARAM2=6 + +''' + + original_object = OpenRCFormat(original, '/path/to/template') + template_object = OpenRCFormat(template, '/path/to/template') + original_object.join_template(template_object) + assert original_object.document_text == result diff --git a/tests/templates/format/testfiles/openrc/result b/tests/templates/format/testfiles/openrc/result index 4540280..3e140a6 100644 --- a/tests/templates/format/testfiles/openrc/result +++ b/tests/templates/format/testfiles/openrc/result @@ -5,7 +5,7 @@ rc_tty_number=12 # The following setting turns on the memory.use_hierarchy setting in the # root memory cgroup for cgroups v1. # It must be set to yes in this file if you want this functionality. -rc_cgroup_memory_use_hierarchy="YES" +RC_CGROUP_MEMORY_USE_HIERARCHY="YES" # Multiple settings and values can be specified. # For example, you would use this to set the maximum memory and maximum @@ -13,10 +13,10 @@ rc_cgroup_memory_use_hierarchy="YES" rc_cgroup_settings="10485760" # If you have multiple slapd instances per #376699, this will provide a default config -instance="openldap${SVCNAME#slapd}" +INSTANCE="openldap${SVCNAME#slapd}" # If you use the classical configuration file: -opts_conf="-f /etc/${INSTANCE}/slapd.conf" +OPTS_CONF="-f /etc/${INSTANCE}/slapd.conf" # Specify the kerberos keytab file #KRB5_KTNAME=/etc/openldap/krb5-ldap.keytab diff --git a/tests/templates/format/testfiles/openrc/template b/tests/templates/format/testfiles/openrc/template index 2fb7fd4..264a0b0 100644 --- a/tests/templates/format/testfiles/openrc/template +++ b/tests/templates/format/testfiles/openrc/template @@ -1,6 +1,6 @@ # It must be set to yes in this file if you want this functionality. -rc_cgroup_memory_use_hierarchy="YES" +RC_CGROUP_MEMORY_USE_HIERARCHY="YES" clock="Any Clock Type"