Skip to content

Document the order of precedence of environment variable sources #4241

Description

@happz

Environment variables visible to test - but not just tests, prepare scripts or Ansible playbooks must be considered too! - are composed from various sources:

External sources

  • run: --environment and --environment-file CLI options
  • plan: environment and environment-file fmf keys
  • importing plan: environment fmf key of the importing plan
  • provision phases ("per-guest environment"): environment fmf key, --environment CLI option
  • test: environment fmf key
  • recipe: saved run environment replacing current run environment

Internal sources

  • plugin action itself - test name, test data, plan data, ...
  • test framework
  • invocation contexts - reboot, restart, abort, pidfile, restraint, ...

Environment variables recognized by tmt

(Did I miss any source?)

The question is: in which order shall they be applied? We are not 100 % sure, and then there are users asking.

The goal is to put together a documentation similar to https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable


Status

Untangling the environment, one step at a time. At this moment, the best we can do is to document the order, but it's far from being clean, nice, and desirable.


Assorted notes

Current (rough) ordering

AFAICT, the rough order of precedence, as of now, is something like the following:

  • provision[].environment
  • test[].environment
  • "plan environment"
    • $TMT_PLAN_ENVIRONMENT_FILE
    • plan environment-file key
    • plan environment key
    • importing plan "native" environment
      • importing plan environment-file key
      • importing plan environment key
      • importing plan importing plan ...
    • run environment saved in the workdir (--environment and --environment-file from previous invocations)
    • tmt run --environment
    • tmt run --environment-file
    • plan intrinsic variables: TMT_VERSION, TMT_TREE, ...
  • plugin intrinsic variables
    • abort context
    • reboot context
    • restart context
    • pidfile context
    • restraint context
    • test framework
    • ...

Desired state

This should be the desired order of precedence, from the weakest to strongest sources:

  1. test[].environment
  2. plan environment-file key
  3. plan environment key
  4. importing plan "native" environment
    1. importing plan environment-file key
    2. importing plan environment key
    3. importing plan importing plan ...
  5. provision[].environment
  6. $TMT_PLAN_ENVIRONMENT_FILE
  7. command-line input:
    1. tmt run
      • run environment saved in the workdir (--environment-file and --environment from previous invocations)
      • tmt run --environment-file
      • tmt run --environment
    2. tmt * export
      • tmt * export --environment-file
      • tmt * export --environment
    3. tmt try
      • tmt try --environment-file
      • tmt try --environment
  8. plugin intrinsic variables
    1. abort context
    2. reboot context
    3. restart context
    4. pidfile context
    5. restraint context
    6. test framework
    7. guest topology
    8. plan intrinsic variables: TMT_VERSION, TMT_TREE, ...

Metadata

Metadata

Assignees

Labels

area | environmentEnvironment variables handlingarea | maintenanceChanges important for efficiency and the long-term health of the projectdocumentationImprovements or additions to documentationstatus | blocking other workAn important pull request, blocking other pull requests or issuestest coverageImprovements or additions to test coverage of tmt itself

Type

Projects

Status
implement
Status
triaged

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions