Skip to content

Commit c8c6d71

Browse files
committed
Extend test_fetch_coredumps.py for zstd cases
Signed-off-by: Jose J Palacios-Perez <[email protected]>
1 parent bc1fcd8 commit c8c6d71

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

teuthology/task/tests/test_fetch_coredumps.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from teuthology.task.internal import fetch_binaries_for_coredumps
2+
from teuthology.task.internal import get_backtraces_from_coredumps
23
from unittest.mock import patch, Mock
34
import gzip
45
import os
@@ -19,6 +20,36 @@ def __init__(self, ret):
1920
def communicate(self, input=None):
2021
return [TestFetchCoreDumps.MockDecode(self.ret)]
2122

23+
class MockCompletedProcess(object):
24+
def __init__(self, ret):
25+
self.ret = ret
26+
27+
@property
28+
def stdout(self):
29+
return self.ret
30+
31+
class MockGdb(object):
32+
def __init__(self, ret):
33+
self.ret = ret
34+
35+
def run(self, *args, **kwargs):
36+
return TestFetchCoreDumps.MockCompletedProcess(self.ret)
37+
38+
class TestGetBacktracesFromCoreDumps(object):
39+
@patch('teuthology.task.internal.subprocess.run')
40+
def test_get_backtraces_from_coredumps(self, mock_run):
41+
mock_run.return_value = TestFetchCoreDumps.MockCompletedProcess(
42+
"Backtrace line 1\nBacktrace line 2\nBacktrace line 3\n"
43+
)
44+
backtraces = get_backtraces_from_coredumps(coredump_path="core_dump_path", dump_path="binary_path",
45+
dump_program="ceph_test_rados_api_io", dump="core_dump")
46+
expected_backtraces = [
47+
"Backtrace line 1",
48+
"Backtrace line 2",
49+
"Backtrace line 3"
50+
]
51+
assert backtraces == expected_backtraces
52+
2253
def setup_method(self):
2354
self.the_function = fetch_binaries_for_coredumps
2455
with gzip.open('file.gz', 'wb') as f:
@@ -44,6 +75,20 @@ def setup_method(self):
4475
" 19:56:56 2022, from Unix, original size modulo 2^32 11"
4576
)
4677

78+
# Centos 9 coredumps are zstd compressed:
79+
self.zstd_compressed_correct = self.MockPopen(
80+
"Zstandard compressed data"\
81+
"'correct.format.core', last modified: Wed Jun 29"\
82+
" 19:55:29 2022, from Unix, original size modulo 2^32 3167080"
83+
)
84+
85+
self.zstd_compressed_incorrect = self.MockPopen(
86+
"Zstandard compressed data"\
87+
"'incorrect.format.core', last modified: Wed Jun 29"\
88+
" 19:56:56 2022, from Unix, original size modulo 2^32 11"
89+
)
90+
91+
4792
# Core is not compressed and file is in the correct format
4893
@patch('teuthology.task.internal.subprocess.Popen')
4994
@patch('teuthology.task.internal.os')
@@ -112,5 +157,39 @@ def test_compressed_incorrect_format(self, m_os, m_subproc_popen):
112157
self.the_function(None, self.m_remote)
113158
assert self.m_remote.get_file.called == False
114159

160+
# Core is zstd-compressed and file is in the correct format
161+
@patch('teuthology.task.internal.subprocess.Popen')
162+
@patch('teuthology.task.internal.os')
163+
def test_zstd_compressed_correct_format(self, m_os, m_subproc_popen):
164+
m_subproc_popen.side_effect = [
165+
self.zstd_compressed_correct,
166+
self.uncompressed_correct
167+
]
168+
m_os.path.join.return_value = self.core_dump_path
169+
m_os.path.sep = self.core_dump_path
170+
m_os.path.isdir.return_value = True
171+
m_os.path.dirname.return_value = self.core_dump_path
172+
m_os.path.exists.return_value = True
173+
m_os.listdir.return_value = [self.core_dump_path]
174+
self.the_function(None, self.m_remote)
175+
assert self.m_remote.get_file.called
176+
177+
# Core is compressed and file is in the wrong format
178+
@patch('teuthology.task.internal.subprocess.Popen')
179+
@patch('teuthology.task.internal.os')
180+
def test_zstd_compressed_incorrect_format(self, m_os, m_subproc_popen):
181+
m_subproc_popen.side_effect = [
182+
self.zstd_compressed_incorrect,
183+
self.uncompressed_incorrect
184+
]
185+
m_os.path.join.return_value = self.core_dump_path
186+
m_os.path.sep = self.core_dump_path
187+
m_os.path.isdir.return_value = True
188+
m_os.path.dirname.return_value = self.core_dump_path
189+
m_os.path.exists.return_value = True
190+
m_os.listdir.return_value = [self.core_dump_path]
191+
self.the_function(None, self.m_remote)
192+
assert self.m_remote.get_file.called == False
193+
115194
def teardown(self):
116-
os.remove(self.core_dump_path)
195+
os.remove(self.core_dump_path)

0 commit comments

Comments
 (0)