Skip to content

Commit 7079a07

Browse files
committed
tests: Fix duplicate local task executions
integration/ssh/timeouts.yml is noteworthy. It was an accidental N**2 in time - executing num hosts * num hosts tasks.
1 parent 65c8a42 commit 7079a07

14 files changed

+130
-31
lines changed

tests/ansible/bench/file_transfer.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
21
- name: bench/file_transfer.yml
32
hosts: test-targets
43
tasks:
5-
64
- name: Make 32MiB file
75
delegate_to: localhost
6+
run_once: true
87
shell: openssl rand 33554432 > /tmp/bigfile.in
8+
args:
9+
creates: /tmp/bigfile.in
910

1011
- name: Make 320MiB file
1112
delegate_to: localhost
13+
run_once: true
1214
shell: >
1315
cat
1416
/tmp/bigfile.in
@@ -22,6 +24,8 @@
2224
/tmp/bigfile.in
2325
/tmp/bigfile.in
2426
> /tmp/bigbigfile.in
27+
args:
28+
creates: /tmp/bigbigfile.in
2529

2630
- name: Delete SSH file is present.
2731
file:
@@ -36,17 +40,20 @@
3640
copy:
3741
src: /tmp/bigfile.in
3842
dest: /tmp/bigfile.out
43+
mode: ugo=rw
3944

4045
- name: Copy 320MiB file via SSH
4146
copy:
4247
src: /tmp/bigbigfile.in
4348
dest: /tmp/bigbigfile.out
49+
mode: ugo=rw
4450

4551
- name: Delete localhost sudo file if present.
4652
file:
4753
path: "{{item}}"
4854
state: absent
4955
delegate_to: localhost
56+
run_once: true
5057
become: true
5158
with_items:
5259
- /tmp/bigfile.out
@@ -56,21 +63,51 @@
5663

5764
- name: Copy 32MiB file via localhost sudo
5865
delegate_to: localhost
66+
run_once: true
5967
become: true
6068
copy:
6169
src: /tmp/bigfile.in
6270
dest: /tmp/bigfile.out
71+
mode: ugo=rw
6372
tags:
6473
- requires_local_sudo
6574

6675
- name: Copy 320MiB file via localhost sudo
6776
delegate_to: localhost
77+
run_once: true
6878
become: true
6979
copy:
7080
src: /tmp/bigbigfile.in
7181
dest: /tmp/bigbigfile.out
82+
mode: ugo=rw
7283
tags:
7384
- requires_local_sudo
7485

86+
- name: Local cleanup
87+
file:
88+
path: "{{ item.path }}"
89+
state: absent
90+
loop:
91+
- /tmp/bigfile.in
92+
- /tmp/bigfile.out
93+
- /tmp/bigbigfile.in
94+
- /tmp/bigbigfile.out
95+
delegate_to: localhost
96+
run_once: true
97+
tags:
98+
- cleanup_local
99+
- cleanup
100+
101+
- name: Target cleanup
102+
file:
103+
path: "{{ item.path }}"
104+
state: absent
105+
loop:
106+
- /tmp/bigfile.out
107+
- /tmp/bigbigfile.out
108+
tags:
109+
- cleanup_target
110+
- cleanup
111+
75112
tags:
76113
- resource_intensive

tests/ansible/integration/action/copy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
content:
1010
this is a tiny file.
1111
delegate_to: localhost
12+
run_once: true
1213

1314
- name: Create large file
1415
copy:
1516
dest: /tmp/copy-large-file
1617
# Must be larger than Connection.SMALL_SIZE_LIMIT.
1718
content: "{% for x in range(200000) %}x{% endfor %}"
1819
delegate_to: localhost
20+
run_once: true
1921

2022
- name: Cleanup copied files
2123
file:

tests/ansible/integration/action/fixup_perms2__copy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
- name: Create local weird mode file
4040
delegate_to: localhost
41+
run_once: true
4142
copy:
4243
content: "weird mode"
4344
dest: "/tmp/weird-mode"

