Skip to content

Commit

Permalink
remote/client: fallback to telnet when microcom is not available
Browse files Browse the repository at this point in the history
microcom is generally not available on rpm based distributions[1],
making it hard to setup labgrid client on them.

[1] https://repology.org/project/microcom/versions
  • Loading branch information
NickCao committed May 23, 2024
1 parent 9e0562e commit cf7b8e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions doc/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ Now we can connect to the serial console:
labgrid-venv $ labgrid-client -p example-place console
.. note:: Using remote connection requires ``microcom`` installed on the host
where the labgrid-client is called.
.. note:: Using remote connection requires ``microcom`` or ``telnet`` installed
on the host where the labgrid-client is called.

See :ref:`remote-usage` for some more advanced features.
For a complete reference have a look at the :doc:`labgrid-client(1) <man/client>`
Expand Down
27 changes: 21 additions & 6 deletions labgrid/remote/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import signal
import sys
import shlex
import shutil
import json
from textwrap import indent
from socket import gethostname
Expand Down Expand Up @@ -824,18 +825,32 @@ async def _console(self, place, target, timeout, *, logfile=None, loop=False, li
# check for valid resources
assert port is not None, "Port is not set"

call = ['microcom', '-s', str(resource.speed), '-t', f"{host}:{port}"]
microcom_bin = shutil.which("microcom")

if listen_only:
call.append("--listenonly")
if microcom_bin is not None:
call = [microcom_bin, '-s', str(resource.speed), '-t', f"{host}:{port}"]

if listen_only:
call.append("--listenonly")

if logfile:
call.append(f"--logfile={logfile}")
else:
call = ['telnet', host, str(port)]

logging.info("microcom not available, using telnet instead")

if listen_only:
logging.info("--listenonly option not supported by telnet, ignoring")

if logfile:
logging.info("--logfile option not supported by telnet, ignoring")

if logfile:
call.append(f"--logfile={logfile}")
print(f"connecting to {resource} calling {' '.join(call)}")
try:
p = await asyncio.create_subprocess_exec(*call)
except FileNotFoundError as e:
raise ServerError(f"failed to execute microcom: {e}")
raise ServerError(f"failed to execute remote console command: {e}")
while p.returncode is None:
try:
await asyncio.wait_for(p.wait(), 1.0)
Expand Down

0 comments on commit cf7b8e0

Please sign in to comment.