mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
bugfixes to JSON junk filter, added unit/integration tests to exercise (#17834)
This commit is contained in:
39
test/integration/roles/test_async/library/async_test.py
Normal file
39
test/integration/roles/test_async/library/async_test.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import sys
|
||||
import json
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
def main():
|
||||
if "--interactive" in sys.argv:
|
||||
import ansible.module_utils.basic
|
||||
ansible.module_utils.basic._ANSIBLE_ARGS = json.dumps(dict(
|
||||
ANSIBLE_MODULE_ARGS=dict(
|
||||
fail_mode="graceful"
|
||||
)
|
||||
))
|
||||
|
||||
module = AnsibleModule(argument_spec = dict(
|
||||
fail_mode = dict(type='list', default=['success'])
|
||||
)
|
||||
)
|
||||
|
||||
result = dict(changed=True)
|
||||
|
||||
fail_mode = module.params['fail_mode']
|
||||
|
||||
try:
|
||||
if 'leading_junk' in fail_mode:
|
||||
print("leading junk before module output")
|
||||
|
||||
if 'graceful' in fail_mode:
|
||||
module.fail_json(msg="failed gracefully")
|
||||
|
||||
if 'exception' in fail_mode:
|
||||
raise Exception('failing via exception')
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
finally:
|
||||
if 'trailing_junk' in fail_mode:
|
||||
print("trailing junk after module output")
|
||||
|
||||
main()
|
||||
@@ -87,3 +87,68 @@
|
||||
assert:
|
||||
that:
|
||||
- fnf_result.finished
|
||||
|
||||
- name: test graceful module failure
|
||||
async_test:
|
||||
fail_mode: graceful
|
||||
async: 30
|
||||
poll: 1
|
||||
register: async_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: assert task failed correctly
|
||||
assert:
|
||||
that:
|
||||
- async_result.ansible_job_id is match('\d+\.\d+')
|
||||
- async_result.finished == 1
|
||||
- async_result | changed == false
|
||||
- async_result | failed
|
||||
- async_result.msg == 'failed gracefully'
|
||||
|
||||
- name: test exception module failure
|
||||
async_test:
|
||||
fail_mode: exception
|
||||
async: 5
|
||||
poll: 1
|
||||
register: async_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: validate response
|
||||
assert:
|
||||
that:
|
||||
- async_result.ansible_job_id is match('\d+\.\d+')
|
||||
- async_result.finished == 1
|
||||
- async_result.changed == false
|
||||
- async_result | failed == true
|
||||
- async_result.stderr is search('failing via exception', multiline=True)
|
||||
|
||||
- name: test leading junk before JSON
|
||||
async_test:
|
||||
fail_mode: leading_junk
|
||||
async: 5
|
||||
poll: 1
|
||||
register: async_result
|
||||
|
||||
- name: validate response
|
||||
assert:
|
||||
that:
|
||||
- async_result.ansible_job_id is match('\d+\.\d+')
|
||||
- async_result.finished == 1
|
||||
- async_result.changed == true
|
||||
- async_result | success
|
||||
|
||||
- name: test trailing junk after JSON
|
||||
async_test:
|
||||
fail_mode: trailing_junk
|
||||
async: 5
|
||||
poll: 1
|
||||
register: async_result
|
||||
|
||||
- name: validate response
|
||||
assert:
|
||||
that:
|
||||
- async_result.ansible_job_id is match('\d+\.\d+')
|
||||
- async_result.finished == 1
|
||||
- async_result.changed == true
|
||||
- async_result | success
|
||||
- async_result.warnings[0] is search('trailing junk after module output')
|
||||
|
||||
Reference in New Issue
Block a user