Merge "Fix inconsistent OptionJsonEncoder behavior on unknown type"

This commit is contained in:
Zuul 2019-03-19 19:21:04 +00:00 committed by Gerrit Code Review
commit f00f31cb2c
4 changed files with 23 additions and 8 deletions

View File

@ -66,7 +66,6 @@
CONGRESS_EXPOSE_ENCRYPTION_KEY_FOR_TEST: true
ENABLE_CONGRESS_Z3: true
USE_Z3_RELEASE: 4.7.1
ENABLE_CONGRESS_AGENT: false # temporarily disable cfg validator congress agent until breakage is fixed
- job:
name: congress-tempest-py2

View File

@ -316,7 +316,7 @@ class ConfigManager(object):
for config_path, template_path in six.iteritems(files):
try:
self.register_config(config_path, template_path, service_name)
except (IOError, cfg.ConfigFilesNotFoundError):
except (IOError, cfg.ConfigFilesNotFoundError, BaseException):
LOG.error(('Error while registering config %s with template'
' %s for service %s') %
(config_path, template_path, service_name))

View File

@ -124,7 +124,9 @@ class OptionJsonEncoder(json.JSONEncoder):
}
else:
return type(o).__name__
return {
'type': repr(o)
}
# pylint: disable=protected-access

View File

@ -67,7 +67,17 @@ def make_type(type_descr):
value_type = make_type(type_descr['value_type'])
type_descr['value_type'] = value_type
return getattr(types, type_name)(**type_descr)
try:
return_obj = getattr(types, type_name)(**type_descr)
except AttributeError:
LOG.warning('Custom type %s is not defined in oslo_config.types and '
'thus cannot be reconstructed. The type constraints will '
'not be enforced.', type_name)
# give the identity function is the type param to oslo_config.cfg.Opt
# not enforcing any type constraints
return_obj = lambda x: x
return return_obj
# This function must never fail even if the content/metadata
@ -93,14 +103,18 @@ def make_opt(option, opt_hash, ns_hash):
depr_descr.get('group', None))
deprecateds.append(depr_opt)
cfgtype = make_type(option.get('type', {}))
if 'type' in option:
cfgtype = make_type(option['type'])
else:
cfgtype = None
default = option.get('default', None)
if default:
if default and cfgtype:
try:
default = cfgtype(default)
except Exception:
_, err, _ = sys.exc_info()
LOG.error('Unvalid default value (%s, %s): %s'
LOG.error('Invalid default value (%s, %s): %s'
% (name, default, err))
try:
cfgopt = IdentifiedOpt(
@ -122,7 +136,7 @@ def make_opt(option, opt_hash, ns_hash):
except Exception:
cfgopt = None
_, err, _ = sys.exc_info()
LOG.error('Unvalid option definition (%s in %s): %s'
LOG.error('Invalid option definition (%s in %s): %s'
% (name, ns_hash, err))
return cfgopt