[autotest] retry takes a blacklist and doesn't retry on ImportError
retry decorator now takes a blacklist of exceptions. The decorated
function will not be retried if an exception falls into the list.
As such, we have the option to let the functions fail faster
on errors we know for sure we don't want to retry.
RetryingAFE and RetryingTKO now don't retry on ImportError.
TEST=locally ran run_suite.py w/ and w/o simplejson installed
BUG=chromium:236847
Change-Id: I7365ee4971611562c4b6ad56720c067a97b2a840
Reviewed-on: https://gerrit.chromium.org/gerrit/49759
Reviewed-by: Scott Zawalski <scottz@chromium.org>
Commit-Queue: Fang Deng <fdeng@chromium.org>
Tested-by: Fang Deng <fdeng@chromium.org>
diff --git a/client/common_lib/cros/retry.py b/client/common_lib/cros/retry.py
index 5aa1f81..bb92b10 100644
--- a/client/common_lib/cros/retry.py
+++ b/client/common_lib/cros/retry.py
@@ -65,12 +65,12 @@
signal.alarm(old_alarm_sec)
-def retry(ExceptionToCheck, timeout_min=1.0, delay_sec=3):
+def retry(ExceptionToCheck, timeout_min=1.0, delay_sec=3, blacklist=None):
"""Retry calling the decorated function using a delay with jitter.
Will raise RPC ValidationError exceptions from the decorated
function without retrying; a malformed RPC isn't going to
- magically become good.
+ magically become good. Will raise exceptions in blacklist as well.
original from:
http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
@@ -81,6 +81,7 @@
@param delay_sec: pre-jittered delay between retries in seconds. Actual
delays will be centered around this value, ranging up to
50% off this midpoint.
+ @param blacklist: a list of exceptions that will be raised without retrying
"""
def deco_retry(func):
random.seed()
@@ -100,6 +101,7 @@
# Used to cache exception to be raised later.
exc_info = None
delayed_enabled = False
+ exception_tuple = () if blacklist is None else tuple(blacklist)
while time.time() < deadline:
if delayed_enabled:
delay()
@@ -112,6 +114,8 @@
timeout_min*60)
if not is_timeout:
return result
+ except exception_tuple:
+ raise
except (error.CrosDynamicSuiteException,
proxy.ValidationError):
raise
@@ -127,4 +131,4 @@
return func_retry # true decorator
- return deco_retry
\ No newline at end of file
+ return deco_retry