From f354c846fab3a13c967f3a1821ff7b22bce0131b Mon Sep 17 00:00:00 2001 From: Liping Xu Date: Thu, 26 Mar 2026 07:01:52 +0000 Subject: [PATCH 1/3] fix(console): use splitlines()[0] to extract TMOUT value in test_idle_timeout When find_prompt() captures a partial prompt, netmiko strip_prompt() may fail to remove the trailing prompt, causing splitlines()[-1] to return the prompt string instead of the numeric value. Using splitlines()[0] always picks the first meaningful output line, which is the actual numeric value. Signed-off-by: Liping Xu Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/dut_console/test_idle_timeout.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/dut_console/test_idle_timeout.py b/tests/dut_console/test_idle_timeout.py index 0ec7b20df0a..bb421c7924a 100644 --- a/tests/dut_console/test_idle_timeout.py +++ b/tests/dut_console/test_idle_timeout.py @@ -1,5 +1,6 @@ import logging import time + import pytest from tests.common.helpers.assertions import pytest_assert @@ -17,13 +18,13 @@ def test_timeout(duthost_console, duthosts, enum_rand_one_per_hwsku_hostname): duthost = duthosts[enum_rand_one_per_hwsku_hostname] logger.info("Get default session idle timeout") - default_tmout = duthost_console.send_command('echo $TMOUT') + default_tmout = duthost_console.send_command('echo $TMOUT').strip().splitlines()[0].strip() pytest_assert(default_tmout == DEFAULT_TMOUT, "default timeout on dut is not {} seconds".format(DEFAULT_TMOUT)) logger.info("Set session idle timeout") duthost_console.send_command('export TMOUT={}'.format(SET_TMOUT)) - set_tmout = duthost_console.send_command('echo $TMOUT') + set_tmout = duthost_console.send_command('echo $TMOUT').strip().splitlines()[0].strip() pytest_assert(set_tmout == SET_TMOUT, "set timeout fail") time.sleep(15) - duthost_console.send_command("\n", expect_string=r"{} login:".format(duthost.hostname)) + duthost_console.send_command("\n", expect_string=r"{} login:".format(duthost.hostname)) \ No newline at end of file From 62ee60fff6461c80e69d4577729eac7f5d557713 Mon Sep 17 00:00:00 2001 From: Liping Xu Date: Thu, 26 Mar 2026 04:53:33 +0000 Subject: [PATCH 2/3] Fix intermittent Socket is closed in console login The Password: prompt from the DUT is sometimes split across multiple TCP reads (e.g., 'Pa' + 'ssword:'), causing re.search(pwd_pattern, output) to fail on each individual chunk. By checking return_msg (the accumulated read buffer) instead of output, we correctly detect the Password: prompt even when it arrives in fragments. This fixes the intermittent 'Socket is closed' failure in create_duthost_console where 1 in ~5 runs would fail because the password was never sent. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Liping Xu --- tests/common/connections/ssh_console_conn.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/common/connections/ssh_console_conn.py b/tests/common/connections/ssh_console_conn.py index ef3122e9176..89b975242ee 100644 --- a/tests/common/connections/ssh_console_conn.py +++ b/tests/common/connections/ssh_console_conn.py @@ -135,7 +135,9 @@ def login_stage_2(self, user_sent = True # Search for password pattern / send password - if user_sent and not password_sent and re.search(pwd_pattern, output, flags=re.I): + # Use return_msg (accumulated) instead of output to handle cases where + # 'Password:' prompt is split across multiple TCP reads (e.g. 'Pa' + 'ssword:') + if user_sent and not password_sent and re.search(pwd_pattern, return_msg, flags=re.I): self.write_channel(password + self.RETURN) time.sleep(0.5 * delay_factor) output = self.read_channel() From 37f17ab36e0b6cd94fbbb504fa4c0d6da8f6d37b Mon Sep 17 00:00:00 2001 From: Liping Xu Date: Thu, 26 Mar 2026 10:24:20 +0000 Subject: [PATCH 3/3] [dut_console]: Fix missing trailing newline in test_idle_timeout.py Add missing newline at end of file to fix the pre-commit fix-end-of-files check failure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Liping Xu --- tests/dut_console/test_idle_timeout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dut_console/test_idle_timeout.py b/tests/dut_console/test_idle_timeout.py index bb421c7924a..06a5e760f8f 100644 --- a/tests/dut_console/test_idle_timeout.py +++ b/tests/dut_console/test_idle_timeout.py @@ -27,4 +27,4 @@ def test_timeout(duthost_console, duthosts, enum_rand_one_per_hwsku_hostname): pytest_assert(set_tmout == SET_TMOUT, "set timeout fail") time.sleep(15) - duthost_console.send_command("\n", expect_string=r"{} login:".format(duthost.hostname)) \ No newline at end of file + duthost_console.send_command("\n", expect_string=r"{} login:".format(duthost.hostname))