Merge pull request #12853 from ansible/winrm-return-bytes

In v2, exec_command should return bytes and the caller will take responsibility for converting to unicode
pull/12855/head
Toshio Kuratomi 9 years ago
commit 42ce3de8d0

@ -47,7 +47,7 @@ from ansible.errors import AnsibleConnectionFailure, AnsibleFileNotFound
from ansible.plugins.connection import ConnectionBase from ansible.plugins.connection import ConnectionBase
from ansible.plugins import shell_loader from ansible.plugins import shell_loader
from ansible.utils.path import makedirs_safe from ansible.utils.path import makedirs_safe
from ansible.utils.unicode import to_bytes, to_unicode from ansible.utils.unicode import to_bytes, to_unicode, to_str
class Connection(ConnectionBase): class Connection(ConnectionBase):
'''WinRM connections over HTTP/HTTPS.''' '''WinRM connections over HTTP/HTTPS.'''
@ -200,8 +200,8 @@ class Connection(ConnectionBase):
except Exception as e: except Exception as e:
traceback.print_exc() traceback.print_exc()
raise AnsibleError("failed to exec cmd %s" % cmd) raise AnsibleError("failed to exec cmd %s" % cmd)
result.std_out = to_unicode(result.std_out) result.std_out = to_bytes(result.std_out)
result.std_err = to_unicode(result.std_err) result.std_err = to_bytes(result.std_err)
return (result.status_code, result.std_out, result.std_err) return (result.status_code, result.std_out, result.std_err)
def put_file(self, in_path, out_path): def put_file(self, in_path, out_path):
@ -239,7 +239,7 @@ class Connection(ConnectionBase):
cmd_parts = self._shell._encode_script(script, as_list=True) cmd_parts = self._shell._encode_script(script, as_list=True)
result = self._winrm_exec(cmd_parts[0], cmd_parts[1:]) result = self._winrm_exec(cmd_parts[0], cmd_parts[1:])
if result.status_code != 0: if result.status_code != 0:
raise IOError(to_unicode(result.std_err)) raise IOError(to_str(result.std_err))
except Exception: except Exception:
traceback.print_exc() traceback.print_exc()
raise AnsibleError('failed to transfer file to "%s"' % out_path) raise AnsibleError('failed to transfer file to "%s"' % out_path)
@ -281,7 +281,7 @@ class Connection(ConnectionBase):
cmd_parts = self._shell._encode_script(script, as_list=True) cmd_parts = self._shell._encode_script(script, as_list=True)
result = self._winrm_exec(cmd_parts[0], cmd_parts[1:]) result = self._winrm_exec(cmd_parts[0], cmd_parts[1:])
if result.status_code != 0: if result.status_code != 0:
raise IOError(to_unicode(result.std_err)) raise IOError(to_str(result.std_err))
if result.std_out.strip() == '[DIR]': if result.std_out.strip() == '[DIR]':
data = None data = None
else: else:

Loading…
Cancel
Save