Skip to content

Commit 63749cf

Browse files
authored
Merge pull request #1894 from Emantor/topic/labgrid-agent-python
agentwrapper: try labgrid-python3 for agent environment
2 parents 8a656ef + f062575 commit 63749cf

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

labgrid/util/agentwrapper.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ def __init__(self, host=None):
6060
['rsync', '-e', ' '.join(ssh_opts), '-tq', agent,
6161
f'{host}:{agent_remote}'],
6262
)
63+
agent_python = "labgrid-python3" if not subprocess.call(ssh_opts + [host, '--', 'which', 'labgrid-python3']) else "python3"
64+
if agent_python == "python3":
65+
self.logger.debug(
66+
"labgrid-python3 on %s not found, using python3 which requires system installed python modules for agents",
67+
host
68+
)
6369
self.agent = subprocess.Popen(
64-
ssh_opts + [host, '--', 'python3', agent_remote],
70+
ssh_opts + [host, '--', agent_python, agent_remote],
6571
stdin=subprocess.PIPE,
6672
stdout=subprocess.PIPE,
6773
start_new_session=True,

tests/test_agent.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import socket
33
import subprocess
4+
import shutil
45

56
import pytest
67
from py.path import local
@@ -18,7 +19,7 @@ def subprocess_mock(mocker):
1819
agent = local(labgrid.util.agentwrapper.__file__).dirpath('agent.py')
1920

2021
def run(args, **kwargs):
21-
assert args[0] in ['rsync', 'ssh']
22+
assert args[0] in ['rsync', 'ssh', 'which']
2223
if args[0] == 'rsync':
2324
src = local(args[-2])
2425
assert src == agent
@@ -32,10 +33,14 @@ def run(args, **kwargs):
3233
assert '--' in args
3334
args = args[args.index('--')+1:]
3435
assert len(args) == 2
35-
assert args[0] == 'python3'
36-
assert args[1].startswith('.labgrid_agent')
37-
# we need to use the original here to get the coverage right
38-
return original(['python3', str(agent)], **kwargs)
36+
assert args[0] in ['labgrid-python3', 'python3', 'which']
37+
if args[0] in ['python3', 'labgrid-python3']:
38+
assert args[1].startswith('.labgrid_agent')
39+
# we need to use the original here to get the coverage right
40+
return original(['python3', str(agent)], **kwargs)
41+
else:
42+
lg_py3_env = 'true' if shutil.which('labgrid-python3') else 'false'
43+
return original([lg_py3_env], **kwargs)
3944

4045
mocker.patch('subprocess.Popen', run)
4146

0 commit comments

Comments
 (0)