Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix py3 string issue in jail connection plugin (take 2) #28374

Merged
merged 2 commits into from
Sep 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 4 additions & 13 deletions lib/ansible/plugins/connection/jail.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

from ansible.errors import AnsibleError
from ansible.module_utils.six.moves import shlex_quote
from ansible.module_utils._text import to_bytes
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.plugins.connection import ConnectionBase, BUFSIZE

try:
Expand Down Expand Up @@ -94,16 +94,7 @@ def list_jails(self):

stdout, stderr = p.communicate()

return stdout.split()

def get_jail_path(self):
p = subprocess.Popen([self.jls_cmd, '-j', to_bytes(self.jail), '-q', 'path'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)

stdout, stderr = p.communicate()
# remove \n
return stdout[:-1]
return to_text(stdout, errors='surrogate_or_strict').split()

def _connect(self):
''' connect to the jail; nothing to do here '''
Expand Down Expand Up @@ -179,7 +170,7 @@ def put_file(self, in_path, out_path):
traceback.print_exc()
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
if p.returncode != 0:
raise AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, stdout, stderr))
raise AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, to_native(stdout), to_native(stderr)))
except IOError:
raise AnsibleError("file or module does not exist at: %s" % in_path)

Expand All @@ -205,7 +196,7 @@ def fetch_file(self, in_path, out_path):
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
stdout, stderr = p.communicate()
if p.returncode != 0:
raise AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, stdout, stderr))
raise AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, to_native(stdout), to_native(stderr)))

def close(self):
''' terminate the connection; nothing to do here '''
Expand Down