Skip to content

Commit

Permalink
feat: New parser for /usr/bin/od -An -t d /dev/cpu_dma_latency (#3353)
Browse files Browse the repository at this point in the history
* 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
crackcodecamp authored Mar 17, 2022
1 parent 3c98505 commit fe6ecf4
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/shared_parsers_catalog/od_cpu_dma_latency.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: insights.parsers.od_cpu_dma_latency
:members:
:show-inheritance:
36 changes: 36 additions & 0 deletions insights/parsers/od_cpu_dma_latency.py
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.')
27 changes: 27 additions & 0 deletions insights/parsers/tests/test_od_cpu_dma_latency.py
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))
1 change: 1 addition & 0 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ class Specs(SpecSet):
oc_get_service = RegistryPoint()
oc_get_configmap = RegistryPoint()
octavia_conf = RegistryPoint(filterable=True)
od_cpu_dma_latency = RegistryPoint()
odbc_ini = RegistryPoint(filterable=True)
odbcinst_ini = RegistryPoint()
open_vm_tools_stat_raw_text_session = RegistryPoint()
Expand Down
1 change: 1 addition & 0 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ def md5chk_file_list(broker):
nvme_core_io_timeout = simple_file("/sys/module/nvme_core/parameters/io_timeout")
oc_get_clusterrole_with_config = simple_command("/usr/bin/oc get clusterrole --config /etc/origin/master/admin.kubeconfig")
oc_get_clusterrolebinding_with_config = simple_command("/usr/bin/oc get clusterrolebinding --config /etc/origin/master/admin.kubeconfig")
od_cpu_dma_latency = simple_command("/usr/bin/od -An -t d /dev/cpu_dma_latency")
odbc_ini = simple_file("/etc/odbc.ini")
odbcinst_ini = simple_file("/etc/odbcinst.ini")
open_vm_tools_stat_raw_text_session = simple_command("/usr/bin/vmware-toolbox-cmd stat raw text session")
Expand Down
1 change: 1 addition & 0 deletions insights/specs/insights_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class InsightsArchiveSpecs(Specs):
numeric_user_group_name = simple_file("insights_commands/grep_-c_digit_.etc.passwd_.etc.group")
oc_get_clusterrole_with_config = simple_file("insights_commands/oc_get_clusterrole_--config_.etc.origin.master.admin.kubeconfig")
oc_get_clusterrolebinding_with_config = simple_file("insights_commands/oc_get_clusterrolebinding_--config_.etc.origin.master.admin.kubeconfig")
od_cpu_dma_latency = simple_file("insights_commands/od_-An_-t_d_.dev.cpu_dma_latency")
open_vm_tools_stat_raw_text_session = simple_file("insights_commands/vmware-toolbox-cmd_stat_raw_text_session")
openvswitch_other_config = simple_file("insights_commands/ovs-vsctl_-t_5_get_Open_vSwitch_._other_config")
ovs_vsctl_list_bridge = simple_file("insights_commands/ovs-vsctl_list_bridge")
Expand Down

0 comments on commit fe6ecf4

Please sign in to comment.