diff options
author | Boden R <bodenvmw@gmail.com> | 2016-09-08 15:22:41 -0600 |
---|---|---|
committer | Rabi Mishra <ramishra@redhat.com> | 2016-11-15 04:34:17 +0000 |
commit | 756dda72d411ae9706c64cebcd9eda6e44dcfdf7 (patch) | |
tree | 7439e6ad5562abbe37ae76b97722168a48718d30 /heat/objects | |
parent | f5291d5781d7a09b62e4b24cd3d9f8e5a537c18f (diff) | |
download | heat-756dda72d411ae9706c64cebcd9eda6e44dcfdf7.tar.gz |
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.
- For retries that check a result, tenacity will raise if the retried
function raises, whereas retrying retried on all exceptions.
This patch updates all usages of retrying with tenacity.
Unit tests will be added/removed where applicable.
[1] https://github.com/jd/tenacity
Closes-Bug: #1635388
Change-Id: Iec0822cc0d5589b04c1764db518478d286455031
Diffstat (limited to 'heat/objects')
-rw-r--r-- | heat/objects/resource.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/heat/objects/resource.py b/heat/objects/resource.py index 69cfd5177..d95f54aca 100644 --- a/heat/objects/resource.py +++ b/heat/objects/resource.py @@ -21,8 +21,8 @@ from oslo_config import cfg from oslo_serialization import jsonutils from oslo_versionedobjects import base from oslo_versionedobjects import fields -import retrying import six +import tenacity from heat.common import crypt from heat.common import exception @@ -36,11 +36,12 @@ cfg.CONF.import_opt('encrypt_parameters_and_properties', 'heat.common.config') def retry_on_conflict(func): - def is_conflict(ex): - return isinstance(ex, exception.ConcurrentTransaction) - wrapper = retrying.retry(stop_max_attempt_number=11, - wait_random_min=0.0, wait_random_max=2.0, - retry_on_exception=is_conflict) + wrapper = tenacity.retry( + stop=tenacity.stop_after_attempt(11), + wait=tenacity.wait_random(max=0.002), + retry=tenacity.retry_if_exception_type( + exception.ConcurrentTransaction), + reraise=True) return wrapper(func) |