[ONOS-6905] Adujust the number of retrying and sleep time to the FUNCintent
Change-Id: I4e8d1002e4915e1bbd8635c7a2a6660adf64d129
diff --git a/TestON/core/utilities.py b/TestON/core/utilities.py
index ed37ae3..2f7e5bb 100644
--- a/TestON/core/utilities.py
+++ b/TestON/core/utilities.py
@@ -295,7 +295,8 @@
return 0
def retry( self, f, retValue, args=(), kwargs={},
- sleep=1, attempts=2, randomTime=False ):
+ sleep=1, attempts=2, randomTime=False,
+ getRetryingTime=False ):
"""
Given a function and bad return values, retry will retry a function
until successful or give up after a certain number of attempts.
@@ -321,6 +322,8 @@
assert sleep >= 0, "sleep must be >= 0"
if not isinstance( retValue, list ):
retValue = [ retValue ]
+ if getRetryingTime:
+ startTime = time.time()
for i in range( 0, attempts ):
ret = f( *args, **kwargs )
if ret not in retValue:
@@ -333,6 +336,8 @@
time.sleep( sleeptime )
if i > 0:
main.log.debug( str( f ) + " was retried " + str( i ) + " times." )
+ if getRetryingTime:
+ main.log.debug( "Took " + str( time.time() - startTime ) + " seconds for retrying." )
return ret
except AssertionError:
main.log.exception( "Invalid arguements for retry: " )