From daf75b8f861484a202bf76bef2b04d03b8cacad8 Mon Sep 17 00:00:00 2001 From: Tasmiya Nalatwad Date: Mon, 22 Jan 2024 15:54:51 +0530 Subject: [PATCH] Patch helps to overcome login issue. Sometimes the console via ssh is not connected and Login attempt fails, This could be due to network issue. Attempting to login for 5 times if the connection is not established in one go. Signed-off-by: Tasmiya Nalatwad --- testcases/InstallUpstreamKernel.py | 34 ++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/testcases/InstallUpstreamKernel.py b/testcases/InstallUpstreamKernel.py index d2d42d616..200985bc7 100644 --- a/testcases/InstallUpstreamKernel.py +++ b/testcases/InstallUpstreamKernel.py @@ -132,9 +132,18 @@ def is_url(path): "grub2-mkconfig --output=/boot/grub2/grub.cfg") log.debug("Rebooting after kernel install...") self.console_thread.console_terminate() + self.prompt = self.cv_SYSTEM.util.build_prompt() + self.console_thread.console_terminate() con.close() - self.cv_SYSTEM.goto_state(OpSystemState.OFF) - self.cv_SYSTEM.goto_state(OpSystemState.OS) + for i in range(5): + raw_pty = self.wait_for(self.cv_SYSTEM.console.get_console, timeout=20) + time.sleep(10) + if raw_pty is not None: + raw_pty.sendline("uname -r") + break + raw_pty.sendline("reboot") + raw_pty.expect("login:", timeout=600) + raw_pty.close() else: self.console_thread.console_terminate() cmdline = con.run_command("cat /proc/cmdline")[-1] @@ -182,3 +191,24 @@ def is_url(path): finally: if self.console_thread.isAlive(): self.console_thread.console_terminate() + + 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