Skip to content

Fetch env file from coordinator#1866

Open
sjg20 wants to merge 2 commits into
labgrid-project:masterfrom
sjg20:push7-env
Open

Fetch env file from coordinator#1866
sjg20 wants to merge 2 commits into
labgrid-project:masterfrom
sjg20:push7-env

Conversation

@sjg20
Copy link
Copy Markdown
Contributor

@sjg20 sjg20 commented May 12, 2026

Description

Adds a way for labgrid-client to fetch the env file from the coordinator instead of requiring every user to keep a local copy in sync.

  • The coordinator gains a new GetEnvironment RPC and an --environment FILE flag pointing at the YAML env file to serve. The file is read fresh on each request, so admins can edit it in place.
  • The client treats the literal string coordinator: as a special LG_ENV / --config value. When set, it issues a one-shot GetEnvironment RPC, writes the YAML under $XDG_CACHE_HOME/labgrid (or ~/.cache/labgrid), and loads it like any other env file. Per-user paths inside the served env are still resolvable via the existing LG_* template substitution.
  • Default behaviour is unchanged: with no --environment flag on the coordinator, GetEnvironment returns an empty string and clients keep loading env from a local file.

What is the feature used for? Triage and console access from a laptop, scaling to larger labs with many clients, and removing the out-of-band env-file distribution step (shared FS, git checkout, scp, etc).

How does labgrid benefit? Lower friction for casual remote use - a remote user only needs labgrid, network access to the coordinator and three env vars (PATH, LG_COORDINATOR, LG_ENV=coordinator:) to run labgrid-client console -p <board> from anywhere.

How was it verified? Ran the coordinator with --environment <file> and a client with LG_ENV=coordinator: against it locally; confirmed the YAML is fetched, cached under ~/.cache/labgrid, and that subsequent commands resolve LG_* template paths correctly. Confirmed that with no --environment flag, behaviour is unchanged.

No hardware-specific changes.

Checklist

  • Documentation for the feature
  • Tests for the feature
  • Add a section on how to use the feature to doc/usage.rst
  • PR has been tested
  • Man pages have been regenerated

sjg20 added 2 commits May 12, 2026 07:36
The lab admin currently has to distribute the env file to every client
out of band - via a shared filesystem, git checkout, scp etc.  This is
awkward duplication for casual clients who just want to talk to a few
boards from a remote machine. It also makes it harder to scale to larger
labs with a lot of clients.

For some labs, particularly smaller ones, the environment is very tied
to the client, with each client having its own special file. For other
labs, such as larger labs where changes are few, the environment is the
same for each client.

Add a new GetEnvironment RPC that returns the env file's text content,
and a coordinator --environment flag pointing at the file to serve. The
file is read fresh on each request, so admins can edit it in place and
clients pick up the new version on their next invocation.

The default (no --environment) is unchanged: GetEnvironment returns an
empty string and clients keep loading env from a local file as before.

Signed-off-by: Simon Glass <sjg@chromium.org>
Remote users have to keep a local copy of the lab env file in sync with
the coordinator before they can run labgrid-client against it.  This is
friction for casual workflows like triage or console access from a
laptop, and is awkward to maintain across many client machines.

Provide a way for clients to fetch the env from the coordinator on
startup.  Setting LG_ENV (or --config) to the literal string
'coordinator:' issues a one-shot GetEnvironment RPC against the
coordinator.  The returned YAML is written under $XDG_CACHE_HOME/labgrid
(or ~/.cache/labgrid) and loaded exactly as if the user had pointed at a
local file, so the rest of the client is untouched.  The cache file is
overwritten on each fetch so users can inspect what env the client just
loaded.  Remote users then only need labgrid, network access to the
coordinator and three environment variables (PATH, LG_COORDINATOR,
LG_ENV=coordinator:) to run labgrid-client console -p <board> from
anywhere.

Per-user paths inside the served env (build dirs, log dirs, source
trees) are still resolvable via the existing LG_* template substitution,
so individual clients can override only the few values that matter to
them without forking the env file.

The coordinator address used for the fetch comes from --coordinator on
the command line if given, otherwise LG_COORDINATOR, with
127.0.0.1:20408 as the final default - matching the fallback chain
main() uses elsewhere.

Signed-off-by: Simon Glass <sjg@chromium.org>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 2.70270% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.9%. Comparing base (db1cba3) to head (a71588f).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/remote/client.py 4.3% 22 Missing ⚠️
labgrid/remote/coordinator.py 0.0% 14 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1866     +/-   ##
========================================
- Coverage    46.0%   45.9%   -0.1%     
========================================
  Files         180     180             
  Lines       14439   14472     +33     
========================================
+ Hits         6654    6655      +1     
- Misses       7785    7817     +32     
Flag Coverage Δ
3.10 45.9% <2.7%> (-0.1%) ⬇️
3.11 45.9% <2.7%> (-0.1%) ⬇️
3.12 45.9% <2.7%> (-0.1%) ⬇️
3.13 45.9% <2.7%> (-0.1%) ⬇️
3.14 45.9% <2.7%> (-0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant