mirror of
https://github.com/ansible/awx.git
synced 2026-01-25 00:11:23 -03:30
[4.6][backport] do not count dark hosts as updated (#6877)
* feat: do not count dark hosts as updated (#15872) * feat: do not count dark hosts as updated * update functional tests * Fix test flake due to host metric id enumeration (#15875) --------- Co-authored-by: Alan Rominger <arominge@redhat.com>
This commit is contained in:
parent
bdfd9dec74
commit
353f0adf36
@ -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
|
||||
|
||||
@ -135,8 +135,9 @@ class TestEvents:
|
||||
|
||||
self._create_job_event(ok=dict((hostname, len(hostname)) for hostname in self.hostnames))
|
||||
|
||||
# Soft delete 6 host metrics
|
||||
for hm in HostMetric.objects.filter(id__in=[1, 3, 5, 7, 9, 11]):
|
||||
# Soft delete 6 of the 12 host metrics, every even host like "Host 2" or "Host 4"
|
||||
for host_name in self.hostnames[::2]:
|
||||
hm = HostMetric.objects.get(hostname=host_name.lower())
|
||||
hm.soft_delete()
|
||||
|
||||
assert len(HostMetric.objects.filter(Q(deleted=False) & Q(deleted_counter=0) & Q(last_deleted__isnull=True))) == 6
|
||||
@ -165,7 +166,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)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user