Skip to content

Commit a8fb494

Browse files
authored
Fix Check Point Gaia double command echo issue (#3742)
* Fix Check Point gaia double command echo issue * Fixing linter * Linting #2
1 parent 47cfa6d commit a8fb494

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

netmiko/checkpoint/checkpoint_gaia_ssh.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import time
2+
import re
3+
14
from netmiko.no_config import NoConfig
25
from netmiko.base_connection import BaseConnection
36

@@ -8,16 +11,43 @@ class CheckPointGaiaSSH(NoConfig, BaseConnection):
811
firewalls.
912
"""
1013

14+
prompt_pattern = r"[>#]"
15+
1116
def session_preparation(self) -> None:
1217
"""
1318
Prepare the session after the connection has been established.
1419
1520
Set the base prompt for interaction ('>').
1621
"""
17-
self._test_channel_read(pattern=r"[>#]")
22+
self._test_channel_read(pattern=self.prompt_pattern)
1823
self.set_base_prompt()
1924
self.disable_paging(command="set clienv rows 0")
2025

26+
# Clear read buffer
27+
time.sleep(0.3 * self.global_delay_factor)
28+
self.clear_buffer()
29+
30+
def command_echo_read(self, cmd: str, read_timeout: float) -> str:
31+
"""Check Point clish double echoes the command (at least sometimes)"""
32+
33+
re_cmd = re.escape(cmd)
34+
pattern = rf"{self.prompt_pattern}\s{re_cmd}"
35+
36+
# Make sure you read until you detect the command echo (avoid getting out of sync)
37+
new_data = self.read_until_pattern(pattern=pattern, read_timeout=read_timeout)
38+
39+
# There can be echoed prompts that haven't been cleared before the cmd echo
40+
# this can later mess up the trailing prompt pattern detection. Clear this out.
41+
lines = new_data.split(cmd)
42+
if len(lines) in [2, 3]:
43+
# lines[-1] should realistically just be the null string
44+
new_data = f"{cmd}{lines[-1]}"
45+
else:
46+
# cmd exists in the output multiple times? Just retain the original output
47+
pass
48+
49+
return new_data
50+
2151
def save_config(
2252
self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
2353
) -> str:

0 commit comments

Comments
 (0)