diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-01-26 17:41:02 +0100 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-01-26 18:14:20 +0100 |
commit | 4862f742a08658459afee5e272122af5f2cdc9de (patch) | |
tree | 07b73dbb0c3c35e7fb4a339ba070e9c7117d8d7f /functest | |
parent | 01efa1e4229157b46d352bce202ed4192992dd3f (diff) |
Avoid duplicating get_parameter_from_yaml
It switches to this helper which was locally copied.
Change-Id: Iaa30d83e8c0e2d4472f4ef8fe1da4943e424ebb3
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest')
-rw-r--r-- | functest/opnfv_tests/vnf/router/cloudify_vrouter.py | 59 | ||||
-rw-r--r-- | functest/tests/unit/vnf/router/test_cloudify_vrouter.py | 3 |
2 files changed, 24 insertions, 38 deletions
diff --git a/functest/opnfv_tests/vnf/router/cloudify_vrouter.py b/functest/opnfv_tests/vnf/router/cloudify_vrouter.py index 1596860d..020085ba 100644 --- a/functest/opnfv_tests/vnf/router/cloudify_vrouter.py +++ b/functest/opnfv_tests/vnf/router/cloudify_vrouter.py @@ -18,12 +18,12 @@ import time from cloudify_rest_client import CloudifyClient from cloudify_rest_client.executions import Execution from scp import SCPClient -import yaml from functest.opnfv_tests.openstack.snaps import snaps_utils import functest.opnfv_tests.vnf.router.vrouter_base as vrouter_base from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf from functest.utils.constants import CONST +from functest.utils import functest_utils from git import Repo @@ -79,35 +79,46 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase): config_file = os.path.join(self.case_dir, self.config) self.orchestrator = dict( - requirements=get_config("orchestrator.requirements", config_file), + requirements=functest_utils.get_parameter_from_yaml( + "orchestrator.requirements", config_file), ) self.details['orchestrator'] = dict( - name=get_config("orchestrator.name", config_file), - version=get_config("orchestrator.version", config_file), + name=functest_utils.get_parameter_from_yaml( + "orchestrator.name", config_file), + version=functest_utils.get_parameter_from_yaml( + "orchestrator.version", config_file), status='ERROR', result='' ) self.__logger.debug("Orchestrator configuration %s", self.orchestrator) self.__logger.debug("name = %s", self.name) self.vnf = dict( - descriptor=get_config("vnf.descriptor", config_file), - inputs=get_config("vnf.inputs", config_file), - requirements=get_config("vnf.requirements", config_file) + descriptor=functest_utils.get_parameter_from_yaml( + "vnf.descriptor", config_file), + inputs=functest_utils.get_parameter_from_yaml( + "vnf.inputs", config_file), + requirements=functest_utils.get_parameter_from_yaml( + "vnf.requirements", config_file) ) self.details['vnf'] = dict( descriptor_version=self.vnf['descriptor']['version'], - name=get_config("vnf.name", config_file), - version=get_config("vnf.version", config_file), + name=functest_utils.get_parameter_from_yaml( + "vnf.name", config_file), + version=functest_utils.get_parameter_from_yaml( + "vnf.version", config_file), ) self.__logger.debug("VNF configuration: %s", self.vnf) self.util = Utilvnf() self.details['test_vnf'] = dict( - name=get_config("vnf_test_suite.name", config_file), - version=get_config("vnf_test_suite.version", config_file) + name=functest_utils.get_parameter_from_yaml( + "vnf_test_suite.name", config_file), + version=functest_utils.get_parameter_from_yaml( + "vnf_test_suite.version", config_file) ) - self.images = get_config("tenant_images", config_file) + self.images = functest_utils.get_parameter_from_yaml( + "tenant_images", config_file) self.__logger.info("Images needed for vrouter: %s", self.images) def prepare(self): @@ -433,30 +444,6 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase): self.cfy_manager_ip, self.deployment_name, target_vnf_name) -# ---------------------------------------------------------- -# -# YAML UTILS -# -# ----------------------------------------------------------- -def get_config(parameter, file_path): - """ - Get config parameter. - Returns the value of a given parameter in file.yaml - parameter must be given in string format with dots - Example: general.openstack.image_name - """ - with open(file_path) as config_file: - file_yaml = yaml.safe_load(config_file) - config_file.close() - value = file_yaml - for element in parameter.split("."): - value = value.get(element) - if value is None: - raise ValueError("The parameter %s is not defined in" - " reporting.yaml" % parameter) - return value - - def wait_for_execution(client, execution, logger, timeout=7200, ): """Wait for a workflow execution on Cloudify Manager.""" # if execution already ended - return without waiting diff --git a/functest/tests/unit/vnf/router/test_cloudify_vrouter.py b/functest/tests/unit/vnf/router/test_cloudify_vrouter.py index 9711da72..db03d716 100644 --- a/functest/tests/unit/vnf/router/test_cloudify_vrouter.py +++ b/functest/tests/unit/vnf/router/test_cloudify_vrouter.py @@ -49,8 +49,7 @@ class CloudifyVrouterTesting(unittest.TestCase): 'cloudify_vrouter.vrouter_base.Utilvnf'), \ mock.patch('os.makedirs'), \ mock.patch( - 'functest.opnfv_tests.vnf.router.cloudify_vrouter.' - 'get_config', + 'functest.utils.functest_utils.get_parameter_from_yaml', return_value={ 'tenant_images': 'foo', 'orchestrator': self.orchestrator, |