From: Patrick Donnelly Date: Tue, 29 Jun 2021 02:21:44 +0000 (-0700) Subject: qa: refactor reading debug file code X-Git-Tag: v16.2.6~151^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8fedfe8968ba6a2e4b6738f8fb40f8e967d6221f;p=ceph.git qa: refactor reading debug file code No need to invoke Python to read a file! Signed-off-by: Patrick Donnelly (cherry picked from commit 891c2773e9067b0d40d222f3f69635211809efaa) --- diff --git a/qa/tasks/cephfs/kernel_mount.py b/qa/tasks/cephfs/kernel_mount.py index 9845454199ad..9a7a50206ecc 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 @@ -203,21 +204,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