Skip to content

Commit

Permalink
Have detect_os not depend on token count in releasename
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el committed Feb 12, 2024
1 parent 5a52c2e commit ea359b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/subscript/runrms/runrms.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,14 @@ def detect_os(self):
"""Detect operating system string in runtime, just use default if not found."""
if RHEL_ID.is_file():
with open(RHEL_ID, "r", encoding="utf-8") as buffer:
major = buffer.read().split(" ")[6].split(".")[0].replace("'", "")
self.osver = "x86_64_RH_" + str(major)
logger.debug("RHEL version found in %s", RHEL_ID)
tokens = buffer.read().split()
for t in tokens:
if "." in t:
major = t.split(".")[0]
self.osver = f"x86_64_RH_{major}"
logger.debug("RHEL version found in %s", RHEL_ID)
return
raise ValueError("Could not detect RHEL version")

def do_parse_args(self, args):
"""Parse command line args."""
Expand Down
3 changes: 2 additions & 1 deletion tests/test_runrms.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def test_runlogger(tmp_path):
("Red Hat Enterprise Linux Server release 6.0 (bar)", "x86_64_RH_6"),
("Red Hat Enterprise Linux Server release 7.2 (Maipo)", "x86_64_RH_7"),
("Red Hat Enterprise Linux Server release 8.2 (foo)", "x86_64_RH_8"),
pytest.param("foobar", None, marks=pytest.mark.xfail(raises=IndexError)),
("Red Hat Enterprise Linux release 8.9 (Ootpa)", "x86_64_RH_8"),
pytest.param("foobar", None, marks=pytest.mark.xfail(raises=ValueError)),
],
)
def test_detect_os(os_id, expected, tmp_path, mocker):
Expand Down

0 comments on commit ea359b9

Please sign in to comment.