mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-17 07:28:36 -05:00
Merge pull request #2174 from chrismeyersfsu/fix-reaper_hostname_map
fix celery task reaper
This commit is contained in:
@@ -265,10 +265,10 @@ class TestReaper():
|
||||
def all_jobs(self, mocker):
|
||||
now = tz_now()
|
||||
|
||||
Instance.objects.create(hostname='host1', capacity=100)
|
||||
Instance.objects.create(hostname='host2', capacity=100)
|
||||
Instance.objects.create(hostname='host3_split', capacity=100)
|
||||
Instance.objects.create(hostname='host4_offline', capacity=0)
|
||||
Instance.objects.create(hostname='host1', system_hostname='host1_not_really', capacity=100)
|
||||
Instance.objects.create(hostname='host2', system_hostname='host2', capacity=100)
|
||||
Instance.objects.create(hostname='host3_split', system_hostname='host3_not_really', capacity=100)
|
||||
Instance.objects.create(hostname='host4_offline', system_hostname='host4_offline', capacity=0)
|
||||
|
||||
j1 = Job.objects.create(status='pending', execution_node='host1')
|
||||
j2 = Job.objects.create(status='waiting', celery_task_id='considered_j2')
|
||||
@@ -327,7 +327,7 @@ class TestReaper():
|
||||
@pytest.fixture
|
||||
def active_tasks(self):
|
||||
return ([], {
|
||||
'host1': ['considered_j2', 'considered_j3', 'considered_j4',],
|
||||
'host1_not_really': ['considered_j2', 'considered_j3', 'considered_j4',],
|
||||
'host2': ['considered_j6', 'considered_j7'],
|
||||
})
|
||||
|
||||
@@ -340,9 +340,9 @@ class TestReaper():
|
||||
|
||||
tm.get_running_tasks = mocker.Mock(return_value=(running_tasks, waiting_tasks))
|
||||
tm.get_active_tasks = mocker.Mock(return_value=active_tasks)
|
||||
|
||||
|
||||
tm.cleanup_inconsistent_celery_tasks()
|
||||
|
||||
|
||||
for j in considered_jobs:
|
||||
if j not in reapable_jobs:
|
||||
j.save.assert_not_called()
|
||||
|
||||
@@ -26,6 +26,7 @@ class TestCleanupInconsistentCeleryTasks():
|
||||
def test_instance_does_not_exist(self, logger_mock, *args):
|
||||
logger_mock.error = mock.MagicMock(side_effect=RuntimeError("mocked"))
|
||||
tm = TaskManager()
|
||||
tm.map_system_hostname_to_instance_hostname = lambda *args: dict()
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
tm.cleanup_inconsistent_celery_tasks()
|
||||
|
||||
@@ -45,6 +46,7 @@ class TestCleanupInconsistentCeleryTasks():
|
||||
job.websocket_emit_status = mock.MagicMock()
|
||||
get_running_tasks.return_value = ({'host1': [job]}, [])
|
||||
tm = TaskManager()
|
||||
tm.map_system_hostname_to_instance_hostname = lambda *args: dict(host1=[])
|
||||
|
||||
with mock.patch.object(job, 'save', side_effect=DatabaseError):
|
||||
tm.cleanup_inconsistent_celery_tasks()
|
||||
|
||||
Reference in New Issue
Block a user