fix a bug in custom venv support that breaks legacy POST /api/v1/jobs

see: https://github.com/ansible/ansible-tower/issues/7876
This commit is contained in:
Ryan Petrello 2018-01-30 15:29:11 -05:00
parent a9b77eb706
commit 8fed469975
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777
2 changed files with 13 additions and 2 deletions

View File

@ -518,7 +518,7 @@ class Job(UnifiedJob, JobOptions, SurveyJobMixin, JobNotificationMixin, TaskMana
def ansible_virtualenv_path(self):
# the order here enforces precedence (it matters)
for virtualenv in (
self.job_template.custom_virtualenv,
self.job_template.custom_virtualenv if self.job_template else None,
self.project.custom_virtualenv,
self.project.organization.custom_virtualenv
):

View File

@ -1,6 +1,6 @@
import pytest
from awx.main.models import JobTemplate
from awx.main.models import JobTemplate, Job
@pytest.mark.django_db
@ -38,3 +38,14 @@ def test_awx_custom_virtualenv(inventory, project, machine_credential):
job.job_template.custom_virtualenv = '/venv/fancy-jt'
job.job_template.save()
assert job.ansible_virtualenv_path == '/venv/fancy-jt'
@pytest.mark.django_db
def test_awx_custom_virtualenv_without_jt(project):
project.custom_virtualenv = '/venv/fancy-proj'
project.save()
job = Job(project=project)
job.save()
job = Job.objects.get(pk=job.id)
assert job.ansible_virtualenv_path == '/venv/fancy-proj'