Skip to content

Commit 5e6378a

Browse files
ktbyersGatorjosh14
andauthored
Updated Adtran Driver - Fixed global_cmd_verify default value and enable mode issues. (#3329)
Co-authored-by: Joshua Robinson <[email protected]>
1 parent a79a1ec commit 5e6378a

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

netmiko/adtran/adtran.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
from typing import Any, Optional
22
import re
33
from netmiko.cisco_base_connection import CiscoBaseConnection
4+
from netmiko.exceptions import NetmikoTimeoutException
45

56

67
class AdtranOSBase(CiscoBaseConnection):
78
prompt_pattern = r"[>#]"
89

9-
def __init__(self, *args: Any, **kwargs: Any) -> None:
10-
if kwargs.get("global_cmd_verify") is None:
11-
kwargs["global_cmd_verify"] = False
12-
return super().__init__(*args, **kwargs)
13-
1410
def session_preparation(self) -> None:
1511
"""Prepare the session after the connection has been established."""
1612
self.ansi_escape_codes = True
@@ -31,14 +27,55 @@ def enable(
3127
check_state: bool = True,
3228
re_flags: int = re.IGNORECASE,
3329
) -> str:
34-
return super().enable(
35-
cmd=cmd,
36-
pattern=pattern,
37-
enable_pattern=enable_pattern,
38-
check_state=check_state,
39-
re_flags=re_flags,
30+
output = ""
31+
msg = (
32+
"Failed to enter enable mode. Please ensure you pass "
33+
"the 'secret' argument to ConnectHandler."
4034
)
4135

36+
# Check if in enable mode already.
37+
if check_state and self.check_enable_mode():
38+
return output
39+
40+
# Send "enable" mode command
41+
self.write_channel(self.normalize_cmd(cmd))
42+
try:
43+
# Read the command echo
44+
if self.global_cmd_verify is not False:
45+
output += self.read_until_pattern(pattern=re.escape(cmd.strip()))
46+
47+
# Search for trailing prompt or password pattern
48+
output += self.read_until_prompt_or_pattern(
49+
pattern=pattern, re_flags=re_flags
50+
)
51+
52+
# Send the "secret" in response to password pattern
53+
if re.search(pattern, output):
54+
self.write_channel(self.normalize_cmd(self.secret))
55+
56+
# Handle the fallback to local authentication case
57+
fallback_pattern = r"Falling back"
58+
new_output = self.read_until_prompt_or_pattern(
59+
pattern=fallback_pattern, re_flags=re_flags
60+
)
61+
output += new_output
62+
63+
if "Falling back" in new_output:
64+
self.write_channel(self.normalize_cmd(self.secret))
65+
output += self.read_until_prompt()
66+
67+
# Search for terminating pattern if defined
68+
if enable_pattern and not re.search(enable_pattern, output):
69+
output += self.read_until_pattern(pattern=enable_pattern)
70+
else:
71+
if not self.check_enable_mode():
72+
raise ValueError(msg)
73+
74+
except NetmikoTimeoutException:
75+
raise ValueError(msg)
76+
77+
return output
78+
4279
def exit_enable_mode(self, exit_command: str = "disable") -> str:
4380
return super().exit_enable_mode(exit_command=exit_command)
4481

0 commit comments

Comments
 (0)