Add new keyword to run keyword in loop until it fails
Resolves openbmc/openbmc-test-automation#561
Change-Id: Ie8a07e83a104d1f2d3f2381a55ce13b2693ee424
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/syslib/utils_keywords.py b/syslib/utils_keywords.py
new file mode 100644
index 0000000..8d47d89
--- /dev/null
+++ b/syslib/utils_keywords.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+r"""
+This module contains keyword functions to supplement robot's built in
+functions and use in test where generic robot keywords don't support.
+
+"""
+import time
+from robot.libraries.BuiltIn import BuiltIn
+from robot.libraries import DateTime
+
+###############################################################################
+def run_until_keyword_fails(retry, retry_interval, name, *args):
+
+ r"""
+ Execute a robot keyword repeatedly until it either fails or the timeout
+ value is exceeded.
+ Note: Opposite of robot keyword "Wait Until Keyword Succeeds".
+
+ Description of argument(s):
+ retry Max timeout time in hour(s).
+ retry_interval Time interval in minute(s) for looping.
+ name Robot keyword to execute.
+ args Robot keyword arguments.
+ """
+
+ # Convert the retry time in seconds
+ retry_seconds= DateTime.convert_time(retry)
+ timeout = time.time() + int(retry_seconds)
+
+ # Convert the interval time in seconds
+ interval_seconds= DateTime.convert_time(retry_interval)
+ interval = int(interval_seconds)
+
+ BuiltIn().log(timeout)
+ BuiltIn().log(interval)
+
+ while True:
+ status= BuiltIn().run_keyword_and_return_status(name, *args)
+
+ # Return if keywords returns as failure.
+ if status==False:
+ BuiltIn().log("Failed as expected")
+ return False
+ # Return if retry timeout as success.
+ elif time.time() > timeout > 0:
+ BuiltIn().log("Max retry timeout")
+ return True
+ time.sleep(interval)
+ BuiltIn().log(time.time())
+
+ return True
+
+###############################################################################