Skip to content

Commit a5a8b65

Browse files
NickCaoEmantor
authored andcommitted
remote/client: fallback to telnet when microcom is not available
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 Signed-off-by: Nick Cao <nickcao@nichi.co> [r.czerwinski@pengutronix.de: rebased, added CHANGES.rst entry] Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
1 parent 1ea0fef commit a5a8b65

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ New Features in 24.0
4747
switches running OpenWrt using the ubus interface.
4848
- The pyproject.toml gained a config for `ruff <https://github.com/astral-sh/ruff>`_.
4949
- ``setuptools_scm`` is now used to generate a version file.
50+
- labgrid-client console will fallback to telnet if microcom is not available.
5051

5152

5253
Bug fixes in 24.0

doc/getting_started.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ Now we can connect to the serial console:
349349
350350
labgrid-venv $ labgrid-client -p example-place console
351351
352-
.. note:: Using remote connection requires ``microcom`` installed on the host
353-
where the labgrid-client is called.
352+
.. note:: Using remote connection requires ``microcom`` or ``telnet`` installed
353+
on the host where the labgrid-client is called.
354354

355355
See :ref:`remote-usage` for some more advanced features.
356356
For a complete reference have a look at the :doc:`labgrid-client(1) <man/client>`

labgrid/remote/client.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import signal
1414
import sys
1515
import shlex
16+
import shutil
1617
import json
1718
from textwrap import indent
1819
from socket import gethostname
@@ -826,18 +827,32 @@ async def _console(self, place, target, timeout, *, logfile=None, loop=False, li
826827
# check for valid resources
827828
assert port is not None, "Port is not set"
828829

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

831-
if listen_only:
832-
call.append("--listenonly")
832+
if microcom_bin is not None:
833+
call = [microcom_bin, "-s", str(resource.speed), "-t", f"{host}:{port}"]
834+
835+
if listen_only:
836+
call.append("--listenonly")
837+
838+
if logfile:
839+
call.append(f"--logfile={logfile}")
840+
else:
841+
call = ["telnet", host, str(port)]
842+
843+
logging.info("microcom not available, using telnet instead")
844+
845+
if listen_only:
846+
logging.warning("--listenonly option not supported by telnet, ignoring")
847+
848+
if logfile:
849+
logging.warning("--logfile option not supported by telnet, ignoring")
833850

834-
if logfile:
835-
call.append(f"--logfile={logfile}")
836851
print(f"connecting to {resource} calling {' '.join(call)}")
837852
try:
838853
p = await asyncio.create_subprocess_exec(*call)
839854
except FileNotFoundError as e:
840-
raise ServerError(f"failed to execute microcom: {e}")
855+
raise ServerError(f"failed to execute remote console command: {e}")
841856
while p.returncode is None:
842857
try:
843858
await asyncio.wait_for(p.wait(), 1.0)

0 commit comments

Comments
 (0)