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):
key: value
"""
+
def __init__(self, ctx, config):
super(Ansible, self).__init__(ctx, config)
self.log = log
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:
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(
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'])
class TestCephLabTask(TestTask):
klass = CephLab
+ task_name = 'ansible.cephlab'
def setup(self):
self.ctx = FakeNamespace()