Move ping and win_ping closer together (#26028)
So in an effort to verify if Windows modules are feature complete compared to the python equivalent, I stumbled upon these differences. This PR includes: - Add missing 'data' option from documentation - Simplify ping module - Update integration tests to test exception
This commit is contained in:
parent
56d33a2967
commit
5be32aa5af
4 changed files with 117 additions and 56 deletions
|
@ -24,12 +24,11 @@ ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
'supported_by': 'core'}
|
'supported_by': 'core'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: ping
|
module: ping
|
||||||
version_added: historical
|
version_added: historical
|
||||||
short_description: Try to connect to host, verify a usable python and return C(pong) on success.
|
short_description: Try to connect to host, verify a usable python and return C(pong) on success
|
||||||
description:
|
description:
|
||||||
- A trivial test module, this module always returns C(pong) on successful
|
- A trivial test module, this module always returns C(pong) on successful
|
||||||
contact. It does not make sense in playbooks, but it is useful from
|
contact. It does not make sense in playbooks, but it is useful from
|
||||||
|
@ -38,15 +37,35 @@ description:
|
||||||
- For Windows targets, use the M(ping) module instead.
|
- For Windows targets, use the M(ping) module instead.
|
||||||
notes:
|
notes:
|
||||||
- For Windows targets, use the M(ping) module instead.
|
- For Windows targets, use the M(ping) module instead.
|
||||||
options: {}
|
options:
|
||||||
|
data:
|
||||||
|
description:
|
||||||
|
- Data to return for the C(ping) return value.
|
||||||
|
- If this parameter is set to C(crash), the module will cause an exception.
|
||||||
|
default: pong
|
||||||
author:
|
author:
|
||||||
- "Ansible Core Team"
|
- Ansible Core Team
|
||||||
- "Michael DeHaan"
|
- Michael DeHaan
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Test we can logon to 'webservers' and execute python with json lib.
|
# Test we can logon to 'webservers' and execute python with json lib.
|
||||||
ansible webservers -m ping
|
# ansible webservers -m ping
|
||||||
|
|
||||||
|
# Example from an Ansible Playbook
|
||||||
|
- ping:
|
||||||
|
|
||||||
|
# Induce an exception to see what happens
|
||||||
|
- ping:
|
||||||
|
data: crash
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
ping:
|
||||||
|
description: value provided with the data parameter
|
||||||
|
returned: success
|
||||||
|
type: string
|
||||||
|
sample: pong
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
@ -55,15 +74,18 @@ from ansible.module_utils.basic import AnsibleModule
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
data=dict(required=False, default=None),
|
data=dict(type='str', default='pong'),
|
||||||
),
|
),
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
result = dict(ping='pong')
|
|
||||||
if module.params['data']:
|
|
||||||
if module.params['data'] == 'crash':
|
if module.params['data'] == 'crash':
|
||||||
raise Exception("boom")
|
raise Exception("boom")
|
||||||
result['ping'] = module.params['data']
|
|
||||||
|
result = dict(
|
||||||
|
ping=module.params['data'],
|
||||||
|
)
|
||||||
|
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
'supported_by': 'core'}
|
'supported_by': 'core'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r'''
|
||||||
---
|
---
|
||||||
module: win_ping
|
module: win_ping
|
||||||
|
@ -38,11 +37,13 @@ description:
|
||||||
options:
|
options:
|
||||||
data:
|
data:
|
||||||
description:
|
description:
|
||||||
- Alternate data to return instead of 'pong'
|
- Alternate data to return instead of 'pong'.
|
||||||
default: 'pong'
|
- If this parameter is set to C(crash), the module will cause an exception.
|
||||||
|
default: pong
|
||||||
notes:
|
notes:
|
||||||
- For non-Windows targets, use the M(ping) module instead.
|
- For non-Windows targets, use the M(ping) module instead.
|
||||||
author: "Chris Church (@cchurch)"
|
author:
|
||||||
|
- Chris Church (@cchurch)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
|
@ -52,7 +53,15 @@ EXAMPLES = r'''
|
||||||
# Example from an Ansible Playbook
|
# Example from an Ansible Playbook
|
||||||
- win_ping:
|
- win_ping:
|
||||||
|
|
||||||
# Induce a crash to see what happens
|
# Induce an exception to see what happens
|
||||||
- win_ping:
|
- win_ping:
|
||||||
data: crash
|
data: crash
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
ping:
|
||||||
|
description: value provided with the data parameter
|
||||||
|
returned: success
|
||||||
|
type: string
|
||||||
|
sample: pong
|
||||||
|
'''
|
||||||
|
|
|
@ -23,15 +23,31 @@
|
||||||
- name: assert the ping worked
|
- name: assert the ping worked
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "result.changed == false"
|
- not result|failed
|
||||||
- "result.ping == 'pong'"
|
- not result|changed
|
||||||
|
- result.ping == 'pong'
|
||||||
|
|
||||||
- name: ping with data
|
- name: ping with data
|
||||||
ping: data="testing"
|
ping:
|
||||||
|
data: testing
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: assert the ping worked with data
|
- name: assert the ping worked with data
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "result.changed == false"
|
- not result|failed
|
||||||
- "result.ping == 'testing'"
|
- not result|changed
|
||||||
|
- result.ping == 'testing'
|
||||||
|
|
||||||
|
- name: ping with data=crash
|
||||||
|
ping:
|
||||||
|
data: crash
|
||||||
|
register: result
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: assert the ping failed with data=boom
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result|failed
|
||||||
|
- not result|changed
|
||||||
|
- "'Exception: boom' in result.module_stderr"
|
||||||
|
|
|
@ -23,20 +23,21 @@
|
||||||
- name: check win_ping result
|
- name: check win_ping result
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "not win_ping_result|failed"
|
- not win_ping_result|failed
|
||||||
- "not win_ping_result|changed"
|
- not win_ping_result|changed
|
||||||
- "win_ping_result.ping == 'pong'"
|
- win_ping_result.ping == 'pong'
|
||||||
|
|
||||||
- name: test win_ping with data
|
- name: test win_ping with data
|
||||||
win_ping: data=☠
|
win_ping:
|
||||||
|
data: ☠
|
||||||
register: win_ping_with_data_result
|
register: win_ping_with_data_result
|
||||||
|
|
||||||
- name: check win_ping result with data
|
- name: check win_ping result with data
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "not win_ping_with_data_result|failed"
|
- not win_ping_with_data_result|failed
|
||||||
- "not win_ping_with_data_result|changed"
|
- not win_ping_with_data_result|changed
|
||||||
- "win_ping_with_data_result.ping == '☠'"
|
- win_ping_with_data_result.ping == '☠'
|
||||||
|
|
||||||
- name: test win_ping.ps1 with data as complex args
|
- name: test win_ping.ps1 with data as complex args
|
||||||
win_ping.ps1:
|
win_ping.ps1:
|
||||||
|
@ -46,9 +47,9 @@
|
||||||
- name: check win_ping.ps1 result with data
|
- name: check win_ping.ps1 result with data
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "not win_ping_ps1_result|failed"
|
- not win_ping_ps1_result|failed
|
||||||
- "not win_ping_ps1_result|changed"
|
- not win_ping_ps1_result|changed
|
||||||
- "win_ping_ps1_result.ping == 'bleep'"
|
- win_ping_ps1_result.ping == 'bleep'
|
||||||
|
|
||||||
- name: test win_ping with extra args to verify that v2 module replacer escaping works as expected
|
- name: test win_ping with extra args to verify that v2 module replacer escaping works as expected
|
||||||
win_ping:
|
win_ping:
|
||||||
|
@ -76,9 +77,22 @@
|
||||||
- name: check that win_ping with extra args succeeds and ignores everything except data
|
- name: check that win_ping with extra args succeeds and ignores everything except data
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "not win_ping_extra_args_result|failed"
|
- not win_ping_extra_args_result|failed
|
||||||
- "not win_ping_extra_args_result|changed"
|
- not win_ping_extra_args_result|changed
|
||||||
- "win_ping_extra_args_result.ping == 'bloop'"
|
- win_ping_extra_args_result.ping == 'bloop'
|
||||||
|
|
||||||
|
- name: test win_ping using data=crash so that it throws an exception
|
||||||
|
win_ping:
|
||||||
|
data: crash
|
||||||
|
register: win_ping_crash_result
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: check win_ping_crash result
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- win_ping_crash_result|failed
|
||||||
|
- not win_ping_crash_result|changed
|
||||||
|
- "'FullyQualifiedErrorId : boom' in win_ping_crash_result.module_stderr"
|
||||||
|
|
||||||
# TODO: fix code or tests? discrete error returns from PS are strange...
|
# TODO: fix code or tests? discrete error returns from PS are strange...
|
||||||
|
|
||||||
|
@ -90,11 +104,11 @@
|
||||||
#- name: check win_ping_throw result
|
#- name: check win_ping_throw result
|
||||||
# assert:
|
# assert:
|
||||||
# that:
|
# that:
|
||||||
# - "win_ping_throw_result|failed"
|
# - win_ping_throw_result|failed
|
||||||
# - "not win_ping_throw_result|changed"
|
# - not win_ping_throw_result|changed
|
||||||
# - "win_ping_throw_result.msg == 'MODULE FAILURE'"
|
# - win_ping_throw_result.msg == 'MODULE FAILURE'
|
||||||
# - "win_ping_throw_result.exception"
|
# - win_ping_throw_result.exception
|
||||||
# - "win_ping_throw_result.error_record"
|
# - win_ping_throw_result.error_record
|
||||||
#
|
#
|
||||||
#- name: test modified win_ping that throws a string exception
|
#- name: test modified win_ping that throws a string exception
|
||||||
# action: win_ping_throw_string
|
# action: win_ping_throw_string
|
||||||
|
@ -104,11 +118,11 @@
|
||||||
#- name: check win_ping_throw_string result
|
#- name: check win_ping_throw_string result
|
||||||
# assert:
|
# assert:
|
||||||
# that:
|
# that:
|
||||||
# - "win_ping_throw_string_result|failed"
|
# - win_ping_throw_string_result|failed
|
||||||
# - "not win_ping_throw_string_result|changed"
|
# - not win_ping_throw_string_result|changed
|
||||||
# - "win_ping_throw_string_result.msg == 'no ping for you'"
|
# - win_ping_throw_string_result.msg == 'no ping for you'
|
||||||
# - "win_ping_throw_string_result.exception"
|
# - win_ping_throw_string_result.exception
|
||||||
# - "win_ping_throw_string_result.error_record"
|
# - win_ping_throw_string_result.error_record
|
||||||
#
|
#
|
||||||
#- name: test modified win_ping that has a syntax error
|
#- name: test modified win_ping that has a syntax error
|
||||||
# action: win_ping_syntax_error
|
# action: win_ping_syntax_error
|
||||||
|
@ -118,10 +132,10 @@
|
||||||
#- name: check win_ping_syntax_error result
|
#- name: check win_ping_syntax_error result
|
||||||
# assert:
|
# assert:
|
||||||
# that:
|
# that:
|
||||||
# - "win_ping_syntax_error_result|failed"
|
# - win_ping_syntax_error_result|failed
|
||||||
# - "not win_ping_syntax_error_result|changed"
|
# - not win_ping_syntax_error_result|changed
|
||||||
# - "win_ping_syntax_error_result.msg"
|
# - win_ping_syntax_error_result.msg
|
||||||
# - "win_ping_syntax_error_result.exception"
|
# - win_ping_syntax_error_result.exception
|
||||||
#
|
#
|
||||||
#- name: test modified win_ping that has an error that only surfaces when strict mode is on
|
#- name: test modified win_ping that has an error that only surfaces when strict mode is on
|
||||||
# action: win_ping_strict_mode_error
|
# action: win_ping_strict_mode_error
|
||||||
|
@ -131,10 +145,10 @@
|
||||||
#- name: check win_ping_strict_mode_error result
|
#- name: check win_ping_strict_mode_error result
|
||||||
# assert:
|
# assert:
|
||||||
# that:
|
# that:
|
||||||
# - "win_ping_strict_mode_error_result|failed"
|
# - win_ping_strict_mode_error_result|failed
|
||||||
# - "not win_ping_strict_mode_error_result|changed"
|
# - not win_ping_strict_mode_error_result|changed
|
||||||
# - "win_ping_strict_mode_error_result.msg"
|
# - win_ping_strict_mode_error_result.msg
|
||||||
# - "win_ping_strict_mode_error_result.exception"
|
# - win_ping_strict_mode_error_result.exception
|
||||||
#
|
#
|
||||||
#- name: test modified win_ping to verify a Set-Attr fix
|
#- name: test modified win_ping to verify a Set-Attr fix
|
||||||
# action: win_ping_set_attr data="fixed"
|
# action: win_ping_set_attr data="fixed"
|
||||||
|
@ -143,6 +157,6 @@
|
||||||
#- name: check win_ping_set_attr_result result
|
#- name: check win_ping_set_attr_result result
|
||||||
# assert:
|
# assert:
|
||||||
# that:
|
# that:
|
||||||
# - "not win_ping_set_attr_result|failed"
|
# - not win_ping_set_attr_result|failed
|
||||||
# - "not win_ping_set_attr_result|changed"
|
# - not win_ping_set_attr_result|changed
|
||||||
# - "win_ping_set_attr_result.ping == 'fixed'"
|
# - win_ping_set_attr_result.ping == 'fixed'
|
||||||
|
|
Loading…
Reference in a new issue