diff options
author | Julien Danjou <julien@danjou.info> | 2016-06-01 10:07:41 +0200 |
---|---|---|
committer | Julien Danjou <julien@danjou.info> | 2016-06-01 10:07:41 +0200 |
commit | 2938f28ca7a75a46068d2cc03f46fa2e7f30aadc (patch) | |
tree | 8297dfde5c87007c1ca738adbb6656a6b61ea30c | |
parent | d1716100a992bdbf96793369cfc961af1c56b19a (diff) | |
download | oslo-db-2938f28ca7a75a46068d2cc03f46fa2e7f30aadc.tar.gz |
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
-rw-r--r-- | oslo_db/api.py | 6 |
1 files 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) |