]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
ceph-defaults: fix handlers that are always triggered 2050/head
authorGuillaume Abrioux <gabrioux@redhat.com>
Fri, 13 Oct 2017 13:16:18 +0000 (15:16 +0200)
committerGuillaume Abrioux <gabrioux@redhat.com>
Fri, 13 Oct 2017 14:15:27 +0000 (16:15 +0200)
Handlers are always triggered in ceph-ansible because ceph.conf file is
generated with a randomly order for the different keys/values pairs
in sections.

In python, a dict is not sorted. It means in our case each time we try
to generate the ceph.conf file it will be rendered with a random order
since the mecanism behind consist of rendering a file from a python dict
with keys/values. Therefore, as a quick workaround, forcing this dict to be
sorted before rendering the configuration file will ensure that it will be
rendered always the same way.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
plugins/actions/_v1_config_template.py
plugins/actions/_v2_config_template.py

index 579c7f89b98ee8f940b9c324ffd2393cbe0fc590..95de13ef1c455944fd1466c91d613669e5f35135 100644 (file)
@@ -26,7 +26,7 @@ from ansible import errors
 from ansible.runner.return_data import ReturnData
 from ansible import utils
 from ansible.utils import template
-
+from collections import OrderedDict
 
 CONFIG_TYPES = {
     'ini': 'return_config_overrides_ini',
@@ -145,14 +145,14 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser):
     def write(self, fp):
         if self._defaults:
             fp.write("[%s]\n" % 'DEFAULT')
-            for key, value in self._defaults.items():
+            for key, value in OrderedDict(sorted(self._defaults.items())).items():
                 self._write_check(fp, key=key, value=value)
             else:
                 fp.write("\n")
 
         for section in self._sections:
             fp.write("[%s]\n" % section)
-            for key, value in self._sections[section].items():
+            for key, value in OrderedDict(sorted(self._sections[section].items())).items():
                 self._write_check(fp, key=key, value=value, section=True)
             else:
                 fp.write("\n")
index a9bc2f5800647ec2ec1da33c639a97bd13cfa5a8..787cd0f9f57c7808218ddfdf9dec8b61f588388d 100644 (file)
@@ -37,7 +37,7 @@ from ansible.plugins.action import ActionBase
 from ansible.utils.unicode import to_bytes, to_unicode
 from ansible import constants as C
 from ansible import errors
-
+from collections import OrderedDict
 
 CONFIG_TYPES = {
     'ini': 'return_config_overrides_ini',
@@ -173,14 +173,14 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser):
     def write(self, fp):
         if self._defaults:
             fp.write("[%s]\n" % 'DEFAULT')
-            for key, value in self._defaults.items():
+            for key, value in OrderedDict(sorted(self._defaults.items())).items():
                 self._write_check(fp, key=key, value=value)
             else:
                 fp.write("\n")
 
         for section in self._sections:
             fp.write("[%s]\n" % section)
-            for key, value in self._sections[section].items():
+            for key, value in OrderedDict(sorted(self._sections[section].items())).items():
                 self._write_check(fp, key=key, value=value, section=True)
             else:
                 fp.write("\n")