mirror of
https://github.com/ansible/awx.git
synced 2026-02-27 07:56:06 -03:30
enforce 1 edge between 2 nodes constraint
This commit is contained in:
@@ -2957,6 +2957,12 @@ class WorkflowJobTemplateNodeChildrenBaseList(WorkflowsEnforcementMixin, Enforce
|
|||||||
if parent.id == sub.id:
|
if parent.id == sub.id:
|
||||||
return {"Error": _("Cycle detected.")}
|
return {"Error": _("Cycle detected.")}
|
||||||
|
|
||||||
|
if WorkflowJobTemplateNode.objects.filter(Q(pk=parent.id) &
|
||||||
|
Q(success_nodes__in=[sub.id]) |
|
||||||
|
Q(failure_nodes__in=[sub.id]) |
|
||||||
|
Q(always_nodes__in=[sub.id])).exists():
|
||||||
|
return {"Error": _("Relationship not allowed.")}
|
||||||
|
|
||||||
parent_node_type_relationship = getattr(parent, self.relationship)
|
parent_node_type_relationship = getattr(parent, self.relationship)
|
||||||
parent_node_type_relationship.add(sub)
|
parent_node_type_relationship.add(sub)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
import json
|
||||||
|
|
||||||
from awx.api.versioning import reverse
|
from awx.api.versioning import reverse
|
||||||
|
|
||||||
@@ -75,6 +76,41 @@ def test_node_accepts_prompted_fields(inventory, project, workflow_job_template,
|
|||||||
user=admin_user, expect=201)
|
user=admin_user, expect=201)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
class TestExclusivePathEnforcement():
|
||||||
|
@pytest.fixture
|
||||||
|
def n1(self, workflow_job_template):
|
||||||
|
return WorkflowJobTemplateNode.objects.create(workflow_job_template=workflow_job_template)
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def n2(self, workflow_job_template):
|
||||||
|
return WorkflowJobTemplateNode.objects.create(workflow_job_template=workflow_job_template)
|
||||||
|
|
||||||
|
def generate_url(self, path, id):
|
||||||
|
return reverse('api:workflow_job_template_node_{}_nodes_list'.format(path),
|
||||||
|
kwargs={'pk': id})
|
||||||
|
|
||||||
|
path_permutations = [
|
||||||
|
['success', 'failure', 'always'],
|
||||||
|
['success', 'always', 'failure'],
|
||||||
|
['failure', 'always', 'success'],
|
||||||
|
['failure', 'success', 'always'],
|
||||||
|
['always', 'success', 'failure'],
|
||||||
|
['always', 'failure', 'success'],
|
||||||
|
]
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("paths", path_permutations, ids=["-".join(item) for item in path_permutations])
|
||||||
|
def test_multi_connections_same_parent_disallowed(self, post, admin_user, n1, n2, paths):
|
||||||
|
for index, path in enumerate(paths):
|
||||||
|
r = post(self.generate_url(path, n1.id),
|
||||||
|
data={'associate': True, 'id': n2.id},
|
||||||
|
user=admin_user,
|
||||||
|
expect=204 if index == 0 else 400)
|
||||||
|
|
||||||
|
if index != 0:
|
||||||
|
assert {'Error': 'Relationship not allowed.'} == json.loads(r.content)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
class TestNodeCredentials:
|
class TestNodeCredentials:
|
||||||
'''
|
'''
|
||||||
|
|||||||
Reference in New Issue
Block a user