Environment precedence
Warning
Just a draft, adding my notes, moving sections around, etc. very fluid.
Todo
AFAICT, the rough order of precedence, as of now, is something like the following:
provision[].environmenttest[].environment- “plan environment”
$TMT_PLAN_ENVIRONMENT_FILEplan
environment-filekeyplan
environmentkey- importing plan “native” environment
importing plan
environment-filekeyimporting plan
environmentkeyimporting plan importing plan …
run environment saved in the workdir (
--environmentand--environment-filefrom previous invocations)tmt run --environmenttmt run --environment-fileplan intrinsic variables:
TMT_VERSION,TMT_TREE, …
- plugin intrinsic variables
abort context
reboot context
restart context
pidfile context
restraint context
test framework
…
Todo
This should be the desired order of precedence:
test[].environmentplan
environment-filekeyplan
environmentkey- importing plan “native” environment
importing plan
environment-filekeyimporting plan
environmentkeyimporting plan importing plan …
provision[].environment$TMT_PLAN_ENVIRONMENT_FILE- command-line input:
tmt runrun environment saved in the workdir (
--environment-fileand--environmentfrom previous invocations)tmt run --environment-filetmt run --environment
tmt * exporttmt * export --environment-filetmt * export --environment
tmt trytmt try --environment-filetmt try --environment
- plugin intrinsic variables
abort context
reboot context
restart context
pidfile context
restraint context
test framework
plan intrinsic variables:
TMT_VERSION,TMT_TREE, ……
Todo
# Asorted list of environment 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
Internal sources
~~plugin action itself - test name, test data, plan data, ...~~
~~test framework~~
~~invocation contexts - reboot, restart, abort, pidfile, restraint, ...~~
Todo
Plan environment is actually dumped into test environment, so it apparently overrides the test environment. In any case, it should be added explicitly into the final environment, not sneaked into via test.
# (tmt/steps/discover/__init__.py)
# Update test environment with plan environment
test.environment.update(self.plan.environment)
“Plan environment” consistst of multiple sources, in this order:
plan environment file,
$TMT_PLAN_ENVIRONMENT_FILEplan
environment-filekey (`plan: environment and environment-file fmf keyssource)plan
environmentkey (`plan: environment and environment-file fmf keyssource)- importing plan “native” environment (
importing plan: environment fmf key of the importing plansource) environment-filekeyenvironmentkeyimporting plan’s “native” environment
- importing plan “native” environment (
run
--environmentoption (run: --environment and --environment-file CLI optionssource)run
--environment-fileoption (run: --environment and --environment-file CLI optionssource)run
environmentproperty (seems to be the duplication of the previous two inputs)plan intrinsic variables:
TMT_VERSION,TMT_TREE, …
Todo
TMT_SOURCE_DIR is added to test environment:
# (tmt/steps/discover/fmf.py)
for test in self._tests:
test.environment['TMT_SOURCE_DIR'] = EnvVarValue(sourcedir)
# (tmt/steps/discover/shell.py)
if self.data.dist_git_source:
test.environment['TMT_SOURCE_DIR'] = EnvVarValue(sourcedir)
Todo
Document order of precedence for environment key and
environment CLI option in case of provision phases
Todo
Send out an announcement.
Important
The following is the draft of how things should be. It is incomplete, and it does contain several notes, but this is what would document the precedence.
Listing environment variable sources in their order of precedence, from the least preferred to the strongest ones.
1. User-provided guest-specific environment
As set via environment key of
individual provision phases. Applies to user commands executed on
the given guest.
Todo
“Applies” is a strong word, we need to fix plugins that do not do
this but should, like shell - and document those that will not
expose the environment, like ansible.
2. User-provided test-specific environment
As set via environment key of individual tests.
X. User-provided plan-specific environment
Todo
Plan environment consists of several inputs, and it is injected into individual test environment mappings, efefctively placing all of them there with on this level.
Last. Variables set by tmt, run, plan, steps, and plugins
These are the strongest sources, always overriding any preexisting variables.
Note
The variables here are not ordered by their order of precedence, as they do appear sharing the same level to the user code. Individual sources contribute their distinct subsets of variables.
- For all steps
TMT_TREETMT_PLAN_DATATMT_PLAN_ENVIRONMENT_FILETMT_VERSION
- For the
discoverstep TMT_SOURCE_DIR(note: very fishy way of setting it by injecting intoTest.environment)
- For the
- For the
executestep TMT_TEST_NAMETMT_TEST_INVOCATION_PATHTMT_TEST_SUBMITTED_FILESTMT_TEST_DATATMT_TEST_SERIAL_NUMBERTMT_TEST_ITERATION_IDTMT_TEST_METADATATMT_RESTRAINT_COMPATIBLE(note: extend scope toprepare|execute|finish)RSTRNT_TASKNAME(note: extend scope toprepare|execute|finish)
- For the
- For the
executestep with thebeakerlibframework BEAKERLIB_DIRBEAKERLIB_COMMAND_SUBMIT_LOGBEAKERLIB_COMMAND_REPORT_RESULTTESTID
- For the
- For the
execute/upgradephase IN_PLACE_UPGRADE
- For the
- For the
prepare,execute, andfinishstep TMT_REBOOT_REQUESTTMT_REBOOT_COUNTREBOOTCOUNTRSTRNT_REBOOTCOUNTTMT_TEST_RESTART_COUNTTMT_TOPOLOGY_BASHTMT_TOPOLOGY_YAMLTMT_TEST_PIDFILETMT_TEST_PIDFILE_LOCKTMT_TEST_PIDFILE_ROOT
- For the
- For the
prepare/shellandfinish/shellphases TMT_PREPARE_SHELL_URL_REPOSITORYTMT_FINISH_SHELL_URL_REPOSITORY
- For the
Consumed by tmt itself
Note
The following environment variables are set for and consumed by tmt process itself, and never propagated to user environment.
TMT_DEBUGTMT_PLUGINSTMT_FEELING_SAFETMT_CONFIG_DIRTMT_WORKDIR_ROOTNO_COLORTMT_NO_COLORTMT_FORCE_COLORTMT_SHOW_TRACEBACKTMT_OUTPUT_WIDTHTMT_GIT_CREDENTIALS_URL_<suffix>TMT_GIT_CREDENTIALS_VALUE_<suffix>TMT_GIT_CLONE_ATTEMPTSTMT_GIT_CLONE_INTERVALTMT_GIT_CLONE_TIMEOUTTMT_BOOT_TIMEOUTTMT_CONNECT_TIMEOUTTMT_REBOOT_TIMEOUTTMT_SCRIPTS_DIRTMT_SSH_*TMT_REPORT_ARTIFACTS_URLTMT_POLICY_FILETMT_POLICY_NAMETMT_POLICY_ROOTTMT_PLUGIN_${STEP}_${PLUGIN}_${OPTION}