From 891c2773e9067b0d40d222f3f69635211809efaa Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Mon, 28 Jun 2021 19:21:44 -0700 Subject: [PATCH] qa: refactor reading debug file code No need to invoke Python to read a file! Signed-off-by: Patrick Donnelly --- qa/tasks/cephfs/kernel_mount.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) 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 -- 2.39.5