Skip to content

Commit

Permalink
Moving environment updates to feature branch
Browse files Browse the repository at this point in the history
  • Loading branch information
pkittenis committed Feb 1, 2017
1 parent 495b777 commit 1696658
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
18 changes: 5 additions & 13 deletions pssh/pssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ def __init__(self, hosts,
self.channel_timeout = channel_timeout

def run_command(self, command, sudo=False, user=None, stop_on_errors=True,
shell=None, use_shell=True, use_pty=True, host_args=None,
environment=None):
shell=None, use_shell=True, use_pty=True, host_args=None):
"""Run command on all hosts in parallel, honoring self.pool_size,
and return output buffers.
Expand Down Expand Up @@ -384,10 +383,6 @@ def run_command(self, command, sudo=False, user=None, stop_on_errors=True,
host list - :py:class:`pssh.exceptions.HostArgumentException` is raised \
otherwise
:type host_args: tuple or list
:param environment: (Optional) Environment variables to be exposed to \
command to be run. This requires that ``AcceptEnv`` server setting \
is enabled - variables will silently not be set otherwise
:type environment: dict
:rtype: Dictionary with host as key and \
:py:class:`pssh.output.HostOutput` as value as per \
Expand Down Expand Up @@ -630,8 +625,7 @@ def run_command(self, command, sudo=False, user=None, stop_on_errors=True,
cmds = [self.pool.spawn(self._exec_command, host,
command % host_args[host_i],
sudo=sudo, user=user, shell=shell,
use_shell=use_shell, use_pty=use_pty,
environment=environment)
use_shell=use_shell, use_pty=use_pty)
for host_i, host in enumerate(self.hosts)]
except IndexError:
raise HostArgumentException(
Expand All @@ -641,8 +635,7 @@ def run_command(self, command, sudo=False, user=None, stop_on_errors=True,
cmds = [self.pool.spawn(
self._exec_command, host, command,
sudo=sudo, user=user, shell=shell,
use_shell=use_shell, use_pty=use_pty,
environment=environment)
use_shell=use_shell, use_pty=use_pty)
for host in self.hosts]
for cmd in cmds:
try:
Expand All @@ -660,8 +653,7 @@ def _get_host_config_values(self, host):
return _user, _port, _password, _pkey

def _exec_command(self, host, command, sudo=False, user=None,
shell=None, use_shell=True, use_pty=True,
environment=None):
shell=None, use_shell=True, use_pty=True):
"""Make SSHClient, run command on host"""
if host not in self.host_clients or self.host_clients[host] is None:
_user, _port, _password, _pkey = self._get_host_config_values(host)
Expand All @@ -682,7 +674,7 @@ def _exec_command(self, host, command, sudo=False, user=None,
channel_timeout=self.channel_timeout)
return self.host_clients[host].exec_command(
command, sudo=sudo, user=user, shell=shell,
use_shell=use_shell, use_pty=use_pty, environment=environment)
use_shell=use_shell, use_pty=use_pty)

def get_output(self, cmd, output):
"""Get output from command.
Expand Down
7 changes: 2 additions & 5 deletions pssh/ssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,13 @@ def _connect(self, client, host, port, sock=None, retries=1,

def exec_command(self, command, sudo=False, user=None,
shell=None,
use_shell=True, use_pty=True,
environment=None):
use_shell=True, use_pty=True):
"""Wrapper to :py:func:`paramiko.SSHClient.exec_command`
Opens a new SSH session with a new pty and runs command before yielding
the main gevent loop to allow other greenlets to execute.
:param command: Cxommand to execute
:param command: Command to execute
:type command: str
:param sudo: (Optional) Run with sudo. Defaults to False
:type sudo: bool
Expand Down Expand Up @@ -241,8 +240,6 @@ def exec_command(self, command, sudo=False, user=None,
channel.get_pty()
if self.channel_timeout:
channel.settimeout(self.channel_timeout)
if environment:
channel.update_environment(environment)
stdout, stderr, stdin = channel.makefile('rb'), \
channel.makefile_stderr('rb'), channel.makefile('wb')
for _char in ['\\', '"', '$', '`']:
Expand Down
9 changes: 0 additions & 9 deletions tests/test_pssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,14 +1014,5 @@ def test_run_command_no_shell(self):
self.assertTrue(len(stdout) > 0)
self.assertTrue(output[self.host].exit_code == 0)

def test_run_command_environment(self):
env = {'ENV_VARIABLE': 'env value'}
output = self.client.run_command('echo ${ENV_VARIABLE}',
environment=env)
self.client.join(output)
stdout = list(output[self.host].stdout)
expected = [env.values()[0]]
self.assertEqual(stdout, expected)

if __name__ == '__main__':
unittest.main()

0 comments on commit 1696658

Please sign in to comment.