Ignore failing message registry download

Redfish agent (running inside BMC) can hyperlink message
registries from other locations so that the client can download
and use them. Trouble is, that sometimes these hyperlinked
locations may not be available or the hyperlink itself can be
malformed (e.g. iLO).

This patch ignores essentially all errors caused by message
registry download. That effectively renders failed message
registry being absent.

Change-Id: Iebe69ed0f93b6ba0c2b3905f751c1f12ed5eac88
Story: 2007445
Task: 39106
(cherry picked from commit 4791814adf)
This commit is contained in:
Ilya Etingof 2020-03-12 12:22:34 +01:00 committed by Bob Fournier
parent 2a464cb6ba
commit 12577c08a8
2 changed files with 62 additions and 2 deletions

View File

@ -126,10 +126,28 @@ class MessageRegistryFile(base.ResourceBase):
{'language': language})
continue
registry = RegistryType(*args, **kwargs)
try:
registry = RegistryType(*args, **kwargs)
except Exception as exc:
LOG.warning(
'Cannot load message registry type from location '
'%(location)s: %(error)s', {
'location': kwargs['path'],
'error': exc})
continue
if registry._odata_type.endswith('MessageRegistry'):
return message_registry.MessageRegistry(*args, **kwargs)
try:
return message_registry.MessageRegistry(*args, **kwargs)
except Exception as exc:
LOG.warning(
'Cannot load message registry from location '
'%(location)s: %(error)s', {
'location': kwargs['path'],
'error': exc})
continue
LOG.warning('Ignoring unsupported flavor of registry %(registry)s',
{'registry': registry._odata_type})

View File

@ -150,6 +150,48 @@ class MessageRegistryFileTestCase(base.TestCase):
'No message registry found for %(language)s or default',
{'language': 'en'})
@mock.patch('sushy.resources.registry.message_registry.MessageRegistry',
autospec=True)
@mock.patch('sushy.resources.registry.message_registry_file.RegistryType',
autospec=True)
@mock.patch('sushy.resources.registry.message_registry_file.LOG',
autospec=True)
def test_get_message_registry_invalid_uri(
self, mock_log, mock_msg_reg_type, mock_msg_reg):
mock_msg_reg_rv = mock.Mock()
mock_msg_reg.return_value = mock_msg_reg_rv
self.reg_file.location[0].uri = {'extref': 'http://127.0.0.1/reg'}
mock_msg_reg.side_effect = TypeError('Wrong URL type')
mock_msg_reg_type.return_value._odata_type = mock.MagicMock(
endswith=mock.MagicMock(return_value=True))
registry = self.reg_file.get_message_registry('en', None)
self.assertIsNone(registry)
mock_msg_reg_type.assert_called_once_with(
mock.ANY,
path={'extref': 'http://127.0.0.1/reg'}, reader=None,
redfish_version='1.0.2')
mock_msg_reg.assert_called_once_with(
mock.ANY,
path={'extref': 'http://127.0.0.1/reg'}, reader=None,
redfish_version='1.0.2')
expected_calls = [
mock.call(
'Cannot load message registry from location %(location)s: '
'%(error)s',
{'location': {'extref': 'http://127.0.0.1/reg'},
'error': mock.ANY}),
mock.call(
'No message registry found for %(language)s or default',
{'language': 'en'})
]
mock_log.warning.assert_has_calls(expected_calls)
@mock.patch('sushy.resources.registry.message_registry_file.RegistryType',
autospec=True)
def test_get_message_registry_non_default_lang(self, mock_registry_type):