Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tests/common/connections/ssh_console_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Good fix — TCP fragmentation splitting Password: across reads is a classic race. Using the accumulated return_msg instead of the per-chunk output is the right approach. Well-commented too.

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()
Expand Down
5 changes: 3 additions & 2 deletions tests/dut_console/test_idle_timeout.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import time

import pytest

from tests.common.helpers.assertions import pytest_assert
Expand All @@ -17,12 +18,12 @@
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()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Nit: .strip().splitlines()[0].strip() could raise IndexError if send_command returns an empty string (unlikely but possible on connection issues). A defensive guard would be:

lines = duthost_console.send_command('echo $TMOUT').strip().splitlines()
default_tmout = lines[0].strip() if lines else ""

Not a blocker — the old code would also fail on empty output.

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)
Expand Down
Loading