aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/common/utils.py
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-04-01 01:19:16 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-04-01 06:24:12 +0000
commitb74d875134b988a26441d559a9e700aaa68d6a0c (patch)
tree5e367401e8b5f16f2c2fe1d52d91203d2dd20424 /yardstick/common/utils.py
parent66aa1cc17bcc3643c2852df7df4a355897ba0b57 (diff)
Yardstick virtualenv support
JIRA: YARDSTICK-620 Currently we recommend using docker to run yardstick. And it is hard to use virtualenv to install yardstick. So I modify install.sh in yardstick root path. It will support using virtualenv to install yardstick(including API) in linux. In this patch, I make yardstick support read yardstick configuration have priority over constants. Change-Id: I9ea1241b228532a6497451e6c8f232173ddb783e Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'yardstick/common/utils.py')
-rw-r--r--yardstick/common/utils.py36
1 files changed, 20 insertions, 16 deletions
diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py
index d2be8000e..7035f3374 100644
--- a/yardstick/common/utils.py
+++ b/yardstick/common/utils.py
@@ -84,26 +84,30 @@ def import_modules_from_package(package):
try_append_module(module_name, sys.modules)
-def get_para_from_yaml(file_path, args):
-
- def func(a, b):
- if a is None:
- return None
- return a.get(b)
-
- if os.path.exists(file_path):
+def parse_yaml(file_path):
+ try:
with open(file_path) as f:
value = yaml.safe_load(f)
- value = reduce(func, args.split('.'), value)
+ except IOError:
+ return {}
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+ else:
+ return value
- if value is None:
- print('parameter not found')
- return None
- return value
- else:
- print('file not exist')
- return None
+def get_param(key, default=''):
+
+ conf_file = os.environ.get('CONF_FILE', '/etc/yardstick/yardstick.yaml')
+
+ conf = parse_yaml(conf_file)
+ try:
+ return reduce(lambda a, b: a[b], key.split('.'), conf)
+ except KeyError:
+ if not default:
+ raise
+ return default
def makedirs(d):