Merge "Updated vims to support keystone v3"
[functest.git] / functest / utils / config.py
1 import os
2
3 import yaml
4
5
6 class Config(object):
7     def __init__(self):
8         if 'CONFIG_FUNCTEST_YAML' not in os.environ:
9             raise Exception('CONFIG_FUNCTEST_YAML not configed')
10         self.config_functest = os.environ['CONFIG_FUNCTEST_YAML']
11         try:
12             with open(self.config_functest) as f:
13                 self.functest_yaml = yaml.safe_load(f)
14                 self._parse(None, self.functest_yaml)
15         except:
16             raise Exception('Parse {} failed'.format(self.config_functest))
17         self._set_others()
18
19     def _parse(self, attr_now, left_parametes):
20         for param_n, param_v in left_parametes.iteritems():
21             attr_further = self._get_attr_further(attr_now, param_n)
22             if not isinstance(param_v, dict):
23                 self.__setattr__(attr_further, param_v)
24             else:
25                 self._parse(attr_further, param_v)
26
27     def _get_attr_further(self, attr_now, next):
28         return attr_now if next == 'general' else (
29             '{}_{}'.format(attr_now, next) if attr_now else next)
30
31     def _set_others(self):
32         self.env_active = os.path.join(self.dir_functest_conf, "env_active")
33
34
35 CONF = Config()