diff --git a/netmiko/cisco/cisco_wlc_ssh.py b/netmiko/cisco/cisco_wlc_ssh.py index 20e9466ba..31eabdc37 100644 --- a/netmiko/cisco/cisco_wlc_ssh.py +++ b/netmiko/cisco/cisco_wlc_ssh.py @@ -11,11 +11,7 @@ class CiscoWlcSSH(BaseConnection): """Netmiko Cisco WLC support.""" - def __init__(self, *args: Any, **kwargs: Any) -> None: - # WLC/AireOS has an issue where you can get "No Existing Session" with - # the default conn_timeout (so increase conn_timeout to 10-seconds). - kwargs.setdefault("conn_timeout", 10) - return super().__init__(*args, **kwargs) + prompt_pattern = r"(?m:[>#]\s*$)" # force re.Multiline def special_login_handler(self, delay_factor: float = 1.0) -> None: """WLC presents with the following on login (in certain OS versions) @@ -28,25 +24,51 @@ def special_login_handler(self, delay_factor: float = 1.0) -> None: Password:**** """ - delay_factor = self.select_delay_factor(delay_factor) - i = 0 - time.sleep(delay_factor * 0.5) output = "" - while i <= 12: - output = self.read_channel() - if output: - if "login as" in output or "User:" in output: - assert isinstance(self.username, str) - self.write_channel(self.username + self.RETURN) - elif "Password" in output: - assert isinstance(self.password, str) - self.write_channel(self.password + self.RETURN) - break - time.sleep(delay_factor * 1) + uname = "User:" + login = "login as" + password = "ssword" + pattern = rf"(?:{uname}|{login}|{password}|{self.prompt_pattern})" + + while True: + new_data = self.read_until_pattern(pattern=pattern, read_timeout=25.0) + output += new_data + if re.search(self.prompt_pattern, new_data): + return + + if uname in new_data or login in new_data: + assert isinstance(self.username, str) + self.write_channel(self.username + self.RETURN) + elif password in new_data: + assert isinstance(self.password, str) + self.write_channel(self.password + self.RETURN) else: - # no output read, sleep and go for one more round of read channel - time.sleep(delay_factor * 1.5) - i += 1 + msg = f""" +Failed to login to Cisco WLC Device. + +Pattern not detected: {pattern} +output: + +{output} + +""" + raise NetmikoAuthenticationException(msg) + + def session_preparation(self) -> None: + """ + Prepare the session after the connection has been established + + Cisco WLC uses "config paging disable" to disable paging + """ + + # _test_channel_read() will happen in the special_login_handler() + try: + self.set_base_prompt() + except ValueError: + msg = f"Authentication failed: {self.host}" + raise NetmikoAuthenticationException(msg) + + self.disable_paging(command="config paging disable") def send_command_w_enter(self, *args: Any, **kwargs: Any) -> str: """ @@ -145,22 +167,6 @@ def _send_command_w_yes(self, *args: Any, **kwargs: Any) -> str: output = self.strip_prompt(output) return output - def session_preparation(self) -> None: - """ - Prepare the session after the connection has been established - - Cisco WLC uses "config paging disable" to disable paging - """ - self._test_channel_read(pattern=r"[>#]") - - try: - self.set_base_prompt() - except ValueError: - msg = f"Authentication failed: {self.host}" - raise NetmikoAuthenticationException(msg) - - self.disable_paging(command="config paging disable") - def cleanup(self, command: str = "logout") -> None: """Reset WLC back to normal paging and gracefully close session.""" self.send_command_timing("config paging enable") diff --git a/netmiko/extreme/extreme_ers_ssh.py b/netmiko/extreme/extreme_ers_ssh.py index 186f52ad5..241f6b453 100644 --- a/netmiko/extreme/extreme_ers_ssh.py +++ b/netmiko/extreme/extreme_ers_ssh.py @@ -50,7 +50,7 @@ def special_login_handler(self, delay_factor: float = 1.0) -> None: self.write_channel(self.password + self.RETURN) else: msg = f""" -Failed to login to Extreme ERS Devices. +Failed to login to Extreme ERS Device. Pattern not detected: {pattern} output: