From cd47eda77b2a5ec37c82faacde6a9241f8d2a5c4 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Mon, 11 Apr 2016 23:17:02 -0500 Subject: [PATCH] Update the config_template plugin These changes address 2 issues: * The config template plugin in v1 mode was not respecting a list of integers and would cause a stacktrace because the ConfigParse module expects everything written to be a string. * The config template plugin in v2 mode was not properly handling the multi-string-op type due to an oversight in the ``_option_write`` method. With these updates the config template is now able to better support all of the potential options that could be thrown at it when writing an INI config file. These issues we're discovered while working with the ceph-ansible project and a mirroring PR has been created here: https://github.com/ceph/ceph-ansible/pull/707 Change-Id: I051096abae883ac81195d4538140566b69f8996c Signed-off-by: Kevin Carter --- action/_v1_config_template.py | 2 +- action/_v2_config_template.py | 17 ++++------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/action/_v1_config_template.py b/action/_v1_config_template.py index 07ddab5..f080d1d 100644 --- a/action/_v1_config_template.py +++ b/action/_v1_config_template.py @@ -263,7 +263,7 @@ class ActionModule(object): if isinstance(value, set): config.set(str(section), str(key), value) elif isinstance(value, list): - config.set(str(section), str(key), ','.join(value)) + config.set(str(section), str(key), ','.join(str(i) for i in value)) else: config.set(str(section), str(key), str(value)) diff --git a/action/_v2_config_template.py b/action/_v2_config_template.py index 0a38982..b039db2 100644 --- a/action/_v2_config_template.py +++ b/action/_v2_config_template.py @@ -303,17 +303,8 @@ class ActionModule(ActionBase): except (ConfigParser.DuplicateSectionError, ValueError): pass for key, value in items.items(): - if isinstance(value, list): - items = ','.join(_convert_2_string(value)) - else: - items = _convert_2_string(value) try: - self._option_write( - config, - str(section), - str(key), - items - ) + self._option_write(config, section, key, value) except ConfigParser.NoSectionError as exp: error_msg = str(exp) error_msg += ( @@ -340,11 +331,11 @@ class ActionModule(ActionBase): except AttributeError: pass if isinstance(value, set): - config.set(section, key, value) + config.set(str(section), str(key), value) elif isinstance(value, list): - config.set(section, key, ','.join(value)) + config.set(str(section), str(key), ','.join(str(i) for i in value)) else: - config.set(section, key, value) + config.set(str(section), str(key), str(value)) def return_config_overrides_json(self, config_overrides, resultant): """Returns config json