From f7d0d72958b41ea6685457abea6dc4d83f4370c3 Mon Sep 17 00:00:00 2001 From: xudan Date: Fri, 17 Mar 2017 09:23:45 +0000 Subject: dovetail tool: remove installer and CI related variables JIRA: DOVETAIL-371 1. remove all the envs in functest_config.yml and yardstick_config.yml 2. remove all relative cmds in cmd_config.yml 3. remove all the envs when running a new functest/yardstick container 4. add some variables just for functest pushing results to db 5. get the external network name for yardstick 6. make --debug/-d just control the log level shown on the screen 7. set requests=2.10.0 since python-openstackclient needs 'requests!=2.12.2,!=2.13.0,>=2.10.0' Change-Id: I9f941e09d067fc95a14c3c9be1374f41df4a9a16 Signed-off-by: xudan --- dovetail/utils/dovetail_config.py | 48 +-------------------------------------- dovetail/utils/dovetail_utils.py | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 47 deletions(-) (limited to 'dovetail/utils') diff --git a/dovetail/utils/dovetail_config.py b/dovetail/utils/dovetail_config.py index 1efb4d8f..f8193e5d 100644 --- a/dovetail/utils/dovetail_config.py +++ b/dovetail/utils/dovetail_config.py @@ -9,19 +9,12 @@ import yaml import os -import re class DovetailConfig(object): dovetail_config = {} - CMD_NAME_TRANS = { - 'SUT_TYPE': 'INSTALLER_TYPE', - 'SUT_IP': 'INSTALLER_IP', - 'DEBUG': 'CI_DEBUG', - } - @classmethod def load_config_files(cls): curr_path = os.path.dirname(os.path.abspath(__file__)) @@ -39,23 +32,6 @@ class DovetailConfig(object): cmd_yml = yaml.safe_load(f) cls.dovetail_config['cli'] = cmd_yml[cmd_yml.keys()[0]] - @classmethod - def cmd_name_trans(cls, cmd_name): - key = cmd_name.upper() - return cls.CMD_NAME_TRANS.get(key, key) - - # Analyze the kind of the giving path, - # return true for env path, - # return false for non_env path. - @classmethod - def is_env_path(cls, path): - if len(path) == 2: - test_project = cls.dovetail_config['test_project'] - if path[0] in test_project and path[1] == 'envs': - return True - else: - return False - # update dovetail_config dict with the giving path. # if path is in the dovetail_config dict, its value will be replaced. # if path is not in the dict, it will be added as a new item of the dict. @@ -66,29 +42,7 @@ class DovetailConfig(object): for item in value['path']: path_list.append([(k.strip()) for k in item.split('/')]) for path in path_list: - if cls.is_env_path(path): - cls.update_envs(key, path, value['value']) - else: - cls.update_non_envs(path, value['value']) - - @classmethod - def update_envs(cls, key, path, value): - key = cls.cmd_name_trans(key) - if not value and key in os.environ: - value = os.environ[key] - if value: - cls.update_config_envs(path[0], key, value) - - @classmethod - def update_config_envs(cls, validate_type, key, value): - envs = cls.dovetail_config[validate_type]['envs'] - old_value = re.findall(r'\s+%s=(.*?)(\s+|$)' % key, envs) - if old_value == []: - envs += ' -e ' + key + '=' + value - else: - envs = envs.replace(old_value[0][0], value) - cls.dovetail_config[validate_type]['envs'] = envs - return envs + cls.update_non_envs(path, value['value']) @staticmethod def set_leaf_dict(dic, path, value): diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py index a54081f5..32d334e8 100644 --- a/dovetail/utils/dovetail_utils.py +++ b/dovetail/utils/dovetail_utils.py @@ -10,6 +10,8 @@ # import sys +import os +import re import subprocess from collections import Mapping, Set, Sequence @@ -96,6 +98,31 @@ def get_obj_by_path(obj, dst_path): return obj +def source_env(env_file): + with open(env_file, 'r') as f: + lines = f.readlines() + for line in lines: + for match in re.findall(r"export (.*)=(.*)", line): + match = (match[0].strip('\"'), match[1].strip('\"')) + match = (match[0].strip('\''), match[1].strip('\'')) + os.environ.update({match[0]: match[1]}) + + +def get_ext_net_name(env_file, logger=None): + source_env(env_file) + cmd_check = "openstack network list" + ret, msg = exec_cmd(cmd_check, logger) + if ret: + logger.error("The credentials info in %s is invalid." % env_file) + return None + cmd = "openstack network list --long | grep 'External' | head -1 | \ + awk '{print $4}'" + ret, msg = exec_cmd(cmd, logger) + if not ret: + return msg + return None + + def show_progress_bar(length): max_len = 50 length %= max_len -- cgit 1.2.3-korg