mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
wakeonlan: coverage near 100% and check_mode++ (#26683)
This makes check_mode run more code (without sending out a packet. And should get coverage to 98%.
This commit is contained in:
parent
112cae73df
commit
d4c0124d04
1 changed files with 6 additions and 4 deletions
|
@ -102,17 +102,19 @@ def wakeonlan(module, mac, broadcast, port):
|
||||||
for i in range(0, len(padding), 2):
|
for i in range(0, len(padding), 2):
|
||||||
data = b''.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
|
# Broadcast payload to network
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||||
|
|
||||||
|
if not module.check_mode:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sock.sendto(data, (broadcast, port))
|
sock.sendto(data, (broadcast, port))
|
||||||
except socket.error:
|
except socket.error:
|
||||||
e = get_exception()
|
e = get_exception()
|
||||||
sock.close()
|
sock.close()
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue