From 25ba209e24bc4a84cdee2a9d90195a1718120c20 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Thu, 21 Feb 2013 18:44:35 +0100
Subject: [PATCH] TcpPing: Better error handling, logging

Log every attempt to reach a port on another node. Don't silently return
False if a target not recognized as an IP address is given (e.g. a
hostname).

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
---
 lib/netutils.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/netutils.py b/lib/netutils.py
index 3b7658845..ad9b53095 100644
--- a/lib/netutils.py
+++ b/lib/netutils.py
@@ -281,10 +281,14 @@ def TcpPing(target, port, timeout=10, live_port_needed=False, source=None):
       than C{EADDRNOTAVAIL} will be ignored
 
   """
+  logging.debug("Attempting to reach TCP port %s on target %s with a timeout"
+                " of %s seconds", port, target, timeout)
+
   try:
     family = IPAddress.GetAddressFamily(target)
-  except errors.GenericError:
-    return False
+  except errors.IPAddressError, err:
+    raise errors.ProgrammerError("Family of IP address given in parameter"
+                                 " 'target' can't be determined: %s" % err)
 
   sock = socket.socket(family, socket.SOCK_STREAM)
   success = False
-- 
GitLab