Fix the way of getting endpoint port 53/47553/2
authorLinda Wang <wangwulin@huawei.com>
Tue, 21 Nov 2017 03:38:49 +0000 (03:38 +0000)
committerLinda Wang <wangwulin@huawei.com>
Tue, 21 Nov 2017 07:18:58 +0000 (07:18 +0000)
It will fail if the endpoint does not contain any port value when
executing self.os_auth_url.rsplit("/")[2].rsplit(":")[1]

JIRA: FUNCTEST-892

Change-Id: Iba4103884b7c6e3b157bb95d775fac02c32ae728
Signed-off-by: Linda Wang <wangwulin@huawei.com>
functest/ci/check_deployment.py
functest/cli/commands/cli_os.py

index e1ad137..db94fd7 100644 (file)
@@ -35,16 +35,20 @@ __author__ = "Jose Lausuch <jose.lausuch@ericsson.com>"
 LOGGER = logging.getLogger(__name__)
 
 
-def verify_connectivity(adress, port):
+def verify_connectivity(endpoint):
     """ Returns true if an ip/port is reachable"""
     connection = socket.socket()
     connection.settimeout(10)
+    ip = urlparse(endpoint).hostname
+    port = urlparse(endpoint).port
+    if not port:
+        port = 443 if urlparse(endpoint).scheme == "https" else 80
     try:
-        connection.connect((adress, port))
-        LOGGER.debug('%s:%s is reachable!', adress, port)
+        connection.connect((ip, port))
+        LOGGER.debug('%s:%s is reachable!', ip, port)
         return True
     except socket.error:
-        LOGGER.error('%s:%s is not reachable.', adress, port)
+        LOGGER.exception('%s:%s is not reachable.', ip, port)
     return False
 
 
@@ -67,8 +71,7 @@ class CheckDeployment(object):
     def check_auth_endpoint(self):
         """ Verifies connectivity to the OS_AUTH_URL given in the RC file """
         rc_endpoint = self.os_creds.auth_url
-        if not (verify_connectivity(urlparse(rc_endpoint).hostname,
-                                    urlparse(rc_endpoint).port)):
+        if not (verify_connectivity(rc_endpoint)):
             raise Exception("OS_AUTH_URL {} is not reachable.".
                             format(rc_endpoint))
         LOGGER.info("Connectivity to OS_AUTH_URL %s ...OK", rc_endpoint)
@@ -78,8 +81,7 @@ class CheckDeployment(object):
         public_endpoint = keystone_utils.get_endpoint(self.os_creds,
                                                       'identity',
                                                       interface='public')
-        if not (verify_connectivity(urlparse(public_endpoint).hostname,
-                                    urlparse(public_endpoint).port)):
+        if not (verify_connectivity(public_endpoint)):
             raise Exception("Public endpoint {} is not reachable.".
                             format(public_endpoint))
         LOGGER.info("Connectivity to the public endpoint %s ...OK",
@@ -90,8 +92,7 @@ class CheckDeployment(object):
         endpoint = keystone_utils.get_endpoint(self.os_creds,
                                                service,
                                                interface='public')
-        if not (verify_connectivity(urlparse(endpoint).hostname,
-                                    urlparse(endpoint).port)):
+        if not (verify_connectivity(endpoint)):
             raise Exception("{} endpoint {} is not reachable.".
                             format(service, endpoint))
         LOGGER.info("Connectivity to endpoint '%s' %s ...OK",
index e97ab08..71cd78c 100644 (file)
@@ -9,6 +9,7 @@
 
 
 import os
+from urlparse import urlparse
 
 import click
 
@@ -27,8 +28,8 @@ class OpenStack(object):
         self.openstack_creds = CONST.__getattribute__('openstack_creds')
         self.snapshot_file = CONST.__getattribute__('openstack_snapshot_file')
         if self.os_auth_url:
-            self.endpoint_ip = self.os_auth_url.rsplit("/")[2].rsplit(":")[0]
-            self.endpoint_port = self.os_auth_url.rsplit("/")[2].rsplit(":")[1]
+            self.endpoint_ip = urlparse(self.os_auth_url).hostname
+            self.endpoint_port = urlparse(self.os_auth_url).port
 
     def ping_endpoint(self):
         if self.os_auth_url is None: