Skip to content

Commit 62941e2

Browse files
moreatijadacyrus
authored andcommitted
tests: Improve Ansible fail_msg formatting
By switching to block style (`|`) with clip (no `-` or `+`) the failure messages don't require quoting and gain a single trailing newline. This causes Ansible to print them as block style, when using the yaml stdout callback plugin. As a result the values have one less layer of quoting and quote escaping, making them much easier to read.
1 parent a89f311 commit 62941e2

File tree

96 files changed

+407
-193
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+407
-193
lines changed

docs/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Unreleased
2323

2424
* :gh:issue:`1106` :mod:`ansible_mitogen`: Support for `ansible_ssh_password`
2525
connection variable, and templated SSH connection password.
26+
* :gh:issue:`1136` tests: Improve Ansible fail_msg formatting.
2627

2728

2829
v0.3.11 (2024-10-30)

tests/ansible/integration/action/copy.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@
7777
that:
7878
- item.stat.checksum == item.item.expected_checksum
7979
quiet: true # Avoid spamming stdout with 400 kB of item.item.content
80-
fail_msg: item={{ item }}
80+
fail_msg: |
81+
item={{ item }}
8182
with_items: "{{ stat.results }}"
8283
loop_control:
8384
label: "{{ item.stat.path }}"

tests/ansible/integration/action/fixup_perms2__copy.yml

+10-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
- assert:
1717
that:
1818
- out.stat.mode in ("0644", "0664")
19-
fail_msg: out={{out}}
19+
fail_msg: |
20+
out={{ out }}
2021
2122
- name: "Copy files from content: arg"
2223
copy:
@@ -29,7 +30,8 @@
2930
- assert:
3031
that:
3132
- out.stat.mode == "0400"
32-
fail_msg: out={{out}}
33+
fail_msg: |
34+
out={{ out }}
3335
3436
- name: Cleanup local weird mode file
3537
file:
@@ -55,7 +57,8 @@
5557
- assert:
5658
that:
5759
- out.stat.mode in ("0644", "0664")
58-
fail_msg: out={{out}}
60+
fail_msg: |
61+
out={{ out }}
5962
6063
- name: Copy file with weird mode, preserving mode
6164
copy:
@@ -69,7 +72,8 @@
6972
- assert:
7073
that:
7174
- out.stat.mode == "1462"
72-
fail_msg: out={{out}}
75+
fail_msg: |
76+
out={{ out }}
7377
7478
- name: Copy file with weird mode, explicit mode
7579
copy:
@@ -84,7 +88,8 @@
8488
- assert:
8589
that:
8690
- out.stat.mode == "1461"
87-
fail_msg: out={{out}}
91+
fail_msg: |
92+
out={{ out }}
8893
8994
- name: Cleanup
9095
file:

tests/ansible/integration/action/low_level_execute_command.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
- 'raw.rc == 0'
1616
- 'raw.stdout_lines[-1]|to_text == "2"'
1717
- 'raw.stdout[-1]|to_text == "2"'
18-
fail_msg: raw={{raw}}
18+
fail_msg: |
19+
raw={{ raw }}
1920
2021
- name: Run raw module with sudo
2122
become: true
@@ -39,6 +40,7 @@
3940
["root\r\n"],
4041
["root"],
4142
)
42-
fail_msg: raw={{raw}}
43+
fail_msg: |
44+
raw={{ raw }}
4345
tags:
4446
- low_level_execute_command

tests/ansible/integration/action/make_tmp_path.yml

