diff --git a/lower-constraints.txt b/lower-constraints.txt index 706e44332b..52756952e9 100644 --- a/lower-constraints.txt +++ b/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 diff --git a/requirements.txt b/requirements.txt index 2061043f50..7ca9fbca47 100644 --- a/requirements.txt +++ b/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 diff --git a/vmware_nsx/common/utils.py b/vmware_nsx/common/utils.py index 5b5c69b271..683ef5b34d 100644 --- a/vmware_nsx/common/utils.py +++ b/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})