Merge "Move few local ODL SFC confs to global functest confs"
[functest.git] / functest / utils / config.py
1 #!/usr/bin/env python
2
3 import os
4 import yaml
5
6 import six
7
8 from functest.utils import env
9
10
11 class Config(object):
12     def __init__(self):
13         try:
14             with open(env.ENV.CONFIG_FUNCTEST_YAML) as f:
15                 self.functest_yaml = yaml.safe_load(f)
16                 self._parse(None, self.functest_yaml)
17         except Exception as error:
18             raise Exception('Parse config failed: {}'.format(str(error)))
19         self._set_others()
20
21     def _parse(self, attr_now, left_parametes):
22         for param_n, param_v in six.iteritems(left_parametes):
23             attr_further = self._get_attr_further(attr_now, param_n)
24             if attr_further:
25                 self.__setattr__(attr_further, param_v)
26             if isinstance(param_v, dict):
27                 self._parse(attr_further, param_v)
28
29     def _get_attr_further(self, attr_now, next):
30         return attr_now if next == 'general' else (
31             '{}_{}'.format(attr_now, next) if attr_now else next)
32
33     def _set_others(self):
34         self.env_active = os.path.join(self.dir_functest_conf, "env_active")
35
36
37 CONF = Config()