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

@sjg20 sjg20 commented May 12, 2026

Copy link
Copy Markdown
Contributor

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

codecov Bot commented May 12, 2026

Copy link
Copy Markdown

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.

@flxzt

flxzt commented May 29, 2026

Copy link
Copy Markdown
Contributor

from the experience of using labgrid, this change sounds great. Reducing complexity on user-side is something I would welcome very much.

@Bastian-Krause

Copy link
Copy Markdown
Member

I haven't looked in detail at this, but I'm currently experimenting with a rather similar change at https://github.com/Bastian-Krause/labgrid/commits/bst/coordinator-remote-env/. It's still a prototype, things might change, but I think that's the general direction we'd like to head.

I'll open a RFC PR with this next week.

@Emantor

Emantor commented May 30, 2026

Copy link
Copy Markdown
Member

Both of these approaches lock the environment down to one target, which limits the usefulness to single target tests. While this is definitely useful on it's own, we should rethink the concept to make multi-target environments possible as well.

@sjg20

sjg20 commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

Both of these approaches lock the environment down to one target, which limits the usefulness to single target tests. While this is definitely useful on it's own, we should rethink the concept to make multi-target environments possible as well.

Thanks for looking at this.

I am actually using this approach with about 30 targets. Do you mean a single exporter?

I have some local changes which allow each exporter to send an environment and have the coordinator merge them. I haven't sent it yet since I thought this PR was a good starting point. Let me know if I should send that too.

But in any case this PR is likely just a starting point.

@Emantor

Emantor commented May 31, 2026

Copy link
Copy Markdown
Member

You are very correct, sorry, that was my fault. I will try to find time to take a closer look some time next week.

@Bastian-Krause

Copy link
Copy Markdown
Member

Both of these approaches lock the environment down to one target, which limits the usefulness to single target tests. While this is definitely useful on it's own, we should rethink the concept to make multi-target environments possible as well.

That's not the case for my approach: The remote env is applied per place (optionally combined with a local env), so multi target envs still work. For pytest, a minimal example (relying solely on the remote envi) would be:

targets:
  test1:
    resources:
      RemotePlace:
        name: test1
  test2:
    resources:
      RemotePlace:
        name: test2

But let's continue the discussion in the draft PR I'm going to open.

@Bastian-Krause

Copy link
Copy Markdown
Member

@sjg20 Could you give an example of an environment you give the exporter? Does it contain all your targets (including drivers and resources)? Looking at the env skeleton in the docs, do you also store options, features, paths, images, tools and imports in there?

@sjg20

sjg20 commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

@sjg20 Could you give an example of an environment you give the exporter? Does it contain all your targets (including drivers and resources)? Looking at the env skeleton in the docs, do you also store options, features, paths, images, tools and imports in there?

Yes, please see here for exporter and environment:

asc.txt
asc2.txt

@jluebbe

jluebbe commented Jun 2, 2026

Copy link
Copy Markdown
Member

asc2.txt

This contains many different targets in a single environment file.
Each environment is intended to describe a single test environment, not a whole lab.
It abstracts different test environments from the perspective of a test suite/client program.
As such it doesn't make sense to have only one, as then you lose the ability to cleanly switch between test environments.

I think I explained this to @sjg20 before, but don't have time to dig it up at the moment.

To be explicit: I'm going to NACK any change which is motivated only by not using labgrid's abstractions as they are intended to be used.

I see the need to share more of the test environment's configuration between users and @Bastian-Krause's approach will give us a way to do that, while not breaking with existing abstractions.

@sjg20

sjg20 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

asc2.txt

This contains many different targets in a single environment file. Each environment is intended to describe a single test environment, not a whole lab. It abstracts different test environments from the perspective of a test suite/client program. As such it doesn't make sense to have only one, as then you lose the ability to cleanly switch between test environments.

I think I explained this to @sjg20 before, but don't have time to dig it up at the moment.

Yes, it is here:

#1375

@Bastian-Krause

Copy link
Copy Markdown
Member

I haven't looked in detail at this, but I'm currently experimenting with a rather similar change at https://github.com/Bastian-Krause/labgrid/commits/bst/coordinator-remote-env/. It's still a prototype, things might change, but I think that's the general direction we'd like to head.

I'll open a RFC PR with this next week.

Here it is: #1889

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.

5 participants