diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 75d3c79cda4182864ed58dd59efd831711db88af..1321a2a2f885d33014cfb568f83ba64fdc67f196 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -5,6 +5,7 @@ gkfs_enable_python_testing( BINARY_DIRECTORIES ${CMAKE_BINARY_DIR}/src/daemon/ ${CMAKE_BINARY_DIR}/src/client/ ${CMAKE_BINARY_DIR}/tests/integration/harness/ + ${CMAKE_BINARY_DIR}/examples/gfind/ LIBRARY_PREFIX_DIRECTORIES ${CMAKE_PREFIX_PATH} ) diff --git a/tests/integration/directories/test_directories.py b/tests/integration/directories/test_directories.py index c83789f13be3ab6b7366a36ce023f478146ad9a4..4a60617dd890943aff8bef053b06e96c6217741a 100644 --- a/tests/integration/directories/test_directories.py +++ b/tests/integration/directories/test_directories.py @@ -220,11 +220,19 @@ def test_extended(gkfs_daemon, gkfs_shell, gkfs_client): ret = gkfs_client.write(file_a, buf, 1) assert ret.retval == 1 - preload = 'LIBGKFS_HOSTS_FILE='+str(gkfs_client._patched_env['LIBGKFS_HOSTS_FILE'])+' LD_PRELOAD='+str(gkfs_client._preload_library) - stream = os.popen(preload+' '+str(gkfs_daemon._workspace.bindirs[1])+'/sfind '+str(topdir)+' -M '+str(gkfs_daemon.mountdir)+' -S 1 -name "*_k*"'); - output = stream.read() - assert output == "MATCHED 0/4\n" - + + cmd = gkfs_shell.sfind( + topdir, + '-M', + gkfs_daemon.mountdir, + '-S', + 1, + '-name', + '*_k*' + ) + + assert cmd.exit_code == 0 + assert cmd.stdout.decode() == "MATCHED 0/4\n" @pytest.mark.skip(reason="invalid errno returned on success") @pytest.mark.parametrize("directory_path", diff --git a/tests/integration/harness/gkfs.py b/tests/integration/harness/gkfs.py index 07373ddb0015418e33cc19fa04acec88da8bdbcc..056bb1463f8993d5b41e9592c4f2f07a9aa9dc8c 100644 --- a/tests/integration/harness/gkfs.py +++ b/tests/integration/harness/gkfs.py @@ -140,6 +140,32 @@ def _process_exists(pid): return True +def _find_search_paths(additional_paths=None): + """ + Return the entire list of search paths available to the process. If + additional_paths is not provided, $PATH env is returned. + + Parameters + ---------- + additional_paths: `list` + If provided, additional paths that should be used for searching before + falling back to the contents of $PATH. + + Returns + ------- + A list containing the paths that should be searched for commands. + """ + + paths_to_search = [] + + if isinstance(additional_paths, (tuple, list)): + paths_to_search.extend(additional_paths) + + env_paths = os.environ.get("PATH", "").split(os.pathsep) + paths_to_search.extend(env_paths) + + return paths_to_search + class FwdDaemonCreator: """ Factory that allows tests to create forwarding daemons in a workspace. @@ -439,7 +465,7 @@ class ShellClient: def __init__(self, workspace): self._workspace = workspace - self._cmd = sh.Command("bash") + self._search_paths = _find_search_paths(self._workspace.bindirs) self._env = os.environ.copy() libdirs = ':'.join( @@ -552,6 +578,8 @@ class ShellClient: if intercept_shell: logger.debug(f"patched env: {self._patched_env}") + self._cmd = sh.Command("bash") + # 'sh' raises an exception if the return code is not zero; # since we'd rather check for return codes explictly, we # whitelist all exit codes from 1 to 255 as 'ok' using the @@ -608,19 +636,27 @@ class ShellClient: extra properties to it. """ - bash_c_args = f"{cmd} {' '.join(str(a) for a in args)}" - logger.debug(f"running bash") - logger.debug(f"cmd: bash -c '{bash_c_args}'") + found_cmd = sh.which(cmd, self._search_paths) + + if not found_cmd: + raise sh.CommandNotFound(cmd) + + self._cmd = sh.Command(found_cmd) + + logger.debug(f"running program") + logger.debug(f"cmd: {cmd} {' '.join(str(a) for a in args)}") + logger.debug(f"search_paths: {':'.join(str(p) for p in self._search_paths)}") logger.debug(f"timeout: {timeout} seconds") logger.debug(f"timeout_signal: {signal.Signals(timeout_signal).name}") logger.debug(f"patched env:\n{pformat(self._patched_env)}") + # 'sh' raises an exception if the return code is not zero; # since we'd rather check for return codes explictly, we # whitelist all exit codes from 1 to 255 as 'ok' using the # _ok_code argument - proc = self._cmd('-c', - bash_c_args, + proc = self._cmd( + args, _env = self._env, # _out=sys.stdout, # _err=sys.stderr, @@ -629,6 +665,9 @@ class ShellClient: # _ok_code=list(range(0, 256)) ) + logger.debug(f"program stdout: {proc.stdout}") + logger.debug(f"program stderr: {proc.stderr}") + return ShellCommand(cmd, proc) def __getattr__(self, name):