Skip to content

Commit

Permalink
Updated setup.py. Py3 compatibility changes for embedded server
Browse files Browse the repository at this point in the history
  • Loading branch information
pkittenis committed Feb 1, 2017
1 parent e7791a2 commit 7d3dd9f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion embedded_server/embedded_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def check_channel_exec_request(self, channel, cmd,
def check_channel_env_request(self, channel, name, value):
if not hasattr(channel, 'environment'):
channel.environment = {}
channel.environment.update({name: value})
channel.environment.update({name.decode('utf8'): value.decode('utf8')})
return True

def _read_response(self, channel, process):
Expand Down
2 changes: 1 addition & 1 deletion pssh/pssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def _exec_command(self, host, command, sudo=False, user=None,
shell=None, use_shell=True, use_pty=True,
environment=None):
"""Make SSHClient, run command on host"""
if not host in self.host_clients or not self.host_clients[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)
_user = user if user else _user
self.host_clients[host] = SSHClient(host, user=_user,
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Software Development :: Libraries :: Python Modules',
'Operating System :: POSIX :: Linux',
'Operating System :: POSIX :: BSD',
Expand Down
20 changes: 10 additions & 10 deletions tests/test_pssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_pssh_client_ssh_exception(self):
self.assertRaises(SSHException, client.run_command, self.fake_cmd)
del client
server.kill()

def test_pssh_client_timeout(self):
server_timeout=0.2
client_timeout=server_timeout-0.1
Expand Down Expand Up @@ -269,7 +269,7 @@ def test_pssh_client_long_running_command_exit_codes(self):
self.assertTrue(output[self.host]['exit_code'] == 0,
msg="Got non-zero exit code %s" % (
output[self.host]['exit_code'],))

def test_pssh_client_retries(self):
"""Test connection error retries"""
listen_port = self.make_random_port()
Expand All @@ -287,7 +287,7 @@ def test_pssh_client_retries(self):
"expected %s" % (num_tries, expected_num_tries,))
else:
raise Exception('No ConnectionErrorException')

def test_sftp_exceptions(self):
# Port with no server listening on it on separate ip
host = '127.0.0.3'
Expand All @@ -297,7 +297,7 @@ def test_sftp_exceptions(self):
client.pool.join()
for cmd in cmds:
self.assertRaises(ConnectionErrorException, cmd.get)

def test_pssh_copy_file(self):
"""Test parallel copy file"""
test_file_data = 'test'
Expand All @@ -319,7 +319,7 @@ def test_pssh_copy_file(self):
os.unlink(filepath)
shutil.rmtree(remote_test_dir)
del client

def test_pssh_client_directory(self):
"""Tests copying multiple directories with SSH client. Copy all the files from
local directory to server, then make sure they are all present."""
Expand Down Expand Up @@ -405,7 +405,7 @@ def test_pssh_client_copy_file_failure(self):
os.chmod(remote_test_path, mask)
for path in [local_test_path, remote_test_path]:
shutil.rmtree(path)

def test_pssh_copy_remote_file(self):
"""Test parallel copy file to local host"""
test_file_data = 'test'
Expand Down Expand Up @@ -737,7 +737,7 @@ def test_ssh_exception(self):
else:
raise Exception("Expected SSHException")
server.kill()

def test_multiple_single_quotes_in_cmd(self):
"""Test that we can run a command with multiple single quotes"""
output = self.client.run_command("echo 'me' 'and me'")
Expand All @@ -751,15 +751,15 @@ def test_multiple_single_quotes_in_cmd(self):
self.assertEqual(expected, stdout[0],
msg="Got unexpected output. Expected %s, got %s" % (
expected, stdout[0],))

def test_backtics_in_cmd(self):
"""Test running command with backtics in it"""
output = self.client.run_command("out=`ls` && echo $out")
self.client.join(output)
self.assertTrue(output[self.host]['exit_code'] == 0,
msg="Error executing cmd with backtics - error code %s" % (
output[self.host]['exit_code'],))

def test_multiple_shell_commands(self):
"""Test running multiple shell commands in one go"""
output = self.client.run_command("echo me; echo and; echo me")
Expand All @@ -771,7 +771,7 @@ def test_multiple_shell_commands(self):
self.assertEqual(expected, stdout,
msg="Got unexpected output. Expected %s, got %s" % (
expected, stdout,))

def test_escaped_quotes(self):
"""Test escaped quotes in shell variable are handled correctly"""
output = self.client.run_command('t="--flags=\\"this\\""; echo $t')
Expand Down

0 comments on commit 7d3dd9f

Please sign in to comment.