From 46754323aeac6193dd9b451a6525a478fdb0887b Mon Sep 17 00:00:00 2001 From: xudan Date: Tue, 29 May 2018 02:42:11 -0400 Subject: Replace openstack commands with shade Use openstack shade to get endpoint infomation rather than executing openstack commands directly. The next step can replace openstack commands by shade for some test cases that need to create openstack resources (images, flavors) if we agree to use shade. JIRA: DOVETAIL-659 Change-Id: I72b302fb2d4a61e9249a7e53f81ea9464944dcd3 Signed-off-by: xudan --- dovetail/test_runner.py | 3 +++ dovetail/utils/dovetail_config.py | 15 +++-------- dovetail/utils/dovetail_utils.py | 53 ++++++++------------------------------- dovetail/utils/openstack_utils.py | 20 +++++++++++++++ etc/conf/dovetail_config.yml | 3 --- etc/conf/functest_config.yml | 10 +++++++- requirements.txt | 3 ++- 7 files changed, 48 insertions(+), 59 deletions(-) create mode 100644 dovetail/utils/openstack_utils.py 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 diff --git a/etc/conf/dovetail_config.yml b/etc/conf/dovetail_config.yml index 312f8ba0..8722e399 100644 --- a/etc/conf/dovetail_config.yml +++ b/etc/conf/dovetail_config.yml @@ -83,9 +83,6 @@ parameters: path: '("validate", "testcase")' include_config: - - functest_config.yml - - yardstick_config.yml - - bottlenecks_config.yml - vnftest_config.yml test_project: diff --git a/etc/conf/functest_config.yml b/etc/conf/functest_config.yml index 93e822f4..1e7cfeb3 100644 --- a/etc/conf/functest_config.yml +++ b/etc/conf/functest_config.yml @@ -1,9 +1,17 @@ --- + +{% set validate_testcase = validate_testcase or '' %} +{% set os_insecure = os_insecure or 'False' %} +{% set os_verify = '' %} +{% if os_insecure == 'True' %} + {% set os_verify = ' -e OS_VERIFY= ' %} +{% endif %} + functest: image_name: opnfv/functest-smoke docker_tag: fraser opts: '-id --privileged=true' - envs: '-e INSTALLER_TYPE=unknown -e DEPLOY_SCENARIO=unknown -e NODE_NAME=unknown + envs: '{{os_verify}} -e INSTALLER_TYPE=unknown -e DEPLOY_SCENARIO=unknown -e NODE_NAME=unknown -e TEST_DB_URL=file:///home/opnfv/functest/results/functest_results.txt' config: dir: '/home/opnfv/userconfig' diff --git a/requirements.txt b/requirements.txt index 82c385bf..fb94da5d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ click==6.6 Jinja2==2.8 keystoneauth1==2.12.3 openstacksdk==0.9.5 -os-client-config==1.21.1 +os-client-config==1.28.0 osc-lib==1.1.0 paramiko==1.18.0 pbr==2.0.0 @@ -18,3 +18,4 @@ PyYAML==3.11 requests==2.10.0 six==1.10.0 stevedore==1.20.0 +shade==1.22.2 -- cgit 1.2.3-korg