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

* Fix py3 string issue in jail connection plugin
This commit is contained in:
Pierre Guinoiseau 2017-09-10 06:52:42 +12:00 committed by Toshio Kuratomi
parent 625a23f155
commit 436b173b24

View file

@ -40,7 +40,7 @@ import traceback
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
from ansible.module_utils.six.moves import shlex_quote 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 from ansible.plugins.connection import ConnectionBase, BUFSIZE
try: try:
@ -94,16 +94,7 @@ class Connection(ConnectionBase):
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
return stdout.split() return to_text(stdout, errors='surrogate_or_strict').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]
def _connect(self): def _connect(self):
''' connect to the jail; nothing to do here ''' ''' connect to the jail; nothing to do here '''
@ -179,7 +170,7 @@ class Connection(ConnectionBase):
traceback.print_exc() traceback.print_exc()
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path)) raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
if p.returncode != 0: 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: except IOError:
raise AnsibleError("file or module does not exist at: %s" % in_path) raise AnsibleError("file or module does not exist at: %s" % in_path)
@ -205,7 +196,7 @@ class Connection(ConnectionBase):
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path)) raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
if p.returncode != 0: 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): def close(self):
''' terminate the connection; nothing to do here ''' ''' terminate the connection; nothing to do here '''