From ef3d23cc6645f49e1eb6ccc492b053064fc0743d Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Mon, 1 Aug 2016 15:47:49 -0600 Subject: [PATCH] CephLab: playbook failures result in status 'dead' Signed-off-by: Zack Cerza --- teuthology/task/ansible.py | 11 +++++++++++ teuthology/test/task/test_ansible.py | 20 ++++++++++++++++++++ teuthology/test/task/test_ceph_ansible.py | 1 + 3 files changed, 32 insertions(+) diff --git a/teuthology/task/ansible.py b/teuthology/task/ansible.py index d873a3959..560d8cb26 100644 --- a/teuthology/task/ansible.py +++ b/teuthology/task/ansible.py @@ -11,6 +11,7 @@ from tempfile import NamedTemporaryFile from teuthology.config import config as teuth_config from teuthology.exceptions import CommandFailedError, AnsibleFailedError +from teuthology.job_status import set_status from teuthology.repo_utils import fetch_repo from . import Task @@ -269,6 +270,7 @@ class Ansible(Task): remote.reconnect() def _handle_failure(self, command, status): + self._set_status('dead') failures = None with open(self.failure_log.name, 'r') as fail_log: try: @@ -286,6 +288,12 @@ class Ansible(Task): raise AnsibleFailedError(failures) raise CommandFailedError(command, status) + def _set_status(self, status): + """ + Not implemented in the base class + """ + pass + def _archive_failures(self): if self.ctx.archive: archive_path = "{0}/ansible_failures.yaml".format(self.ctx.archive) @@ -381,6 +389,9 @@ class CephLab(Ansible): pass super(CephLab, self).begin() + def _set_status(self, status): + set_status(self.ctx.summary, status) + task = Ansible cephlab = CephLab diff --git a/teuthology/test/task/test_ansible.py b/teuthology/test/task/test_ansible.py index 117ea4abf..735f0f939 100644 --- a/teuthology/test/task/test_ansible.py +++ b/teuthology/test/task/test_ansible.py @@ -26,6 +26,7 @@ class TestAnsibleTask(TestTask): self.ctx.cluster.add(Remote('user@remote1'), ['role1']) self.ctx.cluster.add(Remote('user@remote2'), ['role2']) self.ctx.config = dict() + self.ctx.summary = dict() self.task_config = dict(playbook=[]) self.start_patchers() @@ -306,6 +307,7 @@ class TestAnsibleTask(TestTask): m_run.return_value = ('', 1) with raises(CommandFailedError): task.execute_playbook() + assert task.ctx.summary.get('status') is None def test_build_args_no_tags(self): self.task_config.update(dict( @@ -491,3 +493,21 @@ class TestCephLabTask(TestTask): 'remote1\n', 'remote2\n', ] + + def test_fail_status_dead(self): + self.task_config.update(dict( + playbook=[], + )) + task = self.klass(self.ctx, self.task_config) + task.ctx.summary = dict() + task.setup() + with patch.object(ansible.pexpect, 'run') as m_run: + with patch('teuthology.task.ansible.open') as m_open: + fake_failure_log = Mock() + fake_failure_log.__enter__ = Mock() + fake_failure_log.__exit__ = Mock() + m_open.return_value = fake_failure_log + m_run.return_value = ('', 1) + with raises(CommandFailedError): + task.execute_playbook() + assert task.ctx.summary.get('status') == 'dead' diff --git a/teuthology/test/task/test_ceph_ansible.py b/teuthology/test/task/test_ceph_ansible.py index 669ab1ebc..fa1e09faf 100644 --- a/teuthology/test/task/test_ceph_ansible.py +++ b/teuthology/test/task/test_ceph_ansible.py @@ -23,6 +23,7 @@ class TestCephAnsibleTask(TestAnsibleTask): self.ctx.cluster.add(Remote('user@remote1'), ['mon.0']) self.ctx.cluster.add(Remote('user@remote2'), ['mds.0']) self.ctx.cluster.add(Remote('user@remote3'), ['osd.0']) + self.ctx.summary = dict() self.ctx.config = dict() self.task_config = dict() self.start_patchers() -- 2.47.3