aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/common
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2016-10-31 12:56:38 +0000
committerchenjiankun <chenjiankun1@huawei.com>2016-11-08 09:14:26 +0000
commitb3071ecf941d030092a33086c4d632ed88c52bcf (patch)
tree163e6e006ddc61811a516bb141934f918dd10486 /yardstick/common
parente80a6484956de102d14b2b42349ac1e90510cd82 (diff)
Create a constants.py to manage constant variable consistently
JIRA: YARDSTICK-378 Change-Id: I527d4f60f2a2081730118bdbbea6c19fc093672f Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'yardstick/common')
-rw-r--r--yardstick/common/constants.py3
-rw-r--r--yardstick/common/utils.py23
2 files changed, 26 insertions, 0 deletions
diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py
new file mode 100644
index 000000000..40b29a717
--- /dev/null
+++ b/yardstick/common/constants.py
@@ -0,0 +1,3 @@
+CONFIG_SAMPLE = '/etc/yardstick/config.yaml'
+
+RELENG_DIR = 'releng.dir'
diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py
index c482b4da4..d639fb66a 100644
--- a/yardstick/common/utils.py
+++ b/yardstick/common/utils.py
@@ -17,6 +17,7 @@
import os
import sys
+import yaml
from oslo_utils import importutils
import yardstick
@@ -68,3 +69,25 @@ def import_modules_from_package(package):
new_package = ".".join(root.split(os.sep)).split("....")[1]
module_name = "%s.%s" % (new_package, filename[:-3])
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):
+ with open(file_path) as f:
+ value = yaml.safe_load(f)
+ value = reduce(func, args.split('.'), value)
+
+ if value is None:
+ print 'parameter not found'
+ return None
+
+ return value
+ else:
+ print 'file not exist'
+ return None