summaryrefslogtreecommitdiffstats
path: root/awxkit/awxkit/api/pages/workflow_jobs.py
blob: f444ea4a834d7461c63461c6139242083863cfa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from awxkit.api.pages import UnifiedJob
from awxkit.api.resources import resources
from . import page


class WorkflowJob(UnifiedJob):
    def __str__(self):
        # TODO: Update after endpoint's fields are finished filling out
        return super(UnifiedJob, self).__str__()

    def relaunch(self, payload={}):
        result = self.related.relaunch.post(payload)
        return self.walk(result.url)

    def failure_output_details(self):
        """Special implementation of this part of assert_status so that
        workflow_job.assert_successful() will give a breakdown of failure
        """
        node_list = self.related.workflow_nodes.get().results

        msg = '\nNode summary:'
        for node in node_list:
            msg += '\n{}: {}'.format(node.id, node.summary_fields.get('job'))
            for rel in ('failure_nodes', 'always_nodes', 'success_nodes'):
                val = getattr(node, rel, [])
                if val:
                    msg += ' {} {}'.format(rel, val)

        msg += '\n\nUnhandled individual job failures:\n'
        for node in node_list:
            # nodes without always or failure paths consider failures unhandled
            if node.job and not (node.failure_nodes or node.always_nodes):
                job = node.related.job.get()
                try:
                    job.assert_successful()
                except Exception as e:
                    msg += str(e)

        return msg

    @property
    def result_stdout(self):
        # workflow jobs do not have result_stdout
        if 'result_stdout' not in self.json:
            return 'Unprovided AWX field.'
        else:
            return super(WorkflowJob, self).result_stdout


page.register_page(resources.workflow_job, WorkflowJob)


class WorkflowJobs(page.PageList, WorkflowJob):
    pass


page.register_page([resources.workflow_jobs, resources.workflow_job_template_jobs, resources.job_template_slice_workflow_jobs], WorkflowJobs)