import yaml
import logging
-CONF_FILE = os.path.join(os.environ['HOME'], '.teuthology.yaml')
-
log = logging.getLogger(__name__)
-class _Config(object):
+class Config(object):
"""
This class is intended to unify teuthology's many configuration files and
objects. Currently it serves as a convenient interface to
~/.teuthology.yaml and nothing else.
"""
+ teuthology_yaml = os.path.join(os.environ['HOME'], '.teuthology.yaml')
+
def __init__(self):
- if os.path.exists(CONF_FILE):
- self.__conf = yaml.safe_load(file(CONF_FILE))
+ self.load_files()
+
+ def load_files(self):
+ if os.path.exists(self.teuthology_yaml):
+ self.__conf = yaml.safe_load(file(self.teuthology_yaml))
else:
- log.debug("%s not found", CONF_FILE)
+ log.debug("%s not found", self.teuthology_yaml)
self.__conf = {}
# This property declaration exists mainly as an example; it is not
def __getattr__(self, name):
return self.__conf.get(name)
-config = _Config()
+config = Config()
--- /dev/null
+from .. import config
+
+
+class TestConfig(object):
+ def setup(self):
+ pass
+
+ def teardown(self):
+ pass
+
+ def test_get_and_set(self):
+ conf_obj = config.Config()
+ conf_obj.teuthology_yaml = ''
+ conf_obj.load_files()
+ assert conf_obj.ceph_git_base_url == "https://github.com/ceph/"
+ conf_obj._Config__conf['ceph_git_base_url'] = "git://ceph.com/"
+ assert conf_obj.ceph_git_base_url == "git://ceph.com/"