当前位置: 首页>>代码示例>>Python>>正文


Python ParallelSSHClient.get_stdout方法代码示例

本文整理汇总了Python中pssh.ParallelSSHClient.get_stdout方法的典型用法代码示例。如果您正苦于以下问题:Python ParallelSSHClient.get_stdout方法的具体用法?Python ParallelSSHClient.get_stdout怎么用?Python ParallelSSHClient.get_stdout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pssh.ParallelSSHClient的用法示例。


在下文中一共展示了ParallelSSHClient.get_stdout方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_pssh_client_exec_command_get_buffers

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import get_stdout [as 别名]
 def test_pssh_client_exec_command_get_buffers(self):
     server = start_server({ self.fake_cmd : self.fake_resp }, self.listen_socket)
     client = ParallelSSHClient(['127.0.0.1'], port=self.listen_port,
                                pkey=self.user_key)
     cmd = client.exec_command(self.fake_cmd)[0]
     output = client.get_stdout(cmd, return_buffers=True)
     expected_exit_code = 0
     expected_stdout = [self.fake_resp]
     expected_stderr = []
     exit_code = output['127.0.0.1']['exit_code']
     stdout = list(output['127.0.0.1']['stdout'])
     stderr = list(output['127.0.0.1']['stderr'])
     self.assertEqual(expected_exit_code, exit_code,
                      msg = "Got unexpected exit code - %s, expected %s" %
                      (exit_code,
                       expected_exit_code,))
     self.assertEqual(expected_stdout, stdout,
                      msg = "Got unexpected stdout - %s, expected %s" % 
                      (stdout,
                       expected_stdout,))
     self.assertEqual(expected_stderr, stderr,
                      msg = "Got unexpected stderr - %s, expected %s" % 
                      (stderr,
                       expected_stderr,))
     del client
     server.join()
开发者ID:oceanhliu,项目名称:parallel-ssh,代码行数:28,代码来源:test_pssh_client.py

示例2: test_parallel

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import get_stdout [as 别名]
def test_parallel():
    """Perform ls and copy file with ParallelSSHClient on localhost"""
    client = ParallelSSHClient(['localhost'])
    cmds = client.exec_command('ls -ltrh')
    output = [client.get_stdout(cmd, return_buffers=True) for cmd in cmds]
    print output
    cmds = client.copy_file('../test', 'test_dir/test')
    client.pool.join()
开发者ID:oceanhliu,项目名称:parallel-ssh,代码行数:10,代码来源:pssh_local.py

示例3: test_pssh_client_exec_command

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import get_stdout [as 别名]
 def test_pssh_client_exec_command(self):
     client = ParallelSSHClient([self.host], port=self.listen_port,
                                pkey=self.user_key)
     cmd = client.exec_command(self.fake_cmd)[0]
     output = client.get_stdout(cmd)
     expected = {self.host : {'exit_code' : 0}}
     self.assertEqual(expected, output,
                      msg="Got unexpected command output - %s" % (output,))
     self.assertTrue(output[self.host]['exit_code'] == 0)
开发者ID:solarfly73,项目名称:parallel-ssh,代码行数:11,代码来源:test_pssh_client.py

示例4: test_pssh_client_exec_command

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import get_stdout [as 别名]
 def test_pssh_client_exec_command(self):
     server = start_server({ self.fake_cmd : self.fake_resp }, self.listen_socket)
     client = ParallelSSHClient(['127.0.0.1'], port=self.listen_port,
                                pkey=self.user_key)
     cmd = client.exec_command(self.fake_cmd)[0]
     output = client.get_stdout(cmd)
     expected = {'127.0.0.1' : {'exit_code' : 0}}
     self.assertEqual(expected, output,
                      msg = "Got unexpected command output - %s" % (output,))
     del client
     server.join()
开发者ID:oceanhliu,项目名称:parallel-ssh,代码行数:13,代码来源:test_pssh_client.py

示例5: test_pssh_client_long_running_command

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import get_stdout [as 别名]
 def test_pssh_client_long_running_command(self):
     expected_lines = 5
     client = ParallelSSHClient([self.host], port=self.listen_port, pkey=self.user_key)
     cmd = client.exec_command(self.long_cmd(expected_lines))[0]
     output = client.get_stdout(cmd, return_buffers=True)
     self.assertTrue(self.host in output, msg="Got no output for command")
     stdout = list(output[self.host]["stdout"])
     self.assertTrue(
         len(stdout) == expected_lines, msg="Expected %s lines of response, got %s" % (expected_lines, len(stdout))
     )
     del client
