aboutsummaryrefslogtreecommitdiffstats
path: root/functest/utils/config.py
diff options
context:
space:
mode:
authorJose Lausuch <jose.lausuch@ericsson.com>2016-12-20 11:48:16 +0000
committerGerrit Code Review <gerrit@opnfv.org>2016-12-20 11:48:16 +0000
commitef43b6cbc6b445762dd7d48491dfe670bac2f710 (patch)
tree290c9a11b011b2c0d4184b5dcd2b221227f1533d /functest/utils/config.py
parenta60b03203e82f67fb47d4a794a6226a8471b7ecb (diff)
parent5721693e13fe1495541fdd14d9d5e3aed28ef042 (diff)
Merge "Unified way to provide configurations and env variables(proposal 1)"
Diffstat (limited to 'functest/utils/config.py')
-rw-r--r--functest/utils/config.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/functest/utils/config.py b/functest/utils/config.py
new file mode 100644
index 00000000..4cee6349
--- /dev/null
+++ b/functest/utils/config.py
@@ -0,0 +1,30 @@
+import os
+
+import yaml
+
+
+class Config(object):
+ def __init__(self):
+ if 'CONFIG_FUNCTEST_YAML' not in os.environ:
+ raise Exception('CONFIG_FUNCTEST_YAML not configed')
+ self.config_functest = os.environ['CONFIG_FUNCTEST_YAML']
+ try:
+ with open(self.config_functest) as f:
+ self.functest_yaml = yaml.safe_load(f)
+ self.parse(None, self.functest_yaml)
+ except:
+ raise Exception('Parse {} failed'.format(self.config_functest))
+
+ def parse(self, attr_now, left_parametes):
+ for param_n, param_v in left_parametes.iteritems():
+ attr_further = self.get_attr_further(attr_now, param_n)
+ if not isinstance(param_v, dict):
+ self.__setattr__(attr_further, param_v)
+ else:
+ 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)
+
+CONF = Config()