Don't log non-db error in retry wrapper

838e314a21 changed the retry wrapper
code to not log exception traces for expected errors, like when
retrying on a DBDeadlock. It did, however, log an unexpected exception
but was not checking the type, like in the case of a nova OverQuota
exception.

Since _is_execption_expected already logs at debug level an expected
DB error, like DBDeadlock, during a retry loop, we don't need to log
it again. And if the exception is unexpected, like OverQuota from nova,
then we shouldn't trace that exception in the retry loop before
reraising but instead just let the caller handle it.

Adds a unit test to make sure that nothing is logged in the unexpected
exception case during the retry loop.

Co-Authored-By: Sean Dague <sean@dague.net>

Change-Id: Ic3e45029378dc96ce01398d9b55f51e20ef08189
Closes-Bug: #1532880
This commit is contained in:
Matt Riedemann
2016-01-11 09:37:08 -08:00
parent cfa53ac438
commit 4f5384dc99
2 changed files with 12 additions and 5 deletions

View File

@@ -139,11 +139,6 @@ class wrap_db_retry(object):
with excutils.save_and_reraise_exception() as ectxt:
if remaining > 0:
ectxt.reraise = not self._is_exception_expected(e)
if ectxt.reraise:
# We got an unexpected exception so stop
# retrying, log it and raise it up to the
# caller.
LOG.exception(_LE('DB error.'))
else:
LOG.exception(_LE('DB exceeded retry limit.'))
# if it's a RetryRequest, we need to unpack it

View File

@@ -220,3 +220,15 @@ class DBRetryRequestCase(DBAPITestCase):
dbapi.api_class_call1()
self.assertFalse(mocked_wrap.called)
@mock.patch('oslo_db.api.LOG')
def test_retry_wrapper_non_db_error_not_logged(self, mock_log):
# Tests that if the retry wrapper hits a non-db error (raised from the
# wrapped function), then that exception is reraised but not logged.
@api.wrap_db_retry(max_retries=5, retry_on_deadlock=True)
def some_method():
raise AttributeError('test')
self.assertRaises(AttributeError, some_method)
self.assertFalse(mock_log.called)