mirror of https://github.com/ansible/ansible.git
Merge 7db792add3
into a7e666829e
commit
2767df208f
@ -0,0 +1,2 @@
|
||||
shippable/posix/group4
|
||||
context/controller
|
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/python
|
||||
# Copyright: Contributors to the Ansible project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.six import text_type
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec={
|
||||
'rc': {
|
||||
'type': 'int',
|
||||
'default': 0,
|
||||
},
|
||||
'stdout': {
|
||||
'type': 'raw',
|
||||
'default': '{"msg": "Hello, World!"}',
|
||||
},
|
||||
'stderr': {
|
||||
'type': 'raw',
|
||||
'default': '',
|
||||
},
|
||||
'traceback': {
|
||||
'type': 'bool',
|
||||
'default': False,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
if module.params['traceback']:
|
||||
raise Exception('boom')
|
||||
|
||||
stdout = module.params['stdout']
|
||||
stderr = module.params['stderr']
|
||||
if not isinstance(stdout, text_type):
|
||||
stdout = json.dumps(stdout, indent=4, sort_keys=True)
|
||||
if not isinstance(stderr, text_type):
|
||||
stderr = json.dumps(stderr, indent=4, sort_keys=True)
|
||||
|
||||
print('\n' + stdout, file=sys.stdout)
|
||||
print('\n' + stderr, file=sys.stderr)
|
||||
sys.exit(module.params['rc'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,42 @@
|
||||
- name: Nominal behavior
|
||||
module_behavior:
|
||||
register: nominal_behavior
|
||||
|
||||
- name: Missing stdout
|
||||
module_behavior:
|
||||
stdout: ''
|
||||
register: missing_stdout
|
||||
ignore_errors: true
|
||||
|
||||
- name: non-zero rc
|
||||
module_behavior:
|
||||
rc: 2
|
||||
register: non_zero_rc
|
||||
ignore_errors: true
|
||||
|
||||
- name: traceback
|
||||
module_behavior:
|
||||
traceback: true
|
||||
register: traceback
|
||||
ignore_errors: true
|
||||
|
||||
- name: behavior assertions
|
||||
assert:
|
||||
that:
|
||||
- nominal_behavior is successful
|
||||
- nominal_behavior.msg == 'Hello, World!'
|
||||
|
||||
- missing_stdout is failed
|
||||
- missing_stdout.msg.splitlines()|first == empty_stdout
|
||||
|
||||
- non_zero_rc is successful
|
||||
- non_zero_rc.warnings is defined
|
||||
- non_zero_rc.warnings|select('search', 'exited with a non-zero rc') != []
|
||||
# - non_zero_rc.module_rc == 2
|
||||
# - non_zero_rc.module_stdout is defined
|
||||
# - non_zero_rc.module_stderr is defined
|
||||
|
||||
- traceback is failed
|
||||
- traceback.module_rc is not defined
|
||||
vars:
|
||||
empty_stdout: The module returned an empty response to stdout but exited with rc=0, this may indicate a misbehaving module.
|
Loading…
Reference in New Issue