From 8866d37bb69a93049cf83c9bdd76443e01331b90 Mon Sep 17 00:00:00 2001 From: Abdul Haleem Date: Tue, 11 Jun 2024 13:40:36 +0530 Subject: [PATCH] Move wait_for function to utils As this function will be used in multiple tests, we can move this function to optest utils Signed-off-by: Abdul Haleem --- common/OpTestUtil.py | 15 +++++++++++++++ testcases/OpTestKernelTest.py | 21 --------------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/common/OpTestUtil.py b/common/OpTestUtil.py index 97453811..1da8eaf0 100644 --- a/common/OpTestUtil.py +++ b/common/OpTestUtil.py @@ -2469,6 +2469,21 @@ def format_email(self, linux_path , repo): with open("email.json","w") as email: json.dump({"subject":subject,"body":body},email) + def wait_for(self, func, timeout, first=0.0, step=1.0, text=None, args=None, kwargs=None): + args = args or [] + kwargs = kwargs or {} + start_time = time.monotonic() + end_time = start_time + timeout + time.sleep(first) + while time.monotonic() < end_time: + if text: + log.debug("%s (%.9f secs)", text, (time.monotonic() - start_time)) + output = func(*args, **kwargs) + if output: + return output + time.sleep(step) + return None + class Server(object): ''' diff --git a/testcases/OpTestKernelTest.py b/testcases/OpTestKernelTest.py index d35a5698..cab8de97 100644 --- a/testcases/OpTestKernelTest.py +++ b/testcases/OpTestKernelTest.py @@ -77,27 +77,6 @@ def setUp(self): self.fail( "Provide host ip user details refer, --host-{ip,user,password}") - def wait_for(self, func, timeout, first=0.0, step=1.0, text=None, args=None, kwargs=None): - args = args or [] - kwargs = kwargs or {} - - start_time = time.monotonic() - end_time = start_time + timeout - - time.sleep(first) - - while time.monotonic() < end_time: - if text: - log.debug("%s (%.9f secs)", text, (time.monotonic() - start_time)) - - output = func(*args, **kwargs) - if output: - return output - - time.sleep(step) - - return None - def build_kernel(self): """ Build and install the Linux kernel.