]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Drop misc.read_config()
authorZack Cerza <zack@redhat.com>
Tue, 1 Dec 2015 21:29:14 +0000 (14:29 -0700)
committerZack Cerza <zack@redhat.com>
Wed, 2 Dec 2015 17:17:10 +0000 (10:17 -0700)
Replace with config.set_config_attr(). This is mainly for
backward-compatibility in tasks contained in ceph-qa-suite.

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/config.py
teuthology/lock.py
teuthology/misc.py
teuthology/openstack/__init__.py
teuthology/openstack/test/openstack-integration.py
teuthology/openstack/test/test_openstack.py
teuthology/test/test_config.py
teuthology/worker.py

index a9365a60997fa22f48c0bb981947b3489dc38abb..8f3e2ea00cc167e0140b003c50501cb88d178b60 100644 (file)
@@ -178,29 +178,23 @@ class TeuthologyConfig(YamlConfig):
         return (self.ceph_git_url or
                 self.ceph_git_base_url + 'ceph.git')
 
+
 class JobConfig(YamlConfig):
     pass
 
 
 class FakeNamespace(YamlConfig):
     """
-    This class is meant to behave like a argparse Namespace. It mimics the old
-    way of doing things with argparse and teuthology.misc.read_config.
+    This class is meant to behave like a argparse Namespace
 
     We'll use this as a stop-gap as we refactor commands but allow the tasks
     to still be passed a single namespace object for the time being.
     """
-    def __init__(self, config_dict=None, yaml_path=None):
-        if not yaml_path:
-            yaml_path = _get_config_path()
+    def __init__(self, config_dict=None):
         if not config_dict:
             config_dict = dict()
         self._conf = self._clean_config(config_dict)
-        # avoiding circular imports
-        from .misc import read_config
-        # teuthology.misc.read_config attaches the teuthology config
-        # to a teuthology_config key.
-        read_config(self)
+        set_config_attr(self)
 
     def _clean_config(self, config_dict):
         """
@@ -234,6 +228,12 @@ class FakeNamespace(YamlConfig):
             return self._defaults[name]
         raise AttributeError(name)
 
+    def __setattr__(self, name, value):
+        if name == 'teuthology_config':
+            object.__setattr__(self, name, value)
+        else:
+            super(FakeNamespace, self).__setattr__(name, value)
+
     def __repr__(self):
         return repr(self._conf)
 
@@ -241,6 +241,13 @@ class FakeNamespace(YamlConfig):
         return str(self._conf)
 
 
+def set_config_attr(obj):
+    """
+    Set obj.teuthology_config, mimicking the old behavior of misc.read_config
+    """
+    obj.teuthology_config = config
+
+
 def _get_config_path():
     system_config_path = '/etc/teuthology.yaml'
     if not os.path.exists(TeuthologyConfig.yaml_path) and \
index 7eddd2cd3fb2c84d3740add8cb1f8d6df05c2f98..081a6bd48461e43a1881ddc74c6ec2e98a47a2c4 100644 (file)
@@ -14,6 +14,7 @@ import teuthology
 from . import misc
 from . import provision
 from .config import config
+from .config import set_config_attr
 from .contextutil import safe_while
 from .lockstatus import get_status
 
@@ -184,7 +185,7 @@ def main(ctx):
     if ctx.verbose:
         teuthology.log.setLevel(logging.DEBUG)
 
-    misc.read_config(ctx)
+    set_config_attr(ctx)
 
     ret = 0
     user = ctx.owner
index f4043c7680db47a80a119fb64c40d1fa9bacde29..9ea7a421cb2a12b32d9710b7ab83d6bb6998ac40 100644 (file)
@@ -1000,23 +1000,6 @@ def get_user():
     return getpass.getuser() + '@' + socket.gethostname()
 
 
-def read_config(ctx):
-    """
-    read the default teuthology yaml configuration file.
-    """
-    ctx.teuthology_config = {}
-    filename = os.path.join(os.environ['HOME'], '.teuthology.yaml')
-
-    if not os.path.exists(filename):
-        log.debug("%s not found", filename)
-        return
-
-    with file(filename) as f:
-        g = yaml.safe_load_all(f)
-        for new in g:
-            ctx.teuthology_config.update(new)
-
-
 def get_mon_names(ctx):
     """
     :returns: a list of monitor names
index 729862857dac229b687ad5cb78fedb45c7c32ca5..974bb6ae0f37a07f2589b35be51c7ef24d8d7a35 100644 (file)
@@ -38,6 +38,7 @@ from subprocess import CalledProcessError
 
 from teuthology.contextutil import safe_while
 from teuthology.config import config as teuth_config
+from teuthology.config import set_config_attr
 from teuthology.orchestra import connection
 from teuthology import misc
 