tests/ansible/integration/action/synchronize.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@
2424
path: /tmp/sync-test
2525
state: absent
2626
delegate_to: localhost
27+
run_once: true
2728

2829
- name: Create sync-test
2930
file:
3031
path: /tmp/sync-test
3132
state: directory
3233
delegate_to: localhost
34+
run_once: true
3335

3436
- name: Create syn-test item
3537
copy:
3638
dest: /tmp/sync-test/item
3739
content: "item!"
3840
delegate_to: localhost
41+
run_once: true
3942

4043
# TODO: https://github.com/dw/mitogen/issues/692
4144
# - file:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- name: Cleanup local file
2+
file:
3+
path: /tmp/{{ file_name }}
4+
state: absent
5+
delegate_to: localhost
6+
run_once: true
7+
tags:
8+
- cleanup_local
9+
- cleanup
10+
11+
- name: Cleanup target file
12+
file:
13+
path: /tmp/{{ file_name }}.out
14+
state: absent
15+
tags:
16+
- cleanup_target
17+
- cleanup

tests/ansible/integration/connection/_put_file.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
---
2-
31
- name: Create {{ file_name }}
4-
shell: dd if=/dev/urandom of=/tmp/{{ file_name }} bs=1024 count={{ file_size }}
5-
args:
2+
command:
3+
cmd: dd if=/dev/urandom of=/tmp/{{ file_name }} bs=1024 count={{ file_size_kib }}
64
creates: /tmp/{{file_name}}
75
delegate_to: localhost
6+
run_once: true
87

98
- name: Copy {{ file_name }}
109
copy:
1110
dest: /tmp/{{file_name}}.out
1211
src: /tmp/{{file_name}}
12+
mode: "{{ file_mode }}"
1313

1414
- name: Stat created {{ file_name }}
1515
stat: path=/tmp/{{ file_name }}
1616
register: original
1717
delegate_to: localhost
18+
run_once: true
1819

1920
- name: Stat copied {{ file_name }}
2021
stat: path=/tmp/{{ file_name }}.out

tests/ansible/integration/connection/put_large_file.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
gather_facts: no
77
vars:
88
file_name: large-file
9-
file_size: 512
9+
file_size_kib: 512
10+
file_mode: u=rw,go=
1011
tasks:
1112
- include_tasks: _put_file.yml
13+
- include_tasks: _cleanup_file.yml
1214
tags:
1315
- put_file
1416
- put_large_file

tests/ansible/integration/connection/put_small_file.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
gather_facts: no
77
vars:
88
file_name: small-file
9-
file_size: 123
9+
file_size_kib: 123
10+
file_mode: u=rw,go=
1011
tasks:
1112
- include_tasks: _put_file.yml
13+
- include_tasks: _cleanup_file.yml
1214
tags:
1315
- put_file
1416
- put_small_file

tests/ansible/integration/playbook_semantics/delegate_to.yml

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
- name: integration/playbook_semantics/delegate_to.yml
22
hosts: test-targets
3+
vars:
4+
local_path: "/tmp/delegate_to.{{ inventory_hostname }}.txt"
35
tasks:
46
#
57
# delegate_to, no sudo
68
#
79
- name: "delegate_to, no sudo"
810
copy:
9-
dest: /tmp/delegate_to.yml.txt
11+
dest: "{{ local_path }}"
1012
content: "Hello, world."
11-
register: out
13+
mode: u=rw,go=r
1214
delegate_to: localhost
1315

1416
- name: "delegate_to, no sudo"
1517
assert:
16-
that: "lookup('file', '/tmp/delegate_to.yml.txt') == 'Hello, world.'"
18+
that:
19+
- lookup('file', local_path) == 'Hello, world.'
20+
fail_msg: "{{ lookup('file', local_path) }}"
1721

1822
- name: "delegate_to, no sudo"
1923
file:
20-
path: /tmp/delegate_to.yml.txt
24+
path: "{{ local_path }}"
2125
state: absent
2226
delegate_to: localhost
2327

