From 7fdf4c35c2ecaea0c3801ae97ce49cdaaffc7265 Mon Sep 17 00:00:00 2001 From: "nmordech@redhat.com" Date: Sun, 31 Mar 2024 11:49:03 +0000 Subject: [PATCH] scrapy: searching backtrace with gzip Scrapy script that trying to find backtrace in gzip log files can hit TypeError: a bytes-like object is required, not 'str' error and fail to collect results. the gzip file need to be decoded. Fixes: https://tracker.ceph.com/issues/64402 Signed-off-by: Nitzan Mordechai --- teuthology/scrape.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/teuthology/scrape.py b/teuthology/scrape.py index e84122e62..e490c50a9 100644 --- a/teuthology/scrape.py +++ b/teuthology/scrape.py @@ -3,7 +3,7 @@ import difflib from errno import ENOENT -from gzip import GzipFile +import gzip import sys import os import yaml @@ -356,6 +356,8 @@ def _populate_backtrace(self): return for line in grep(tlog_path, "command crashed with signal"): + if not line: + continue log.debug("Found a crash indication: {0}".format(line)) # tasks.ceph.osd.1.plana82.stderr match = re.search(r"tasks.ceph.([^\.]+).([^\.]+).([^\.]+).stderr", line) @@ -382,7 +384,10 @@ def _populate_backtrace(self): )) continue - bt, ass = self._search_backtrace(GzipFile(gzipped_log_path)) + with gzip.open(gzipped_log_path, 'rb') as f: + # Read and decode the contents into strings + decoded_content = f.read().decode('utf-8') + bt, ass = self._search_backtrace(decoded_content) if ass and not self.assertion: self.assertion = ass if bt: