From 28c6b226c75b3677eb6f489c11b72cceee1cdfe4 Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Wed, 5 Jul 2017 14:07:26 -0400 Subject: [PATCH] ansible-connection Python3 fix (#26441) * Fix a number of unicode <-> bytes mismatches * Return socket_path as text, not bytes * Docstring run() --- bin/ansible-connection | 4 ++-- lib/ansible/plugins/connection/persistent.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/ansible-connection b/bin/ansible-connection index 1f46a9e1167..8e9114817c4 100755 --- a/bin/ansible-connection +++ b/bin/ansible-connection @@ -40,7 +40,7 @@ import datetime import errno from ansible import constants as C -from ansible.module_utils._text import to_bytes, to_native +from ansible.module_utils._text import to_bytes, to_native, to_text from ansible.module_utils.six import PY3 from ansible.module_utils.six.moves import cPickle from ansible.module_utils.connection import send_data, recv_data @@ -141,7 +141,7 @@ class Server(): signal.signal(signal.SIGALRM, self.command_timeout) signal.alarm(self.play_context.timeout) - op = data.split(':')[0] + op = to_text(data.split(b':')[0]) display.display('socket operation is %s' % op, log_only=True) method = getattr(self, 'do_%s' % op, None) diff --git a/lib/ansible/plugins/connection/persistent.py b/lib/ansible/plugins/connection/persistent.py index 6b3adff3c17..9b0df90cbbf 100644 --- a/lib/ansible/plugins/connection/persistent.py +++ b/lib/ansible/plugins/connection/persistent.py @@ -23,7 +23,7 @@ import pty import subprocess import sys -from ansible.module_utils._text import to_bytes +from ansible.module_utils._text import to_bytes, to_text from ansible.module_utils.six.moves import cPickle from ansible.plugins.connection import ConnectionBase @@ -84,5 +84,11 @@ class Connection(ConnectionBase): self._connected = False def run(self): + """Returns the path of the persistent connection socket. + + Attempts to ensure (within playcontext.timeout seconds) that the + socket path exists. If the path exists (or the timeout has expired), + returns the socket path. + """ rc, out, err = self._do_it('RUN:') - return out + return to_text(out, errors='surrogate_or_strict')