@@ -27,18 +31,20 @@
2731
#
2832
- name: "connection:local, no sudo"
2933
copy:
30-
dest: /tmp/delegate_to.yml.txt
34+
dest: "{{ local_path }}"
3135
content: "Hello, world."
32-
register: out
36+
mode: u=rw,go=r
3337
connection: local
3438

3539
- name: "connection:local, no sudo"
3640
assert:
37-
that: "lookup('file', '/tmp/delegate_to.yml.txt') == 'Hello, world.'"
41+
that:
42+
- lookup('file', local_path) == 'Hello, world.'
43+
fail_msg: "{{ lookup('file', local_path) }}"
3844

3945
- name: "connection:local, no sudo"
4046
file:
41-
path: /tmp/delegate_to.yml.txt
47+
path: "{{ local_path }}"
4248
state: absent
4349
connection: local
4450

@@ -47,21 +53,26 @@
4753
# delegate_to, sudo
4854
#
4955
- name: "delegate_to, sudo"
50-
shell: whoami > /tmp/delegate_to.yml.txt
56+
shell: |
57+
whoami > "{{ local_path }}"
58+
args:
59+
creates: "{{ local_path }}"
5160
delegate_to: localhost
5261
become: true
5362
tags:
5463
- requires_local_sudo
5564

5665
- name: "delegate_to, sudo"
5766
assert:
58-
that: "lookup('file', '/tmp/delegate_to.yml.txt') == 'root'"
67+
that:
68+
- lookup('file', local_path) == 'root'
69+
fail_msg: "{{ lookup('file', local_path) }}"
5970
tags:
6071
- requires_local_sudo
6172

6273
- name: "delegate_to, sudo"
6374
file:
64-
path: /tmp/delegate_to.yml.txt
75+
path: "{{ local_path }}"
6576
state: absent
6677
delegate_to: localhost
6778
become: true
@@ -73,21 +84,26 @@
7384
# connection:local, sudo
7485
#
7586
- name: "connection:local, sudo"
76-
shell: whoami > /tmp/delegate_to.yml.txt
87+
shell: |
88+
whoami > "{{ local_path }}"
89+
args:
90+
creates: "{{ local_path }}"
7791
connection: local
7892
become: true
7993
tags:
8094
- requires_local_sudo
8195

8296
- name: "connection:local, sudo"
8397
assert:
84-
that: "lookup('file', '/tmp/delegate_to.yml.txt') == 'root'"
98+
that:
99+
- lookup('file', local_path) == 'root'
100+
fail_msg: "{{ lookup('file', local_path) }}"
85101
tags:
86102
- requires_local_sudo
87103

88104
- name: "connection:local, sudo"
89105
file:
90-
path: /tmp/delegate_to.yml.txt
106+
path: "{{ local_path }}"
91107
state: absent
92108
connection: local
93109
become: true

tests/ansible/integration/runner/missing_module.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
- name: integration/runner/missing_module.yml
32
hosts: test-targets[0]
43
connection: local
@@ -17,6 +16,8 @@
1716
args:
1817
chdir: ../..
1918
register: out
19+
changed_when: false
20+
check_mode: false
2021
ignore_errors: true
2122

2223
- assert:

tests/ansible/integration/ssh/timeouts.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
{% for inv in ansible_inventory_sources %}
2121
-i "{{ inv }}"
2222
{% endfor %}
23-
test-targets
24-
-m custom_python_detect_environment
23+
"{{ inventory_hostname }}"
24+
-m ping
2525
-e ansible_user=mitogen__slow_user -e ansible_password=slow_user_password
2626
-e ansible_python_interpreter=python3000
2727
args:
2828
chdir: ../..
2929
register: out
30+
changed_when: false
31+
check_mode: false
3032
ignore_errors: true
3133

3234
- name: Verify connection timeout occurred

0 commit comments

Comments
 (0)