mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 09:57:33 -02:30
Prevent running jobs from blocking inventory updates
A running job that has an inventory source will block that inventory update from running. This fix removes the block. The test creates a job in running state, and an inventory update in pending state. The test asserts that the task manager and dependency graph .is_job_blocked method returns False for the inventory update (i.e. update can run). issue #4809
This commit is contained in:
@@ -15,7 +15,6 @@ class DependencyGraph(object):
|
|||||||
INVENTORY_UPDATES = 'inventory_updates'
|
INVENTORY_UPDATES = 'inventory_updates'
|
||||||
|
|
||||||
JOB_TEMPLATE_JOBS = 'job_template_jobs'
|
JOB_TEMPLATE_JOBS = 'job_template_jobs'
|
||||||
JOB_INVENTORY_IDS = 'job_inventory_ids'
|
|
||||||
|
|
||||||
SYSTEM_JOB = 'system_job'
|
SYSTEM_JOB = 'system_job'
|
||||||
INVENTORY_SOURCE_UPDATES = 'inventory_source_updates'
|
INVENTORY_SOURCE_UPDATES = 'inventory_source_updates'
|
||||||
@@ -40,8 +39,6 @@ class DependencyGraph(object):
|
|||||||
Track runnable job related project and inventory to ensure updates
|
Track runnable job related project and inventory to ensure updates
|
||||||
don't run while a job needing those resources is running.
|
don't run while a job needing those resources is running.
|
||||||
'''
|
'''
|
||||||
# inventory_id -> True / False
|
|
||||||
self.data[self.JOB_INVENTORY_IDS] = {}
|
|
||||||
|
|
||||||
# inventory_source_id -> True / False
|
# inventory_source_id -> True / False
|
||||||
self.data[self.INVENTORY_SOURCE_UPDATES] = {}
|
self.data[self.INVENTORY_SOURCE_UPDATES] = {}
|
||||||
@@ -77,7 +74,6 @@ class DependencyGraph(object):
|
|||||||
self.data[self.INVENTORY_SOURCE_UPDATES][inventory_source_id] = False
|
self.data[self.INVENTORY_SOURCE_UPDATES][inventory_source_id] = False
|
||||||
|
|
||||||
def mark_job_template_job(self, job):
|
def mark_job_template_job(self, job):
|
||||||
self.data[self.JOB_INVENTORY_IDS][job.inventory_id] = False
|
|
||||||
self.data[self.JOB_TEMPLATE_JOBS][job.job_template_id] = False
|
self.data[self.JOB_TEMPLATE_JOBS][job.job_template_id] = False
|
||||||
|
|
||||||
def mark_workflow_job(self, job):
|
def mark_workflow_job(self, job):
|
||||||
@@ -87,8 +83,7 @@ class DependencyGraph(object):
|
|||||||
return self.data[self.PROJECT_UPDATES].get(job.project_id, True)
|
return self.data[self.PROJECT_UPDATES].get(job.project_id, True)
|
||||||
|
|
||||||
def can_inventory_update_run(self, job):
|
def can_inventory_update_run(self, job):
|
||||||
return self.data[self.JOB_INVENTORY_IDS].get(job.inventory_source.inventory_id, True) and \
|
return self.data[self.INVENTORY_SOURCE_UPDATES].get(job.inventory_source_id, True)
|
||||||
self.data[self.INVENTORY_SOURCE_UPDATES].get(job.inventory_source_id, True)
|
|
||||||
|
|
||||||
def can_job_run(self, job):
|
def can_job_run(self, job):
|
||||||
if self.data[self.PROJECT_UPDATES].get(job.project_id, True) is True and \
|
if self.data[self.PROJECT_UPDATES].get(job.project_id, True) is True and \
|
||||||
|
|||||||
@@ -353,3 +353,33 @@ def test_job_not_blocking_project_update(default_instance_group, job_template_fa
|
|||||||
dependency_graph = DependencyGraph(None)
|
dependency_graph = DependencyGraph(None)
|
||||||
dependency_graph.add_job(job)
|
dependency_graph.add_job(job)
|
||||||
assert not dependency_graph.is_job_blocked(project_update)
|
assert not dependency_graph.is_job_blocked(project_update)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_job_not_blocking_inventory_update(default_instance_group, job_template_factory, inventory_source_factory):
|
||||||
|
objects = job_template_factory('jt', organization='org1', project='proj',
|
||||||
|
inventory='inv', credential='cred',
|
||||||
|
jobs=["job"])
|
||||||
|
job = objects.jobs["job"]
|
||||||
|
job.instance_group = default_instance_group
|
||||||
|
job.status = "running"
|
||||||
|
job.save()
|
||||||
|
|
||||||
|
with mock.patch("awx.main.scheduler.TaskManager.start_task"):
|
||||||
|
task_manager = TaskManager()
|
||||||
|
task_manager._schedule()
|
||||||
|
|
||||||
|
inv = objects.inventory
|
||||||
|
inv_source = inventory_source_factory("ec2")
|
||||||
|
inv_source.source = "ec2"
|
||||||
|
inv.inventory_sources.add(inv_source)
|
||||||
|
inventory_update = inv_source.create_inventory_update()
|
||||||
|
inventory_update.instance_group = default_instance_group
|
||||||
|
inventory_update.status = "pending"
|
||||||
|
inventory_update.save()
|
||||||
|
|
||||||
|
assert not task_manager.is_job_blocked(inventory_update)
|
||||||
|
|
||||||
|
dependency_graph = DependencyGraph(None)
|
||||||
|
dependency_graph.add_job(job)
|
||||||
|
assert not dependency_graph.is_job_blocked(inventory_update)
|
||||||
|
|||||||
Reference in New Issue
Block a user