Skip to content

Commit 3336a03

Browse files
lukaszachypsss
andauthored
Allow to ignore duration in tests (#3569)
There are other ways to adjust this value, but sometimes it is just easier to just let test run as long as they need. Co-authored-by: Petr Šplíchal <[email protected]>
1 parent d1ef9cb commit 3336a03

File tree

10 files changed

+116
-0
lines changed

10 files changed

+116
-0
lines changed

docs/overview.rst

+5
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@ TMT_TEST_PIDFILE_ROOT
629629
of temporary directory permissions, e.g. ``chmod 1777``, to
630630
allow access to users with all privilege levels.
631631

632+
.. _plugin-variables:
633+
632634
Plugin Variables
633635
----------------
634636

@@ -685,6 +687,9 @@ example, an interactive mode would be enabled in this run::
685687
# Here the environment variable will take effect:
686688
$ TMT_PLUGIN_DISCOVER_FMF_VERBOSE=2 tmt run -a discover -h fmf ...
687689

690+
Several plugins (``report -h reportportal``, ``report -h polarion``,
691+
``execute -h tmt``) allow selected variables to be processed,
692+
even when plugin is not specified on the command line.
688693

689694
.. _regular-expressions:
690695

docs/releases.rst

+6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
tmt-1.44.0
99
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1010

11+
1112
The ``results.yaml`` file is now populated with test results
1213
right after the ``discover`` step is finished and the file is
1314
continuously updated during test execution to provide the latest
1415
results. This change also adds a new ``pending`` result outcome
1516
to the :ref:`/spec/results` specification for tests that were
1617
discovered but not yet executed.
1718

19+
Execute tmt option ``--ignore-duration`` makes tmt to execute
20+
the test as long as it needs. Execute plugin doesn't need to be
21+
specified on the commandline for :ref:`plugin-variables` to work
22+
for this option.
23+
1824

1925
tmt-1.43.0
2026
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/test:
2+
test: sleep 4
3+
duration: "1"
4+
5+
/plan:
6+
discover:
7+
how: fmf
8+
provision:
9+
how: local
10+
execute:
11+
how: tmt
12+
/no-option:
13+
/via-plan-true:
14+
execute+:
15+
ignore-duration: true
16+
/via-plan-false:
17+
execute+:
18+
ignore-duration: false
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
summary: Verify that the ignore-duration is correctly handled
2+
duration: 5m

tests/execute/ignore-duration/test.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
. /usr/share/beakerlib/beakerlib.sh || exit 1
3+
4+
5+
rlJournalStart
6+
rlPhaseStartSetup
7+
rlRun "tmp=\$(mktemp -d)" 0 "Creating tmp directory"
8+
rlRun "export TMT_WORKDIR_ROOT=$tmp"
9+
rlRun "pushd data"
10+
rlPhaseEnd
11+
12+
rlPhaseStartTest "No envvar used"
13+
rlRun -s "tmt run -vv plan -n /no-option" "2"
14+
rlAssertGrep 'errr /demo/test (timeout)' $rlRun_LOG '-F'
15+
16+
rlRun "tmt run -vv plan -n /via-plan-true" "0"
17+
18+
rlRun "tmt run -vv plan -n /via-plan-false" "2"
19+
rlAssertGrep 'errr /demo/test (timeout)' $rlRun_LOG '-F'
20+
rlPhaseEnd
21+
22+
rlPhaseStartTest "With IGNORE_DURATION=1"
23+
export TMT_PLUGIN_EXECUTE_TMT_IGNORE_DURATION=1
24+
rlRun "tmt run -vv plan -n /no-option"
25+
rlRun "tmt run -vv plan -n /via-plan-true"
26+
# ENV should win over CLI or file values, but to be consistent with
27+
# reporportal/polarion plugin envar is weaker than plan.fmf
28+
rlRun "tmt run -vv plan -n /via-plan-false" "2"
29+
rlPhaseEnd
30+
31+
rlPhaseStartTest "With IGNORE_DURATION=0"
32+
export TMT_PLUGIN_EXECUTE_TMT_IGNORE_DURATION=0
33+
rlRun "tmt run -vv plan -n /no-option" "2"
34+
# ENV should win over CLI or file values, but to be consistent with
35+
# reporportal/polarion plugin envar is weaker than plan.fmf
36+
rlRun "tmt run -vv plan -n /via-plan-true"
37+
rlRun "tmt run -vv plan -n /via-plan-false" "2"
38+
rlPhaseEnd
39+
40+
41+
rlPhaseStartCleanup
42+
rlRun "popd"
43+
rlRun "rm -rf $tmp" 0 "Removing tmp directory"
44+
rlPhaseEnd
45+
rlJournalEnd

tmt/schemas/execute/tmt.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ properties:
2323
exit-first:
2424
type: boolean
2525

26+
ignore-duration:
27+
type: boolean
28+
2629
# name attribute can exist if more methods
2730
name:
2831
type: string

tmt/steps/execute/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
Path,
3232
ShellScript,
3333
Stopwatch,
34+
configure_bool_constant,
3435
format_duration,
3536
format_timestamp,
3637
)
@@ -261,6 +262,18 @@ class ExecuteStepData(tmt.steps.WhereableStepData, tmt.steps.StepData):
261262
option='--duration',
262263
help='The maximal time allowed for the test to run.',
263264
)
265+
ignore_duration: bool = field(
266+
default=configure_bool_constant(False, 'TMT_PLUGIN_EXECUTE_TMT_IGNORE_DURATION'),
267+
option='--ignore-duration',
268+
is_flag=True,
269+
envvar="TMT_PLUGIN_EXECUTE_TMT_IGNORE_DURATION",
270+
help="""
271+
Ignore test duration value and allow test to run forever.
272+
Can be set by environment variable even when step is not
273+
specified on the commandline. This environment variable
274+
will be replaced by fmf config file or CLI arguments.
275+
""",
276+
)
264277
exit_first: bool = field(
265278
default=False,
266279
option=('-x', '--exit-first'),
@@ -709,6 +722,7 @@ def go(
709722
logger: tmt.log.Logger,
710723
) -> None:
711724
self.go_prolog(logger)
725+
logger.verbose('ignore-duration', self.data.ignore_duration, 'green', level=2)
712726
logger.verbose('exit-first', self.data.exit_first, 'green', level=2)
713727

714728
@property

tmt/steps/execute/internal.py

+4
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,10 @@ def _save_process(
560560

561561
timeout = None
562562

563+
elif self.data.ignore_duration:
564+
logger.debug("Test duration is not effective due ignore-duration option.")
565+
timeout = None
566+
563567
else:
564568
timeout = tmt.utils.duration_to_seconds(
565569
test.duration, tmt.base.DEFAULT_TEST_DURATION_L1

tmt/utils/__init__.py

+18
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@ def configure_constant(default: int, envvar: str) -> int:
120120
) from exc
121121

122122

123+
def configure_bool_constant(default: bool, envvar: str) -> bool:
124+
"""
125+
Deduce the bool value of global constant.
126+
127+
Value '1' means True, all other values mean False.
128+
129+
:param default: the default value of the constant.
130+
:param envvar: name of the optional environment variable which would
131+
override the default value.
132+
:returns: value extracted from the environment variable, or the
133+
given default value if the variable did not exist.
134+
"""
135+
value = os.environ.get(envvar)
136+
if value is None:
137+
return default
138+
return value == "1"
139+
140+
123141
log = fmf.utils.Logging('tmt').logger
124142

125143

0 commit comments

Comments
 (0)