]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Add CephLab subclass
authorZack Cerza <zack@redhat.com>
Fri, 22 May 2015 00:25:12 +0000 (18:25 -0600)
committerZack Cerza <zack@redhat.com>
Mon, 1 Jun 2015 16:21:08 +0000 (10:21 -0600)
It simply defaults to pointing at our ceph-cm-ansible repo and our
cephlab.yml playbook

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

index 8d6684e77bf7bd67d1a1bc54d270a62d9013f6fd..70138f965ed7c1bcdf949665f351312e07399840 100644 (file)
@@ -7,6 +7,7 @@ import yaml
 from cStringIO import StringIO
 from tempfile import NamedTemporaryFile
 
+from teuthology.config import config as teuth_config
 from teuthology.exceptions import CommandFailedError
 from teuthology.repo_utils import fetch_repo
 
@@ -242,4 +243,24 @@ class Ansible(Task):
         super(Ansible, self).teardown()
 
 
+class CephLab(Ansible):
+    __doc__ = """
+    A very simple subclass of Ansible that defaults to:
+
+    - ansible:
+        repo: {git_base}ceph-cm-ansible.git
+        playbook: cephlab.yml
+    """.format(git_base=teuth_config.ceph_git_base_url)
+
+    def __init__(self, ctx, config):
+        config = config or dict()
+        if 'playbook' not in config:
+            config['playbook'] = 'cephlab.yml'
+        if 'repo' not in config:
+            config['repo'] = os.path.join(teuth_config.ceph_git_base_url,
+                                          'ceph-cm-ansible.git')
+        super(CephLab, self).__init__(ctx, config)
+
+
 task = Ansible
+cephlab = CephLab
index f9fc9d1281c97574c609ca033b1fa7f1414253c8..1fa608ffde73eb7e0301f05a986b406cf8721224 100644 (file)
@@ -5,12 +5,12 @@ from mock import patch, DEFAULT, Mock
 from pytest import raises
 from StringIO import StringIO
 
-from teuthology.config import FakeNamespace
+from teuthology.config import config, FakeNamespace
 from teuthology.exceptions import CommandFailedError
 from teuthology.orchestra.cluster import Cluster
 from teuthology.orchestra.remote import Remote
 from teuthology.task import ansible
-from teuthology.task.ansible import Ansible
+from teuthology.task.ansible import Ansible, CephLab
 
 from . import TestTask
 
@@ -308,3 +308,32 @@ class TestAnsibleTask(TestTask):
         with patch.object(ansible.os, 'remove') as m_remove:
             task.teardown()
             assert m_remove.called_once_with('fake')
+
+
+class TestCephLabTask(TestTask):
+    def setup(self):
+        self.ctx = FakeNamespace()
+        self.ctx.cluster = Cluster()
+        self.ctx.cluster.add(Remote('remote1'), ['role1'])
+        self.ctx.cluster.add(Remote('remote2'), ['role2'])
+        self.ctx.config = dict()
+
+    @patch('teuthology.task.ansible.fetch_repo')
+    def test_find_repo_http(self, m_fetch_repo):
+        repo = os.path.join(config.ceph_git_base_url,
+                            'ceph-cm-ansible.git')
+        task = CephLab(self.ctx, dict())
+        task.find_repo()
+        m_fetch_repo.assert_called_once_with(repo, 'master')
+
+    def test_playbook_file(self):
+        fake_playbook = [dict(fake_playbook=True)]
+        fake_playbook_obj = StringIO(yaml.safe_dump(fake_playbook))
+        playbook = 'cephlab.yml'
+        fake_playbook_obj.name = playbook
+        task = CephLab(self.ctx, dict())
+        task.repo_path = '/tmp/fake/repo'
+        with patch('teuthology.task.ansible.file', create=True) as m_file:
+            m_file.return_value = fake_playbook_obj
+            task.get_playbook()
+        assert task.playbook_file.name == playbook