Merge "Make tight the way an instance is considered as UP"
[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 logging
12 import pkg_resources
13
14 from functest.utils.constants import CONST
15 import functest.utils.functest_utils as ft_utils
16
17 logger = logging.getLogger('sdnvpn_test_config')
18
19
20 class CommonConfig(object):
21     """
22     Common configuration parameters across testcases
23     """
24     def __init__(self):
25         self.config_file = pkg_resources.resource_filename(
26             'sdnvpn', 'test/functest/config.yaml')
27         self.keyfile_path = pkg_resources.resource_filename(
28             'sdnvpn', 'artifacts/id_rsa')
29         self.test_db = CONST.results_test_db_url
30         self.quagga_setup_script_path = pkg_resources.resource_filename(
31             'sdnvpn', 'artifacts/quagga_setup.sh')
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_images,
39                                            self.image_filename)
40         # This is the ubuntu image used by sfc
41         # Basically vanilla ubuntu + some scripts in there
42         # We can use it to setup a quagga instance
43         # TODO does functest have an ubuntu image somewhere?
44         self.ubuntu_image_name = "sdnvpn-ubuntu"
45         self.ubuntu_image_path = '{0}/{1}'.format(
46             CONST.dir_functest_images,
47             "ubuntu-16.04-server-cloudimg-amd64-disk1.img")
48         self.custom_flavor_name = 'm1.custom'
49         self.custom_flavor_ram = 1024
50         self.custom_flavor_disk = 10
51         self.custom_flavor_vcpus = 1
52
53
54 class TestcaseConfig(object):
55     """
56     Configuration for a testcase.
57     Parse config.yaml into a dict and create an object out of it.
58     """
59
60     def __init__(self, testcase):
61         common_config = CommonConfig()
62         test_config = None
63         with open(common_config.config_file) as f:
64             testcases_yaml = yaml.safe_load(f)
65             test_config = testcases_yaml['testcases'].get(testcase, None)
66         if test_config is None:
67             logger.error('Test {0} configuration is not present in {1}'
68                          .format(testcase, common_config.config_file))
69         # Update class fields with configuration variables dynamically
70         self.__dict__.update(**test_config)