Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up test suite #1060

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/ansible_detailed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ Noteworthy Differences
part of the core library, and should therefore be straightforward to fix as
part of 0.2.x.

* Connection and become timeouts are applied differently. Mitogen may consider
a connection to have timed out, when Ansible would have waited longer or
indefinately. For example if SSH authentication completes within the
timeout, but execution of login scripts exceeds it - then Mitogen will
consider the task to have timed out and that host to have failed.

..
tests/ansible/integration/ssh/timeouts.yml covers (some of) this behaviour.

..
* SSH and ``become`` are treated distinctly when applying timeouts, and
timeouts apply up to the point when the new interpreter is ready to accept
Expand Down
41 changes: 39 additions & 2 deletions tests/ansible/bench/file_transfer.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

- name: bench/file_transfer.yml
hosts: test-targets
tasks:

- name: Make 32MiB file
delegate_to: localhost
run_once: true
shell: openssl rand 33554432 > /tmp/bigfile.in
args:
creates: /tmp/bigfile.in

- name: Make 320MiB file
delegate_to: localhost
run_once: true
shell: >
cat
/tmp/bigfile.in
Expand All @@ -22,6 +24,8 @@
/tmp/bigfile.in
/tmp/bigfile.in
> /tmp/bigbigfile.in
args:
creates: /tmp/bigbigfile.in

- name: Delete SSH file is present.
file:
Expand All @@ -36,17 +40,20 @@
copy:
src: /tmp/bigfile.in
dest: /tmp/bigfile.out
mode: ugo=rw

- name: Copy 320MiB file via SSH
copy:
src: /tmp/bigbigfile.in
dest: /tmp/bigbigfile.out
mode: ugo=rw

- name: Delete localhost sudo file if present.
file:
path: "{{item}}"
state: absent
delegate_to: localhost
run_once: true
become: true
with_items:
- /tmp/bigfile.out
Expand All @@ -56,21 +63,51 @@

- name: Copy 32MiB file via localhost sudo
delegate_to: localhost
run_once: true
become: true
copy:
src: /tmp/bigfile.in
dest: /tmp/bigfile.out
mode: ugo=rw
tags:
- requires_local_sudo

- name: Copy 320MiB file via localhost sudo
delegate_to: localhost
run_once: true
become: true
copy:
src: /tmp/bigbigfile.in
dest: /tmp/bigbigfile.out
mode: ugo=rw
tags:
- requires_local_sudo

- name: Local cleanup
file:
path: "{{ item.path }}"
state: absent
loop:
- /tmp/bigfile.in
- /tmp/bigfile.out
- /tmp/bigbigfile.in
- /tmp/bigbigfile.out
delegate_to: localhost
run_once: true
tags:
- cleanup_local
- cleanup

- name: Target cleanup
file:
path: "{{ item.path }}"
state: absent
loop:
- /tmp/bigfile.out
- /tmp/bigbigfile.out
tags:
- cleanup_target
- cleanup

tags:
- resource_intensive
2 changes: 2 additions & 0 deletions tests/ansible/integration/action/copy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
content:
this is a tiny file.
delegate_to: localhost
run_once: true

- name: Create large file
copy:
dest: /tmp/copy-large-file
# Must be larger than Connection.SMALL_SIZE_LIMIT.
content: "{% for x in range(200000) %}x{% endfor %}"
delegate_to: localhost
run_once: true

- name: Cleanup copied files
file:
Expand Down
1 change: 1 addition & 0 deletions tests/ansible/integration/action/fixup_perms2__copy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

- name: Create local weird mode file
delegate_to: localhost
run_once: true
copy:
content: "weird mode"
dest: "/tmp/weird-mode"
Expand Down
3 changes: 3 additions & 0 deletions tests/ansible/integration/action/synchronize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@
path: /tmp/sync-test
state: absent
delegate_to: localhost
run_once: true

- name: Create sync-test
file:
path: /tmp/sync-test
state: directory
delegate_to: localhost
run_once: true

- name: Create syn-test item
copy:
dest: /tmp/sync-test/item
content: "item!"
delegate_to: localhost
run_once: true

# TODO: https://github.com/dw/mitogen/issues/692
# - file:
Expand Down
17 changes: 17 additions & 0 deletions tests/ansible/integration/connection/_cleanup_file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- name: Cleanup local file
file:
path: /tmp/{{ file_name }}
state: absent
delegate_to: localhost
run_once: true
tags:
- cleanup_local
- cleanup

- name: Cleanup target file
file:
path: /tmp/{{ file_name }}.out
state: absent
tags:
- cleanup_target
- cleanup
9 changes: 5 additions & 4 deletions tests/ansible/integration/connection/_put_file.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
---

- name: Create {{ file_name }}
shell: dd if=/dev/urandom of=/tmp/{{ file_name }} bs=1024 count={{ file_size }}
args:
command:
cmd: dd if=/dev/urandom of=/tmp/{{ file_name }} bs=1024 count={{ file_size_kib }}
creates: /tmp/{{file_name}}
delegate_to: localhost
run_once: true

- name: Copy {{ file_name }}
copy:
dest: /tmp/{{file_name}}.out
src: /tmp/{{file_name}}
mode: "{{ file_mode }}"

- name: Stat created {{ file_name }}
stat: path=/tmp/{{ file_name }}
register: original
delegate_to: localhost
run_once: true

