Better logging when registries are not available
Log which registries are available. Log differently when no registries are available at all. Clarify which language does not match what. Also move _get_registries to BaseResource since it's quite generic. Change-Id: Ie42f68032fc94f98e5b7cb1b0ccea86609b1812c
This commit is contained in:
parent
f804e95496
commit
738f7aa8c9
@ -589,6 +589,7 @@ class Sushy(base.ResourceBase):
|
||||
|
||||
registry_col = self._get_registry_collection()
|
||||
|
||||
endpoint_registries = {}
|
||||
if registry_col:
|
||||
provided = registry_col.get_members()
|
||||
for r in provided:
|
||||
@ -602,9 +603,16 @@ class Sushy(base.ResourceBase):
|
||||
self._language,
|
||||
self._public_connector)
|
||||
if registry:
|
||||
registries[r.registry] = registry
|
||||
if r.identity not in registries:
|
||||
registries[r.identity] = registry
|
||||
endpoint_registries[r.registry] = registry
|
||||
endpoint_registries.setdefault(r.identity, registry)
|
||||
|
||||
if endpoint_registries:
|
||||
LOG.debug('Found registries for %(id)s: %(reg)s',
|
||||
{'id': self.identity,
|
||||
'reg': ', '.join(endpoint_registries)})
|
||||
registries.update(endpoint_registries)
|
||||
else:
|
||||
LOG.debug('No registries are available for %s', self.identity)
|
||||
|
||||
return registries
|
||||
|
||||
|
@ -578,6 +578,43 @@ class ResourceBase(object, metaclass=abc.ABCMeta):
|
||||
|
||||
return val
|
||||
|
||||
def _get_registry(self, identity, language='en', description='registry'):
|
||||
"""Get a registry with the given identity.
|
||||
|
||||
:param identity: The registry identity.
|
||||
:param language: RFC 5646 language code for Message Registries.
|
||||
Indicates language of registry to be used. Defaults to 'en'.
|
||||
:param description: Human-readable description to use in logging.
|
||||
:returns: the corresponding registry object or None.
|
||||
"""
|
||||
registries = self._registries
|
||||
if not registries:
|
||||
LOG.info('No %s is available', description)
|
||||
return None
|
||||
|
||||
for key, registry in registries.items():
|
||||
if (registry
|
||||
and self._attribute_registry in (key, registry.identity)):
|
||||
if language != registry.language:
|
||||
LOG.debug('Found %(descr)s but its language %(reg_lang)s '
|
||||
'does not match the requested %(lang)s',
|
||||
{'descr': description,
|
||||
'lang': language,
|
||||
'reg_lang': registry.language})
|
||||
continue
|
||||
|
||||
return registry
|
||||
|
||||
avail = ', '.join(f'{reg.identity} ({reg.language})'
|
||||
for reg in registries.values())
|
||||
LOG.info('%(descr)s %(registry)s not available for language %(lang)s; '
|
||||
'available are: %(avail)s',
|
||||
{'descr': description,
|
||||
'registry': self._attribute_registry,
|
||||
'lang': language,
|
||||
'avail': avail})
|
||||
return None
|
||||
|
||||
def _parse_attributes(self, json_doc):
|
||||
"""Parse the attributes of a resource.
|
||||
|
||||
|
@ -252,24 +252,6 @@ class Bios(base.ResourceBase):
|
||||
Indicates language of registry to be used. Defaults to 'en'.
|
||||
:returns: the BIOS Attribute Registry
|
||||
"""
|
||||
registries = self._registries
|
||||
for key, registry in registries.items():
|
||||
# Check that BIOS attribute_registry matches the identity
|
||||
# of a registry, and this is the requested language
|
||||
if (registry
|
||||
and self._attribute_registry in (key, registry.identity)):
|
||||
if language != registry.language:
|
||||
LOG.debug('Found BIOS attribute registry but '
|
||||
'language %(lang)s does not match '
|
||||
'%(reg_lang)s',
|
||||
{'lang': language,
|
||||
'reg_lang': registry.language})
|
||||
continue
|
||||
|
||||
return registry
|
||||
|
||||
LOG.info('BIOS attribute registry %(registry)s '
|
||||
'not available for language %(lang)s',
|
||||
{'registry': self._attribute_registry,
|
||||
'lang': language})
|
||||
return None
|
||||
return self._get_registry(self._attribute_registry,
|
||||
language=language,
|
||||
description='BIOS attribute registry')
|
||||
|
Loading…
Reference in New Issue
Block a user