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
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
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
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