From dba9bd0b15f9a0156b83bcd0d17ae35322f9f6ec Mon Sep 17 00:00:00 2001 From: Dennis Dmitriev Date: Thu, 14 Jun 2018 18:36:52 +0300 Subject: [PATCH] Allow to disable printing expected runtime errors in SSHAuth When users on a node are not prepared yet, it is expected to get wrong authorization exception like this: ssh_client.py:147 -- Connection using stored authentication info failed! Traceback (most recent call last): ... BadAuthenticationType: ('Bad authentication type', [u'publickey']) (allowed_types=[u'publickey']) - new parameter to SSHClient 'verbose' allows to disable printing such errors during waiting for ssh access. Change-Id: I665d5dca3c064e5445863870bfb97d12cf2a4905 --- devops/helpers/ssh_client.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/devops/helpers/ssh_client.py b/devops/helpers/ssh_client.py index 1f37b0ee..40f49601 100644 --- a/devops/helpers/ssh_client.py +++ b/devops/helpers/ssh_client.py @@ -243,7 +243,7 @@ class _MemorizedSSH(type): cls, host, port=22, username=None, password=None, private_keys=None, - auth=None + auth=None, verbose=True ): """Main memorize method: check for cached instance and return it @@ -280,7 +280,7 @@ class _MemorizedSSH(type): _MemorizedSSH, cls).__call__( host=host, port=port, username=username, password=password, private_keys=private_keys, - auth=auth) + auth=auth, verbose=verbose) @classmethod def record(mcs, ssh): @@ -323,7 +323,7 @@ class _MemorizedSSH(type): class SSHClient(six.with_metaclass(_MemorizedSSH, object)): __slots__ = [ '__hostname', '__port', '__auth', '__ssh', '__sftp', 'sudo_mode', - '__lock' + '__lock', '__verbose' ] class __get_sudo(object): @@ -367,7 +367,7 @@ class SSHClient(six.with_metaclass(_MemorizedSSH, object)): self, host, port=22, username=None, password=None, private_keys=None, - auth=None + auth=None, verbose=True ): """SSHClient helper @@ -377,6 +377,7 @@ class SSHClient(six.with_metaclass(_MemorizedSSH, object)): :type password: str :type private_keys: list :type auth: SSHAuth + :type verbose: bool, show additional error/warning messages """ self.__lock = threading.RLock() @@ -389,6 +390,7 @@ class SSHClient(six.with_metaclass(_MemorizedSSH, object)): self.__sftp = None self.__auth = auth if auth is None else auth.copy() + self.__verbose = verbose if auth is None: msg = ( @@ -501,7 +503,7 @@ class SSHClient(six.with_metaclass(_MemorizedSSH, object)): self.auth.connect( client=self.__ssh, hostname=self.hostname, port=self.port, - log=True) + log=self.__verbose) def __connect_sftp(self): """SFTP connection opener"""