Skip to content

Commit

Permalink
agent: add argument to specify python virutal env
Browse files Browse the repository at this point in the history
When using agentwrapper, the python packages used are the one installed
on the machine.
This commit add an argument to specify the path to a virtual env which
will be used by the agent.

Signed-off-by: Nicolas VINCENT <[email protected]>
  • Loading branch information
nvincent-vossloh committed May 31, 2024
1 parent 9e0562e commit af39ced
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions labgrid/util/agentwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __getattr__(self, name):

class AgentWrapper:

def __init__(self, host=None):
def __init__(self, host=None, pyvirtenv=None):
self.agent = None
self.loaded = {}
self.logger = logging.getLogger(f"ResourceExport({host})")
Expand All @@ -58,8 +58,12 @@ def __init__(self, host=None):
['rsync', '-e', ' '.join(ssh_opts), '-tq', agent,
f'{host}:{agent_remote}'],
)
select_virtenv = []
if pyvirtenv is not None:
select_virtenv = f'source {pyvirtenv}/bin/activate &&'.split()
cmd = select_virtenv + ['python3', agent_remote]
self.agent = subprocess.Popen(
ssh_opts + [host, '--', 'python3', agent_remote],
ssh_opts + [host, '--'] + cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
start_new_session=True,
Expand Down

0 comments on commit af39ced

Please sign in to comment.