Browse Source

Update tenacity version and usage

Some tenacity apis now get a single retry_state parameter which contain
all the previous information.

Change-Id: I3e34949dfb9a72ef30706f91beef079894d26201
changes/22/672022/2
Adit Sarfaty 2 years ago
parent
commit
883816713d
  1. 2
      lower-constraints.txt
  2. 2
      requirements.txt
  3. 23
      vmware_nsx/common/utils.py

2
lower-constraints.txt

@ -38,7 +38,7 @@ SQLAlchemy==1.2.0
sphinx==1.6.5
stestr==1.0.0
stevedore==1.20.0
tenacity==4.9.0
tenacity==5.0.1
testtools==2.2.0
tooz==1.58.0
vmware-nsxlib==13.1.0

2
requirements.txt

@ -7,7 +7,7 @@ eventlet>=0.24.1 # MIT
httplib2>=0.9.1 # MIT
requests>=2.14.2 # Apache-2.0
netaddr>=0.7.18 # BSD
tenacity>=4.9.0 # Apache-2.0
tenacity>=5.0.1 # Apache-2.0
SQLAlchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8,>=1.2.0 # MIT
six>=1.11.0 # MIT
stevedore>=1.20.0 # Apache-2.0

23
vmware_nsx/common/utils.py

@ -164,12 +164,14 @@ def _get_bad_request_error_code(e):
pass
def _log_before_retry(func, trial_number):
def _log_before_retry(retry_state):
"""Before call strategy that logs to some logger the attempt."""
if trial_number > 1:
if retry_state.attempt_number > 1:
LOG.warning("Retrying call to '%(func)s' for the %(num)s time",
{'func': tenacity_utils.get_callback_name(func),
'num': tenacity_utils.to_ordinal(trial_number)})
{'func': tenacity_utils.get_callback_name(
retry_state.fn),
'num': tenacity_utils.to_ordinal(
retry_state.attempt_number)})
def _get_args_from_frame(frames, frame_num):
@ -183,19 +185,22 @@ def _get_args_from_frame(frames, frame_num):
return formated_args
def _log_after_retry(func, trial_number, trial_time_taken):
def _log_after_retry(retry_state):
"""After call strategy that logs to some logger the finished attempt."""
# Using inspect to get arguments of the relevant call
frames = inspect.trace()
formated_args = _get_args_from_frame(frames, 1)
# Look at frame #2 first because of the internal functions _do_X
formated_args = _get_args_from_frame(frames, 2)
if not formated_args:
formated_args = _get_args_from_frame(frames, 1)
if not formated_args:
formated_args = "Unknown"
LOG.warning("Finished retry of %(func)s for the %(num)s time after "
"%(time)0.3f(s) with args: %(args)s",
{'func': tenacity_utils.get_callback_name(func),
'num': tenacity_utils.to_ordinal(trial_number),
'time': trial_time_taken,
{'func': tenacity_utils.get_callback_name(retry_state.fn),
'num': tenacity_utils.to_ordinal(retry_state.attempt_number),
'time': retry_state.seconds_since_start,
'args': formated_args})

Loading…
Cancel
Save