I\'m desinging test cases in which I use paramiko for SSH connections. Test cases usually contain paramiko.exec_command()
calls which I have a wrapper for (call
My solution basically the same as yours, just organized differently:
def connection(self):
if not self.is_connected():
self._ssh = paramiko.SSHClient()
self._ssh.connect(self.server, self.port,
username = self.username, password = self.password)
return self._ssh
def is_connected(self):
transport = self._ssh.get_transport() if self._ssh else None
return transport and transport.is_active()
def do_something(self):
self.connection().exec_command('ls')