From be18542803ff026a4e2d0068113d831e09e8f3a1 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 21 May 2015 18:25:12 -0600 Subject: [PATCH] Add CephLab subclass It simply defaults to pointing at our ceph-cm-ansible repo and our cephlab.yml playbook Signed-off-by: Zack Cerza --- teuthology/task/ansible.py | 21 ++++++++++++++++++ teuthology/test/task/test_ansible.py | 33 ++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/teuthology/task/ansible.py b/teuthology/task/ansible.py index 8d6684e77b..70138f965e 100644 --- a/teuthology/task/ansible.py +++ b/teuthology/task/ansible.py @@ -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 diff --git a/teuthology/test/task/test_ansible.py b/teuthology/test/task/test_ansible.py index f9fc9d1281..1fa608ffde 100644 --- a/teuthology/test/task/test_ansible.py +++ b/teuthology/test/task/test_ansible.py @@ -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 -- 2.39.5