- name: Stat copied {{ file_name }}
stat: path=/tmp/{{ file_name }}.out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

- name: Run _disconnect_during_module.yml
delegate_to: localhost
environment:
ANSIBLE_VERBOSITY: "{{ ansible_verbosity }}"
command: |
ansible-playbook
{% for inv in ansible_inventory_sources %}
Expand Down
4 changes: 3 additions & 1 deletion tests/ansible/integration/connection/put_large_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
gather_facts: no
vars:
file_name: large-file
file_size: 512
file_size_kib: 512
file_mode: u=rw,go=
tasks:
- include_tasks: _put_file.yml
- include_tasks: _cleanup_file.yml
tags:
- put_file
- put_large_file
4 changes: 3 additions & 1 deletion tests/ansible/integration/connection/put_small_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
gather_facts: no
vars:
file_name: small-file
file_size: 123
file_size_kib: 123
file_mode: u=rw,go=
tasks:
- include_tasks: _put_file.yml
- include_tasks: _cleanup_file.yml
tags:
- put_file
- put_small_file
44 changes: 30 additions & 14 deletions tests/ansible/integration/playbook_semantics/delegate_to.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
- name: integration/playbook_semantics/delegate_to.yml
hosts: test-targets
vars:
local_path: "/tmp/delegate_to.{{ inventory_hostname }}.txt"
tasks:
#
# delegate_to, no sudo
#
- name: "delegate_to, no sudo"
copy:
dest: /tmp/delegate_to.yml.txt
dest: "{{ local_path }}"
content: "Hello, world."
register: out
mode: u=rw,go=r
delegate_to: localhost

- name: "delegate_to, no sudo"
assert:
that: "lookup('file', '/tmp/delegate_to.yml.txt') == 'Hello, world.'"
that:
- lookup('file', local_path) == 'Hello, world.'
fail_msg: "{{ lookup('file', local_path) }}"

- name: "delegate_to, no sudo"
file:
path: /tmp/delegate_to.yml.txt
path: "{{ local_path }}"
state: absent
delegate_to: localhost

Expand All @@ -27,18 +31,20 @@
#
- name: "connection:local, no sudo"
copy:
dest: /tmp/delegate_to.yml.txt
dest: "{{ local_path }}"
content: "Hello, world."
register: out
mode: u=rw,go=r
connection: local

- name: "connection:local, no sudo"
assert:
that: "lookup('file', '/tmp/delegate_to.yml.txt') == 'Hello, world.'"
that:
- lookup('file', local_path) == 'Hello, world.'
fail_msg: "{{ lookup('file', local_path) }}"

- name: "connection:local, no sudo"
file:
path: /tmp/delegate_to.yml.txt
path: "{{ local_path }}"
state: absent
connection: local

Expand All @@ -47,21 +53,26 @@
# delegate_to, sudo
#
- name: "delegate_to, sudo"
shell: whoami > /tmp/delegate_to.yml.txt
shell: |
whoami > "{{ local_path }}"
args:
creates: "{{ local_path }}"
delegate_to: localhost
become: true
tags:
- requires_local_sudo

- name: "delegate_to, sudo"
assert:
that: "lookup('file', '/tmp/delegate_to.yml.txt') == 'root'"
that:
- lookup('file', local_path) == 'root'
fail_msg: "{{ lookup('file', local_path) }}"
tags:
- requires_local_sudo

- name: "delegate_to, sudo"
file:
path: /tmp/delegate_to.yml.txt
path: "{{ local_path }}"
state: absent
delegate_to: localhost
become: true
Expand All @@ -73,21 +84,26 @@
# connection:local, sudo
#
- name: "connection:local, sudo"
shell: whoami > /tmp/delegate_to.yml.txt
shell: |
whoami > "{{ local_path }}"
args:
creates: "{{ local_path }}"
connection: local
become: true
tags:
- requires_local_sudo

- name: "connection:local, sudo"
assert:
that: "lookup('file', '/tmp/delegate_to.yml.txt') == 'root'"
that:
- lookup('file', local_path) == 'root'
fail_msg: "{{ lookup('file', local_path) }}"
tags:
- requires_local_sudo

- name: "connection:local, sudo"
file:
path: /tmp/delegate_to.yml.txt
path: "{{ local_path }}"
state: absent
connection: local
become: true
Expand Down
1 change: 1 addition & 0 deletions tests/ansible/integration/process/unix_socket_cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- shell: >
ANSIBLE_STRATEGY=mitogen_linear
ANSIBLE_SSH_ARGS="-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa"
ANSIBLE_VERBOSITY="{{ ansible_verbosity }}"
ansible -m shell -c local -a whoami
{% for inv in ansible_inventory_sources %}
-i "{{ inv }}"
Expand Down
7 changes: 5 additions & 2 deletions tests/ansible/integration/runner/missing_module.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

- name: integration/runner/missing_module.yml
hosts: test-targets[0]
connection: local
tasks:
- name: Run missing_module
connection: local
environment:
ANSIBLE_VERBOSITY: "{{ ansible_verbosity }}"
command: |
ansible -vvv
ansible
{% for inv in ansible_inventory_sources %}
-i "{{ inv }}"
{% endfor %}
Expand All @@ -15,6 +16,8 @@
args:
chdir: ../..
register: out
changed_when: false
check_mode: false
ignore_errors: true

- assert:
Expand Down
Loading
Loading