Skip to content

Commit 5df2bbe

Browse files
Merge pull request #52 from amd/feature/techsupport-fix
journal techsupport changes
2 parents 14dbe50 + 9267c21 commit 5df2bbe

File tree

3 files changed

+72
-7
lines changed

3 files changed

+72
-7
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 typing import Optional
28+
29+
from nodescraper.models import CollectorArgs
30+
31+
32+
class JournalCollectorArgs(CollectorArgs):
33+
boot: Optional[int] = None

nodescraper/plugins/inband/journal/journal_collector.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,50 @@
2525
###############################################################################
2626
from typing import Optional
2727

28+
from pydantic import ValidationError
29+
2830
from nodescraper.base import InBandDataCollector
2931
from nodescraper.enums import EventCategory, EventPriority, ExecutionStatus, OSFamily
3032
from nodescraper.models import TaskResult
33+
from nodescraper.utils import get_exception_details
3134

35+
from .collector_args import JournalCollectorArgs
3236
from .journaldata import JournalData
3337

3438

35-
class JournalCollector(InBandDataCollector[JournalData, None]):
39+
class JournalCollector(InBandDataCollector[JournalData, JournalCollectorArgs]):
3640
"""Read journal log via journalctl."""
3741

3842
SUPPORTED_OS_FAMILY = {OSFamily.LINUX}
3943
DATA_MODEL = JournalData
4044
CMD = "journalctl --no-pager --system --output=short-iso"
4145

42-
def _read_with_journalctl(self):
46+
def _read_with_journalctl(self, args: Optional[JournalCollectorArgs] = None):
4347
"""Read journal logs using journalctl
4448
4549
Returns:
4650
str|None: system journal read
4751
"""
48-
res = self._run_sut_cmd(self.CMD, sudo=True, log_artifact=False, strip=False)
52+
53+
cmd = "journalctl --no-pager --system --output=short-iso"
54+
try:
55+
# safe check for args.boot
56+
if args is not None and getattr(args, "boot", None):
57+
cmd = f"journalctl --no-pager -b {args.boot} --system --output=short-iso"
58+
59+
res = self._run_sut_cmd(cmd, sudo=True, log_artifact=False, strip=False)
60+
61+
except ValidationError as val_err:
62+
self._log_event(
63+
category=EventCategory.OS,
64+
description="Exception while running journalctl",
65+
data=get_exception_details(val_err),
66+
priority=EventPriority.ERROR,
67+
console_log=True,
68+
)
69+
self.result.message = "Could not read journalctl data"
70+
self.result.status = ExecutionStatus.ERROR
71+
return None
4972

5073
if res.exit_code != 0:
5174
self._log_event(
@@ -61,16 +84,22 @@ def _read_with_journalctl(self):
6184

6285
return res.stdout
6386

64-
def collect_data(self, args=None) -> tuple[TaskResult, Optional[JournalData]]:
87+
def collect_data(
88+
self,
89+
args: Optional[JournalCollectorArgs] = None,
90+
) -> tuple[TaskResult, Optional[JournalData]]:
6591
"""Collect journal logs
6692
6793
Args:
6894
args (_type_, optional): Collection args. Defaults to None.
6995
7096
Returns:
71-
tuple[TaskResult, Optional[JournalData, None]]: Tuple of results and data model or none.
97+
tuple[TaskResult, Optional[JournalData]]: Tuple of results and data model or none.
7298
"""
73-
journal_log = self._read_with_journalctl()
99+
if args is None:
100+
args = JournalCollectorArgs()
101+
102+
journal_log = self._read_with_journalctl(args)
74103
if journal_log:
75104
data = JournalData(journal_log=journal_log)
76105
self.result.message = self.result.message or "Journal data collected"

nodescraper/plugins/inband/journal/journal_plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525
###############################################################################
2626
from nodescraper.base import InBandDataPlugin
2727

28+
from .collector_args import JournalCollectorArgs
2829
from .journal_collector import JournalCollector
2930
from .journaldata import JournalData
3031

3132

32-
class JournalPlugin(InBandDataPlugin[JournalData, None, None]):
33+
class JournalPlugin(InBandDataPlugin[JournalData, JournalCollectorArgs, None]):
3334
"""Plugin for collection of journal data"""
3435

3536
DATA_MODEL = JournalData
3637

3738
COLLECTOR = JournalCollector
39+
40+
COLLECTOR_ARGS = JournalCollectorArgs

0 commit comments

Comments
 (0)