summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavanum Srinivas <davanum@gmail.com>2015-03-09 15:07:44 -0400
committerDavanum Srinivas <davanum@gmail.com>2015-03-09 15:35:24 -0400
commit9db52476f67ac1d66510c80c2e41e8bc3d653adf (patch)
treeaa995105a1a4c59e83a86ee6a19d769835e0b39b
parent1e42eb8f40eae29dd062d40b53ad37e908d7e72f (diff)
downloadoslo-config-9db52476f67ac1d66510c80c2e41e8bc3d653adf.tar.gz
None in config choices breaks oslo-config-generator
Tempest using StrOpt with choices choices=[None, 'normal', 'direct', 'macvtap'] And oslo-config-generator does not like it. We need to print "<None>" when we encounter None as a choice. Closes-Bug: #1429981 Change-Id: I3bb3621420915a6a2990440294a389b45a23c519
-rw-r--r--oslo_config/generator.py5
-rw-r--r--oslo_config/tests/test_generator.py4
-rw-r--r--tests/test_generator.py4
3 files changed, 8 insertions, 5 deletions
diff --git a/oslo_config/generator.py b/oslo_config/generator.py
index 0a4f7ce..749a556 100644
--- a/oslo_config/generator.py
+++ b/oslo_config/generator.py
@@ -109,6 +109,7 @@ import sys
import textwrap
import pkg_resources
+import six
from oslo.config import cfg
import stevedore.named # noqa
@@ -194,7 +195,9 @@ class _OptFormatter(object):
lines = self._format_help(help_text)
if getattr(opt.type, 'choices', None):
- choices_text = ', '.join(opt.type.choices)
+ choices_text = ', '.join([six.text_type(choice)
+ if choice else '<None>'
+ for choice in opt.type.choices])
lines.append('# Allowed values: %s\n' % choices_text)
for d in opt.deprecated_opts:
diff --git a/oslo_config/tests/test_generator.py b/oslo_config/tests/test_generator.py
index afd500f..1c30ca3 100644
--- a/oslo_config/tests/test_generator.py
+++ b/oslo_config/tests/test_generator.py
@@ -50,7 +50,7 @@ class GeneratorTestCase(base.BaseTestCase):
'laborum.'),
'choices_opt': cfg.StrOpt('choices_opt',
default='a',
- choices=('a', 'b', 'c'),
+ choices=(None, 'a', 'b', 'c'),
help='a string with choices'),
'deprecated_opt': cfg.StrOpt('bar',
deprecated_name='foobar',
@@ -294,7 +294,7 @@ class GeneratorTestCase(base.BaseTestCase):
#
# a string with choices (string value)
-# Allowed values: a, b, c
+# Allowed values: <None>, a, b, c
#choices_opt = a
''')),
('deprecated',
diff --git a/tests/test_generator.py b/tests/test_generator.py
index 41ddfec..3db32c9 100644
--- a/tests/test_generator.py
+++ b/tests/test_generator.py
@@ -54,7 +54,7 @@ class GeneratorTestCase(base.BaseTestCase):
'laborum.'),
'choices_opt': cfg.StrOpt('choices_opt',
default='a',
- choices=('a', 'b', 'c'),
+ choices=(None, 'a', 'b', 'c'),
help='a string with choices'),
'deprecated_opt': cfg.StrOpt('bar',
deprecated_name='foobar',
@@ -309,7 +309,7 @@ class GeneratorTestCase(base.BaseTestCase):
#
# a string with choices (string value)
-# Allowed values: a, b, c
+# Allowed values: <None>, a, b, c
#choices_opt = a
''')),
('deprecated',