Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where unrelated jobs were linked as dependencies #15610

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions awx/main/scheduler/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,10 @@
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)

Check warning on line 395 in awx/main/scheduler/task_manager.py

View check run for this annotation

Codecov / codecov/patch

awx/main/scheduler/task_manager.py#L392-L395

Added lines #L392 - L395 were not covered by tests

return dependencies

Expand Down
44 changes: 42 additions & 2 deletions awx/main/tests/functional/task_management/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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
Expand Down Expand Up @@ -371,7 +371,7 @@


@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
Expand All @@ -386,6 +386,46 @@
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(

Check warning on line 400 in awx/main/tests/functional/task_management/test_scheduler.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/functional/task_management/test_scheduler.py#L400

Added line #L400 was not covered by tests
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()

Check warning on line 410 in awx/main/tests/functional/task_management/test_scheduler.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/functional/task_management/test_scheduler.py#L408-L410

Added lines #L408 - L410 were not covered by tests

jt = JobTemplate.objects.create(

Check warning on line 412 in awx/main/tests/functional/task_management/test_scheduler.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/functional/task_management/test_scheduler.py#L412

Added line #L412 was not covered by tests
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()

Check warning on line 418 in awx/main/tests/functional/task_management/test_scheduler.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/functional/task_management/test_scheduler.py#L416-L418

Added lines #L416 - L418 were not covered by tests

dm = DependencyManager()
dm.schedule()

Check warning on line 421 in awx/main/tests/functional/task_management/test_scheduler.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/functional/task_management/test_scheduler.py#L420-L421

Added lines #L420 - L421 were not covered by tests

# 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]

Check warning on line 426 in awx/main/tests/functional/task_management/test_scheduler.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/functional/task_management/test_scheduler.py#L424-L426

Added lines #L424 - L426 were not covered by tests


@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')
Expand Down
Loading