Clean up work_type processing and fix execution vs control capacity (#10930)

* Clean up added work_type processing for mesh_code branch

* track both execution and control capacity

* Remove unused execution_capacity property

* Count all forms of capacity to make test pass

* Force jobs to be on execution nodes, updates on control nodes

* Introduce capacity_type property to abstract some details out

* Update test to cover all job types at same time

* Register OpenShift nodes as control types

* Remove unqualified consumed_capacity from task manager and make unit tests work

* Remove unqualified consumed_capacity from task manager and make unit tests work

* Update unit test to execution vs control TM logic changes

* Fix bug, else handling for work_type method
This commit is contained in:
Alan Rominger
2021-08-26 07:24:14 -04:00
committed by GitHub
parent fb0e55fd1b
commit daf4310176
16 changed files with 159 additions and 88 deletions

View File

@@ -17,8 +17,9 @@ def test_capacity_adjustment_no_save(capacity_adjustment):
def T(impact):
j = mock.Mock(spec_set=['task_impact'])
j = mock.Mock(spec_set=['task_impact', 'capacity_type'])
j.task_impact = impact
j.capacity_type = 'execution'
return j
@@ -35,11 +36,13 @@ def Is(param):
inst = Mock()
inst.capacity = capacity
inst.jobs_running = jobs_running
inst.node_type = 'execution'
instances.append(inst)
else:
for i in param:
inst = Mock()
inst.remaining_capacity = i
inst.node_type = 'execution'
instances.append(inst)
return instances

View File

@@ -3,10 +3,16 @@ import pytest
from awx.main.models import InstanceGroup
class FakeMeta(object):
model_name = 'job'
class FakeObject(object):
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
self._meta = FakeMeta()
self._meta.concrete_model = self
class Job(FakeObject):
@@ -85,7 +91,7 @@ def test_offline_node_running(sample_cluster):
ig_small.instance_list[0].capacity = 0
tasks = [Job(status='running', execution_node='i1', instance_group=ig_small)]
capacities = InstanceGroup.objects.capacity_values(qs=[default, ig_large, ig_small], tasks=tasks)
assert capacities['ig_small']['consumed_capacity'] == 43
assert capacities['ig_small']['consumed_execution_capacity'] == 43
def test_offline_node_waiting(sample_cluster):
@@ -96,7 +102,7 @@ def test_offline_node_waiting(sample_cluster):
ig_small.instance_list[0].capacity = 0
tasks = [Job(status='waiting', instance_group=ig_small)]
capacities = InstanceGroup.objects.capacity_values(qs=[default, ig_large, ig_small], tasks=tasks)
assert capacities['ig_small']['consumed_capacity'] == 43
assert capacities['ig_small']['consumed_execution_capacity'] == 43
def test_RBAC_reduced_filter(sample_cluster):

View File

@@ -104,18 +104,32 @@ def test_get_type_for_model(model, name):
assert common.get_type_for_model(model) == name
@pytest.mark.django_db
def test_get_model_for_invalid_type():
with pytest.raises(LookupError):
common.get_model_for_type('foobar')
@pytest.mark.django_db
@pytest.mark.parametrize("model_type,model_class", [(name, cls) for cls, name in TEST_MODELS])
def test_get_model_for_valid_type(model_type, model_class):
assert common.get_model_for_type(model_type) == model_class
@pytest.mark.parametrize("model_type,model_class", [(name, cls) for cls, name in TEST_MODELS])
def test_get_capacity_type(model_type, model_class):
if model_type in ('job', 'ad_hoc_command', 'inventory_update', 'job_template'):
expectation = 'execution'
elif model_type in ('project_update', 'system_job'):
expectation = 'control'
else:
expectation = None
if model_type in ('unified_job', 'unified_job_template', 'inventory'):
with pytest.raises(RuntimeError):
common.get_capacity_type(model_class)
else:
assert common.get_capacity_type(model_class) == expectation
assert common.get_capacity_type(model_class()) == expectation
@pytest.fixture
def memoized_function(mocker, mock_cache):
with mock.patch('awx.main.utils.common.get_memoize_cache', return_value=mock_cache):