开发者ID:hokadiri,项目名称:parallel-ssh,代码行数:13,代码来源:test_pssh_client.py

示例6: test_pssh_client_exec_command_password

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import get_stdout [as 别名]
 def test_pssh_client_exec_command_password(self):
     """Test password authentication. Embedded server accepts any password
     even empty string"""
     client = ParallelSSHClient([self.host], port=self.listen_port, password="")
     cmd = client.exec_command(self.fake_cmd)[0]
     output = client.get_stdout(cmd)
     self.assertTrue(self.host in output, msg="No output for host")
     self.assertTrue(
         output[self.host]["exit_code"] == 0, msg="Expected exit code 0, got %s" % (output[self.host]["exit_code"],)
     )
     del client
开发者ID:hokadiri,项目名称:parallel-ssh,代码行数:13,代码来源:test_pssh_client.py

示例7: test_pssh_client_exec_command_password

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import get_stdout [as 别名]
 def test_pssh_client_exec_command_password(self):
     """Test password authentication. Fake server accepts any password
     even empty string"""
     client = ParallelSSHClient([self.host], port=self.listen_port,
                                password='')
     cmd = client.exec_command(self.fake_cmd)[0]
     output = client.get_stdout(cmd)
     expected = {self.host : {'exit_code' : 0}}
     self.assertEqual(expected, output,
                      msg="Got unexpected command output - %s" % (output,))
     del client
开发者ID:solarfly73,项目名称:parallel-ssh,代码行数:13,代码来源:test_pssh_client.py

示例8: test_pssh_client_exec_command_password

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import get_stdout [as 别名]
 def test_pssh_client_exec_command_password(self):
     """Test password authentication. Fake server accepts any password
     even empty string"""
     server = start_server({ self.fake_cmd : self.fake_resp }, self.listen_socket)
     client = ParallelSSHClient(['127.0.0.1'], port=self.listen_port,
                                password='')
     cmd = client.exec_command(self.fake_cmd)[0]
     output = client.get_stdout(cmd)
     expected = {'127.0.0.1' : {'exit_code' : 0}}
     self.assertEqual(expected, output,
                      msg = "Got unexpected command output - %s" % (output,))
     del client
     server.join()
开发者ID:oceanhliu,项目名称:parallel-ssh,代码行数:15,代码来源:test_pssh_client.py

示例9: test_pssh_client_long_running_command

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import get_stdout [as 别名]
 def test_pssh_client_long_running_command(self):
     expected_lines = 5
     server = start_server({ self.long_running_cmd :
                             self.long_running_response(expected_lines) },
                           self.listen_socket)
     client = ParallelSSHClient(['127.0.0.1'], port=self.listen_port,
                                pkey=self.user_key)
     cmd = client.exec_command(self.long_running_cmd)[0]
     output = client.get_stdout(cmd)
     self.assertTrue('127.0.0.1' in output, msg="Got no output for command")
     stdout = list(output['127.0.0.1']['stdout'])
     self.assertTrue(len(stdout) == expected_lines, msg="Expected %s lines of response, got %s" %
                     (expected_lines, len(stdout)))
     del client
     server.kill()
开发者ID:oceanhliu,项目名称:parallel-ssh,代码行数:17,代码来源:test_pssh_client.py

示例10: test_pssh_client_exec_command_get_buffers

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import get_stdout [as 别名]
 def test_pssh_client_exec_command_get_buffers(self):
     client = ParallelSSHClient([self.host], port=self.listen_port, pkey=self.user_key, agent=self.agent)
     cmd = client.exec_command(self.fake_cmd)[0]
     output = client.get_stdout(cmd, return_buffers=True)
     expected_exit_code = 0
     expected_stdout = [self.fake_resp]
     expected_stderr = []
     exit_code = output[self.host]["exit_code"]
     stdout = list(output[self.host]["stdout"])
     stderr = list(output[self.host]["stderr"])
     self.assertEqual(
         expected_exit_code,
         exit_code,
         msg="Got unexpected exit code - %s, expected %s" % (exit_code, expected_exit_code),
     )
     self.assertEqual(
         expected_stdout, stdout, msg="Got unexpected stdout - %s, expected %s" % (stdout, expected_stdout)
     )
     self.assertEqual(
         expected_stderr, stderr, msg="Got unexpected stderr - %s, expected %s" % (stderr, expected_stderr)
     )