@@ -421,7 +422,7 @@ class TeuthologyOpenStack(OpenStack):
         Entry point implementing the teuthology-openstack command.
         """
         self.setup_logs()
-        misc.read_config(self.args)
+        set_config_attr(self.args)
         self.key_filename = self.args.key_filename
         self.verify_openstack()
         ip = self.setup()
index 8fe04129591dad3dfc480836fc4aa4c1816f20b8..64ec9feb010d2bb00c678be85f830ea0866dadf1 100644 (file)
@@ -39,13 +39,15 @@ import scripts.schedule
 import scripts.lock
 import scripts.suite
 from teuthology.config import config as teuth_config
+from teuthology.config import set_config_attr
+
 
 class Integration(object):
 
     @classmethod
     def setup_class(self):
         teuthology.log.setLevel(logging.DEBUG)
-        teuthology.misc.read_config(argparse.Namespace())
+        set_config_attr(argparse.Namespace())
         self.teardown_class()
 
     @classmethod
index 32fecb5b7265a2895249921a0312e2e7dba5dec9..c46287be3f9339962efd7907347fd4833015d4ea 100644 (file)
@@ -31,6 +31,7 @@ from mock import patch
 
 import teuthology
 from teuthology import misc
+from teuthology.config import set_config_attr
 from teuthology.openstack import TeuthologyOpenStack, OpenStack, OpenStackInstance
 import scripts.openstack
 
@@ -214,7 +215,7 @@ class TestTeuthologyOpenStack(object):
             pytest.skip('no OS_AUTH_URL environment variable')
 
         teuthology.log.setLevel(logging.DEBUG)
-        teuthology.misc.read_config(argparse.Namespace())
+        set_config_attr(argparse.Namespace())
 
         ip = TeuthologyOpenStack.create_floating_ip()
         if ip:
@@ -223,7 +224,7 @@ class TestTeuthologyOpenStack(object):
             self.can_create_floating_ips = True
         else:
             self.can_create_floating_ips = False
-        
+
     def setup(self):
         self.key_filename = tempfile.mktemp()
         self.key_name = 'teuthology-test'
index fee44bf1f27bcd08dddf64c6b6422704024551f8..30c32491906bc31f249e38d66f073728d324b4d6 100644 (file)
@@ -133,14 +133,12 @@ class TestFakeNamespace(TestYamlConfig):
     def test_config(self):
         """
         Tests that a teuthology_config property is automatically added
-        by misc.read_config.
+        to the conf_obj
         """
         conf_obj = self.test_class(dict(foo="bar"))
         assert conf_obj["foo"] == "bar"
         assert conf_obj.foo == "bar"
-        # teuthology_config needs to be a dict because all
-        # of the tasks expect it to be
-        assert isinstance(conf_obj.teuthology_config, dict)
+        assert conf_obj.teuthology_config.get("fake key") is None
 
     def test_getattr(self):
         conf_obj = self.test_class.from_dict({"foo": "bar"})
@@ -165,3 +163,20 @@ class TestFakeNamespace(TestYamlConfig):
         in_str = "foo: bar"
         conf_obj = self.test_class.from_str(in_str)
         assert conf_obj.to_str() == "{'foo': 'bar'}"
+
+    def test_multiple_access(self):
+        """
+        Test that config.config and FakeNamespace.teuthology_config reflect
+        each others' modifications
+        """
+        in_str = "foo: bar"
+        conf_obj = self.test_class.from_str(in_str)
+        assert config.config.get('test_key_1') is None
+        assert conf_obj.teuthology_config.get('test_key_1') is None
+        config.config.test_key_1 = 'test value'
+        assert conf_obj.teuthology_config['test_key_1'] == 'test value'
+
+        assert config.config.get('test_key_2') is None
+        assert conf_obj.teuthology_config.get('test_key_2') is None
+        conf_obj.teuthology_config['test_key_2'] = 'test value'
+        assert config.config['test_key_2'] == 'test value'
index 48befffcd8f5d825e90bb5631a2c0d24ff2b351c..9ea1c77466c92e591bae52bb0509d353060d3692 100644 (file)
@@ -13,9 +13,9 @@ from . import beanstalk
 from . import report
 from . import safepath
 from .config import config as teuth_config
+from .config import set_config_attr
 from .exceptions import BranchNotFoundError
 from .kill import kill_job
-from .misc import read_config
 from .repo_utils import fetch_qa_suite, fetch_teuthology
 
 log = logging.getLogger(__name__)
@@ -73,7 +73,7 @@ def main(ctx):
     else:
         teuth_config.archive_base = ctx.archive_dir
 
-    read_config(ctx)
+    set_config_attr(ctx)
 
     connection = beanstalk.connect()
     beanstalk.watch_tube(connection, ctx.tube)