diff options
-rw-r--r-- | lib/ansible/plugins/test/core.py | 21 | ||||
-rw-r--r-- | test/integration/targets/async/tasks/main.yml | 1 | ||||
-rw-r--r-- | test/integration/targets/win_async_wrapper/tasks/main.yml | 1 |
3 files changed, 20 insertions, 3 deletions
diff --git a/lib/ansible/plugins/test/core.py b/lib/ansible/plugins/test/core.py index aab2b5aa3f..88614c3f5d 100644 --- a/lib/ansible/plugins/test/core.py +++ b/lib/ansible/plugins/test/core.py @@ -84,16 +84,30 @@ def skipped(result): return result.get('skipped', False) +def started(result): + ''' Test if async task has started ''' + if not isinstance(result, MutableMapping): + raise errors.AnsibleFilterError("The 'started' test expects a dictionary") + if 'started' in result: + # For async tasks, return status + # NOTE: The value of started is 0 or 1, not False or True :-/ + return result.get('started', 0) == 1 + else: + # For non-async tasks, warn user, but return as if started + display.warning("The 'started' test expects an async task, but a non-async task was tested") + return True + + def finished(result): ''' Test if async task has finished ''' if not isinstance(result, MutableMapping): raise errors.AnsibleFilterError("The 'finished' test expects a dictionary") if 'finished' in result: - # For async tasks return status - # NOTE: The value of finished it 0 or 1, not False or True :-/ + # For async tasks, return status + # NOTE: The value of finished is 0 or 1, not False or True :-/ return result.get('finished', 0) == 1 else: - # For non-async tasks warn user, but return as finished + # For non-async tasks, warn user, but return as if finished display.warning("The 'finished' test expects an async task, but a non-async task was tested") return True @@ -175,6 +189,7 @@ class TestModule(object): # async testing 'finished': finished, + 'started': started, # regex 'match': match, diff --git a/test/integration/targets/async/tasks/main.yml b/test/integration/targets/async/tasks/main.yml index 38536109fb..f8e244eca5 100644 --- a/test/integration/targets/async/tasks/main.yml +++ b/test/integration/targets/async/tasks/main.yml @@ -76,6 +76,7 @@ assert: that: - fnf_task.started == 1 + - fnf_task is started - "'ansible_job_id' in fnf_task" - name: 'check on task started as a "fire-and-forget"' diff --git a/test/integration/targets/win_async_wrapper/tasks/main.yml b/test/integration/targets/win_async_wrapper/tasks/main.yml index f7d011758c..20cca10b43 100644 --- a/test/integration/targets/win_async_wrapper/tasks/main.yml +++ b/test/integration/targets/win_async_wrapper/tasks/main.yml @@ -14,6 +14,7 @@ that: - asyncresult.ansible_job_id is match('\d+\.\d+') - asyncresult.started == 1 + - asyncresult is started - asyncresult.finished == 0 - asyncresult is not finished - asyncresult.results_file is search('\.ansible_async.+\d+\.\d+') |