mirror of
https://github.com/ansible/awx.git
synced 2026-05-15 05:17:36 -02:30
Merge pull request #6147 from ryanpetrello/job-host-summary-notification
properly support job host summary data in custom notification templates (and remove a few fields that don't work) Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -270,21 +270,19 @@ class JobNotificationMixin(object):
|
|||||||
'elapsed', 'job_explanation', 'execution_node', 'controller_node', 'allow_simultaneous',
|
'elapsed', 'job_explanation', 'execution_node', 'controller_node', 'allow_simultaneous',
|
||||||
'scm_revision', 'diff_mode', 'job_slice_number', 'job_slice_count', 'custom_virtualenv',
|
'scm_revision', 'diff_mode', 'job_slice_number', 'job_slice_count', 'custom_virtualenv',
|
||||||
'approval_status', 'approval_node_name', 'workflow_url',
|
'approval_status', 'approval_node_name', 'workflow_url',
|
||||||
{'host_status_counts': ['skipped', 'ok', 'changed', 'failures', 'dark']},
|
{'host_status_counts': ['skipped', 'ok', 'changed', 'failed', 'failures', 'dark'
|
||||||
{'playbook_counts': ['play_count', 'task_count']},
|
'processed', 'rescued', 'ignored']},
|
||||||
{'summary_fields': [{'inventory': ['id', 'name', 'description', 'has_active_failures',
|
{'summary_fields': [{'inventory': ['id', 'name', 'description', 'has_active_failures',
|
||||||
'total_hosts', 'hosts_with_active_failures', 'total_groups',
|
'total_hosts', 'hosts_with_active_failures', 'total_groups',
|
||||||
'has_inventory_sources',
|
'has_inventory_sources',
|
||||||
'total_inventory_sources', 'inventory_sources_with_failures',
|
'total_inventory_sources', 'inventory_sources_with_failures',
|
||||||
'organization_id', 'kind']},
|
'organization_id', 'kind']},
|
||||||
{'project': ['id', 'name', 'description', 'status', 'scm_type']},
|
{'project': ['id', 'name', 'description', 'status', 'scm_type']},
|
||||||
{'project_update': ['id', 'name', 'description', 'status', 'failed']},
|
|
||||||
{'job_template': ['id', 'name', 'description']},
|
{'job_template': ['id', 'name', 'description']},
|
||||||
{'unified_job_template': ['id', 'name', 'description', 'unified_job_type']},
|
{'unified_job_template': ['id', 'name', 'description', 'unified_job_type']},
|
||||||
{'instance_group': ['name', 'id']},
|
{'instance_group': ['name', 'id']},
|
||||||
{'created_by': ['id', 'username', 'first_name', 'last_name']},
|
{'created_by': ['id', 'username', 'first_name', 'last_name']},
|
||||||
{'labels': ['count', 'results']},
|
{'labels': ['count', 'results']}]}]
|
||||||
{'source_workflow_job': ['description', 'elapsed', 'failed', 'id', 'name', 'status']}]}]
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def context_stub(cls):
|
def context_stub(cls):
|
||||||
@@ -303,7 +301,7 @@ class JobNotificationMixin(object):
|
|||||||
'finished': False,
|
'finished': False,
|
||||||
'force_handlers': False,
|
'force_handlers': False,
|
||||||
'forks': 0,
|
'forks': 0,
|
||||||
'host_status_counts': {'skipped': 1, 'ok': 5, 'changed': 3, 'failures': 0, 'dark': 0},
|
'host_status_counts': {'skipped': 1, 'ok': 5, 'changed': 3, 'failures': 0, 'dark': 0, 'failed': False, 'processed': 0, 'rescued': 0},
|
||||||
'id': 42,
|
'id': 42,
|
||||||
'job_explanation': 'Sample job explanation',
|
'job_explanation': 'Sample job explanation',
|
||||||
'job_slice_count': 1,
|
'job_slice_count': 1,
|
||||||
@@ -314,7 +312,6 @@ class JobNotificationMixin(object):
|
|||||||
'limit': 'bar_limit',
|
'limit': 'bar_limit',
|
||||||
'modified': datetime.datetime(2018, 12, 13, 6, 4, 0, 0, tzinfo=datetime.timezone.utc),
|
'modified': datetime.datetime(2018, 12, 13, 6, 4, 0, 0, tzinfo=datetime.timezone.utc),
|
||||||
'name': 'Stub JobTemplate',
|
'name': 'Stub JobTemplate',
|
||||||
'playbook_counts': {'play_count': 5, 'task_count': 10},
|
|
||||||
'playbook': 'ping.yml',
|
'playbook': 'ping.yml',
|
||||||
'scm_revision': '',
|
'scm_revision': '',
|
||||||
'skip_tags': '',
|
'skip_tags': '',
|
||||||
@@ -347,18 +344,10 @@ class JobNotificationMixin(object):
|
|||||||
'name': 'Stub project',
|
'name': 'Stub project',
|
||||||
'scm_type': 'git',
|
'scm_type': 'git',
|
||||||
'status': 'successful'},
|
'status': 'successful'},
|
||||||
'project_update': {'id': 5, 'name': 'Stub Project Update', 'description': 'Project Update',
|
|
||||||
'status': 'running', 'failed': False},
|
|
||||||
'unified_job_template': {'description': 'Sample unified job template description',
|
'unified_job_template': {'description': 'Sample unified job template description',
|
||||||
'id': 39,
|
'id': 39,
|
||||||
'name': 'Stub Job Template',
|
'name': 'Stub Job Template',
|
||||||
'unified_job_type': 'job'},
|
'unified_job_type': 'job'}},
|
||||||
'source_workflow_job': {'description': 'Sample workflow job description',
|
|
||||||
'elapsed': 0.000,
|
|
||||||
'failed': False,
|
|
||||||
'id': 88,
|
|
||||||
'name': 'Stub WorkflowJobTemplate',
|
|
||||||
'status': 'running'}},
|
|
||||||
'timeout': 0,
|
'timeout': 0,
|
||||||
'type': 'job',
|
'type': 'job',
|
||||||
'url': '/api/v2/jobs/13/',
|
'url': '/api/v2/jobs/13/',
|
||||||
@@ -392,10 +381,20 @@ class JobNotificationMixin(object):
|
|||||||
The context will contain whitelisted content retrieved from a serialized job object
|
The context will contain whitelisted content retrieved from a serialized job object
|
||||||
(see JobNotificationMixin.JOB_FIELDS_WHITELIST), the job's friendly name,
|
(see JobNotificationMixin.JOB_FIELDS_WHITELIST), the job's friendly name,
|
||||||
and a url to the job run."""
|
and a url to the job run."""
|
||||||
context = {'job': {},
|
job_context = {'host_status_counts': {}}
|
||||||
'job_friendly_name': self.get_notification_friendly_name(),
|
summary = None
|
||||||
'url': self.get_ui_url(),
|
if hasattr(self, 'job_host_summaries'):
|
||||||
'job_metadata': json.dumps(self.notification_data(), indent=4)}
|
summary = self.job_host_summaries.first()
|
||||||
|
if summary:
|
||||||
|
from awx.api.serializers import JobHostSummarySerializer
|
||||||
|
summary_data = JobHostSummarySerializer(summary).to_representation(summary)
|
||||||
|
job_context['host_status_counts'] = summary_data
|
||||||
|
context = {
|
||||||
|
'job': job_context,
|
||||||
|
'job_friendly_name': self.get_notification_friendly_name(),
|
||||||
|
'url': self.get_ui_url(),
|
||||||
|
'job_metadata': json.dumps(self.notification_data(), indent=4)
|
||||||
|
}
|
||||||
|
|
||||||
def build_context(node, fields, whitelisted_fields):
|
def build_context(node, fields, whitelisted_fields):
|
||||||
for safe_field in whitelisted_fields:
|
for safe_field in whitelisted_fields:
|
||||||
|
|||||||
@@ -23,8 +23,11 @@ class TestJobNotificationMixin(object):
|
|||||||
'finished': bool,
|
'finished': bool,
|
||||||
'force_handlers': bool,
|
'force_handlers': bool,
|
||||||
'forks': int,
|
'forks': int,
|
||||||
'host_status_counts': {'skipped': int, 'ok': int, 'changed': int,
|
'host_status_counts': {
|
||||||
'failures': int, 'dark': int},
|
'skipped': int, 'ok': int, 'changed': int,
|
||||||
|
'failures': int, 'dark': int, 'processed': int,
|
||||||
|
'rescued': int, 'failed': bool
|
||||||
|
},
|
||||||
'id': int,
|
'id': int,
|
||||||
'job_explanation': str,
|
'job_explanation': str,
|
||||||
'job_slice_count': int,
|
'job_slice_count': int,
|
||||||
@@ -36,7 +39,6 @@ class TestJobNotificationMixin(object):
|
|||||||
'modified': datetime.datetime,
|
'modified': datetime.datetime,
|
||||||
'name': str,
|
'name': str,
|
||||||
'playbook': str,
|
'playbook': str,
|
||||||
'playbook_counts': {'play_count': int, 'task_count': int},
|
|
||||||
'scm_revision': str,
|
'scm_revision': str,
|
||||||
'skip_tags': str,
|
'skip_tags': str,
|
||||||
'start_at_task': str,
|
'start_at_task': str,
|
||||||
@@ -68,17 +70,10 @@ class TestJobNotificationMixin(object):
|
|||||||
'name': str,
|
'name': str,
|
||||||
'scm_type': str,
|
'scm_type': str,
|
||||||
'status': str},
|
'status': str},
|
||||||
'project_update': {'id': int, 'name': str, 'description': str, 'status': str, 'failed': bool},
|
|
||||||
'unified_job_template': {'description': str,
|
'unified_job_template': {'description': str,
|
||||||
'id': int,
|
'id': int,
|
||||||
'name': str,
|
'name': str,
|
||||||
'unified_job_type': str},
|
'unified_job_type': str}},
|
||||||
'source_workflow_job': {'description': str,
|
|
||||||
'elapsed': float,
|
|
||||||
'failed': bool,
|
|
||||||
'id': int,
|
|
||||||
'name': str,
|
|
||||||
'status': str}},
|
|
||||||
|
|
||||||
'timeout': int,
|
'timeout': int,
|
||||||
'type': str,
|
'type': str,
|
||||||
|
|||||||
Reference in New Issue
Block a user