Get SUT's endpoint info 01/46501/2
authorxudan <xudan16@huawei.com>
Wed, 1 Nov 2017 03:53:18 +0000 (23:53 -0400)
committerxudan <xudan16@huawei.com>
Thu, 2 Nov 2017 08:08:26 +0000 (04:08 -0400)
Get the admin endpoints of all service.

JIRA: DOVETAIL-546

Change-Id: Ie0ac3bc5b4eb0885046e207b73217994a4f0e358
Signed-off-by: xudan <xudan16@huawei.com>
dovetail/run.py
dovetail/utils/dovetail_utils.py

index b7c7897..4778fa5 100755 (executable)
@@ -262,6 +262,7 @@ def main(*args, **kwargs):
     copy_userconfig_files(logger)
     copy_patch_files(logger)
     dt_utils.check_docker_version(logger)
+    dt_utils.get_openstack_endpoint(logger)
     validate_input(kwargs, dt_cfg.dovetail_config['validate_input'], logger)
     check_hosts_file(logger)
     configs = filter_config(kwargs, logger)
index 75f7356..99d4448 100644 (file)
@@ -297,3 +297,30 @@ def combine_files(file_path, result_file, logger=None):
         logger.exception("Failed to write file {}.".format(result_file))
         return None
     return result_file
+
+
+def get_openstack_endpoint(logger=None):
+    https_enabled = check_https_enabled(logger)
+    insecure_option = ''
+    insecure = os.getenv('OS_INSECURE',)
+    if https_enabled:
+        if insecure:
+            if insecure.lower() == "true":
+                insecure_option = ' --insecure '
+    cmd = ("openstack {} endpoint list --interface admin -f json"
+           .format(insecure_option))
+    ret, msg = exec_cmd(cmd, logger, verbose=False)
+    if ret != 0:
+        logger.error("Failed to get the endpoint info.")
+        return None
+    result_file = os.path.join(dt_cfg.dovetail_config['result_dir'],
+                               'endpoint_info.json')
+    try:
+        with open(result_file, 'w') as f:
+            f.write(msg)
+            logger.debug("Record all endpoint info into file {}."
+                         .format(result_file))
+            return result_file
+    except Exception:
+        logger.exception("Failed to write endpoint info into file.")
+        return None