mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
Fix 500 on missing inventory for provisioning callbacks (#13862)
* Fix 500 on missing inventory for provisioning callbacks * Added test to cover bug fix * Reworded msg to clear what is missing to start the callback
This commit is contained in:
@@ -2692,7 +2692,10 @@ class JobTemplateCallback(GenericAPIView):
|
|||||||
# Permission class should have already validated host_config_key.
|
# Permission class should have already validated host_config_key.
|
||||||
job_template = self.get_object()
|
job_template = self.get_object()
|
||||||
# Attempt to find matching hosts based on remote address.
|
# Attempt to find matching hosts based on remote address.
|
||||||
matching_hosts = self.find_matching_hosts()
|
if job_template.inventory:
|
||||||
|
matching_hosts = self.find_matching_hosts()
|
||||||
|
else:
|
||||||
|
return Response({"msg": _("Cannot start automatically, an inventory is required.")}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
# If the host is not found, update the inventory before trying to
|
# If the host is not found, update the inventory before trying to
|
||||||
# match again.
|
# match again.
|
||||||
inventory_sources_already_updated = []
|
inventory_sources_already_updated = []
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import pytest
|
|||||||
# AWX
|
# AWX
|
||||||
from awx.api.serializers import JobTemplateSerializer
|
from awx.api.serializers import JobTemplateSerializer
|
||||||
from awx.api.versioning import reverse
|
from awx.api.versioning import reverse
|
||||||
from awx.main.models import Job, JobTemplate, CredentialType, WorkflowJobTemplate, Organization, Project
|
from awx.main.models import Job, JobTemplate, CredentialType, WorkflowJobTemplate, Organization, Project, Inventory
|
||||||
from awx.main.migrations import _save_password_keys as save_password_keys
|
from awx.main.migrations import _save_password_keys as save_password_keys
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
@@ -353,3 +353,19 @@ def test_job_template_branch_prompt_error(project, inventory, post, admin_user):
|
|||||||
expect=400,
|
expect=400,
|
||||||
)
|
)
|
||||||
assert 'Project does not allow overriding branch' in str(r.data['ask_scm_branch_on_launch'])
|
assert 'Project does not allow overriding branch' in str(r.data['ask_scm_branch_on_launch'])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_job_template_missing_inventory(project, inventory, admin_user, post):
|
||||||
|
jt = JobTemplate.objects.create(
|
||||||
|
name='test-jt', inventory=inventory, ask_inventory_on_launch=True, project=project, playbook='helloworld.yml', host_config_key='abcd'
|
||||||
|
)
|
||||||
|
Inventory.objects.get(pk=inventory.pk).delete()
|
||||||
|
r = post(
|
||||||
|
url=reverse('api:job_template_callback', kwargs={'pk': jt.pk}),
|
||||||
|
data={'host_config_key': 'abcd'},
|
||||||
|
user=admin_user,
|
||||||
|
expect=400,
|
||||||
|
)
|
||||||
|
assert r.status_code == 400
|
||||||
|
assert "Cannot start automatically, an inventory is required." in str(r.data)
|
||||||
|
|||||||
Reference in New Issue
Block a user