From 6fd6c097aca1ba0d04bde7a56bc9d6ecdc7a12e9 Mon Sep 17 00:00:00 2001 From: Boden R Date: Fri, 2 Sep 2016 14:27:39 -0600 Subject: [PATCH] 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: I18a0075e9a7c376b6881555ce67267a8944caafa --- murano/cfapi/cfapi.py | 12 ++++++------ murano/engine/system/net_explorer.py | 11 ++++++----- requirements.txt | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/murano/cfapi/cfapi.py b/murano/cfapi/cfapi.py index abb51572..6fe37fce 100644 --- a/murano/cfapi/cfapi.py +++ b/murano/cfapi/cfapi.py @@ -17,8 +17,8 @@ import uuid from oslo_config import cfg from oslo_log import log as logging -import retrying import six +import tenacity from webob import response from murano.common.i18n import _LI, _LW @@ -224,11 +224,11 @@ class Controller(object): for action_id in list(actions): if 'getCredentials' in action_id: - @retrying.retry(retry_on_exception=lambda e: isinstance(e, - TypeError), - wait_random_min=1000, - wait_random_max=10000, - stop_max_delay=30000) + @tenacity.retry( + retry=tenacity.retry_if_exception_type(TypeError), + wait=tenacity.wait_random(min=1, max=10), + stop=tenacity.stop_after_delay(30), + reraise=True) def _get_creds(client, task_id, environment_id): result = m_cli.actions.get_result(environment_id, task_id)['result'] diff --git a/murano/engine/system/net_explorer.py b/murano/engine/system/net_explorer.py index d75543f3..ff11f0d2 100644 --- a/murano/engine/system/net_explorer.py +++ b/murano/engine/system/net_explorer.py @@ -20,7 +20,7 @@ import neutronclient.v2_0.client as nclient from oslo_config import cfg from oslo_log import log as logging from oslo_utils import uuidutils -import retrying +import tenacity from murano.common import auth_utils from murano.common import exceptions as exc @@ -60,10 +60,11 @@ class NetworkExplorer(object): # NOTE(starodubcevna): to avoid simultaneous router requests we use retry # decorator with random delay 1-10 seconds between attempts and maximum # delay time 30 seconds. - @retrying.retry(retry_on_exception=lambda e: isinstance(e, - exc.RouterInfoException), - wait_random_min=1000, wait_random_max=10000, - stop_max_delay=30000) + @tenacity.retry( + retry=tenacity.retry_if_exception_type(exc.RouterInfoException), + stop=tenacity.stop_after_delay(30), + wait=tenacity.wait_random(min=1, max=10), + reraise=True) def get_default_router(self): router_name = self._settings.router_name diff --git a/requirements.txt b/requirements.txt index c1490a70..5e6c025b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ eventlet!=0.18.3,>=0.18.2 # MIT PasteDeploy>=1.5.0 # MIT Routes!=2.0,!=2.1,!=2.3.0,>=1.12.3;python_version=='2.7' # MIT Routes!=2.0,!=2.3.0,>=1.12.3;python_version!='2.7' # MIT -retrying!=1.3.0,>=1.2.3 # Apache-2.0 +tenacity>=3.1.0 # Apache-2.0 WebOb>=1.2.3 # MIT kombu>=3.0.25 # BSD psutil<2.0.0,>=1.1.1 # BSD