From 5b11494437e0bcb888f81552ce6fa5885a880c50 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 16 Mar 2016 14:12:48 -0700 Subject: [PATCH] python3 compatiblity remove use of basestring deal with configparser --- lib/ansible/executor/playbook_executor.py | 5 +++-- lib/ansible/executor/task_executor.py | 5 ++++- lib/ansible/executor/task_queue_manager.py | 3 ++- lib/ansible/plugins/callback/logentries.py | 5 +++-- lib/ansible/plugins/connection/local.py | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py index 31d62984508..5a1b76f9410 100644 --- a/lib/ansible/executor/playbook_executor.py +++ b/lib/ansible/executor/playbook_executor.py @@ -168,8 +168,9 @@ class PlaybookExecutor: # send the stats callback for this playbook if self._tqm is not None: if C.RETRY_FILES_ENABLED: - retries = list(set(self._tqm._failed_hosts.keys() + self._tqm._unreachable_hosts.keys())) - retries.sort() + retries = set(self._tqm._failed_hosts.keys()) + retries.update(self._tqm._unreachable_hosts.keys()) + retries = sorted(retries) if len(retries) > 0: if C.RETRY_FILES_SAVE_PATH: basedir = C.shell_expand(C.RETRY_FILES_SAVE_PATH) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index d25fb036f58..b198f225e4d 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -607,7 +607,8 @@ class TaskExecutor: try: cmd = subprocess.Popen(['ssh','-o','ControlPersist'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = cmd.communicate() - if "Bad configuration option" in err or "Usage:" in err: + err = to_unicode(err) + if u"Bad configuration option" in err or u"Usage:" in err: conn_type = "paramiko" except OSError: conn_type = "paramiko" @@ -645,7 +646,9 @@ class TaskExecutor: try: connection._connect() except AnsibleConnectionFailure: + display.debug('connection failed, fallback to accelerate') res = handler._execute_module(module_name='accelerate', module_args=accelerate_args, task_vars=variables, delete_remote_tmp=False) + display.debug(res) connection._connect() return connection diff --git a/lib/ansible/executor/task_queue_manager.py b/lib/ansible/executor/task_queue_manager.py index 601d27c58b5..a16ac755da5 100644 --- a/lib/ansible/executor/task_queue_manager.py +++ b/lib/ansible/executor/task_queue_manager.py @@ -34,6 +34,7 @@ from ansible.template import Templar from ansible.vars.hostvars import HostVars from ansible.plugins.callback import CallbackBase from ansible.utils.unicode import to_unicode +from ansible.compat.six import string_types try: from __main__ import display @@ -143,7 +144,7 @@ class TaskQueueManager: if isinstance(self._stdout_callback, CallbackBase): stdout_callback_loaded = True - elif isinstance(self._stdout_callback, basestring): + elif isinstance(self._stdout_callback, string_types): if self._stdout_callback not in callback_loader: raise AnsibleError("Invalid callback for stdout specified: %s" % self._stdout_callback) else: diff --git a/lib/ansible/plugins/callback/logentries.py b/lib/ansible/plugins/callback/logentries.py index 281ca044c5f..f5e80d3be76 100644 --- a/lib/ansible/plugins/callback/logentries.py +++ b/lib/ansible/plugins/callback/logentries.py @@ -60,8 +60,9 @@ import socket import random import time import codecs -import ConfigParser import uuid +from ansible.compat.six.moves import configparser + try: import certifi HAS_CERTIFI = True @@ -212,7 +213,7 @@ class CallbackModule(CallbackBase): 'Disabling the Logentries callback plugin.') config_path = os.path.abspath(os.path.dirname(__file__)) - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() try: config.readfp(open(os.path.join(config_path, 'logentries.ini'))) if config.has_option('logentries', 'api'): diff --git a/lib/ansible/plugins/connection/local.py b/lib/ansible/plugins/connection/local.py index 00ee3bc7071..737a31971e0 100644 --- a/lib/ansible/plugins/connection/local.py +++ b/lib/ansible/plugins/connection/local.py @@ -79,7 +79,7 @@ class Connection(ConnectionBase): p = subprocess.Popen( cmd, - shell=isinstance(cmd, basestring), + shell=isinstance(cmd, (text_type, binary_type)), executable=executable, #cwd=... stdin=subprocess.PIPE, stdout=subprocess.PIPE,