python3 compatiblity

remove use of basestring
deal with configparser
This commit is contained in:
Brian Coca 2016-03-16 14:12:48 -07:00
parent 943e4d37f5
commit 5b11494437
5 changed files with 13 additions and 7 deletions

View file

@ -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)

View file

@ -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

View file

@ -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:

View file

@ -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'):

View file

@ -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,