Merge pull request #1085 from ryanpetrello/fix-7876

fix a bug in custom venv support that breaks legacy `POST /api/v1/jobs`
This commit is contained in:
Ryan Petrello 2018-01-30 16:21:10 -05:00 committed by GitHub
commit 20a999f846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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'