+18-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@
4242
assert:
4343
that:
4444
- good_temp_path == good_temp_path2
45-
fail_msg: good_temp_path={{good_temp_path}} good_temp_path2={{good_temp_path2}}
45+
fail_msg: |
46+
good_temp_path={{ good_temp_path }}
47+
good_temp_path2={{ good_temp_path2 }}
4648
4749
- name: "Verify different subdir for both tasks"
4850
assert:
4951
that:
5052
- tmp_path.path != tmp_path2.path
51-
fail_msg: tmp_path={{tmp_path}} tmp_path2={{tmp_path2}}
53+
fail_msg: |
54+
tmp_path={{ tmp_path }}
55+
tmp_path2={{ tmp_path2 }}
5256
5357
#
5458
# Verify subdirectory removal.
@@ -69,7 +73,9 @@
6973
that:
7074
- not stat1.stat.exists
7175
- not stat2.stat.exists
72-
fail_msg: stat1={{stat1}} stat2={{stat2}}
76+
fail_msg: |
77+
stat1={{ stat1 }}
78+
stat2={{ stat2 }}
7379
7480
#
7581
# Verify good directory persistence.
@@ -84,7 +90,8 @@
8490
assert:
8591
that:
8692
- stat.stat.exists
87-
fail_msg: stat={{stat}}
93+
fail_msg: |
94+
stat={{ stat }}
8895
8996
#
9097
# Write some junk into the temp path.
@@ -107,7 +114,8 @@
107114
- assert:
108115
that:
109116
- not out.stat.exists
110-
fail_msg: out={{out}}
117+
fail_msg: |
118+
out={{ out }}
111119
112120
#
113121
# root
@@ -126,7 +134,9 @@
126134
that:
127135
- tmp_path2.path != tmp_path_root.path
128136
- tmp_path2.path|dirname != tmp_path_root.path|dirname
129-
fail_msg: tmp_path_root={{tmp_path_root}} tmp_path2={{tmp_path2}}
137+
fail_msg: |
138+
tmp_path_root={{ tmp_path_root }}
139+
tmp_path2={{ tmp_path2 }}
130140
131141
#
132142
# readonly homedir
@@ -157,7 +167,8 @@
157167
that:
158168
- out.module_path.startswith(good_temp_path2)
159169
- out.module_tmpdir.startswith(good_temp_path2)
160-
fail_msg: out={{out}}
170+
fail_msg: |
171+
out={{ out }}
161172
tags:
162173
- make_tmp_path
163174
- mitogen_only

tests/ansible/integration/action/remote_expand_user.yml

+12-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
register: out
2727
- assert:
2828
that: out.result == user_facts.ansible_facts.ansible_user_dir ~ '/foo'
29-
fail_msg: out={{out}}
29+
fail_msg: |
30+
out={{ out }}
3031
3132
- name: "Expand ~/foo with become active. ~ is become_user's home."
3233
action_passthrough:
@@ -49,7 +50,8 @@
4950
register: out
5051
- assert:
5152
that: out.result == user_facts.ansible_facts.ansible_user_dir ~ '/foo'
52-
fail_msg: out={{out}}
53+
fail_msg: |
54+
out={{ out }}
5355
5456
- name: "Expanding $HOME/foo has no effect."
5557
action_passthrough:
@@ -60,7 +62,8 @@
6062
register: out
6163
- assert:
6264
that: out.result == '$HOME/foo'
63-
fail_msg: out={{out}}
65+
fail_msg: |
66+
out={{ out }}
6467
6568
# ------------------------
6669

@@ -73,7 +76,8 @@
7376
register: out
7477
- assert:
7578
that: out.result == user_facts.ansible_facts.ansible_user_dir ~ '/foo'
76-
fail_msg: out={{out}}
79+
fail_msg: |
80+
out={{ out }}
7781
7882
- name: "sudoable; Expand ~/foo with become active. ~ is become_user's home."
7983
action_passthrough:
@@ -97,7 +101,8 @@
97101
register: out
98102
- assert:
99103
that: out.result == user_facts.ansible_facts.ansible_user_dir ~ '/foo'
100-
fail_msg: out={{out}}
104+
fail_msg: |
105+
out={{ out }}
101106
102107
- name: "sudoable; Expanding $HOME/foo has no effect."
103108
action_passthrough:
@@ -108,6 +113,7 @@
108113
register: out
109114
- assert:
110115
that: out.result == '$HOME/foo'
111-
fail_msg: out={{out}}
116+
fail_msg: |
117+
out={{ out }}
112118
tags:
113119
- remote_expand_user

tests/ansible/integration/action/remote_file_exists.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
register: out
1313
- assert:
1414
that: out.result == False
15-
fail_msg: out={{out}}
15+
fail_msg: |
16+
out={{ out }}
1617
1718
- name: Ensure does-exist does
1819
copy:
@@ -24,7 +25,8 @@
2425
register: out
2526
- assert:
2627
that: out.result == True
27-
fail_msg: out={{out}}
28+
fail_msg: |
29+
out={{ out }}
2830
2931
- name: Cleanup
3032
file:

tests/ansible/integration/action/remove_tmp_path.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
- assert:
2424
that:
2525
- not out2.stat.exists
26-
fail_msg: out={{out}}
26+
fail_msg: |
27+
out={{ out }}
2728
2829
- stat:
2930
path: "{{out.src|dirname}}"
@@ -32,7 +33,8 @@
3233
- assert:
3334
that:
3435
- not out2.stat.exists
35-
fail_msg: out={{out}}
36+
fail_msg: |
37+
out={{ out }}
3638
3739
- file:
3840
path: /tmp/remove_tmp_path_test

