]
result = subprocess.run(cmd)
+
# Return code 123 is the expected success code
- if result.returncode != 123:
- if result.returncode != 77 and journal_file:
- cmd = [
- 'journalctl',
- '--no-hostname',
- '-o', 'short-monotonic',
- '--file', journal_file,
- '-u', test_unit,
- '-p', 'info',
- ]
- print("Test failed, relevant logs can be viewed with: \n\n"
- f"{shlex.join(str(a) for a in cmd)}\n", file=sys.stderr)
- exit(result.returncode or 1)
+ if result.returncode in (123, 77):
+ # Do not keep journal files for tests that don't fail.
+ if journal_file:
+ journal_file.unlink(missing_ok=True)
+
+ exit(0 if result.returncode == 123 else 77)
- # Do not keep journal files for tests that don't fail.
if journal_file:
- journal_file.unlink(missing_ok=True)
+ cmd = [
+ 'journalctl',
+ '--no-hostname',
+ '-o', 'short-monotonic',
+ '--file', journal_file,
+ '-u', test_unit,
+ '-p', 'info',
+ ]
+ print("Test failed, relevant logs can be viewed with: \n\n"
+ f"{shlex.join(str(a) for a in cmd)}\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)
if __name__ == '__main__':