From f66a572720ecc44f8b59718ae0f26a41f8c8b641 Mon Sep 17 00:00:00 2001 From: Andreas Eknes Lie Date: Wed, 21 Feb 2024 08:37:57 +0100 Subject: [PATCH 1/3] Add detect rhel version to testkomodo script --- ci/testkomodo.sh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ci/testkomodo.sh b/ci/testkomodo.sh index 80a92bb45..12b2ba45e 100644 --- a/ci/testkomodo.sh +++ b/ci/testkomodo.sh @@ -7,6 +7,28 @@ copy_test_files () { cp $CI_SOURCE_ROOT/pyproject.toml $CI_TEST_ROOT } +get_os_arch () { + uname_info=$(uname -a) + + rhel7=$(echo "$uname_info" | grep "el7") + rhel8=$(echo "$uname_info" | grep "el8") + + os_arch="undetermined" + + if [ "$rhel7" ]; then + os_arch="x86_64_RH_7" + elif [ "$rhel8" ]; then + os_arch="x86_64_RH_8" + else + echo "$os_arch" + exit 1 + fi + + echo "$os_arch" + exit 0 +} + start_tests () { - pytest -n auto --flow-simulator="/project/res/x86_64_RH_7/bin/flowdaily" --eclipse-simulator="runeclipse" + os_arch="$(get_os_arch)" + pytest -n auto --flow-simulator="/project/res/$os_arch/bin/flowdaily" --eclipse-simulator="runeclipse" } From 5859d687c1da108f0bf0053cdc03b1bbdf54184c Mon Sep 17 00:00:00 2001 From: Andreas Eknes Lie Date: Wed, 21 Feb 2024 08:54:58 +0100 Subject: [PATCH 2/3] Update documentation with rhel8 example --- docs/contributing.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/contributing.rst b/docs/contributing.rst index d7ab4fe28..2c2afe112 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -58,8 +58,11 @@ running tests that rely upon a black oil simulation. .. code-block:: console + # running on redhat 7 pytest -n auto --flow-simulator="/project/res/x86_64_RH_7/bin/flowdaily" --eclipse-simulator="runeclipse" + # running on redhat 8 + pytest -n auto --flow-simulator="/project/res/x86_64_RH_8/bin/flowdaily" --eclipse-simulator="runeclipse" Code style ---------- From c779d6fb74a79ad3752955ca51f2a635c0256a44 Mon Sep 17 00:00:00 2001 From: Andreas Eknes Lie Date: Thu, 22 Feb 2024 20:33:23 +0100 Subject: [PATCH 3/3] Extract detect_os function --- src/subscript/__init__.py | 16 ++++++++++++++++ src/subscript/runrms/runrms.py | 17 ++--------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/subscript/__init__.py b/src/subscript/__init__.py index 7ec9c3453..d0735d8e5 100644 --- a/src/subscript/__init__.py +++ b/src/subscript/__init__.py @@ -1,5 +1,6 @@ import logging import sys +from pathlib import Path try: from importlib import metadata @@ -9,6 +10,21 @@ pass +def detect_os(release_file: Path = Path("/etc/redhat-release")) -> str: + """Detect operating system string in runtime, just use default if not found.""" + default_os_version = "x86_64_RH_7" + + if release_file.is_file(): + with open(release_file, "r", encoding="utf-8") as buffer: + tokens = buffer.read().split() + for t in tokens: + if "." in t: + major = t.split(".")[0] + return f"x86_64_RH_{major}" + raise ValueError("Could not detect RHEL version") + return default_os_version + + def getLogger(module_name="subscript"): # pylint: disable=invalid-name """Provides a unified logger for subscript scripts. diff --git a/src/subscript/runrms/runrms.py b/src/subscript/runrms/runrms.py index 470c354b4..e0a26bc14 100644 --- a/src/subscript/runrms/runrms.py +++ b/src/subscript/runrms/runrms.py @@ -18,7 +18,7 @@ import yaml -from subscript import getLogger +from subscript import detect_os, getLogger logger = getLogger(__name__) @@ -288,7 +288,7 @@ def __init__(self): self.warn_empty_version = False self.aps_toolbox_path = None - self.detect_os() + self.osver = detect_os(RHEL_ID) self.oldpythonpath = "" if "PYTHONPATH" in os.environ: @@ -304,19 +304,6 @@ def __init__(self): _BColors.ENDC, ) - 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: - 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.""" if args is None: