Skip to content

Commit

Permalink
Add Alpha to redhat release detection (#3431)
Browse files Browse the repository at this point in the history
* Add new check and attributed for Alpha releases
* Add test and documentation for new attribute

Signed-off-by: Bob Fahr <[email protected]>
  • Loading branch information
bfahr authored May 31, 2022
1 parent 3569c71 commit 6d9c45b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion insights/parsers/redhat_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RedhatRelease(Parser):
"""Parses the content of file ``/etc/redhat-release``
Attributes:
is_alpha(bool): True if this is an Alpha release
is_beta(bool): True if this is a Beta release
is_centos(bool): True if this release is CentOS
is_fedora(bool): True if this release is Fedora
Expand All @@ -49,8 +50,13 @@ class RedhatRelease(Parser):
def parse_content(self, content):
self.raw = content[0]
self.is_beta = False
self.is_alpha = False
product, _, version_name = [v.strip() for v in content[0].partition("release")]
if 'Beta' in version_name:
if 'Alpha' in version_name:
# Red Hat Enterprise Linux release 9 Alpha (Plow)
version_number, code_name = version_name.split('Alpha', 1)
self.is_alpha = True
elif 'Beta' in version_name:
# Red Hat Enterprise Linux release 8.5 Beta (Ootpa)
version_number, code_name = version_name.split('Beta', 1)
self.is_beta = True
Expand Down
18 changes: 18 additions & 0 deletions insights/tests/parsers/test_redhat_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
CentOS Linux release 7.6.1810 (Core)
""".strip()

REDHAT_RELEASE_ALPHA = """
Red Hat Enterprise Linux release 9.0 Alpha (Plow)
""".strip()


def test_rhe6():
release = RedhatRelease(context_wrap(REDHAT_RELEASE1))
Expand Down Expand Up @@ -131,6 +135,19 @@ def test_rhel8():
assert release.product == "Red Hat Enterprise Linux"


def test_rhel_alpha():
release = RedhatRelease(context_wrap(REDHAT_RELEASE_ALPHA))
assert release.raw == REDHAT_RELEASE_ALPHA
assert release.major == 9
assert release.minor == 0
assert release.version == "9.0"
assert release.is_rhel
assert release.is_alpha
assert not release.is_beta
assert release.parsed['code_name'] == 'Plow'
assert release.product == "Red Hat Enterprise Linux"


def test_rhel_beta():
release = RedhatRelease(context_wrap(REDHAT_RELEASE_BETA))
assert release.raw == REDHAT_RELEASE_BETA
Expand All @@ -139,6 +156,7 @@ def test_rhel_beta():
assert release.version == "8.5"
assert release.is_rhel
assert release.is_beta
assert not release.is_alpha
assert release.parsed['code_name'] == 'Ootpa'
assert release.product == "Red Hat Enterprise Linux Server"

Expand Down

0 comments on commit 6d9c45b

Please sign in to comment.