Skip to content

Conversation

@happz
Copy link
Contributor

@happz happz commented Nov 25, 2025

Related to #4241

TODO

Pull Request Checklist

  • implement the feature
  • write the documentation
  • extend the test coverage
  • update the specification
  • adjust plugin docstring
  • modify the json schema
  • mention the version
  • include a release note

@happz happz added documentation Improvements or additions to documentation area | environment Environment variables handling labels Nov 25, 2025
@happz happz added this to planning Nov 25, 2025
@github-project-automation github-project-automation bot moved this to backlog in planning Nov 25, 2025
@happz happz moved this from backlog to implement in planning Nov 25, 2025
@happz
Copy link
Contributor Author

happz commented Nov 25, 2025

Ok, kicking of with a summary and a couple of notes and TODO items while my memory is reasonably fresh.

See https://tmt--4364.org.readthedocs.build/en/4364/environment.html for the preview.

Ignore the location of the document, I just needed to hook it somewhere.

@psss psss linked an issue Nov 26, 2025 that may be closed by this pull request
@psss
Copy link
Contributor

psss commented Nov 26, 2025

Synced priority with the issue and proposed for the next sprint as agreed on the hacking session.

@LecrisUT LecrisUT self-assigned this Nov 28, 2025
@happz happz moved this from implement to backlog in planning Dec 2, 2025
@psss psss self-assigned this Dec 4, 2025
@psss psss added this to the 1.64 milestone Dec 4, 2025

.. important::

See the TODO above, plan environment seems to be injected into
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we document as this order first or invert the preference and document our intended order?

As for the order preference, I think it's better to be:

  1. Plan env
  2. Guest env (combined in plan env)
  3. Test env
  4. tmt controlled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this moment, what I have here is a collection of inputs as they are now, i.e. documenting the current state. It needs (senior) developers' input on what should be the desired order, which we would then document and test.

# (tmt/steps/discover/__init__.py)

# Update test environment with plan environment
test.environment.update(self.plan.environment)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just drop this and do the expansion at the caller or property to see the exact order being used.

This being done at the discover level? would indicate that the later step environments are not updated? I believe that's not the case since TMT_PLAN_ENVIRONMENT_FILE is being processed, but maybe that one is a special case altogether? The deciding parameter should be the guest env since that is only defined after the provision.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, it's much harder to control and follow. A plan environment being injected into test environment so early means it's there, forever, and from this moment there is no "plan environment" but only "test environment". I believe this needs to go, "plan environment" needs to be added in the correct order where the command environment is composed from components (execute/internal, prepare/*, finish/*).


"Plan environment" consistst of multiple sources, in this order:

* plan environment file, ``$TMT_PLAN_ENVIRONMENT_FILE``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a rather special case because it is being written on the guest. Let me verify the logic, after a PrepareShell step the plan data is synced back so any changes to TMT_PLAN_ENVIRONMENT_FILE are reflected back to the runner, and the runner always reads this source when needing to evaluate the plan env, e.g. when running ansible plugin.

But then what happens in the multi guest case? Isn't the plan data still shared between all guests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then what happens in the multi guest case? Isn't the plan data still shared between all guests?

The puzzlement comes from the fact you speak about "plan data", I'm afraid we need to be more precise as there is so many of different inputs, and "plan environment" can mean a lot of them.

Yes, a test invoked on multiple guests shares some portion of environment: from run, from plan's keys, from test keys, from the importing plan. They also share the intrinsic bits - TMT_TREE, TMT_TEST_NAME, etc. They do not share environment from guest keys, they do not share environment from the plan environment file, as it may be have different content across guests. So, yeah, "plan data" is shared, but also isn't, depending of what you ask about.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The puzzlement comes from the fact you speak about "plan data"

By plan data there, I mean the plan_workdir a.k.a. TMT_PLAN_DATA, under which the physical TMT_PLAN_ENVIRONMENT_FILE is located.

after a PrepareShell step the plan data is synced back so any changes to TMT_PLAN_ENVIRONMENT_FILE are reflected back to the runner,

they do not share environment from the plan environment file

So when doing guest.pull is there a filter to not pull $TMT_PLAN_DATA/variables.env? There are multiple aspects that seem to be in conflict with each other between:

  • TMT_PLAN_DATA being shared across guests
  • TMT_PLAN_ENVIRONMENT_FILE=$TMT_PLAN_DATA/variables.env
  • Reading back changes to TMT_PLAN_ENVIRONMENT_FILE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The puzzlement comes from the fact you speak about "plan data"

By plan data there, I mean the plan_workdir a.k.a. TMT_PLAN_DATA, under which the physical TMT_PLAN_ENVIRONMENT_FILE is located.

Hmmm, good point - I don't know the answer. In theory, a plan may put different content into this file on different guests, but do they share the same path on the runner when fetched from guests? This might be a bug.

after a PrepareShell step the plan data is synced back so any changes to TMT_PLAN_ENVIRONMENT_FILE are reflected back to the runner,

they do not share environment from the plan environment file

So when doing guest.pull is there a filter to not pull $TMT_PLAN_DATA/variables.env? There are multiple aspects that seem to be in conflict with each other between:

  • TMT_PLAN_DATA being shared across guests
  • TMT_PLAN_ENVIRONMENT_FILE=$TMT_PLAN_DATA/variables.env
  • Reading back changes to TMT_PLAN_ENVIRONMENT_FILE

Indeed, I'm no longer sure they do not share plan environment file content. Maybe they do, and maybe they should not. Added a TODO item to the PR description.


As set via :ref:`environment </plugins/provision/common-keys>` key of
individual ``provision`` phases. Applies to user commands executed on
the given guest.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about when used in ansible plugin? That one does not include these right? And similarly for all guestless step/plugins right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, to reflect the current state it should be rather "Should apply to user commands executed on the given guest".

@happz happz removed this from the 1.64 milestone Dec 9, 2025
@happz happz force-pushed the document-envvar-precedence branch from c1f008e to cf4c675 Compare December 9, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area | environment Environment variables handling documentation Improvements or additions to documentation

Projects

Status: backlog

Development

Successfully merging this pull request may close these issues.

Document the order of precedence of environment variable sources

4 participants