From 778a6b34a69d481bf5ee209696754ef4eac096cf Mon Sep 17 00:00:00 2001 From: Dalton Bohning Date: Tue, 16 Apr 2024 20:54:24 +0000 Subject: [PATCH] DAOS-15659 test: fix local ftest prefix Test-tag: pr Skip-unit-tests: true Skip-fault-injection-test: true PR #13565 accidentally broke how ftest determines the prefix from .build_vars.json because it is no longer installed. Eliminate the need for .build_vars.json in ftest entirely. Required-githooks: true Signed-off-by: Dalton Bohning --- src/tests/ftest/util/apricot/apricot/test.py | 24 +++----- src/tests/ftest/util/environment_utils.py | 58 ++++---------------- 2 files changed, 19 insertions(+), 63 deletions(-) diff --git a/src/tests/ftest/util/apricot/apricot/test.py b/src/tests/ftest/util/apricot/apricot/test.py index 641036f39171..3120f400b4e6 100644 --- a/src/tests/ftest/util/apricot/apricot/test.py +++ b/src/tests/ftest/util/apricot/apricot/test.py @@ -127,7 +127,6 @@ def __init__(self, *args, **kwargs): self._teardown_errors = [] self.basepath = None self.prefix = None - self.ofi_prefix = None self.cancel_file = os.path.join(os.sep, "scratch", "CI-skip-list-master") # List of methods to call during tearDown to cleanup after the steps @@ -150,22 +149,13 @@ def __init__(self, *args, **kwargs): def setUp(self): """Set up each test case.""" - # get paths from the build_vars generated by build - try: - with open('../../.build_vars.json') as build_vars: - build_paths = json.load(build_vars) - self.basepath = os.path.normpath(os.path.join(build_paths['PREFIX'], - '..') + os.path.sep) - self.prefix = build_paths['PREFIX'] - try: - self.ofi_prefix = build_paths['OFI_PREFIX'] - except KeyError: - self.ofi_prefix = os.sep + "usr" - except FileNotFoundError: - self.prefix = "/usr" - self.basepath = "/" - self.ofi_prefix = os.sep + "usr" - self.log.info("No build vars file, assuming RPM install") + # Assume PREFIX relative to this installed file + self.prefix = os.path.normpath( + os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "..", "..", "..", "..", "..", "..", "..")) + self.log.info("Assuming daos install prefix = %s", self.prefix) + self.basepath = os.path.normpath(os.path.join(self.prefix, '..')) + os.path.sep self.cancel_from_list() self.check_variant_skip() self.log.info("*** SETUP running on %s ***", str(detect())) diff --git a/src/tests/ftest/util/environment_utils.py b/src/tests/ftest/util/environment_utils.py index da08bd8c52bd..8bb393ab308d 100644 --- a/src/tests/ftest/util/environment_utils.py +++ b/src/tests/ftest/util/environment_utils.py @@ -18,61 +18,25 @@ class TestEnvironmentException(Exception): """Exception for launch.py execution.""" -def _get_build_environment(logger, build_vars_file): - """Obtain DAOS build environment variables from the .build_vars.json file. - - Args: - logger (Logger): logger for the messages produced by this method - build_vars_file (str): the full path to the DAOS build_vars.json file - - Raises: - TestEnvironmentException: if there is an error obtaining the DAOS build environment - - Returns: - str: The prefix of the DAOS install. - None: If the file is not present. - """ - logger.debug("Obtaining DAOS build environment from %s", build_vars_file) - try: - with open(build_vars_file, encoding="utf-8") as vars_file: - return json.load(vars_file)["PREFIX"] - - except FileNotFoundError: - return None - - except Exception as error: # pylint: disable=broad-except - raise TestEnvironmentException("Error obtaining build environment:", str(error)) from error - - -def _update_path(logger, build_vars_file): +def _update_path(daos_prefix): """Update the PATH environment variable for functional testing. Args: - logger (Logger): logger for the messages produced by this method - build_vars_file (str): the full path to the DAOS build_vars.json file + daos_prefix (str): daos install prefix - Raises: - TestEnvironmentException: if there is an error obtaining the DAOS build environment """ - base_dir = _get_build_environment(logger, build_vars_file) - - path = os.environ.get("PATH") - - parts = path.split(":") - - # If a custom prefix is used for the daos installation then prepend that to the path so that - # any binaries provided are picked up from there, else do not modify the path. - if base_dir: - bin_dir = os.path.join(base_dir, "bin") - sbin_dir = os.path.join(base_dir, "sbin") + parts = os.environ.get("PATH").split(":") + # Insert bin and sbin at the beginning of PATH if prefix is not /usr + if daos_prefix != os.path.join(os.sep, "usr"): + bin_dir = os.path.join(daos_prefix, "bin") + sbin_dir = os.path.join(daos_prefix, "sbin") parts.insert(0, bin_dir) parts.insert(0, sbin_dir) # /usr/sbin is not setup on non-root user for CI nodes. # SCM formatting tool mkfs.ext4 is located under /usr/sbin directory. usr_sbin = os.path.join(os.sep, "usr", "sbin") - if usr_sbin not in parts: parts.append(usr_sbin) @@ -552,9 +516,11 @@ def set_test_environment(logger, test_env=None, servers=None, clients=None, prov if test_env: # Update the PATH environment variable - build_vars_file = os.path.join( - os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", ".build_vars.json") - _update_path(logger, build_vars_file) + # Assume PREFIX relative to this installed file + daos_prefix = os.path.normpath( + os.path.join( + os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..", "..")) + _update_path(daos_prefix) # Get the default fabric interface and provider test_env.set_defaults(logger, servers, clients, provider, insecure_mode)