summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--oslo_config/generator.py6
-rw-r--r--oslo_config/tests/test_generator.py28
-rw-r--r--oslo_config/types.py5
3 files changed, 37 insertions, 2 deletions
diff --git a/oslo_config/generator.py b/oslo_config/generator.py
index ba3d3cc..4b59ee9 100644
--- a/oslo_config/generator.py
+++ b/oslo_config/generator.py
@@ -113,7 +113,7 @@ def _format_defaults(opt):
default_str = str(opt.default)
elif isinstance(opt, (cfg.ListOpt, cfg._ConfigFileOpt,
cfg._ConfigDirOpt)):
- default_str = ','.join(opt.default)
+ default_str = ','.join(six.text_type(d) for d in opt.default)
elif isinstance(opt, cfg.DictOpt):
sorted_items = sorted(opt.default.items(),
key=operator.itemgetter(0))
@@ -125,7 +125,9 @@ def _format_defaults(opt):
results = []
for default_str in defaults:
- if default_str.strip() != default_str:
+ if not isinstance(default_str, six.text_type):
+ default_str = six.text_type(default_str)
+ elif default_str.strip() != default_str:
default_str = '"%s"' % default_str
results.append(default_str)
return results
diff --git a/oslo_config/tests/test_generator.py b/oslo_config/tests/test_generator.py
index 8c7651e..015521e 100644
--- a/oslo_config/tests/test_generator.py
+++ b/oslo_config/tests/test_generator.py
@@ -151,6 +151,12 @@ class GeneratorTestCase(base.BaseTestCase):
'list_opt': cfg.ListOpt('list_opt',
default=['1', '2', '3'],
help='a list'),
+ 'list_opt_single': cfg.ListOpt('list_opt_single',
+ default='1',
+ help='a list'),
+ 'list_int_opt': cfg.ListOpt('list_int_opt',
+ default=[1, 2, 3],
+ help='a list'),
'dict_opt': cfg.DictOpt('dict_opt',
default={'1': 'yes', '2': 'no'},
help='a dict'),
@@ -620,6 +626,28 @@ class GeneratorTestCase(base.BaseTestCase):
# a list (list value)
#list_opt = 1,2,3
''')),
+ ('list_opt_single',
+ dict(opts=[('test', [(None, [opts['list_opt_single']])])],
+ expected='''[DEFAULT]
+
+#
+# From test
+#
+
+# a list (list value)
+#list_opt_single = 1
+''')),
+ ('list_int_opt',
+ dict(opts=[('test', [(None, [opts['list_int_opt']])])],
+ expected='''[DEFAULT]
+
+#
+# From test
+#
+
+# a list (list value)
+#list_int_opt = 1,2,3
+''')),
('dict_opt',
dict(opts=[('test', [(None, [opts['dict_opt']])])],
expected='''[DEFAULT]
diff --git a/oslo_config/types.py b/oslo_config/types.py
index c531e0c..976f497 100644
--- a/oslo_config/types.py
+++ b/oslo_config/types.py
@@ -489,6 +489,11 @@ class List(ConfigType):
def _formatter(self, value):
if isinstance(value, six.string_types):
return value
+ if isinstance(value, list):
+ value = [
+ six.text_type(v)
+ for v in value
+ ]
return ','.join(value)