From 7cdfb5175be62d2e04a0fa25232aa0c9d5d14e56 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Mon, 22 Jul 2019 14:33:35 +0300 Subject: [PATCH] Update tenacity version and usage Some tenacity apis now get a single retry_state parameter which contain all the previous information. Change-Id: I8c83c21fe424bd6884a8e61893f1bda22dc7787b --- lower-constraints.txt | 2 +- requirements.txt | 2 +- vmware_nsxlib/v3/utils.py | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 490e2b32..5475cf29 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -25,7 +25,7 @@ six==1.10.0 sphinx==1.6.5 stestr==1.0.0 tempest==17.1.0 -tenacity==4.9.0 +tenacity==5.0.1 testresources==2.0.0 testtools==2.2.0 testscenarios==0.4 diff --git a/requirements.txt b/requirements.txt index fa0911e4..175d63a7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ pbr>=4.0.0 # Apache-2.0 decorator>=4.3.0 # BSD eventlet>=0.24.1 # MIT netaddr>=0.7.18 # BSD -tenacity>=4.9.0 # Apache-2.0 +tenacity>=5.0.1 # Apache-2.0 six>=1.10.0 # MIT oslo.i18n>=3.15.3 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 diff --git a/vmware_nsxlib/v3/utils.py b/vmware_nsxlib/v3/utils.py index 32af86f9..9eabbbbd 100644 --- a/vmware_nsxlib/v3/utils.py +++ b/vmware_nsxlib/v3/utils.py @@ -128,12 +128,14 @@ def update_v3_tags(current_tags, tags_update): return tags -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): @@ -145,7 +147,7 @@ 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() @@ -158,9 +160,9 @@ def _log_after_retry(func, trial_number, trial_time_taken): 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})