Skip to content

Commit

Permalink
Updates to Huawei Login issue fix (#2728)
Browse files Browse the repository at this point in the history
* fix(huawei): fix special_login_handler (#2711)

* Relocate password change code back to special_login_handler

* Fix issue you could get into where prompt might not be available.

* Increase timeouts to allow for more time during initial read.

Remove the _test_channel_read()

* Removing ReadTimeout handling

Co-authored-by: Florian Harbecke <florian@harbecke.net>
  • Loading branch information
ktbyers and fharbe committed Apr 14, 2022
1 parent fca1b3c commit b3119c5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions netmiko/huawei/huawei.py
Expand Up @@ -11,10 +11,19 @@


class HuaweiBase(NoEnable, CiscoBaseConnection):
def special_login_handler(self, delay_factor: float = 1.0) -> None:
# Huawei prompts for password change before displaying the initial base prompt.
# Search for that password change prompt or for base prompt.
password_change_prompt = r"(Change now|Please choose)"
data = self.read_until_pattern(pattern=rf"({password_change_prompt}|[>\]])")
if re.search(password_change_prompt, data):
self.write_channel("N" + self.RETURN)
self.read_until_pattern(pattern=r"[>\]]")

def session_preparation(self) -> None:
"""Prepare the session after the connection has been established."""
self.ansi_escape_codes = True
self._test_channel_read(pattern=r"[>\]]")
# The _test_channel_read happens in special_login_handler()
self.set_base_prompt()
self.disable_paging(command="screen-length 0 temporary")

Expand Down Expand Up @@ -97,16 +106,7 @@ def save_config(
class HuaweiSSH(HuaweiBase):
"""Huawei SSH driver."""

def special_login_handler(self, delay_factor: float = 1.0) -> None:
"""Handle password change request by ignoring it"""

# Huawei can prompt for password change. Search for that or for normal prompt
password_change_prompt = r"((Change now|Please choose))|([\]>]\s*$)"
output = self.read_until_pattern(password_change_prompt)
if re.search(password_change_prompt, output):
self.write_channel("N\n")
self.clear_buffer()
return None
pass


class HuaweiTelnet(HuaweiBase):
Expand Down

0 comments on commit b3119c5

Please sign in to comment.