Skip to content

Commit

Permalink
Fixes the tmt reboot test, updating the pidfile location in the scripts.
Browse files Browse the repository at this point in the history
Also formats the pid directory creation command.

Signed-off-by: mcasquer <[email protected]>
  • Loading branch information
mcasquer committed Nov 6, 2024
1 parent 53bcb02 commit 2eba702
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
8 changes: 7 additions & 1 deletion tests/execute/reboot/out-of-session.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
rlJournalStart
rlPhaseStartSetup
rlRun "PROVISION_HOW=${PROVISION_HOW:-container}"

# To allow running the test outside of tmt.
rlRun "TMT_TEST_PIDFILE_ROOT=${TMT_TEST_PIDFILE_ROOT:-/var/tmp/tmt/pid}"
rlRun "TMT_TEST_PIDFILE=${TMT_TEST_PIDFILE:-$TMT_TEST_PIDFILE_ROOT/tmt-test.pid}"
rlRun "TMT_TEST_PIDFILE_LOCK=${TMT_TEST_PIDFILE_LOCK:-$TMT_TEST_PIDFILE.lock}"

rlRun "run=\$(mktemp -d -p /var/tmp)" 0 "Create run directory"
rlRun "set -o pipefail"
rlRun "pushd out-of-session"
Expand Down Expand Up @@ -39,7 +45,7 @@ rlJournalStart
# and use it to issue a `tmt-reboot` from outside the direct process tree of the test.
set -x

tmt_reboot_command="export TMT_TEST_PIDFILE=/var/tmp/tmt-test.pid; export TMT_TEST_PIDFILE_LOCK=/var/tmp/tmt-test.pid.lock; export TMT_DEBUG=1; tmt-reboot"
tmt_reboot_command="export TMT_TEST_PIDFILE=$TMT_TEST_PIDFILE; export TMT_TEST_PIDFILE_LOCK=$TMT_TEST_PIDFILE_LOCK; export TMT_DEBUG=1; tmt-reboot"

if [ "$PROVISION_HOW" = "container" ]; then
podman_exec="$(sed -nr 's/\s*Run command: (podman exec .*) \/bin\/bash.*cd.*/\1/p' tmt.output | head -1)"
Expand Down
4 changes: 4 additions & 0 deletions tmt/steps/execute/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
format_timestamp,
)

# Note: if modified, pidfile root, filename, and lock filename must be
# also changed in `tmt-reboot` and `tmt-reboot-core` scripts.
TEST_PIDFILE_FILENAME = 'tmt-test.pid'
TEST_PIDFILE_LOCK_FILENAME = f'{TEST_PIDFILE_FILENAME}.lock'

Expand Down Expand Up @@ -254,6 +256,8 @@ def _test_environment(
assert isinstance(self.parent, tmt.steps.execute.Execute)
assert self.parent.plan.my_run is not None

environment['TMT_TEST_PIDFILE_ROOT'] = EnvVarValue(
effective_pidfile_root())
environment['TMT_TEST_PIDFILE'] = EnvVarValue(
effective_pidfile_root() / TEST_PIDFILE_FILENAME)
environment['TMT_TEST_PIDFILE_LOCK'] = EnvVarValue(
Expand Down
4 changes: 3 additions & 1 deletion tmt/steps/execute/scripts/tmt-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

[ -n "$TMT_DEBUG" ] && set -x

TMT_TEST_PIDFILE_LOCK="${TMT_TEST_PIDFILE_LOCK:-/var/tmp/tmt-test.pid}"
TMT_TEST_PIDFILE_ROOT="${TMT_TEST_PIDFILE_ROOT:-/var/tmp/tmt/pid}"
TMT_TEST_PIDFILE="${TMT_TEST_PIDFILE:-$TMT_TEST_PIDFILE_ROOT/tmt-test.pid}"
TMT_TEST_PIDFILE_LOCK="${TMT_TEST_PIDFILE_LOCK:-$TMT_TEST_PIDFILE.lock}"

PATH=/sbin:/usr/sbin:$PATH

Expand Down
4 changes: 3 additions & 1 deletion tmt/steps/execute/scripts/tmt-reboot-core
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

[ -n "$TMT_DEBUG" ] && set -x

TMT_TEST_PIDFILE="${TMT_TEST_PIDFILE:-/var/tmp/tmt-test.pid}"
TMT_TEST_PIDFILE_ROOT="${TMT_TEST_PIDFILE_ROOT:-/var/tmp/tmt/pid}"
TMT_TEST_PIDFILE="${TMT_TEST_PIDFILE:-$TMT_TEST_PIDFILE_ROOT/tmt-test.pid}"
TMT_TEST_PIDFILE_LOCK="${TMT_TEST_PIDFILE_LOCK:-$TMT_TEST_PIDFILE.lock}"

if [ ! -e "$TMT_TEST_PIDFILE" ]; then
echo "There is no running test to signal the reboot to!"
Expand Down
11 changes: 8 additions & 3 deletions tmt/steps/provision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,9 +925,14 @@ def setup(self) -> None:
"""
from tmt.steps.execute.internal import effective_pidfile_root
pid_directory = effective_pidfile_root()
command = f"if [ ! -d {pid_directory} ]; then mkdir -p {pid_directory} \
&& chmod ugo+rwx {pid_directory}; fi"
self.execute(ShellScript(command))
self.execute(ShellScript(
f"""
if [ ! -d {pid_directory} ]; then \
mkdir -p {pid_directory} \
&& chmod ugo+rwx {pid_directory}; \
fi
"""
))

# A couple of requiremens for this field:
#
Expand Down

0 comments on commit 2eba702

Please sign in to comment.