开发者ID:hokadiri,项目名称:parallel-ssh,代码行数:23,代码来源:test_pssh_client.py

示例11: ParallelSSHClientTest

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import get_stdout [as 别名]
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)
        self.client = ParallelSSHClient([self.host], port=self.listen_port,
                                        pkey=self.user_key,
                                        agent=self.agent)
    
    def tearDown(self):
        del self.server
        del self.listen_socket
        del self.client
            
    def test_pssh_client_exec_command(self):
        cmd = self.client.exec_command(self.fake_cmd)[0]
        output = self.client.get_stdout(cmd)
        self.assertTrue(self.host in output,
                        msg="No output for host")
        self.assertTrue(output[self.host]['exit_code'] == 0)

    def test_pssh_client_no_stdout_non_zero_exit_code_immediate_exit(self):
        output = self.client.run_command('exit 1')
        expected_exit_code = 1
        exit_code = output[self.host]['exit_code']
        self.assertEqual(expected_exit_code, exit_code,
                         msg="Got unexpected exit code - %s, expected %s" %
                         (exit_code,
                          expected_exit_code,))

    def test_pssh_client_exec_command_get_buffers(self):
        client = ParallelSSHClient([self.host], port=self.listen_port,
                                   pkey=self.user_key,
                                   agent=self.agent)
        cmd = client.exec_command(self.fake_cmd)[0]
        output = client.get_stdout(cmd, return_buffers=True)
        expected_exit_code = 0
        expected_stdout = [self.fake_resp]
        expected_stderr = []
        exit_code = output[self.host]['exit_code']
        stdout = list(output[self.host]['stdout'])
        stderr = list(output[self.host]['stderr'])
        self.assertEqual(expected_exit_code, exit_code,
                         msg="Got unexpected exit code - %s, expected %s" %
                         (exit_code,
                          expected_exit_code,))
        self.assertEqual(expected_stdout, stdout,
                         msg="Got unexpected stdout - %s, expected %s" % 
                         (stdout,
                          expected_stdout,))
        self.assertEqual(expected_stderr, stderr,
                         msg="Got unexpected stderr - %s, expected %s" % 
                         (stderr,
                          expected_stderr,))

    def test_pssh_client_run_command_get_output(self):
        client = ParallelSSHClient([self.host], port=self.listen_port,
                                   pkey=self.user_key,
                                   agent=self.agent)
        output = client.run_command(self.fake_cmd)
        expected_exit_code = 0
        expected_stdout = [self.fake_resp]
        expected_stderr = []
        exit_code = output[self.host]['exit_code']
        stdout = list(output[self.host]['stdout'])
        stderr = list(output[self.host]['stderr'])
        self.assertEqual(expected_exit_code, exit_code,
                         msg="Got unexpected exit code - %s, expected %s" %
                         (exit_code,
                          expected_exit_code,))
        self.assertEqual(expected_stdout, stdout,
                         msg="Got unexpected stdout - %s, expected %s" %
                         (stdout,
                          expected_stdout,))
        self.assertEqual(expected_stderr, stderr,
                         msg="Got unexpected stderr - %s, expected %s" %
                         (stderr,
                          expected_stderr,))

    def test_pssh_client_run_command_get_output_explicit(self):
        client = ParallelSSHClient([self.host], port=self.listen_port,
                                   pkey=self.user_key)
        out = client.run_command(self.fake_cmd)
        cmds = [cmd for host in out for cmd in [out[host]['cmd']]]
        output = {}
        for cmd in cmds:
            client.get_output(cmd, output)
        expected_exit_code = 0
        expected_stdout = [self.fake_resp]
        expected_stderr = []
        stdout = list(output[self.host]['stdout'])
        stderr = list(output[self.host]['stderr'])
#.........这里部分代码省略.........
开发者ID:bentsi,项目名称:parallel-ssh,代码行数:103,代码来源:test_pssh_client.py


注:本文中的pssh.ParallelSSHClient.get_stdout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。