Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/man/device-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ previous driver.
For a list of available resources and drivers refer to
https://labgrid.readthedocs.io/en/latest/configuration.html.

.. _labgrid-device-config-options:

OPTIONS
-------
The ``options:`` top key configures various options such as the coordinator_address.
Expand All @@ -42,6 +44,14 @@ OPTIONS KEYS
``coordinator_address``
takes as parameter the coordinator ``HOST[:PORT]`` to connect to.
Defaults to ``127.0.0.1:20408``.
Overrides the ``LG_COORDINATOR`` environment variable.

``proxy``
takes as parameter the SSH proxy host used to tunnel connections to the
coordinator and to network resources.
Overrides the ``LG_PROXY`` environment variable.
Set it to an empty value (e.g. ``proxy:``) to force a direct connection
without a proxy, even when ``LG_PROXY`` is set.

.. _labgrid-device-config-images:

Expand Down
7 changes: 7 additions & 0 deletions doc/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@ respective proxies. This means that with :code:`LG_PROXY` and
:code:`LG_COORDINATOR` labgrid can be used fully remotely with only a SSH
connection as a requirement.

Instead of the environment variables, the :code:`proxy` and
:code:`coordinator_address` options can be set in the environment config (see
:ref:`labgrid-device-config-options`). The config options take precedence over
the corresponding environment variables. Setting the :code:`proxy` option to an
empty value forces a direct connection without a proxy, even when
:code:`LG_PROXY` is set.

.. note::
Labgrid prefers to connect to an exporter-defined proxy over using the
LG_PROXY variable. This means that a correct entry for the exporter needs to
Expand Down
4 changes: 4 additions & 0 deletions doc/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ Specifies a SSH proxy host to be used for port forwards to access the
coordinator. Network resources made available by the exporter will prefer their
own proxy, and only fallback to LG_PROXY.

This can be overridden by the ``proxy`` option in the environment config (see
:ref:`labgrid-device-config-options`). Setting that option to an empty value
forces a direct connection without a proxy, even when ``LG_PROXY`` is set.

See also :ref:`overview-proxy-mechanism`.


Expand Down
7 changes: 7 additions & 0 deletions labgrid/pytestplugin/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .. import Environment
from ..consoleloggingreporter import ConsoleLoggingReporter
from ..util.helper import processwrapper
from ..util.proxy import proxymanager
from ..logging import StepFormatter, StepLogger
from ..exceptions import NoStrategyFoundError

Expand Down Expand Up @@ -89,6 +90,12 @@ def pytest_configure(config):
env = Environment(config_file=lg_env)
if lg_coordinator is not None:
env.config.set_option('coordinator_address', lg_coordinator)
# Let the 'proxy' config option override the LG_PROXY environment
# variable; a present but empty/false value disables proxying.
try:
proxymanager.force_proxy(env.config.get_option("proxy"))
except KeyError:
pass # no 'proxy' option: keep the LG_PROXY default
config.stash[LABGRID_ENV_KEY] = env

processwrapper.enable_logging()
Expand Down
15 changes: 12 additions & 3 deletions labgrid/remote/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2302,13 +2302,22 @@ def main():
print("Setting the initial state requires a desired state", file=sys.stderr)
exit(1)

if args.proxy:
proxymanager.force_proxy(args.proxy)

env = None
if args.config:
env = Environment(config_file=args.config)

# Proxy precedence: --proxy command line argument > 'proxy' config option >
# LG_PROXY environment variable (the latter is the proxymanager's default).
# A 'proxy' config option that is present but empty/false explicitly
# disables proxying, even when LG_PROXY is set.
if args.proxy:
proxymanager.force_proxy(args.proxy)
elif env:
try:
proxymanager.force_proxy(env.config.get_option("proxy"))
except KeyError:
pass # no 'proxy' option: keep the LG_PROXY default

role = None
if args.command != "reserve" and env and env.config.get_targets():
if args.place:
Expand Down
5 changes: 5 additions & 0 deletions labgrid/util/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class ProxyManager:

@classmethod
def force_proxy(cls, force_proxy):
# A falsy value (empty string, None, False) disables proxying, even if
# the LG_PROXY environment variable is set.
if not force_proxy:
cls._force_proxy = None
return
assert isinstance(force_proxy, str)
cls._force_proxy = force_proxy

Expand Down
8 changes: 8 additions & 0 deletions man/labgrid-device-config.5
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ The \fBoptions:\fP top key configures various options such as the coordinator_ad
.B \fBcoordinator_address\fP
takes as parameter the coordinator \fBHOST[:PORT]\fP to connect to.
Defaults to \fB127.0.0.1:20408\fP\&.
Overrides the \fBLG_COORDINATOR\fP environment variable.
.TP
.B \fBproxy\fP
takes as parameter the SSH proxy host used to tunnel connections to the
coordinator and to network resources.
Overrides the \fBLG_PROXY\fP environment variable.
Set it to an empty value (e.g. \fBproxy:\fP) to force a direct connection
without a proxy, even when \fBLG_PROXY\fP is set.
.UNINDENT
.SS IMAGES
.sp
Expand Down
Loading