From: Patrick Donnelly Date: Tue, 29 Jun 2021 02:21:44 +0000 (-0700) Subject: qa: refactor reading debug file code X-Git-Tag: v17.1.0~1481^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=891c2773e9067b0d40d222f3f69635211809efaa;p=ceph-ci.git qa: refactor reading debug file code No need to invoke Python to read a file! Signed-off-by: Patrick Donnelly --- diff --git a/qa/tasks/cephfs/kernel_mount.py b/qa/tasks/cephfs/kernel_mount.py index 9f725a8faa0..95e3b401bb8 100644 --- a/qa/tasks/cephfs/kernel_mount.py +++ b/qa/tasks/cephfs/kernel_mount.py @@ -1,5 +1,6 @@ import json import logging +import os import re from io import StringIO @@ -188,21 +189,15 @@ class KernelMount(CephFSMount): """ Read the debug file "filename", return None if the file doesn't exist. """ - debug_dir = self._find_debug_dir() - pyscript = dedent(""" - import os - - print(open(os.path.join("{debug_dir}", "{filename}")).read()) - """).format(debug_dir=debug_dir, filename=filename) + path = os.path.join(self._find_debug_dir(), filename) + stdout = StringIO() stderr = StringIO() try: - output = self.client_remote.sh([ - 'sudo', 'python3', '-c', pyscript - ], stderr=stderr, timeout=(5*60)) - - return output + self.run_shell_payload(f"sudo dd if={path}", timeout=(5*60), + stdout=stdout, stderr=stderr) + return stdout.getvalue() except CommandFailedError: if 'no such file or directory' in stderr.getvalue().lower(): return None