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