test: Check that the journal file was actually created (#36821)

If the test fails in the mkosi setup logic the journal file will never
be created so let's add some checks.
This commit is contained in:
Daan De Meyer
2025-03-21 14:31:20 +01:00
committed by GitHub
2 changed files with 14 additions and 15 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ actions:
post-upstream-clone:
# Use the Fedora Rawhide specfile
- git clone https://src.fedoraproject.org/rpms/systemd .packit_rpm --depth=1
- git clone https://src.fedoraproject.org/rpms/systemd .packit_rpm
- bash -c 'git -C .packit_rpm checkout "$(grep GIT_COMMIT= mkosi.images/build/mkosi.conf.d/centos-fedora/mkosi.conf | cut -d= -f2)"'
- bash -c 'echo "%bcond upstream 1" > .packit_rpm/systemd.spec.new'
- bash -c 'echo "%define meson_extra_configure_options --werror" >> .packit_rpm/systemd.spec.new'
+13 -14
View File
@@ -574,29 +574,28 @@ def main() -> None:
and not sanitizer
):
journal_file.unlink(missing_ok=True)
elif os.getenv('TEST_JOURNAL_USE_TMP', '0') == '1':
elif os.getenv('TEST_JOURNAL_USE_TMP', '0') == '1' and journal_file.exists():
dst = args.meson_build_dir / f'test/journal/{name}.journal'
dst.parent.mkdir(parents=True, exist_ok=True)
shutil.move(journal_file, dst)
journal_file = shutil.move(journal_file, dst)
if shell or (result.returncode in (args.exit_code, 77) and not coredumps and not sanitizer):
exit(0 if shell or result.returncode == args.exit_code else 77)
ops = []
if journal_file.exists():
ops = []
if os.getenv('GITHUB_ACTIONS'):
id = os.environ['GITHUB_RUN_ID']
workflow = os.environ['GITHUB_WORKFLOW']
iteration = os.environ['GITHUB_RUN_ATTEMPT']
artifact = (
f'ci-{workflow}-{id}-{iteration}-{summary.distribution}-{summary.release}-failed-test-journals'
)
ops += [f'gh run download {id} --name {artifact} -D ci/{artifact}']
journal_file = Path(f'ci/{artifact}/test/journal/{name}.journal')
if os.getenv('GITHUB_ACTIONS'):
id = os.environ['GITHUB_RUN_ID']
wf = os.environ['GITHUB_WORKFLOW']
iter = os.environ['GITHUB_RUN_ATTEMPT']
artifact = f'ci-{wf}-{id}-{iter}-{summary.distribution}-{summary.release}-failed-test-journals'
ops += [f'gh run download {id} --name {artifact} -D ci/{artifact}']
journal_file = Path(f'ci/{artifact}/test/journal/{name}.journal')
ops += [f'journalctl --file {journal_file} --no-hostname -o short-monotonic -u {args.unit} -p info']
ops += [f'journalctl --file {journal_file} --no-hostname -o short-monotonic -u {args.unit} -p info']
print(f'Test failed, relevant logs can be viewed with: \n\n{(" && ".join(ops))}\n', file=sys.stderr)
print(f'Test failed, relevant logs can be viewed with: \n\n{(" && ".join(ops))}\n', file=sys.stderr)
# 0 also means we failed so translate that to a non-zero exit code to mark the test as failed.
exit(result.returncode or 1)