wakeonlan: Add integration tests and improvements (#26254)
This PR includes: - Checkmode improvements - Integration tests - A fix for python3 - PEP8 fixes This backports improvements from the win_wakeonlan module.
This commit is contained in:
parent
9a9b1db62b
commit
f8982dcbd0
4 changed files with 35 additions and 25 deletions
|
@ -22,8 +22,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
|
DOCUMENTATION = r'''
|
||||||
DOCUMENTATION = '''
|
|
||||||
---
|
---
|
||||||
module: wakeonlan
|
module: wakeonlan
|
||||||
version_added: '2.2'
|
version_added: '2.2'
|
||||||
|
@ -43,7 +42,8 @@ options:
|
||||||
description:
|
description:
|
||||||
- UDP port to use for magic Wake-on-LAN packet.
|
- UDP port to use for magic Wake-on-LAN packet.
|
||||||
default: 7
|
default: 7
|
||||||
author: "Dag Wieers (@dagwieers)"
|
author:
|
||||||
|
- Dag Wieers (@dagwieers)
|
||||||
todo:
|
todo:
|
||||||
- Add arping support to check whether the system is up (before and after)
|
- Add arping support to check whether the system is up (before and after)
|
||||||
- Enable check-mode support (when we have arping support)
|
- Enable check-mode support (when we have arping support)
|
||||||
|
@ -51,10 +51,10 @@ todo:
|
||||||
notes:
|
notes:
|
||||||
- This module sends a magic packet, without knowing whether it worked
|
- This module sends a magic packet, without knowing whether it worked
|
||||||
- Only works if the target system was properly configured for Wake-on-LAN (in the BIOS and/or the OS)
|
- Only works if the target system was properly configured for Wake-on-LAN (in the BIOS and/or the OS)
|
||||||
- Some BIOSes have a different (configurable) Wake-on-LAN boot order (i.e. PXE first) when turned off
|
- Some BIOSes have a different (configurable) Wake-on-LAN boot order (i.e. PXE first).
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = r'''
|
||||||
- name: Send a magic Wake-on-LAN packet to 00:00:5E:00:53:66
|
- name: Send a magic Wake-on-LAN packet to 00:00:5E:00:53:66
|
||||||
wakeonlan:
|
wakeonlan:
|
||||||
mac: '00:00:5E:00:53:66'
|
mac: '00:00:5E:00:53:66'
|
||||||
|
@ -67,7 +67,7 @@ EXAMPLES = '''
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN='''
|
RETURN = r'''
|
||||||
# Default return values
|
# Default return values
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -97,39 +97,40 @@ def wakeonlan(module, mac, broadcast, port):
|
||||||
module.fail_json(msg="Incorrect MAC address format: %s" % mac_orig)
|
module.fail_json(msg="Incorrect MAC address format: %s" % mac_orig)
|
||||||
|
|
||||||
# Create payload for magic packet
|
# Create payload for magic packet
|
||||||
data = ''
|
data = b''
|
||||||
padding = ''.join(['FFFFFFFFFFFF', mac * 20])
|
padding = ''.join(['FFFFFFFFFFFF', mac * 20])
|
||||||
for i in range(0, len(padding), 2):
|
for i in range(0, len(padding), 2):
|
||||||
data = ''.join([data, struct.pack('B', int(padding[i: i + 2], 16))])
|
data = b''.join([data, struct.pack('B', int(padding[i: i + 2], 16))])
|
||||||
|
|
||||||
# Broadcast payload to network
|
if not module.check_mode:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
# Broadcast payload to network
|
||||||
try:
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
sock.sendto(data, (broadcast, port))
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||||
except socket.error:
|
try:
|
||||||
e = get_exception()
|
sock.sendto(data, (broadcast, port))
|
||||||
|
except socket.error:
|
||||||
|
e = get_exception()
|
||||||
|
sock.close()
|
||||||
|
module.fail_json(msg=str(e))
|
||||||
sock.close()
|
sock.close()
|
||||||
module.fail_json(msg=str(e))
|
|
||||||
sock.close()
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec=dict(
|
||||||
mac = dict(type='str', required=True),
|
mac=dict(type='str', required=True),
|
||||||
broadcast = dict(type='str', default='255.255.255.255'),
|
broadcast=dict(type='str', default='255.255.255.255'),
|
||||||
port = dict(type='int', default=7),
|
port=dict(type='int', default=7),
|
||||||
),
|
),
|
||||||
supports_check_mode = True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
mac = module.params['mac']
|
mac = module.params['mac']
|
||||||
broadcast = module.params['broadcast']
|
broadcast = module.params['broadcast']
|
||||||
port = module.params['port']
|
port = module.params['port']
|
||||||
|
|
||||||
if not module.check_mode:
|
wakeonlan(module, mac, broadcast, port)
|
||||||
wakeonlan(module, mac, broadcast, port)
|
|
||||||
|
|
||||||
module.exit_json(changed=True)
|
module.exit_json(changed=True)
|
||||||
|
|
||||||
|
|
1
test/integration/targets/wakeonlan/aliases
Normal file
1
test/integration/targets/wakeonlan/aliases
Normal file
|
@ -0,0 +1 @@
|
||||||
|
posix/ci/group2
|
9
test/integration/targets/wakeonlan/tasks/main.yml
Normal file
9
test/integration/targets/wakeonlan/tasks/main.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
- name: Send a magic Wake-on-LAN packet to 00:00:5E:00:53:66
|
||||||
|
wakeonlan:
|
||||||
|
mac: 00:00:5E:00:53:66
|
||||||
|
broadcast: 192.0.2.255
|
||||||
|
|
||||||
|
- name: Send a magic Wake-on-LAN packet on port 9 to 00-00-5E-00-53-66
|
||||||
|
wakeonlan:
|
||||||
|
mac: 00-00-5E-00-53-66
|
||||||
|
port: 9
|
|
@ -474,7 +474,6 @@ lib/ansible/modules/remote_management/hpilo/hpilo_boot.py
|
||||||
lib/ansible/modules/remote_management/hpilo/hpilo_facts.py
|
lib/ansible/modules/remote_management/hpilo/hpilo_facts.py
|
||||||
lib/ansible/modules/remote_management/hpilo/hponcfg.py
|
lib/ansible/modules/remote_management/hpilo/hponcfg.py
|
||||||
lib/ansible/modules/remote_management/stacki/stacki_host.py
|
lib/ansible/modules/remote_management/stacki/stacki_host.py
|
||||||
lib/ansible/modules/remote_management/wakeonlan.py
|
|
||||||
lib/ansible/modules/source_control/bzr.py
|
lib/ansible/modules/source_control/bzr.py
|
||||||
lib/ansible/modules/source_control/gitlab_group.py
|
lib/ansible/modules/source_control/gitlab_group.py
|
||||||
lib/ansible/modules/source_control/gitlab_project.py
|
lib/ansible/modules/source_control/gitlab_project.py
|
||||||
|
|
Loading…
Reference in a new issue