mirror of
https://github.com/ansible/awx.git
synced 2026-06-23 15:47:49 -02:30
fix: constructed inventories no longer increase the host count (#16433)
This commit is contained in:
34
awx/main/tests/functional/api/test_dashboard.py
Normal file
34
awx/main/tests/functional/api/test_dashboard.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import pytest
|
||||
|
||||
from awx.api.versioning import reverse
|
||||
from awx.main.models import Host, Inventory
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_dashboard_hosts_total_excludes_constructed(get, admin_user, organization):
|
||||
"""
|
||||
Constructed inventory hosts are not counted in the dashboard
|
||||
"""
|
||||
source_inv = Inventory.objects.create(name='source-inv', organization=organization)
|
||||
source_host = source_inv.hosts.create(name='host1')
|
||||
|
||||
constructed = Inventory.objects.create(name='constructed-inv', kind='constructed', organization=organization)
|
||||
Host.objects.create(name='host1', inventory=constructed, instance_id=str(source_host.pk))
|
||||
|
||||
response = get(reverse('api:dashboard_view'), user=admin_user, expect=200)
|
||||
assert response.data['hosts']['total'] == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_host_list_still_returns_constructed(get, admin_user, organization):
|
||||
"""
|
||||
Constructed inventory hosts are still visible through the API
|
||||
"""
|
||||
source_inv = Inventory.objects.create(name='source-inv', organization=organization)
|
||||
source_host = source_inv.hosts.create(name='host1')
|
||||
|
||||
constructed = Inventory.objects.create(name='constructed-inv', kind='constructed', organization=organization)
|
||||
Host.objects.create(name='host1', inventory=constructed, instance_id=str(source_host.pk))
|
||||
|
||||
response = get(reverse('api:host_list'), user=admin_user, expect=200)
|
||||
assert response.data['count'] == 2
|
||||
@@ -108,6 +108,28 @@ class TestActiveCount:
|
||||
source.hosts.create(name='remotely-managed-host', inventory=inventory)
|
||||
assert Host.objects.active_count() == 1
|
||||
|
||||
def test_active_count_minus_constructed(self, organization):
|
||||
"""
|
||||
Active hosts do not include duplicated hosts from construted inventories.
|
||||
"""
|
||||
inv = Inventory.objects.create(name='source-inv', organization=organization)
|
||||
inv.hosts.create(name='host1')
|
||||
assert Host.objects.active_count() == 1
|
||||
|
||||
constructed = Inventory.objects.create(name='constructed-inv', kind='constructed', organization=organization)
|
||||
Host.objects.create(name='host1', inventory=constructed)
|
||||
assert Host.objects.active_count() == 1
|
||||
|
||||
def test_org_active_count_minus_constructed(self, organization):
|
||||
"""Org-scoped count must also exclude constructed-inventory shadow rows."""
|
||||
inv = Inventory.objects.create(name='source-inv', organization=organization)
|
||||
inv.hosts.create(name='host1')
|
||||
assert Host.objects.org_active_count(organization.id) == 1
|
||||
|
||||
constructed = Inventory.objects.create(name='constructed-inv', kind='constructed', organization=organization)
|
||||
Host.objects.create(name='host1', inventory=constructed)
|
||||
assert Host.objects.org_active_count(organization.id) == 1
|
||||
|
||||
def test_host_case_insensitivity(self, organization):
|
||||
inv1 = Inventory.objects.create(name='inv1', organization=organization)
|
||||
inv2 = Inventory.objects.create(name='inv2', organization=organization)
|
||||
|
||||
Reference in New Issue
Block a user