Fetch env file from coordinator#1866
Conversation
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
from the experience of using labgrid, this change sounds great. Reducing complexity on user-side is something I would welcome very much. |
|
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. |
|
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. |
|
You are very correct, sorry, that was my fault. I will try to find time to take a closer look some time next week. |
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: test2But let's continue the discussion in the draft PR I'm going to open. |
|
@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: |
|
This contains many different targets in a single environment file. 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. |
Yes, it is here: |
Here it is: #1889 |
Description
Adds a way for
labgrid-clientto fetch the env file from the coordinator instead of requiring every user to keep a local copy in sync.GetEnvironmentRPC and an--environment FILEflag pointing at the YAML env file to serve. The file is read fresh on each request, so admins can edit it in place.coordinator:as a specialLG_ENV/--configvalue. When set, it issues a one-shotGetEnvironmentRPC, 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 existingLG_*template substitution.--environmentflag on the coordinator,GetEnvironmentreturns 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 runlabgrid-client console -p <board>from anywhere.How was it verified? Ran the coordinator with
--environment <file>and a client withLG_ENV=coordinator:against it locally; confirmed the YAML is fetched, cached under~/.cache/labgrid, and that subsequent commands resolveLG_*template paths correctly. Confirmed that with no--environmentflag, behaviour is unchanged.No hardware-specific changes.
Checklist