bugfixes to JSON junk filter, added unit/integration tests to exercise (#17834)

This commit is contained in:
Matt Davis
2016-10-02 08:03:42 -07:00
committed by GitHub
parent 657506cddd
commit aa0ad073b8
7 changed files with 272 additions and 84 deletions

View 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()

View File

@@ -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')