From 16966588dcffa7176b5e6c6fe465aa26ba67d89c Mon Sep 17 00:00:00 2001 From: Dan <22e889d8@opayq.com> Date: Wed, 1 Feb 2017 17:36:21 +0000 Subject: [PATCH] Moving environment updates to feature branch --- pssh/pssh_client.py | 18 +++++------------- pssh/ssh_client.py | 7 ++----- tests/test_pssh_client.py | 9 --------- 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/pssh/pssh_client.py b/pssh/pssh_client.py index d580cf2f..3de0eeff 100644 --- a/pssh/pssh_client.py +++ b/pssh/pssh_client.py @@ -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. @@ -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 \ @@ -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( @@ -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: @@ -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) @@ -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. diff --git a/pssh/ssh_client.py b/pssh/ssh_client.py index 7d309aa6..44821017 100644 --- a/pssh/ssh_client.py +++ b/pssh/ssh_client.py @@ -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 @@ -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 ['\\', '"', '$', '`']: diff --git a/tests/test_pssh_client.py b/tests/test_pssh_client.py index 175436a0..7819ebf5 100644 --- a/tests/test_pssh_client.py +++ b/tests/test_pssh_client.py @@ -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()