Skip to content

Commit

Permalink
DAOS-15659 test: fix local ftest prefix
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
daltonbohning committed Apr 16, 2024
1 parent c555ef0 commit b01be00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 64 deletions.
24 changes: 6 additions & 18 deletions src/tests/ftest/util/apricot/apricot/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ def __init__(self, *args, **kwargs):
# use 'add_cancel_ticket(<ticket>)' to add to this set.
self._teardown_cancel = set()
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
Expand All @@ -150,22 +148,12 @@ 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.cancel_from_list()
self.check_variant_skip()
self.log.info("*** SETUP running on %s ***", str(detect()))
Expand Down
58 changes: 12 additions & 46 deletions src/tests/ftest/util/environment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b01be00

Please sign in to comment.