Squelch irrelevant format complaints

When we're eating a multi-inspector stream, we would expect the other
formats to fail at some point in the stream when they don't match.
This makes us not log the irrelevant format failures when we're
looking for a specific one. We were already logging that at debug
level for the sake of visibility into the process, but some people
have been misled by the complaint. In addition, soften the language
a bit to make it clear it's not an actual failure.

Change-Id: Ife973cead13eba0900b72d9234253d543f723636
This commit is contained in:
Dan Smith 2024-09-20 09:43:05 -07:00
parent 3c33e37d64
commit e927ac2ecb
2 changed files with 22 additions and 3 deletions

View File

@ -1316,7 +1316,13 @@ class InspectWrapper:
# Absolutely do not allow the format inspector to break
# our streaming of the image for non-expected formats. If we
# failed, just stop trying, log and keep going.
LOG.debug('Format inspector failed, aborting: %s', e)
if not self._expected_format:
# If we are expecting to parse a specific format, we do
# not need to log scary messages about the other formats
# failing to parse the data as expected.
LOG.debug('Format inspector for %s does not match, '
'excluding from consideration (%s)',
inspector.NAME, e)
self._errored_inspectors.add(inspector)
def __next__(self):

View File

@ -970,8 +970,11 @@ class TestFormatInspectorInfra(test_base.BaseTestCase):
mock_eat.assert_called_once_with(b'123')
@mock.patch.object(format_inspector.VMDKInspector, 'eat_chunk')
def test_wrapper_iter_like_eats_error(self, mock_eat):
wrapper = format_inspector.InspectWrapper(iter([b'123', b'456']))
@mock.patch.object(format_inspector.LOG, 'debug')
def test_wrapper_iter_like_eats_error(self, mock_log, mock_eat,
expected=None):
wrapper = format_inspector.InspectWrapper(iter([b'123', b'456']),
expected_format=expected)
mock_eat.side_effect = Exception('fail')
data = b''
@ -984,6 +987,16 @@ class TestFormatInspectorInfra(test_base.BaseTestCase):
# Make sure we only called this once and never again after
# the error was raised
mock_eat.assert_called_once_with(b'123')
if expected:
self.assertFalse(mock_log.called)
else:
self.assertTrue(mock_log.called)
def test_wrapper_iter_like_eats_error_expected_quiet(self):
# Test with an expected format, but not the one we're going to
# intentionally fail to make sure that we do not log failures
# for non-expected formats.
self.test_wrapper_iter_like_eats_error(expected='vhd')
def test_get_inspector(self):
self.assertEqual(format_inspector.QcowInspector,