commit f91033cae06c1a078c9a1f375efbe3dc555aec6b Author: Aija Jauntēva Date: Wed Oct 7 10:09:50 2020 -0400 Lower log severity for unknown type registries When unknown type encountered return and do not try another location as it is not expected to have different type. This is done to avoid another LOG.warning about not finding registry at all. Also fix mocking for test `test_get_message_registry_unknown_type` to take the intended path. And add `test_get_message_registry_loading_type_fails` to cover missing lines due to changes. Change-Id: I5a8190c55837f1e09ebdd3be34aae1fccd5a8229 Story: 2008094 Task: 40795 diff --git a/sushy/resources/registry/message_registry_file.py b/sushy/resources/registry/message_registry_file.py index 4d7d8d9..248c8d1 100644 --- a/sushy/resources/registry/message_registry_file.py +++ b/sushy/resources/registry/message_registry_file.py @@ -149,8 +149,9 @@ class MessageRegistryFile(base.ResourceBase): 'error': exc}) continue - LOG.warning('Ignoring unsupported flavor of registry %(registry)s', - {'registry': registry._odata_type}) + LOG.debug('Ignoring unsupported flavor of registry %(registry)s', + {'registry': registry._odata_type}) + return LOG.warning('No message registry found for %(language)s or ' 'default', {'language': language}) diff --git a/sushy/tests/unit/resources/registry/test_message_registry_file.py b/sushy/tests/unit/resources/registry/test_message_registry_file.py index 2dc858f..79367a2 100644 --- a/sushy/tests/unit/resources/registry/test_message_registry_file.py +++ b/sushy/tests/unit/resources/registry/test_message_registry_file.py @@ -125,22 +125,20 @@ class MessageRegistryFileTestCase(base.TestCase): reader=mock_reader_rv) self.assertEqual(mock_msg_reg_rv, registry) - @mock.patch('sushy.resources.registry.message_registry.MessageRegistry', + @mock.patch('sushy.resources.registry.message_registry_file.RegistryType', + autospec=True) + @mock.patch('sushy.resources.registry.message_registry_file.LOG', autospec=True) - @mock.patch('sushy.resources.base.JsonDataReader', autospec=True) def test_get_message_registry_unknown_type( - self, mock_reader, mock_msg_reg): - mock_reader_rv = mock.Mock() - mock_reader.return_value = mock_reader_rv - mock_reader_rv.get_json.return_value = { - "@odata.type": "#FishingRegistry.v1_1_1.FishingRegistry", - } - mock_msg_reg_rv = mock.Mock() - mock_msg_reg.return_value = mock_msg_reg_rv + self, mock_log, mock_registry_type): + mock_fishing_registry = mock_registry_type.return_value + mock_fishing_registry._odata_type = 'FishingRegistry' registry = self.reg_file.get_message_registry('en', None) - self.assertFalse(mock_msg_reg.called) self.assertIsNone(registry) + mock_log.debug.assert_called_with( + 'Ignoring unsupported flavor of registry %(registry)s', + {'registry': 'FishingRegistry'}) @mock.patch('sushy.resources.registry.message_registry.MessageRegistry', autospec=True) @@ -214,6 +212,26 @@ class MessageRegistryFileTestCase(base.TestCase): reader=None, redfish_version=self.reg_file.redfish_version) self.assertIsNone(registry) + @mock.patch('sushy.resources.registry.message_registry_file.LOG', + autospec=True) + @mock.patch('sushy.resources.registry.message_registry_file.RegistryType', + autospec=True) + def test_get_message_registry_loading_type_fails( + self, mock_reg_type, mock_log): + mock_reg_type.side_effect = TypeError('Something wrong') + + registry = self.reg_file.get_message_registry('en', None) + self.assertTrue(mock_reg_type.called) + self.assertIsNone(registry) + mock_log.warning.assert_any_call( + 'Cannot load message registry type from location ' + '%(location)s: %(error)s', + {'location': '/redfish/v1/Registries/Test/Test.1.0.json', + 'error': mock.ANY}) + mock_log.warning.assert_called_with( + 'No message registry found for %(language)s or default', + {'language': 'en'}) + @mock.patch('sushy.resources.registry.message_registry_file.RegistryType', autospec=True) def test_get_message_registry_strangely_cased_lang(