mirror of
https://github.com/ansible/awx.git
synced 2024-10-30 22:21:13 +03:00
Merge pull request #3770 from AlanCoding/playbook_files
Update JT playbook validation for HA
This commit is contained in:
commit
fb33878d64
@ -1847,7 +1847,7 @@ class JobOptionsSerializer(LabelsListMixin, BaseSerializer):
|
||||
job_type = attrs.get('job_type', self.instance and self.instance.job_type or None)
|
||||
if not project and job_type != PERM_INVENTORY_SCAN:
|
||||
raise serializers.ValidationError({'project': 'This field is required.'})
|
||||
if project and playbook and force_text(playbook) not in project.playbooks:
|
||||
if project and playbook and force_text(playbook) not in project.playbook_files:
|
||||
raise serializers.ValidationError({'playbook': 'Playbook not found for project.'})
|
||||
if project and not playbook:
|
||||
raise serializers.ValidationError({'playbook': 'Must select playbook for project.'})
|
||||
|
@ -74,7 +74,8 @@ def mk_user(name, is_superuser=False, organization=None, team=None, persisted=Tr
|
||||
|
||||
def mk_project(name, organization=None, description=None, persisted=True):
|
||||
description = description or '{}-description'.format(name)
|
||||
project = Project(name=name, description=description)
|
||||
project = Project(name=name, description=description,
|
||||
playbook_files=['helloworld.yml', 'alt-helloworld.yml'])
|
||||
if organization is not None:
|
||||
project.organization = organization
|
||||
if persisted:
|
||||
@ -134,7 +135,7 @@ def mk_job_template(name, job_type='run',
|
||||
extra_vars = json.dumps(extra_vars)
|
||||
|
||||
jt = JobTemplate(name=name, job_type=job_type, extra_vars=extra_vars,
|
||||
playbook='mocked')
|
||||
playbook='helloworld.yml')
|
||||
|
||||
jt.inventory = inventory
|
||||
if jt.inventory is None:
|
||||
|
@ -1,22 +1,15 @@
|
||||
import pytest
|
||||
import mock
|
||||
|
||||
# AWX
|
||||
from awx.api.serializers import JobTemplateSerializer, JobLaunchSerializer
|
||||
from awx.main.models.jobs import Job
|
||||
from awx.main.models.projects import ProjectOptions
|
||||
from awx.main.migrations import _save_password_keys as save_password_keys
|
||||
|
||||
# Django
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.apps import apps
|
||||
|
||||
@property
|
||||
def project_playbooks(self):
|
||||
return ['mocked', 'mocked.yml', 'alt-mocked.yml']
|
||||
|
||||
@pytest.mark.django_db
|
||||
@mock.patch.object(ProjectOptions, "playbooks", project_playbooks)
|
||||
@pytest.mark.parametrize(
|
||||
"grant_project, grant_credential, grant_inventory, expect", [
|
||||
(True, True, True, 201),
|
||||
@ -38,11 +31,10 @@ def test_create(post, project, machine_credential, inventory, alice, grant_proje
|
||||
'project': project.id,
|
||||
'credential': machine_credential.id,
|
||||
'inventory': inventory.id,
|
||||
'playbook': 'mocked.yml',
|
||||
'playbook': 'helloworld.yml',
|
||||
}, alice, expect=expect)
|
||||
|
||||
@pytest.mark.django_db
|
||||
@mock.patch.object(ProjectOptions, "playbooks", project_playbooks)
|
||||
@pytest.mark.parametrize(
|
||||
"grant_project, grant_credential, grant_inventory, expect", [
|
||||
(True, True, True, 200),
|
||||
@ -67,11 +59,10 @@ def test_edit_sensitive_fields(patch, job_template_factory, alice, grant_project
|
||||
'project': objs.project.id,
|
||||
'credential': objs.credential.id,
|
||||
'inventory': objs.inventory.id,
|
||||
'playbook': 'alt-mocked.yml',
|
||||
'playbook': 'alt-helloworld.yml',
|
||||
}, alice, expect=expect)
|
||||
|
||||
@pytest.mark.django_db
|
||||
@mock.patch.object(ProjectOptions, "playbooks", project_playbooks)
|
||||
def test_edit_playbook(patch, job_template_factory, alice):
|
||||
objs = job_template_factory('jt', organization='org1', project='prj', inventory='inv', credential='cred')
|
||||
objs.job_template.admin_role.members.add(alice)
|
||||
@ -80,16 +71,15 @@ def test_edit_playbook(patch, job_template_factory, alice):
|
||||
objs.inventory.use_role.members.add(alice)
|
||||
|
||||
patch(reverse('api:job_template_detail', args=(objs.job_template.id,)), {
|
||||
'playbook': 'alt-mocked.yml',
|
||||
'playbook': 'alt-helloworld.yml',
|
||||
}, alice, expect=200)
|
||||
|
||||
objs.inventory.use_role.members.remove(alice)
|
||||
patch(reverse('api:job_template_detail', args=(objs.job_template.id,)), {
|
||||
'playbook': 'mocked.yml',
|
||||
'playbook': 'helloworld.yml',
|
||||
}, alice, expect=403)
|
||||
|
||||
@pytest.mark.django_db
|
||||
@mock.patch.object(ProjectOptions, "playbooks", project_playbooks)
|
||||
def test_edit_nonsenstive(patch, job_template_factory, alice):
|
||||
objs = job_template_factory('jt', organization='org1', project='prj', inventory='inv', credential='cred')
|
||||
jt = objs.job_template
|
||||
@ -121,10 +111,6 @@ def jt_copy_edit(job_template_factory, project):
|
||||
project=project)
|
||||
return objects.job_template
|
||||
|
||||
@property
|
||||
def project_playbooks(self):
|
||||
return ['mocked', 'mocked.yml', 'alt-mocked.yml']
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_job_template_role_user(post, organization_factory, job_template_factory):
|
||||
objects = organization_factory("org",
|
||||
@ -143,7 +129,6 @@ def test_job_template_role_user(post, organization_factory, job_template_factory
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@mock.patch.object(ProjectOptions, "playbooks", project_playbooks)
|
||||
def test_jt_admin_copy_edit_functional(jt_copy_edit, rando, get, post):
|
||||
|
||||
# Grant random user JT admin access only
|
||||
|
@ -110,7 +110,8 @@ def team_member(user, team):
|
||||
def project(instance, organization):
|
||||
prj = Project.objects.create(name="test-proj",
|
||||
description="test-proj-desc",
|
||||
organization=organization
|
||||
organization=organization,
|
||||
playbook_files=['helloworld.yml', 'alt-helloworld.yml']
|
||||
)
|
||||
return prj
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user