From 2430b5268649ee5753064fdf38ba220b5797afe0 Mon Sep 17 00:00:00 2001 From: jiazhang Date: Wed, 18 Dec 2024 18:05:17 +0800 Subject: [PATCH 1/2] feat: Add is_rhel_ai into parser os_release Signed-off-by: jiazhang rh-pre-commit.version: 2.3.1 rh-pre-commit.check-secrets: ENABLED --- insights/parsers/os_release.py | 8 ++++++++ insights/tests/parsers/test_os_release.py | 2 ++ 2 files changed, 10 insertions(+) diff --git a/insights/parsers/os_release.py b/insights/parsers/os_release.py index 8f079e0ccc..e294578305 100644 --- a/insights/parsers/os_release.py +++ b/insights/parsers/os_release.py @@ -67,3 +67,11 @@ def data(self): Deprecated, it will be removed from 3.7.0 """ return self + + @property + def is_rhel_ai(self): + """ + Returns: + bool: True when the system is from RHEL AI image. + """ + return True if self.get("VARIANT", None) == "RHEL AI" and self.get("VARIANT_ID", None) == "rhel_ai" else False diff --git a/insights/tests/parsers/test_os_release.py b/insights/tests/parsers/test_os_release.py index a378f8c152..ee791d68a8 100644 --- a/insights/tests/parsers/test_os_release.py +++ b/insights/tests/parsers/test_os_release.py @@ -94,6 +94,7 @@ def test_rhel(): rls = OsRelease(context_wrap(REHL_OS_RELEASE)) assert rls.get("VARIANT_ID") is None assert rls.get("VERSION") == "7.2 (Maipo)" + assert rls.is_rhel_ai is False def test_rhevh(): @@ -115,6 +116,7 @@ def test_rhel_ai(): assert rls.get("VARIANT_ID") == "rhel_ai" assert rls.get("VARIANT") == "RHEL AI" assert rls.get("BUILD_ID") == "v1.1.3" + assert rls.is_rhel_ai is True def test_empty(): From 3127212122a61df50eadb2b886902f2a1a03e4a0 Mon Sep 17 00:00:00 2001 From: jiazhang Date: Thu, 19 Dec 2024 10:05:27 +0800 Subject: [PATCH 2/2] Update condition Signed-off-by: jiazhang rh-pre-commit.version: 2.3.1 rh-pre-commit.check-secrets: ENABLED --- insights/parsers/os_release.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/insights/parsers/os_release.py b/insights/parsers/os_release.py index e294578305..12b746fe76 100644 --- a/insights/parsers/os_release.py +++ b/insights/parsers/os_release.py @@ -74,4 +74,4 @@ def is_rhel_ai(self): Returns: bool: True when the system is from RHEL AI image. """ - return True if self.get("VARIANT", None) == "RHEL AI" and self.get("VARIANT_ID", None) == "rhel_ai" else False + return self.get("VARIANT", None) == "RHEL AI" and self.get("VARIANT_ID", None) == "rhel_ai"