tests/ansible/integration/action/synchronize.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666

6767
- assert:
6868
that: outout == "item!"
69-
fail_msg: outout={{outout}}
69+
fail_msg: |
70+
outout={{ outout }}
7071
when: False
7172

7273
# TODO: https://github.com/dw/mitogen/issues/692

tests/ansible/integration/action/transfer_data.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
- assert:
2323
that: |
2424
out.content|b64decode == '{"I am JSON": true}'
25-
fail_msg: out={{out}}
25+
fail_msg: |
26+
out={{ out }}
2627
2728
- name: Create text transfer data
2829
action_passthrough:
@@ -37,7 +38,8 @@
3738
- assert:
3839
that:
3940
out.content|b64decode == 'I am text.'
40-
fail_msg: out={{out}}
41+
fail_msg: |
42+
out={{ out }}
4143
4244
- name: Cleanup transfer data
4345
file:

tests/ansible/integration/async/multiple_items_loop.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- out.results[1].stdout == 'hi-from-job-2'
3434
- out.results[1].rc == 0
3535
- out.results[1].delta > '0:00:05'
36-
fail_msg: out={{out}}
36+
fail_msg: |
37+
out={{ out }}
3738
tags:
3839
- multiple_items_loop

tests/ansible/integration/async/result_binary_producing_json.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
(job.started == 1) and
2828
(job.changed == True) and
2929
(job.finished == 0)
30-
fail_msg: job={{job}}
30+
fail_msg: |
31+
job={{ job }}
3132
3233
- name: busy-poll up to 100000 times
3334
async_status:
@@ -52,7 +53,8 @@
5253
- async_out.failed == False
5354
- async_out.msg == "Hello, world."
5455
- 'async_out.stderr == "binary_producing_json: oh noes\n"'
55-
fail_msg: async_out={{async_out}}
56+
fail_msg: |
57+
async_out={{ async_out }}
5658
vars:
5759
async_out: "{{result.content|b64decode|from_json}}"
5860
tags:

tests/ansible/integration/async/result_binary_producing_junk.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
- async_out.msg.startswith("Traceback")
3939
- '"ValueError: No start of json char found\n" in async_out.msg'
4040
- 'async_out.stderr == "binary_producing_junk: oh noes\n"'
41-
fail_msg: async_out={{async_out}}
41+
fail_msg: |
42+
async_out={{ async_out }}
4243
vars:
4344
async_out: "{{result.content|b64decode|from_json}}"
4445
tags:

tests/ansible/integration/async/result_shell_echo_hi.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@
4242
- async_out.start.startswith("20")
4343
- async_out.stderr == "there"
4444
- async_out.stdout == "hi"
45-
fail_msg: async_out={{async_out}}
45+
fail_msg: |
46+
async_out={{ async_out }}
4647
vars:
4748
async_out: "{{result.content|b64decode|from_json}}"
4849

4950
- assert:
5051
that:
5152
- async_out.invocation.module_args.stdin == None
52-
fail_msg: async_out={{async_out}}
53+
fail_msg: |
54+
async_out={{ async_out }}
5355
when:
5456
- ansible_version.full is version('2.4', '>=', strict=True)
5557
vars:

tests/ansible/integration/async/runner_new_process.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
- assert:
1616
that:
1717
- sync_proc1.pid == sync_proc2.pid
18-
fail_msg: sync_proc1={{sync_proc1}} sync_proc2={{sync_proc2}}
18+
fail_msg: |
19+
sync_proc1={{ sync_proc1 }}
20+
sync_proc2={{ sync_proc2 }}
1921
when: is_mitogen
2022

2123
- name: get async process ID.
@@ -52,7 +54,9 @@
5254
- sync_proc1.pid == sync_proc2.pid
5355
- async_result1.pid != sync_proc1.pid
5456
- async_result1.pid != async_result2.pid
55-
fail_msg: async_result1={{async_result1}} async_result2={{async_result2}}
57+
fail_msg: |
58+
async_result1={{ async_result1 }}
59+
async_result2={{ async_result2 }}
5660
when: is_mitogen
5761
tags:
5862
- runner_new_process

0 commit comments

Comments
 (0)