mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: wakeonlan
|
||||
version_added: '2.2'
|
||||
|
@ -43,7 +42,8 @@ options:
|
|||
description:
|
||||
- UDP port to use for magic Wake-on-LAN packet.
|
||||
default: 7
|
||||
author: "Dag Wieers (@dagwieers)"
|
||||
author:
|
||||
- Dag Wieers (@dagwieers)
|
||||
todo:
|
||||
- Add arping support to check whether the system is up (before and after)
|
||||
- Enable check-mode support (when we have arping support)
|
||||
|
@ -51,10 +51,10 @@ todo:
|
|||
notes:
|
||||
- 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)
|
||||
- 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
|
||||
wakeonlan:
|
||||
mac: '00:00:5E:00:53:66'
|
||||
|
@ -67,7 +67,7 @@ EXAMPLES = '''
|
|||
delegate_to: localhost
|
||||
'''
|
||||
|
||||
RETURN='''
|
||||
RETURN = r'''
|
||||
# Default return values
|
||||
'''
|
||||
|
||||
|
@ -97,10 +97,12 @@ def wakeonlan(module, mac, broadcast, port):
|
|||
module.fail_json(msg="Incorrect MAC address format: %s" % mac_orig)
|
||||
|
||||
# Create payload for magic packet
|
||||
data = ''
|
||||
data = b''
|
||||
padding = ''.join(['FFFFFFFFFFFF', mac * 20])
|
||||
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))])
|
||||
|
||||
if not module.check_mode:
|
||||
|
||||
# Broadcast payload to network
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
@ -116,19 +118,18 @@ def wakeonlan(module, mac, broadcast, port):
|
|||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
mac = dict(type='str', required=True),
|
||||
broadcast = dict(type='str', default='255.255.255.255'),
|
||||
port = dict(type='int', default=7),
|
||||
argument_spec=dict(
|
||||
mac=dict(type='str', required=True),
|
||||
broadcast=dict(type='str', default='255.255.255.255'),
|
||||
port=dict(type='int', default=7),
|
||||
),
|
||||
supports_check_mode = True,
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
mac = module.params['mac']
|
||||
broadcast = module.params['broadcast']
|
||||
port = module.params['port']
|
||||
|
||||
if not module.check_mode:
|
||||
wakeonlan(module, mac, broadcast, port)
|
||||
|
||||
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/hponcfg.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/gitlab_group.py
|
||||
lib/ansible/modules/source_control/gitlab_project.py
|
||||
|
|
Loading…
Reference in a new issue