summaryrefslogtreecommitdiffstats
path: root/func
diff options
context:
space:
mode:
authorAdrian Likins <alikins@grimlock.devel.redhat.com>2008-01-17 16:12:32 -0500
committerAdrian Likins <alikins@grimlock.devel.redhat.com>2008-01-17 16:12:32 -0500
commit42bf650d7da5982acf7bcd33a18c40ecb55946f6 (patch)
tree38d6863ed18e5c8e1b5a4472505853455c808a47 /func
parent34e1fb915d46f04487c75cd162155aa42cce6bbb (diff)
downloadthird_party-func-42bf650d7da5982acf7bcd33a18c40ecb55946f6.tar.gz
third_party-func-42bf650d7da5982acf7bcd33a18c40ecb55946f6.tar.xz
third_party-func-42bf650d7da5982acf7bcd33a18c40ecb55946f6.zip
make networktest.isportopen slightly more robust
now returns a tuple of [return_code, message, data (aka, socket error, etc)]
Diffstat (limited to 'func')
-rw-r--r--func/minion/modules/networktest.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/func/minion/modules/networktest.py b/func/minion/modules/networktest.py
index 5f54c5e..0e6fbb2 100644
--- a/func/minion/modules/networktest.py
+++ b/func/minion/modules/networktest.py
@@ -38,12 +38,22 @@ class NetworkTest(func_module.FuncModule):
self.__args_to_list(args))
def isportopen(self, host, port):
+ # FIXME: the return api here needs some work... -akl
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect((host, int(port)))
- data = sock.recv(2048)
+ timeout = 3.0
+ sock.settimeout(timeout)
+ try:
+ sock.connect((host, int(port)))
+ except socket.error, e:
+ sock.close()
+ return [1, ("connection to %s:%s failed" % (host, port), "%s" % e)]
+ except socket.timeout:
+ sock.close()
+ return [2, ("connection to %s:%s timed out after %s seconds" % (host, port, timeout))]
+
sock.close()
- return [line for line in data.split('\n')]
+ return [0, "connection to %s:%s succeeded" % (host, port)]
def __args_to_list(self, args):
return [arg for arg in args]