diff --git a/CHANGES.rst b/CHANGES.rst index 56996efad..c8a4d9545 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -47,6 +47,7 @@ New Features in 24.0 switches running OpenWrt using the ubus interface. - The pyproject.toml gained a config for `ruff `_. - ``setuptools_scm`` is now used to generate a version file. +- labgrid-client console will fallback to telnet if microcom is not available. Bug fixes in 24.0 diff --git a/doc/getting_started.rst b/doc/getting_started.rst index f07086129..7d1990bb5 100644 --- a/doc/getting_started.rst +++ b/doc/getting_started.rst @@ -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) ` diff --git a/labgrid/remote/client.py b/labgrid/remote/client.py index 63c0cf859..8b9ef847a 100755 --- a/labgrid/remote/client.py +++ b/labgrid/remote/client.py @@ -13,6 +13,7 @@ import signal import sys import shlex +import shutil import json from textwrap import indent from socket import gethostname @@ -826,18 +827,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.warning("--listenonly option not supported by telnet, ignoring") + + if logfile: + logging.warning("--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)