From: Thierry Parmentelat Date: Thu, 5 Mar 2015 12:43:18 +0000 (+0100) Subject: make tcptest ready more stringent : check that eth0 indeed has an ipv4 address X-Git-Tag: tests-5.3-10~14 X-Git-Url: http://git.onelab.eu/?p=tests.git;a=commitdiff_plain;h=e5be380b21da0baf2b1a30cdc09c4d8f96aa690f make tcptest ready more stringent : check that eth0 indeed has an ipv4 address --- diff --git a/system/tcptest.py b/system/tcptest.py index bff3c66..6cd1213 100755 --- a/system/tcptest.py +++ b/system/tcptest.py @@ -82,13 +82,20 @@ class Ready: default=socket.gethostname(), help="address") (options, args) = parser.parse_args() - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - s.bind((options.address, options.port)) - sys.exit(0) - except Exception as e: - print e - sys.exit(1) + def can_bind (): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + try: + s.bind((options.address, options.port)) + return True + except Exception as e: + print e + return False + + def eth0_has_ipv4(): + command = "ip address show eth0 | grep -q ' inet '" + return subprocess.check_call(command, shell=True) == 0 + + sys.exit(0 if can_bind() and eth0_has_ipv4() else 1) class Client: """