Skip to content

Commit d052081

Browse files
committed
updates
1 parent fa94d8c commit d052081

File tree

4 files changed

+56
-25
lines changed

4 files changed

+56
-25
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
26+
27+
from nodescraper.models import CollectorArgs
28+
29+
30+
class DmesgCollectorArgs(CollectorArgs):
31+
collect_logs: bool = False

nodescraper/plugins/inband/dmesg/dmesg_collector.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
#
2525
###############################################################################
2626
import re
27+
from typing import Optional
2728

2829
from nodescraper.base import InBandDataCollector
2930
from nodescraper.connection.inband import FileArtifact
3031
from nodescraper.enums import EventCategory, EventPriority, OSFamily
3132
from nodescraper.models import TaskResult
3233

34+
from .collector_args import DmesgCollectorArgs
3335
from .dmesgdata import DmesgData
3436

3537

@@ -54,7 +56,7 @@ def _nice_dmesg_name(self, path: str) -> str:
5456
"""Map path to filename."""
5557
base = path.rstrip("/").rsplit("/", 1)[-1]
5658
if base == "dmesg":
57-
return "dmesg.log"
59+
return "dmesg_log.log"
5860
m = re.fullmatch(r"dmesg\.(\d+)\.gz", base)
5961
if m:
6062
return f"dmesg.{m.group(1)}.gz.log"
@@ -81,7 +83,7 @@ def _collect_dmesg_rotations(self) -> int:
8183
qp = self._shell_quote(p)
8284
if p.endswith(".gz"):
8385
cmd = f"gzip -dc {qp} 2>/dev/null || zcat {qp} 2>/dev/null"
84-
res = self._run_sut_cmd(cmd, sudo=True)
86+
res = self._run_sut_cmd(cmd, sudo=True, log_artifact=False)
8587
if res.exit_code == 0 and res.stdout is not None:
8688
fname = self._nice_dmesg_name(p)
8789
self.logger.info("Collected dmesg log: %s", fname)
@@ -95,7 +97,7 @@ def _collect_dmesg_rotations(self) -> int:
9597
)
9698
else:
9799
cmd = f"cat {qp}"
98-
res = self._run_sut_cmd(cmd, sudo=True)
100+
res = self._run_sut_cmd(cmd, sudo=True, log_artifact=False)
99101
if res.exit_code == 0 and res.stdout is not None:
100102
fname = self._nice_dmesg_name(p)
101103
self.logger.info("Collected dmesg log: %s", fname)
@@ -125,8 +127,6 @@ def _collect_dmesg_rotations(self) -> int:
125127
priority=EventPriority.WARNING,
126128
)
127129

