Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #1229 #1230

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b96efd2
Serial connection bugfix
Aaron-MJohn Feb 6, 2023
e2f4a4e
Serial connection bugfix
Aaron-MJohn Feb 6, 2023
66ce164
Merge branch 'master' into HEAD
Aaron-MJohn Feb 16, 2023
c3a8a84
Unit test serial read prompt fix
Aaron-MJohn Feb 21, 2023
74621bd
Unit test_console fix
Aaron-MJohn Feb 21, 2023
5ab6d73
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Feb 28, 2023
9327eac
Check for bad password
Aaron-MJohn Mar 8, 2023
106c751
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Mar 22, 2023
4f86b06
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Apr 3, 2023
50b2eca
reset the password counter after a successfull login and bad password…
Aaron-MJohn Apr 3, 2023
4e7c949
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Apr 7, 2023
f782709
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Sep 8, 2023
fbff60a
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Oct 3, 2023
86b9ec3
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Dec 14, 2023
68d5e2b
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Jan 24, 2024
4f258f2
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Feb 21, 2024
2946917
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Mar 30, 2024
4e3979c
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Apr 12, 2024
9f9695b
Fix unit test for serial connection
Aaron-MJohn Apr 13, 2024
98455b4
Fixed field name to match template
Aaron-MJohn Apr 13, 2024
a93aa89
Merge branch 'fix_unit_test_failing' into bugfix/serial_connection
Aaron-MJohn Apr 13, 2024
ea13744
Revert "Merge branch 'fix_unit_test_failing' into bugfix/serial_conne…
Aaron-MJohn Apr 13, 2024
08c5d09
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Aug 29, 2024
7a96d1d
Merge branch 'Juniper:master' into bugfix/serial_connection
Aaron-MJohn Dec 2, 2024
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
14 changes: 10 additions & 4 deletions lib/jnpr/junos/transport/tty.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ def _ev_netconf_closed():
def _login_state_machine(self, attempt=0):
if self.login_attempts == attempt:
raise RuntimeError("login_sm_failure")

if attempt == 0:
self._password_entered = False
prompt, found = self.read_prompt()

def _ev_loader():
Expand All @@ -194,17 +195,22 @@ def _ev_loader():
raise RuntimeError("probably corrupted image, stuck in loader")

def _ev_login():
self.state = self._ST_LOGIN
self.write(self.user)
if self._password_entered:
_ev_bad_passwd()
else:
self.state = self._ST_LOGIN
self.write(self.user)

def _ev_passwd():
self.state = self._ST_PASSWD
self.write(self.passwd)
self._password_entered = True

def _ev_bad_passwd():
self.state = self._ST_BAD_PASSWD
self.write("\n")
self._badpasswd += 1
self._password_entered = False
if self._badpasswd == 2:
# raise RuntimeError("Bad username/password")
raise EzErrors.ConnectAuthError(self, "Bad username/password")
Expand Down Expand Up @@ -236,7 +242,7 @@ def _ev_shell():
# open. probably not a good thing,
# so issue a logging message, but move on.
logger.warning("login_warn: Shell login was open!!")

self._password_entered = False
self.at_shell = True
self.state = self._ST_DONE
# if we are here, then we are done
Expand Down
5 changes: 3 additions & 2 deletions lib/jnpr/junos/transport/tty_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def read_prompt(self):

while datetime.now() < mark_end:
sleep(0.1) # do not remove
line = self._ser.readline()
allline = self._ser.readall()
line = re.findall("\n(.*)", allline.decode())
if not line:
continue
rxb += line
rxb += six.b(line[-1])
found = _PROMPT.search(rxb)
if found is not None:
break # done reading
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_console_tty_open_err(self, mock_login, mock_telnet):
self.assertRaises(ValueError, self.dev.open)

@patch("jnpr.junos.transport.tty_serial.Serial._tty_open")
@patch("jnpr.junos.transport.tty_serial.serial.Serial.readline")
@patch("jnpr.junos.transport.tty_serial.serial.Serial.readall")
@patch("jnpr.junos.transport.tty_serial.Serial.write")
def test_console_serial(self, mock_write, mock_expect, mock_open):
tty_netconf.open = MagicMock()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/transport/test_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_tty_serial_read(self):
def test_tty_serial_read_prompt(self):
self.dev._tty._ser = MagicMock()
self.dev._tty.EXPECT_TIMEOUT = 0.1
self.dev._tty._ser.readline.side_effect = ["", "test"]
self.dev._tty._ser.readall.side_effect = [six.b(""), six.b("test")]
self.assertEqual(self.dev._tty.read_prompt()[0], None)


Expand Down