Publish tenantnetwork scenarios
[functest.git] / functest / ci / check_deployment.py
index ffea6be..a475491 100644 (file)
@@ -18,18 +18,19 @@ Verifies that:
 import logging
 import logging.config
 import os
-import pkg_resources
-from six.moves import urllib
 import socket
 
-from functest.opnfv_tests.openstack.snaps import snaps_utils
-
+import pkg_resources
+from six.moves import urllib
 from snaps.openstack.tests import openstack_tests
 from snaps.openstack.utils import glance_utils
 from snaps.openstack.utils import keystone_utils
 from snaps.openstack.utils import neutron_utils
 from snaps.openstack.utils import nova_utils
 
+from functest.utils import constants
+from functest.opnfv_tests.openstack.snaps import snaps_utils
+
 __author__ = "Jose Lausuch <jose.lausuch@ericsson.com>"
 
 LOGGER = logging.getLogger(__name__)
@@ -37,25 +38,38 @@ LOGGER = logging.getLogger(__name__)
 
 def verify_connectivity(endpoint):
     """ Returns true if an hostname/port is reachable"""
-    connection = socket.socket()
-    connection.settimeout(10)
-    hostname = urllib.parse.urlparse(endpoint).hostname
-    port = urllib.parse.urlparse(endpoint).port
-    if not port:
-        port = 443 if urllib.parse.urlparse(endpoint).scheme == "https" else 80
     try:
-        connection.connect((hostname, port))
-        LOGGER.debug('%s:%s is reachable!', hostname, port)
+        connection = socket.socket()
+        connection.settimeout(10)
+        url = urllib.parse.urlparse(endpoint)
+        port = url.port
+        if not port:
+            port = 443 if url.scheme == "https" else 80
+        connection.connect((url.hostname, port))
+        LOGGER.debug('%s:%s is reachable!', url.hostname, port)
         return True
     except socket.error:
-        LOGGER.exception('%s:%s is not reachable.', hostname, port)
+        LOGGER.error('%s:%s is not reachable.', url.hostname, port)
+    except Exception:  # pylint: disable=broad-except
+        LOGGER.exception(
+            'Errors when verifying connectivity to %s:%s', url.hostname, port)
     return False
 
 
+def get_auth_token(os_creds):
+    """ Get auth token """
+    sess = keystone_utils.keystone_session(os_creds)
+    try:
+        return sess.get_token()
+    except Exception as error:
+        LOGGER.error("Got token ...FAILED")
+        raise error
+
+
 class CheckDeployment(object):
     """ Check deployment class."""
 
-    def __init__(self, rc_file='/home/opnfv/functest/conf/openstack.creds'):
+    def __init__(self, rc_file=constants.ENV_FILE):
         self.rc_file = rc_file
         self.services = ('compute', 'network', 'image')
         self.os_creds = None
@@ -69,12 +83,15 @@ class CheckDeployment(object):
                               format(self.rc_file))
 
     def check_auth_endpoint(self):
-        """ Verifies connectivity to the OS_AUTH_URL given in the RC file """
+        """ Verifies connectivity to the OS_AUTH_URL given in the RC file
+        and get auth token"""
         rc_endpoint = self.os_creds.auth_url
         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)
+        if get_auth_token(self.os_creds):
+            LOGGER.info("Got token ...OK")
 
     def check_public_endpoint(self):
         """ Gets the public endpoint and verifies connectivity to it """