From e06bf9f87efa8ad105bface2f0921e60258b646e Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 14 Oct 2019 10:11:58 -0400 Subject: [PATCH] Change host counting for task impact Go through the job -> inventory module linkage to calculate the hosts for a more accurate view of the number of hosts that could be impacted. This also creates a bailout that will set count hosts to the forks rather than assuming some crazy low number in the case where we can't determine the actual number of hosts because we are missing the inventory --- awx/main/models/jobs.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 65be4db925..d573d1ed96 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -629,15 +629,17 @@ class Job(UnifiedJob, JobOptions, SurveyJobMixin, JobNotificationMixin, TaskMana @property def task_impact(self): - # NOTE: We sorta have to assume the host count matches and that forks default to 5 - from awx.main.models.inventory import Host if self.launch_type == 'callback': count_hosts = 2 else: - count_hosts = Host.objects.filter(inventory__jobs__pk=self.pk).count() - if self.job_slice_count > 1: - # Integer division intentional - count_hosts = (count_hosts + self.job_slice_count - self.job_slice_number) // self.job_slice_count + # If for some reason we can't count the hosts then lets assume the impact as forks + if self.inventory is not None: + count_hosts = self.inventory.hosts.count() + if self.job_slice_count > 1: + # Integer division intentional + count_hosts = (count_hosts + self.job_slice_count - self.job_slice_number) // self.job_slice_count + else: + count_hosts = 5 if self.forks == 0 else self.forks return min(count_hosts, 5 if self.forks == 0 else self.forks) + 1 @property