Merge "Fix incompatibility with new tempest functest API"
[sdnvpn.git] / sdnvpn / lib / config.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2017 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 import yaml
11 import os
12
13 from functest.utils.constants import CONST
14 import functest.utils.functest_logger as ft_logger
15 import functest.utils.functest_utils as ft_utils
16
17 logger = ft_logger.Logger("sndvpn_test_config").getLogger()
18
19
20 class CommonConfig(object):
21     """
22     Common configuration parameters across testcases
23     """
24
25     def __init__(self):
26         self.repo_path = CONST.dir_repo_sdnvpn
27         self.config_file = os.path.join(self.repo_path,
28                                         'sdnvpn/test/functest/config.yaml')
29         self.keyfile_path = os.path.join(self.repo_path,
30                                          'sdnvpn/artifacts/id_rsa')
31         self.test_db = CONST.results_test_db_url
32         self.line_length = 90  # length for the summary table
33         self.vm_boot_timeout = 180
34         self.default_flavor = ft_utils.get_parameter_from_yaml(
35             "defaults.flavor", self.config_file)
36         self.image_filename = CONST.openstack_image_file_name
37         self.image_format = CONST.openstack_image_disk_format
38         self.image_path = '{0}/{1}'.format(CONST.dir_functest_data,
39                                            self.image_filename)
40
41
42 class TestcaseConfig(object):
43     """
44     Configuration for a testcase.
45     Parse config.yaml into a dict and create an object out of it.
46     """
47
48     def __init__(self, testcase):
49         common_config = CommonConfig()
50         test_config = None
51         with open(common_config.config_file) as f:
52             testcases_yaml = yaml.safe_load(f)
53             test_config = testcases_yaml['testcases'].get(testcase, None)
54         if test_config is None:
55             logger.error('Test {0} configuration is not present in {1}'
56                          .format(testcase, common_config.config_file))
57         # Update class fields with configuration variables dynamically
58         self.__dict__.update(**test_config)