summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIhar Hrachyshka <ihrachys@redhat.com>2016-05-27 14:12:37 +0200
committerIhar Hrachyshka <ihrachys@redhat.com>2016-06-02 15:00:10 +0000
commit9dd6ac634842b037c99d25b34431eaa2f4ed427c (patch)
tree45a6b000ac624f9cbf6ba9b223150e8a01500305
parentc83437020108c10ad6b51b52dd910496e04a5c0b (diff)
downloadoslo-config-stable/mitaka.tar.gz
generator: format string default value for List type properlymitaka-eolstable/mitaka
List type allows to pass string values as default values, which are then handled by splitting on commas. For formatting matters, if the default value is of string type, there is no special conversion needed, and we can reuse the value as-is. Change-Id: Ie9ecdfc064e886f6138b1fa9e839d8f95a7df339 Closes-Bug: #1586366 (cherry picked from commit 75e1c306630378673861d52a34de51e869183062)
-rw-r--r--oslo_config/tests/test_generator.py29
-rw-r--r--oslo_config/types.py2
2 files changed, 31 insertions, 0 deletions
diff --git a/oslo_config/tests/test_generator.py b/oslo_config/tests/test_generator.py
index 72ae1d3..4ea7100 100644
--- a/oslo_config/tests/test_generator.py
+++ b/oslo_config/tests/test_generator.py
@@ -939,6 +939,35 @@ class GeneratorAdditionalTestCase(base.BaseTestCase):
content = open(tmp_file).read()
self.assertEqual(expected, content)
+ def _test_output_default_list_opt_with_string_value(self, default):
+ opt = cfg.ListOpt('list_opt', help='a list', default=default)
+ config = [("namespace1", [
+ ("alpha", [opt])])]
+ groups = generator._get_groups(config)
+
+ fd, tmp_file = tempfile.mkstemp()
+ f = open(tmp_file, 'w+')
+ formatter = generator._OptFormatter(output_file=f)
+ expected = '''[alpha]
+
+#
+# From namespace1
+#
+
+# a list (list value)
+#list_opt = %(default)s
+''' % {'default': default}
+ generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
+ f.close()
+ content = open(tmp_file).read()
+ self.assertEqual(expected, content)
+
+ def test_output_default_list_opt_with_string_value_multiple_entries(self):
+ self._test_output_default_list_opt_with_string_value('foo,bar')
+
+ def test_output_default_list_opt_with_string_value_single_entry(self):
+ self._test_output_default_list_opt_with_string_value('foo')
+
class GeneratorMutableOptionTestCase(base.BaseTestCase):
diff --git a/oslo_config/types.py b/oslo_config/types.py
index 2464c5c..71d7817 100644
--- a/oslo_config/types.py
+++ b/oslo_config/types.py
@@ -447,6 +447,8 @@ class List(ConfigType):
)
def _formatter(self, value):
+ if isinstance(value, six.string_types):
+ return value
return ','.join(value)