]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Fix ansible overrides 559/head
authorZack Cerza <zack@redhat.com>
Thu, 2 Jul 2015 23:07:39 +0000 (17:07 -0600)
committerZack Cerza <zack@redhat.com>
Mon, 6 Jul 2015 16:59:56 +0000 (10:59 -0600)
Overrides weren't properly being looked up by name. This commit fixes
that.

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/task/__init__.py
teuthology/task/ansible.py
teuthology/test/task/__init__.py
teuthology/test/task/test_ansible.py

index 32aed56aeb86e9d27bde87154c52ce38b1d82853..31b19acfe41b4e1b37e51ab8983f464c6cd812be 100644 (file)
@@ -12,10 +12,22 @@ class Task(object):
 
     Can be used as a drop-in replacement for the old-style task functions with
     @contextmanager decorators.
+
+    Note: While looking up overrides, we use the lowercase name of the class by
+          default. While this works well for the main task in a module, other
+          tasks or 'subtasks' may want to override that name using a class
+          variable called 'name' e.g.:
+
+              class MyTask(Task):
+                  pass
+              class MySubtask(MyTask):
+                  name = 'mytask.mysubtask'
     """
+
     def __init__(self, ctx=None, config=None):
+        if not hasattr(self, 'name'):
+            self.name = self.__class__.__name__.lower()
         self.log = log
-        self.name = self.__class__.__name__.lower()
         self.ctx = ctx
         self.config = config or dict()
         if not isinstance(self.config, dict):
index f3b73288493bd5bd4745dbc812e3d776708f114e..d20a44472c02fb01831ac5d0d20f3883799b6434 100644 (file)
@@ -94,6 +94,7 @@ class Ansible(Task):
                 key: value
 
     """
+
     def __init__(self, ctx, config):
         super(Ansible, self).__init__(ctx, config)
         self.log = log
@@ -289,6 +290,10 @@ class CephLab(Ansible):
         playbook: cephlab.yml
     """.format(git_base=teuth_config.ceph_git_base_url)
 
+    # Set the name so that Task knows to look up overrides for
+    # 'ansible.cephlab' instead of just 'cephlab'
+    name = 'ansible.cephlab'
+
     def __init__(self, ctx, config):
         config = config or dict()
         if 'playbook' not in config:
index 319342823d07888e1cce2efbd917d08d24967f57..687744667a0f15a6f3ff685de4414af75c78e873 100644 (file)
@@ -8,15 +8,17 @@ from teuthology.task import Task
 
 
 class TestTask(object):
+    klass = Task
+    task_name = 'task'
+
     def setup(self):
-        self.klass = Task
         self.ctx = FakeNamespace()
         self.ctx.config = dict()
         self.task_config = dict()
 
     def test_overrides(self):
         self.ctx.config['overrides'] = dict()
-        self.ctx.config['overrides'][self.klass.name] = dict(
+        self.ctx.config['overrides'][self.task_name] = dict(
             key_1='overridden',
         )
         self.task_config.update(dict(
index 55c3722777b9aefa3f89c879bc23021a0e9031bb..a0be36bb881fdb582f0ef4c561b4765def8c995f 100644 (file)
@@ -17,8 +17,10 @@ from . import TestTask
 
 
 class TestAnsibleTask(TestTask):
+    klass = Ansible
+    task_name = 'ansible'
+
     def setup(self):
-        self.klass = Ansible
         self.ctx = FakeNamespace()
         self.ctx.cluster = Cluster()
         self.ctx.cluster.add(Remote('user@remote1'), ['role1'])
@@ -387,6 +389,7 @@ class TestAnsibleTask(TestTask):
 
 class TestCephLabTask(TestTask):
     klass = CephLab
+    task_name = 'ansible.cephlab'
 
     def setup(self):
         self.ctx = FakeNamespace()