unify functest_yaml obtain process 45/19945/3
authorSerenaFeng <feng.xiaowei@zte.com.cn>
Wed, 31 Aug 2016 02:22:33 +0000 (10:22 +0800)
committerSerenaFeng <feng.xiaowei@zte.com.cn>
Wed, 31 Aug 2016 15:20:19 +0000 (23:20 +0800)
functest_yaml is needed in almost all of the testcases, the obtain process is the same:
with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
functest_yaml = yaml.safe_load(f)
f.close()
abstract a method to unify the process, and provide the interface

JIRA: FUNCTEST-447

Change-Id: I96a9a9962d7b466f10bbd3b5ab2495957524e22a
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
14 files changed:
ci/prepare_env.py
cli/commands/cli_os.py
cli/commands/cli_testcase.py
cli/commands/cli_tier.py
testcases/OpenStack/rally/run_rally-cert.py
testcases/OpenStack/tempest/run_tempest.py
testcases/OpenStack/vPing/vping_util.py
testcases/features/copper.py
testcases/features/doctor.py
testcases/features/domino.py
testcases/features/promise.py
testcases/vnf/vIMS/vIMS.py
testcases/vnf/vRNC/parser.py
utils/functest_utils.py

index 116b1a6..b8c536f 100755 (executable)
@@ -50,8 +50,7 @@ CONFIG_FUNCTEST_PATH = os.environ["CONFIG_FUNCTEST_YAML"]
 CONFIG_PATCH_PATH = os.path.join(os.path.dirname(
     CONFIG_FUNCTEST_PATH), "config_patch.yaml")
 
-with open(CONFIG_FUNCTEST_PATH) as f:
-    functest_yaml = yaml.safe_load(f)
+functest_yaml = ft_utils.get_functest_yaml()
 
 with open(CONFIG_PATCH_PATH) as f:
     functest_patch_yaml = yaml.safe_load(f)
index 722c700..a3b7ad3 100644 (file)
@@ -9,15 +9,13 @@
 
 
 import os
+
 import click
 import functest.utils.functest_utils as ft_utils
 import functest.utils.openstack_clean as os_clean
 import functest.utils.openstack_snapshot as os_snapshot
-import yaml
-
 
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
+functest_yaml = ft_utils.get_functest_yaml()
 
 REPOS_DIR = os.getenv('repos_dir')
 FUNCTEST_REPO = ("%s/functest/" % REPOS_DIR)
index d1b2482..498f081 100644 (file)
@@ -15,11 +15,8 @@ import click
 import functest.ci.tier_builder as tb
 import functest.utils.functest_utils as ft_utils
 import functest.utils.functest_vacation as vacation
-import yaml
 
-
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
+functest_yaml = ft_utils.get_functest_yaml()
 
 FUNCTEST_CONF_DIR = functest_yaml.get("general").get(
     "directories").get("dir_functest_conf")
index 7797e9b..ea86a79 100644 (file)
@@ -14,11 +14,8 @@ import os
 import click
 import functest.ci.tier_builder as tb
 import functest.utils.functest_utils as ft_utils
-import yaml
 
-
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
+functest_yaml = ft_utils.get_functest_yaml()
 
 FUNCTEST_CONF_DIR = functest_yaml.get("general").get(
     "directories").get("dir_functest_conf")
index f3eb79d..43096c1 100755 (executable)
 #
 """ tests configuration """
 
-import argparse
 import json
 import os
 import re
 import subprocess
 import time
+
+import argparse
 import functest.utils.functest_logger as ft_logger
 import functest.utils.functest_utils as functest_utils
 import functest.utils.openstack_utils as os_utils
 import iniparse
-import yaml
-
 
 tests = ['authenticate', 'glance', 'cinder', 'heat', 'keystone',
          'neutron', 'nova', 'quotas', 'requests', 'vm', 'all']
