logger as server_logger, paramiko_logger from embedded_server.fake_agent import FakeAgent import random import logging import gevent import threading import paramiko import os import warnings import shutil USER_KEY = paramiko.RSAKey.from_private_key_file( os.path.sep.join([os.path.dirname(__file__), 'test_client_private_key'])) server_logger.setLevel(logging.DEBUG) pssh_logger.setLevel(logging.DEBUG) logging.basicConfig() class ParallelSSHClientTest(unittest.TestCase): def setUp(self): self.fake_cmd = 'echo "me"' self.fake_resp = 'me' self.long_cmd = lambda lines: 'for (( i=0; i<%s; i+=1 )) do echo $i; sleep 1; done' % (lines,) self.user_key = USER_KEY self.host = '127.0.0.1' self.listen_socket = make_socket(self.host) self.listen_port = self.listen_socket.getsockname()[1] self.server = start_server(self.listen_socket) self.agent = FakeAgent() self.agent.add_key(USER_KEY)
import time from datetime import datetime from sys import version_info from gevent import joinall, spawn, socket, Greenlet from pssh.exceptions import UnknownHostException, \ AuthenticationException, ConnectionErrorException, SessionError, \ HostArgumentException, SFTPError, SFTPIOError, Timeout, SCPError, \ ProxyError, PKeyFileError from pssh import logger as pssh_logger from pssh.clients.ssh.parallel import ParallelSSHClient from .base_ssh_case import PKEY_FILENAME, PUB_FILE from ..embedded_server.openssh import OpenSSHServer pssh_logger.setLevel(logging.DEBUG) logging.basicConfig() class LibSSHParallelTest(unittest.TestCase): @classmethod def setUpClass(cls): _mask = int('0600') if version_info <= (2, ) else 0o600 os.chmod(PKEY_FILENAME, _mask) cls.host = '127.0.0.1' cls.port = 2422 cls.server = OpenSSHServer(listen_ip=cls.host, port=cls.port) cls.server.start_server() cls.cmd = 'echo me' cls.resp = u'me' cls.user_key = PKEY_FILENAME
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """Unittests for :mod:`pssh.output.HostOutput` class""" import unittest import logging from pssh import logger from pssh.output import HostOutput logger.setLevel(logging.DEBUG) logging.basicConfig() class TestHostOutput(unittest.TestCase): def setUp(self): self.output = HostOutput(None, None, None, None, None, None, True) def test_print(self): self.assertTrue(str(self.output)) def test_update(self): host, cmd, chan, stdout, stderr, \ stdin, exception = 'host', 'cmd', 'chan', 'stdout', \ 'stderr', 'stdin', Exception() self.output.update({