Skip to content

Commit

Permalink
Merge pull request mitogen-hq#964 from moreati/test-tweaks
Browse files Browse the repository at this point in the history
Test tweaks
  • Loading branch information
moreati authored Sep 13, 2022
2 parents 4a5d529 + a3a10cb commit 572636a
Show file tree
Hide file tree
Showing 49 changed files with 289 additions and 298 deletions.
6 changes: 4 additions & 2 deletions .ci/ansible_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ def pause_if_interactive():
for container in containers
)

for distro, hostnames in distros.items():
for distro, hostnames in sorted(distros.items(), key=lambda t: t[0]):
fp.write('\n[%s]\n' % distro)
fp.writelines('%s\n' % name for name in hostnames)

for family, hostnames in families.items():
for family, hostnames in sorted(families.items(), key=lambda t: t[0]):
fp.write('\n[%s]\n' % family)
fp.writelines('%s\n' % name for name in hostnames)

fp.write('\n[linux:children]\ntest-targets\n')

ci_lib.dump_file(inventory_path)

if not ci_lib.exists_in_path('sshpass'):
Expand Down
14 changes: 9 additions & 5 deletions tests/ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
[defaults]
any_errors_fatal = true
# callback_whitelist naming will be deprecated in ansible-core >= 2.15.
# callbacks_enabled naming was added in ansible-core 2.11
# profile_tasks: Displays timing for each task and summary table of top N tasks
# timer: Displays "Playbook run took 0 days, 0 hours, ..."
callback_whitelist =
profile_tasks,
timer
inventory = hosts
gathering = explicit
strategy_plugins = ../../ansible_mitogen/plugins/strategy
inventory_plugins = lib/inventory
action_plugins = lib/action
callback_plugins = lib/callback
stdout_callback = yaml
stdout_whitelist =
profile_roles,
timer,
yaml
vars_plugins = lib/vars
library = lib/modules
filter_plugins = lib/filters
module_utils = lib/module_utils
retry_files_enabled = False
show_task_path_on_failure = true # Added in ansible-core 2.11
display_args_to_stdout = True
forks = 100

Expand All @@ -31,7 +35,7 @@ transport = ssh
no_target_syslog = True

# Required by integration/ssh/timeouts.yml
timeout = 10
timeout = 30

# On Travis, paramiko check fails due to host key checking enabled.
host_key_checking = False
Expand Down
6 changes: 4 additions & 2 deletions tests/ansible/bench/loop-20-templates.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
- name: bench/loop-20-templates.yml
hosts: all
tasks:
- file:
- name: Create loop templates dir
file:
dest: /tmp/templates
state: "{{item}}"
with_items: ["absent", "directory"]

- copy:
- name: Copy loop files
copy:
dest: /tmp/templates/{{item}}
mode: 0755
content:
Expand Down
31 changes: 18 additions & 13 deletions tests/ansible/integration/action/copy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
- name: integration/action/copy.yml
hosts: test-targets
tasks:
- copy:
- name: Create tiny file
copy:
dest: /tmp/copy-tiny-file
content:
this is a tiny file.
delegate_to: localhost

- copy:
- 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

# end of making files

- file:
- name: Cleanup copied files
file:
state: absent
path: "{{item}}"
with_items:
Expand All @@ -26,28 +27,31 @@
- /tmp/copy-tiny-inline-file.out
- /tmp/copy-large-inline-file.out

# end of cleaning out files

- copy:
- name: Copy large file
copy:
dest: /tmp/copy-large-file.out
src: /tmp/copy-large-file

- copy:
- name: Copy tiny file
copy:
dest: /tmp/copy-tiny-file.out
src: /tmp/copy-tiny-file

- copy:
- name: Copy tiny inline file
copy:
dest: /tmp/copy-tiny-inline-file.out
content: "tiny inline content"

- copy:
- name: Copy large inline file
copy:
dest: /tmp/copy-large-inline-file.out
content: |
{% for x in range(200000) %}y{% endfor %}
# stat results

- stat:
- name: Stat copied files
stat:
path: "{{item}}"
with_items:
- /tmp/copy-tiny-file.out
Expand All @@ -64,7 +68,8 @@
- stat.results[3].stat.checksum == "d675f47e467eae19e49032a2cc39118e12a6ee72"
fail_msg: stat={{stat}}

- file:
- name: Cleanup files
file:
state: absent
path: "{{item}}"
with_items:
Expand Down
37 changes: 11 additions & 26 deletions tests/ansible/integration/action/fixup_perms2__copy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
- name: integration/action/fixup_perms2__copy.yml
hosts: test-targets
tasks:
#
# copy module (no mode).
#

- name: "Copy files (no mode)"
copy:
content: ""
Expand All @@ -22,10 +18,6 @@
- out.stat.mode in ("0644", "0664")
fail_msg: out={{out}}

#
# copy module (explicit mode).
#

