mirror of
https://github.com/ansible/awx.git
synced 2026-02-12 07:04:45 -03:30
Instance has gone lost, and jobs are still either running or waiting inside of its instance group RBAC - user does not have permission to see some of the groups that would be used in the capacity calculation For some cases, a naive capacity dictionary is returned, main goal is to not throw errors and avoid unpredicted behavior Detailed capacity tests are moved into new unit test file.
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
import pytest
|
|
|
|
from django.test import TransactionTestCase
|
|
|
|
from awx.main.models import (
|
|
Instance,
|
|
InstanceGroup,
|
|
)
|
|
|
|
|
|
@pytest.mark.django_db
|
|
class TestCapacityMapping(TransactionTestCase):
|
|
|
|
def sample_cluster(self):
|
|
ig_small = InstanceGroup.objects.create(name='ig_small')
|
|
ig_large = InstanceGroup.objects.create(name='ig_large')
|
|
tower = InstanceGroup.objects.create(name='tower')
|
|
i1 = Instance.objects.create(hostname='i1', capacity=200)
|
|
i2 = Instance.objects.create(hostname='i2', capacity=200)
|
|
i3 = Instance.objects.create(hostname='i3', capacity=200)
|
|
ig_small.instances.add(i1)
|
|
ig_large.instances.add(i2, i3)
|
|
tower.instances.add(i2)
|
|
return [tower, ig_large, ig_small]
|
|
|
|
def test_mapping(self):
|
|
self.sample_cluster()
|
|
with self.assertNumQueries(2):
|
|
inst_map, ig_map = InstanceGroup.objects.capacity_mapping()
|
|
assert inst_map['i1'] == set(['ig_small'])
|
|
assert inst_map['i2'] == set(['ig_large', 'tower'])
|
|
assert ig_map['ig_small'] == set(['ig_small'])
|
|
assert ig_map['ig_large'] == set(['ig_large', 'tower'])
|
|
assert ig_map['tower'] == set(['ig_large', 'tower'])
|