async: use async_dir for the async results file directory (#45461)

* win async: use async_dir for the async results file directory

* tried to unify POSIX and PowerShell async implementations of async_dir

* fix sanity issue
This commit is contained in:
Jordan Borean
2018-09-20 19:37:54 +10:00
committed by GitHub
parent 60979a96a9
commit 5c73d4f4bd
11 changed files with 269 additions and 19 deletions

View File

@@ -177,3 +177,108 @@
- non_async_result is changed
- non_async_result is finished
- "'ansible_job_id' not in non_async_result"
- name: set fact of custom tmp dir
set_fact:
custom_async_tmp: ~/.ansible_async_test
- name: ensure custom async tmp dir is absent
file:
path: '{{ custom_async_tmp }}'
state: absent
- block:
- name: run async task with custom dir
command: sleep 1
register: async_custom_dir
async: 5
poll: 1
vars:
ansible_async_dir: '{{ custom_async_tmp }}'
- name: check if the async temp dir is created
stat:
path: '{{ custom_async_tmp }}'
register: async_custom_dir_result
- name: assert run async task with custom dir
assert:
that:
- async_custom_dir is successful
- async_custom_dir is finished
- async_custom_dir_result.stat.exists
- name: remove custom async dir again
file:
path: '{{ custom_async_tmp }}'
state: absent
- name: run async task with custom dir - deprecated format
command: sleep 1
register: async_custom_dir_dep
async: 5
poll: 1
environment:
ANSIBLE_ASYNC_DIR: '{{ custom_async_tmp }}'
- name: check if the async temp dir is created - deprecated format
stat:
path: '{{ custom_async_tmp }}'
register: async_custom_dir_dep_result
- name: assert run async task with custom dir - deprecated format
assert:
that:
- async_custom_dir_dep is successful
- async_custom_dir_dep is finished
- async_custom_dir_dep_result.stat.exists
- name: remove custom async dir after deprecation test
file:
path: '{{ custom_async_tmp }}'
state: absent
- name: run fire and forget async task with custom dir
command: sleep 1
register: async_fandf_custom_dir
async: 5
poll: 0
vars:
ansible_async_dir: '{{ custom_async_tmp }}'
- name: fail to get async status with custom dir with defaults
async_status:
jid: '{{ async_fandf_custom_dir.ansible_job_id }}'
register: async_fandf_custom_dir_fail
ignore_errors: yes
- name: get async status with custom dir using newer format
async_status:
jid: '{{ async_fandf_custom_dir.ansible_job_id }}'
register: async_fandf_custom_dir_result
vars:
ansible_async_dir: '{{ custom_async_tmp }}'
- name: get async status with custom dir - deprecated format
async_status:
jid: '{{ async_fandf_custom_dir.ansible_job_id }}'
register: async_fandf_custom_dir_dep_result
environment:
ANSIBLE_ASYNC_DIR: '{{ custom_async_tmp }}'
- name: assert run fire and forget async task with custom dir
assert:
that:
- async_fandf_custom_dir is successful
- async_fandf_custom_dir_fail is failed
- async_fandf_custom_dir_fail.msg == "could not find job"
- async_fandf_custom_dir_result is successful
- async_fandf_custom_dir_result is finished
- async_fandf_custom_dir_dep_result is successful
- async_fandf_custom_dir_dep_result is finished
always:
- name: remove custom tmp dir after test
file:
path: '{{ custom_async_tmp }}'
state: absent

View File

@@ -166,17 +166,46 @@
- nonascii_output.stdout_lines[0] == 'über den Fußgängerübergang gehen'
- nonascii_output.stderr == ''
- name: test async with custom remote_tmp
- name: test async with custom async dir
win_shell: echo hi
register: async_custom_tmp
register: async_custom_dir
async: 5
vars:
ansible_remote_tmp: '{{win_output_dir}}'
ansible_async_dir: '{{win_output_dir}}'
- name: assert results file is in the remote tmp specified
assert:
that:
- async_custom_tmp.results_file == win_output_dir + '\\.ansible_async\\' + async_custom_tmp.ansible_job_id
- async_custom_dir.results_file == win_output_dir + '\\' + async_custom_dir.ansible_job_id
- name: test async fire and forget with custom async dir
win_shell: echo hi
register: async_custom_dir_poll
async: 5
poll: 0
vars:
ansible_async_dir: '{{win_output_dir}}'
- name: poll with different dir - fail
async_status:
jid: '{{ async_custom_dir_poll.ansible_job_id }}'
register: fail_async_custom_dir_poll
ignore_errors: yes
- name: poll with different dir - success
async_status:
jid: '{{ async_custom_dir_poll.ansible_job_id }}'
register: success_async_custom_dir_poll
vars:
ansible_async_dir: '{{win_output_dir}}'
- name: assert test async fire and forget with custom async dir
assert:
that:
- fail_async_custom_dir_poll.failed
- '"could not find job at ''" + nonascii_output.results_file|win_dirname + "''" in fail_async_custom_dir_poll.msg'
- not success_async_custom_dir_poll.failed
- success_async_custom_dir_poll.results_file == win_output_dir + '\\' + async_custom_dir_poll.ansible_job_id
# FUTURE: figure out why the last iteration of this test often fails on shippable
#- name: loop async success