Fix inconsistent OptionJsonEncoder behavior on unknown type
Update OptionJsonEncoder to encode an unknown type as the expected
{'type': 'type_name'} rather than as 'type_name', fixing an error
encountered by related code that expects to index into the generated
dict construct.
Also updated congress agent tolerate unknown (custom) types instead
of exiting completely.
This reverts commit 69848285c8
.
Change-Id: Ie18967b1b4191c43e00817d7661cc4b5efd247be
Closes-Bug: 1819248
This commit is contained in:
parent
e84057a6f5
commit
9abf99939b
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -124,7 +124,9 @@ class OptionJsonEncoder(json.JSONEncoder):
|
|||
}
|
||||
|
||||
else:
|
||||
return type(o).__name__
|
||||
return {
|
||||
'type': repr(o)
|
||||
}
|
||||
|
||||
|
||||
# pylint: disable=protected-access
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue