diff options
author | Mark McLoughlin <markmc@redhat.com> | 2014-07-07 16:57:23 +0100 |
---|---|---|
committer | Mark McLoughlin <markmc@redhat.com> | 2014-07-09 09:11:02 +0100 |
commit | 26eb1026f95a5ffc8b5c5a73bb09d715530014b1 (patch) | |
tree | ccd7533973769f36c54c4a7a8849f71fab64bd88 | |
parent | 020e68d8e8fe6af19bd55aa13363e2f402d0af41 (diff) | |
download | oslo-config-26eb1026f95a5ffc8b5c5a73bb09d715530014b1.tar.gz |
generator: tweak how MultiStrOpt defaults are handled
If a MultiStrOpt default is set to None or [], the best thing to do is
just add:
#multi_str_opt =
to the sample config file.
Change-Id: Ibaee466978870082be47a2135ae3f412d3efd623
-rw-r--r-- | oslo/config/generator.py | 8 | ||||
-rw-r--r-- | tests/test_generator.py | 27 |
2 files changed, 32 insertions, 3 deletions
diff --git a/oslo/config/generator.py b/oslo/config/generator.py index 57c70bd..d5bdf13 100644 --- a/oslo/config/generator.py +++ b/oslo/config/generator.py @@ -186,8 +186,8 @@ class _OptFormatter(object): if isinstance(opt, cfg.MultiStrOpt): if opt.sample_default is not None: defaults = opt.sample_default - elif opt.default is None: - defaults = ['<None>'] + elif not opt.default: + defaults = [''] else: defaults = opt.default else: @@ -216,7 +216,9 @@ class _OptFormatter(object): for default_str in defaults: if default_str.strip() != default_str: default_str = '"%s"' % default_str - lines.append('#%s = %s\n' % (opt.dest, default_str)) + if default_str: + default_str = ' ' + default_str + lines.append('#%s =%s\n' % (opt.dest, default_str)) self.writelines(lines) diff --git a/tests/test_generator.py b/tests/test_generator.py index aa274e0..6b99967 100644 --- a/tests/test_generator.py +++ b/tests/test_generator.py @@ -85,6 +85,11 @@ class GeneratorTestCase(base.BaseTestCase): 'multi_opt': cfg.MultiStrOpt('multi_opt', default=['1', '2', '3'], help='multiple strings'), + 'multi_opt_none': cfg.MultiStrOpt('multi_opt_none', + help='multiple strings'), + 'multi_opt_empty': cfg.MultiStrOpt('multi_opt_empty', + default=[], + help='multiple strings'), 'multi_opt_sample_default': cfg.MultiStrOpt('multi_opt', default=['1', '2', '3'], sample_default=['5', '6'], @@ -408,6 +413,28 @@ class GeneratorTestCase(base.BaseTestCase): #multi_opt = 2 #multi_opt = 3 ''')), + ('multi_opt_none', + dict(opts=[('test', [(None, [opts['multi_opt_none']])])], + expected='''[DEFAULT] + +# +# From test +# + +# multiple strings (multi valued) +#multi_opt_none = +''')), + ('multi_opt_empty', + dict(opts=[('test', [(None, [opts['multi_opt_empty']])])], + expected='''[DEFAULT] + +# +# From test +# + +# multiple strings (multi valued) +#multi_opt_empty = +''')), ('str_opt_sample_default', dict(opts=[('test', [(None, [opts['str_opt_sample_default']])])], expected='''[DEFAULT] |