Skip to content

Commit 9ccec7f

Browse files
authored
[telemetry_logging] Fix failure condition in journalctl (#248)
failed_when and assert use `and` for for list items, and only fails/passes when all conditions are met. Currently, failed_when is used to trigger a test failure in the journal tests, however, it is implemented incorrectly, since a list is used, and the task will only fail if all conditions are met. This is incorrect, the test should fail if any of the failure conditions are met. Using assert instead of failed_when means the test will fail if any of the conditions are not met, which is the expected and correct behaviour. This change switches to using assert, and check for the complementary conditions. Using assert also allows for some verbose fail messages to aid in debugging.
1 parent c978637 commit 9ccec7f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

roles/telemetry_logging/tasks/journal_tests.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@
77
cmd: |
88
tstamp=$(date -d '30 minute ago' "+%Y-%m-%d %H:%M:%S")
99
journalctl -t "{{ item }}" --no-pager -S "${tstamp}"
10-
register: journal_wc
10+
register: journalctl
1111
changed_when: false
12-
failed_when:
13-
- journal_wc.stdout_lines | length <= 1
14-
- '"-- No entries --" in journal_wc.stdout'
15-
- journal_wc.stderr_lines | length > 0
12+
13+
- name: |
14+
TEST Get journals {{ item }}
15+
{{ journal_test_id }}
16+
ansible.builtin.assert:
17+
that:
18+
- 'journalctl.stdout_lines | length > 1'
19+
- 'not "-- No entries --" in journalctl.stdout'
20+
- 'journalctl.stderr_lines | length == 0'
21+
fail_msg: |
22+
Journal entry {{ item }} check failed for the following reasons:
23+
{%- if journalctl.stdout_lines | length <= 1 %} journalctl output is too short.{% endif %}
24+
{%- if "-- No entries --" in journalctl.stdout %} journalctl output contains "-- No entries --".{% endif %}
25+
{%- if journalctl.stdout_lines | length > 0 %} journalctl has an error message.{% endif %}
26+
success_msg: "The test passed!"

0 commit comments

Comments
 (0)