Merge pull request #9251 from Saurabh-Thakre/Saurabh-Thakre-patch-1

Fixed the Customized Notification returning incorrect values for host_status_counts

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-02-19 16:07:30 +00:00 committed by GitHub
commit 182a7e8e5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -388,12 +388,17 @@ class JobNotificationMixin(object):
and a url to the job run."""
job_context = {'host_status_counts': {}}
summary = None
if hasattr(self, 'job_host_summaries'):
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
try:
has_event_property = any([f for f in self.event_class._meta.fields if f.name == 'event'])
except NotImplementedError:
has_event_property = False
if has_event_property:
qs = self.get_event_queryset()
if qs:
event = qs.only('event_data').filter(event='playbook_on_stats').first()
if event:
summary = event.get_host_status_counts()
job_context['host_status_counts'] = summary
context = {
'job': job_context,
'job_friendly_name': self.get_notification_friendly_name(),