diff --git a/docs/overview.rst b/docs/overview.rst index bd52ef878e..19da2b135f 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -734,7 +734,7 @@ belongs to, and the option name: ``TMT_PLUGIN_${STEP}_${PLUGIN}_${OPTION}`` -All values are upper-cased, with dashes (``-``) replaced by +All names are upper-cased, with dashes (``-``) replaced by underscores (``_``). For example, an execute plugin "tmt" would run with verbosity @@ -762,29 +762,11 @@ The following commands would override the URL:: TMT_PLUGIN_DISCOVER_FMF_URL=https://actual.org/ tmt run ... -For setting flag-like option, 0 and 1 are the expected value. For -example, an interactive mode would be enabled in this run:: +For setting flag-like option, ``0`` and ``1`` are the expected values. +For example, an interactive mode would be enabled in this run:: TMT_PLUGIN_EXECUTE_TMT_INTERACTIVE=1 tmt run ... execute -h tmt ... -.. note:: - - The following applies to situations when a plugin is specified - on the command line only. Keys of plugins specified in fmf files - would not be modified. This is a limit of the current implementation, - and will be addressed in the future:: - - # Here the verbosity will not be increased since the plugin is - # not mentioned on the command line: - $ TMT_PLUGIN_DISCOVER_FMF_VERBOSE=2 tmt run -a - - # Here the environment variable will take effect: - $ TMT_PLUGIN_DISCOVER_FMF_VERBOSE=2 tmt run -a discover -h fmf ... - - Several plugins (``report -h reportportal``, ``report -h polarion``, - ``execute -h tmt``) allow selected variables to be processed, - even when plugin is not specified on the command line. - .. _regular-expressions: Regular Expressions diff --git a/docs/releases/pending/4472.fmf b/docs/releases/pending/4472.fmf new file mode 100644 index 0000000000..6077963bf9 --- /dev/null +++ b/docs/releases/pending/4472.fmf @@ -0,0 +1,8 @@ +description: | + tmt now correctly applies :ref:`plugin-variables` even when + plugin is not mentioned on the command line. This has been a limit + imposed by tmt implementation, where only phases of plugins explicitly + mentioned were modified by environment. For example, ``tmt run report + -h html`` would ignore every ``TMT_PLUGIN_REPORT_*`` environment + variable except those for the ``html`` plugin, ``TMT_PLUGIN_REPORT_HTML_*``. + This limitation has been removed. diff --git a/tests/cli/plugin-envvars/data/.fmf/version b/tests/cli/plugin-envvars/data/.fmf/version new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/cli/plugin-envvars/data/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/tests/cli/plugin-envvars/data/main.fmf b/tests/cli/plugin-envvars/data/main.fmf new file mode 100644 index 0000000000..2944d6e72b --- /dev/null +++ b/tests/cli/plugin-envvars/data/main.fmf @@ -0,0 +1,10 @@ +provision: + how: local + +execute: + script: /bin/true + +report: + - how: html + absolute-paths: false + display-guest: auto diff --git a/tests/cli/plugin-envvars/main.fmf b/tests/cli/plugin-envvars/main.fmf new file mode 100644 index 0000000000..fbc7d6aa54 --- /dev/null +++ b/tests/cli/plugin-envvars/main.fmf @@ -0,0 +1,4 @@ +summary: Verify some basic output of `tmt about` + +tag+: + - provision-local diff --git a/tests/cli/plugin-envvars/test.sh b/tests/cli/plugin-envvars/test.sh new file mode 100755 index 0000000000..70bac92227 --- /dev/null +++ b/tests/cli/plugin-envvars/test.sh @@ -0,0 +1,47 @@ +#!/bin/bash +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +rlJournalStart + rlPhaseStartSetup + rlRun "set -o pipefail" + rlRun "export LANG=C" + rlRun "rundir=$(mktemp -d)" + + rlRun "pushd data" + rlPhaseEnd + + rlPhaseStartTest "Foo" + rlRun "run_tmt=\"tmt -vvv --feeling-safe --log-topic=cli-invocations run --id $rundir --scratch\"" + + rlRun -s "$run_tmt" + rlAssertGrep "ReportPlugin.delegate\(step=report, data=None, raw_data=\{'how': 'html', 'absolute-paths': False, 'display-guest': 'auto', 'name': 'default-0'\}\)" $rundir/log.txt -E + + rlRun -s "TMT_PLUGIN_REPORT_HTML_ABSOLUTE_PATHS=1 TMT_PLUGIN_REPORT_HTML_FILE=/tmp/foo TMT_PLUGIN_REPORT_HTML_DISPLAY_GUEST=never $run_tmt" + rlAssertGrep "ReportPlugin.delegate\(step=report, data=None, raw_data=\{'how': 'html', 'absolute-paths': True, 'display-guest': 'never', 'name': 'default-0', 'file': '/tmp/foo'\}\)" $rundir/log.txt -E + rlPhaseEnd + + rlPhaseStartTest "Verify unknown plugins are reported" + rlRun -s "TMT_PLUGIN_REPORT_XHTML_DISPLAY_GUEST=never $run_tmt" + + rlAssertGrep "warn: Found environment variables for plugin 'report/xhtml', but the plugin was not found. The following environment variables will have no effect:" $rlRun_LOG + rlAssertGrep "warn: TMT_PLUGIN_REPORT_XHTML_DISPLAY_GUEST" $rlRun_LOG + rlPhaseEnd + + rlPhaseStartTest "Verify unused envvars are reported" + rlRun -s "TMT_PLUGIN_REPORT_DISPLAY_DISPLAY_GUEST=never $run_tmt" + + rlAssertGrep "warn: Found environment variables for plugin 'report/display', but the plugin is not used by the plan '/'. The following environment variables will have no effect:" $rlRun_LOG + rlAssertGrep "warn: TMT_PLUGIN_REPORT_DISPLAY_DISPLAY_GUEST" $rlRun_LOG + rlPhaseEnd + + rlPhaseStartTest "Verify unknown options are reported" + rlRun -s "TMT_PLUGIN_REPORT_HTML_HIDE_GUEST=never $run_tmt" 2 + + rlAssertGrep "Failed to find the 'hide-guest' key of the 'report/html' plugin." $rlRun_LOG + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -rf $rundir" + rlPhaseEnd +rlJournalEnd diff --git a/tests/execute/ignore-duration/test.sh b/tests/execute/ignore-duration/test.sh index a9bdc808c9..14f9dc6e48 100755 --- a/tests/execute/ignore-duration/test.sh +++ b/tests/execute/ignore-duration/test.sh @@ -25,17 +25,13 @@ rlJournalStart export TMT_PLUGIN_EXECUTE_TMT_IGNORE_DURATION=1 rlRun "tmt run -vv plan -n /no-option" rlRun "tmt run -vv plan -n /via-plan-true" - # ENV should win over CLI or file values, but to be consistent with - # reporportal/polarion plugin envar is weaker than plan.fmf - rlRun "tmt run -vv plan -n /via-plan-false" "2" + rlRun "tmt run -vv plan -n /via-plan-false" rlPhaseEnd rlPhaseStartTest "With IGNORE_DURATION=0" export TMT_PLUGIN_EXECUTE_TMT_IGNORE_DURATION=0 rlRun "tmt run -vv plan -n /no-option" "2" - # ENV should win over CLI or file values, but to be consistent with - # reporportal/polarion plugin envar is weaker than plan.fmf - rlRun "tmt run -vv plan -n /via-plan-true" + rlRun "tmt run -vv plan -n /via-plan-true" "2" rlRun "tmt run -vv plan -n /via-plan-false" "2" rlPhaseEnd diff --git a/tmt/steps/__init__.py b/tmt/steps/__init__.py index 22fe13c46b..73e8596a46 100644 --- a/tmt/steps/__init__.py +++ b/tmt/steps/__init__.py @@ -61,6 +61,7 @@ Command, CommandOutput, Environment, + EnvVarName, EnvVarValue, GeneralError, HasPhaseWorkdir, @@ -132,6 +133,11 @@ CODE_BLOCK_REGEXP = re.compile(r"^\s*\.\. code-block::.*$\n", re.MULTILINE) +#: A regular expression to cut the special, plugin-specific environment +#: variable names into their components: step, plugin, and option names. +PLUGIN_ENVIRONMENT_VARIABLE_NAME_PATTERN = re.compile( + r'TMT_PLUGIN_(?P[A-Z]+)_(?P[A-Z]+)_(?P