Skip to content

Commit

Permalink
Feat: new spec "/usr/bin/iris list" and its parser (#3828)
Browse files Browse the repository at this point in the history
* Add parser iris_list

Signed-off-by: jiazhang <jiazhang@redhat.com>

* Update parser name

Signed-off-by: jiazhang <jiazhang@redhat.com>
(cherry picked from commit a003d6f)
  • Loading branch information
wushiqinlou authored and xiangce committed Jun 29, 2023
1 parent 1ea12a9 commit f3ac077
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/shared_parsers_catalog/iris.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: insights.parsers.iris
:members:
:show-inheritance:
55 changes: 55 additions & 0 deletions insights/parsers/iris.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
IrisList - Command ``/usr/bin/iris list``
=========================================
This parser reads the output of ``/usr/bin/iris list``.
"""

from insights.core import CommandParser
from insights.core.exceptions import SkipComponent
from insights.core.plugins import parser
from insights.specs import Specs


@parser(Specs.iris_list)
class IrisList(CommandParser, dict):
"""
Parse the output of the ``/usr/bin/iris list`` command.
Sample Input::
Configuration 'IRIS' (default)
directory: /intersystems
versionid: 2023.1.0.235.1com
datadir: /intersystems
conf file: iris.cpf (SuperServer port = 1972, WebServer = 52773)
status: running, since Tue Jun 27 01:55:25 2023
state: ok
product: InterSystems IRIS
Examples:
>>> iris_info['name']
'IRIS'
>>> iris_info['status']
'running, since Tue Jun 27 01:55:25 2023'
>>> iris_info.is_running
True
"""

def parse_content(self, content):
for line in content:
if not line.strip():
continue
if line.strip().startswith('Configuration'):
self['name'] = line.split()[1].strip('\'"')
elif ":" in line:
key, value = line.split(":", 1)
self[key.strip()] = value.strip()

if len(self) == 0:
raise SkipComponent("The result is empty")

@property
def is_running(self):
"""Return True when the iris instance is running, and False when it is down"""
return self.get('status', "").startswith('running')
1 change: 1 addition & 0 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class Specs(SpecSet):
iptables_permanent = RegistryPoint()
ipv4_neigh = RegistryPoint()
ipv6_neigh = RegistryPoint()
iris_list = RegistryPoint()
ironic_conf = RegistryPoint(filterable=True)
ironic_inspector_log = RegistryPoint(filterable=True)
iscsiadm_m_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 @@ -306,6 +306,7 @@ class DefaultSpecs(Specs):
iptables_permanent = simple_file("etc/sysconfig/iptables")
ipv4_neigh = simple_command("/sbin/ip -4 neighbor show nud all")
ipv6_neigh = simple_command("/sbin/ip -6 neighbor show nud all")
iris_list = simple_command("/usr/bin/iris list")
ironic_inspector_log = first_file(["/var/log/containers/ironic-inspector/ironic-inspector.log", "/var/log/ironic-inspector/ironic-inspector.log"])
iscsiadm_m_session = simple_command("/usr/sbin/iscsiadm -m session")
jbcs_httpd24_httpd_error_log = simple_file("/opt/rh/jbcs-httpd24/root/etc/httpd/logs/error_log")
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 @@ -109,6 +109,7 @@ class InsightsArchiveSpecs(Specs):
iptables = simple_file("insights_commands/iptables-save")
ipv4_neigh = simple_file("insights_commands/ip_-4_neighbor_show_nud_all")
ipv6_neigh = simple_file("insights_commands/ip_-6_neighbor_show_nud_all")
iris_list = simple_file("insights_commands/iris_list")
iscsiadm_m_session = simple_file("insights_commands/iscsiadm_-m_session")
journal_header = simple_file("insights_commands/journalctl_--no-pager_--header")
keystone_crontab = first_file(["insights_commands/crontab_-l_-u_keystone", "var/spool/cron/keystone"])
Expand Down
61 changes: 61 additions & 0 deletions insights/tests/parsers/test_iris.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import doctest
import pytest

from insights.core.exceptions import SkipComponent
from insights.parsers import iris
from insights.tests import context_wrap


IRIS_RUNNING = """
Configuration 'IRIS' (default)
directory: /intersystems
versionid: 2023.1.0.235.1com
datadir: /intersystems
conf file: iris.cpf (SuperServer port = 1972, WebServer = 52773)
status: running, since Tue Jun 27 01:55:25 2023
state: ok
product: InterSystems IRIS
""".strip()

IRIS_DOWN = """
Configuration 'IRIS' (default)
directory: /intersystems
versionid: 2023.1.0.235.1com
datadir: /intersystems
conf file: iris.cpf (SuperServer port = 1972, WebServer = 52773)
status: down, last used Tue Jun 27 01:50:36 2023
product: InterSystems IRIS
""".strip()

IRIS_NO_CONTENT = """"""


def test_iris_list():
iris_running = iris.IrisList(context_wrap(IRIS_RUNNING))
assert iris_running['name'] == "IRIS"
assert iris_running['status'] == "running, since Tue Jun 27 01:55:25 2023"
assert 'state' in iris_running
assert iris_running.is_running

iris_down = iris.IrisList(context_wrap(IRIS_DOWN))
assert iris_down['name'] == "IRIS"
assert iris_down['status'] == "down, last used Tue Jun 27 01:50:36 2023"
assert 'state' not in iris_down
assert not iris_down.is_running


def test_fail():
with pytest.raises(SkipComponent) as e:
iris.IrisList(context_wrap(IRIS_NO_CONTENT))
assert "The result is empty" in str(e)


def test_doc_examples():
env = {
'iris_info': iris.IrisList(
context_wrap(IRIS_RUNNING)),
}
failed, total = doctest.testmod(iris, globs=env)
assert failed == 0

0 comments on commit f3ac077

Please sign in to comment.