Use unified retrying decorator
Replace retry.retrying decorator with oslo_services.loopingcall.RetryDecorator and remove obsolete retry decorator from murano.common.utils Change-Id: I622c9b0fdff4b3bd5836d80a4abab056799158ca Closes-Bug: #1559890
This commit is contained in:
parent
14f08ecc85
commit
275ee8861d
@ -15,12 +15,11 @@
|
||||
import collections
|
||||
import functools as func
|
||||
|
||||
import eventlet
|
||||
import jsonschema
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from murano.common.i18n import _, _LE
|
||||
from murano.common.i18n import _
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -210,50 +209,6 @@ def build_entity_map(value):
|
||||
return id_map
|
||||
|
||||
|
||||
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2):
|
||||
"""Retry calling the decorated function using an exponential backoff.
|
||||
|
||||
http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
|
||||
original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
|
||||
|
||||
:param ExceptionToCheck: the exception to check. may be a tuple of
|
||||
exceptions to check
|
||||
:type ExceptionToCheck: Exception or tuple
|
||||
:param tries: number of times to try (not retry) before giving up
|
||||
:type tries: int
|
||||
:param delay: initial delay between retries in seconds
|
||||
:type delay: int
|
||||
:param backoff: backoff multiplier e.g. value of 2 will double the delay
|
||||
each retry
|
||||
:type backoff: int
|
||||
"""
|
||||
|
||||
def deco_retry(f):
|
||||
@func.wraps(f)
|
||||
def f_retry(*args, **kwargs):
|
||||
mtries, mdelay = tries, delay
|
||||
forever = mtries == -1
|
||||
while forever or mtries > 1:
|
||||
try:
|
||||
return f(*args, **kwargs)
|
||||
except ExceptionToCheck as e:
|
||||
LOG.exception(_LE("An exception occurred {exc}. Retrying "
|
||||
"in {time} seconds").format(exc=e,
|
||||
time=mdelay))
|
||||
eventlet.sleep(mdelay)
|
||||
|
||||
if not forever:
|
||||
mtries -= 1
|
||||
|
||||
if mdelay < 60:
|
||||
mdelay *= backoff
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return f_retry
|
||||
|
||||
return deco_retry
|
||||
|
||||
|
||||
def handle(f):
|
||||
"""Handles exception in wrapped function and writes to LOG."""
|
||||
|
||||
|
@ -19,8 +19,8 @@ from netaddr.strategy import ipv4
|
||||
import neutronclient.v2_0.client as nclient
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_service import loopingcall
|
||||
from oslo_utils import uuidutils
|
||||
import retrying
|
||||
|
||||
from murano.common import auth_utils
|
||||
from murano.common import exceptions as exc
|
||||
@ -58,10 +58,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)
|
||||
@loopingcall.RetryDecorator(max_retry_count=10,
|
||||
inc_sleep_time=2,
|
||||
max_sleep_time=60,
|
||||
exceptions=(lambda e: isinstance(e,
|
||||
exc.RouterInfoException),))
|
||||
def get_default_router(self):
|
||||
router_name = self._settings.router_name
|
||||
|
||||
|
@ -10,7 +10,6 @@ eventlet!=0.18.3,>=0.18.2 # MIT
|
||||
PasteDeploy>=1.5.0 # MIT
|
||||
Routes!=2.0,!=2.1,>=1.12.3;python_version=='2.7' # MIT
|
||||
Routes!=2.0,>=1.12.3;python_version!='2.7' # MIT
|
||||
retrying!=1.3.0,>=1.2.3 # Apache-2.0
|
||||
WebOb>=1.2.3 # MIT
|
||||
kombu>=3.0.25 # BSD
|
||||
psutil<2.0.0,>=1.1.1 # BSD
|
||||
|
Loading…
Reference in New Issue
Block a user