]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
task/internal: open gzip file if core is compressed
authorKamoltat <ksirivad@redhat.com>
Tue, 1 Mar 2022 16:49:05 +0000 (16:49 +0000)
committerKamoltat Sirivadhna <ksirivad@redhat.com>
Wed, 20 Jul 2022 20:26:04 +0000 (20:26 +0000)
Addded a case where if core is compressed, then
we will try to open it as gzip and read the content
inside.

We also add try and except when we are parsing
through the content to prevent the program from
crashing.

Fixes: https://tracker.ceph.com/issues/53206
Signed-off-by: Kamoltat Sirivadhna <ksirivad@redhat.com>
teuthology/task/internal/__init__.py

index d85b3f212e0994d51c7001e959ca7c7f4478c141..041964d38c13fcae338724e2cb13b505aebab66f 100644 (file)
@@ -12,6 +12,7 @@ import shutil
 import time
 import yaml
 import subprocess
+import tempfile
 
 import humanfriendly
 
@@ -318,7 +319,28 @@ def fetch_binaries_for_coredumps(path, remote):
             # 1422917770.7450.core: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style, \
             # from 'radosgw --rgw-socket-path /home/ubuntu/cephtest/apache/tmp.client.0/fastcgi_soc'
             log.info(f' core looks like: {dump_out}')
-            dump_program = dump_out.split("from '")[1].split(' ')[0]
+
+            if 'gzip' in dump_out:
+                try:
+                    log.info("core is compressed, try accessing gzip file ...")
+                    with gzip.open(dump_path, 'rb') as f_in, \
+                         tempfile.NamedTemporaryFile(mode='w+b') as f_out:
+                         shutil.copyfileobj(f_in, f_out)
+                         dump_info = subprocess.Popen(['file', f_out.name],
+                                                        stdout=subprocess.PIPE)
+                         dump_out = dump_info.communicate()[0].decode()
+                         log.info(f' core looks like: {dump_out}')
+                except Exception as e:
+                    log.info('Something went wrong while opening the compressed file')
+                    log.error(e)
+                    continue
+            try:
+                dump_program = dump_out.split("from '")[1].split(' ')[0]
+                log.info(f' dump_program: {dump_program}')
+            except Exception as e:
+                log.info("core doesn't have the desired format, moving on ...")
+                log.error(e)
+                continue
 
             # Find path on remote server:
             remote_path = remote.sh(['which', dump_program]).rstrip()