128-
return collected_logs
129-
130130
def _get_dmesg_content(self) -> str:
131131
"""run dmesg command on system and return output
132132
@@ -148,15 +148,20 @@ def _get_dmesg_content(self) -> str:
148148

149149
def collect_data(
150150
self,
151-
args=None,
151+
args: Optional[DmesgCollectorArgs] = None,
152152
) -> tuple[TaskResult, DmesgData | None]:
153153
"""Collect dmesg data from the system
154154
155155
Returns:
156156
tuple[TaskResult, DmesgData | None]: tuple containing the result of the task and the dmesg data if available
157157
"""
158+
159+
if args is None:
160+
args = DmesgCollectorArgs()
161+
158162
dmesg_content = self._get_dmesg_content()
159-
_ = self._collect_dmesg_rotations()
163+
if args.collect_logs:
164+
self._collect_dmesg_rotations()
160165

161166
if dmesg_content:
162167
dmesg_data = DmesgData(dmesg_content=dmesg_content)

nodescraper/plugins/inband/dmesg/dmesg_plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,21 @@
2626
from nodescraper.base import InBandDataPlugin
2727

2828
from .analyzer_args import DmesgAnalyzerArgs
29+
from .collector_args import DmesgCollectorArgs
2930
from .dmesg_analyzer import DmesgAnalyzer
3031
from .dmesg_collector import DmesgCollector
3132
from .dmesgdata import DmesgData
3233

3334

34-
class DmesgPlugin(InBandDataPlugin[DmesgData, None, DmesgAnalyzerArgs]):
35+
class DmesgPlugin(InBandDataPlugin[DmesgData, DmesgCollectorArgs, DmesgAnalyzerArgs]):
3536
"""Plugin for collection and analysis of dmesg data"""
3637

3738
DATA_MODEL = DmesgData
3839

3940
COLLECTOR = DmesgCollector
4041

4142
ANALYZER = DmesgAnalyzer
43+
44+
ANALYZER_ARGS = DmesgAnalyzerArgs
45+
46+
COLLECTOR_ARGS = DmesgCollectorArgs

test/unit/plugin/test_dmesg_collector.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def test_bad_exit_code(conn_mock, system_info):
117117

118118
res, _ = collector.collect_data()
119119
assert res.status == ExecutionStatus.ERROR
120-
assert len(res.events) == 2
120+
assert len(res.events) == 1
121121
assert res.events[0].description == "Error reading dmesg"
122122

123123

@@ -177,7 +177,7 @@ def test_collect_rotations_good_path(monkeypatch, system_info, conn_mock):
177177
ls_out = (
178178
"\n".join(
179179
[
180-
"/var/log/dmesg",
180+
"/var/log/dmesg_log",
181181
"/var/log/dmesg.1",
182182
"/var/log/dmesg.2.gz",
183183
"/var/log/dmesg.10.gz",
@@ -192,7 +192,7 @@ def run_map(cmd, **kwargs):
192192
if cmd.startswith("cat '"):
193193
if "/var/log/dmesg.1'" in cmd:
194194
return DummyRes(command=cmd, stdout="dmesg.1 content\n", exit_code=0)
195-
if "/var/log/dmesg'" in cmd:
195+
if "/var/log/dmesg_log'" in cmd:
196196
return DummyRes(command=cmd, stdout="dmesg content\n", exit_code=0)
197197
if "gzip -dc" in cmd and "/var/log/dmesg.2.gz" in cmd:
198198
return DummyRes(command=cmd, stdout="gz2 content\n", exit_code=0)
@@ -202,13 +202,10 @@ def run_map(cmd, **kwargs):
202202

203203
c = get_collector(monkeypatch, run_map, system_info, conn_mock)
204204

205-
collected = c._collect_dmesg_rotations()
205+
c._collect_dmesg_rotations()
206206

207207
names = {a.filename for a in c.result.artifacts}
208-
assert names == {"dmesg.log", "dmesg.1.log", "dmesg.2.gz.log", "dmesg.10.gz.log"}
209-
210-
assert isinstance(collected, list)
211-
assert len(collected) == 4
208+
assert names == {"dmesg_log.log", "dmesg.1.log", "dmesg.2.gz.log", "dmesg.10.gz.log"}
212209

213210
descs = [e["description"] for e in c._events]
214211
assert "Collected dmesg rotated files" in descs
@@ -222,9 +219,8 @@ def run_map(cmd, **kwargs):
222219

223220
c = get_collector(monkeypatch, run_map, system_info, conn_mock)
224221

225-
collected = c._collect_dmesg_rotations()
222+
c._collect_dmesg_rotations()
226223

227-
assert collected == 0
228224
assert c.result.artifacts == []
229225

230226
events = c._events
@@ -247,10 +243,8 @@ def run_map(cmd, **kwargs):
247243

248244
c = get_collector(monkeypatch, run_map, system_info, conn_mock)
249245

250-
collected = c._collect_dmesg_rotations()
246+
c._collect_dmesg_rotations()
251247

252-
assert isinstance(collected, list)
253-
assert len(collected) == 0
254248
assert c.result.artifacts == []
255249

256250
fail_events = [
@@ -277,7 +271,3 @@ def run_map(cmd, **kwargs):
277271

278272
assert isinstance(data, DmesgData)
279273
assert data.dmesg_content == "DMESG OUTPUT\n"
280-
281-
assert len(c.result.artifacts) == 1
282-
assert c.result.artifacts[0].filename == "dmesg.log"
283-
assert c.result.message == "Dmesg data collected"

0 commit comments

Comments
 (0)