From: Zack Cerza Date: Thu, 2 Jul 2015 23:07:39 +0000 (-0600) Subject: Fix ansible overrides X-Git-Tag: 1.1.0~886^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4d82f3948dd7f25b6cf2f84e1faefe8fadddbe9a;p=teuthology.git Fix ansible overrides Overrides weren't properly being looked up by name. This commit fixes that. Signed-off-by: Zack Cerza --- diff --git a/teuthology/task/__init__.py b/teuthology/task/__init__.py index 32aed56ae..31b19acfe 100644 --- a/teuthology/task/__init__.py +++ b/teuthology/task/__init__.py @@ -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): diff --git a/teuthology/task/ansible.py b/teuthology/task/ansible.py index f3b732884..d20a44472 100644 --- a/teuthology/task/ansible.py +++ b/teuthology/task/ansible.py @@ -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: diff --git a/teuthology/test/task/__init__.py b/teuthology/test/task/__init__.py index 319342823..687744667 100644 --- a/teuthology/test/task/__init__.py +++ b/teuthology/test/task/__init__.py @@ -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( diff --git a/teuthology/test/task/test_ansible.py b/teuthology/test/task/test_ansible.py index 55c372277..a0be36bb8 100644 --- a/teuthology/test/task/test_ansible.py +++ b/teuthology/test/task/test_ansible.py @@ -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()