-
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 spec "rhui-set-release" and parser (#3998)
* feat: New spec "rhui-set-release" and parser Signed-off-by: Huanhuan Li <[email protected]>
- Loading branch information
Showing
8 changed files
with
151 additions
and
9 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.rhui_release | ||
: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
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,57 @@ | ||
""" | ||
RHUI release commands | ||
===================== | ||
RHUISetRelease - command ``rhui_set_release`` | ||
--------------------------------------------- | ||
""" | ||
import os | ||
|
||
from insights.core import CommandParser | ||
from insights.core.exceptions import SkipComponent | ||
from insights.core.plugins import parser | ||
from insights.specs import Specs | ||
|
||
|
||
@parser(Specs.rhui_set_release) | ||
class RHUISetRelease(CommandParser): | ||
""" | ||
Class for parsing the output of `rhui_set_release` command. | ||
It will output the rhel minor release when a minor release is set, | ||
or emtpy when it isn't set. | ||
Typical output of the command is:: | ||
8.6 | ||
Attributes: | ||
set (str): the set release. | ||
major (int): the major version of the set release. | ||
minor (int): the minor version of the set release. | ||
Examples: | ||
>>> type(rhui_rel) | ||
<class 'insights.parsers.rhui_release.RHUISetRelease'> | ||
>>> rhui_rel.set | ||
'8.6' | ||
>>> rhui_rel.major | ||
8 | ||
>>> rhui_rel.minor | ||
6 | ||
""" | ||
|
||
def parse_content(self, content): | ||
self.set = self.major = self.minor = None | ||
if len(content) == 0: | ||
# Release not set | ||
return | ||
if len(content) == 1: | ||
rhel_version = content[0].strip() | ||
line_splits = rhel_version.split('.') | ||
if len(line_splits) == 2 and line_splits[0].isdigit() and line_splits[-1].isdigit(): | ||
self.set = rhel_version | ||
self.major = int(line_splits[0]) | ||
self.minor = int(line_splits[-1]) | ||
return | ||
raise SkipComponent("Unexpected content: {0}".format(os.linesep.join(content))) |
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
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 @@ | ||
import doctest | ||
import pytest | ||
|
||
from insights.core.exceptions import SkipComponent | ||
from insights.parsers import rhui_release | ||
from insights.parsers.rhui_release import RHUISetRelease | ||
from insights.tests import context_wrap | ||
|
||
INPUT_NORMAL_1 = """ | ||
8.6 | ||
""".strip() | ||
|
||
INPUT_NOT_SET = """""".strip() | ||
|
||
INPUT_NG_1 = """ | ||
XYC | ||
Release not set | ||
""".strip() | ||
|
||
INPUT_NG_2 = """ | ||
abc def | ||
""".strip() | ||
|
||
|
||
def test_rhui_release_ok(): | ||
ret = RHUISetRelease(context_wrap(INPUT_NORMAL_1)) | ||
assert ret.set == '8.6' | ||
assert ret.major == 8 | ||
assert ret.minor == 6 | ||
|
||
|
||
def test_rhui_release_not_set(): | ||
ret = RHUISetRelease(context_wrap(INPUT_NOT_SET)) | ||
assert ret.set is None | ||
assert ret.major is None | ||
assert ret.minor is None | ||
|
||
|
||
def test_rhui_release_show_ng(): | ||
with pytest.raises(SkipComponent) as e_info: | ||
RHUISetRelease(context_wrap(INPUT_NG_1)) | ||
assert "Unexpected content" in str(e_info.value) | ||
|
||
with pytest.raises(SkipComponent) as e_info: | ||
RHUISetRelease(context_wrap(INPUT_NG_2)) | ||
assert "Unexpected content" in str(e_info.value) | ||
|
||
|
||
def test_doc_examples(): | ||
env = { | ||
'rhui_rel': | ||
RHUISetRelease(context_wrap(INPUT_NORMAL_1)), | ||
} | ||
failed, _ = doctest.testmod(rhui_release, globs=env) | ||
assert failed == 0 |