class YamlConfig(object):
- defaults = dict()
+ """
+ A configuration object populated by parsing a yaml file, with optional
+ default values.
+
+ Note that modifying the _defaults attribute of an instance can potentially
+ yield confusing results; if you need to do modify defaults, use the class
+ variable or create a subclass.
+ """
+ _defaults = dict()
def __init__(self, yaml_path=None):
self.yaml_path = yaml_path
return self._conf.__getitem__(name)
def __getattr__(self, name):
- return self._conf.get(name, self.defaults.get(name))
+ return self._conf.get(name, self._defaults.get(name))
def __setattr__(self, name, value):
if name.endswith('_conf') or name in ('yaml_path'):
~/.teuthology.yaml and nothing else.
"""
yaml_path = os.path.join(os.environ['HOME'], '.teuthology.yaml')
- defaults = {
+ _defaults = {
'archive_base': '/var/lib/teuthworker/archive',
'automated_scheduling': False,
'ceph_git_base_url': 'https://github.com/ceph/',
def setup(self):
self.test_class = config.TeuthologyConfig
- def test_defaults(self):
- conf_obj = self.test_class()
- conf_obj.defaults['archive_base'] = 'bar'
- assert conf_obj.archive_base == 'bar'
-
def test_get_ceph_git_base_default(self):
conf_obj = self.test_class()
conf_obj.yaml_path = ''