diff --git a/lib/jnpr/junos/transport/tty.py b/lib/jnpr/junos/transport/tty.py index 34ae5ff94..f16a9a920 100644 --- a/lib/jnpr/junos/transport/tty.py +++ b/lib/jnpr/junos/transport/tty.py @@ -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(): @@ -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") @@ -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 diff --git a/lib/jnpr/junos/transport/tty_serial.py b/lib/jnpr/junos/transport/tty_serial.py index 6946be3c4..dece597e9 100644 --- a/lib/jnpr/junos/transport/tty_serial.py +++ b/lib/jnpr/junos/transport/tty_serial.py @@ -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 diff --git a/tests/unit/test_console.py b/tests/unit/test_console.py index 074dfac25..233d202a8 100644 --- a/tests/unit/test_console.py +++ b/tests/unit/test_console.py @@ -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() diff --git a/tests/unit/transport/test_serial.py b/tests/unit/transport/test_serial.py index 310205737..42ddf356f 100644 --- a/tests/unit/transport/test_serial.py +++ b/tests/unit/transport/test_serial.py @@ -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)