-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New parser for /usr/bin/od -An -t d /dev/cpu_dma_latency (#3353)
* New parser for /usr/bin/hexdump -C /dev/cpu_dma_latency command Signed-off-by: Akshay Ghodake <[email protected]> * Updated command from hexdump to od Signed-off-by: Akshay Ghodake <[email protected]>
- Loading branch information
1 parent
3c98505
commit fe6ecf4
Showing
6 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.. automodule:: insights.parsers.od_cpu_dma_latency | ||
:members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
OdCpuDmaLatency - command ``/usr/bin/od -An -t d /dev/cpu_dma_latency`` | ||
======================================================================= | ||
This module provides the class ``OdCpuDmaLatency`` which processes | ||
``/usr/bin/od -An -t d /dev/cpu_dma_latency`` command output. | ||
""" | ||
from insights import parser, CommandParser | ||
from insights.specs import Specs | ||
from insights.parsers import SkipException | ||
|
||
|
||
@parser(Specs.od_cpu_dma_latency) | ||
class OdCpuDmaLatency(CommandParser): | ||
""" | ||
Class for parsing the output of `/usr/bin/od -An -t d /dev/cpu_dma_latency` command. | ||
Typical output of is:: | ||
2000000000 | ||
Attributes: | ||
force_latency(int): A integer containing the value of force_latency. | ||
Examples: | ||
>>> type(cpu_dma_latency) | ||
<class 'insights.parsers.od_cpu_dma_latency.OdCpuDmaLatency'> | ||
>>> cpu_dma_latency.force_latency | ||
2000000000 | ||
""" | ||
|
||
def parse_content(self, content): | ||
if content and content[0].isdigit(): | ||
self.force_latency = int(content[0]) | ||
else: | ||
raise SkipException('Nothing to parse.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import doctest | ||
import pytest | ||
from insights.parsers import od_cpu_dma_latency | ||
from insights.parsers.od_cpu_dma_latency import OdCpuDmaLatency | ||
from insights.tests import context_wrap | ||
from insights.parsers import SkipException | ||
|
||
|
||
CONTENT_OD_CPU_DMA_LATENCY = """ | ||
2000000000 | ||
""" | ||
|
||
CONTENT_OD_CPU_DMA_LATENCY_EMPTY = "" | ||
|
||
|
||
def test_doc_examples(): | ||
env = {'cpu_dma_latency': OdCpuDmaLatency(context_wrap(CONTENT_OD_CPU_DMA_LATENCY))} | ||
failed, total = doctest.testmod(od_cpu_dma_latency, globs=env) | ||
assert failed == 0 | ||
|
||
|
||
def test_OdCpuDmaLatency(): | ||
d = OdCpuDmaLatency(context_wrap(CONTENT_OD_CPU_DMA_LATENCY)) | ||
assert d.force_latency == 2000000000 | ||
|
||
with pytest.raises(SkipException): | ||
OdCpuDmaLatency(context_wrap(CONTENT_OD_CPU_DMA_LATENCY_EMPTY)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters