本文整理汇总了Python中pssh.ParallelSSHClient.exec_command方法的典型用法代码示例。如果您正苦于以下问题:Python ParallelSSHClient.exec_command方法的具体用法?Python ParallelSSHClient.exec_command怎么用?Python ParallelSSHClient.exec_command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pssh.ParallelSSHClient
的用法示例。
在下文中一共展示了ParallelSSHClient.exec_command方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pssh_client_exec_command_get_buffers
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [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()
示例2: test_parallel
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [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()
示例3: test_pssh_client_exec_command
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [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)
示例4: test_pssh_client_exec_command
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [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()
示例5: test_pssh_client_long_running_command
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [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
示例6: test_pssh_client_exec_command_password
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [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
示例7: test_pssh_client_exec_command_password
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [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
示例8: test_pssh_client_retries
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [as 别名]
def test_pssh_client_retries(self):
"""Test connection error retries"""
expected_num_tries = 2
with self.assertRaises(ConnectionErrorException) as cm:
client = ParallelSSHClient(['127.0.0.1'], port=self.listen_port,
pkey=self.user_key, num_retries=expected_num_tries)
cmd = client.exec_command('blah')[0]
cmd.get()
num_tries = cm.exception.args[-1:][0]
self.assertEqual(expected_num_tries, num_tries,
msg="Got unexpected number of retries %s - expected %s"
% (num_tries, expected_num_tries,))
示例9: test_pssh_client_exec_command_password
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [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()
示例10: test_pssh_client_auth_failure
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [as 别名]
def test_pssh_client_auth_failure(self):
server = start_server({ self.fake_cmd : self.fake_resp },
self.listen_socket, fail_auth=True)
client = ParallelSSHClient(['127.0.0.1'], port=self.listen_port,
pkey=self.user_key)
cmd = client.exec_command(self.fake_cmd)[0]
# Handle exception
try:
cmd.get()
raise Exception("Expected AuthenticationException, got none")
except AuthenticationException:
pass
del client
server.join()
示例11: test_pssh_client_auth_failure
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [as 别名]
def test_pssh_client_auth_failure(self):
listen_socket = make_socket(self.host)
listen_port = listen_socket.getsockname()[1]
server = start_server(listen_socket, fail_auth=True)
client = ParallelSSHClient([self.host], port=listen_port, pkey=self.user_key, agent=self.agent)
cmd = client.exec_command(self.fake_cmd)[0]
# Handle exception
try:
cmd.get()
raise Exception("Expected AuthenticationException, got none")
except AuthenticationException:
pass
del client
server.join()
示例12: test_pssh_client_long_running_command
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [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()
示例13: test_pssh_client_exec_command_get_buffers
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [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)
)
示例14: ParallelSSHClientTest
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import exec_command [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'])
#.........这里部分代码省略.........