From 2938f28ca7a75a46068d2cc03f46fa2e7f30aadc Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 1 Jun 2016 10:07:41 +0200 Subject: [PATCH] api: do not log a traceback if error is not expected Currently, when using the retry decorator on a function that raises an error on the last retry, oslo.db always log the following: ERROR oslo_db.api [-] DB exceeded retry limit. ERROR oslo_db.api Traceback (most recent call last): ERROR oslo_db.api File "/usr/local/lib/python2.7/dist-packages/oslo_db/api.py", line 138, in wrapper ERROR oslo_db.api return f(*args, **kwargs) ERROR oslo_db.api File "/opt/stack/gnocchi/gnocchi/indexer/sqlalchemy.py", line 686, in list_resources ERROR oslo_db.api raise indexer.InvalidPagination("Invalid sort keys") ERROR oslo_db.api InvalidPagination: Invalid pagination: `Invalid sort keys' Which is wrong, since in this case the `InvalidPagination' is totally unrelated to the retry code. This patch fixes that by only calling LOG.exception if the last try is really about an expected retry condition. Change-Id: Iacc6d3aeac41ddfff76f081428678e2e0688055a Closes-Bug: #1587637 --- oslo_db/api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/oslo_db/api.py b/oslo_db/api.py index 6a58394..93931f7 100644 --- a/oslo_db/api.py +++ b/oslo_db/api.py @@ -139,10 +139,12 @@ class wrap_db_retry(object): return f(*args, **kwargs) except Exception as e: with excutils.save_and_reraise_exception() as ectxt: + expected = self._is_exception_expected(e) if remaining > 0: - ectxt.reraise = not self._is_exception_expected(e) + ectxt.reraise = not expected else: - LOG.exception(_LE('DB exceeded retry limit.')) + if expected: + LOG.exception(_LE('DB exceeded retry limit.')) # if it's a RetryRequest, we need to unpack it if isinstance(e, exception.RetryRequest): ectxt.type_ = type(e.inner_exc)