From 09bdb9f121f0097461dba40d1689087fc3112462 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 20 Nov 2023 23:34:09 +0100 Subject: [PATCH] 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). --- test/test-functions | 57 +++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/test/test-functions b/test/test-functions index dfe4b8e..674ba1c 100644 --- a/test/test-functions +++ b/test/test-functions @@ -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 - 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 [ -n "${TEST_SHOW_JOURNAL}" ]; then - echo "---- $j ----" - "$JOURNALCTL" --no-pager -o short-monotonic --no-hostname --priority="${TEST_SHOW_JOURNAL}" -D "$j" + 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 - rm -r "$j" - done - - if ! get_bool "$save"; then - return 0 - fi + if [[ -n "${SUDO_USER:-}" ]]; then + setfacl -R -m "user:$SUDO_USER:r-X" "$dest" + fi - if [ -n "${SUDO_USER}" ]; then - setfacl -m "user:${SUDO_USER:?}:r-X" "$dest"* + # we want to print this sometime later, so save this in a variable + JOURNAL_LIST="$(ls -lR "$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() { -- 2.7.4