From d4c0124d04e188139e27ca8161ec10f94174cf6a Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Wed, 12 Jul 2017 14:48:17 +0200 Subject: [PATCH] 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%. --- lib/ansible/modules/remote_management/wakeonlan.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/remote_management/wakeonlan.py b/lib/ansible/modules/remote_management/wakeonlan.py index eb04c9a483..fcc045ff35 100644 --- a/lib/ansible/modules/remote_management/wakeonlan.py +++ b/lib/ansible/modules/remote_management/wakeonlan.py @@ -102,18 +102,20 @@ def wakeonlan(module, mac, broadcast, port): for i in range(0, len(padding), 2): data = b''.join([data, struct.pack('B', int(padding[i: i + 2], 16))]) + # Broadcast payload to network + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + if not module.check_mode: - # Broadcast payload to network - sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) try: sock.sendto(data, (broadcast, port)) except socket.error: e = get_exception() sock.close() module.fail_json(msg=str(e)) - sock.close() + + sock.close() def main():