mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
Fix bug where unrelated jobs were linked as dependencies (#6735)
This commit is contained in:
parent
6d959daca1
commit
b97240417a
@ -389,8 +389,8 @@ class DependencyManager(TaskBase):
|
||||
if job_deps:
|
||||
dependencies += job_deps
|
||||
with disable_activity_stream():
|
||||
task.dependent_jobs.add(*dependencies)
|
||||
logger.debug(f'Linked {[dep.log_format for dep in dependencies]} as dependencies of {task.log_format}')
|
||||
task.dependent_jobs.add(*job_deps)
|
||||
logger.debug(f'Linked {[dep.log_format for dep in job_deps]} as dependencies of {task.log_format}')
|
||||
|
||||
UnifiedJob.objects.filter(pk__in=[task.pk for task in undeped_tasks]).update(dependencies_processed=True)
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ from datetime import timedelta
|
||||
|
||||
from awx.main.scheduler import TaskManager, DependencyManager, WorkflowManager
|
||||
from awx.main.utils import encrypt_field
|
||||
from awx.main.models import WorkflowJobTemplate, JobTemplate, Job
|
||||
from awx.main.models import WorkflowJobTemplate, JobTemplate, Job, Project, InventorySource, Inventory
|
||||
from awx.main.models.ha import Instance
|
||||
from . import create_job
|
||||
from django.conf import settings
|
||||
@ -371,7 +371,7 @@ def test_single_job_dependencies_inventory_update_launch(controlplane_instance_g
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_inventory_update_launches_project_update(controlplane_instance_group, scm_inventory_source):
|
||||
def test_inventory_update_launches_project_update(scm_inventory_source):
|
||||
ii = scm_inventory_source
|
||||
project = scm_inventory_source.source_project
|
||||
project.scm_update_on_launch = True
|
||||
@ -386,6 +386,46 @@ def test_inventory_update_launches_project_update(controlplane_instance_group, s
|
||||
assert project.project_updates.count() == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_dependency_isolation(organization):
|
||||
"""Spawning both a job project update dependency, and an inventory update project dependency
|
||||
|
||||
this should keep dependencies isolated"""
|
||||
with mock.patch('awx.main.models.unified_jobs.UnifiedJobTemplate.update'):
|
||||
updating_projects = [
|
||||
Project.objects.create(name='iso-proj', organization=organization, scm_url='https://foo.invalid', scm_type='git', scm_update_on_launch=True)
|
||||
for i in range(2)
|
||||
]
|
||||
|
||||
inv_src = InventorySource.objects.create(
|
||||
name='iso-inv',
|
||||
organization=organization,
|
||||
source_project=updating_projects[0],
|
||||
source='scm',
|
||||
inventory=Inventory.objects.create(name='for-inv-src', organization=organization),
|
||||
)
|
||||
|
||||
inv_update = inv_src.create_unified_job()
|
||||
inv_update.signal_start()
|
||||
assert not inv_update.dependent_jobs.exists()
|
||||
|
||||
jt = JobTemplate.objects.create(
|
||||
project=updating_projects[1],
|
||||
inventory=Inventory.objects.create(name='one-off', organization=organization), # non-updating inventory source
|
||||
)
|
||||
job = jt.create_unified_job()
|
||||
job.signal_start()
|
||||
assert not job.dependent_jobs.exists()
|
||||
|
||||
dm = DependencyManager()
|
||||
dm.schedule()
|
||||
|
||||
# in a single run, the completely unrelated inventory and jobs are linked to their own dependencies
|
||||
assert (inv_update.dependent_jobs.count(), job.dependent_jobs.count()) == (1, 1)
|
||||
assert inv_update.dependent_jobs.first().project == updating_projects[0]
|
||||
assert job.dependent_jobs.first().project == updating_projects[1]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_job_dependency_with_already_updated(controlplane_instance_group, job_template_factory, mocker, inventory_source_factory):
|
||||
objects = job_template_factory('jt', organization='org1', project='proj', inventory='inv', credential='cred')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user