From 304874fb6aa3cd6c935be4e02e4fa41d52bae6a1 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 21 Aug 2020 12:56:36 +1000 Subject: [PATCH] tox: include command output in log/error There's a couple of places that call subprocess.check_output that might raise and exception (I'm seeing one finding the "--name"); catch the CalledProcessError and include it's output to give more info. Change-Id: I53cfb9c1b37bd4dbf9e5bf04fbab83d3cdad795d --- roles/tox/library/tox_install_sibling_packages.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/roles/tox/library/tox_install_sibling_packages.py b/roles/tox/library/tox_install_sibling_packages.py index 50f7b25fc..408f4e336 100644 --- a/roles/tox/library/tox_install_sibling_packages.py +++ b/roles/tox/library/tox_install_sibling_packages.py @@ -96,7 +96,8 @@ def get_sibling_python_packages(projects, tox_python): # package name is. package_name = subprocess.check_output( [os.path.abspath(tox_python), 'setup.py', '--name'], - cwd=os.path.abspath(root)).decode('utf-8') + cwd=os.path.abspath(root), + stderr=subprocess.STDOUT).decode('utf-8') if package_name: package_name = package_name.strip() packages[package_name] = root @@ -111,7 +112,8 @@ def get_installed_packages(tox_python): # We use the output of pip freeze here as that is pip's stable public # interface. frozen_pkgs = subprocess.check_output( - [tox_python, '-m', 'pip', '-qqq', 'freeze'] + [tox_python, '-m', 'pip', '-qqq', 'freeze'], + stderr=subprocess.STDOUT ).decode('utf-8') # Matches strings of the form: # 1. '==' @@ -330,6 +332,13 @@ def main(): projects, package_name, constraints) + except subprocess.CalledProcessError as e: + tb = traceback.format_exc() + log.append(str(e)) + log.append(tb) + log.append("Output:") + log.extend(e.output.decode('utf-8').split('\n')) + module.fail_json(msg=str(e), log="\n".join(log)) except Exception as e: tb = traceback.format_exc() log.append(str(e))