Merge "Bug Fix: retrieve version from build tag in weekly jobs"
[functest.git] / functest / utils / config.py
1 import os
2
3 import yaml
4
5 import env
6
7
8 class Config(object):
9     def __init__(self):
10         try:
11             with open(env.ENV.CONFIG_FUNCTEST_YAML) as f:
12                 self.functest_yaml = yaml.safe_load(f)
13                 self._parse(None, self.functest_yaml)
14         except Exception as error:
15             raise Exception('Parse config failed: {}'.format(str(error)))
16         self._set_others()
17
18     def _parse(self, attr_now, left_parametes):
19         for param_n, param_v in left_parametes.iteritems():
20             attr_further = self._get_attr_further(attr_now, param_n)
21             if attr_further:
22                 self.__setattr__(attr_further, param_v)
23             if isinstance(param_v, dict):
24                 self._parse(attr_further, param_v)
25
26     def _get_attr_further(self, attr_now, next):
27         return attr_now if next == 'general' else (
28             '{}_{}'.format(attr_now, next) if attr_now else next)
29
30     def _set_others(self):
31         self.env_active = os.path.join(self.dir_functest_conf, "env_active")
32
33
34 CONF = Config()
35
36 if __name__ == "__main__":
37     print CONF.vnf_cloudify_ims
38     print CONF.vnf_cloudify_ims_tenant_images
39     print CONF.vnf_cloudify_ims_tenant_images_centos_7