Fix timeout for socket connection 03/44003/1
authorLinda Wang <wangwulin@huawei.com>
Tue, 26 Sep 2017 03:31:51 +0000 (03:31 +0000)
committerJose Lausuch <jalausuch@suse.com>
Tue, 3 Oct 2017 06:28:47 +0000 (06:28 +0000)
Change-Id: I0688761ba7224f40f79310295efadd9b40bfeefb
Signed-off-by: Linda Wang <wangwulin@huawei.com>
(cherry picked from commit 112e652af2b2f61192d3f1bd903522a14be06b94)

functest/ci/check_deployment.py

index 13bb4c8..e593e17 100644 (file)
@@ -20,7 +20,6 @@ import logging.config
 import os
 import pkg_resources
 import socket
-import time
 from urlparse import urlparse
 
 from snaps.openstack.utils import glance_utils
@@ -34,20 +33,16 @@ __author__ = "Jose Lausuch <jose.lausuch@ericsson.com>"
 LOGGER = logging.getLogger(__name__)
 
 
-def verify_connectivity(adress, port, timeout=10):
+def verify_connectivity(adress, port):
     """ Returns true if an ip/port is reachable"""
     connection = socket.socket()
-    count = 0
-    while count < timeout:
-        try:
-            connection.connect((adress, port))
-            LOGGER.debug('%s:%s is reachable!', adress, port)
-            return True
-        except socket.error:
-            count += 1
-            time.sleep(1)
-            continue
-    LOGGER.error('%s:%s is not reachable.', adress, port)
+    connection.settimeout(10)
+    try:
+        connection.connect((adress, port))
+        LOGGER.debug('%s:%s is reachable!', adress, port)
+        return True
+    except socket.error:
+        LOGGER.error('%s:%s is not reachable.', adress, port)
     return False