mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 08:48:46 -03:30
Merge pull request #11693 from AlexSCorey/5576-host_count_case_sensitivity
Fixes case sensitive host count
This commit is contained in:
@@ -6,7 +6,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db.models.functions import Lower
|
||||||
from awx.main.utils.filters import SmartFilter
|
from awx.main.utils.filters import SmartFilter
|
||||||
from awx.main.utils.pglock import advisory_lock
|
from awx.main.utils.pglock import advisory_lock
|
||||||
from awx.main.utils.common import get_capacity_type
|
from awx.main.utils.common import get_capacity_type
|
||||||
@@ -35,7 +35,7 @@ class HostManager(models.Manager):
|
|||||||
- Only consider results that are unique
|
- Only consider results that are unique
|
||||||
- Return the count of this query
|
- Return the count of this query
|
||||||
"""
|
"""
|
||||||
return self.order_by().exclude(inventory_sources__source='controller').values('name').distinct().count()
|
return self.order_by().exclude(inventory_sources__source='controller').values(name_lower=Lower('name')).distinct().count()
|
||||||
|
|
||||||
def org_active_count(self, org_id):
|
def org_active_count(self, org_id):
|
||||||
"""Return count of active, unique hosts used by an organization.
|
"""Return count of active, unique hosts used by an organization.
|
||||||
|
|||||||
@@ -110,6 +110,16 @@ class TestActiveCount:
|
|||||||
source.hosts.create(name='remotely-managed-host', inventory=inventory)
|
source.hosts.create(name='remotely-managed-host', inventory=inventory)
|
||||||
assert Host.objects.active_count() == 1
|
assert Host.objects.active_count() == 1
|
||||||
|
|
||||||
|
def test_host_case_insensitivity(self, organization):
|
||||||
|
inv1 = Inventory.objects.create(name='inv1', organization=organization)
|
||||||
|
inv2 = Inventory.objects.create(name='inv2', organization=organization)
|
||||||
|
assert Host.objects.active_count() == 0
|
||||||
|
inv1.hosts.create(name='host1')
|
||||||
|
inv2.hosts.create(name='Host1')
|
||||||
|
assert Host.objects.active_count() == 1
|
||||||
|
inv1.hosts.create(name='host2')
|
||||||
|
assert Host.objects.active_count() == 2
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
class TestSCMUpdateFeatures:
|
class TestSCMUpdateFeatures:
|
||||||
|
|||||||
Reference in New Issue
Block a user