-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: new spec "/usr/bin/iris list" and its parser (#3828)
* 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
1 parent
1ea12a9
commit f3ac077
Showing
6 changed files
with
122 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.iris | ||
: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,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') |
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
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,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 |