From c10d4b4f4b8d0ec9ac6b2a714fb1676b4b0dcc29 Mon Sep 17 00:00:00 2001 From: Ye Cao Date: Thu, 21 Sep 2023 19:02:55 +0800 Subject: [PATCH] Travel the path to find the vineyard socket in the vineyard.csi.read/write API. (#1577) Fixes part of #1568 Signed-off-by: Ye Cao --- python/vineyard/csi/__init__.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/python/vineyard/csi/__init__.py b/python/vineyard/csi/__init__.py index e58fccb0..2f7b36f1 100644 --- a/python/vineyard/csi/__init__.py +++ b/python/vineyard/csi/__init__.py @@ -22,6 +22,16 @@ import vineyard +def _find_vineyard_socket(path): + current_dir = path + while current_dir != "/": + socket_path = os.path.join(current_dir, "vineyard.sock") + if os.path.exists(socket_path): + return socket_path + current_dir = os.path.dirname(current_dir) + return None + + def write( value: Any, path: str, @@ -31,19 +41,17 @@ def write( Notice, the API is only used for CSI driver. Parameters: - client: IPCClient - The vineyard client to use. path: str The path that represents a vineyard object. .. code:: python >>> arr = np.arange(8) - >>> client.write(arr) + >>> vineyard.write(arr) """ - socket_path = os.path.join(path, "vineyard.sock") + socket_path = _find_vineyard_socket(path) - if not os.path.exists(path): + if socket_path is None: raise FileNotFoundError( f"The given path is not generated by vineyard CSI driver: {path}" ) @@ -72,9 +80,9 @@ def read( Returns: A python object that return by the resolver, by resolving an vineyard object. """ - socket_path = os.path.join(path, "vineyard.sock") + socket_path = _find_vineyard_socket(path) - if not os.path.exists(path): + if socket_path is None: raise FileNotFoundError( f"The given path is not generated by vineyard CSI driver: {path}" )