Skip to content

Commit 50d53a9

Browse files
authored
Prevent tmt scripts from running outside of test context (teemtee#3833)
Now when scripts are moved, they are not ready to be executed anywhere but in `execute`. Adding a short check to prevent them being used in `prepare` or `finish`. I expected that will change gradually, e.g. there is no reason to not use `tmt-abort` in `prepare` scripts, for example, except its connection to `execute. Part of the effort to implement teemtee#902.
1 parent 47bd8f3 commit 50d53a9

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

tmt/steps/scripts/tmt-abort

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/bash
2+
3+
if [ -z "$TMT_TEST_PIDFILE" ]; then
4+
echo "tmt-abort can be used only in the context of a running test."
5+
exit 1
6+
fi
7+
28
# Create the abort file.
39
touch "$TMT_TEST_DATA/abort"
410
# Kill PPID to exit test execution.

tmt/steps/scripts/tmt-file-submit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/bash
2+
3+
if [ -z "$TMT_TEST_PIDFILE" ]; then
4+
echo "tmt-file-submit can be used only in the context of a running test."
5+
exit 1
6+
fi
7+
28
set -o errexit -o pipefail -o noclobber -o nounset
39

410
die() { echo "$*" >&2; exit 2; } # complain to STDERR and exit with error

tmt/steps/scripts/tmt-reboot

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
22

3+
if [ -z "$TMT_TEST_PIDFILE" ]; then
4+
echo "tmt-reboot can be used only in the context of a running test."
5+
exit 1
6+
fi
7+
38
# Two-level reboot: `tmt-reboot` extracts command line arguments, and
49
# calls `tmt-reboot-core` *while holding the tmt test pidfile lock!*
510
# That should assure the pidfile would exist and contain valid info.

tmt/steps/scripts/tmt-report-result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/bash
2+
3+
if [ -z "$TMT_TEST_PIDFILE" ]; then
4+
echo "tmt-report-result can be used only in the context of a running test."
5+
exit 1
6+
fi
7+
28
set -o errexit -o pipefail -o noclobber -o nounset
39

410
REPORT_RESULT_OUTPUTFILE="$TMT_TEST_DATA/tmt-report-results.yaml"

0 commit comments

Comments
 (0)