Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove paramiko hacks #464

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 8 additions & 28 deletions src/SSHLibrary/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .config import (Configuration, IntegerEntry, NewlineEntry, StringEntry,
TimeEntry)
from robot.api import logger
from robot.utils import is_bytes, is_string, is_truthy, is_list_like
from robot.utils import is_bytes, is_string, is_truthy
from .pythonforward import LocalPortForwarding

try:
Expand All @@ -46,29 +46,7 @@
)


# There doesn't seem to be a simpler way to increase banner timeout
def _custom_start_client(self, *args, **kwargs):
self.banner_timeout = 45
self._orig_start_client(*args, **kwargs)


paramiko.transport.Transport._orig_start_client = \
paramiko.transport.Transport.start_client
paramiko.transport.Transport.start_client = _custom_start_client


# See http://code.google.com/p/robotframework-sshlibrary/issues/detail?id=55
def _custom_log(self, level, msg, *args):
escape = lambda s: s.replace('%', '%%')
if is_list_like(msg):
msg = [escape(m) for m in msg]
else:
msg = escape(msg)
return self._orig_log(level, msg, *args)


paramiko.sftp_client.SFTPClient._orig_log = paramiko.sftp_client.SFTPClient._log
paramiko.sftp_client.SFTPClient._log = _custom_log
BANNER_TIMEOUT = 45


class SSHClientException(RuntimeError):
Expand Down Expand Up @@ -900,7 +878,8 @@ def _login(self, username, password, allow_agent=False, look_for_keys=False, pro
self.client.connect(self.config.host, self.config.port, username,
password, look_for_keys=look_for_keys,
allow_agent=allow_agent,
timeout=float(self.config.timeout), sock=sock_tunnel)
timeout=float(self.config.timeout), sock=sock_tunnel,
banner_timeout=BANNER_TIMEOUT)
except paramiko.SSHException:
pass
transport = self.client.get_transport()
Expand All @@ -911,7 +890,8 @@ def _login(self, username, password, allow_agent=False, look_for_keys=False, pro
self.client.connect(self.config.host, self.config.port, username,
password, look_for_keys=look_for_keys,
allow_agent=allow_agent,
timeout=float(self.config.timeout), sock=sock_tunnel)
timeout=float(self.config.timeout), sock=sock_tunnel,
banner_timeout=BANNER_TIMEOUT)
transport = self.client.get_transport()
transport.set_keepalive(keep_alive_interval)
except paramiko.AuthenticationException:
Expand Down Expand Up @@ -958,7 +938,7 @@ def _login_with_public_key(self, username, key_file, password, allow_agent, look
allow_agent=allow_agent,
look_for_keys=look_for_keys,
timeout=float(self.config.timeout),
sock=sock_tunnel)
sock=sock_tunnel, banner_timeout=BANNER_TIMEOUT)
transport = self.client.get_transport()
transport.set_keepalive(keep_alive_interval)
except paramiko.AuthenticationException:
Expand All @@ -981,7 +961,7 @@ def get_banner_without_login(host, port=22):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(str(host), int(port), username="bad-username")
client.connect(str(host), int(port), username="bad-username", banner_timeout=BANNER_TIMEOUT)
except paramiko.AuthenticationException:
return client.get_transport().get_banner()
except Exception:
Expand Down
2 changes: 0 additions & 2 deletions src/SSHLibrary/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function

import re

from .logger import logger
Expand Down
Loading