本文整理汇总了Python中pssh.ParallelSSHClient.join方法的典型用法代码示例。如果您正苦于以下问题:Python ParallelSSHClient.join方法的具体用法?Python ParallelSSHClient.join怎么用?Python ParallelSSHClient.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pssh.ParallelSSHClient
的用法示例。
在下文中一共展示了ParallelSSHClient.join方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pssh_client_hosts_list_part_failure
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import join [as 别名]
def test_pssh_client_hosts_list_part_failure(self):
"""Test getting output for remainder of host list in the case where one
host in the host list has a failure"""
server2_socket = make_socket('127.0.0.2', port=self.listen_port)
server2_port = server2_socket.getsockname()[1]
server2 = start_server(server2_socket, fail_auth=True)
hosts = [self.host, '127.0.0.2']
client = ParallelSSHClient(hosts,
port=self.listen_port,
pkey=self.user_key,
agent=self.agent)
output = client.run_command(self.fake_cmd,
stop_on_errors=False)
client.join(output)
self.assertTrue(hosts[0] in output,
msg="Successful host does not exist in output - output is %s" % (output,))
self.assertTrue(hosts[1] in output,
msg="Failed host does not exist in output - output is %s" % (output,))
self.assertTrue('exception' in output[hosts[1]],
msg="Failed host %s has no exception in output - %s" % (hosts[1], output,))
try:
raise output[hosts[1]]['exception']
except AuthenticationException:
pass
else:
raise Exception("Expected AuthenticationException, got %s instead" % (
output[hosts[1]]['exception'],))
del client
server2.kill()
示例2: test_host_config
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import join [as 别名]
def test_host_config(self):
"""Test per-host configuration functionality of ParallelSSHClient"""
hosts = ['127.0.0.%01d' % n for n in xrange(1,3)]
host_config = dict.fromkeys(hosts)
servers = []
user = 'overriden_user'
password = 'overriden_pass'
for host in hosts:
_socket = make_socket(host)
port = _socket.getsockname()[1]
host_config[host] = {}
host_config[host]['port'] = port
host_config[host]['user'] = user
host_config[host]['password'] = password
server = start_server(_socket, fail_auth=hosts.index(host))
servers.append((server, port))
pkey_data = load_private_key(PKEY_FILENAME)
host_config[hosts[0]]['private_key'] = pkey_data
client = ParallelSSHClient(hosts, host_config=host_config)
output = client.run_command(self.fake_cmd, stop_on_errors=False)
client.join(output)
for host in hosts:
self.assertTrue(host in output)
try:
raise output[hosts[1]]['exception']
except AuthenticationException, ex:
pass
示例3: test_pssh_client_long_running_command_exit_codes
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import join [as 别名]
def test_pssh_client_long_running_command_exit_codes(self):
expected_lines = 5
client = ParallelSSHClient([self.host], port=self.listen_port,
pkey=self.user_key)
output = client.run_command(self.long_cmd(expected_lines))
self.assertTrue(self.host in output, msg="Got no output for command")
self.assertTrue(not output[self.host]['exit_code'],
msg="Got exit code %s for still running cmd.." % (
output[self.host]['exit_code'],))
# Embedded server is also asynchronous and in the same thread
# as our client so need to sleep for duration of server connection
gevent.sleep(expected_lines)
client.join(output)
self.assertTrue(output[self.host]['exit_code'] == 0,
msg="Got non-zero exit code %s" % (
output[self.host]['exit_code'],))
del client
示例4: test_parallel
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import join [as 别名]
def test_parallel():
"""Perform ls and copy file with ParallelSSHClient on localhost.
Two identical hosts cause the same command to be executed
twice on the same host in two parallel connections.
In printed output there will be two identical lines per printed per
line of `ls -ltrh` output as output is printed by host_logger as it
becomes available and commands are executed in parallel
Host output key is de-duplicated so that output for the two
commands run on the same host(s) is not lost
"""
client = ParallelSSHClient(['localhost', 'localhost'])
output = client.run_command('ls -ltrh')
client.join(output)
pprint(output)
cmds = client.copy_file('../test', 'test_dir/test')
client.pool.join()
示例5: ParallelSSHClient
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import join [as 别名]
from pssh import ParallelSSHClient
import datetime
output = []
host = 'localhost'
hosts = [host]
client = ParallelSSHClient(hosts)
# Run 10 five second sleeps
cmds = ['sleep 5' for _ in xrange(10)]
start = datetime.datetime.now()
for cmd in cmds:
output.append(client.run_command(cmd, stop_on_errors=False))
end = datetime.datetime.now()
print("Started %s commands on %s host(s) in %s" % (
len(cmds), len(hosts), end-start,))
start = datetime.datetime.now()
for _output in output:
client.join(_output)
end = datetime.datetime.now()
print("All commands finished in %s" % (end-start,))
示例6: ParallelSSHClientTest
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import join [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
self.client.join(output)
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 = []
stdout = list(output[self.host]['stdout'])
stderr = list(output[self.host]['stderr'])
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,))
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'])
#.........这里部分代码省略.........