]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Discourage modifying defaults in instances 289/head
authorZack Cerza <zack@cerza.org>
Fri, 11 Jul 2014 16:41:16 +0000 (10:41 -0600)
committerZack Cerza <zack@cerza.org>
Fri, 11 Jul 2014 16:41:16 +0000 (10:41 -0600)
Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/config.py
teuthology/test/test_config.py

index 713b34e0f5575a24c4d91470569cba5bbe676dac..63838e46b75741f72643e6d819b7af402b4dfb63 100644 (file)
@@ -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/',
index ac5d9e495bda3e7df5f65b4f1bdb48b854a374ec..3e57346bd05ca62ee8bcd5a6a2603cfb2b797314 100644 (file)
@@ -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 = ''