URL: https://github.com/freeipa/freeipa/pull/1271
Author: stlaz
 Title: #1271: [Backport][ipa-4-6] Py3: fix fetching of tar files
Action: opened

PR body:
"""
This PR was opened automatically because PR #1256 was pushed to master and 
backport to ipa-4-6 is required.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1271/head:pr1271
git checkout pr1271
From 0eb7aa5ee4c22522a9cd7d7c83996d7240f6ece5 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Wed, 8 Nov 2017 13:43:43 +0100
Subject: [PATCH] Py3: fix fetching of tar files

pytest_multihost does not support binary stdout stream yet,
https://pagure.io/python-pytest-multihost/issue/7 . Write logs to
temporary file and use host.get_file_content() to fetch them.

https://pagure.io/freeipa/issue/7131

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 ipatests/pytest_plugins/integration/__init__.py | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/ipatests/pytest_plugins/integration/__init__.py b/ipatests/pytest_plugins/integration/__init__.py
index 62b8e71ecf..bee669b0dd 100644
--- a/ipatests/pytest_plugins/integration/__init__.py
+++ b/ipatests/pytest_plugins/integration/__init__.py
@@ -131,23 +131,25 @@ def collect_logs(name, logs_dict, logfile_dir=None, beakerlib_plugin=None):
 
         for host, logs in logs_dict.items():
             logger.info('Collecting logs from: %s', host.hostname)
-
+            dirname = os.path.join(topdirname, host.hostname)
+            if not os.path.isdir(dirname):
+                os.makedirs(dirname)
+            tarname = os.path.join(dirname, 'logs.tar.xz')
+            # get temporary file name
+            cmd = host.run_command(['mktemp'])
+            tmpname = cmd.stdout_text.strip()
             # Tar up the logs on the remote server
             cmd = host.run_command(
-                ['tar', '-c',  '--ignore-failed-read', '-J', '-v'] + logs,
+                ['tar', 'cJvf', tmpname, '--ignore-failed-read'] + logs,
                 log_stdout=False, raiseonerr=False)
             if cmd.returncode:
                 logger.warning('Could not collect all requested logs')
-
+            # fetch tar file
+            with open(tarname, 'wb') as f:
+                f.write(host.get_file_contents(tmpname))
+            # delete from remote
+            host.run_command(['rm', '-f', tmpname])
             # Unpack on the local side
-            dirname = os.path.join(topdirname, host.hostname)
-            try:
-                os.makedirs(dirname)
-            except OSError:
-                pass
-            tarname = os.path.join(dirname, 'logs.tar.xz')
-            with open(tarname, 'w') as f:
-                f.write(cmd.stdout_text)
             ipautil.run(['tar', 'xJvf', 'logs.tar.xz'], cwd=dirname,
                         raiseonerr=False)
             os.unlink(tarname)
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to