Skip to content

Commit

Permalink
Update regexp patterns for telnet (telekom#1)
Browse files Browse the repository at this point in the history
* comment adding patterns

* update regexp pattern

* add timeout for telnet and pattern fixed

* remove extra lines

* update test csses

---------
  • Loading branch information
ok2day authored and christian-sahlmann committed Nov 10, 2023
1 parent ab6617a commit 1fbb6d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mb_netmgmt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_cli_patterns():
b"[\r\n\x00\x1b\[K]RP/\d+/(?:RS?P)?\d+\/CPU\d+:[^#]+(?:\([^\)]+\))?#$"
) # based on IOS XR driver of Exscript
patterns.append(
b"[\r\n\x00\x1b\[K](?P<text>[\w/ .:,>\(\)\-\?]*)(?P<default>\[[\w/.,():\-]*\])?(?(default)(?P<end1>(?:\?|: ?| |)$)|(?P<end2>: $))"
b"[\r\n\x00\x1b\[K]+(?P<text>[A-Z][\w\/ .:,>\(\)\-\?\"]*[^A-Z])(?P<default>\[[\w\/.,():\-]*\])?(?(default)(?P<end1>(?:\?|: ?| |)$)|(?P<end2>: $))"
) # Interactive prompt
patterns.append(b"[\r\n\x00\x1b\[K] --More-- $") # Terminal paging
return patterns
Expand Down
2 changes: 1 addition & 1 deletion mb_netmgmt/telnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def respond(self, response, request_id):
def read_proxy_response(self):
prompt_patterns = [self.command_prompt]
prompt_patterns += get_cli_patterns()
_, _, response = self.telnet.expect(prompt_patterns)
_, _, response = self.telnet.expect(prompt_patterns, timeout=600)
return {"response": response.decode()}

def handle_username_prompt(self):
Expand Down
6 changes: 6 additions & 0 deletions test/test_mb_netmgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@
(b"\rDestination file name (control-c to abort): [running-config]?", True),
(b"\rDelete net/node0_8_CPU0/disk0:/c12k-mini.vm-4.3.2[confirm]", True),
(b"\rDestination filename [/net/node0_8_CPU0/disk0:/c12k-mini.vm-4.3.2]?", True),
(b"\r\n\rCopy : Destination exists, overwrite ?[confirm]", True),
(b"\rReload hardware module ? [no,yes] ", True),
(b"\rDo you wish to continue?[confirm(y/n)]", True),
(b'\r\n\r\nFormat will destroy all data on "harddisk:". Continue? [confirm]', True),
(b"\r --More-- ", True),
(b"\rSending 5, 100-byte ICMP Echos to 8.8.8.8, timeout is 2 seconds:", False),
(b"\rProceed with switchover 0/8/CPU0 -> 0/7/CPU0? [confirm]", True),
(b"\rPID: SPA-222XXXPOS/RPR, VID: ", False),
(b"\rNAME: ", False),
(b"\r Configured hold time: 180, keepalive: ", False),
(b"\n\r\n For Address Family: ", False),
]


Expand Down

0 comments on commit 1fbb6d2

Please sign in to comment.