From e927ac2ecb3c81b25ded81e29ba291a865a107a4 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Fri, 20 Sep 2024 09:43:05 -0700 Subject: [PATCH] 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 --- oslo_utils/imageutils/format_inspector.py | 8 +++++++- .../tests/imageutils/test_format_inspector.py | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/oslo_utils/imageutils/format_inspector.py b/oslo_utils/imageutils/format_inspector.py index 7463c670..49d426d5 100644 --- a/oslo_utils/imageutils/format_inspector.py +++ b/oslo_utils/imageutils/format_inspector.py @@ -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): diff --git a/oslo_utils/tests/imageutils/test_format_inspector.py b/oslo_utils/tests/imageutils/test_format_inspector.py index 0ad30709..92e7fa74 100644 --- a/oslo_utils/tests/imageutils/test_format_inspector.py +++ b/oslo_utils/tests/imageutils/test_format_inspector.py @@ -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,