]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
qa: refactor reading debug file code
authorPatrick Donnelly <pdonnell@redhat.com>
Tue, 29 Jun 2021 02:21:44 +0000 (19:21 -0700)
committerPatrick Donnelly <pdonnell@redhat.com>
Wed, 30 Jun 2021 03:13:41 +0000 (20:13 -0700)
No need to invoke Python to read a file!

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
qa/tasks/cephfs/kernel_mount.py

index 9f725a8faa0f3b4106eda905914467dbc939f7d9..95e3b401bb87ef49ddca2a570bb133023d8aba49 100644 (file)
@@ -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