From 9cce211df96c378b0b1d4cb05123aff4192a2271 Mon Sep 17 00:00:00 2001
From: Alberto Miranda <alberto.miranda@bsc.es>
Date: Thu, 10 Dec 2020 16:07:56 +0100
Subject: [PATCH] ShellClient now considers _workspace.bindirs when searching
 for programs

---
 tests/integration/harness/gkfs.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tests/integration/harness/gkfs.py b/tests/integration/harness/gkfs.py
index 07373ddb0..bcec22a2a 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,6 +465,7 @@ class ShellClient:
 
     def __init__(self, workspace):
         self._workspace = workspace
+        self._search_paths = _find_search_paths(self._workspace.bindirs)
         self._cmd = sh.Command("bash")
         self._env = os.environ.copy()
 
@@ -608,9 +635,12 @@ class ShellClient:
         extra properties to it.
         """
 
+        cmd = sh.which(cmd, self._search_paths)
+
         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}'")
+        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)}")
-- 
GitLab