diff options
Diffstat (limited to 'dovetail')
-rw-r--r-- | dovetail/test_runner.py | 3 | ||||
-rw-r--r-- | dovetail/utils/dovetail_config.py | 15 | ||||
-rw-r--r-- | dovetail/utils/dovetail_utils.py | 53 | ||||
-rw-r--r-- | dovetail/utils/openstack_utils.py | 20 |
4 files changed, 37 insertions, 54 deletions
diff --git a/dovetail/test_runner.py b/dovetail/test_runner.py index 44eddabd..7aa5854c 100644 --- a/dovetail/test_runner.py +++ b/dovetail/test_runner.py @@ -187,9 +187,12 @@ class DockerRunner(object): class FunctestRunner(DockerRunner): + config_file_name = 'functest_config.yml' + def __init__(self, testcase): self.type = 'functest' super(FunctestRunner, self).__init__(testcase) + self._update_config(testcase) class YardstickRunner(DockerRunner): diff --git a/dovetail/utils/dovetail_config.py b/dovetail/utils/dovetail_config.py index 394bcf73..67ad9612 100644 --- a/dovetail/utils/dovetail_config.py +++ b/dovetail/utils/dovetail_config.py @@ -21,17 +21,10 @@ class DovetailConfig(object): cls.dovetail_config = yaml.safe_load(f) for extra_config_file in cls.dovetail_config['include_config']: - - # The yardstick and bottlenecks config files are with Jinja2. - # They need to be parsed later. - # All other config files should be transfer to like this gradually. - if extra_config_file.startswith(("yardstick", "bottlenecks")): - continue - else: - file_path = os.path.join(conf_path, extra_config_file) - with open(file_path) as f: - extra_config = yaml.safe_load(f) - cls.dovetail_config.update(extra_config) + file_path = os.path.join(conf_path, extra_config_file) + with open(file_path) as f: + extra_config = yaml.safe_load(f) + cls.dovetail_config.update(extra_config) path = os.path.join(conf_path, cls.dovetail_config['cli_file_name']) with open(path) as f: diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py index 02ffa798..e758a84b 100644 --- a/dovetail/utils/dovetail_utils.py +++ b/dovetail/utils/dovetail_utils.py @@ -22,6 +22,7 @@ import python_hosts from dovetail import constants from dovetail_config import DovetailConfig as dt_cfg +from openstack_utils import OS_Utils def exec_log(verbose, logger, msg, level, flush=False): @@ -132,38 +133,6 @@ def check_https_enabled(logger=None): return False -def get_ext_net_name(env_file, logger=None): - ext_net = os.getenv('EXTERNAL_NETWORK') - if ext_net: - return ext_net - else: - https_enabled = check_https_enabled(logger) - insecure_option = '' - insecure = os.getenv('OS_INSECURE') - if https_enabled: - logger.debug("https enabled...") - if insecure: - if insecure.lower() == "true": - insecure_option = ' --insecure ' - else: - logger.warn("Env variable OS_INSECURE is {}, if https + " - "no credential used, should be set as True." - .format(insecure)) - - cmd_check = "openstack %s network list" % insecure_option - ret, msg = exec_cmd(cmd_check, logger) - if ret: - logger.error("The credentials info in {} is invalid." - .format(env_file)) - return None - cmd = "openstack %s network list --long | grep 'External' | head -1 | \ - awk '{print $4}'" % insecure_option - ret, msg = exec_cmd(cmd, logger) - if not ret: - return msg - return None - - def get_duration(start_date, stop_date, logger): fmt = '%Y-%m-%d %H:%M:%S' try: @@ -296,17 +265,15 @@ def combine_files(file_path, result_file, logger=None): 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.") + if https_enabled and insecure and insecure.lower() == "true": + os_utils = OS_Utils(verify=False) + else: + os_utils = OS_Utils() + res, msg = os_utils.list_endpoints() + if not res: + logger.error("Failed to get admin endpoints. Exception message, {}" + .format(msg)) return None result_file = os.path.join(dt_cfg.dovetail_config['result_dir'], 'endpoint_info.json') @@ -315,7 +282,7 @@ def get_openstack_endpoint(logger=None): f.write(msg) logger.debug("Record all endpoint info into file {}." .format(result_file)) - return result_file + return msg except Exception: logger.exception("Failed to write endpoint info into file.") return None diff --git a/dovetail/utils/openstack_utils.py b/dovetail/utils/openstack_utils.py new file mode 100644 index 00000000..c4dfabf9 --- /dev/null +++ b/dovetail/utils/openstack_utils.py @@ -0,0 +1,20 @@ +import json +import os_client_config +import shade +from shade import exc + + +class OS_Utils(object): + + def __init__(self, **kwargs): + self.cloud = shade.OperatorCloud(os_client_config.get_config(**kwargs)) + self.images = [] + self.flavors = [] + + def list_endpoints(self): + try: + res = self.cloud.search_endpoints() + endpoints = json.dumps(res) + return True, endpoints + except exc.OpenStackCloudException as o_exc: + return False, o_exc.orig_message |