@@ -76,9 +75,7 @@ if not os.path.exists(REPO_PATH):
     exit(-1)
 
 
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
-f.close()
+functest_yaml = functest_utils.get_functest_yaml()
 
 HOME = os.environ['HOME'] + "/"
 RALLY_DIR = REPO_PATH + functest_yaml.get("general").get(
index 306664f..fbb65db 100755 (executable)
@@ -60,9 +60,7 @@ logger = ft_logger.Logger("run_tempest").getLogger()
 
 REPO_PATH = os.environ['repos_dir'] + '/functest/'
 
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
-f.close()
+functest_yaml = ft_utils.get_functest_yaml()
 TEST_DB = functest_yaml.get("results").get("test_db_url")
 
 MODE = "smoke"
index 3f4adae..8e9ce23 100644 (file)
@@ -1,6 +1,6 @@
 import os
-import re
 import pprint
+import re
 import sys
 import time
 
@@ -8,13 +8,10 @@ import functest.utils.functest_utils as ft_utils
 import functest.utils.openstack_utils as os_utils
 import paramiko
 from scp import SCPClient
-import yaml
 
 REPO_PATH = os.environ['repos_dir'] + '/functest/'
 
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
-f.close()
+functest_yaml = ft_utils.get_functest_yaml()
 
 NAME_VM_1 = functest_yaml.get("vping").get("vm_name_1")
 NAME_VM_2 = functest_yaml.get("vping").get("vm_name_2")
index c79754a..73def7d 100755 (executable)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-import argparse
-import os
 import sys
 import time
+
+import argparse
 import functest.utils.functest_logger as ft_logger
 import functest.utils.functest_utils as functest_utils
-import yaml
 
 parser = argparse.ArgumentParser()
 parser.add_argument("-r", "--report",
@@ -28,8 +27,7 @@ parser.add_argument("-r", "--report",
                     action="store_true")
 args = parser.parse_args()
 
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
+functest_yaml = functest_utils.get_functest_yaml()
 
 dirs = functest_yaml.get('general').get('directories')
 COPPER_REPO = dirs.get('dir_repo_copper')
index 02edd25..6e6f26f 100755 (executable)
 # 0.2: measure test duration and publish results under json format
 #
 #
-import argparse
-import os
 import time
-import yaml
 
+import argparse
 import functest.utils.functest_logger as ft_logger
 import functest.utils.functest_utils as functest_utils
 
@@ -27,8 +25,7 @@ parser.add_argument("-r", "--report",
                     action="store_true")
 args = parser.parse_args()
 
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
+functest_yaml = functest_utils.get_functest_yaml()
 
 dirs = functest_yaml.get('general').get('directories')
 DOCTOR_REPO = dirs.get('dir_repo_doctor')
index 291a3b4..cc98f54 100755 (executable)
 # 0.3: add report flag to push results when needed
 #
 
-import argparse
-import os
 import time
-import yaml
 
+import argparse
 import functest.utils.functest_logger as ft_logger
 import functest.utils.functest_utils as functest_utils
 
@@ -29,8 +27,7 @@ parser.add_argument("-r", "--report",
                     action="store_true")
 args = parser.parse_args()
 
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
+functest_yaml = functest_utils.get_functest_yaml()
 
 dirs = functest_yaml.get('general').get('directories')
 DOMINO_REPO = dirs.get('dir_repo_domino')
index 3728adf..3f58dce 100755 (executable)
@@ -9,20 +9,18 @@
 #
 # Maintainer : jose.lausuch@ericsson.com
 #
-import argparse
 import json
 import os
 import subprocess
 import time
 
+import argparse
 import functest.utils.functest_logger as ft_logger
 import functest.utils.functest_utils as functest_utils
 import functest.utils.openstack_utils as openstack_utils
 import keystoneclient.v2_0.client as ksclient
-from neutronclient.v2_0 import client as ntclient
 import novaclient.client as nvclient
-import yaml
-
+from neutronclient.v2_0 import client as ntclient
 
 parser = argparse.ArgumentParser()
 
@@ -32,8 +30,7 @@ parser.add_argument("-r", "--report",
                     action="store_true")
 args = parser.parse_args()
 
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
+functest_yaml = functest_utils.get_functest_yaml()
 
 dirs = functest_yaml.get('general').get('directories')
 PROMISE_REPO = dirs.get('dir_repo_promise')
index 3737617..32e8fc1 100755 (executable)
 # http://www.apache.org/licenses/LICENSE-2.0
 ########################################################################
 
-import argparse
 import datetime
 import json
 import os
 import pprint
-import requests
 import subprocess
 import time
-import yaml
 
+import argparse
+import functest.utils.functest_logger as ft_logger
+import functest.utils.functest_utils as functest_utils
+import functest.utils.openstack_utils as os_utils
 import keystoneclient.v2_0.client as ksclient
 import novaclient.client as nvclient
+import requests
 from neutronclient.v2_0 import client as ntclient
 
 from clearwater import clearwater
 from orchestrator import orchestrator
 
-import functest.utils.functest_logger as ft_logger
-import functest.utils.functest_utils as functest_utils
-import functest.utils.openstack_utils as os_utils
-
-
 pp = pprint.PrettyPrinter(indent=4)
 
 
@@ -54,9 +51,7 @@ if not os.path.exists(REPO_PATH):
     logger.error("Functest repository directory not found '%s'" % REPO_PATH)
     exit(-1)
 
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
-f.close()
+functest_yaml = functest_utils.get_functest_yaml()
 
 # Cloudify parameters
 VIMS_DIR = (REPO_PATH +
index 00593b0..d22ca8e 100755 (executable)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-import os
 import time
-import yaml
-import argparse
 
+import argparse
 import functest.utils.functest_logger as ft_logger
 import functest.utils.functest_utils as functest_utils
 
@@ -28,8 +26,7 @@ parser.add_argument("-r", "--report",
                     action="store_true")
 args = parser.parse_args()
 
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
+functest_yaml = functest_utils.get_functest_yaml()
 
 dirs = functest_yaml.get('general').get('directories')
 PARSER_REPO = dirs.get('dir_repo_parser')
index b8bd403..ff82341 100644 (file)
@@ -152,9 +152,7 @@ def get_db_url(logger=None):
     """
     Returns DB URL
     """
-    with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-        functest_yaml = yaml.safe_load(f)
-    f.close()
+    functest_yaml = get_functest_yaml()
     db_url = functest_yaml.get("results").get("test_db_url")
     return db_url
 
@@ -329,9 +327,7 @@ def get_deployment_dir(logger=None):
     """
     Returns current Rally deployment directory
     """
-    with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-        functest_yaml = yaml.safe_load(f)
-    f.close()
+    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")
@@ -437,3 +433,10 @@ def check_test_result(test_name, ret, start_time, stop_time):
 
 def get_testcases_file():
     return FUNCTEST_REPO + "/ci/testcases.yaml"
+
+
+def get_functest_yaml():
+    with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
+        functest_yaml = yaml.safe_load(f)
+    f.close()
+    return functest_yaml