diff options
author | Davanum Srinivas <davanum@gmail.com> | 2015-12-04 15:09:07 -0500 |
---|---|---|
committer | Davanum Srinivas <davanum@gmail.com> | 2015-12-04 16:46:33 -0500 |
commit | 8cd41466d36a359482f6ed7cc0b1c919541f5461 (patch) | |
tree | cc795fc735319f0ee4fbef7385e5699b7c4132b7 | |
parent | 5490a28a1398f10a3d346fef23374a972f90c40f (diff) | |
download | oslo-config-8cd41466d36a359482f6ed7cc0b1c919541f5461.tar.gz |
[fix-compat] Tolerate non-string defaults in String type3.1.0
Cinder folks found an issue where StrOpt had a default
value set to an integer. We were tolerating this before
so we should continue to do so with a warning.
Change-Id: I0af75f1a7102454d9285ab8df9d19242fada2325
-rw-r--r-- | oslo_config/tests/test_generator.py | 15 | ||||
-rw-r--r-- | oslo_config/types.py | 4 |
2 files changed, 19 insertions, 0 deletions
diff --git a/oslo_config/tests/test_generator.py b/oslo_config/tests/test_generator.py index f2875ea..1f64ebe 100644 --- a/oslo_config/tests/test_generator.py +++ b/oslo_config/tests/test_generator.py @@ -137,6 +137,9 @@ class GeneratorTestCase(base.BaseTestCase): default=['1', '2', '3'], sample_default=['5', '6'], help='multiple strings'), + 'string_type_with_bad_default': cfg.Opt('string_type_with_bad_default', + help='string with bad default', + default=4096), 'custom_type': cfg.Opt('custom_type', help='custom help', type=type('string')), @@ -619,6 +622,18 @@ class GeneratorTestCase(base.BaseTestCase): # custom help (unknown value) #custom_type = <None> ''')), + ('string_type_with_bad_default', + dict(opts=[('test', [(None, + [opts['string_type_with_bad_default']])])], + expected='''[DEFAULT] + +# +# From test +# + +# string with bad default (string value) +#string_type_with_bad_default = 4096 +''')), ] output_file_scenarios = [ diff --git a/oslo_config/types.py b/oslo_config/types.py index c098bfa..a126681 100644 --- a/oslo_config/types.py +++ b/oslo_config/types.py @@ -21,6 +21,7 @@ Use these classes as values for the `type` argument to """ import operator import re +import warnings import abc import netaddr @@ -46,6 +47,9 @@ class ConfigType(object): return [default_str] def quote_trailing_and_leading_space(self, str_val): + if not isinstance(str_val, six.string_types): + warnings.warn('converting \'%s\' to a string' % str_val) + str_val = six.text_type(str_val) if str_val.strip() != str_val: return '"%s"' % str_val return str_val |