Replace retrying with tenacity

We are replacing all usages of the 'retrying' package with
'tenacity' as the author of retrying is not actively maintaining
the project. Tenacity is a fork of retrying, but has improved the
interface and extensibility (see [1] for more details). Our end
goal here is removing the retrying package from our requirements.

Tenacity provides the same functionality as retrying, but has the
following major differences to account for:
- tenacity uses seconds rather than ms as retrying did.
- tenacity has different kwargs for the decorator and
Retrying class itself.
- tenacity has a different approach for retrying args by
using classes for its stop/wait/retry kwargs.
- By default tenacity raises a RetryError if a retried callable
times out; retrying raises the last exception from the callable.
Tenacity provides backwards compatibility here by offering
the 'reraise' kwarg.
- tenacity defines 'time.sleep' as a default value for a kwarg.
That said consumers who need to mock patch time.sleep
need to account for this via mocking of time.sleep before
tenacity is imported.

This patch updates all usages of retrying with tenacity.
Unit tests will be added where applicable.

Note: This change is not newton critical so projects are welcome
to hold off on committing until post-newton. Ideally this change
will merge by the first part of Ocata so dependant functionality
can land and have time to solidify for Ocata.

[1] https://github.com/jd/tenacity

Change-Id: Id9507d1a192768cd636be308f85275a80df0157c
This commit is contained in:
Boden R 2016-09-08 14:35:34 -06:00
parent bd142765da
commit 723557ff64
2 changed files with 6 additions and 9 deletions

View File

@ -18,8 +18,8 @@ import datetime
import iso8601
from oslo_utils import timeutils
from pytimeparse import timeparse
import retrying
import six
import tenacity
import uuid
# uuid5 namespace for id transformation.
@ -54,14 +54,11 @@ class Retry(Exception):
pass
def retry_if_retry_is_raised(exception):
return isinstance(exception, Retry)
# Retry with exponential backoff for up to 1 minute
retry = retrying.retry(wait_exponential_multiplier=500,
wait_exponential_max=60000,
retry_on_exception=retry_if_retry_is_raised)
retry = tenacity.retry(
wait=tenacity.wait_exponential(multiplier=0.5, max=60),
retry=tenacity.retry_if_exception_type(Retry),
reraise=True)
def to_timestamp(v):

View File

@ -19,7 +19,7 @@ stevedore
voluptuous
werkzeug
trollius; python_version < '3.4'
retrying
tenacity>=3.1.0 # Apache-2.0
WebOb>=1.4.1
Paste
PasteDeploy