diff --git a/awx/main/models/events.py b/awx/main/models/events.py index fb19de554b..fcbb81409a 100644 --- a/awx/main/models/events.py +++ b/awx/main/models/events.py @@ -565,7 +565,6 @@ class JobEvent(BasePlaybookEvent): summaries = dict() updated_hosts_list = list() for host in hostnames: - updated_hosts_list.append(host.lower()) host_id = host_map.get(host) if host_id not in existing_host_ids: host_id = None @@ -582,6 +581,12 @@ class JobEvent(BasePlaybookEvent): summary.failed = bool(summary.dark or summary.failures) summaries[(host_id, host)] = summary + # do not count dark / unreachable hosts as updated + if not bool(summary.dark): + updated_hosts_list.append(host.lower()) + else: + logger.warning(f'host {host.lower()} is dark / unreachable, not marking it as updated') + JobHostSummary.objects.bulk_create(summaries.values()) # update the last_job_id and last_job_host_summary_id diff --git a/awx/main/tests/functional/models/test_events.py b/awx/main/tests/functional/models/test_events.py index 48adc781e7..9b70b7fd13 100644 --- a/awx/main/tests/functional/models/test_events.py +++ b/awx/main/tests/functional/models/test_events.py @@ -165,7 +165,9 @@ class TestEvents: skipped=dict((hostname, len(hostname)) for hostname in self.hostnames[10:12]), ) assert len(HostMetric.objects.filter(Q(deleted=False) & Q(deleted_counter=0) & Q(last_deleted__isnull=True))) == 6 - assert len(HostMetric.objects.filter(Q(deleted=False) & Q(deleted_counter=1) & Q(last_deleted__isnull=False))) == 6 + + # one of those 6 hosts is dark, so will not be counted + assert len(HostMetric.objects.filter(Q(deleted=False) & Q(deleted_counter=1) & Q(last_deleted__isnull=False))) == 5 def _generate_hosts(self, cnt, id_from=0): self.hostnames = [f'Host {i}' for i in range(id_from, id_from + cnt)]