From 0d310a694398cee6b027a8834de757a89234e9bb Mon Sep 17 00:00:00 2001 From: Kuba Mazurek Date: Fri, 13 Aug 2021 10:52:09 +0200 Subject: [PATCH] Expand path variable in get_agent_env_vars (#534) --- goth/interactive.py | 2 +- goth/runner/probe/__init__.py | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/goth/interactive.py b/goth/interactive.py index 9764b1d5..3a185399 100644 --- a/goth/interactive.py +++ b/goth/interactive.py @@ -45,7 +45,7 @@ async def start_network( for provider in providers: await provider.provider_agent.wait_for_log("Subscribed offer") - requestor_env = requestor.get_agent_env_vars() + requestor_env = requestor.get_agent_env_vars(expand_path=False) subnet = providers[0].provider_agent.subnet requestor_env["YAGNA_SUBNET"] = subnet diff --git a/goth/runner/probe/__init__.py b/goth/runner/probe/__init__.py index b4467652..f4306216 100644 --- a/goth/runner/probe/__init__.py +++ b/goth/runner/probe/__init__.py @@ -6,6 +6,7 @@ import contextlib import copy import logging +import os from pathlib import Path from typing import ( AsyncIterator, @@ -261,23 +262,31 @@ async def create_app_key(self, key_name: str = "test_key") -> str: key = app_key.key return key - def get_agent_env_vars(self, path_var: str = "$PATH") -> Dict[str, str]: + def get_agent_env_vars(self, expand_path: bool = True) -> Dict[str, str]: """Get env vars needed to talk to the daemon in this probe's container. - The returned vars include the `PATH` variable as it needs to include the - directory which contains the gftp proxy script. - By default, the `PATH` value is: `{gftp_script_dir}:$PATH`, allowing for shell - substitution of `$PATH`. This part can be overridden by setting the `path_var` - argument. + The returned vars include the `PATH` variable as it needs to contain the + directory in which the gftp proxy script resides. + The value of the result's `PATH` variable gets prefixed with the gftp script's + directory, so it will look like this: `/tmp/some_gftp_dir:$PATH`. + + When `expand_path` is `True` (default behaviour) the `$PATH` in the above + example gets expanded to the system's actual `PATH` variable (taken from + `os.environ`). + When `expand_path` is `False` the `$PATH` part stays as-is (useful for shell + substitution). """ if not self.app_key: raise AttributeError("Yagna application key is not set yet") + + path: str = os.environ["PATH"] if expand_path else "$PATH" + return { "YAGNA_APPKEY": self.app_key, "YAGNA_API_URL": YAGNA_REST_URL.substitute(host=self.ip_address), "GSB_URL": YAGNA_BUS_URL.substitute(host=self.ip_address), - "PATH": f"{self._gftp_script_dir}:{path_var}", + "PATH": f"{self._gftp_script_dir}:{path}", } @contextlib.asynccontextmanager @@ -286,7 +295,7 @@ async def run_command_on_host( command: str, env: Optional[Dict[str, str]] = None, command_timeout: float = 300, - ) -> Iterator[Tuple[asyncio.Task, PatternMatchingEventMonitor]]: + ) -> AsyncIterator[Tuple[asyncio.Task, PatternMatchingEventMonitor]]: """Run `command` on host in given `env` and with optional `timeout`. The command is run in the environment extending `env` with variables needed