From 60acfd1e87a4d48a1a0957950ae1219c88e588cc Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 17 Oct 2016 15:58:23 -0700 Subject: [PATCH] Fix ansible-pull on python3 On python3, we can't write bytes directly to sys.stdout. --- lib/ansible/utils/cmd_functions.py | 14 +++++++++++--- .../shippable/python3-test-target-blacklist.txt | 3 --- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/ansible/utils/cmd_functions.py b/lib/ansible/utils/cmd_functions.py index b3a77e4c2c3..80937e41488 100644 --- a/lib/ansible/utils/cmd_functions.py +++ b/lib/ansible/utils/cmd_functions.py @@ -24,7 +24,7 @@ import shlex import subprocess import select -from ansible.compat.six import PY2 +from ansible.compat.six import PY2, PY3 from ansible.module_utils._text import to_bytes def run_cmd(cmd, live=False, readsize=10): @@ -51,7 +51,11 @@ def run_cmd(cmd, live=False, readsize=10): if p.stdout in rfd: dat = os.read(p.stdout.fileno(), readsize) if live: - sys.stdout.write(dat) + # On python3, stdout has a codec to go from text type to bytes + if PY3: + sys.stdout.buffer.write(dat) + else: + sys.stdout.write(dat) stdout += dat if dat == b'': rpipes.remove(p.stdout) @@ -59,7 +63,11 @@ def run_cmd(cmd, live=False, readsize=10): dat = os.read(p.stderr.fileno(), readsize) stderr += dat if live: - sys.stdout.write(dat) + # On python3, stdout has a codec to go from text type to bytes + if PY3: + sys.stdout.buffer.write(dat) + else: + sys.stdout.write(dat) if dat == b'': rpipes.remove(p.stderr) # only break out if we've emptied the pipes, or there is nothing to diff --git a/test/utils/shippable/python3-test-target-blacklist.txt b/test/utils/shippable/python3-test-target-blacklist.txt index 2c22b39ac99..e69de29bb2d 100644 --- a/test/utils/shippable/python3-test-target-blacklist.txt +++ b/test/utils/shippable/python3-test-target-blacklist.txt @@ -1,3 +0,0 @@ -s/ pull_run / / -s/ pull_no_127 / / -s/ pull_limit_inventory / /