]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
CephLab: playbook failures result in status 'dead' 921/head
authorZack Cerza <zack@redhat.com>
Mon, 1 Aug 2016 21:47:49 +0000 (15:47 -0600)
committerZack Cerza <zack@redhat.com>
Mon, 1 Aug 2016 22:31:30 +0000 (16:31 -0600)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/task/ansible.py
teuthology/test/task/test_ansible.py
teuthology/test/task/test_ceph_ansible.py

index d873a39590d1902356cbb56e903617a485455747..560d8cb26374ad818b76e98b7f6846ad07ce57a2 100644 (file)
@@ -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
index 117ea4abfac4fd368a26e5afa2e381da633fc850..735f0f93939cfe2ae2dcdb30e3e095ec8cc29411 100644 (file)
@@ -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'
index 669ab1ebcb66ce7dc22af158b7806cfb2012acc0..fa1e09faffa3218161eee2a61821013fec23f166 100644 (file)
@@ -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()