Merge "Handle some native python types in config generation"
This commit is contained in:
commit
91002b6f45
@ -108,6 +108,28 @@ def _format_defaults(opt):
|
||||
return results
|
||||
|
||||
|
||||
_TYPE_NAMES = {
|
||||
str: 'string value',
|
||||
int: 'integer value',
|
||||
float: 'floating point value',
|
||||
}
|
||||
|
||||
|
||||
def _format_type_name(opt_type):
|
||||
"""Format the type name to use in describing an option"""
|
||||
try:
|
||||
return opt_type.type_name
|
||||
except AttributeError: # nosec
|
||||
pass
|
||||
|
||||
try:
|
||||
return _TYPE_NAMES[opt_type]
|
||||
except KeyError: # nosec
|
||||
pass
|
||||
|
||||
return 'unknown value'
|
||||
|
||||
|
||||
class _OptFormatter(object):
|
||||
|
||||
"""Format configuration option descriptions to a file."""
|
||||
@ -171,9 +193,7 @@ class _OptFormatter(object):
|
||||
if not opt.help:
|
||||
LOG.warning(_LW('"%s" is missing a help string'), opt.dest)
|
||||
|
||||
option_type = getattr(opt, 'type', None)
|
||||
opt_type = getattr(option_type, 'type_name', 'unknown value')
|
||||
|
||||
opt_type = _format_type_name(opt.type)
|
||||
opt_prefix = ''
|
||||
if (opt.deprecated_for_removal and
|
||||
not opt.help.startswith('DEPRECATED')):
|
||||
|
@ -29,6 +29,11 @@ from oslo_config import types
|
||||
load_tests = testscenarios.load_tests_apply_scenarios
|
||||
|
||||
|
||||
def custom_type(a):
|
||||
"""Something that acts like a type, but isn't known"""
|
||||
return a
|
||||
|
||||
|
||||
class GeneratorTestCase(base.BaseTestCase):
|
||||
|
||||
groups = {
|
||||
@ -158,9 +163,18 @@ class GeneratorTestCase(base.BaseTestCase):
|
||||
'string_type_with_bad_default': cfg.Opt('string_type_with_bad_default',
|
||||
help='string with bad default',
|
||||
default=4096),
|
||||
'native_str_type': cfg.Opt('native_str_type',
|
||||
help='native help',
|
||||
type=str),
|
||||
'native_int_type': cfg.Opt('native_int_type',
|
||||
help='native help',
|
||||
type=int),
|
||||
'native_float_type': cfg.Opt('native_float_type',
|
||||
help='native help',
|
||||
type=float),
|
||||
'custom_type': cfg.Opt('custom_type',
|
||||
help='custom help',
|
||||
type=type('string')),
|
||||
type=custom_type),
|
||||
'custom_type_name': cfg.Opt('custom_opt_type',
|
||||
type=types.Integer(type_name='port'
|
||||
' number'),
|
||||
@ -666,6 +680,39 @@ class GeneratorTestCase(base.BaseTestCase):
|
||||
|
||||
# a string (string value)
|
||||
#str_opt = fooishbar
|
||||
''')),
|
||||
('native_str_type',
|
||||
dict(opts=[('test', [(None, [opts['native_str_type']])])],
|
||||
expected='''[DEFAULT]
|
||||
|
||||
#
|
||||
# From test
|
||||
#
|
||||
|
||||
# native help (string value)
|
||||
#native_str_type = <None>
|
||||
''')),
|
||||
('native_int_type',
|
||||
dict(opts=[('test', [(None, [opts['native_int_type']])])],
|
||||
expected='''[DEFAULT]
|
||||
|
||||
#
|
||||
# From test
|
||||
#
|
||||
|
||||
# native help (integer value)
|
||||
#native_int_type = <None>
|
||||
''')),
|
||||
('native_float_type',
|
||||
dict(opts=[('test', [(None, [opts['native_float_type']])])],
|
||||
expected='''[DEFAULT]
|
||||
|
||||
#
|
||||
# From test
|
||||
#
|
||||
|
||||
# native help (floating point value)
|
||||
#native_float_type = <None>
|
||||
''')),
|
||||
('multi_opt_sample_default',
|
||||
dict(opts=[('test', [(None, [opts['multi_opt_sample_default']])])],
|
||||
|
Loading…
x
Reference in New Issue
Block a user