Skip to content

Commit

Permalink
Add ability to enforce flushing of artifacts during reboot
Browse files Browse the repository at this point in the history
There are situations when getting the artifacts just before reboot
is very desired as the reboot may be risky operation which may lead
into situation when the system is not reachable, TMT timeouts
and is no longer able to fetch anything from the system.

This change adds optional -f switch to the tmt-reboot command
where the test can signal that it is entering "critical reboot" and
it's requesting to flush the artifacts produced by the test before
the system reboots.
  • Loading branch information
pholica committed May 13, 2024
1 parent 40ec859 commit dd87d68
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions tmt/steps/execute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def handle_reboot(self) -> bool:

reboot_command: Optional[ShellScript] = None
timeout: Optional[int] = None
flush_artifacts: Optional[bool] = False

if self.hard_reboot_requested:
pass
Expand All @@ -362,6 +363,13 @@ def handle_reboot(self) -> bool:
except ValueError:
timeout = None

flush_artifacts = reboot_data.get('flush_artifacts', flush_artifacts)

if flush_artifacts:
# Pull artifacts created in the plan data directory
self.logger.debug("Flush artifacts requested, pull the test data directory.", level=2)
self.guest.pull(source=self.test_data_path)

os.remove(self.reboot_request_path)
self.guest.push(self.test_data_path)

Expand Down
6 changes: 4 additions & 2 deletions tmt/steps/execute/scripts/tmt-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ PATH=/sbin:/usr/sbin:$PATH
command=""
timeout=""
efi=True
while getopts "c:t:e" flag; do
flush_artifacts=False
while getopts "c:t:e:f" flag; do
case "${flag}" in
c) command="${OPTARG}";;
t) timeout="${OPTARG}";;
e) efi=False;;
f) flush_artifacts=True;;
esac
done

Expand All @@ -37,4 +39,4 @@ if [ $efi = True ]; then
fi
fi

flock "$TMT_TEST_PIDFILE_LOCK" tmt-reboot-core "$command" "$timeout"
flock "$TMT_TEST_PIDFILE_LOCK" tmt-reboot-core "$command" "$timeout" "$flush_artifacts"
3 changes: 2 additions & 1 deletion tmt/steps/execute/scripts/tmt-reboot-core
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fi

command="$1"
timeout="$2"
flush_artifacts="$3"

# Thanks to being run while holding the pidfile lock, the file exists and should
# no go away. It should be safe to read test PID and reboot-request filepath from
Expand All @@ -20,5 +21,5 @@ test_reboot_file="$(awk '{print $2}' < "$TMT_TEST_PIDFILE")"

mkdir -p "$(dirname "$test_reboot_file")"

printf '{"command": "%s", "timeout": "%s"}' "$command" "$timeout" > "$test_reboot_file"
printf '{"command": "%s", "timeout": "%s", "flush_artifacts": "%s"}' "$command" "$timeout" "$flush_artifacts" > "$test_reboot_file"
kill "$test_pid"

0 comments on commit dd87d68

Please sign in to comment.