mirror of
https://github.com/systemd/systemd
synced 2024-10-14 20:17:52 +00:00
test: clean up the save_journal() stuff a bit
Let's save all journals from the test machine instead of calling export on each journal file separately, which makes the code less complicated (and probably faster).
This commit is contained in:
parent
36f4476361
commit
09bdb9f121
|
@ -1765,48 +1765,53 @@ check_coverage_reports() {
|
|||
}
|
||||
|
||||
save_journal() {
|
||||
local source_dir="${1:?}"
|
||||
local state="${2:?}"
|
||||
# Default to always saving journal
|
||||
local save="yes"
|
||||
local dest_dir dest_name dest
|
||||
|
||||
if [ "${TEST_SAVE_JOURNAL}" = "no" ]; then
|
||||
if [[ "${TEST_SAVE_JOURNAL:-}" == "no" ]]; then
|
||||
save="no"
|
||||
elif [ "${TEST_SAVE_JOURNAL}" = "fail" ] && [ "$2" = "0" ]; then
|
||||
elif [[ "${TEST_SAVE_JOURNAL:-}" == "fail" && "$state" -eq 0 ]]; then
|
||||
save="no"
|
||||
fi
|
||||
|
||||
if [ -n "${ARTIFACT_DIRECTORY}" ]; then
|
||||
dest="${ARTIFACT_DIRECTORY}/${testname:?}.journal"
|
||||
if [[ -n "${ARTIFACT_DIRECTORY:-}" ]]; then
|
||||
dest_dir="$ARTIFACT_DIRECTORY"
|
||||
dest_name="${testname:?}.journal"
|
||||
else
|
||||
dest="${TESTDIR:?}/system.journal"
|
||||
dest_dir="${TESTDIR:?}"
|
||||
dest_name="system.journal"
|
||||
fi
|
||||
|
||||
for j in "${1:?}"/*; do
|
||||
if get_bool "$save"; then
|
||||
if [ "$SYSTEMD_JOURNAL_REMOTE" = "" ]; then
|
||||
cp -a "$j" "$dest"
|
||||
else
|
||||
"$SYSTEMD_JOURNAL_REMOTE" -o "$dest" --getter="$JOURNALCTL -o export -D $j"
|
||||
fi
|
||||
if [[ -n "$TEST_SHOW_JOURNAL" ]]; then
|
||||
echo "---- $source_dir ----"
|
||||
"$JOURNALCTL" --no-pager -o short-monotonic --no-hostname --priority="$TEST_SHOW_JOURNAL" -D "$source_dir"
|
||||
fi
|
||||
|
||||
if get_bool "$save"; then
|
||||
# If we don't have systemd-journal-remote copy all journals from /var/log/journal/
|
||||
# to $dest_dir/journals/ as is, otherwise merge all journals into a single .journal
|
||||
# file
|
||||
if [[ -z "${SYSTEMD_JOURNAL_REMOTE:-}" ]]; then
|
||||
dest="$dest_dir/journals"
|
||||
mkdir -p "$dest"
|
||||
cp -a "$source_dir/*" "$dest/"
|
||||
else
|
||||
dest="$dest_dir/$dest_name"
|
||||
"$SYSTEMD_JOURNAL_REMOTE" -o "$dest" --getter="$JOURNALCTL -o export -D $source_dir"
|
||||
fi
|
||||
|
||||
if [ -n "${TEST_SHOW_JOURNAL}" ]; then
|
||||
echo "---- $j ----"
|
||||
"$JOURNALCTL" --no-pager -o short-monotonic --no-hostname --priority="${TEST_SHOW_JOURNAL}" -D "$j"
|
||||
if [[ -n "${SUDO_USER:-}" ]]; then
|
||||
setfacl -R -m "user:$SUDO_USER:r-X" "$dest"
|
||||
fi
|
||||
|
||||
rm -r "$j"
|
||||
done
|
||||
|
||||
if ! get_bool "$save"; then
|
||||
return 0
|
||||
# we want to print this sometime later, so save this in a variable
|
||||
JOURNAL_LIST="$(ls -lR "$dest")"
|
||||
fi
|
||||
|
||||
if [ -n "${SUDO_USER}" ]; then
|
||||
setfacl -m "user:${SUDO_USER:?}:r-X" "$dest"*
|
||||
fi
|
||||
|
||||
# we want to print this sometime later, so save this in a variable
|
||||
JOURNAL_LIST="$(ls -l "$dest"*)"
|
||||
rm -rf "${source_dir:?}"/*
|
||||
}
|
||||
|
||||
check_result_common() {
|
||||
|
|
Loading…
Reference in a new issue