From 529b7a111798d1b58f8f9b23e69264b7198f4361 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Thu, 14 May 2015 15:48:09 -0400 Subject: [PATCH] Remove changes to only count unique hostnames. Fixes https://trello.com/c/HN7S4KF3 again. --- awx/api/views.py | 10 ++-------- awx/main/tests/inventory.py | 15 ++++++++------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index 5c177dbebf..2a5cda34b3 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -282,16 +282,10 @@ class DashboardView(APIView): user_hosts = get_user_queryset(request.user, Host) user_hosts_failed = user_hosts.filter(has_active_failures=True) - try: - user_hosts_count = user_hosts.distinct('name').count() - user_hosts_failed_count = user_hosts_failed.distinct('name').count() - except NotImplementedError: # For unit tests only, SQLite doesn't support distinct('name') - user_hosts_count = len(set(user_hosts.values_list('name', flat=True))) - user_hosts_failed_count = len(set(user_hosts_failed.values_list('name', flat=True))) data['hosts'] = {'url': reverse('api:host_list'), 'failures_url': reverse('api:host_list') + "?has_active_failures=True", - 'total': user_hosts_count, - 'failed': user_hosts_failed_count} + 'total': user_hosts.count(), + 'failed': user_hosts_failed.count()} user_projects = get_user_queryset(request.user, Project) user_projects_failed = user_projects.filter(last_job_failed=True) diff --git a/awx/main/tests/inventory.py b/awx/main/tests/inventory.py index 8771501062..71a1b826b7 100644 --- a/awx/main/tests/inventory.py +++ b/awx/main/tests/inventory.py @@ -1098,35 +1098,36 @@ class InventoryTest(BaseTest): self.assertEqual(response['hosts']['total'], 0) self.assertEqual(response['hosts']['failed'], 0) - # Create hosts with the same name in different inventories. + # Create hosts with the same name in different inventories. This host + # count should include total hosts, not unique names. for x in xrange(4): hostname = 'host-%d' % x self.inventory_a.hosts.create(name=hostname) self.inventory_b.hosts.create(name=hostname) with self.current_user(self.super_django_user): response = self.get(url, expect=200) - self.assertEqual(response['hosts']['total'], 4) + self.assertEqual(response['hosts']['total'], 8) self.assertEqual(response['hosts']['failed'], 0) # Mark all hosts in one inventory as failed. Failed count should - # reflect unique hostnames. + # reflect all hosts, not unique hostnames. for host in self.inventory_a.hosts.all(): host.has_active_failures = True host.save() with self.current_user(self.super_django_user): response = self.get(url, expect=200) - self.assertEqual(response['hosts']['total'], 4) + self.assertEqual(response['hosts']['total'], 8) self.assertEqual(response['hosts']['failed'], 4) # Mark all hosts in the other inventory as failed. Failed count - # should reflect unique hostnames and never be greater than total. + # should reflect all hosts and never be greater than total. for host in self.inventory_b.hosts.all(): host.has_active_failures = True host.save() with self.current_user(self.super_django_user): response = self.get(url, expect=200) - self.assertEqual(response['hosts']['total'], 4) - self.assertEqual(response['hosts']['failed'], 4) + self.assertEqual(response['hosts']['total'], 8) + self.assertEqual(response['hosts']['failed'], 8) def test_dashboard_inventory_graph_view(self): url = reverse('api:dashboard_inventory_graph_view')