aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2016-09-07 22:13:42 +0800
committerMorgan Richomme <morgan.richomme@orange.com>2016-09-08 16:40:45 +0000
commit5d716dab95938923defdcd992dacaf024de49421 (patch)
treefb6c55fc2a92a8a6837042a1af7fd490fb9a4c62 /utils
parent4a4bfda9d9032aa9ae18ce91f9c62b7ac091851d (diff)
make use of functest_utils.get_parameter_from_yaml
JIRA: FUNCTEST-463 Change-Id: I1d54a65c5bfa2542f2fd3a2e408967641e6e4ac9 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn> (cherry picked from commit 55d301a2622ff5b63d431b9272caa68224d53843)
Diffstat (limited to 'utils')
-rw-r--r--utils/functest_utils.py25
-rwxr-xr-xutils/openstack_clean.py4
-rwxr-xr-xutils/openstack_snapshot.py4
3 files changed, 16 insertions, 17 deletions
diff --git a/utils/functest_utils.py b/utils/functest_utils.py
index 644ad1a1b..c6141d09c 100644
--- a/utils/functest_utils.py
+++ b/utils/functest_utils.py
@@ -152,9 +152,7 @@ def get_db_url():
"""
Returns DB URL
"""
- functest_yaml = get_functest_yaml()
- db_url = functest_yaml.get("results").get("test_db_url")
- return db_url
+ return get_functest_config('results.test_db_url')
def logger_test_results(project, case_name, status, details):
@@ -331,10 +329,8 @@ def get_deployment_dir():
"""
Returns current Rally deployment directory
"""
- functest_yaml = get_functest_yaml()
- deployment_name = functest_yaml.get("rally").get("deployment_name")
- rally_dir = functest_yaml.get("general").get("directories").get(
- "dir_rally_inst")
+ deployment_name = get_functest_config('rally.deployment_name')
+ rally_dir = get_functest_config('general.directories.dir_rally_inst')
cmd = ("rally deployment list | awk '/" + deployment_name +
"/ {print $2}'")
p = subprocess.Popen(cmd, shell=True,
@@ -366,18 +362,16 @@ def get_criteria_by_test(testname):
# YAML UTILS
#
# -----------------------------------------------------------
-def get_parameter_from_yaml(parameter, file=None):
+def get_parameter_from_yaml(parameter, file):
"""
- Returns the value of a given parameter in config_functest.yaml
+ Returns the value of a given parameter in file.yaml
parameter must be given in string format with dots
Example: general.openstack.image_name
"""
- if file is None:
- file = os.environ["CONFIG_FUNCTEST_YAML"]
with open(file) as f:
- functest_yaml = yaml.safe_load(f)
+ file_yaml = yaml.safe_load(f)
f.close()
- value = functest_yaml
+ value = file_yaml
for element in parameter.split("."):
value = value.get(element)
if value is None:
@@ -386,6 +380,11 @@ def get_parameter_from_yaml(parameter, file=None):
return value
+def get_functest_config(parameter):
+ yaml_ = os.environ["CONFIG_FUNCTEST_YAML"]
+ return get_parameter_from_yaml(parameter, yaml_)
+
+
def check_success_rate(case_name, success_rate):
success_rate = float(success_rate)
criteria = get_criteria_by_test(case_name)
diff --git a/utils/openstack_clean.py b/utils/openstack_clean.py
index ef26be1f3..bf582dea2 100755
--- a/utils/openstack_clean.py
+++ b/utils/openstack_clean.py
@@ -29,8 +29,8 @@ import yaml
logger = ft_logger.Logger("openstack_clean").getLogger()
-OS_SNAPSHOT_FILE = ft_utils.get_parameter_from_yaml(
- "general.openstack.snapshot_file")
+OS_SNAPSHOT_FILE = \
+ ft_utils.get_functest_config("general.openstack.snapshot_file")
def separator():
diff --git a/utils/openstack_snapshot.py b/utils/openstack_snapshot.py
index 236cf74e5..560cadbdb 100755
--- a/utils/openstack_snapshot.py
+++ b/utils/openstack_snapshot.py
@@ -29,8 +29,8 @@ import yaml
logger = ft_logger.Logger("openstack_snapshot").getLogger()
-OS_SNAPSHOT_FILE = ft_utils.get_parameter_from_yaml(
- "general.openstack.snapshot_file")
+OS_SNAPSHOT_FILE = \
+ ft_utils.get_functest_config("general.openstack.snapshot_file")
def separator():