- name: "Copy files from content: arg"
copy:
content: ""
Expand All @@ -39,22 +31,20 @@
- out.stat.mode == "0400"
fail_msg: out={{out}}

#
# copy module (existing disk files, no mode).
#

- file:
- name: Cleanup local weird mode file
file:
path: /tmp/weird-mode.out
state: absent

- name: Create local test file.
- name: Create local weird mode file
delegate_to: localhost
copy:
content: "weird mode"
dest: "/tmp/weird-mode"
mode: "1462"

- copy:
- name: Copy file with weird mode
copy:
src: "/tmp/weird-mode"
dest: "/tmp/weird-mode.out"

Expand All @@ -66,11 +56,8 @@
- out.stat.mode in ("0644", "0664")
fail_msg: out={{out}}

#
# copy module (existing disk files, preserve mode).
#

- copy:
- name: Copy file with weird mode, preserving mode
copy:
src: "/tmp/weird-mode"
dest: "/tmp/weird-mode"
mode: preserve
Expand All @@ -83,11 +70,8 @@
- out.stat.mode == "1462"
fail_msg: out={{out}}

#
# copy module (existing disk files, explicit mode).
#

- copy:
- name: Copy file with weird mode, explicit mode
copy:
src: "/tmp/weird-mode"
dest: "/tmp/weird-mode"
mode: "1461"
Expand All @@ -101,7 +85,8 @@
- out.stat.mode == "1461"
fail_msg: out={{out}}

- file:
- name: Cleanup
file:
state: absent
path: "{{item}}"
with_items:
Expand Down
16 changes: 6 additions & 10 deletions tests/ansible/integration/action/remote_file_exists.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,32 @@
- name: integration/action/remote_file_exists.yml
hosts: test-targets
tasks:

- file:
- name: Ensure does-not-exist doesnt
file:
path: /tmp/does-not-exist
state: absent

- action_passthrough:
method: _remote_file_exists
args: ['/tmp/does-not-exist']
register: out

- assert:
that: out.result == False
fail_msg: out={{out}}

# ---

- copy:
- name: Ensure does-exist does
copy:
dest: /tmp/does-exist
content: "I think, therefore I am"

- action_passthrough:
method: _remote_file_exists
args: ['/tmp/does-exist']
register: out

- assert:
that: out.result == True
fail_msg: out={{out}}

- file:
- name: Cleanup
file:
path: /tmp/does-exist
state: absent
tags:
Expand Down
3 changes: 2 additions & 1 deletion tests/ansible/integration/action/remove_tmp_path.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# return a result with a 'src' attribute pointing into that directory.
#

- copy:
- name: Ensure remove_tmp_path_test
copy:
dest: /tmp/remove_tmp_path_test
content: "{{ 123123 | random }}"
register: out
Expand Down
12 changes: 8 additions & 4 deletions tests/ansible/integration/action/synchronize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@
ansible_password: ''
tasks:
# must copy git file to set proper file mode.
- copy:
- name: Copy synchronize-action-key
copy:
dest: /tmp/synchronize-action-key
src: ../../../data/docker/mitogen__has_sudo_pubkey.key
mode: u=rw,go=
delegate_to: localhost

- file:
- name: Cleanup sync-test
file:
path: /tmp/sync-test
state: absent
delegate_to: localhost

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

- copy:
- name: Create syn-test item
copy:
dest: /tmp/sync-test/item
content: "item!"
delegate_to: localhost
Expand Down
26 changes: 12 additions & 14 deletions tests/ansible/integration/action/transfer_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,45 @@
- name: integration/action/transfer_data.yml
hosts: test-targets
tasks:

- file:
- name: Cleanup transfer data
file:
path: /tmp/transfer-data
state: absent

# Ensure it JSON-encodes dicts.
- action_passthrough:
- name: Create JSON transfer data
action_passthrough:
method: _transfer_data
kwargs:
remote_path: /tmp/transfer-data
data: {
"I am JSON": true
}

- slurp:
- name: Slurp JSON transfer data
slurp:
src: /tmp/transfer-data
register: out

- assert:
that: |
out.content|b64decode == '{"I am JSON": true}'
fail_msg: out={{out}}


# Ensure it handles strings.
- action_passthrough:
- name: Create text transfer data
action_passthrough:
method: _transfer_data
kwargs:
remote_path: /tmp/transfer-data
data: "I am text."

- slurp:
- name: Slurp text transfer data
slurp:
src: /tmp/transfer-data
register: out

- assert:
that:
out.content|b64decode == 'I am text.'
fail_msg: out={{out}}

- file:
- name: Cleanup transfer data
file:
path: /tmp/transfer-data
state: absent
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
retries: 100000
delay: 0

- slurp:
- name: Slurp async busy-poll
slurp:
src: "{{ansible_user_dir}}/.ansible_async/{{job.ansible_job_id}}"
register: result

Expand Down
Loading

0 comments on commit 572636a

Please sign in to comment.