mirror of
https://github.com/ansible/awx.git
synced 2026-03-23 11:55:04 -02:30
Merge pull request #2498 from AlanCoding/relaunch_fix
Fix bug with relaunching with changed JT Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
@@ -847,10 +847,10 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
setattr(unified_job, fd, val)
|
setattr(unified_job, fd, val)
|
||||||
unified_job.save()
|
unified_job.save()
|
||||||
|
|
||||||
# Labels copied here
|
# Labels copied here
|
||||||
from awx.main.signals import disable_activity_stream
|
from awx.main.signals import disable_activity_stream
|
||||||
with disable_activity_stream():
|
with disable_activity_stream():
|
||||||
copy_m2m_relationships(self, unified_job, fields)
|
copy_m2m_relationships(self, unified_job, fields)
|
||||||
|
|
||||||
return unified_job
|
return unified_job
|
||||||
|
|
||||||
|
|||||||
@@ -671,6 +671,24 @@ def job_template_labels(organization, job_template):
|
|||||||
return job_template
|
return job_template
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def jt_linked(job_template_factory, credential, net_credential, vault_credential):
|
||||||
|
'''
|
||||||
|
A job template with a reasonably complete set of related objects to
|
||||||
|
test RBAC and other functionality affected by related objects
|
||||||
|
'''
|
||||||
|
objects = job_template_factory(
|
||||||
|
'testJT', organization='org1', project='proj1', inventory='inventory1',
|
||||||
|
credential='cred1')
|
||||||
|
jt = objects.job_template
|
||||||
|
jt.credentials.add(vault_credential)
|
||||||
|
jt.save()
|
||||||
|
# Add AWS cloud credential and network credential
|
||||||
|
jt.credentials.add(credential)
|
||||||
|
jt.credentials.add(net_credential)
|
||||||
|
return jt
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def workflow_job_template(organization):
|
def workflow_job_template(organization):
|
||||||
wjt = WorkflowJobTemplate(name='test-workflow_job_template', organization=organization)
|
wjt = WorkflowJobTemplate(name='test-workflow_job_template', organization=organization)
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
import itertools
|
import itertools
|
||||||
import pytest
|
import pytest
|
||||||
|
import six
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.models import UnifiedJobTemplate, Job, JobTemplate, WorkflowJobTemplate, Project, WorkflowJob, Schedule
|
from awx.main.models import (
|
||||||
|
UnifiedJobTemplate, Job, JobTemplate, WorkflowJobTemplate,
|
||||||
|
Project, WorkflowJob, Schedule,
|
||||||
|
Credential
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@@ -63,6 +68,21 @@ class TestCreateUnifiedJob:
|
|||||||
assert second_job.limit == 'my_server'
|
assert second_job.limit == 'my_server'
|
||||||
assert net_credential in second_job.credentials.all()
|
assert net_credential in second_job.credentials.all()
|
||||||
|
|
||||||
|
def test_job_relaunch_modifed_jt(self, jt_linked):
|
||||||
|
# Replace all credentials with a new one of same type
|
||||||
|
new_creds = []
|
||||||
|
for cred in jt_linked.credentials.all():
|
||||||
|
new_creds.append(Credential.objects.create(
|
||||||
|
name=six.text_type(cred.name) + six.text_type('_new'),
|
||||||
|
credential_type=cred.credential_type,
|
||||||
|
inputs=cred.inputs
|
||||||
|
))
|
||||||
|
job = jt_linked.create_unified_job()
|
||||||
|
jt_linked.credentials.clear()
|
||||||
|
jt_linked.credentials.add(*new_creds)
|
||||||
|
relaunched_job = job.copy_unified_job()
|
||||||
|
assert set(relaunched_job.credentials.all()) == set(new_creds)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
class TestMetaVars:
|
class TestMetaVars:
|
||||||
|
|||||||
@@ -15,24 +15,6 @@ from awx.main.models.organization import Organization
|
|||||||
from awx.main.models.schedules import Schedule
|
from awx.main.models.schedules import Schedule
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def jt_linked(job_template_factory, credential, net_credential, vault_credential):
|
|
||||||
'''
|
|
||||||
A job template with a reasonably complete set of related objects to
|
|
||||||
test RBAC and other functionality affected by related objects
|
|
||||||
'''
|
|
||||||
objects = job_template_factory(
|
|
||||||
'testJT', organization='org1', project='proj1', inventory='inventory1',
|
|
||||||
credential='cred1')
|
|
||||||
jt = objects.job_template
|
|
||||||
jt.credentials.add(vault_credential)
|
|
||||||
jt.save()
|
|
||||||
# Add AWS cloud credential and network credential
|
|
||||||
jt.credentials.add(credential)
|
|
||||||
jt.credentials.add(net_credential)
|
|
||||||
return jt
|
|
||||||
|
|
||||||
|
|
||||||
@mock.patch.object(BaseAccess, 'check_license', return_value=None)
|
@mock.patch.object(BaseAccess, 'check_license', return_value=None)
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_job_template_access_superuser(check_license, user, deploy_jobtemplate):
|
def test_job_template_access_superuser(check_license, user, deploy_jobtemplate):
|
||||||
|
|||||||
Reference in New Issue
Block a user