From: Zack Cerza Date: Fri, 11 Jul 2014 16:41:16 +0000 (-0600) Subject: Discourage modifying defaults in instances X-Git-Tag: 1.1.0~1334^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9547a7f398765e028ce7db9ca12389a6478a2ccc;p=teuthology.git Discourage modifying defaults in instances Signed-off-by: Zack Cerza --- diff --git a/teuthology/config.py b/teuthology/config.py index 713b34e0f..63838e46b 100644 --- a/teuthology/config.py +++ b/teuthology/config.py @@ -11,7 +11,15 @@ log = init_logging() 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 @@ -78,7 +86,7 @@ class YamlConfig(object): 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'): @@ -97,7 +105,7 @@ class TeuthologyConfig(YamlConfig): ~/.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/', diff --git a/teuthology/test/test_config.py b/teuthology/test/test_config.py index ac5d9e495..3e57346bd 100644 --- a/teuthology/test/test_config.py +++ b/teuthology/test/test_config.py @@ -52,11 +52,6 @@ class TestTeuthologyConfig(TestYamlConfig): 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 = ''